Statistics
| Revision:

root / trunk / extensions / extGraph_predes / src / com / iver / cit / gvsig / graph / gui / RouteReportPanel.java @ 8197

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

    
55
import java.awt.BorderLayout;
56
import java.util.ArrayList;
57

    
58
import javax.swing.JEditorPane;
59
import javax.swing.JPanel;
60
import javax.swing.JScrollPane;
61
import javax.swing.event.HyperlinkEvent;
62
import javax.swing.event.HyperlinkListener;
63
import javax.swing.text.html.HTMLEditorKit;
64

    
65
import com.iver.andami.PluginServices;
66
import com.iver.andami.ui.mdiManager.IWindow;
67
import com.iver.andami.ui.mdiManager.WindowInfo;
68
import com.iver.cit.gvsig.fmap.MapControl;
69
import com.iver.cit.gvsig.fmap.core.IFeature;
70
import com.iver.cit.gvsig.graph.solvers.Route;
71

    
72
public class RouteReportPanel extends JPanel implements IWindow{
73
        
74
        private Route route;
75
        
76
        private MapControl mapControl;
77
        
78
        private JScrollPane scrollPanel;
79
        
80
        private JEditorPane htmlPanel;
81
        
82
        private String htmlText;
83
        
84
        private WindowInfo viewInfo;
85
        
86
        
87
        private final String START_IMAGE = "<img src=\"/images/drapeau_depart.gif\">";
88
        private final String STOP_IMAGE = "<img src=\"/images/drapeau_arrivee.gif\">";
89
        
90
        public RouteReportPanel(Route route, MapControl mapControl){
91
                super();
92
                setLayout(new BorderLayout());
93
                this.route = route;
94
                this.mapControl = mapControl;
95
                scrollPanel = new JScrollPane();
96
                htmlPanel = new JEditorPane();
97
                htmlPanel.setEditable(false);
98
                htmlPanel.setEditorKit(new HTMLEditorKit());
99
                
100
                final MapControl map = mapControl;
101
                final Route routeTemp = route;
102
                htmlPanel.addHyperlinkListener(new HyperlinkListener(){
103
                        public void hyperlinkUpdate(HyperlinkEvent e) {
104
                                if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
105
                                int indexOfFeature = Integer.parseInt(e.getDescription());
106
                                IFeature feature = (IFeature) routeTemp.getFeatureList().get(indexOfFeature);
107
                                map.getMapContext().getViewPort().setExtent(feature.getGeometry().getBounds2D());
108
                              }
109
                        }});
110
                initialize();
111
                scrollPanel.setViewportView(htmlPanel);
112
                add(scrollPanel, BorderLayout.CENTER);
113
        }
114
        
115
        public void setRoute(Route route){
116
                this.route = route;
117
                initialize();
118
        }
119
        
120
        private void initialize(){
121
                htmlText = "";
122
                ArrayList features = route.getFeatureList();
123
                IFeature firstFeature = (IFeature) features.get(0);
124
                IFeature lastFeature = (IFeature) features.get(features.size() - 1);
125
                renderHeader(firstFeature, lastFeature);
126
                renderFirstStrech(firstFeature);
127
                for(int i = 1; i < features.size() - 1; i++){
128
                        renderStrech((IFeature) features.get(i));
129
                }
130
                htmlPanel.setText(htmlText);
131
        }
132
        
133
        private void renderHeader(IFeature firstFeature, IFeature lastFeature){
134
                htmlText += "<h1>";
135
                htmlText += "Informe de Ruta:";//TODO INTERNACIONALIZAR ESTO
136
                htmlText += "</h1><br>";
137
                
138
                htmlText += "<table>";
139
                htmlText += "<tr>";
140
                htmlText += "<td>";
141
                htmlText += "Salida desde: ";//TODO INTERNAC
142
                htmlText += "</td><td>";
143
                htmlText += firstFeature.getAttribute(Route.TEXT_INDEX);
144
                htmlText += "</td>";
145
                htmlText += "</tr>";
146
                htmlText += "<tr>";
147
                htmlText += "Llegada a: ";//TODO INTERNAC
148
                htmlText += lastFeature.getAttribute(Route.TEXT_INDEX);
149
                htmlText += "</td><td>";
150
                htmlText += "</tr>";
151
                htmlText += "</table>";
152
        }
153
        
154
        private void renderFirstStrech(IFeature feature){
155
                htmlText += "<table>";
156
                htmlText += "<tr>";
157
                htmlText += "<td>";
158
                htmlText += START_IMAGE;
159
                htmlText += "</td>";
160
                htmlText += "<td>";
161
                htmlText += "1. Salir de: ";//TODO INTERNAC
162
                htmlText += feature.getAttribute(Route.TEXT_INDEX);
163
                htmlText += "</td></tr>";
164
                htmlText += "<tr><td><a href=\""+0+"\">Ver sobre el mapa</a><td></tr>";
165
                htmlText += "</table>";
166
        }
167
        
168
        private void renderStrech(IFeature feature){
169
                
170
                
171
        }
172
        
173
        
174
        
175
        private void renderLastStretch(IFeature feature){
176
                
177
        }
178

    
179
        public WindowInfo getWindowInfo() {
180
                if (viewInfo == null) {
181
                        viewInfo = new WindowInfo(WindowInfo.MODELESSDIALOG | 
182
                                                                                WindowInfo.RESIZABLE);
183
                        viewInfo.setTitle("Informe de la ruta calculada");//Internacionalizar esto
184
                        viewInfo.setWidth(400);
185
                        viewInfo.setHeight(350);
186
                }
187
                return viewInfo;
188
        }
189
        
190
        
191
        
192
        
193
        
194
}
195