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.JButton;
import javax.swing.JCheckBox; import javax.swing.JCheckBox;
import javax.swing.JComboBox; import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.GroupLayout.Alignment; import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement; import javax.swing.LayoutStyle.ComponentPlacement;
import static pro.litvinovg.w2phtml.gui.Contstants.*; import static pro.litvinovg.w2phtml.gui.Contstants.*;
public class HTMLPanel extends BasePanel{ public class HTMLPanel extends BasePanel{
/**
*
*/
private static final long serialVersionUID = 1L; 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) { public HTMLPanel(HashMap<String, Component> configuration, Localizer localizer, UIPreferences preferences) {
super(localizer, configuration, preferences); super(localizer, configuration, preferences);

View file

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

View file

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