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 / DefaultView3DPanel.java @ 498

History | View | Annotate | Download (4.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 java.awt.BorderLayout;
28
import java.awt.event.ComponentEvent;
29
import java.awt.event.ComponentListener;
30

    
31
import javax.swing.JComponent;
32
import javax.swing.JPanel;
33

    
34
import org.gvsig.fmap.mapcontext.MapContext;
35
import org.gvsig.fmap.mapcontext.layers.ExtendedPropertiesSupport;
36
import org.gvsig.tools.ToolsLocator;
37
import org.gvsig.tools.i18n.I18nManager;
38
import org.gvsig.tools.observer.ObservableHelper;
39
import org.gvsig.tools.observer.Observer;
40
import org.gvsig.tools.swing.api.ToolsSwingLocator;
41
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
42
import org.gvsig.view3d.swing.api.MapControl3D;
43
import org.gvsig.view3d.swing.api.View3DPanel;
44
import org.gvsig.view3d.swing.api.View3DSwingLocator;
45
import org.gvsig.view3d.swing.api.View3DSwingManager;
46
import org.gvsig.view3d.swing.api.View3DSwingManager.TYPE;
47

    
48
/**
49
 * Default implementaion of {@link View3DPanel}.
50
 * 
51
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
52
 */
53
public class DefaultView3DPanel extends JPanel implements View3DPanel {
54

    
55
    private static final long serialVersionUID = -87105248886531868L;
56

    
57
    private ObservableHelper observableHelper;
58
    
59
    private String title;
60

    
61
    private MapControl3D mapControl3D;
62

    
63
    /**
64
     * Default constructor of {@link DefaultView3DPanel}. Creates an
65
     * {@link MapControl3D}, initialize local fileds and register listeners.
66
     * 
67
     * @param theMapContext
68
     *            associated <code>MapContext</code>
69
     * @param type
70
     *            Type of this {@link DefaultMapControl3D}. See {@link TYPE}.
71
     * @param viewProperties
72
     *            View properties to register a <code>MapControl3D</code>           
73
     */
74
    public DefaultView3DPanel(MapContext theMapContext,String title, TYPE type,
75
        ExtendedPropertiesSupport viewProperties) {
76
        
77
        super(new BorderLayout());
78
        
79
        this.title = composeTitle(title);
80

    
81
        View3DSwingManager swingManager = View3DSwingLocator.getManager();
82
        this.mapControl3D =
83
            swingManager.createMapControl3D(theMapContext, type, viewProperties);
84
        this.observableHelper = new ObservableHelper();
85

    
86
        this.add(mapControl3D.asJComponent(), BorderLayout.CENTER);
87

    
88
        this.addComponentListener(new ComponentListener() {
89

    
90
            public void componentShown(ComponentEvent e) {
91
            }
92

    
93
            public void componentResized(ComponentEvent e) {
94
            }
95

    
96
            public void componentMoved(ComponentEvent e) {
97
            }
98

    
99
            public void componentHidden(ComponentEvent e) {
100
                getMapControl3D().dispose();
101
            }
102
        });
103
    }
104

    
105
    private String composeTitle(String title) {
106
        I18nManager i18nManager = ToolsLocator.getI18nManager();
107
        StringBuilder stb = new StringBuilder();
108
        stb.append(i18nManager.getTranslation("view_3d"));
109
        stb.append(" ");
110
        stb.append(":");
111
        stb.append(" ");
112
        stb.append(title);
113
        return stb.toString();
114
    }
115

    
116
    public JComponent asJComponent() {
117
        return this;
118
    }
119

    
120
    public MapControl3D getMapControl3D() {
121
        return this.mapControl3D;
122
    }
123

    
124
    public void show() {
125
        WindowManager wm = ToolsSwingLocator.getWindowManager();
126
        wm.showWindow(this, title, WindowManager.MODE.WINDOW);
127
    }
128

    
129
    public void addObserver(Observer o) {
130
        if (observableHelper != null) {
131
            observableHelper.addObserver(o);
132
        }
133
    }
134

    
135
    public void deleteObserver(Observer o) {
136
        if (observableHelper != null) {
137
            observableHelper.deleteObserver(o);
138
        }
139

    
140
    }
141

    
142
    public void deleteObservers() {
143
        if (observableHelper != null) {
144
            observableHelper.deleteObservers();
145
        }
146
    }
147
}