Added file chooser
This commit is contained in:
parent
87373b3769
commit
52635b6de6
3 changed files with 114 additions and 47 deletions
|
@ -15,6 +15,7 @@ import java.awt.Toolkit;
|
||||||
import java.awt.GridLayout;
|
import java.awt.GridLayout;
|
||||||
import javax.swing.JTabbedPane;
|
import javax.swing.JTabbedPane;
|
||||||
import javax.swing.JMenuBar;
|
import javax.swing.JMenuBar;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JMenu;
|
import javax.swing.JMenu;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
|
@ -28,6 +29,7 @@ import javax.swing.LayoutStyle.ComponentPlacement;
|
||||||
import javax.swing.JRadioButton;
|
import javax.swing.JRadioButton;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.io.File;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -382,7 +384,7 @@ public class ConfigurationWindow extends JFrame {
|
||||||
JCheckBox cb_convertToPx = new JCheckBox("Convert dimensions to pixels instead of REM (root em)");
|
JCheckBox cb_convertToPx = new JCheckBox("Convert dimensions to pixels instead of REM (root em)");
|
||||||
configuration.put("convert_to_px", cb_convertToPx);
|
configuration.put("convert_to_px", cb_convertToPx);
|
||||||
|
|
||||||
JLabel lb_FilePath = new JLabel("File path");
|
JLabel lb_FilePath = new JLabel("Input file path");
|
||||||
|
|
||||||
JTextField tf_inputFile = new JTextField(fileName);
|
JTextField tf_inputFile = new JTextField(fileName);
|
||||||
tf_inputFile.setColumns(10);
|
tf_inputFile.setColumns(10);
|
||||||
|
@ -391,52 +393,60 @@ public class ConfigurationWindow extends JFrame {
|
||||||
|
|
||||||
JLabel lb_TargetFormat = new JLabel("html5");
|
JLabel lb_TargetFormat = new JLabel("html5");
|
||||||
configuration.put("targetFormat", lb_TargetFormat);
|
configuration.put("targetFormat", lb_TargetFormat);
|
||||||
|
|
||||||
|
|
||||||
JLabel lb_TargetFormat_description = new JLabel("Target format");
|
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);
|
GroupLayout gl_panel_configHTML = new GroupLayout(panel_configHTML);
|
||||||
gl_panel_configHTML.setHorizontalGroup(
|
gl_panel_configHTML.setHorizontalGroup(
|
||||||
gl_panel_configHTML.createParallelGroup(Alignment.LEADING)
|
gl_panel_configHTML.createParallelGroup(Alignment.LEADING)
|
||||||
.addGroup(gl_panel_configHTML.createSequentialGroup()
|
.addGroup(gl_panel_configHTML.createSequentialGroup()
|
||||||
.addGap(32)
|
.addGap(32)
|
||||||
.addGroup(gl_panel_configHTML.createParallelGroup(Alignment.LEADING)
|
.addGroup(gl_panel_configHTML.createParallelGroup(Alignment.LEADING)
|
||||||
|
.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, 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_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)
|
||||||
|
.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)
|
||||||
.addGroup(gl_panel_configHTML.createSequentialGroup()
|
.addGroup(gl_panel_configHTML.createSequentialGroup()
|
||||||
.addComponent(lb_TargetFormat_description, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)
|
.addComponent(lb_TargetFormat_description, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)
|
||||||
.addPreferredGap(ComponentPlacement.UNRELATED)
|
.addPreferredGap(ComponentPlacement.UNRELATED)
|
||||||
.addComponent(lb_TargetFormat, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)
|
.addComponent(lb_TargetFormat, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE))
|
||||||
.addContainerGap())
|
|
||||||
.addGroup(gl_panel_configHTML.createSequentialGroup()
|
.addGroup(gl_panel_configHTML.createSequentialGroup()
|
||||||
.addGroup(gl_panel_configHTML.createParallelGroup(Alignment.LEADING)
|
.addComponent(lb_FilePath, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)
|
||||||
.addGroup(gl_panel_configHTML.createSequentialGroup()
|
.addPreferredGap(ComponentPlacement.RELATED)
|
||||||
.addComponent(lb_FilePath, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)
|
.addComponent(tf_inputFile, GroupLayout.PREFERRED_SIZE, 616, GroupLayout.PREFERRED_SIZE)
|
||||||
.addGap(18)
|
.addPreferredGap(ComponentPlacement.UNRELATED)
|
||||||
.addComponent(tf_inputFile, GroupLayout.DEFAULT_SIZE, 755, Short.MAX_VALUE))
|
.addComponent(btnChooseFile)))
|
||||||
.addComponent(cb_UseMathJax, GroupLayout.PREFERRED_SIZE, 303, GroupLayout.PREFERRED_SIZE)
|
.addContainerGap(68, 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_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, 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_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)
|
|
||||||
.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))))
|
|
||||||
);
|
);
|
||||||
gl_panel_configHTML.setVerticalGroup(
|
gl_panel_configHTML.setVerticalGroup(
|
||||||
gl_panel_configHTML.createParallelGroup(Alignment.LEADING)
|
gl_panel_configHTML.createParallelGroup(Alignment.LEADING)
|
||||||
|
@ -445,13 +455,16 @@ public class ConfigurationWindow extends JFrame {
|
||||||
.addGroup(gl_panel_configHTML.createParallelGroup(Alignment.BASELINE)
|
.addGroup(gl_panel_configHTML.createParallelGroup(Alignment.BASELINE)
|
||||||
.addComponent(lb_TargetFormat_description)
|
.addComponent(lb_TargetFormat_description)
|
||||||
.addComponent(lb_TargetFormat))
|
.addComponent(lb_TargetFormat))
|
||||||
.addGap(22)
|
|
||||||
.addGroup(gl_panel_configHTML.createParallelGroup(Alignment.LEADING)
|
.addGroup(gl_panel_configHTML.createParallelGroup(Alignment.LEADING)
|
||||||
.addGroup(gl_panel_configHTML.createSequentialGroup()
|
.addGroup(gl_panel_configHTML.createSequentialGroup()
|
||||||
.addGap(2)
|
.addGap(24)
|
||||||
.addComponent(lb_FilePath))
|
.addComponent(lb_FilePath))
|
||||||
.addComponent(tf_inputFile, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
.addGroup(gl_panel_configHTML.createSequentialGroup()
|
||||||
.addPreferredGap(ComponentPlacement.RELATED)
|
.addGap(22)
|
||||||
|
.addGroup(gl_panel_configHTML.createParallelGroup(Alignment.BASELINE)
|
||||||
|
.addComponent(tf_inputFile, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
|
||||||
|
.addComponent(btnChooseFile))))
|
||||||
|
.addGap(46)
|
||||||
.addGroup(gl_panel_configHTML.createParallelGroup(Alignment.LEADING)
|
.addGroup(gl_panel_configHTML.createParallelGroup(Alignment.LEADING)
|
||||||
.addGroup(gl_panel_configHTML.createSequentialGroup()
|
.addGroup(gl_panel_configHTML.createSequentialGroup()
|
||||||
.addGap(2)
|
.addGap(2)
|
||||||
|
@ -494,7 +507,7 @@ public class ConfigurationWindow extends JFrame {
|
||||||
.addComponent(cb_SplitWholePagesOnly)
|
.addComponent(cb_SplitWholePagesOnly)
|
||||||
.addPreferredGap(ComponentPlacement.UNRELATED)
|
.addPreferredGap(ComponentPlacement.UNRELATED)
|
||||||
.addComponent(cb_UseMathJax)
|
.addComponent(cb_UseMathJax)
|
||||||
.addContainerGap(274, Short.MAX_VALUE))
|
.addContainerGap(282, Short.MAX_VALUE))
|
||||||
);
|
);
|
||||||
panel_configHTML.setLayout(gl_panel_configHTML);
|
panel_configHTML.setLayout(gl_panel_configHTML);
|
||||||
return panel_configHTML;
|
return panel_configHTML;
|
||||||
|
@ -657,21 +670,28 @@ public class ConfigurationWindow extends JFrame {
|
||||||
});
|
});
|
||||||
|
|
||||||
JButton btn_SaveAs = new JButton("Save As");
|
JButton btn_SaveAs = new JButton("Save As");
|
||||||
|
btn_SaveAs.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
JOptionPane.showMessageDialog(singleFrame, "Not implemented, yet.");
|
||||||
|
}
|
||||||
|
});
|
||||||
JButton btn_Save = new JButton("Save");
|
JButton btn_Save = new JButton("Save");
|
||||||
|
btn_Save.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
JOptionPane.showMessageDialog(singleFrame, "Not implemented, yet.");
|
||||||
|
}
|
||||||
|
});
|
||||||
JButton btn_Convert = new JButton("Convert");
|
JButton btn_Convert = new JButton("Convert");
|
||||||
btn_Convert.addActionListener(new ActionListener() {
|
btn_Convert.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent actionEvent) {
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
try {
|
try {
|
||||||
ConfigurationReader reader = new ConfigurationReader(configuration, context);
|
ConfigurationReader reader = new ConfigurationReader(configuration, context);
|
||||||
Application.main(reader.getCommandLine());
|
Application.main(reader.getCommandLine());
|
||||||
Debug.printLog("Finish", context);
|
JOptionPane.showMessageDialog(singleFrame, "Conversion completed.");
|
||||||
|
|
||||||
} catch(Throwable e) {
|
} catch(Throwable e) {
|
||||||
StringWriter errors = new StringWriter();
|
StringWriter errors = new StringWriter();
|
||||||
e.printStackTrace(new PrintWriter(errors));
|
e.printStackTrace(new PrintWriter(errors));
|
||||||
Debug.printLog(errors.toString(), context);
|
JOptionPane.showMessageDialog(singleFrame,errors.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -723,7 +743,7 @@ public class ConfigurationWindow extends JFrame {
|
||||||
try {
|
try {
|
||||||
ConfigurationWindow frame = new ConfigurationWindow(context,doc);
|
ConfigurationWindow frame = new ConfigurationWindow(context,doc);
|
||||||
singleFrame = frame;
|
singleFrame = frame;
|
||||||
frame.setBounds(100, 100, 800, 800);
|
frame.setBounds(100, 100, 1100, 800);
|
||||||
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
|
|
||||||
|
|
47
src/main/java/pro/litvinovg/w2phtml/gui/FileDialog.java
Normal file
47
src/main/java/pro/litvinovg/w2phtml/gui/FileDialog.java
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
package pro.litvinovg.w2phtml.gui;
|
||||||
|
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.io.File;
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||||
|
public class FileDialog extends JFrame {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public static String chooseFile(String lastPath){
|
||||||
|
File selected = null;
|
||||||
|
File currentDirectory = null;
|
||||||
|
if (lastPath != null && !lastPath.isEmpty()) {
|
||||||
|
File preselected = new File(lastPath);
|
||||||
|
if (preselected.exists()) {
|
||||||
|
if (preselected.isFile()) {
|
||||||
|
currentDirectory = preselected.getParentFile();
|
||||||
|
} else if (preselected.isDirectory()) {
|
||||||
|
currentDirectory = preselected;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (currentDirectory == null) {
|
||||||
|
currentDirectory = new File(System.getProperty("user.home"));
|
||||||
|
}
|
||||||
|
JFileChooser fileChooser = new JFileChooser();
|
||||||
|
fileChooser.setPreferredSize(new Dimension(800,600));
|
||||||
|
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
|
||||||
|
FileNameExtensionFilter filter = new FileNameExtensionFilter("ODT", "odt");
|
||||||
|
fileChooser.setFileFilter(filter);
|
||||||
|
fileChooser.setCurrentDirectory(currentDirectory);
|
||||||
|
int result = fileChooser.showOpenDialog(null);
|
||||||
|
if (result == fileChooser.APPROVE_OPTION){
|
||||||
|
selected = fileChooser.getSelectedFile();
|
||||||
|
return selected.getAbsolutePath();
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Binary file not shown.
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 6 KiB |
Loading…
Add table
Reference in a new issue