svn-gvsig-desktop / trunk / libraries / lib3DMap / src / org / gvsig / gvsig3d / listener / EditorListener.java @ 25561
History | View | Annotate | Download (4.75 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.geotools.data.wms.xml.WMSDescribeLayerTypes._LayerDescription; |
37 |
import org.gvsig.gvsig3d.navigation.NavigationMode; |
38 |
import org.gvsig.osgvp.ActionCommand; |
39 |
import org.gvsig.osgvp.Group; |
40 |
import org.gvsig.osgvp.Node; |
41 |
import org.gvsig.osgvp.exceptions.node.NodeException; |
42 |
import org.gvsig.osgvp.manipulator.AddSelectionCommand; |
43 |
import org.gvsig.osgvp.manipulator.EditionManager; |
44 |
import org.gvsig.osgvp.manipulator.Manipulator; |
45 |
import org.gvsig.osgvp.manipulator.ManipulatorHandler; |
46 |
import org.gvsig.osgvp.manipulator.RemoveAllSelectionCommand; |
47 |
import org.gvsig.osgvp.util.Util; |
48 |
import org.gvsig.osgvp.viewer.IViewerContainer; |
49 |
import org.gvsig.osgvp.viewer.Intersection; |
50 |
import org.gvsig.osgvp.viewer.Intersections; |
51 |
|
52 |
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps; |
53 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
54 |
|
55 |
public class EditorListener implements MouseListener, KeyListener { |
56 |
|
57 |
private boolean _lockPick = false; |
58 |
private EditionManager _manager;
|
59 |
private ManipulatorHandler _handler;
|
60 |
private IViewerContainer viewer;
|
61 |
private FLayer _layer;
|
62 |
IViewerContainer _canvas3d; |
63 |
|
64 |
public EditorListener(EditionManager manager, ManipulatorHandler handler,
|
65 |
FLayer layer, IViewerContainer canvas3d) { |
66 |
|
67 |
_manager = manager; |
68 |
_handler = handler; |
69 |
_layer = layer; |
70 |
_canvas3d = canvas3d; |
71 |
viewer = canvas3d; |
72 |
viewer.addMouseListener(this);
|
73 |
viewer.addKeyListener(this);
|
74 |
|
75 |
} |
76 |
|
77 |
public void mouseDoubleClick(MouseEvent e) { |
78 |
|
79 |
} |
80 |
|
81 |
public void mouseDown(MouseEvent e) { |
82 |
|
83 |
} |
84 |
|
85 |
public void mouseUp(MouseEvent e) { |
86 |
|
87 |
} |
88 |
|
89 |
public void keyPressed(KeyEvent e) { |
90 |
|
91 |
if (e.getKeyCode() == KeyEvent.VK_SHIFT) { |
92 |
|
93 |
Util.logger.log(Level.INFO, "Control Pressed"); |
94 |
if (Layer3DProps.getLayer3DProps(this._layer).isEditing()) { |
95 |
_lockPick = true;
|
96 |
_handler.setActive(true);
|
97 |
|
98 |
} |
99 |
|
100 |
NavigationMode.removeAllNavigationModes(); |
101 |
} |
102 |
|
103 |
} |
104 |
|
105 |
public void keyReleased(KeyEvent e) { |
106 |
|
107 |
if (e.getKeyCode() == KeyEvent.VK_SHIFT) { |
108 |
|
109 |
if (Layer3DProps.getLayer3DProps(this._layer).isEditing()) { |
110 |
_lockPick = false;
|
111 |
Util.logger.log(Level.INFO, "Control Released"); |
112 |
_handler.setActive(false);
|
113 |
|
114 |
} |
115 |
NavigationMode.restoreAllNavigationModes(); |
116 |
|
117 |
} |
118 |
|
119 |
} |
120 |
|
121 |
public void mouseClicked(MouseEvent e) { |
122 |
ActionCommand command; |
123 |
if (_lockPick) {
|
124 |
|
125 |
try {
|
126 |
if (e.getButton() == MouseEvent.BUTTON1) { |
127 |
Intersections polytopeHits; |
128 |
polytopeHits = viewer.getOSGViewer().rayPick( |
129 |
this._manager.getScene(), e.getX(), e.getY(),
|
130 |
Manipulator.NEG_MANIPULATOR_NODEMASK); |
131 |
|
132 |
if (polytopeHits.containsIntersections()) {
|
133 |
|
134 |
Intersection hit = polytopeHits.getFirstIntersection(); |
135 |
Node nodeHit = (Node) hit.getNodePath().get(1);
|
136 |
System.out.println("Node name: " |
137 |
+ nodeHit.getNodeName()); |
138 |
Group parent;
|
139 |
parent = new Group(nodeHit.getParent(0).getCPtr()); |
140 |
int k;
|
141 |
k = parent.getChildIndex(nodeHit); |
142 |
command = new AddSelectionCommand(k, _manager);
|
143 |
command.execute(); |
144 |
|
145 |
} |
146 |
} |
147 |
} catch (NodeException e2) {
|
148 |
// TODO Auto-generated catch block
|
149 |
e2.printStackTrace(); |
150 |
} |
151 |
} |
152 |
// else if (e.button == 3) {
|
153 |
//
|
154 |
// command = new RemoveAllSelectionCommand(_manager);
|
155 |
// command.execute();
|
156 |
//
|
157 |
//
|
158 |
// }
|
159 |
|
160 |
} |
161 |
|
162 |
public void mouseEntered(MouseEvent e) { |
163 |
// TODO Auto-generated method stub
|
164 |
|
165 |
} |
166 |
|
167 |
public void mouseExited(MouseEvent e) { |
168 |
// TODO Auto-generated method stub
|
169 |
|
170 |
} |
171 |
|
172 |
public void mousePressed(MouseEvent e) { |
173 |
// TODO Auto-generated method stub
|
174 |
|
175 |
} |
176 |
|
177 |
public void mouseReleased(MouseEvent e) { |
178 |
// TODO Auto-generated method stub
|
179 |
|
180 |
} |
181 |
|
182 |
public void keyTyped(KeyEvent e) { |
183 |
// TODO Auto-generated method stub
|
184 |
|
185 |
} |
186 |
|
187 |
} |