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 / DefaultView3DSwingManager.java @ 541

History | View | Annotate | Download (7.87 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2015 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;
26

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

    
30
import java.beans.PropertyChangeEvent;
31
import java.beans.PropertyChangeListener;
32
import java.io.File;
33
import java.util.ArrayList;
34
import java.util.List;
35

    
36
import org.gvsig.fmap.mapcontext.MapContext;
37
import org.gvsig.fmap.mapcontext.layers.ExtendedPropertiesSupport;
38
import org.gvsig.fmap.mapcontext.layers.FLayer;
39
import org.gvsig.view3d.swing.api.MapControl3D;
40
import org.gvsig.view3d.swing.api.View3DPanel;
41
import org.gvsig.view3d.swing.api.View3DSwingManager;
42
import org.gvsig.view3d.swing.api.properties.GeneralProperties3D;
43
import org.gvsig.view3d.swing.api.properties.GeneralProperties3DPanel;
44
import org.gvsig.view3d.swing.api.properties.LayerProperties3DPanel;
45
import org.gvsig.view3d.swing.api.properties.MapControlProperties3D;
46
import org.gvsig.view3d.swing.api.properties.ViewProperties3DPanel;
47
import org.gvsig.view3d.swing.impl.data.ConfigurableFileStore;
48
import org.gvsig.view3d.swing.impl.properties.DefaultGeneralProperties3D;
49
import org.gvsig.view3d.swing.impl.properties.DefaultGeneralProperties3DPanel;
50
import org.gvsig.view3d.swing.impl.properties.DefaultLayerProperties3DPanel;
51
import org.gvsig.view3d.swing.impl.properties.DefaultMapControlProperties3D;
52
import org.gvsig.view3d.swing.impl.properties.DefaultViewProperties3DPanel;
53
import org.slf4j.Logger;
54
import org.slf4j.LoggerFactory;
55

    
56
/**
57
 * Default implementation of {@link View3DSwingManager}.
58
 * 
59
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
60
 */
61
public class DefaultView3DSwingManager implements View3DSwingManager{
62

    
63
    private static final Logger LOG =
64
        LoggerFactory.getLogger(DefaultView3DSwingManager.class);
65
    
66
    private GeneralProperties3D generalProperties;
67

    
68
    public MapControl3D createMapControl3D(MapContext theMapContext, TYPE type,
69
        ExtendedPropertiesSupport viewProperties) {
70
        
71
        if(theMapContext == null || type == null){
72
            LOG.error("Can't create MapControl3D because MapContext or TYPE are null");
73
            throw new IllegalArgumentException();
74
        }
75
        
76
        MapControl3D mapControl3D =
77
            new DefaultMapControl3D(theMapContext, type, viewProperties);
78
        
79
        if(type == TYPE.SPHERE){
80
            viewProperties.setProperty("sphereMapControl3D", mapControl3D);
81
        } else if(type == TYPE.FLAT){
82
            viewProperties.setProperty("flatMapControl3D", mapControl3D);
83
        }
84

    
85
        return mapControl3D;
86
    }
87

    
88
    public View3DPanel createView3DPanel(MapContext theMapContext,String title, TYPE type,
89
        ExtendedPropertiesSupport viewProperties) {
90
        
91
        if(theMapContext == null || type == null){
92
            LOG.error("Can't create View3DPanel because MapContext or TYPE are null");
93
            throw new IllegalArgumentException();
94
        }
95
        
96
        return new DefaultView3DPanel(theMapContext,title, type, viewProperties);
97
    }
98
    
99
    public View3DPanel createView3DPanel(MapControl3D mapControl3D, String title) {
100

    
101
        if (mapControl3D == null) {
102
            LOG.error("Can't create View3DPanel because MapControl3D is null");
103
            throw new IllegalArgumentException();
104
        }
105

    
106
        return new DefaultView3DPanel(mapControl3D, title);
107
    }
108

    
109
    public LayerProperties3DPanel createLayerProperties3DPanel(FLayer layer) {
110
        return new DefaultLayerProperties3DPanel(layer);
111
    }
112

    
113
    public List<MapControl3D> getMapControl3D(
114
        ExtendedPropertiesSupport viewProperties) {
115

    
116
        List<MapControl3D> mapControls3D = new ArrayList<MapControl3D>();
117

    
118
        MapControl3D sphereMapControl3D =
119
            (MapControl3D) viewProperties.getProperty("sphereMapControl3D");
120
        MapControl3D flatMapControl3D =
121
            (MapControl3D) viewProperties.getProperty("flatMapControl3D");
122

    
123
        if (sphereMapControl3D != null) {
124
            mapControls3D.add(sphereMapControl3D);
125
        }
126

    
127
        if (flatMapControl3D != null) {
128
            mapControls3D.add(flatMapControl3D);
129
        }
130

    
131
        return mapControls3D;
132
    }
133
    
134
    public MapControl3D getMapControl3D(ExtendedPropertiesSupport viewProperties, TYPE type) {
135
        
136
        if(type == TYPE.SPHERE){
137
            return (MapControl3D) viewProperties.getProperty("sphereMapControl3D");
138
        } else if (type == TYPE.FLAT){
139
            return (MapControl3D) viewProperties.getProperty("flatMapControl3D");
140
        }
141
        return null;
142
    }
143

    
144
    public ViewProperties3DPanel createViewProperties3DPanel(
145
        MapControlProperties3D properties) {
146
        return new DefaultViewProperties3DPanel(properties);
147
    }
148

    
149
    public GeneralProperties3DPanel createGeneralProperties3DPanel(
150
        GeneralProperties3D properties) {
151
        return new DefaultGeneralProperties3DPanel(properties);
152
    }
153
    
154
    public MapControlProperties3D getMapControl3DProperties(
155
        ExtendedPropertiesSupport viewProperties) {
156
        
157
        MapControlProperties3D properties =
158
            (MapControlProperties3D) viewProperties
159
                .getProperty("mapControl3DProperties");
160
        
161
        if(properties == null){
162
            properties = new DefaultMapControlProperties3D();
163
            setMapControlProperties3D(viewProperties, properties);
164
        }
165
        
166
        return properties;
167
    }
168

    
169
    public void setMapControlProperties3D(
170
        ExtendedPropertiesSupport viewProperties,
171
        MapControlProperties3D mapControl3DProperties) {
172
        
173
        viewProperties.setProperty("mapControl3DProperties",
174
            mapControl3DProperties);
175
    }
176

    
177
    public GeneralProperties3D getGeneral3DProperties() {
178
        if(generalProperties == null){
179
            generalProperties = new DefaultGeneralProperties3D();
180
            generalProperties.addPropertyChangeListener(getCachePathPropertyListener());
181
        }
182
        return generalProperties;
183
    }
184

    
185
    public void setGeneral3DProperties(GeneralProperties3D properties) {
186
        if(properties != null){
187
            this.generalProperties = properties;
188
            this.generalProperties
189
                .addPropertyChangeListener(getCachePathPropertyListener());
190
        }
191
        
192
    }
193
    
194
    private PropertyChangeListener getCachePathPropertyListener(){
195
        return new PropertyChangeListener() {
196
            
197
            public void propertyChange(PropertyChangeEvent evt) {
198
                if (evt.getPropertyName().equals(
199
                    GeneralProperties3D.CACHE_PATH_PROPERTY_NAME)) {
200
                    
201
                    FileStore dataFileStore = WorldWind.getDataFileStore();
202
                    
203
                    if(dataFileStore instanceof ConfigurableFileStore){
204
                        ConfigurableFileStore confDataStore =
205
                            (ConfigurableFileStore) dataFileStore;
206
                        
207
                        confDataStore.setWriteLocation((File) evt.getNewValue());
208
                        LOG.info("Changed cache path to {}", evt.getNewValue());
209
                    }
210
                }
211
            }
212
        };
213
    }
214
}