Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGraph_predes / src / com / iver / cit / gvsig / graph / gui / RouteReportPanel.java @ 8215

History | View | Annotate | Download (7.83 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 8215 2006-10-20 19:54:01Z azabala $
47
* $Log$
48
* Revision 1.2  2006-10-20 19:54:01  azabala
49
* *** empty log message ***
50
*
51
* Revision 1.1  2006/10/19 19:09:43  azabala
52
* *** empty log message ***
53
*
54
*
55
*/
56
package com.iver.cit.gvsig.graph.gui;
57

    
58
import java.awt.BorderLayout;
59
import java.util.ArrayList;
60

    
61
import javax.swing.JEditorPane;
62
import javax.swing.JPanel;
63
import javax.swing.JScrollPane;
64
import javax.swing.event.HyperlinkEvent;
65
import javax.swing.event.HyperlinkListener;
66

    
67

    
68

    
69
import com.hardcode.gdbms.engine.values.DoubleValue;
70
import com.iver.andami.ui.mdiManager.IWindow;
71
import com.iver.andami.ui.mdiManager.WindowInfo;
72
import com.iver.cit.gvsig.fmap.MapControl;
73
import com.iver.cit.gvsig.fmap.core.IFeature;
74
import com.iver.cit.gvsig.graph.core.TurnUtil;
75
import com.iver.cit.gvsig.graph.solvers.Route;
76

    
77
public class RouteReportPanel extends JPanel implements IWindow{
78
        
79
        private Route route;
80
        
81
        private MapControl mapControl;
82
        
83
        private JScrollPane scrollPanel;
84
        
85
        private JEditorPane htmlPanel;
86
        
87
        private String htmlText;
88
        
89
        private WindowInfo viewInfo;
90
        
91
        
92
        private final String START_IMAGE = "<img src=\"images/drapeau_depart.gif\">";
93
        private final String STOP_IMAGE = "<img src=\"images/drapeau_arrivee.gif\">";
94
        
95
        public RouteReportPanel(Route route, MapControl mapControl){
96
                super();
97
                setLayout(new BorderLayout());
98
                this.route = route;
99
                this.mapControl = mapControl;
100
                scrollPanel = new JScrollPane();
101
                htmlPanel = new JEditorPane();
102
                htmlPanel.setEditable(false);
103
                htmlPanel.setEditorKit(new HTMLEditorKit());
104
                
105
                final MapControl map = mapControl;
106
                final Route routeTemp = route;
107
                htmlPanel.addHyperlinkListener(new HyperlinkListener(){
108
                        public void hyperlinkUpdate(HyperlinkEvent e) {
109
                                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());
113
                              }
114
                        }});
115
                initialize();
116
                scrollPanel.setViewportView(htmlPanel);
117
                add(scrollPanel, BorderLayout.CENTER);
118
        }
119
        
120
        public void setRoute(Route route){
121
                this.route = route;
122
                initialize();
123
        }
124
        
125
        private void initialize(){
126
                htmlText = "";
127
                ArrayList features = route.getFeatureList();
128
                IFeature firstFeature = (IFeature) features.get(0);
129
                IFeature lastFeature = (IFeature) features.get(features.size() - 1);
130
                renderHeader(firstFeature, lastFeature);
131
                renderFirstStrech(firstFeature);
132
                IFeature previousFeature = firstFeature;
133
                for(int i = 1; i < features.size() - 1; i++){
134
                        renderStrech((IFeature) features.get(i), previousFeature, i+1);
135
                }
136
                renderLastStretch((IFeature)features.get(features.size() -1));
137
                htmlPanel.setText(htmlText);
138
        }
139
        
140
        
141
        
142
        private void renderHeader(IFeature firstFeature, IFeature lastFeature){
143
                String startName = firstFeature.getAttribute(Route.TEXT_INDEX).toString();
144
                String stopName = lastFeature.getAttribute(Route.TEXT_INDEX).toString();
145
                htmlText += "<h1>";
146
                htmlText += "Informe de Ruta:" + startName + "-" + stopName ;//TODO INTERNACIONALIZAR ESTO
147
                htmlText += "</h1><br>";
148
                htmlText += "Salida desde: <b>";//TODO INTERNAC
149
                htmlText += startName;
150
                htmlText += "</b><br>";
151
                htmlText += "Llegada a:<b> ";//TODO INTERNAC
152
                htmlText += stopName + "</b><br>";
153
        }
154
        
155
        private void renderFirstStrech(IFeature feature){
156
                htmlText += "<table>";
157
                htmlText += "<tr>";
158
                htmlText += "<td>";
159
                htmlText += START_IMAGE;
160
                htmlText += "</td>";
161
                htmlText += "<td>";
162
                htmlText += "1. Salir de:<b> ";//TODO INTERNAC
163
                htmlText += feature.getAttribute(Route.TEXT_INDEX);
164
                htmlText += "</b></td></tr>";
165
                htmlText += "<tr><td><a href=\""+0+"\">Ver sobre el mapa</a><td></tr>";
166
                htmlText += "</table>";
167
        }
168
        
169
        private void renderStrech(IFeature feature, IFeature previousFeature, int numberOfStrech){
170
                int direction = TurnUtil.getDirection(previousFeature, feature);
171
                String street1 =  previousFeature.getAttribute(Route.TEXT_INDEX).toString();
172
                String street2 = feature.getAttribute(Route.TEXT_INDEX).toString();
173
                boolean changeStreet = street1.equalsIgnoreCase(street2);
174
                double length = ((DoubleValue)feature.getAttribute(Route.LENGTH_INDEX)).getValue();
175
                double weight = ((DoubleValue)feature.getAttribute(Route.WEIGHT_INDEX)).getValue();
176
                
177
                
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>";
185
                        }
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;
191
                        }
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
                        }
198
                }
199
                
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
                
213
        }
214
        
215
        
216
        
217
        private void renderLastStretch(IFeature feature){
218
                
219
                double length = ((DoubleValue)feature.getAttribute(Route.LENGTH_INDEX)).getValue();
220
                double weight = ((DoubleValue)feature.getAttribute(Route.WEIGHT_INDEX)).getValue();
221
                
222
                htmlText += "<table>";
223
                htmlText += "<tr>";
224
                htmlText += "<td>";
225
                htmlText += STOP_IMAGE;
226
                htmlText += "</td>";
227
                htmlText += "<td>";
228
                htmlText += route.getFeatureList().size()+". Llegada: ";//TODO INTERNAC
229
                htmlText += feature.getAttribute(Route.TEXT_INDEX);
230
                htmlText += "</td></tr>";
231
                htmlText += "<tr><td>Distancia:</td><td>"+length+"</td></tr>";
232
                htmlText += "<tr><td>Coste:</td><td>"+weight+"</td></tr>";
233
                htmlText += "<tr><td><a href=\""+(route.getFeatureList().size()-1)+"\">Ver sobre el mapa</a><td></tr>";
234
                htmlText += "</table>";
235
        }
236

    
237
        public WindowInfo getWindowInfo() {
238
                if (viewInfo == null) {
239
                        viewInfo = new WindowInfo(WindowInfo.MODELESSDIALOG | 
240
                                                                                WindowInfo.RESIZABLE);
241
                        viewInfo.setTitle("Informe de la ruta calculada");//Internacionalizar esto
242
                        viewInfo.setWidth(400);
243
                        viewInfo.setHeight(350);
244
                }
245
                return viewInfo;
246
        }
247
        
248
        
249
        
250
        
251
        
252
}
253