svn-gvsig-desktop / tags / v1_1_2_Build_1044 / prototypes / VectorialAvanzado / extensions / extGraph / src / com / iver / cit / gvsig / graph / tools / BarrierListener.java @ 20099
History | View | Annotate | Download (4.79 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.PluginServices; |
52 |
import com.iver.andami.messages.NotificationManager; |
53 |
import com.iver.andami.plugins.PluginClassLoader; |
54 |
import com.iver.cit.gvsig.fmap.MapControl; |
55 |
import com.iver.cit.gvsig.fmap.core.FShape; |
56 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
57 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
58 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
59 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
60 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
61 |
import com.iver.cit.gvsig.fmap.layers.GraphicLayer; |
62 |
import com.iver.cit.gvsig.fmap.layers.SingleLayerIterator; |
63 |
import com.iver.cit.gvsig.fmap.rendering.FGraphic; |
64 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
65 |
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent; |
66 |
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener; |
67 |
import com.iver.cit.gvsig.graph.core.EdgePair; |
68 |
import com.iver.cit.gvsig.graph.core.GraphException; |
69 |
import com.iver.cit.gvsig.graph.core.GvEdge; |
70 |
import com.iver.cit.gvsig.graph.core.GvFlag; |
71 |
import com.iver.cit.gvsig.graph.core.Network; |
72 |
|
73 |
public class BarrierListener implements PointListener { |
74 |
private MapControl mapCtrl;
|
75 |
|
76 |
private int idSymbolBarrier = -1; |
77 |
|
78 |
private Cursor cur = java.awt.Cursor |
79 |
.getPredefinedCursor(Cursor.HAND_CURSOR);
|
80 |
|
81 |
public BarrierListener(MapControl mc) {
|
82 |
this.mapCtrl = mc;
|
83 |
} |
84 |
|
85 |
/*
|
86 |
* (non-Javadoc)
|
87 |
*
|
88 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
|
89 |
* The PointEvent method bring you a point in pixel coordinates. You
|
90 |
* need to transform it to world coordinates. The class to do
|
91 |
* conversions is ViewPort, obtained thru the MapContext of mapCtrl.
|
92 |
*/
|
93 |
public void point(PointEvent event) throws BehaviorException { |
94 |
|
95 |
Point2D pReal = mapCtrl.getMapContext().getViewPort().toMapPoint(
|
96 |
event.getPoint()); |
97 |
|
98 |
SingleLayerIterator it = new SingleLayerIterator(mapCtrl
|
99 |
.getMapContext().getLayers()); |
100 |
while (it.hasNext()) {
|
101 |
FLayer aux = it.next(); |
102 |
if (!aux.isActive())
|
103 |
continue;
|
104 |
Network net = (Network) aux.getProperty("network");
|
105 |
|
106 |
if (net != null) { |
107 |
Point2D nearestPoint = new Point2D.Double(); |
108 |
double realTol = mapCtrl.getViewPort().toMapDistance(
|
109 |
FlagListener.pixelTolerance); |
110 |
int idArc = net.findClosestArc(pReal.getX(), pReal.getY(),
|
111 |
realTol, nearestPoint); |
112 |
if (idArc == -1) { |
113 |
JOptionPane.showMessageDialog(null, "No est? sobre la red"); |
114 |
return;
|
115 |
} |
116 |
|
117 |
net.addModifiedCost(idArc, -1.0, 3); |
118 |
GraphicLayer graphicLayer = mapCtrl.getMapContext() |
119 |
.getGraphicsLayer(); |
120 |
if (idSymbolBarrier == -1) { |
121 |
FSymbol simFlag = new FSymbol(FShape.POINT, Color.BLUE); |
122 |
simFlag.setSize(16);
|
123 |
simFlag.setStyle(FConstant.SYMBOL_STYLE_MARKER_IMAGEN); |
124 |
ImageIcon icon = new ImageIcon(this.getClass() |
125 |
.getClassLoader().getResource("images/barrier.png"));
|
126 |
simFlag.setIcon(icon.getImage()); |
127 |
|
128 |
idSymbolBarrier = graphicLayer.addSymbol(simFlag); |
129 |
} |
130 |
IGeometry gAux = ShapeFactory.createPoint2D(nearestPoint.getX(), |
131 |
nearestPoint.getY()); |
132 |
FGraphic graphic = new FGraphic(gAux, idSymbolBarrier);
|
133 |
graphic.setTag("BARRIER");
|
134 |
graphicLayer.addGraphic(graphic); |
135 |
mapCtrl.drawGraphics(); |
136 |
PluginServices.getMainFrame().enableControls(); |
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 |
public void pointDoubleClick(PointEvent event) throws BehaviorException { |
152 |
|
153 |
} |
154 |
|
155 |
} |