Statistics
| Revision:

svn-gvsig-desktop / tags / 3D_Animation_v1_0alpha_Build_5 / libraries / lib3DMap / src / org / gvsig / gvsig3d / listener / EditorListener.java @ 25534

History | View | Annotate | Download (4.26 KB)

1 23309 jcampos
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.gvsig.gvsig3d.navigation.NavigationMode;
37
import org.gvsig.osgvp.ActionCommand;
38
import org.gvsig.osgvp.Group;
39
import org.gvsig.osgvp.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.util.Util;
47
import org.gvsig.osgvp.viewer.IViewerContainer;
48
import org.gvsig.osgvp.viewer.Intersection;
49
import org.gvsig.osgvp.viewer.Intersections;
50
51
public class EditorListener implements MouseListener, KeyListener {
52
53
        private boolean _lockPick = false;
54
        private EditionManager _manager;
55
        private ManipulatorHandler _handler;
56
        private IViewerContainer viewer;
57
58
59
        public EditorListener(EditionManager manager, ManipulatorHandler handler,
60
                        IViewerContainer canvas3d) {
61
62
                _manager = manager;
63
                _handler = handler;
64
                viewer = canvas3d;
65
                viewer.addMouseListener(this);
66
                viewer.addKeyListener(this);
67
68
        }
69
70
        public void mouseDoubleClick(MouseEvent e) {
71
72
        }
73
74
        public void mouseDown(MouseEvent e) {
75
76
        }
77
78
        public void mouseUp(MouseEvent e) {
79
80
        }
81
82
        public void keyPressed(KeyEvent e) {
83
84
                if (e.getKeyCode() == KeyEvent.VK_SHIFT) {
85
86
                        _lockPick = true;
87
                        Util.logger.log(Level.INFO, "Control Pressed");
88
                        _handler.setActive(true);
89
                        NavigationMode.removeAllNavigationModes();
90
91
                }
92
93
        }
94
95
        public void keyReleased(KeyEvent e) {
96
97
                if (e.getKeyCode() == KeyEvent.VK_SHIFT) {
98
99
                        _lockPick = false;
100
                        Util.logger.log(Level.INFO, "Control Released");
101
                        _handler.setActive(false);
102
                        NavigationMode.restoreAllNavigationModes();
103
                }
104
105
        }
106
107
        public void mouseClicked(MouseEvent e) {
108
                ActionCommand command;
109
                if (_lockPick) {
110
111
                        try {
112
                                if (e.getButton() == MouseEvent.BUTTON1) {
113
                                        Intersections polytopeHits;
114
                                        polytopeHits = viewer.getOSGViewer().rayPick(
115
                                                        this._manager.getScene(), e.getX(), e.getY(),
116
                                                        Manipulator.NEG_MANIPULATOR_NODEMASK);
117
118
                                        if (polytopeHits.containsIntersections()) {
119
120
                                                Intersection hit = polytopeHits.getFirstIntersection();
121 24105 jcampos
                                                Node nodeHit = (Node) hit.getNodePath().get(4);
122 23309 jcampos
                                                Group parent;
123
                                                parent = new Group(nodeHit.getParent(0).getCPtr());
124
                                                int k;
125
                                                k = parent.getChildIndex(nodeHit);
126
                                                command = new AddSelectionCommand(k, _manager);
127
                                                command.execute();
128
129
                                        }
130
                                }
131
                        } catch (NodeException e2) {
132
                                // TODO Auto-generated catch block
133
                                e2.printStackTrace();
134
                        }
135
                }
136
//                 else if (e.button == 3) {
137
//
138
//                 command = new RemoveAllSelectionCommand(_manager);
139
//                 command.execute();
140
//
141
//
142
//                 }
143
144
        }
145
146
        public void mouseEntered(MouseEvent e) {
147
                // TODO Auto-generated method stub
148
149
        }
150
151
        public void mouseExited(MouseEvent e) {
152
                // TODO Auto-generated method stub
153
154
        }
155
156
        public void mousePressed(MouseEvent e) {
157
                // TODO Auto-generated method stub
158
159
        }
160
161
        public void mouseReleased(MouseEvent e) {
162
                // TODO Auto-generated method stub
163
164
        }
165
166
        public void keyTyped(KeyEvent e) {
167
                // TODO Auto-generated method stub
168
169
        }
170
171
}