chore: refactoring

This commit is contained in:
Georgy Litvinov 2021-08-10 14:27:19 +02:00
parent 1d4ce4e100
commit 8621834a5b
3 changed files with 78 additions and 68 deletions

View file

@ -9,20 +9,22 @@ import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import static pro.litvinovg.w2phtml.gui.Contstants.*;
public class HTMLPanel extends BasePanel{
/**
*
*/
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
Localizer localizerStub = new Localizer();
HashMap<String, Component> configStub = new HashMap<String,Component>();
UIPreferences prefStub = PreferencesStorage.getDefaultHTML(null);
Object htmlPanel = new HTMLPanel(configStub,localizerStub,prefStub);
}
public HTMLPanel(HashMap<String, Component> configuration, Localizer localizer, UIPreferences preferences) {
super(localizer, configuration, preferences);

View file

@ -33,77 +33,77 @@ public class PreferencesStorage {
}
private void initializeDefault() {
initializeDefaultHTML();
initializeDefaultEpub();
initializeDefaultRDF();
tabs.put(HTML, getDefaultHTML(this));
tabs.put(EPUB,getDefaultEpub(this));
tabs.put(RDF,getDefaultRDF(this));
}
private void initializeDefaultHTML() {
UIPreferences prefs = new UIPreferences(this);
add(PREF_RESOLUTIONS, new String[]{"0","72","150","300","600","1200","2400"} , prefs);
add(PREF_DEFAULT_IMAGE_RESOLUTION,"2", prefs);
add(PREF_USE_MATHJAX,"true", prefs);
add(PREF_IGNORE_EMPTY_PARS,"false", prefs);
add(PREF_IGNORE_HARD_BREAKS,"false", prefs);
add(PREF_GREENSTONE_TAGS,"false", prefs);
add(PREF_LETTER_SPACING,"0.15",prefs);
add(PREF_INLINE_STYLES,"true", prefs);
add(PREF_EMBED_RASTER,"true", prefs);
add(PREF_EMBED_VECTOR,"true", prefs);
add(PREF_CONVERT_TO_PX,"false", prefs);
add(PREF_PAGEBREAK_STYLES,DEFAULT_PAGEBREAK_STYLE_SETTINGS,prefs);
add(PREF_PAGINATION,"true",prefs);
add(PREF_SPLIT_LEVELS, new String[]{"0","1","2","3","4","5","6","7","8","9","10"} ,prefs);
add(PREF_SPLIT_BY_LEVEL,"0",prefs);
add(PREF_TYPE,HTML,prefs);
add(PREF_MAX_WIDTH,"",prefs);
add(PREF_SPLIT_WHOLE_PAGES,"false",prefs);
add(PREF_SCALING, SCALING_DEFAULT_VALUE, prefs);
public static UIPreferences getDefaultHTML(PreferencesStorage store) {
UIPreferences prefs = new UIPreferences(store);
prefs.put(PREF_RESOLUTIONS, new String[]{"0","72","150","300","600","1200","2400"} );
prefs.put(PREF_DEFAULT_IMAGE_RESOLUTION,"2");
prefs.put(PREF_USE_MATHJAX,"true");
prefs.put(PREF_IGNORE_EMPTY_PARS,"false");
prefs.put(PREF_IGNORE_HARD_BREAKS,"false");
prefs.put(PREF_GREENSTONE_TAGS,"false");
prefs.put(PREF_LETTER_SPACING,"0.15");
prefs.put(PREF_INLINE_STYLES,"true");
prefs.put(PREF_EMBED_RASTER,"true");
prefs.put(PREF_EMBED_VECTOR,"true");
prefs.put(PREF_CONVERT_TO_PX,"false");
prefs.put(PREF_PAGEBREAK_STYLES,DEFAULT_PAGEBREAK_STYLE_SETTINGS);
prefs.put(PREF_PAGINATION,"true");
prefs.put(PREF_SPLIT_LEVELS, new String[]{"0","1","2","3","4","5","6","7","8","9","10"} );
prefs.put(PREF_SPLIT_BY_LEVEL,"0");
prefs.put(PREF_TYPE,HTML);
prefs.put(PREF_MAX_WIDTH,"");
prefs.put(PREF_SPLIT_WHOLE_PAGES,"false");
prefs.put(PREF_SCALING, SCALING_DEFAULT_VALUE);
prefs.setDefault(true);
tabs.put(HTML, prefs);
return prefs;
}
private void initializeDefaultEpub() {
UIPreferences prefs = new UIPreferences(this);
add(PREF_RESOLUTIONS, new String[]{"0","72","150","300","600","1200","2400"} , prefs);
add(PREF_DEFAULT_IMAGE_RESOLUTION,"2", prefs);
add(PREF_USE_MATHJAX,"true", prefs);
add(PREF_IGNORE_EMPTY_PARS,"false", prefs);
add(PREF_IGNORE_HARD_BREAKS,"false", prefs);
add(PREF_LETTER_SPACING,"0.15",prefs);
add(PREF_INLINE_STYLES,"true", prefs);
add(PREF_EMBED_RASTER,"true", prefs);
add(PREF_EMBED_VECTOR,"true", prefs);
add(PREF_CONVERT_TO_PX,"false", prefs);
add(PREF_SCALING, SCALING_DEFAULT_VALUE, prefs);
add(PREF_PAGEBREAK_STYLES,DEFAULT_PAGEBREAK_STYLE_SETTINGS,prefs);
add(PREF_PAGINATION,"true",prefs);
add(PREF_TYPE,EPUB,prefs);
public static UIPreferences getDefaultEpub(PreferencesStorage store) {
UIPreferences prefs = new UIPreferences(store);
prefs.put(PREF_RESOLUTIONS, new String[]{"0","72","150","300","600","1200","2400"});
prefs.put(PREF_DEFAULT_IMAGE_RESOLUTION,"2");
prefs.put(PREF_USE_MATHJAX,"true");
prefs.put(PREF_IGNORE_EMPTY_PARS,"false");
prefs.put(PREF_IGNORE_HARD_BREAKS,"false");
prefs.put(PREF_LETTER_SPACING,"0.15");
prefs.put(PREF_INLINE_STYLES,"true");
prefs.put(PREF_EMBED_RASTER,"true");
prefs.put(PREF_EMBED_VECTOR,"true");
prefs.put(PREF_CONVERT_TO_PX,"false");
prefs.put(PREF_SCALING, SCALING_DEFAULT_VALUE);
prefs.put(PREF_PAGEBREAK_STYLES,DEFAULT_PAGEBREAK_STYLE_SETTINGS);
prefs.put(PREF_PAGINATION,"true");
prefs.put(PREF_TYPE,EPUB);
prefs.setDefault(true);
tabs.put(EPUB, prefs);
return prefs;
}
private void initializeDefaultRDF() {
UIPreferences prefs = new UIPreferences(this);
add(PREF_PUBLICATION_TYPES, new String[]{"elenphArticle", "encArticle", "book", "journal"} , prefs);
add(PREF_RESOLUTIONS, new String[]{"0","72","150","300","600","1200","2400"} , prefs);
add(PREF_DEFAULT_IMAGE_RESOLUTION,"2", prefs);
add(PREF_DEFAULT_PUBLICATION_TYPE,"0", prefs);
add(PREF_USE_MATHJAX,"true", prefs);
add(PREF_IGNORE_EMPTY_PARS,"false", prefs);
add(PREF_IGNORE_HARD_BREAKS,"false", prefs);
add(PREF_LETTER_SPACING,"0.15",prefs);
add(PREF_INLINE_STYLES,"true", prefs);
add(PREF_EMBED_RASTER,"true", prefs);
add(PREF_EMBED_VECTOR,"true", prefs);
add(PREF_CONVERT_TO_PX,"false", prefs);
add(PREF_PAGEBREAK_STYLES,DEFAULT_PAGEBREAK_STYLE_SETTINGS,prefs);
add(PREF_TYPE,RDF,prefs);
add(PREF_SCALING, SCALING_DEFAULT_VALUE, prefs);
add(PREF_PAGINATION,"true",prefs);
public static UIPreferences getDefaultRDF(PreferencesStorage store) {
UIPreferences prefs = new UIPreferences(store);
prefs.put(PREF_PUBLICATION_TYPES, new String[]{"elenphArticle", "encArticle", "book", "journal"} );
prefs.put(PREF_RESOLUTIONS, new String[]{"0","72","150","300","600","1200","2400"} );
prefs.put(PREF_DEFAULT_IMAGE_RESOLUTION,"2");
prefs.put(PREF_DEFAULT_PUBLICATION_TYPE,"0");
prefs.put(PREF_USE_MATHJAX,"true");
prefs.put(PREF_IGNORE_EMPTY_PARS,"false");
prefs.put(PREF_IGNORE_HARD_BREAKS,"false");
prefs.put(PREF_LETTER_SPACING,"0.15");
prefs.put(PREF_INLINE_STYLES,"true");
prefs.put(PREF_EMBED_RASTER,"true");
prefs.put(PREF_EMBED_VECTOR,"true");
prefs.put(PREF_CONVERT_TO_PX,"false");
prefs.put(PREF_PAGEBREAK_STYLES,DEFAULT_PAGEBREAK_STYLE_SETTINGS);
prefs.put(PREF_TYPE,RDF);
prefs.put(PREF_SCALING, SCALING_DEFAULT_VALUE);
prefs.put(PREF_PAGINATION,"true");
prefs.setDefault(true);
tabs.put(RDF, prefs);
return prefs;
}
public void put(String prefName, UIPreferences newPreferences) {

View file

@ -14,7 +14,6 @@ import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JTextField;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -54,6 +53,11 @@ public class UIPreferences {
prefs.put(name, values);
}
public void put(String name, String value) {
prefs.put(name, new String[] {value});
}
public String getSourceFileName() {
return sourceFileName;
}
@ -75,6 +79,10 @@ public class UIPreferences {
logger.error("Tab preferences doesn't have type!");
return new String[] {""};
}
if (storage == null) {
logger.error("Storage is null");
return new String[] {""};
}
UIPreferences defaultPreferences = storage.get(type[0]);
return defaultPreferences.getAll(name);
}