Statistics
| Revision:

gvsig-3d / 2.1 / trunk / org.gvsig.view3d / org.gvsig.view3d.swing / org.gvsig.view3d.swing.impl / src / main / java / org / gvsig / view3d / swing / impl / properties / DefaultGeneralProperties3DPanel.java @ 509

History | View | Annotate | Download (4.7 KB)

1
package org.gvsig.view3d.swing.impl.properties;
2

    
3
import gov.nasa.worldwind.WorldWind;
4
import gov.nasa.worldwind.cache.FileStore;
5

    
6
import java.awt.event.ActionEvent;
7
import java.awt.event.ActionListener;
8
import java.io.File;
9

    
10
import javax.swing.JComponent;
11
import javax.swing.JOptionPane;
12

    
13
import org.gvsig.tools.ToolsLocator;
14
import org.gvsig.tools.i18n.I18nManager;
15
import org.gvsig.tools.swing.api.ToolsSwingLocator;
16
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager;
17
import org.gvsig.view3d.swing.api.properties.GeneralProperties3D;
18

    
19
public class DefaultGeneralProperties3DPanel extends
20
    AbstractGeneralProperties3DPanel {
21

    
22
    private static final long serialVersionUID = -4877460179232095806L;
23

    
24
    private GeneralProperties3D properties;
25

    
26
    public DefaultGeneralProperties3DPanel(GeneralProperties3D properties) {
27
        super();
28

    
29
        this.properties = properties;
30

    
31
        fillPanel();
32

    
33
        addDeleteCacheAction();
34
    }
35

    
36
    private void addDeleteCacheAction() {
37

    
38
        getCacheButton().addActionListener(new ActionListener() {
39

    
40
            public void actionPerformed(ActionEvent e) {
41

    
42
                ThreadSafeDialogsManager tsd =
43
                    ToolsSwingLocator.getThreadSafeDialogsManager();
44
                I18nManager i18nManager = ToolsLocator.getI18nManager();
45

    
46
                FileStore store = WorldWind.getDataFileStore();
47
                File cacheRoot = store.getWriteLocation();
48

    
49
                StringBuilder stb = new StringBuilder();
50
                stb.append(i18nManager.getTranslation("path_tilecache"));
51
                stb.append(" ");
52
                stb.append(store.getWriteLocation().getAbsolutePath());
53
                stb.append("\n");
54
                stb.append(i18nManager
55
                    .getTranslation("are_you_sure_remove_cache_XquestionX"));
56

    
57
                int reply =
58
                    tsd.confirmDialog(stb.toString(),
59
                        i18nManager.getTranslation("remove_cache"),
60
                        JOptionPane.OK_CANCEL_OPTION,
61
                        JOptionPane.QUESTION_MESSAGE);
62

    
63
                if (reply == JOptionPane.OK_OPTION) {
64
                    deleteFiles(cacheRoot);
65
                }
66

    
67
            }
68
        });
69
    }
70

    
71
    private void fillPanel() {
72

    
73
        getHeightField().setText(
74
            String.valueOf(properties.getDefaultViewHeight()));
75
        getWidthField().setText(
76
            String.valueOf(properties.getDefaultViewWidht()));
77
        getAtmosphereCheckBox().setSelected(
78
            properties.getAtmosphereVisibility());
79
        getNorthIndicatorCheckBox().setSelected(
80
            properties.getNorthIndicatorVisibility());
81
        getMinimapCheckBox().setSelected(properties.getMinimapVisibility());
82
        getStarsBackGroundCheckBox().setSelected(
83
            properties.getStarsBackgroundVisibility());
84
        getScaleCheckBox().setSelected(properties.getScaleVisibility());
85
        getViewPortAnimationCheckBox().setSelected(
86
            properties.getViewPortAnimation());
87

    
88
        if (properties.getCachePath() == null || properties.getCachePath().equals("")) {
89
            getCacheField().setText(
90
                WorldWind.getDataFileStore().getWriteLocation()
91
                    .getAbsolutePath());
92
        } else {
93
            getCacheField().setText(properties.getCachePath());
94
        }
95
    }
96

    
97
    public JComponent asJComponent() {
98
        return this;
99
    }
100

    
101
    private void deleteFiles(File dir) {
102
        if (!dir.isDirectory())
103
            return;
104

    
105
        File[] files = dir.listFiles();
106
        for (File file : files) {
107
            if (file.isFile()) {
108
                file.delete();
109
            } else if (file.isDirectory()) {
110
                this.deleteFiles(file);
111
                if (file.list().length == 0) {
112
                    file.delete();
113
                }
114
            }
115
        }
116
    }
117

    
118
    public boolean getAtmosphereVisibility() {
119
        return getAtmosphereCheckBox().isSelected();
120
    }
121

    
122
    public String getCachePath() {
123
        return getCacheField().getText();
124
    }
125

    
126
    public boolean getMinimapVisibility() {
127
        return getMinimapCheckBox().isSelected();
128
    }
129

    
130
    public boolean getNorthIndicatorVisibility() {
131
        return getNorthIndicatorCheckBox().isSelected();
132
    }
133

    
134
    public boolean getScaleVisiblity() {
135
        return getScaleCheckBox().isSelected();
136
    }
137

    
138
    public boolean getStarsBackgroundVisiblity() {
139
        return getStarsBackGroundCheckBox().isSelected();
140
    }
141

    
142
    public boolean getViewPortAnimation() {
143
        return getViewPortAnimationCheckBox().isSelected();
144
    }
145

    
146
    public int getDefaultHeight() {
147
        return Integer.valueOf(getHeightField().getText());
148
    }
149

    
150
    public int getDefaultWidth() {
151
        return Integer.valueOf(getWidthField().getText());
152
    }
153
}