diff --git a/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationWindow.java b/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationWindow.java index a0434e1..8ace8f9 100644 --- a/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationWindow.java +++ b/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationWindow.java @@ -5,9 +5,11 @@ import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.UIManager; +import com.github.andrewoma.dexx.collection.Map; import com.sun.star.uno.XComponentContext; import pro.litvinovg.xml.Debug; +import w2phtml.Application; import java.awt.Toolkit; import java.awt.GridLayout; @@ -26,6 +28,8 @@ import javax.swing.LayoutStyle.ComponentPlacement; import javax.swing.JRadioButton; import javax.swing.JButton; import java.awt.event.ActionListener; +import java.util.HashMap; +import java.util.Set; import java.awt.event.ActionEvent; import javax.swing.JSplitPane; import java.awt.BorderLayout; @@ -34,6 +38,8 @@ import javax.swing.BoxLayout; import javax.swing.SpringLayout; import java.awt.FlowLayout; import java.awt.CardLayout; +import java.awt.Component; + import javax.swing.SwingConstants; public class ConfigurationWindow extends JFrame { @@ -101,37 +107,28 @@ public class ConfigurationWindow extends JFrame { private JPanel createEpubPanel() { JPanel panel_epub = new JPanel(); - - JPanel panel_control = createControlPanel(panel_epub); - + HashMap configuration = new HashMap(); + JPanel panel_control = createControlPanel(configuration); JPanel panel_configEpub = createConfigEpubPanel(); - applyDefaultLayout(panel_epub, panel_configEpub, panel_control); - return panel_epub; } private JPanel createRDFPanel() { JPanel panel_rdf = new JPanel(); - - JPanel panel_control = createControlPanel(panel_rdf); - + HashMap configuration = new HashMap(); + JPanel panel_control = createControlPanel(configuration); JPanel panel_configRDF = createConfigRDFPanel(); - applyDefaultLayout2(panel_rdf, panel_configRDF, panel_control); - return panel_rdf; } private JPanel createHTMLPanel() { JPanel panel_html = new JPanel(); - - JPanel panel_configHTML = createConfigHTMLPanel(); - - JPanel panel_control = createControlPanel(panel_configHTML); - + HashMap configuration = new HashMap(); + JPanel panel_configHTML = createConfigHTMLPanel(configuration); + JPanel panel_control = createControlPanel(configuration); applyDefaultLayout3(panel_html, panel_configHTML, panel_control); - return panel_html; } @@ -343,99 +340,129 @@ public class ConfigurationWindow extends JFrame { return panel_configHTML; } - private JPanel createConfigHTMLPanel() { + private JPanel createConfigHTMLPanel(HashMap configuration) { JPanel panel_configHTML = new JPanel(); - JCheckBox cb_UseMathJax = new JCheckBox("Use MathJax"); + configuration.put("useMathJax", cb_UseMathJax); - JCheckBox cb_IgnoreEmptyParagraphs_2 = new JCheckBox("Split on whole pages only"); + JCheckBox cb_SplitWholePagesOnly = new JCheckBox("Split on whole pages only"); + configuration.put("splitWholePagesOnly", cb_SplitWholePagesOnly); JLabel lb_SplitByLevel = new JLabel("Split into multiple files by heading level"); - JTextField tf_SplitByLevel = new JTextField(); + configuration.put("splitByLevel", tf_SplitByLevel); + tf_SplitByLevel.setColumns(10); JCheckBox cb_Greenstone = new JCheckBox("Split document into subsections for Greenstone digital library"); + configuration.put("greenstone", cb_Greenstone); JCheckBox cb_IgnoreEmptyParagraphs = new JCheckBox("Filter empty paragraphs"); + configuration.put("filterEmptyParagraphs", cb_IgnoreEmptyParagraphs); JCheckBox cb_IgnoreHardLineBreaks = new JCheckBox("Filter hard line breaks"); + configuration.put("filterHardLineBreaks", cb_IgnoreHardLineBreaks); JLabel lb_FilterLetterSpacing = new JLabel("Filter letter spacing less than"); JTextField tf_FilterLetterSpacing = new JTextField(); + configuration.put("filterLetterSpacing", tf_FilterLetterSpacing); + tf_FilterLetterSpacing.setColumns(10); JCheckBox cb_InlineStyles = new JCheckBox("Inline styles"); + configuration.put("inlineStyles", cb_InlineStyles); JCheckBox cb_EmbedVectorImages = new JCheckBox("Embed vector images"); + configuration.put("embedVectorImages", cb_EmbedVectorImages); JCheckBox cb_EmbedRaster = new JCheckBox("Embed raster images"); + configuration.put("embedRaster", cb_EmbedRaster); JLabel lb_Scale = new JLabel("Scale"); - JTextField tf_Scale = new JTextField(); + configuration.put("scale", tf_Scale); + tf_Scale.setColumns(10); JLabel lb_MaxWidth = new JLabel("Max body width"); JTextField tf_MaxWidth = new JTextField(); + configuration.put("maxWidth", tf_MaxWidth); + tf_MaxWidth.setColumns(10); JCheckBox cb_ConversionToRem = new JCheckBox("Convert dimensions to REM"); + configuration.put("conversionToRem", cb_ConversionToRem); JLabel lb_FilePath = new JLabel("File path"); tf_FilePath = new JTextField(); tf_FilePath.setColumns(10); + + JLabel lb_TargetFormat = new JLabel("HTML"); + configuration.put("targetFormat", lb_TargetFormat); + + + JLabel lb_TargetFormat_description = new JLabel("Target format"); GroupLayout gl_panel_configHTML = new GroupLayout(panel_configHTML); gl_panel_configHTML.setHorizontalGroup( gl_panel_configHTML.createParallelGroup(Alignment.LEADING) .addGroup(gl_panel_configHTML.createSequentialGroup() - .addGap(40) + .addGap(32) .addGroup(gl_panel_configHTML.createParallelGroup(Alignment.LEADING) .addGroup(gl_panel_configHTML.createSequentialGroup() - .addComponent(lb_FilePath, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE) - .addGap(18) - .addComponent(tf_FilePath, GroupLayout.DEFAULT_SIZE, 755, Short.MAX_VALUE)) - .addComponent(cb_UseMathJax, GroupLayout.PREFERRED_SIZE, 303, GroupLayout.PREFERRED_SIZE) + .addComponent(lb_TargetFormat_description, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(ComponentPlacement.UNRELATED) + .addComponent(lb_TargetFormat, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE) + .addContainerGap()) .addGroup(gl_panel_configHTML.createSequentialGroup() - .addComponent(lb_Scale, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE) - .addGap(18) - .addComponent(tf_Scale, GroupLayout.PREFERRED_SIZE, 175, GroupLayout.PREFERRED_SIZE)) - .addGroup(gl_panel_configHTML.createSequentialGroup() - .addComponent(lb_MaxWidth) - .addGap(18) - .addComponent(tf_MaxWidth, GroupLayout.PREFERRED_SIZE, 175, GroupLayout.PREFERRED_SIZE)) - .addGroup(gl_panel_configHTML.createSequentialGroup() - .addComponent(lb_FilterLetterSpacing, GroupLayout.PREFERRED_SIZE, 253, GroupLayout.PREFERRED_SIZE) - .addGap(18) - .addComponent(tf_FilterLetterSpacing, GroupLayout.PREFERRED_SIZE, 175, GroupLayout.PREFERRED_SIZE)) - .addComponent(cb_InlineStyles, GroupLayout.PREFERRED_SIZE, 592, GroupLayout.PREFERRED_SIZE) - .addComponent(cb_EmbedVectorImages, GroupLayout.PREFERRED_SIZE, 592, GroupLayout.PREFERRED_SIZE) - .addComponent(cb_EmbedRaster, GroupLayout.PREFERRED_SIZE, 592, GroupLayout.PREFERRED_SIZE) - .addComponent(cb_ConversionToRem, GroupLayout.PREFERRED_SIZE, 592, GroupLayout.PREFERRED_SIZE) - .addComponent(cb_IgnoreHardLineBreaks, GroupLayout.PREFERRED_SIZE, 303, GroupLayout.PREFERRED_SIZE) - .addComponent(cb_IgnoreEmptyParagraphs, GroupLayout.PREFERRED_SIZE, 303, GroupLayout.PREFERRED_SIZE) - .addComponent(cb_Greenstone, GroupLayout.PREFERRED_SIZE, 482, GroupLayout.PREFERRED_SIZE) - .addGroup(gl_panel_configHTML.createSequentialGroup() - .addComponent(lb_SplitByLevel, GroupLayout.PREFERRED_SIZE, 295, GroupLayout.PREFERRED_SIZE) - .addGap(42) - .addComponent(tf_SplitByLevel, GroupLayout.PREFERRED_SIZE, 175, GroupLayout.PREFERRED_SIZE)) - .addComponent(cb_IgnoreEmptyParagraphs_2, GroupLayout.PREFERRED_SIZE, 303, GroupLayout.PREFERRED_SIZE)) - .addGap(40)) + .addGroup(gl_panel_configHTML.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel_configHTML.createSequentialGroup() + .addComponent(lb_FilePath, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE) + .addGap(18) + .addComponent(tf_FilePath, GroupLayout.DEFAULT_SIZE, 755, Short.MAX_VALUE)) + .addComponent(cb_UseMathJax, GroupLayout.PREFERRED_SIZE, 303, GroupLayout.PREFERRED_SIZE) + .addGroup(gl_panel_configHTML.createSequentialGroup() + .addComponent(lb_Scale, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE) + .addGap(18) + .addComponent(tf_Scale, GroupLayout.PREFERRED_SIZE, 175, GroupLayout.PREFERRED_SIZE)) + .addGroup(gl_panel_configHTML.createSequentialGroup() + .addComponent(lb_MaxWidth) + .addGap(18) + .addComponent(tf_MaxWidth, GroupLayout.PREFERRED_SIZE, 175, GroupLayout.PREFERRED_SIZE)) + .addGroup(gl_panel_configHTML.createSequentialGroup() + .addComponent(lb_FilterLetterSpacing, GroupLayout.PREFERRED_SIZE, 253, GroupLayout.PREFERRED_SIZE) + .addGap(18) + .addComponent(tf_FilterLetterSpacing, GroupLayout.PREFERRED_SIZE, 175, GroupLayout.PREFERRED_SIZE)) + .addComponent(cb_InlineStyles, GroupLayout.PREFERRED_SIZE, 592, GroupLayout.PREFERRED_SIZE) + .addComponent(cb_EmbedVectorImages, GroupLayout.PREFERRED_SIZE, 592, GroupLayout.PREFERRED_SIZE) + .addComponent(cb_EmbedRaster, GroupLayout.PREFERRED_SIZE, 592, GroupLayout.PREFERRED_SIZE) + .addComponent(cb_ConversionToRem, GroupLayout.PREFERRED_SIZE, 592, GroupLayout.PREFERRED_SIZE) + .addComponent(cb_IgnoreHardLineBreaks, GroupLayout.PREFERRED_SIZE, 303, GroupLayout.PREFERRED_SIZE) + .addComponent(cb_IgnoreEmptyParagraphs, GroupLayout.PREFERRED_SIZE, 303, GroupLayout.PREFERRED_SIZE) + .addComponent(cb_Greenstone, GroupLayout.PREFERRED_SIZE, 482, GroupLayout.PREFERRED_SIZE) + .addGroup(gl_panel_configHTML.createSequentialGroup() + .addComponent(lb_SplitByLevel, GroupLayout.PREFERRED_SIZE, 295, GroupLayout.PREFERRED_SIZE) + .addGap(42) + .addComponent(tf_SplitByLevel, GroupLayout.PREFERRED_SIZE, 175, GroupLayout.PREFERRED_SIZE)) + .addComponent(cb_SplitWholePagesOnly, GroupLayout.PREFERRED_SIZE, 303, GroupLayout.PREFERRED_SIZE)) + .addGap(48)))) ); gl_panel_configHTML.setVerticalGroup( gl_panel_configHTML.createParallelGroup(Alignment.LEADING) .addGroup(gl_panel_configHTML.createSequentialGroup() + .addContainerGap() + .addGroup(gl_panel_configHTML.createParallelGroup(Alignment.BASELINE) + .addComponent(lb_TargetFormat_description) + .addComponent(lb_TargetFormat)) + .addGap(22) .addGroup(gl_panel_configHTML.createParallelGroup(Alignment.LEADING) .addGroup(gl_panel_configHTML.createSequentialGroup() - .addGap(17) + .addGap(2) .addComponent(lb_FilePath)) - .addGroup(gl_panel_configHTML.createSequentialGroup() - .addGap(15) - .addComponent(tf_FilePath, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))) + .addComponent(tf_FilePath, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(gl_panel_configHTML.createParallelGroup(Alignment.LEADING) .addGroup(gl_panel_configHTML.createSequentialGroup() @@ -475,16 +502,16 @@ public class ConfigurationWindow extends JFrame { .addGap(2) .addComponent(lb_SplitByLevel))) .addPreferredGap(ComponentPlacement.RELATED) - .addComponent(cb_IgnoreEmptyParagraphs_2) + .addComponent(cb_SplitWholePagesOnly) .addPreferredGap(ComponentPlacement.UNRELATED) .addComponent(cb_UseMathJax) - .addContainerGap(364, Short.MAX_VALUE)) + .addContainerGap(274, Short.MAX_VALUE)) ); panel_configHTML.setLayout(gl_panel_configHTML); return panel_configHTML; } - private JPanel createControlPanel(JPanel configurationPanel) { + private JPanel createControlPanel(HashMap configuration) { JPanel controlPanel = new JPanel(); JButton btn_Exit = new JButton("Exit"); @@ -500,6 +527,13 @@ public class ConfigurationWindow extends JFrame { JButton btn_Save = new JButton("Save"); JButton btn_Convert = new JButton("Convert"); + btn_Convert.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ConfigurationReader reader = new ConfigurationReader(configuration, context); + //Application.main(reader.getCommandLine()); + } + + }); GroupLayout gl_panel_control = new GroupLayout(controlPanel); gl_panel_control.setHorizontalGroup(