1 package osm.jp.gpx.matchtime.gui;
3 import java.awt.event.ActionEvent;
5 import java.io.FileNotFoundException;
6 import javax.swing.JButton;
7 import javax.swing.JFileChooser;
9 @SuppressWarnings("serial")
10 public class ParameterPanelImageFile extends ParameterPanel {
12 public JButton openButton;
13 public ParameterPanelFolder paramDir;
15 @SuppressWarnings("OverridableMethodCallInConstructor")
16 public ParameterPanelImageFile(
17 String label, String text,
18 ParameterPanelFolder paramDir
23 SelectButtonAction buttonAction = new SelectButtonAction();
24 openButton = new JButton(i18n.getString("button.select"));
25 openButton.addActionListener(buttonAction);
28 //Create a file chooser
29 this.paramDir = paramDir;
32 class SelectButtonAction implements java.awt.event.ActionListener
34 @SuppressWarnings("override")
35 public void actionPerformed(ActionEvent e) {
36 //Set up the file chooser.
37 File sdir = new File(paramDir.getText());
38 System.out.println(sdir.toPath());
39 if (sdir.isDirectory()) {
40 fc = new JFileChooser(sdir);
43 fc = new JFileChooser();
46 //Add a custom file filter and disable the default
47 //(Accept All) file filter.
48 fc.addChoosableFileFilter(new ImageFilter());
49 fc.setAcceptAllFileFilterUsed(false);
51 //Add custom icons for file types.
52 fc.setFileView(new ImageFileView());
54 //Add the preview pane.
55 fc.setAccessory(new ImagePreview(fc));
58 int returnVal = fc.showDialog(ParameterPanelImageFile.this, "選択");
60 //Process the results.
61 if (returnVal == JFileChooser.APPROVE_OPTION) {
62 File file = fc.getSelectedFile();
63 argField.setText(file.getName());
66 //Reset the file chooser for the next time it's shown.
67 fc.setSelectedFile(null);
76 public boolean isEnable() {
77 if (this.paramDir.isEnable()) {
78 String text = this.argField.getText();
81 File dir = this.paramDir.getDirectory(text);
82 File file = new File(dir, text);
83 if (file.exists() && file.isFile()) {
84 String name = file.getName().toUpperCase();
85 if (name.endsWith(".JPG") || name.endsWith(".JPEG")) {
90 catch (FileNotFoundException e) {