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 @ 473
History | View | Annotate | Download (4.54 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 java.util.ArrayList; |
28 |
import java.util.HashMap; |
29 |
import java.util.List; |
30 |
import java.util.Map; |
31 |
|
32 |
import org.gvsig.fmap.mapcontext.MapContext; |
33 |
import org.gvsig.tools.observer.Notification; |
34 |
import org.gvsig.tools.observer.Observable; |
35 |
import org.gvsig.tools.observer.Observer; |
36 |
import org.gvsig.view3d.swing.api.MapControl3D; |
37 |
import org.gvsig.view3d.swing.api.View3DPanel; |
38 |
import org.gvsig.view3d.swing.api.View3DSwingManager; |
39 |
import org.slf4j.Logger; |
40 |
import org.slf4j.LoggerFactory; |
41 |
|
42 |
/**
|
43 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
|
44 |
*
|
45 |
*/
|
46 |
public class DefaultView3DSwingManager implements View3DSwingManager, Observer { |
47 |
|
48 |
private static final Logger LOG = |
49 |
LoggerFactory.getLogger(DefaultView3DSwingManager.class); |
50 |
|
51 |
Map<MapContext, List<MapControl3D>> mapContextRegister = |
52 |
new HashMap<MapContext, List<MapControl3D>>(); |
53 |
|
54 |
public MapControl3D createMapControl3D(MapContext theMapContext, TYPE type) {
|
55 |
|
56 |
if(theMapContext == null || type == null){ |
57 |
LOG.error("Can't create MapControl3D because MapContext or TYPE are null");
|
58 |
throw new IllegalArgumentException(); |
59 |
} |
60 |
|
61 |
MapControl3D mapControl3D = |
62 |
new DefaultMapControl3D(theMapContext, type);
|
63 |
mapControl3D.addObserver(this);
|
64 |
|
65 |
if (mapContextRegister.containsKey(theMapContext)) {
|
66 |
List<MapControl3D> mapControlList =
|
67 |
mapContextRegister.get(theMapContext); |
68 |
mapControlList.add(mapControl3D); |
69 |
} else {
|
70 |
List<MapControl3D> mapControlList = new ArrayList<MapControl3D>(); |
71 |
mapControlList.add(mapControl3D); |
72 |
mapContextRegister.put(theMapContext, mapControlList); |
73 |
} |
74 |
return mapControl3D;
|
75 |
} |
76 |
|
77 |
public View3DPanel createView3DPanel(MapContext theMapContext, TYPE type) {
|
78 |
|
79 |
if(theMapContext == null || type == null){ |
80 |
LOG.error("Can't create View3DPanel because MapContext or TYPE are null");
|
81 |
throw new IllegalArgumentException(); |
82 |
} |
83 |
|
84 |
return new DefaultView3DPanel(theMapContext, type); |
85 |
} |
86 |
|
87 |
public MapControl3D getMapControl3D(MapContext theMapContext, TYPE type) {
|
88 |
|
89 |
if (theMapContext == null || type == null) { |
90 |
LOG.error("Can't get associated MapControl3D because MapContext or TYPE are null");
|
91 |
throw new IllegalArgumentException(); |
92 |
} |
93 |
|
94 |
if (mapContextRegister.containsKey(theMapContext)) {
|
95 |
|
96 |
List<MapControl3D> mapControlList =
|
97 |
mapContextRegister.get(theMapContext); |
98 |
for (MapControl3D mapControl3D : mapControlList) {
|
99 |
if (mapControl3D.getType() == type) {
|
100 |
return mapControl3D;
|
101 |
} |
102 |
} |
103 |
} |
104 |
return null; |
105 |
} |
106 |
|
107 |
public void update(Observable observable, Object notification) { |
108 |
|
109 |
if (observable instanceof MapControl3D |
110 |
&& notification instanceof Notification) { |
111 |
|
112 |
Notification n = (Notification) notification; |
113 |
if (n.getType().equalsIgnoreCase(
|
114 |
MapControl3D.AFTER_DISPOSE_MAPCONTEX3D_NOTIFICATION)) { |
115 |
|
116 |
MapControl3D mapControl3D = (MapControl3D) observable; |
117 |
MapContext mapContext = mapControl3D.getMapContext(); |
118 |
List<MapControl3D> list = mapContextRegister.get(mapContext);
|
119 |
|
120 |
if (list.contains(mapControl3D)) {
|
121 |
list.remove(mapControl3D); |
122 |
mapContextRegister.remove(mapContext); |
123 |
mapContextRegister.put(mapContext, list); |
124 |
} |
125 |
} |
126 |
} |
127 |
} |
128 |
} |