Revision 1987 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/pickercontroller/FilePickerControllerImpl.java

View differences:

FilePickerControllerImpl.java
29 29
 *
30 30
 * @author jjdelcerro
31 31
 */
32
public class FilePickerControllerImpl 
33
        extends AbstractPickerController<File> 
34
        implements FilePickerController 
35
    {
36
    
32
public class FilePickerControllerImpl
33
        extends AbstractPickerController<File>
34
        implements FilePickerController {
35

  
37 36
    private final JButton btnFile;
38 37
    private final JTextField txtFile;
39 38
    private final File initialPath;
......
41 40
    private final String dialogTitle;
42 41
    private File value;
43 42
    private FileFilter filter;
44
    
43

  
45 44
    public static void selfRegister() {
46 45
        URL imageResource = DatePickerControllerImpl.class.getClassLoader().getResource("org/gvsig/tools/swing/picker/picker-file.png");
47 46
        if (imageResource != null) {
......
59 58
        }
60 59
    }
61 60
    private final JButton btnClear;
62
    
61

  
63 62
    public FilePickerControllerImpl(JTextField txtFile, JButton btnFile, String dialogTitle) {
64 63
        this(txtFile, btnFile, dialogTitle, null, null, true);
65 64
    }
66
    
65

  
67 66
    public FilePickerControllerImpl(JTextField txtFile, JButton btnFile) {
68 67
        this(txtFile, btnFile, null, null, null, true);
69 68
    }
......
74 73
        this.btnFile = btnFile;
75 74
        this.fileChooserID = fileChooserID;
76 75
        this.initialPath = initialPath;
77
        if( dialogTitle==null ) {
76
        if (dialogTitle == null) {
78 77
            I18nManager i18n = ToolsLocator.getI18nManager();
79 78
            this.dialogTitle = i18n.getTranslation("_Select_file");
80 79
        } else {
81 80
            this.dialogTitle = dialogTitle;
82 81
        }
83
        if( seticon ) {
82
        if (seticon) {
84 83
            this.btnFile.setIcon(this.getIcon("picker-file"));
85 84
            this.btnFile.setText("");
86 85
        }
......
91 90
            }
92 91
        });
93 92
        this.btnClear = new JButton(getIcon("picker-cleartext"));
94
        btnClear.setBorderPainted( false );
95
        btnClear.setFocusPainted( false );
96
        btnClear.setContentAreaFilled( false );        
97
        btnClear.setOpaque(false);        
93
        btnClear.setBorderPainted(false);
94
        btnClear.setFocusPainted(false);
95
        btnClear.setContentAreaFilled(false);
96
        btnClear.setOpaque(false);
98 97
        btnClear.addActionListener(new ActionListener() {
99 98
            @Override
100 99
            public void actionPerformed(ActionEvent e) {
......
107 106
        this.txtFile.addKeyListener(new KeyAdapter() {
108 107
            @Override
109 108
            public void keyPressed(KeyEvent e) {
110
                if( e.getKeyCode()==KeyEvent.VK_ENTER ) {
109
                if (e.getKeyCode() == KeyEvent.VK_ENTER) {
111 110
                    coerceAndSet(txtFile.getText());
112 111
                    fireChangeEvent();
113 112
                }
......
119 118
    private void doClear() {
120 119
        this.set(null);
121 120
    }
122
            
121

  
123 122
    @Override
124 123
    public boolean isEmpty() {
125
        return this.value==null;
124
        return this.value == null;
126 125
    }
127
    
126

  
128 127
    @Override
129 128
    public File get() {
129
        coerceAndSet(txtFile.getText());
130 130
        return this.value;
131 131
    }
132 132

  
133 133
    @Override
134 134
    public void set(File value) {
135 135
        this.value = value;
136
        if( value==null ) {
136
        if (value == null) {
137 137
            this.txtFile.setText("");
138 138
        } else {
139 139
            this.txtFile.setText(value.toString());
......
145 145
        super.setEditable(editable);
146 146
        this.txtFile.setEditable(editable);
147 147
    }
148
    
148

  
149 149
    @Override
150 150
    public void setEnabled(boolean enabled) {
151 151
        this.btnFile.setEnabled(enabled);
......
159 159
    }
160 160

  
161 161
    private void doSelectFile() {
162
        if( !this.isEditable() ) {
162
        if (!this.isEditable()) {
163 163
            return;
164 164
        }
165 165
        ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager();
166 166
        FoldersManager folderManager = ToolsLocator.getFoldersManager();
167
        File pathToUse = initialPath;
168
        if (this.value != null) {
169
            pathToUse =  this.value;
170
        }
167 171
        File[] f = dialogs.showChooserDialog(
168
                this.dialogTitle, 
169
                JFileChooser.OPEN_DIALOG, 
170
                JFileChooser.FILES_ONLY, 
171
                true, 
172
                this.dialogTitle,
173
                JFileChooser.OPEN_DIALOG,
174
                JFileChooser.FILES_ONLY,
175
                true,
172 176
                folderManager.getLastPath(
173
                        this.fileChooserID, 
174
                        this.initialPath
177
                        this.fileChooserID,
178
                        pathToUse
175 179
                ),
176
                this.filter, 
180
                this.filter,
177 181
                true
178 182
        );
179
        
180
        if( ArrayUtils.isEmpty(f) ) {
183

  
184
        if (ArrayUtils.isEmpty(f)) {
181 185
            return;
182 186
        }
183 187
        this.set(f[0]);
......
193 197
    public void setFileFilter(FileFilter filter) {
194 198
        this.filter = filter;
195 199
    }
196
    
200

  
197 201
}

Also available in: Unified diff