Statistics
| Revision:

root / branches / gvSIG_19_ext3D_osgVP_2_2_0 / libraries / lib3DMap / src / org / gvsig / gvsig3d / listener / EditorListener.java @ 32405

History | View | Annotate | Download (5.46 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

    
36
import org.apache.log4j.Logger;
37
import org.gvsig.gvsig3d.navigation.NavigationMode;
38
import org.gvsig.osgvp.core.osg.Group;
39
import org.gvsig.osgvp.core.osg.Node;
40
import org.gvsig.osgvp.exceptions.node.NodeException;
41
import org.gvsig.osgvp.manipulator.AddSelectionCommand;
42
import org.gvsig.osgvp.manipulator.EditionManager;
43
import org.gvsig.osgvp.manipulator.Manipulator;
44
import org.gvsig.osgvp.manipulator.ManipulatorHandler;
45
import org.gvsig.osgvp.manipulator.RemoveAllSelectionCommand;
46
import org.gvsig.osgvp.terrain.TerrainViewer;
47
import org.gvsig.osgvp.util.ActionCommand;
48
import org.gvsig.osgvp.util.Util;
49
import org.gvsig.osgvp.viewer.Camera;
50
import org.gvsig.osgvp.viewer.IViewerContainer;
51
import org.gvsig.osgvp.viewer.Intersection;
52
import org.gvsig.osgvp.viewer.Intersections;
53

    
54
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps;
55
import com.iver.cit.gvsig.fmap.layers.FLayer;
56

    
57
public class EditorListener implements MouseListener, KeyListener {
58

    
59
        private EditionManager _manager;
60
        private ManipulatorHandler _handler;
61
        private IViewerContainer _viewer;
62
        private FLayer _layer;
63
        IViewerContainer _canvas3d;
64
        private TerrainViewer _terrainViewer;
65
        private boolean _camEnabled;
66

    
67
        public EditorListener(EditionManager manager, ManipulatorHandler handler,
68
                        FLayer layer, IViewerContainer canvas3d, TerrainViewer terrainViewer) {
69

    
70
                _manager = manager;
71
                _handler = handler;
72
                _layer = layer;
73
                _canvas3d = canvas3d;
74
                _viewer = canvas3d;
75
                // _viewer.addMouseListener(this);
76
                // _viewer.addKeyListener(this);
77
                _terrainViewer = terrainViewer;
78
                _camEnabled = false;
79

    
80
        }
81

    
82
        public void mouseDoubleClick(MouseEvent e) {
83

    
84
        }
85

    
86
        public void mouseDown(MouseEvent e) {
87

    
88
        }
89

    
90
        public void mouseUp(MouseEvent e) {
91

    
92
        }
93

    
94
        public void keyPressed(KeyEvent e) {
95

    
96
                if (e.getKeyCode() == KeyEvent.VK_CONTROL) {
97

    
98
                        _handler.setActive(false);
99
                        NavigationMode.restoreAllNavigationModes(_terrainViewer
100
                                        .getTerrainCameraManipulator());
101
                        _camEnabled = true;
102

    
103
                } else if (e.getKeyCode() == KeyEvent.VK_G) {
104

    
105
                        _manager.group();
106

    
107
                } else if (e.getKeyCode() == KeyEvent.VK_U) {
108

    
109
                        _manager.ungroup();
110

    
111
                }
112

    
113
        }
114

    
115
        public void keyReleased(KeyEvent e) {
116

    
117
                if (e.getKeyCode() == KeyEvent.VK_CONTROL) {
118

    
119
                        _handler.setActive(true);
120
                        NavigationMode.removeAllNavigationModes(_terrainViewer
121
                                        .getTerrainCameraManipulator());
122
                        _camEnabled = false;
123

    
124
                } else if (e.getKeyCode() == KeyEvent.VK_DELETE) {
125

    
126
                        if (Layer3DProps.getLayer3DProps(this._layer).isEditing()) {
127
                                _manager.deleteSelectedNodes();
128
                        }
129

    
130
                }
131

    
132
        }
133

    
134
        public void mouseClicked(MouseEvent e) {
135

    
136
                ActionCommand command;
137
                if (!_camEnabled) {
138
                        try {
139
                                if (e.getButton() == MouseEvent.BUTTON1) {
140
                                        Intersections polytopeHits;
141
                                        polytopeHits = _viewer.getOSGViewer().rayPick(
142
                                                        this._manager.getScene(), e.getX(), e.getY(),
143
                                                        Manipulator.NEG_MANIPULATOR_NODEMASK);
144

    
145
                                        if (polytopeHits.containsIntersections()) {
146

    
147
                                                Intersection hit = polytopeHits.getFirstIntersection();
148
                                                Node nodeHit = (Node) hit.getNodePath().get(1);
149
                                                System.out.println("Node name: "
150
                                                                + nodeHit.getNodeName());
151
                                                /*
152
                                                 * Group parent; parent = new
153
                                                 * Group(nodeHit.getParent(0).getCPtr()); int k; k =
154
                                                 * parent.getChildIndex(nodeHit); command = new
155
                                                 * AddSelectionCommand(k, _manager); command.execute();
156
                                                 * 
157
                                                 * System.out.println("SELECTED A TRUE!");
158
                                                 */
159
                                                int k;
160
                                                try {
161
                                                        k = nodeHit.getParent(0).getChildIndex(nodeHit);
162

    
163
                                                        AddSelectionCommand addCommand = new AddSelectionCommand(
164
                                                                        k, _manager);
165
                                                        addCommand.execute();
166

    
167
                                                } catch (NodeException e1) {
168
                                                        // TODO Auto-generated catch block
169
                                                        e1.printStackTrace();
170
                                                }
171

    
172
                                        }
173

    
174
                                        else {
175

    
176
                                                command = new RemoveAllSelectionCommand(_manager);
177
                                                command.execute();
178

    
179
                                        }
180
                                }
181
                        } catch (NodeException e2) {
182
                                // TODO Auto-generated catch block
183
                                e2.printStackTrace();
184
                        }
185
                }
186

    
187
        }
188

    
189
        public void mouseEntered(MouseEvent e) {
190
                // TODO Auto-generated method stub
191

    
192
        }
193

    
194
        public void mouseExited(MouseEvent e) {
195
                // TODO Auto-generated method stub
196

    
197
        }
198

    
199
        public void mousePressed(MouseEvent e) {
200
                // TODO Auto-generated method stub
201

    
202
        }
203

    
204
        public void mouseReleased(MouseEvent e) {
205
                // TODO Auto-generated method stub
206

    
207
        }
208

    
209
        public void keyTyped(KeyEvent e) {
210
                // TODO Auto-generated method stub
211

    
212
        }
213

    
214
}