From 9ec64419a41fdf1d4cb13a578792456271bdda7c Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Mon, 3 Aug 2020 20:35:02 +0200 Subject: [PATCH] File chooser for other panels --- .../w2phtml/gui/ConfigurationWindow.java | 139 ++++++++++-------- 1 file changed, 81 insertions(+), 58 deletions(-) diff --git a/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationWindow.java b/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationWindow.java index 9eaa7f5..6991d80 100644 --- a/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationWindow.java +++ b/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationWindow.java @@ -235,42 +235,50 @@ public class ConfigurationWindow extends JFrame { JLabel lb_TargetFormat_description = new JLabel("Target format"); + + JButton btnChooseFile = new JButton("Choose file"); + btnChooseFile.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + FileDialog fileDialog = new FileDialog(); + String newFilePath = fileDialog.chooseFile(tf_inputFile.getText()); + if (newFilePath != null && !newFilePath.isEmpty()) { + tf_inputFile.setText(newFilePath); + } + } + }); GroupLayout gl_panel_configHTML = new GroupLayout(panel_configHTML); gl_panel_configHTML.setHorizontalGroup( gl_panel_configHTML.createParallelGroup(Alignment.LEADING) .addGroup(gl_panel_configHTML.createSequentialGroup() .addGap(32) .addGroup(gl_panel_configHTML.createParallelGroup(Alignment.LEADING) + .addComponent(cb_UseMathJax, GroupLayout.PREFERRED_SIZE, 303, GroupLayout.PREFERRED_SIZE) .addGroup(gl_panel_configHTML.createSequentialGroup() - .addComponent(cb_UseMathJax, GroupLayout.PREFERRED_SIZE, 303, GroupLayout.PREFERRED_SIZE) - .addContainerGap()) + .addComponent(lb_TargetFormat_description, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(ComponentPlacement.UNRELATED) + .addComponent(lb_TargetFormat, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)) .addGroup(gl_panel_configHTML.createParallelGroup(Alignment.LEADING) .addGroup(gl_panel_configHTML.createSequentialGroup() - .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()) + .addComponent(lb_FilePath, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE) + .addGap(18) + .addComponent(tf_inputFile, GroupLayout.PREFERRED_SIZE, 604, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(ComponentPlacement.RELATED) + .addComponent(btnChooseFile, GroupLayout.PREFERRED_SIZE, 113, GroupLayout.PREFERRED_SIZE)) .addGroup(gl_panel_configHTML.createSequentialGroup() - .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_inputFile, GroupLayout.DEFAULT_SIZE, 755, Short.MAX_VALUE)) - .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_FilterLetterSpacing, GroupLayout.PREFERRED_SIZE, 253, GroupLayout.PREFERRED_SIZE) - .addGap(18) - .addComponent(tf_FilterLetterSpacing, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE)) - .addComponent(cb_convertToPx, 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_EmbedRaster, GroupLayout.PREFERRED_SIZE, 194, GroupLayout.PREFERRED_SIZE) - .addComponent(cb_EmbedVectorImages, GroupLayout.PREFERRED_SIZE, 214, GroupLayout.PREFERRED_SIZE) - .addComponent(cb_InlineStyles, GroupLayout.PREFERRED_SIZE, 156, GroupLayout.PREFERRED_SIZE)) - .addGap(48))))) + .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_FilterLetterSpacing, GroupLayout.PREFERRED_SIZE, 253, GroupLayout.PREFERRED_SIZE) + .addGap(18) + .addComponent(tf_FilterLetterSpacing, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE)) + .addComponent(cb_convertToPx, 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_EmbedRaster, GroupLayout.PREFERRED_SIZE, 194, GroupLayout.PREFERRED_SIZE) + .addComponent(cb_EmbedVectorImages, GroupLayout.PREFERRED_SIZE, 214, GroupLayout.PREFERRED_SIZE) + .addComponent(cb_InlineStyles, GroupLayout.PREFERRED_SIZE, 156, GroupLayout.PREFERRED_SIZE))) + .addContainerGap(80, Short.MAX_VALUE)) ); gl_panel_configHTML.setVerticalGroup( gl_panel_configHTML.createParallelGroup(Alignment.LEADING) @@ -279,12 +287,15 @@ public class ConfigurationWindow extends JFrame { .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(2) + .addGap(24) .addComponent(lb_FilePath)) - .addComponent(tf_inputFile, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addGroup(gl_panel_configHTML.createSequentialGroup() + .addGap(22) + .addGroup(gl_panel_configHTML.createParallelGroup(Alignment.BASELINE) + .addComponent(tf_inputFile, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(btnChooseFile)))) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(gl_panel_configHTML.createParallelGroup(Alignment.LEADING) .addGroup(gl_panel_configHTML.createSequentialGroup() @@ -573,42 +584,50 @@ public class ConfigurationWindow extends JFrame { JLabel lb_TargetFormat_description = new JLabel("Target format"); + + JButton btnChooseFile = new JButton("Choose file"); + btnChooseFile.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + FileDialog fileDialog = new FileDialog(); + String newFilePath = fileDialog.chooseFile(tf_inputFile.getText()); + if (newFilePath != null && !newFilePath.isEmpty()) { + tf_inputFile.setText(newFilePath); + } + } + }); GroupLayout gl_panel_configHTML = new GroupLayout(panel_configHTML); gl_panel_configHTML.setHorizontalGroup( gl_panel_configHTML.createParallelGroup(Alignment.LEADING) .addGroup(gl_panel_configHTML.createSequentialGroup() .addGap(32) .addGroup(gl_panel_configHTML.createParallelGroup(Alignment.LEADING) + .addComponent(cb_UseMathJax, GroupLayout.PREFERRED_SIZE, 303, GroupLayout.PREFERRED_SIZE) .addGroup(gl_panel_configHTML.createSequentialGroup() - .addComponent(cb_UseMathJax, GroupLayout.PREFERRED_SIZE, 303, GroupLayout.PREFERRED_SIZE) - .addContainerGap()) + .addComponent(lb_TargetFormat_description, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(ComponentPlacement.UNRELATED) + .addComponent(lb_TargetFormat, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)) .addGroup(gl_panel_configHTML.createParallelGroup(Alignment.LEADING) .addGroup(gl_panel_configHTML.createSequentialGroup() - .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()) + .addComponent(lb_FilePath, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE) + .addGap(18) + .addComponent(tf_inputFile, GroupLayout.PREFERRED_SIZE, 614, GroupLayout.PREFERRED_SIZE) + .addGap(6) + .addComponent(btnChooseFile, GroupLayout.PREFERRED_SIZE, 113, GroupLayout.PREFERRED_SIZE)) .addGroup(gl_panel_configHTML.createSequentialGroup() - .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_inputFile, GroupLayout.DEFAULT_SIZE, 755, Short.MAX_VALUE)) - .addGroup(gl_panel_configHTML.createSequentialGroup() - .addComponent(lb_Scale, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE) - .addGap(18) - .addComponent(tf_Scale, GroupLayout.PREFERRED_SIZE, 98, 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, 58, GroupLayout.PREFERRED_SIZE)) - .addComponent(cb_convertToPx, 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_EmbedRaster, GroupLayout.PREFERRED_SIZE, 194, GroupLayout.PREFERRED_SIZE) - .addComponent(cb_EmbedVectorImages, GroupLayout.PREFERRED_SIZE, 214, GroupLayout.PREFERRED_SIZE) - .addComponent(cb_InlineStyles, GroupLayout.PREFERRED_SIZE, 156, GroupLayout.PREFERRED_SIZE)) - .addGap(48))))) + .addComponent(lb_Scale, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE) + .addGap(18) + .addComponent(tf_Scale, GroupLayout.PREFERRED_SIZE, 98, 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, 58, GroupLayout.PREFERRED_SIZE)) + .addComponent(cb_convertToPx, 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_EmbedRaster, GroupLayout.PREFERRED_SIZE, 194, GroupLayout.PREFERRED_SIZE) + .addComponent(cb_EmbedVectorImages, GroupLayout.PREFERRED_SIZE, 214, GroupLayout.PREFERRED_SIZE) + .addComponent(cb_InlineStyles, GroupLayout.PREFERRED_SIZE, 156, GroupLayout.PREFERRED_SIZE))) + .addContainerGap(97, Short.MAX_VALUE)) ); gl_panel_configHTML.setVerticalGroup( gl_panel_configHTML.createParallelGroup(Alignment.LEADING) @@ -617,12 +636,16 @@ public class ConfigurationWindow extends JFrame { .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(2) + .addGap(24) .addComponent(lb_FilePath)) - .addComponent(tf_inputFile, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addGroup(gl_panel_configHTML.createSequentialGroup() + .addGap(22) + .addGroup(gl_panel_configHTML.createParallelGroup(Alignment.BASELINE) + .addComponent(tf_inputFile, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(btnChooseFile)))) + .addPreferredGap(ComponentPlacement.RELATED) .addGroup(gl_panel_configHTML.createParallelGroup(Alignment.LEADING) .addGroup(gl_panel_configHTML.createSequentialGroup() .addGap(8)