1 package osm.jp.gpx.matchtime.gui;
3 import java.awt.event.ActionEvent;
4 import java.awt.event.ActionListener;
5 import javax.swing.JButton;
6 import javax.swing.JFileChooser;
8 @SuppressWarnings("serial")
9 public class ParameterPanelImageFile extends ParameterPanel implements ActionListener {
12 ParameterPanelFolder paramDir;
14 @SuppressWarnings("OverridableMethodCallInConstructor")
15 public ParameterPanelImageFile(String label, String text, ParameterPanelFolder paramDir) {
19 openButton = new JButton(i18n.getString("button.select"));
22 openButton.addActionListener(this);
27 //Create a file chooser
28 this.paramDir = paramDir;
31 @SuppressWarnings("override")
32 public void actionPerformed(ActionEvent e) {
34 //Set up the file chooser.
35 File sdir = new File(paramDir.getText());
36 System.out.println(sdir.toPath());
37 if (sdir.isDirectory()) {
38 fc = new JFileChooser(sdir);
41 fc = new JFileChooser();
44 //Add a custom file filter and disable the default
45 //(Accept All) file filter.
46 fc.addChoosableFileFilter(new ImageFilter());
47 fc.setAcceptAllFileFilterUsed(false);
49 //Add custom icons for file types.
50 fc.setFileView(new ImageFileView());
52 //Add the preview pane.
53 fc.setAccessory(new ImagePreview(fc));
56 int returnVal = fc.showDialog(ParameterPanelImageFile.this, "選択");
58 //Process the results.
59 if (returnVal == JFileChooser.APPROVE_OPTION) {
60 File file = fc.getSelectedFile();
61 this.argField.setText(file.getName());
64 //Reset the file chooser for the next time it's shown.
65 fc.setSelectedFile(null);