Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / lib3DMap / src / org / gvsig / gvsig3d / listener / EditorListener.java @ 25613

History | View | Annotate | Download (6.54 KB)

1
package org.gvsig.gvsig3d.listener;
2

    
3
/* gvSIG. Geographic Information System of the Valencian Government
4
 *  osgVP. OSG Virtual Planets.
5
 *
6
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
7
 * of the Valencian Government (CIT)
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22
 * MA  02110-1301, USA.
23
 *
24
 */
25
/*
26
 * AUTHORS (In addition to CIT):
27
 * 2008 Instituto de Automática e Informática Industrial, UPV.
28
 */
29

    
30
import java.awt.event.KeyEvent;
31
import java.awt.event.KeyListener;
32
import java.awt.event.MouseEvent;
33
import java.awt.event.MouseListener;
34
import java.util.logging.Level;
35
import org.apache.log4j.Logger;
36
import org.geotools.data.wms.xml.WMSDescribeLayerTypes._LayerDescription;
37
import org.gvsig.gvsig3d.cacheservices.OSGCacheService;
38
import org.gvsig.gvsig3d.navigation.NavigationMode;
39
import org.gvsig.osgvp.ActionCommand;
40
import org.gvsig.osgvp.Group;
41
import org.gvsig.osgvp.Node;
42
import org.gvsig.osgvp.exceptions.node.ChildIndexOutOfBoundsExceptions;
43
import org.gvsig.osgvp.exceptions.node.NodeException;
44
import org.gvsig.osgvp.manipulator.AddSelectionCommand;
45
import org.gvsig.osgvp.manipulator.EditionManager;
46
import org.gvsig.osgvp.manipulator.Manipulator;
47
import org.gvsig.osgvp.manipulator.ManipulatorHandler;
48
import org.gvsig.osgvp.manipulator.RemoveAllSelectionCommand;
49
import org.gvsig.osgvp.manipulator.UngroupCommand;
50
import org.gvsig.osgvp.planets.CustomTerrainManipulator;
51
import org.gvsig.osgvp.planets.PlanetViewer;
52
import org.gvsig.osgvp.planets.PlanetViewer;
53
import org.gvsig.osgvp.util.Util;
54
import org.gvsig.osgvp.viewer.Camera;
55
import org.gvsig.osgvp.viewer.IViewerContainer;
56
import org.gvsig.osgvp.viewer.Intersection;
57
import org.gvsig.osgvp.viewer.Intersections;
58
import org.gvsig.osgvp.viewer.manipulator.CameraManipulator;
59
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps;
60
import com.iver.cit.gvsig.fmap.layers.FLayer;
61

    
62
public class EditorListener implements MouseListener, KeyListener {
63

    
64
        private boolean _lockPick = false;
65
        private EditionManager _manager;
66
        private ManipulatorHandler _handler;
67
        private IViewerContainer viewer;
68
        private FLayer _layer;
69
        IViewerContainer _canvas3d;
70
        private Camera _cam;
71
        private static Logger logger = Logger.getLogger(EditorListener.class
72
                        .getName());
73

    
74
        private PlanetViewer planetViewer;
75

    
76
        public EditorListener(EditionManager manager, ManipulatorHandler handler,
77
                        FLayer layer, IViewerContainer canvas3d, PlanetViewer planetViewer) {
78

    
79
                _manager = manager;
80
                _handler = handler;
81
                _layer = layer;
82
                _canvas3d = canvas3d;
83
                viewer = canvas3d;
84
                viewer.addMouseListener(this);
85
                viewer.addKeyListener(this);
86
                this.planetViewer = planetViewer;
87

    
88
        }
89

    
90
        public void mouseDoubleClick(MouseEvent e) {
91

    
92
        }
93

    
94
        public void mouseDown(MouseEvent e) {
95

    
96
        }
97

    
98
        public void mouseUp(MouseEvent e) {
99

    
100
        }
101

    
102
        public void keyPressed(KeyEvent e) {
103

    
104
                if (e.getKeyCode() == KeyEvent.VK_SHIFT) {
105

    
106
                        Util.logger.log(Level.INFO, "Control Pressed");
107
                        if (Layer3DProps.getLayer3DProps(this._layer).isEditing()) {
108
                                _lockPick = true;
109
                                _handler.setActive(true);
110
                                /*
111
                                 * _cam = _canvas3d.getOSGViewer().getCamera();
112
                                 * _canvas3d.getOSGViewer().setCameraManipulator(null);
113
                                 * _canvas3d.getOSGViewer().setCamera(_cam);
114
                                 */
115
                                NavigationMode.removeAllNavigationModes(this.planetViewer
116
                                                .getCustomTerrainManipulator());
117

    
118
                        }
119

    
120
                }
121

    
122
                else if (e.getKeyCode() == KeyEvent.VK_G) {
123

    
124
                        _manager.group();
125

    
126
                }
127

    
128
                else if (e.getKeyCode() == KeyEvent.VK_U) {
129
                        _manager.ungroup();
130

    
131
                }
132

    
133
        }
134

    
135
        public void keyReleased(KeyEvent e) {
136

    
137
                if (e.getKeyCode() == KeyEvent.VK_SHIFT) {
138

    
139
                        if (Layer3DProps.getLayer3DProps(this._layer).isEditing()) {
140
                                Util.logger.log(Level.INFO, "Control Released");
141
                                _lockPick = false;
142
                                _handler.setActive(false);
143
                                // NavigationMode.restoreAllNavigationModes();
144
                                /*
145
                                 * ((PlanetViewer) _canvas3d.getOSGViewer())
146
                                 * .restoreCustomTerrainManipulator();
147
                                 * _canvas3d.getOSGViewer().setCamera(_cam); try {
148
                                 * ((PlanetViewer) _canvas3d.getOSGViewer()) .activePlanet(0);
149
                                 * ((PlanetViewer)
150
                                 * _canvas3d.getOSGViewer()).computeActiveCoordinateSystemNodePath(); }
151
                                 * catch (ChildIndexOutOfBoundsExceptions e1) {
152
                                 * logger.fatal("Planet doesn't exist"); }
153
                                 */
154

    
155
                                NavigationMode.restoreAllNavigationModes(planetViewer
156
                                                .getCustomTerrainManipulator());
157

    
158
                        }
159

    
160
                }
161

    
162
                if (e.getKeyCode() == KeyEvent.VK_DELETE) {
163

    
164
                        if (Layer3DProps.getLayer3DProps(this._layer).isEditing()) {
165
                                _manager.deleteSelectedNodes();
166
                        }
167

    
168
                }
169

    
170
        }
171

    
172
        public void mouseClicked(MouseEvent e) {
173

    
174
                ActionCommand command;
175
                if (_lockPick) {
176

    
177
                        try {
178
                                if (e.getButton() == MouseEvent.BUTTON1) {
179
                                        Intersections polytopeHits;
180
                                        polytopeHits = viewer.getOSGViewer().rayPick(
181
                                                        this._manager.getScene(), e.getX(), e.getY(),
182
                                                        Manipulator.NEG_MANIPULATOR_NODEMASK);
183

    
184
                                        if (polytopeHits.containsIntersections()) {
185

    
186
                                                Intersection hit = polytopeHits.getFirstIntersection();
187
                                                Node nodeHit = (Node) hit.getNodePath().get(1);
188
                                                System.out.println("Node name: "
189
                                                                + nodeHit.getNodeName());
190
                                                Group parent;
191
                                                parent = new Group(nodeHit.getParent(0).getCPtr());
192
                                                int k;
193
                                                k = parent.getChildIndex(nodeHit);
194
                                                command = new AddSelectionCommand(k, _manager);
195
                                                command.execute();
196

    
197
                                        }
198

    
199
                                        else {
200

    
201
                                                command = new RemoveAllSelectionCommand(_manager);
202
                                                command.execute();
203

    
204
                                        }
205
                                }
206
                        } catch (NodeException e2) {
207
                                // TODO Auto-generated catch block
208
                                e2.printStackTrace();
209
                        }
210
                }
211
// } else if (e.getButton() == MouseEvent.BUTTON2) {
212
//
213
// command = new UngroupCommand(_manager);
214
// command.execute();
215
//
216
// }
217

    
218
        }
219

    
220
        public void mouseEntered(MouseEvent e) {
221
                // TODO Auto-generated method stub
222

    
223
        }
224

    
225
        public void mouseExited(MouseEvent e) {
226
                // TODO Auto-generated method stub
227

    
228
        }
229

    
230
        public void mousePressed(MouseEvent e) {
231
                // TODO Auto-generated method stub
232

    
233
        }
234

    
235
        public void mouseReleased(MouseEvent e) {
236
                // TODO Auto-generated method stub
237

    
238
        }
239

    
240
        public void keyTyped(KeyEvent e) {
241
                // TODO Auto-generated method stub
242

    
243
        }
244

    
245
}