From 8621834a5b4570b8db0a72e2c8f8dd320c9ba6a6 Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Tue, 10 Aug 2021 14:27:19 +0200 Subject: [PATCH] chore: refactoring --- .../pro/litvinovg/w2phtml/gui/HTMLPanel.java | 14 +- .../w2phtml/gui/PreferencesStorage.java | 122 +++++++++--------- .../litvinovg/w2phtml/gui/UIPreferences.java | 10 +- 3 files changed, 78 insertions(+), 68 deletions(-) diff --git a/src/main/java/pro/litvinovg/w2phtml/gui/HTMLPanel.java b/src/main/java/pro/litvinovg/w2phtml/gui/HTMLPanel.java index 48ebe0f..412c23a 100644 --- a/src/main/java/pro/litvinovg/w2phtml/gui/HTMLPanel.java +++ b/src/main/java/pro/litvinovg/w2phtml/gui/HTMLPanel.java @@ -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 configStub = new HashMap(); + UIPreferences prefStub = PreferencesStorage.getDefaultHTML(null); + Object htmlPanel = new HTMLPanel(configStub,localizerStub,prefStub); + } + public HTMLPanel(HashMap configuration, Localizer localizer, UIPreferences preferences) { super(localizer, configuration, preferences); diff --git a/src/main/java/pro/litvinovg/w2phtml/gui/PreferencesStorage.java b/src/main/java/pro/litvinovg/w2phtml/gui/PreferencesStorage.java index 0744e38..6159f11 100644 --- a/src/main/java/pro/litvinovg/w2phtml/gui/PreferencesStorage.java +++ b/src/main/java/pro/litvinovg/w2phtml/gui/PreferencesStorage.java @@ -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) { diff --git a/src/main/java/pro/litvinovg/w2phtml/gui/UIPreferences.java b/src/main/java/pro/litvinovg/w2phtml/gui/UIPreferences.java index 55be64f..9c7e9f1 100644 --- a/src/main/java/pro/litvinovg/w2phtml/gui/UIPreferences.java +++ b/src/main/java/pro/litvinovg/w2phtml/gui/UIPreferences.java @@ -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); }