Statistics
| Revision:

gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.util / org.gvsig.tools.util.impl / src / main / java / org / gvsig / filedialogchooser / impl / JFileChooserBased.java @ 1872

History | View | Annotate | Download (1.86 KB)

1 1553 jjdelcerro
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.filedialogchooser.impl;
7
8
import java.awt.Component;
9
import java.awt.HeadlessException;
10
import java.io.File;
11
import javax.swing.JFileChooser;
12
import org.gvsig.filedialogchooser.FileDialogChooser;
13
import org.gvsig.filedialogchooser.FileDialogChooserManager;
14
import org.gvsig.tools.util.ToolsUtilLocator;
15
16
17
18
19
public class JFileChooserBased extends JFileChooser implements FileDialogChooser {
20
21
    private static final long serialVersionUID = 2825200958209418322L;
22
    private final String fileChooserID;
23
24 1557 jjdelcerro
    public JFileChooserBased(String fileChooserID) {
25 1553 jjdelcerro
        super();
26
        this.fileChooserID = fileChooserID;
27
    }
28
29
    @Override
30
    public int showOpenDialog(Component parent) throws HeadlessException {
31 1571 jjdelcerro
        FileDialogChooserManager manager = ToolsUtilLocator.getFileDialogChooserManager();
32 1711 jjdelcerro
        File f = this.getCurrentDirectory();
33
        if( f==null ) {
34
            f = manager.getLastPath(fileChooserID, null);
35
            super.setCurrentDirectory(f);
36
        }
37 1553 jjdelcerro
        int r = super.showOpenDialog(parent);
38
        if( r == JFileChooser.APPROVE_OPTION ) {
39
            manager.setLastPath(fileChooserID, this.getCurrentDirectory());
40
        }
41
        return r;
42
    }
43
44
    @Override
45
    public int showSaveDialog(Component parent) throws HeadlessException {
46 1571 jjdelcerro
        FileDialogChooserManager manager = ToolsUtilLocator.getFileDialogChooserManager();
47 1575 jjdelcerro
        File f = manager.getLastPath(fileChooserID, this.getCurrentDirectory());
48 1571 jjdelcerro
        super.setCurrentDirectory(f);        int r = super.showSaveDialog(parent);
49 1553 jjdelcerro
        if( r == JFileChooser.APPROVE_OPTION ) {
50
            manager.setLastPath(fileChooserID, this.getCurrentDirectory());
51
        }
52
        return r;
53 1872 jjdelcerro
    }
54 1553 jjdelcerro
}