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 @ 693
History | View | Annotate | Download (8.64 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.tools.observer.ObservableHelper; |
40 |
import org.gvsig.tools.observer.Observer; |
41 |
import org.gvsig.view3d.swing.api.MapControl3D; |
42 |
import org.gvsig.view3d.swing.api.View3DPanel; |
43 |
import org.gvsig.view3d.swing.api.View3DSwingManager; |
44 |
import org.gvsig.view3d.swing.api.properties.GeneralProperties3D; |
45 |
import org.gvsig.view3d.swing.api.properties.GeneralProperties3DPanel; |
46 |
import org.gvsig.view3d.swing.api.properties.LayerProperties3DPanel; |
47 |
import org.gvsig.view3d.swing.api.properties.MapControlProperties3D; |
48 |
import org.gvsig.view3d.swing.api.properties.ViewProperties3DPanel; |
49 |
import org.gvsig.view3d.swing.impl.data.ConfigurableFileStore; |
50 |
import org.gvsig.view3d.swing.impl.properties.DefaultGeneralProperties3D; |
51 |
import org.gvsig.view3d.swing.impl.properties.DefaultGeneralProperties3DPanel; |
52 |
import org.gvsig.view3d.swing.impl.properties.DefaultLayerProperties3DPanel; |
53 |
import org.gvsig.view3d.swing.impl.properties.DefaultMapControlProperties3D; |
54 |
import org.gvsig.view3d.swing.impl.properties.DefaultViewProperties3DPanel; |
55 |
import org.slf4j.Logger; |
56 |
import org.slf4j.LoggerFactory; |
57 |
|
58 |
/**
|
59 |
* Default implementation of {@link View3DSwingManager}.
|
60 |
*
|
61 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
|
62 |
*/
|
63 |
public class DefaultView3DSwingManager implements View3DSwingManager{ |
64 |
|
65 |
private static final Logger LOG = |
66 |
LoggerFactory.getLogger(DefaultView3DSwingManager.class); |
67 |
|
68 |
private GeneralProperties3D generalProperties;
|
69 |
|
70 |
private ObservableHelper helper;
|
71 |
|
72 |
/**
|
73 |
* Default constructor
|
74 |
*/
|
75 |
public DefaultView3DSwingManager() {
|
76 |
helper = new ObservableHelper();
|
77 |
} |
78 |
|
79 |
public MapControl3D createMapControl3D(MapContext theMapContext, TYPE type,
|
80 |
ExtendedPropertiesSupport viewProperties) { |
81 |
|
82 |
if(theMapContext == null || type == null){ |
83 |
LOG.error("Can't create MapControl3D because MapContext or TYPE are null");
|
84 |
throw new IllegalArgumentException(); |
85 |
} |
86 |
|
87 |
helper.notifyObservers(this, BEFORE_CREATE_MAPCONTROL3D, new Object[] { theMapContext, |
88 |
type, viewProperties }); |
89 |
|
90 |
MapControl3D mapControl3D = |
91 |
new DefaultMapControl3D(theMapContext, type, viewProperties);
|
92 |
|
93 |
if(type == TYPE.SPHERE){
|
94 |
viewProperties.setProperty("sphereMapControl3D", mapControl3D);
|
95 |
} else if(type == TYPE.FLAT){ |
96 |
viewProperties.setProperty("flatMapControl3D", mapControl3D);
|
97 |
} |
98 |
|
99 |
helper.notifyObservers(this, AFTER_CREATE_MAPCONTROL3D, mapControl3D);
|
100 |
|
101 |
return mapControl3D;
|
102 |
} |
103 |
|
104 |
public View3DPanel createView3DPanel(MapContext theMapContext,String title, TYPE type, |
105 |
ExtendedPropertiesSupport viewProperties) { |
106 |
|
107 |
if(theMapContext == null || type == null){ |
108 |
LOG.error("Can't create View3DPanel because MapContext or TYPE are null");
|
109 |
throw new IllegalArgumentException(); |
110 |
} |
111 |
|
112 |
return new DefaultView3DPanel(theMapContext,title, type, viewProperties); |
113 |
} |
114 |
|
115 |
public View3DPanel createView3DPanel(MapControl3D mapControl3D, String title) { |
116 |
|
117 |
if (mapControl3D == null) { |
118 |
LOG.error("Can't create View3DPanel because MapControl3D is null");
|
119 |
throw new IllegalArgumentException(); |
120 |
} |
121 |
|
122 |
return new DefaultView3DPanel(mapControl3D, title); |
123 |
} |
124 |
|
125 |
public LayerProperties3DPanel createLayerProperties3DPanel(FLayer layer) {
|
126 |
return new DefaultLayerProperties3DPanel(layer); |
127 |
} |
128 |
|
129 |
public List<MapControl3D> getMapControl3D( |
130 |
ExtendedPropertiesSupport viewProperties) { |
131 |
|
132 |
List<MapControl3D> mapControls3D = new ArrayList<MapControl3D>(); |
133 |
|
134 |
MapControl3D sphereMapControl3D = |
135 |
(MapControl3D) viewProperties.getProperty("sphereMapControl3D");
|
136 |
MapControl3D flatMapControl3D = |
137 |
(MapControl3D) viewProperties.getProperty("flatMapControl3D");
|
138 |
|
139 |
if (sphereMapControl3D != null) { |
140 |
mapControls3D.add(sphereMapControl3D); |
141 |
} |
142 |
|
143 |
if (flatMapControl3D != null) { |
144 |
mapControls3D.add(flatMapControl3D); |
145 |
} |
146 |
|
147 |
return mapControls3D;
|
148 |
} |
149 |
|
150 |
public MapControl3D getMapControl3D(ExtendedPropertiesSupport viewProperties, TYPE type) {
|
151 |
|
152 |
if(type == TYPE.SPHERE){
|
153 |
return (MapControl3D) viewProperties.getProperty("sphereMapControl3D"); |
154 |
} else if (type == TYPE.FLAT){ |
155 |
return (MapControl3D) viewProperties.getProperty("flatMapControl3D"); |
156 |
} |
157 |
return null; |
158 |
} |
159 |
|
160 |
public ViewProperties3DPanel createViewProperties3DPanel(
|
161 |
MapControlProperties3D properties) { |
162 |
return new DefaultViewProperties3DPanel(properties); |
163 |
} |
164 |
|
165 |
public GeneralProperties3DPanel createGeneralProperties3DPanel(
|
166 |
GeneralProperties3D properties) { |
167 |
return new DefaultGeneralProperties3DPanel(properties); |
168 |
} |
169 |
|
170 |
public MapControlProperties3D getMapControl3DProperties(
|
171 |
ExtendedPropertiesSupport viewProperties) { |
172 |
|
173 |
MapControlProperties3D properties = |
174 |
(MapControlProperties3D) viewProperties |
175 |
.getProperty("mapControl3DProperties");
|
176 |
|
177 |
if(properties == null){ |
178 |
properties = new DefaultMapControlProperties3D();
|
179 |
setMapControlProperties3D(viewProperties, properties); |
180 |
} |
181 |
|
182 |
return properties;
|
183 |
} |
184 |
|
185 |
public void setMapControlProperties3D( |
186 |
ExtendedPropertiesSupport viewProperties, |
187 |
MapControlProperties3D mapControl3DProperties) { |
188 |
|
189 |
viewProperties.setProperty("mapControl3DProperties",
|
190 |
mapControl3DProperties); |
191 |
} |
192 |
|
193 |
public GeneralProperties3D getGeneral3DProperties() {
|
194 |
if(generalProperties == null){ |
195 |
generalProperties = new DefaultGeneralProperties3D();
|
196 |
generalProperties.addPropertyChangeListener(getCachePathPropertyListener()); |
197 |
} |
198 |
return generalProperties;
|
199 |
} |
200 |
|
201 |
public void setGeneral3DProperties(GeneralProperties3D properties) { |
202 |
if(properties != null){ |
203 |
this.generalProperties = properties;
|
204 |
this.generalProperties
|
205 |
.addPropertyChangeListener(getCachePathPropertyListener()); |
206 |
} |
207 |
|
208 |
} |
209 |
|
210 |
private PropertyChangeListener getCachePathPropertyListener(){ |
211 |
return new PropertyChangeListener() { |
212 |
|
213 |
public void propertyChange(PropertyChangeEvent evt) { |
214 |
if (evt.getPropertyName().equals(
|
215 |
GeneralProperties3D.CACHE_PATH_PROPERTY_NAME)) { |
216 |
|
217 |
FileStore dataFileStore = WorldWind.getDataFileStore(); |
218 |
|
219 |
if(dataFileStore instanceof ConfigurableFileStore){ |
220 |
ConfigurableFileStore confDataStore = |
221 |
(ConfigurableFileStore) dataFileStore; |
222 |
|
223 |
confDataStore.setWriteLocation((File) evt.getNewValue());
|
224 |
LOG.info("Changed cache path to {}", evt.getNewValue());
|
225 |
} |
226 |
} |
227 |
} |
228 |
}; |
229 |
} |
230 |
|
231 |
@Override
|
232 |
public void addObserver(Observer o) { |
233 |
helper.addObserver(o); |
234 |
} |
235 |
|
236 |
@Override
|
237 |
public void deleteObserver(Observer o) { |
238 |
helper.deleteObserver(o); |
239 |
} |
240 |
|
241 |
@Override
|
242 |
public void deleteObservers() { |
243 |
helper.deleteObservers(); |
244 |
} |
245 |
} |