svn-gvsig-desktop / trunk / extensions / extGraph / src / org / gvsig / graph / gui / RouteReportPanel.java @ 24989
History | View | Annotate | Download (15.2 KB)
1 |
/*
|
---|---|
2 |
* Created on 19-oct-2006
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
/* CVS MESSAGES:
|
45 |
*
|
46 |
* $Id: RouteReportPanel.java 24989 2008-11-12 12:28:13Z jcampos $
|
47 |
* $Log$
|
48 |
* Revision 1.15 2007-09-07 11:29:47 fjp
|
49 |
* Casi compila. Falta arreglar lo de FArrowSymbol y retocar el graphiclist de FMap.
|
50 |
*
|
51 |
* Revision 1.14 2006/11/20 08:44:55 fjp
|
52 |
* borrar tramos amarillos, seleccionar solo campos num?ricos y situar las barreras encima del tramo invalidado
|
53 |
*
|
54 |
* Revision 1.13 2006/11/14 16:12:01 fjp
|
55 |
* *** empty log message ***
|
56 |
*
|
57 |
* Revision 1.12 2006/11/08 16:48:20 fjp
|
58 |
* *** empty log message ***
|
59 |
*
|
60 |
* Revision 1.11 2006/11/06 17:19:02 fjp
|
61 |
* Depurando el aspecto
|
62 |
*
|
63 |
* Revision 1.10 2006/11/06 13:21:38 fjp
|
64 |
* detalles
|
65 |
*
|
66 |
* Revision 1.9 2006/10/27 10:17:27 fjp
|
67 |
* Correcto. Falta ponerlo bonito.
|
68 |
*
|
69 |
* Revision 1.8 2006/10/26 17:47:14 fjp
|
70 |
* previo a formato
|
71 |
*
|
72 |
* Revision 1.7 2006/10/26 11:42:42 fjp
|
73 |
* Ya pita, ya.
|
74 |
*
|
75 |
* Revision 1.6 2006/10/25 15:51:20 fjp
|
76 |
* por terminar lo de los giros
|
77 |
*
|
78 |
* Revision 1.5 2006/10/25 14:47:34 fjp
|
79 |
* *** empty log message ***
|
80 |
*
|
81 |
* Revision 1.4 2006/10/24 18:42:05 azabala
|
82 |
* *** empty log message ***
|
83 |
*
|
84 |
* Revision 1.3 2006/10/23 18:51:42 azabala
|
85 |
* *** empty log message ***
|
86 |
*
|
87 |
* Revision 1.2 2006/10/20 19:54:01 azabala
|
88 |
* *** empty log message ***
|
89 |
*
|
90 |
* Revision 1.1 2006/10/19 19:09:43 azabala
|
91 |
* *** empty log message ***
|
92 |
*
|
93 |
*
|
94 |
*/
|
95 |
package org.gvsig.graph.gui; |
96 |
|
97 |
import java.awt.BorderLayout; |
98 |
import java.awt.Color; |
99 |
import java.awt.geom.Rectangle2D; |
100 |
import java.text.NumberFormat; |
101 |
import java.util.ArrayList; |
102 |
import java.util.StringTokenizer; |
103 |
|
104 |
import javax.swing.JEditorPane; |
105 |
import javax.swing.JPanel; |
106 |
import javax.swing.JScrollPane; |
107 |
import javax.swing.event.HyperlinkEvent; |
108 |
import javax.swing.event.HyperlinkListener; |
109 |
|
110 |
import org.gvsig.graph.core.TurnUtil; |
111 |
import org.gvsig.graph.solvers.Route; |
112 |
|
113 |
import com.hardcode.gdbms.engine.values.DoubleValue; |
114 |
import com.iver.andami.ui.mdiManager.IWindow; |
115 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
116 |
import com.iver.cit.gvsig.fmap.MapControl; |
117 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
118 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
119 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
120 |
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol; |
121 |
import com.iver.cit.gvsig.fmap.layers.GraphicLayer; |
122 |
import com.iver.cit.gvsig.fmap.rendering.FGraphic; |
123 |
|
124 |
public class RouteReportPanel extends JPanel implements IWindow{ |
125 |
|
126 |
private final String START_IMAGE = "<img src=\"images/drapeau_depart.gif\">"; |
127 |
private final String STOP_IMAGE = "<img src=\"images/drapeau_arrivee.gif\">"; |
128 |
private final String LEFT_IMAGE = "<img src=\"images/turn-left.png\">"; |
129 |
private final String RIGHT_IMAGE = "<img src=\"images/turn-right.png\">"; |
130 |
private final String STRAIGHT_IMAGE = "<img src=\"images/gtk-go-up.png\">"; |
131 |
|
132 |
private final String LINE_SEPARATOR = "<hr width =\"70%\">"; |
133 |
|
134 |
private Route route;
|
135 |
|
136 |
private JScrollPane scrollPanel; |
137 |
private JEditorPane htmlPanel; |
138 |
private WindowInfo viewInfo;
|
139 |
|
140 |
|
141 |
private String htmlText; |
142 |
private MapControl mapControl;
|
143 |
|
144 |
//Para poder poner duraci?n, etc.
|
145 |
private String weightText = "Longitud:"; |
146 |
|
147 |
//Distancias y costes acumulados (entre dos cambios de calles)
|
148 |
private double acumuledLenght = 0d; |
149 |
private double acumuledWeight = 0d; |
150 |
|
151 |
private double totalLenght = 0d; |
152 |
private double totalWeight = 0d; |
153 |
|
154 |
|
155 |
|
156 |
private int numberOfStreets = 1;//partimos de 1 porque consideramos la salida |
157 |
private ArrayList tramesOfSameStreet = new ArrayList(); |
158 |
|
159 |
NumberFormat nf = NumberFormat.getInstance(); |
160 |
|
161 |
|
162 |
public RouteReportPanel(Route route, MapControl mapControl){
|
163 |
super();
|
164 |
setLayout(new BorderLayout()); |
165 |
this.route = route;
|
166 |
this.mapControl = mapControl;
|
167 |
scrollPanel = new JScrollPane(); |
168 |
htmlPanel = new JEditorPane(); |
169 |
htmlPanel.setEditable(false);
|
170 |
htmlPanel.setEditorKit(new HTMLEditorKit()); |
171 |
|
172 |
nf.setMaximumFractionDigits(2);
|
173 |
|
174 |
final MapControl map = mapControl;
|
175 |
final Route routeTemp = route;
|
176 |
final MapControl mapControlTemp = mapControl;
|
177 |
htmlPanel.addHyperlinkListener(new HyperlinkListener(){ |
178 |
ArrayList previousSelection;
|
179 |
public void hyperlinkUpdate(HyperlinkEvent e) { |
180 |
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { |
181 |
Rectangle2D bounds = null; |
182 |
StringTokenizer st = new StringTokenizer(e.getDescription(),","); |
183 |
System.err.println("E.GETDESCRIPTION():" + e.getDescription()); |
184 |
ArrayList features = new ArrayList(); |
185 |
while (st.hasMoreTokens()) {
|
186 |
int indexOfFeature = Integer.parseInt(st.nextToken()); |
187 |
IFeature feature = (IFeature) routeTemp.getFeatureList().get(indexOfFeature); |
188 |
if(bounds == null) |
189 |
bounds = feature.getGeometry().getBounds2D(); |
190 |
else
|
191 |
bounds.add(feature.getGeometry().getBounds2D()); |
192 |
features.add(feature); |
193 |
} |
194 |
if(bounds != null){ |
195 |
bounds = expand(bounds); |
196 |
GraphicLayer graphicLayer = mapControlTemp.getMapContext().getGraphicsLayer(); |
197 |
if(previousSelection != null){ |
198 |
for(int i = 0; i < previousSelection.size(); i++){ |
199 |
graphicLayer.removeGraphic((FGraphic) previousSelection.get(i)); |
200 |
} |
201 |
} |
202 |
previousSelection = new ArrayList(); |
203 |
|
204 |
ILineSymbol lineSymbol = SymbologyFactory.createDefaultLineSymbol(); |
205 |
lineSymbol.setLineColor(Color.YELLOW);
|
206 |
lineSymbol.setLineWidth(3.0f);
|
207 |
int idSymbolLine = graphicLayer.addSymbol(lineSymbol);
|
208 |
for(int i = 0; i < features.size(); i++ ){ |
209 |
IGeometry gAux = ((IFeature)features.get(i)).getGeometry(); |
210 |
FGraphic graphic = new FGraphic(gAux, idSymbolLine);
|
211 |
graphic.setTag("ROUTE");
|
212 |
graphicLayer.addGraphic( graphic); |
213 |
previousSelection.add(graphic); |
214 |
} |
215 |
mapControlTemp.drawGraphics(); |
216 |
map.getMapContext().getViewPort().setExtent(bounds); |
217 |
} |
218 |
} |
219 |
}}); |
220 |
initialize(); |
221 |
scrollPanel.setViewportView(htmlPanel); |
222 |
add(scrollPanel, BorderLayout.CENTER);
|
223 |
} |
224 |
|
225 |
|
226 |
private Rectangle2D expand(Rectangle2D rect){ |
227 |
double xmin = rect.getMinX();
|
228 |
double ymin = rect.getMinY();
|
229 |
double width = rect.getWidth();
|
230 |
double height = rect.getHeight();
|
231 |
|
232 |
xmin -= width ; |
233 |
ymin -= height ; |
234 |
double newWidth = width * 2; |
235 |
double newHeight = height * 2 ; |
236 |
return new Rectangle2D.Double(xmin, ymin, newWidth, newHeight); |
237 |
} |
238 |
|
239 |
|
240 |
public void setRoute(Route route){ |
241 |
this.route = route;
|
242 |
initialize(); |
243 |
} |
244 |
|
245 |
private void initialize(){ |
246 |
htmlText = "<head>";
|
247 |
htmlText += "<style type='text/css'>";
|
248 |
htmlText += "<!-- ";
|
249 |
htmlText += " .normal { ";
|
250 |
htmlText += " font-family: Arial, Helvetica, sans-serif; font-size: 10px; font-style: normal; color: #333333;";
|
251 |
htmlText += "}";
|
252 |
htmlText += " a { ";
|
253 |
htmlText += " font-family: Arial, Helvetica, sans-serif; font-size: 10px; font-style: italic; font-weight: bold;";
|
254 |
htmlText += "}";
|
255 |
htmlText += " h1 { ";
|
256 |
htmlText += " font-family: Arial, Helvetica, sans-serif; font-size: 14px;";
|
257 |
htmlText += "}";
|
258 |
htmlText += " .distancia { ";
|
259 |
htmlText += " font-family: Arial, Helvetica, sans-serif; font-size: 10px; color: #666666;";
|
260 |
htmlText += "}";
|
261 |
htmlText += " .resumen { ";
|
262 |
htmlText += " font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #333333;";
|
263 |
htmlText += "}";
|
264 |
htmlText += " .left { ";
|
265 |
htmlText += " font-weight: bold; color: #990000;";
|
266 |
htmlText += "}";
|
267 |
htmlText += " .right { ";
|
268 |
htmlText += " font-weight: bold; color: #0033FF;";
|
269 |
htmlText += "}";
|
270 |
|
271 |
htmlText += " -->";
|
272 |
htmlText += "</style>";
|
273 |
htmlText += "</head>";
|
274 |
htmlText += "<body>";
|
275 |
ArrayList features = route.getFeatureList();
|
276 |
|
277 |
//Route is ordered from the the start to the end
|
278 |
IFeature firstFeature = (IFeature) features.get(0);
|
279 |
IFeature lastFeature = (IFeature) features.get(features.size() - 1);
|
280 |
|
281 |
renderHeader(firstFeature, lastFeature); |
282 |
renderFirstStrech(firstFeature); |
283 |
|
284 |
IFeature previousFeature = firstFeature; |
285 |
for (int i = 1; i < features.size() ; i++) { |
286 |
IFeature feature = (IFeature) features.get(i); |
287 |
renderStrech(feature , previousFeature, i); |
288 |
previousFeature = feature; |
289 |
} |
290 |
|
291 |
//TODO
|
292 |
//Invertir el FIRST y el LAST
|
293 |
//Borrar el graphics resaltado cuando se resalte otro
|
294 |
renderLastStretch((IFeature)features.get(features.size() -1), previousFeature);
|
295 |
htmlText += "</body>";
|
296 |
System.out.println(htmlText);
|
297 |
htmlPanel.setText(htmlText); |
298 |
|
299 |
} |
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
private void renderHeader(IFeature firstFeature, IFeature lastFeature){ |
306 |
String startName = firstFeature.getAttribute(Route.TEXT_INDEX).toString();
|
307 |
String stopName = lastFeature.getAttribute(Route.TEXT_INDEX).toString();
|
308 |
htmlText += "<h1>";
|
309 |
htmlText += "Informe de Ruta:" + startName + "-" + stopName ;//TODO INTERNACIONALIZAR ESTO |
310 |
htmlText += "</h1><br>";
|
311 |
htmlText += "<span class='resumen'>Salida desde: <b>";//TODO INTERNAC |
312 |
htmlText += startName; |
313 |
htmlText += "</b><br>";
|
314 |
htmlText += "Llegada a:<b> ";//TODO INTERNAC |
315 |
htmlText += stopName + "</b><br>";
|
316 |
|
317 |
//TODO METER LA LONGITUD TOTAL DEL TRAYECTO AQUI
|
318 |
htmlText += "Longitud total del trayecto: <b>" + nf.format(getLengthOfRoute()) + "</b></span>"; |
319 |
htmlText += LINE_SEPARATOR; |
320 |
} |
321 |
|
322 |
private double getLengthOfRoute() { |
323 |
double solution = 0d; |
324 |
ArrayList featureList = route.getFeatureList();
|
325 |
for(int i = 0; i < featureList.size(); i++){ |
326 |
IFeature feature = (IFeature) featureList.get(i); |
327 |
solution += ((DoubleValue)feature.getAttribute(Route.LENGTH_INDEX)).getValue(); |
328 |
} |
329 |
return solution;
|
330 |
} |
331 |
|
332 |
|
333 |
private void renderFirstStrech(IFeature feature){ |
334 |
htmlText += "<table>";
|
335 |
htmlText += "<tr>";
|
336 |
htmlText += "<td width='40'>";
|
337 |
htmlText += START_IMAGE; |
338 |
htmlText += "</td>";
|
339 |
htmlText += "<td class='normal'>";
|
340 |
htmlText += "1. Salir de:<b> ";//TODO INTERNAC |
341 |
htmlText += feature.getAttribute(Route.TEXT_INDEX); |
342 |
htmlText += "</b></td></tr>";
|
343 |
htmlText += "<tr>";
|
344 |
htmlText += "<td width='40'></td><td><a href=\""+0+"\">Ver sobre el mapa</a><td></tr>"; |
345 |
htmlText += "</table>";
|
346 |
htmlText += LINE_SEPARATOR; |
347 |
|
348 |
double length = ((DoubleValue)feature.getAttribute(Route.LENGTH_INDEX)).getValue();
|
349 |
double weight = ((DoubleValue)feature.getAttribute(Route.WEIGHT_INDEX)).getValue();
|
350 |
acumuledLenght += length; |
351 |
acumuledWeight += weight; |
352 |
|
353 |
totalLenght += length; |
354 |
totalWeight += weight; |
355 |
|
356 |
tramesOfSameStreet.add(new Integer(0)); |
357 |
} |
358 |
|
359 |
private void renderStrech(IFeature feature, IFeature previousFeature, int index){ |
360 |
String street1 = previousFeature.getAttribute(Route.TEXT_INDEX).toString();
|
361 |
String street2 = feature.getAttribute(Route.TEXT_INDEX).toString();
|
362 |
boolean changeStreet = ! street1.equalsIgnoreCase(street2);
|
363 |
double length = ((DoubleValue)feature.getAttribute(Route.LENGTH_INDEX)).getValue();
|
364 |
double weight = ((DoubleValue)feature.getAttribute(Route.WEIGHT_INDEX)).getValue();
|
365 |
|
366 |
String textoTramo = null; |
367 |
String imageTurn = null; |
368 |
|
369 |
if(changeStreet){
|
370 |
numberOfStreets++; |
371 |
String prefix = "Contin?e por <b>" + street1 + "</b> durante "+ |
372 |
nf.format(acumuledLenght)+" y ";
|
373 |
int direction = TurnUtil.getDirection(previousFeature, feature);
|
374 |
|
375 |
if(direction == TurnUtil.GO_STRAIGH_ON){
|
376 |
textoTramo = prefix + " prosiga por <b>"+ street2 + "</b>"; |
377 |
imageTurn = STRAIGHT_IMAGE; |
378 |
|
379 |
}else if(direction == TurnUtil.TURN_LEFT){ |
380 |
textoTramo = prefix += " gire a la <span class='left'><b>izquierda</b></span> por <b>" + street2 + "</b>"; |
381 |
imageTurn = LEFT_IMAGE; |
382 |
|
383 |
}else if(direction == TurnUtil.TURN_RIGHT){ |
384 |
textoTramo = prefix += " gire a la <span class='right'><b>derecha</b></span> por <b>" + street2 + "</b>"; |
385 |
imageTurn = RIGHT_IMAGE; |
386 |
} |
387 |
htmlText += "<table>";
|
388 |
htmlText += "<tr>";
|
389 |
htmlText += "<td width='40'>";
|
390 |
htmlText += imageTurn; |
391 |
htmlText += "</td>";
|
392 |
htmlText += "<td class='normal'>";
|
393 |
htmlText += numberOfStreets+" "+textoTramo;//TODO INTERNAC |
394 |
htmlText += "</td></tr>";
|
395 |
htmlText += "<tr>";
|
396 |
htmlText += "<td with='40'></td><td class='distancia'>Distancia acumulada:"+nf.format(totalLenght)+"</td></tr>"; |
397 |
|
398 |
if(!weightText.equalsIgnoreCase("Longitud:")) |
399 |
{ |
400 |
htmlText += "<tr>";
|
401 |
htmlText += "<td with='40'></td><td class='distancia'>Coste:"+nf.format(totalWeight)+"</td></tr>"; |
402 |
} |
403 |
|
404 |
String features = ""; |
405 |
for(int i = 0; i < tramesOfSameStreet.size() -1; i++){ |
406 |
int featureIndex = ((Integer) tramesOfSameStreet.get(i)).intValue(); |
407 |
features += featureIndex + ",";
|
408 |
} |
409 |
|
410 |
features += ((Integer)tramesOfSameStreet.get(tramesOfSameStreet.size()-1)).intValue(); |
411 |
// System.out.println("features = " + features);
|
412 |
htmlText += "<tr><td with='40'></td><td><a href=\""+features+"\">Ver sobre el mapa</a><td></tr>"; |
413 |
htmlText += "</table>";
|
414 |
htmlText += LINE_SEPARATOR; |
415 |
|
416 |
acumuledLenght = length; |
417 |
acumuledWeight = weight; |
418 |
tramesOfSameStreet.clear(); |
419 |
|
420 |
|
421 |
}else{
|
422 |
acumuledLenght += length; |
423 |
acumuledWeight += weight; |
424 |
} |
425 |
|
426 |
tramesOfSameStreet.add(new Integer(index)); |
427 |
totalLenght += length; |
428 |
totalWeight += weight; |
429 |
|
430 |
} |
431 |
|
432 |
|
433 |
|
434 |
private void renderLastStretch(IFeature feature, IFeature previousFeature){ |
435 |
|
436 |
// double length = ((DoubleValue)feature.getAttribute(Route.LENGTH_INDEX)).getValue();
|
437 |
// double weight = ((DoubleValue)feature.getAttribute(Route.WEIGHT_INDEX)).getValue();
|
438 |
//
|
439 |
//
|
440 |
// totalLenght += length;
|
441 |
// totalWeight += weight;
|
442 |
|
443 |
htmlText += "<table>";
|
444 |
htmlText += "<tr>";
|
445 |
htmlText += "<td width='40'>";
|
446 |
htmlText += STOP_IMAGE; |
447 |
htmlText += "</td>";
|
448 |
htmlText += "<td>";
|
449 |
htmlText += numberOfStreets+". Llegada: ";//TODO INTERNAC |
450 |
htmlText += feature.getAttribute(Route.TEXT_INDEX); |
451 |
htmlText += "</td></tr>";
|
452 |
htmlText += "<tr><td with='40'></td><td>Longitud:"+nf.format(totalLenght)+"</td></tr>"; |
453 |
|
454 |
if(!weightText.equalsIgnoreCase("Longitud:")) |
455 |
htmlText += "<tr><td with='40'></td><td class='distancia'>Coste:"+totalWeight+"</td></tr>"; |
456 |
htmlText += "<tr><td with='40'></td><td><a href=\""+(route.getFeatureList().size()-1)+"\">Ver sobre el mapa</a><td></tr>"; |
457 |
htmlText += "</table>";
|
458 |
} |
459 |
|
460 |
public WindowInfo getWindowInfo() {
|
461 |
if (viewInfo == null) { |
462 |
viewInfo = new WindowInfo(WindowInfo.MODELESSDIALOG |
|
463 |
WindowInfo.RESIZABLE | |
464 |
WindowInfo.MAXIMIZABLE | |
465 |
WindowInfo.ICONIFIABLE | |
466 |
WindowInfo.PALETTE); |
467 |
viewInfo.setTitle("Informe de la ruta calculada");//Internacionalizar esto |
468 |
viewInfo.setWidth(400);
|
469 |
viewInfo.setHeight(350);
|
470 |
} |
471 |
return viewInfo;
|
472 |
} |
473 |
|
474 |
public Object getWindowProfile() { |
475 |
return WindowInfo.TOOL_PROFILE;
|
476 |
} |
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 |
} |
483 |
|