OSDN Git Service

step by step
[importpicture/importpicture.git] / src / osm / jp / gpx / matchtime / gui / ParameterPanelImageFile.java
1 package osm.jp.gpx.matchtime.gui;
2
3 import java.awt.event.ActionEvent;
4 import java.io.File;
5 import javax.swing.JButton;
6 import javax.swing.JFileChooser;
7
8 @SuppressWarnings("serial")
9 public class ParameterPanelImageFile extends ParameterPanel {
10     JFileChooser fc;
11     public JButton openButton;
12     public ParameterPanelFolder paramDir;
13
14     @SuppressWarnings("OverridableMethodCallInConstructor")
15     public ParameterPanelImageFile(String label, String text, ParameterPanelFolder paramDir) {
16         super(label, text);
17
18         // "選択..."
19         openButton = new JButton(i18n.getString("button.select"));
20         openButton.addActionListener(this);
21         this.add(openButton);
22         
23         //Create a file chooser
24         this.paramDir = paramDir;
25     }
26
27     @SuppressWarnings("override")
28     public void actionPerformed(ActionEvent e) {
29         //Set up the file chooser.
30         File sdir = new File(paramDir.getText());
31         System.out.println(sdir.toPath());
32         if (sdir.isDirectory()) {
33             fc = new JFileChooser(sdir);
34         }
35         else {
36             fc = new JFileChooser();
37         }
38
39         //Add a custom file filter and disable the default
40         //(Accept All) file filter.
41         fc.addChoosableFileFilter(new ImageFilter());
42         fc.setAcceptAllFileFilterUsed(false);
43
44         //Add custom icons for file types.
45         fc.setFileView(new ImageFileView());
46
47         //Add the preview pane.
48         fc.setAccessory(new ImagePreview(fc));
49
50         //Show it.
51         int returnVal = fc.showDialog(ParameterPanelImageFile.this, "選択");
52
53         //Process the results.
54         if (returnVal == JFileChooser.APPROVE_OPTION) {
55             File file = fc.getSelectedFile();
56             this.argField.setText(file.getName());
57         }
58
59         //Reset the file chooser for the next time it's shown.
60         fc.setSelectedFile(null);
61     }
62
63     /**
64      * 
65      * @return 
66      */
67     @Override
68     public boolean isEnable() {
69         throw new UnsupportedOperationException("Not supported yet.");
70     }
71 }