svn-gvsig-desktop / trunk / extensions / extGraph / src / org / gvsig / graph / gui / DlgDirections.java @ 22182
History | View | Annotate | Download (3.59 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 org.gvsig.graph.gui; |
42 |
|
43 |
import java.awt.Frame; |
44 |
import java.text.NumberFormat; |
45 |
import java.util.ArrayList; |
46 |
|
47 |
import javax.swing.JDialog; |
48 |
import javax.swing.JScrollPane; |
49 |
import javax.swing.JTextPane; |
50 |
|
51 |
import com.hardcode.gdbms.engine.values.DoubleValue; |
52 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
53 |
|
54 |
public class DlgDirections extends JDialog { |
55 |
|
56 |
private JScrollPane jScrollPane = null; |
57 |
|
58 |
private JTextPane jTextPane = null; |
59 |
|
60 |
/**
|
61 |
* This method initializes
|
62 |
*
|
63 |
* @param b
|
64 |
* @param frame
|
65 |
*
|
66 |
*/
|
67 |
public DlgDirections(Frame frame, boolean b) { |
68 |
super(frame, b);
|
69 |
initialize(); |
70 |
} |
71 |
|
72 |
/**
|
73 |
* Es responsabilidad del interfaz de usuario presentar el modelo a su
|
74 |
* manera.
|
75 |
*
|
76 |
* @param features
|
77 |
*/
|
78 |
public void setModel(ArrayList featureList) { |
79 |
String cad = "Pasa por:"; |
80 |
int cont = 0; |
81 |
double longitud = 0, sumaLong = 0, longAnt = 0; |
82 |
String cadAnt = ""; |
83 |
NumberFormat nf = NumberFormat.getInstance(); |
84 |
nf.setMaximumFractionDigits(2);
|
85 |
for (int i = featureList.size() - 1; i >= 0; i--) { |
86 |
// INSTRUCCIONES
|
87 |
IFeature feat = (IFeature) featureList.get(i); |
88 |
DoubleValue length = (DoubleValue) feat.getAttribute(2);
|
89 |
double dist = length.doubleValue();
|
90 |
longitud = longitud + dist; |
91 |
sumaLong = sumaLong + dist; |
92 |
|
93 |
String cadProv = feat.getAttribute(3).toString(); |
94 |
if ((cadAnt.compareTo(cadProv) != 0) && (cont > 0)) { |
95 |
longitud = dist; |
96 |
cad = cad + "\n" + cadAnt + " " + nf.format(longAnt) |
97 |
+ " metros";
|
98 |
|
99 |
} |
100 |
longAnt = longitud; |
101 |
cadAnt = cadProv; |
102 |
|
103 |
cont = cont + 1;
|
104 |
} |
105 |
cad = cad + "\n" + cadAnt + " " + nf.format(longAnt) + " metros"; |
106 |
cad = cad + "\n" + "=================" + "\n" |
107 |
+ "Distancia total recorrida: " + nf.format(sumaLong)
|
108 |
+ " metros";
|
109 |
getJTextPane().setText(cad); |
110 |
} |
111 |
|
112 |
/**
|
113 |
* This method initializes this
|
114 |
*
|
115 |
*/
|
116 |
private void initialize() { |
117 |
this.setSize(new java.awt.Dimension(363, 254)); |
118 |
this.setContentPane(getJScrollPane());
|
119 |
|
120 |
} |
121 |
|
122 |
/**
|
123 |
* This method initializes jScrollPane
|
124 |
*
|
125 |
* @return javax.swing.JScrollPane
|
126 |
*/
|
127 |
private JScrollPane getJScrollPane() { |
128 |
if (jScrollPane == null) { |
129 |
jScrollPane = new JScrollPane(); |
130 |
jScrollPane.setViewportView(getJTextPane()); |
131 |
} |
132 |
return jScrollPane;
|
133 |
} |
134 |
|
135 |
/**
|
136 |
* This method initializes jTextPane
|
137 |
*
|
138 |
* @return javax.swing.JTextPane
|
139 |
*/
|
140 |
private JTextPane getJTextPane() { |
141 |
if (jTextPane == null) { |
142 |
jTextPane = new JTextPane(); |
143 |
} |
144 |
return jTextPane;
|
145 |
} |
146 |
|
147 |
} // @jve:decl-index=0:visual-constraint="10,10"
|
148 |
|