Statistics
| Revision:

gvsig-3d / 2.1 / branches / org.gvsig.view3d_vector_and_extrusion_2.3 / org.gvsig.view3d / org.gvsig.view3d / org.gvsig.view3d.swing / org.gvsig.view3d.swing.impl / src / main / java / org / gvsig / view3d / swing / impl / properties / DefaultGeneralProperties3DPanel.java @ 708

History | View | Annotate | Download (5.66 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright © 2007-2016 gvSIG Association
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

    
25
package org.gvsig.view3d.swing.impl.properties;
26

    
27
import gov.nasa.worldwind.WorldWind;
28
import gov.nasa.worldwind.cache.FileStore;
29

    
30
import java.awt.event.ActionEvent;
31
import java.awt.event.ActionListener;
32
import java.io.File;
33

    
34
import javax.swing.JComponent;
35
import javax.swing.JOptionPane;
36

    
37
import org.gvsig.tools.ToolsLocator;
38
import org.gvsig.tools.i18n.I18nManager;
39
import org.gvsig.tools.swing.api.ToolsSwingLocator;
40
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager;
41
import org.gvsig.view3d.swing.api.properties.GeneralProperties3D;
42

    
43
/**
44
 * @see AbstractGeneralProperties3DPanel
45
 */
46
public class DefaultGeneralProperties3DPanel
47
    extends AbstractGeneralProperties3DPanel {
48

    
49
    private static final long serialVersionUID = -4877460179232095806L;
50

    
51
    private GeneralProperties3D properties;
52

    
53
    public DefaultGeneralProperties3DPanel(GeneralProperties3D properties) {
54
        super();
55

    
56
        this.properties = properties;
57

    
58
        fillPanel();
59

    
60
        addDeleteCacheAction();
61
    }
62

    
63
    private void addDeleteCacheAction() {
64

    
65
        getCacheButton().addActionListener(new ActionListener() {
66

    
67
            public void actionPerformed(ActionEvent e) {
68

    
69
                ThreadSafeDialogsManager tsd =
70
                    ToolsSwingLocator.getThreadSafeDialogsManager();
71
                I18nManager i18nManager = ToolsLocator.getI18nManager();
72

    
73
                FileStore store = WorldWind.getDataFileStore();
74
                File cacheRoot = store.getWriteLocation();
75

    
76
                StringBuilder stb = new StringBuilder();
77
                stb.append(i18nManager.getTranslation("path_tilecache"));
78
                stb.append(" ");
79
                stb.append(store.getWriteLocation().getAbsolutePath());
80
                stb.append("\n");
81
                stb.append(i18nManager
82
                    .getTranslation("are_you_sure_remove_cache_XquestionX"));
83

    
84
                int reply = tsd.confirmDialog(stb.toString(),
85
                    i18nManager.getTranslation("remove_cache"),
86
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
87

    
88
                if (reply == JOptionPane.OK_OPTION) {
89
                    deleteFiles(cacheRoot);
90
                }
91

    
92
            }
93
        });
94
    }
95

    
96
    private void fillPanel() {
97

    
98
        getHeightField()
99
            .setText(String.valueOf(properties.getDefaultViewHeight()));
100
        getWidthField()
101
            .setText(String.valueOf(properties.getDefaultViewWidth()));
102
        getAtmosphereCheckBox()
103
            .setSelected(properties.getAtmosphereVisibility());
104
        getNorthIndicatorCheckBox()
105
            .setSelected(properties.getNorthIndicatorVisibility());
106
        getMinimapCheckBox().setSelected(properties.getMinimapVisibility());
107
        getStarsBackGroundCheckBox()
108
            .setSelected(properties.getStarsBackgroundVisibility());
109
        getScaleCheckBox().setSelected(properties.getScaleVisibility());
110
        getViewPortAnimationCheckBox()
111
            .setSelected(properties.getViewPortAnimation());
112

    
113
        if (properties.getCachePath() == null
114
            || properties.getCachePath().equals("")) {
115
            getCacheField().setText(WorldWind.getDataFileStore()
116
                .getWriteLocation().getAbsolutePath());
117
        } else {
118
            getCacheField()
119
                .setText(properties.getCachePath().getAbsolutePath());
120
        }
121
    }
122

    
123
    public JComponent asJComponent() {
124
        return this;
125
    }
126

    
127
    private void deleteFiles(File dir) {
128
        if (!dir.isDirectory())
129
            return;
130

    
131
        File[] files = dir.listFiles();
132
        for (File file : files) {
133
            if (file.isFile()) {
134
                file.delete();
135
            } else if (file.isDirectory()) {
136
                this.deleteFiles(file);
137
                if (file.list().length == 0) {
138
                    file.delete();
139
                }
140
            }
141
        }
142
    }
143

    
144
    public boolean getAtmosphereVisibility() {
145
        return getAtmosphereCheckBox().isSelected();
146
    }
147

    
148
    public String getCachePath() {
149
        return getCacheField().getText();
150
    }
151

    
152
    public boolean getMinimapVisibility() {
153
        return getMinimapCheckBox().isSelected();
154
    }
155

    
156
    public boolean getNorthIndicatorVisibility() {
157
        return getNorthIndicatorCheckBox().isSelected();
158
    }
159

    
160
    public boolean getScaleVisiblity() {
161
        return getScaleCheckBox().isSelected();
162
    }
163

    
164
    public boolean getStarsBackgroundVisiblity() {
165
        return getStarsBackGroundCheckBox().isSelected();
166
    }
167

    
168
    public boolean getViewPortAnimation() {
169
        return getViewPortAnimationCheckBox().isSelected();
170
    }
171

    
172
    public int getDefaultHeight() {
173
        return Integer.valueOf(getHeightField().getText());
174
    }
175

    
176
    public int getDefaultWidth() {
177
        return Integer.valueOf(getWidthField().getText());
178
    }
179
}