root / trunk / extensions / extGraph_predes / src / com / iver / cit / gvsig / graph / tools / FlagListener.java @ 8261
History | View | Annotate | Download (4.85 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.graph.tools; |
42 |
|
43 |
import java.awt.Color; |
44 |
import java.awt.Cursor; |
45 |
import java.awt.Image; |
46 |
import java.awt.geom.Point2D; |
47 |
|
48 |
import javax.swing.ImageIcon; |
49 |
import javax.swing.JOptionPane; |
50 |
|
51 |
import com.iver.andami.messages.NotificationManager; |
52 |
import com.iver.andami.plugins.PluginClassLoader; |
53 |
import com.iver.cit.gvsig.fmap.MapControl; |
54 |
import com.iver.cit.gvsig.fmap.core.FShape; |
55 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
56 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
57 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
58 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
59 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
60 |
import com.iver.cit.gvsig.fmap.layers.GraphicLayer; |
61 |
import com.iver.cit.gvsig.fmap.layers.SingleLayerIterator; |
62 |
import com.iver.cit.gvsig.fmap.rendering.FGraphic; |
63 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
64 |
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent; |
65 |
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener; |
66 |
import com.iver.cit.gvsig.graph.GraphException; |
67 |
import com.iver.cit.gvsig.graph.core.GvFlag; |
68 |
import com.iver.cit.gvsig.graph.core.Network; |
69 |
|
70 |
public class FlagListener implements PointListener { |
71 |
public static int pixelTolerance = 10; |
72 |
private MapControl mapCtrl;
|
73 |
private int idSymbolFlag = -1; |
74 |
private Cursor cur = java.awt.Cursor.getPredefinedCursor(Cursor.HAND_CURSOR); |
75 |
|
76 |
|
77 |
public FlagListener(MapControl mc) {
|
78 |
this.mapCtrl = mc;
|
79 |
} |
80 |
|
81 |
|
82 |
/* (non-Javadoc)
|
83 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
|
84 |
* The PointEvent method bring you a point in pixel coordinates. You
|
85 |
* need to transform it to world coordinates. The class to do conversions
|
86 |
* is ViewPort, obtained thru the MapContext of mapCtrl.
|
87 |
*/
|
88 |
public void point(PointEvent event) throws BehaviorException { |
89 |
|
90 |
Point2D pReal = mapCtrl.getMapContext().getViewPort().toMapPoint(event.getPoint());
|
91 |
|
92 |
SingleLayerIterator it = new SingleLayerIterator(mapCtrl.getMapContext().getLayers());
|
93 |
while (it.hasNext())
|
94 |
{ |
95 |
FLayer aux = it.next(); |
96 |
if (!aux.isActive())
|
97 |
continue;
|
98 |
Network net = (Network) aux.getProperty("network");
|
99 |
|
100 |
if ( net != null) |
101 |
{ |
102 |
double realTol = mapCtrl.getViewPort().toMapDistance(pixelTolerance);
|
103 |
GvFlag flag; |
104 |
try {
|
105 |
flag = net.addFlag(pReal.getX(), pReal.getY(), realTol); |
106 |
if (flag == null) |
107 |
{ |
108 |
JOptionPane.showMessageDialog(null, "No est? sobre la red"); |
109 |
return;
|
110 |
} |
111 |
GraphicLayer graphicLayer = mapCtrl.getMapContext().getGraphicsLayer(); |
112 |
if (idSymbolFlag == -1) |
113 |
{ |
114 |
FSymbol simFlag = new FSymbol(FShape.POINT, Color.BLUE); |
115 |
simFlag.setSize(24);
|
116 |
// simFlag.setStyle(FConstant.SYMBOL_STYLE_MARKER_SQUARE);
|
117 |
// simFlag.setFill(null);
|
118 |
// simFlag.setOutlined(true);
|
119 |
// simFlag.setOutlineColor(Color.BLUE);
|
120 |
|
121 |
simFlag.setStyle(FConstant.SYMBOL_STYLE_MARKER_IMAGEN); |
122 |
ImageIcon icon = new ImageIcon(this.getClass().getClassLoader() |
123 |
.getResource("images/pushpin.png"));
|
124 |
simFlag.setIcon(icon.getImage()); |
125 |
|
126 |
idSymbolFlag = graphicLayer.addSymbol(simFlag); |
127 |
} |
128 |
IGeometry gAux = ShapeFactory.createPoint2D(pReal.getX(), pReal.getY()); |
129 |
FGraphic graphic = new FGraphic(gAux, idSymbolFlag);
|
130 |
graphicLayer.addGraphic(graphic); |
131 |
mapCtrl.drawGraphics(); |
132 |
} catch (GraphException e) {
|
133 |
e.printStackTrace(); |
134 |
NotificationManager.addError(e); |
135 |
} |
136 |
|
137 |
} |
138 |
} |
139 |
|
140 |
|
141 |
} |
142 |
|
143 |
public Cursor getCursor() { |
144 |
return cur;
|
145 |
} |
146 |
|
147 |
public boolean cancelDrawing() { |
148 |
return false; |
149 |
} |
150 |
|
151 |
|
152 |
public void pointDoubleClick(PointEvent event) throws BehaviorException { |
153 |
|
154 |
} |
155 |
|
156 |
} |
157 |
|
158 |
|