Revision 8264

View differences:

trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/gui/RouteReportPanel.java
45 45
*
46 46
* $Id$
47 47
* $Log$
48
* Revision 1.2  2006-10-20 19:54:01  azabala
48
* Revision 1.3  2006-10-23 18:51:42  azabala
49 49
* *** empty log message ***
50 50
*
51
* Revision 1.2  2006/10/20 19:54:01  azabala
52
* *** empty log message ***
53
*
51 54
* Revision 1.1  2006/10/19 19:09:43  azabala
52 55
* *** empty log message ***
53 56
*
......
55 58
*/
56 59
package com.iver.cit.gvsig.graph.gui;
57 60

  
61
import java.awt.BasicStroke;
58 62
import java.awt.BorderLayout;
63
import java.awt.Color;
64
import java.awt.geom.Rectangle2D;
65
import java.text.NumberFormat;
59 66
import java.util.ArrayList;
67
import java.util.Collection;
68
import java.util.Iterator;
69
import java.util.StringTokenizer;
60 70

  
61 71
import javax.swing.JEditorPane;
62 72
import javax.swing.JPanel;
......
70 80
import com.iver.andami.ui.mdiManager.IWindow;
71 81
import com.iver.andami.ui.mdiManager.WindowInfo;
72 82
import com.iver.cit.gvsig.fmap.MapControl;
83
import com.iver.cit.gvsig.fmap.core.FShape;
73 84
import com.iver.cit.gvsig.fmap.core.IFeature;
85
import com.iver.cit.gvsig.fmap.core.IGeometry;
86
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
87
import com.iver.cit.gvsig.fmap.layers.GraphicLayer;
88
import com.iver.cit.gvsig.fmap.rendering.FGraphic;
74 89
import com.iver.cit.gvsig.graph.core.TurnUtil;
75 90
import com.iver.cit.gvsig.graph.solvers.Route;
76 91

  
77 92
public class RouteReportPanel extends JPanel implements IWindow{
78 93
	
94
	private final String START_IMAGE = "<img src=\"images/drapeau_depart.gif\">";
95
	private final String STOP_IMAGE = "<img src=\"images/drapeau_arrivee.gif\">";
96
	private final String LEFT_IMAGE = "<img src=\"images/gtk-go-left.png\">";
97
	private final String RIGHT_IMAGE = "<img src=\"images/gtk-go-right.png\">";
98
	private final String STRAIGHT_IMAGE = "<img src=\"images/gtk-go-up.png\">";
99
	
100
	private final String LINE_SEPARATOR = "<hr width =\"70%\">";
101
	
79 102
	private Route route;
80 103
	
81
	private MapControl mapControl;
82
	
83 104
	private JScrollPane scrollPanel;
84
	
85 105
	private JEditorPane htmlPanel;
106
	private WindowInfo viewInfo;
86 107
	
108
	
87 109
	private String htmlText;
110
	private MapControl mapControl;
88 111
	
89
	private WindowInfo viewInfo;
112
	//Para poder poner duraci?n, etc.
113
	private String weightText = "Longitud:";
90 114
	
115
	//Distancias y costes acumulados (entre dos cambios de calles)
116
	private double acumuledLenght = 0d;
117
	private double acumuledWeight = 0d;
91 118
	
92
	private final String START_IMAGE = "<img src=\"images/drapeau_depart.gif\">";
93
	private final String STOP_IMAGE = "<img src=\"images/drapeau_arrivee.gif\">";
119
	private double totalLenght = 0d;
120
	private double totalWeight = 0d;
94 121
	
122
	
123
	
124
	private int numberOfStreets = 1;//partimos de 1 porque consideramos la salida
125
	private ArrayList tramesOfSameStreet = new ArrayList();
126
	
127
	NumberFormat nf = NumberFormat.getInstance();
128
	
129
	
95 130
	public RouteReportPanel(Route route, MapControl mapControl){
96 131
		super();
97 132
		setLayout(new BorderLayout());
......
102 137
		htmlPanel.setEditable(false);
103 138
		htmlPanel.setEditorKit(new HTMLEditorKit());
104 139
		
140
		nf.setMaximumFractionDigits(2);
141
		
105 142
		final MapControl map = mapControl;
106 143
		final Route routeTemp = route;
107 144
		htmlPanel.addHyperlinkListener(new HyperlinkListener(){
108 145
			public void hyperlinkUpdate(HyperlinkEvent e) {
109 146
				if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
110
			        int indexOfFeature = Integer.parseInt(e.getDescription());
111
			        IFeature feature = (IFeature) routeTemp.getFeatureList().get(indexOfFeature);
112
			        map.getMapContext().getViewPort().setExtent(feature.getGeometry().getBounds2D());
147
					Rectangle2D bounds = null; 
148
					StringTokenizer st = new StringTokenizer(e.getDescription(),",");
149
					ArrayList features = new ArrayList();
150
				     while (st.hasMoreTokens()) {
151
				    	 int indexOfFeature = Integer.parseInt(st.nextToken());
152
				    	 IFeature feature = (IFeature) routeTemp.getFeatureList().get(indexOfFeature);
153
				    	 if(bounds == null)
154
				    		 bounds = feature.getGeometry().getBounds2D();
155
				    	 else
156
				    		 bounds.add(feature.getGeometry().getBounds2D());
157
				    	 features.add(feature);
158
				     }
159
					if(bounds != null){
160
						graphicSelection(features);
161
						map.getMapContext().getViewPort().setExtent(bounds);
162
					}	
113 163
			      }
114 164
			}});
115 165
		initialize();
......
117 167
		add(scrollPanel, BorderLayout.CENTER);
118 168
	}
119 169
	
170
	
120 171
	public void setRoute(Route route){
121 172
		this.route = route;
122 173
		initialize();
......
125 176
	private void initialize(){
126 177
		htmlText = "";
127 178
		ArrayList features = route.getFeatureList();
128
		IFeature firstFeature = (IFeature) features.get(0);
129
		IFeature lastFeature = (IFeature) features.get(features.size() - 1);
179
		
180
		//Route is ordered from the end to the start
181
		IFeature firstFeature = (IFeature) features.get(features.size() - 1);
182
		IFeature lastFeature = (IFeature) features.get(0);
130 183
		renderHeader(firstFeature, lastFeature);
131 184
		renderFirstStrech(firstFeature);
132 185
		IFeature previousFeature = firstFeature;
133
		for(int i = 1; i < features.size() - 1; i++){
134
			renderStrech((IFeature) features.get(i), previousFeature, i+1);
186
		int counter = 1;
187
		for (int i = features.size() - 2; i > 0; i--) {
188
			IFeature feature = (IFeature) features.get(i);
189
			renderStrech(feature , previousFeature, counter);
190
			previousFeature = feature;
191
			counter++;
135 192
		}
193
		
194
		//TODO
195
		//Invertir el FIRST y el LAST
196
		//Borrar el graphics resaltado cuando se resalte otro
197
		
136 198
		renderLastStretch((IFeature)features.get(features.size() -1));
137 199
		htmlPanel.setText(htmlText);
138 200
	}
139 201
	
202
	private void graphicSelection(ArrayList selectedFeature) {
203
		GraphicLayer graphicLayer = mapControl.getMapContext().getGraphicsLayer();
204
		FSymbol lineSymbol = new FSymbol(FShape.LINE, Color.YELLOW);
205
		lineSymbol.setStroke(new BasicStroke(3.0f));
206
		int idSymbolLine = graphicLayer.addSymbol(lineSymbol);
207
		for(int i = 0; i < selectedFeature.size(); i++ ){
208
			IGeometry gAux = ((IFeature)selectedFeature.get(i)).getGeometry();
209
			FGraphic graphic = new FGraphic(gAux, idSymbolLine);
210
			graphicLayer.addGraphic( graphic);
211
		}
212
		mapControl.drawGraphics();
213

  
214
	}
140 215
	
141 216
	
217
	
142 218
	private void renderHeader(IFeature firstFeature, IFeature lastFeature){
143 219
		String startName = firstFeature.getAttribute(Route.TEXT_INDEX).toString();
144 220
		String stopName = lastFeature.getAttribute(Route.TEXT_INDEX).toString();
......
150 226
		htmlText += "</b><br>";
151 227
		htmlText += "Llegada a:<b> ";//TODO INTERNAC
152 228
		htmlText += stopName + "</b><br>";
229
		
230
		//TODO METER LA LONGITUD TOTAL DEL TRAYECTO AQUI
231
		
232
		htmlText += LINE_SEPARATOR;
153 233
	}
154 234
	
155 235
	private void renderFirstStrech(IFeature feature){
......
164 244
		htmlText += "</b></td></tr>";
165 245
		htmlText += "<tr><td><a href=\""+0+"\">Ver sobre el mapa</a><td></tr>";
166 246
		htmlText += "</table>";
247
		htmlText += LINE_SEPARATOR;
248
		
249
		double length = ((DoubleValue)feature.getAttribute(Route.LENGTH_INDEX)).getValue();
250
		double weight = ((DoubleValue)feature.getAttribute(Route.WEIGHT_INDEX)).getValue();
251
		acumuledLenght += length;
252
		acumuledWeight += weight;
253
		
254
		totalLenght += length;
255
		totalWeight += weight;
256
		
257
		tramesOfSameStreet.add(new Integer(0));
167 258
	}
168 259
	
169
	private void renderStrech(IFeature feature, IFeature previousFeature, int numberOfStrech){
170
		int direction = TurnUtil.getDirection(previousFeature, feature);
260
	private void renderStrech(IFeature feature, IFeature previousFeature, int index){
171 261
		String street1 =  previousFeature.getAttribute(Route.TEXT_INDEX).toString();
172 262
		String street2 = feature.getAttribute(Route.TEXT_INDEX).toString();
173
		boolean changeStreet = street1.equalsIgnoreCase(street2);
263
		boolean changeStreet = ! street1.equalsIgnoreCase(street2);
174 264
		double length = ((DoubleValue)feature.getAttribute(Route.LENGTH_INDEX)).getValue();
175 265
		double weight = ((DoubleValue)feature.getAttribute(Route.WEIGHT_INDEX)).getValue();
176 266
		
267
		String textoTramo = null;
268
		String imageTurn = null;
177 269
		
178
		String textoTramo = null;
179
		String imageGiro = null;
180
		if(direction == TurnUtil.GO_STRAIGH_ON){
181
			if(changeStreet){
182
				textoTramo = "Siga recto por <b>"+ street2 + "durante "+length+"</b>";
183
			}else{
184
				textoTramo = "Siga durante <b>"+ length + "y permanezca en "+street2+"</b>";
270
		if(changeStreet){
271
			numberOfStreets++;
272
			String prefix = "Continue durante  "+
273
			nf.format(acumuledLenght)+" y ";
274
			int direction = TurnUtil.getDirection(previousFeature, feature);
275
			if(direction == TurnUtil.GO_STRAIGH_ON){
276
				textoTramo += prefix + " prosiga por<b>"+ street2 + "</b>";
277
				imageTurn = STRAIGHT_IMAGE;
278
				
279
			}else if(direction == TurnUtil.TURN_LEFT){
280
				textoTramo = prefix += " gire a la izquierda por <b>" + street2 + "</b>";
281
				imageTurn = LEFT_IMAGE;
282
				
283
			}else if(direction == TurnUtil.TURN_RIGHT){
284
				textoTramo = prefix += " gire a la derecha por <b>" + street2 + "</b>";
285
				imageTurn = RIGHT_IMAGE;	
185 286
			}
186
		}else if(direction == TurnUtil.TURN_LEFT){
187
			if(changeStreet){
188
				textoTramo = "Gire a la izquierda por " + street2 + "durante " + length;
189
			}else{
190
				textoTramo = "Permanezca en " + street2 + ", gire a la izquierda y continue durante " + length;
287
			htmlText += "<table>";
288
			htmlText += "<tr>";
289
			htmlText += "<td>";
290
			htmlText += imageTurn;
291
			htmlText += "</td>";
292
			htmlText += "<td>";
293
			htmlText += numberOfStreets+" "+textoTramo;//TODO INTERNAC
294
			htmlText += "</td></tr>";
295
			htmlText += "<tr><td>Distancia acumulada:</td><td>"+nf.format(totalLenght)+"</td></tr>";
296
			if(!weightText.equalsIgnoreCase("Longitud:"))
297
				htmlText += "<tr><td>Coste:</td><td>"+nf.format(totalWeight)+"</td></tr>";
298
			String features = "";
299
			for(int i = 0; i < tramesOfSameStreet.size() -1; i++){
300
				int featureIndex = ((Integer) tramesOfSameStreet.get(i)).intValue();
301
				features += featureIndex + ",";
191 302
			}
192
		}else if(direction == TurnUtil.TURN_RIGHT){
193
			if(changeStreet){
194
				textoTramo = "Gire a la derecha por " + street2 + "durante " + length;
195
			}else{
196
				textoTramo = "Permanezca en " + street2 + ", gire a la derecha y continue durante " + length;
197
			}
303
			features += ((Integer)tramesOfSameStreet.get(tramesOfSameStreet.size()-1)).intValue();
304
			htmlText += "<tr><td><a href=\""+features+"\">Ver sobre el mapa</a><td></tr>";
305
			htmlText += "</table>";
306
			htmlText += LINE_SEPARATOR;
307
			
308
			acumuledLenght = length;
309
			acumuledWeight = weight;
310
			tramesOfSameStreet.clear();
311
	
312
			
313
		}else{
314
			acumuledLenght += length;
315
			acumuledWeight += weight;
198 316
		}
199 317
		
200
		htmlText += "<table>";
201
		htmlText += "<tr>";
202
		htmlText += "<td>";
203
		htmlText += STOP_IMAGE;//TODO CAMBIAR POR UNA IMAGEN ADECUADA AL GIRO
204
		htmlText += "</td>";
205
		htmlText += "<td>";
206
		htmlText += numberOfStrech+" "+textoTramo;//TODO INTERNAC
207
		htmlText += "</td></tr>";
208
		htmlText += "<tr><td>Distancia:</td><td>"+length+"</td></tr>";
209
		htmlText += "<tr><td>Coste:</td><td>"+weight+"</td></tr>";
210
		htmlText += "<tr><td><a href=\""+numberOfStrech+"\">Ver sobre el mapa</a><td></tr>";
211
		htmlText += "</table>";
212
		
318
		totalLenght += length;
319
		totalWeight += weight;
320
		tramesOfSameStreet.add(new Integer(index));
213 321
	}
214 322
	
215 323
	
......
219 327
		double length = ((DoubleValue)feature.getAttribute(Route.LENGTH_INDEX)).getValue();
220 328
		double weight = ((DoubleValue)feature.getAttribute(Route.WEIGHT_INDEX)).getValue();
221 329
		
330
		
331
		totalLenght += length;
332
		totalWeight += weight;
333
		
222 334
		htmlText += "<table>";
223 335
		htmlText += "<tr>";
224 336
		htmlText += "<td>";
225 337
		htmlText += STOP_IMAGE;
226 338
		htmlText += "</td>";
227 339
		htmlText += "<td>";
228
		htmlText += route.getFeatureList().size()+". Llegada: ";//TODO INTERNAC
340
		htmlText += numberOfStreets+". Llegada: ";//TODO INTERNAC
229 341
		htmlText += feature.getAttribute(Route.TEXT_INDEX);
230 342
		htmlText += "</td></tr>";
231
		htmlText += "<tr><td>Distancia:</td><td>"+length+"</td></tr>";
232
		htmlText += "<tr><td>Coste:</td><td>"+weight+"</td></tr>";
343
		htmlText += "<tr><td>Longitud:</td><td>"+nf.format(totalLenght)+"</td></tr>";
344
		
345
		if(!weightText.equalsIgnoreCase("Longitud:"))
346
			htmlText += "<tr><td>Coste:</td><td>"+totalWeight+"</td></tr>";
233 347
		htmlText += "<tr><td><a href=\""+(route.getFeatureList().size()-1)+"\">Ver sobre el mapa</a><td></tr>";
234 348
		htmlText += "</table>";
235 349
	}
trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/core/TurnUtil.java
45 45
*
46 46
* $Id$
47 47
* $Log$
48
* Revision 1.1  2006-10-20 19:54:01  azabala
48
* Revision 1.2  2006-10-23 18:51:42  azabala
49 49
* *** empty log message ***
50 50
*
51
* Revision 1.1  2006/10/20 19:54:01  azabala
52
* *** empty log message ***
51 53
*
54
*
52 55
*/
53 56
package com.iver.cit.gvsig.graph.core;
54 57

  
......
85 88
	    Coordinate p0 = coords1[coords1.length -2];
86 89
	    Coordinate p1 = coords1[coords1.length -1];
87 90
	    Coordinate[] coords2 = geom2.getCoordinates();
88
	    Coordinate p2 = coords2[0];
91
	    Coordinate p2 = coords2[1];
89 92
	    
90 93
		 double dx = p1.x - p0.x;
91 94
	     double dy = p1.y - p0.y;

Also available in: Unified diff