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 @ 530

History | View | Annotate | Download (6.56 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.List;
29

    
30
import org.gvsig.fmap.mapcontext.MapContext;
31
import org.gvsig.fmap.mapcontext.layers.ExtendedPropertiesSupport;
32
import org.gvsig.fmap.mapcontext.layers.FLayer;
33
import org.gvsig.view3d.swing.api.MapControl3D;
34
import org.gvsig.view3d.swing.api.View3DPanel;
35
import org.gvsig.view3d.swing.api.View3DSwingManager;
36
import org.gvsig.view3d.swing.api.properties.GeneralProperties3D;
37
import org.gvsig.view3d.swing.api.properties.GeneralProperties3DPanel;
38
import org.gvsig.view3d.swing.api.properties.LayerProperties3DPanel;
39
import org.gvsig.view3d.swing.api.properties.MapControlProperties3D;
40
import org.gvsig.view3d.swing.api.properties.ViewProperties3DPanel;
41
import org.gvsig.view3d.swing.impl.properties.DefaultGeneralProperties3D;
42
import org.gvsig.view3d.swing.impl.properties.DefaultGeneralProperties3DPanel;
43
import org.gvsig.view3d.swing.impl.properties.DefaultLayerProperties3DPanel;
44
import org.gvsig.view3d.swing.impl.properties.DefaultMapControlProperties3D;
45
import org.gvsig.view3d.swing.impl.properties.DefaultViewProperties3DPanel;
46
import org.slf4j.Logger;
47
import org.slf4j.LoggerFactory;
48

    
49
/**
50
 * Default implementation of {@link View3DSwingManager}.
51
 * 
52
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
53
 */
54
public class DefaultView3DSwingManager implements View3DSwingManager{
55

    
56
    private static final Logger LOG =
57
        LoggerFactory.getLogger(DefaultView3DSwingManager.class);
58
    
59
    private GeneralProperties3D generalProperties;
60

    
61
    public MapControl3D createMapControl3D(MapContext theMapContext, TYPE type,
62
        ExtendedPropertiesSupport viewProperties) {
63
        
64
        if(theMapContext == null || type == null){
65
            LOG.error("Can't create MapControl3D because MapContext or TYPE are null");
66
            throw new IllegalArgumentException();
67
        }
68
        
69
        MapControl3D mapControl3D =
70
            new DefaultMapControl3D(theMapContext, type, viewProperties);
71
        
72
        if(type == TYPE.SPHERE){
73
            viewProperties.setProperty("sphereMapControl3D", mapControl3D);
74
        } else if(type == TYPE.FLAT){
75
            viewProperties.setProperty("flatMapControl3D", mapControl3D);
76
        }
77

    
78
        return mapControl3D;
79
    }
80

    
81
    public View3DPanel createView3DPanel(MapContext theMapContext,String title, TYPE type,
82
        ExtendedPropertiesSupport viewProperties) {
83
        
84
        if(theMapContext == null || type == null){
85
            LOG.error("Can't create View3DPanel because MapContext or TYPE are null");
86
            throw new IllegalArgumentException();
87
        }
88
        
89
        return new DefaultView3DPanel(theMapContext,title, type, viewProperties);
90
    }
91
    
92
    public View3DPanel createView3DPanel(MapControl3D mapControl3D, String title) {
93

    
94
        if (mapControl3D == null) {
95
            LOG.error("Can't create View3DPanel because MapControl3D is null");
96
            throw new IllegalArgumentException();
97
        }
98

    
99
        return new DefaultView3DPanel(mapControl3D, title);
100
    }
101

    
102
    public LayerProperties3DPanel createLayerProperties3DPanel(FLayer layer) {
103
        return new DefaultLayerProperties3DPanel(layer);
104
    }
105

    
106
    public List<MapControl3D> getMapControl3D(
107
        ExtendedPropertiesSupport viewProperties) {
108

    
109
        List<MapControl3D> mapControls3D = new ArrayList<MapControl3D>();
110

    
111
        MapControl3D sphereMapControl3D =
112
            (MapControl3D) viewProperties.getProperty("sphereMapControl3D");
113
        MapControl3D flatMapControl3D =
114
            (MapControl3D) viewProperties.getProperty("flatMapControl3D");
115

    
116
        if (sphereMapControl3D != null) {
117
            mapControls3D.add(sphereMapControl3D);
118
        }
119

    
120
        if (flatMapControl3D != null) {
121
            mapControls3D.add(flatMapControl3D);
122
        }
123

    
124
        return mapControls3D;
125
    }
126
    
127
    public MapControl3D getMapControl3D(ExtendedPropertiesSupport viewProperties, TYPE type) {
128
        
129
        if(type == TYPE.SPHERE){
130
            return (MapControl3D) viewProperties.getProperty("sphereMapControl3D");
131
        } else if (type == TYPE.FLAT){
132
            return (MapControl3D) viewProperties.getProperty("flatMapControl3D");
133
        }
134
        return null;
135
    }
136

    
137
    public ViewProperties3DPanel createViewProperties3DPanel(
138
        MapControlProperties3D properties) {
139
        return new DefaultViewProperties3DPanel(properties);
140
    }
141

    
142
    public GeneralProperties3DPanel createGeneralProperties3DPanel(
143
        GeneralProperties3D properties) {
144
        return new DefaultGeneralProperties3DPanel(properties);
145
    }
146
    
147
    public MapControlProperties3D getMapControl3DProperties(
148
        ExtendedPropertiesSupport viewProperties) {
149
        
150
        MapControlProperties3D properties =
151
            (MapControlProperties3D) viewProperties
152
                .getProperty("mapControl3DProperties");
153
        
154
        if(properties == null){
155
            properties = new DefaultMapControlProperties3D();
156
            setMapControlProperties3D(viewProperties, properties);
157
        }
158
        
159
        return properties;
160
    }
161

    
162
    public void setMapControlProperties3D(
163
        ExtendedPropertiesSupport viewProperties,
164
        MapControlProperties3D mapControl3DProperties) {
165
        
166
        viewProperties.setProperty("mapControl3DProperties",
167
            mapControl3DProperties);
168
    }
169

    
170
    public GeneralProperties3D getGeneral3DProperties() {
171
        if(generalProperties == null){
172
            generalProperties = new DefaultGeneralProperties3D();
173
        }
174
        return generalProperties;
175
    }
176

    
177
    public void setGeneral3DProperties(GeneralProperties3D properties) {
178
        if(properties != null){
179
            this.generalProperties = properties;
180
        }
181
        
182
    }
183
}