Statistics
| Revision:

gvsig-3d / 2.1 / trunk / org.gvsig.view3d / org.gvsig.view3d.app / org.gvsig.view3d.app.common / src / main / java / org / gvsig / view3d / app / properties / General3DPreferencePage.java @ 518

History | View | Annotate | Download (8.4 KB)

1
package org.gvsig.view3d.app.properties;
2

    
3
import java.awt.BorderLayout;
4
import java.io.File;
5

    
6
import javax.swing.ImageIcon;
7
import javax.swing.JPanel;
8

    
9
import org.gvsig.andami.IconThemeHelper;
10
import org.gvsig.andami.PluginServices;
11
import org.gvsig.andami.PluginsLocator;
12
import org.gvsig.andami.PluginsManager;
13
import org.gvsig.andami.preferences.AbstractPreferencePage;
14
import org.gvsig.andami.preferences.StoreException;
15
import org.gvsig.tools.ToolsLocator;
16
import org.gvsig.tools.dynobject.DynObject;
17
import org.gvsig.tools.i18n.I18nManager;
18
import org.gvsig.view3d.swing.api.View3DSwingLocator;
19
import org.gvsig.view3d.swing.api.View3DSwingManager;
20
import org.gvsig.view3d.swing.api.properties.GeneralProperties3D;
21
import org.gvsig.view3d.swing.api.properties.GeneralProperties3DPanel;
22

    
23
public class General3DPreferencePage extends AbstractPreferencePage {
24

    
25
    private static final long serialVersionUID = -3384416698766077019L;
26

    
27
    public static final String ID = General3DPreferencePage.class.getName();
28

    
29
    private GeneralProperties3DPanel propertiesPanel;
30
    private DynObject pluginProperties;
31
    private PluginServices plugin;
32

    
33
    public General3DPreferencePage() {
34
        initComponents();
35
    }
36

    
37
    private void initComponents() {
38
        PluginsManager pluginManager = PluginsLocator.getManager();
39
        this.plugin = pluginManager.getPlugin(this);
40
        this.pluginProperties = this.plugin.getPluginProperties();
41

    
42
        initializeValues();
43

    
44
        View3DSwingManager swingManager = View3DSwingLocator.getManager();
45
        GeneralProperties3D generalProperties3D =
46
            swingManager.getGeneral3DProperties();
47

    
48
        propertiesPanel =
49
            swingManager.createGeneralProperties3DPanel(generalProperties3D);
50

    
51
        this.setLayout(new BorderLayout());
52
        this.add(propertiesPanel.asJComponent(), BorderLayout.NORTH);
53
    }
54

    
55
    public String getID() {
56
        return ID;
57
    }
58

    
59
    public String getTitle() {
60
        I18nManager i18nManager = ToolsLocator.getI18nManager();
61
        return i18nManager.getTranslation("3D");
62
    }
63

    
64
    public JPanel getPanel() {
65
        return this;
66
    }
67

    
68
    public void initializeValues() {
69
        
70
        View3DSwingManager swingManager = View3DSwingLocator.getManager();
71
        GeneralProperties3D generalProperties3D =
72
            swingManager.getGeneral3DProperties();
73

    
74
        int width =
75
            (Integer) this.pluginProperties.getDynValue("defultViewWidth");
76
        int height =
77
            (Integer) this.pluginProperties.getDynValue("defultViewHeight");
78
        boolean atmosphereVisibility =
79
            (Boolean) this.pluginProperties.getDynValue("atmosphereVisibility");
80
        boolean northIndicatorVisibility =
81
            (Boolean) this.pluginProperties
82
                .getDynValue("northIndicatorVisibility");
83
        boolean minimapVisibility =
84
            (Boolean) this.pluginProperties.getDynValue("minimapVisibility");
85
        boolean starsBackgroundVisibility =
86
            (Boolean) this.pluginProperties
87
                .getDynValue("starsBackgroundVisibility");
88
        boolean scaleVisibility =
89
            (Boolean) this.pluginProperties.getDynValue("scaleVisibility");
90
        boolean viewportAnimation =
91
            (Boolean) this.pluginProperties.getDynValue("viewportAnimation");
92
        String cachePath =
93
            (String) this.pluginProperties.getDynValue("cachePath");
94

    
95
        generalProperties3D.setDefaultViewWidth(width);
96
        generalProperties3D.setDefaultViewHeight(height);
97
        generalProperties3D.setAtmosphereVisibility(atmosphereVisibility);
98
        generalProperties3D.setMinimapVisibility(minimapVisibility);
99
        generalProperties3D
100
            .setNorthIndicatorVisibility(northIndicatorVisibility);
101
        generalProperties3D
102
            .setStarsBackgroundVisibility(starsBackgroundVisibility);
103
        generalProperties3D.setScaleVisibility(scaleVisibility);
104
        generalProperties3D.setViewPortAnimation(viewportAnimation);
105
        
106
        if(cachePath != null){
107
            generalProperties3D.setCachePath(new File(cachePath));
108
        }
109

    
110
        swingManager.setGeneral3DProperties(generalProperties3D);
111
        
112
    }
113

    
114
    public void initializeDefaults() {
115
        
116
    }
117

    
118
    @Override
119
    public boolean isResizeable() {
120
        return true;
121
    }
122

    
123
    public ImageIcon getIcon() {
124
        return IconThemeHelper.getImageIcon("general-properties-view-3d");
125
    }
126

    
127
    public boolean isValueChanged() {
128
        
129
        int width = propertiesPanel.getDefaultWidth();
130
        int heigth = propertiesPanel.getDefaultHeight();
131
        boolean atmosphereVisibility = propertiesPanel.getAtmosphereVisibility();
132
        boolean minimapVisibility = propertiesPanel.getMinimapVisibility();
133
        boolean northIndicatorVisibility = propertiesPanel.getNorthIndicatorVisibility();
134
        boolean scaleVisiblity = propertiesPanel.getScaleVisiblity();
135
        boolean starsBackgroundVisiblity = propertiesPanel.getStarsBackgroundVisiblity();
136
        boolean viewPortAnimation = propertiesPanel.getViewPortAnimation();
137
        String cachePath = propertiesPanel.getCachePath();
138
        
139
        View3DSwingManager swingManager = View3DSwingLocator.getManager();
140
        GeneralProperties3D general3dProperties = swingManager.getGeneral3DProperties();
141

    
142
        if (width != general3dProperties.getDefaultViewWidth()
143
            || heigth != general3dProperties.getDefaultViewHeight()
144
            || atmosphereVisibility != general3dProperties
145
                .getAtmosphereVisibility()
146
            || minimapVisibility != general3dProperties.getMinimapVisibility()
147
            || northIndicatorVisibility != general3dProperties
148
                .getNorthIndicatorVisibility()
149
            || scaleVisiblity != general3dProperties.getScaleVisibility()
150
            || starsBackgroundVisiblity != general3dProperties
151
                .getStarsBackgroundVisibility()
152
            || viewPortAnimation != general3dProperties.getViewPortAnimation()
153
            || !cachePath.equals(general3dProperties.getCachePath()
154
                .getAbsolutePath())) {
155
            
156
            return true;
157
        }
158
        return false;
159
    }
160

    
161
    @Override
162
    public void storeValues() throws StoreException {
163

    
164
        this.pluginProperties.setDynValue("defultViewWidth",
165
            propertiesPanel.getDefaultWidth());
166
        this.pluginProperties.setDynValue("defultViewHeight",
167
            propertiesPanel.getDefaultHeight());
168
        this.pluginProperties.setDynValue("atmosphereVisibility",
169
            propertiesPanel.getAtmosphereVisibility());
170
        this.pluginProperties.setDynValue("minimapVisibility",
171
            propertiesPanel.getMinimapVisibility());
172
        this.pluginProperties.setDynValue("northIndicatorVisibility",
173
            propertiesPanel.getNorthIndicatorVisibility());
174
        this.pluginProperties.setDynValue("starsBackgroundVisibility",
175
            propertiesPanel.getStarsBackgroundVisiblity());
176
        this.pluginProperties.setDynValue("scaleVisibility",
177
            propertiesPanel.getScaleVisiblity());
178
        this.pluginProperties.setDynValue("viewportAnimation",
179
            propertiesPanel.getViewPortAnimation());
180
        this.pluginProperties.setDynValue("cachePath",
181
            propertiesPanel.getCachePath());
182

    
183
        this.plugin.savePluginProperties();
184
    }
185

    
186
    @Override
187
    public void setChangesApplied() {
188

    
189
        View3DSwingManager swingManager = View3DSwingLocator.getManager();
190
        GeneralProperties3D generalProperties3D =
191
            swingManager.getGeneral3DProperties();
192

    
193
        generalProperties3D.setDefaultViewWidth(propertiesPanel
194
            .getDefaultWidth());
195
        generalProperties3D.setDefaultViewHeight(propertiesPanel
196
            .getDefaultHeight());
197
        generalProperties3D.setAtmosphereVisibility(propertiesPanel
198
            .getAtmosphereVisibility());
199
        generalProperties3D.setMinimapVisibility(propertiesPanel
200
            .getMinimapVisibility());
201
        generalProperties3D.setNorthIndicatorVisibility(propertiesPanel
202
            .getNorthIndicatorVisibility());
203
        generalProperties3D.setScaleVisibility(propertiesPanel
204
            .getScaleVisiblity());
205
        generalProperties3D.setStarsBackgroundVisibility(propertiesPanel
206
            .getStarsBackgroundVisiblity());
207
        generalProperties3D.setViewPortAnimation(propertiesPanel
208
            .getViewPortAnimation());
209
        generalProperties3D.setCachePath(new File(propertiesPanel
210
            .getCachePath()));
211

    
212
        swingManager.setGeneral3DProperties(generalProperties3D);
213
    }
214

    
215
}