svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameScaleBar.java @ 6806
History | View | Annotate | Download (43.1 KB)
1 |
/*
|
---|---|
2 |
* Created on 20-feb-2004
|
3 |
*
|
4 |
*/
|
5 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
6 |
*
|
7 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
8 |
*
|
9 |
* This program is free software; you can redistribute it and/or
|
10 |
* modify it under the terms of the GNU General Public License
|
11 |
* as published by the Free Software Foundation; either version 2
|
12 |
* of the License, or (at your option) any later version.
|
13 |
*
|
14 |
* This program is distributed in the hope that it will be useful,
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
* GNU General Public License for more details.
|
18 |
*
|
19 |
* You should have received a copy of the GNU General Public License
|
20 |
* along with this program; if not, write to the Free Software
|
21 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
22 |
*
|
23 |
* For more information, contact:
|
24 |
*
|
25 |
* Generalitat Valenciana
|
26 |
* Conselleria d'Infraestructures i Transport
|
27 |
* Av. Blasco Ib??ez, 50
|
28 |
* 46010 VALENCIA
|
29 |
* SPAIN
|
30 |
*
|
31 |
* +34 963862235
|
32 |
* gvsig@gva.es
|
33 |
* www.gvsig.gva.es
|
34 |
*
|
35 |
* or
|
36 |
*
|
37 |
* IVER T.I. S.A
|
38 |
* Salamanca 50
|
39 |
* 46005 Valencia
|
40 |
* Spain
|
41 |
*
|
42 |
* +34 963163400
|
43 |
* dac@iver.es
|
44 |
*/
|
45 |
package com.iver.cit.gvsig.gui.layout.fframes; |
46 |
|
47 |
import com.iver.andami.PluginServices; |
48 |
|
49 |
import com.iver.cit.gvsig.fmap.DriverException; |
50 |
import com.iver.cit.gvsig.fmap.FMap; |
51 |
import com.iver.cit.gvsig.gui.layout.Attributes; |
52 |
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities; |
53 |
import com.iver.cit.gvsig.gui.layout.Layout; |
54 |
import com.iver.cit.gvsig.gui.project.SaveException; |
55 |
|
56 |
import com.iver.utiles.StringUtilities; |
57 |
import com.iver.utiles.XMLEntity; |
58 |
|
59 |
import java.awt.BasicStroke; |
60 |
import java.awt.Color; |
61 |
import java.awt.Font; |
62 |
import java.awt.FontMetrics; |
63 |
import java.awt.Graphics; |
64 |
import java.awt.Graphics2D; |
65 |
import java.awt.geom.AffineTransform; |
66 |
import java.awt.geom.Point2D; |
67 |
import java.awt.geom.Rectangle2D; |
68 |
import java.awt.image.BufferedImage; |
69 |
|
70 |
import java.text.NumberFormat; |
71 |
|
72 |
|
73 |
|
74 |
/**
|
75 |
* FFrame para introducir una barra de escala en el Layout.
|
76 |
*
|
77 |
* @author Vicente Caballero Navarro
|
78 |
*/
|
79 |
public class FFrameScaleBar extends FFrame implements IFFrameViewDependence { |
80 |
private static final int NUMERO = 0; |
81 |
private static final int BARRA1 = 1; |
82 |
private static final int BARRA2 = 2; |
83 |
private static final int BARRA3 = 3; |
84 |
private static final int BARRA4 = 4; |
85 |
private double DIFDOWN = 1.5; |
86 |
private double DIFL = 30; |
87 |
private double DIFR = 30; |
88 |
private double DIFUP = 10; |
89 |
private boolean m_bIntervalSet = false; |
90 |
private int m_style = NUMERO; |
91 |
private int m_units = 1; //Metros |
92 |
private int m_mapUnits = 1; //unidad de medida de la vista(Metros) |
93 |
private double m_interval = 1; |
94 |
private int m_numinterval = 3; |
95 |
private int m_numleft = 2; |
96 |
private double m_height = 0; |
97 |
private FFrameView fframeview = null; |
98 |
private double m_typeUnit = Attributes.CHANGE[1]; //METROS; |
99 |
private String m_nameUnit = null; |
100 |
private double m_numUnit = 0; |
101 |
private double m_dif = 1; |
102 |
private int m_hasleft = 0; |
103 |
private Font m_f = new Font("SansSerif", Font.PLAIN, 9); |
104 |
private Color barcolor = Color.black; |
105 |
private Color textcolor = Color.black; |
106 |
private boolean showNameUnits = true; |
107 |
private boolean showDescription = false; |
108 |
private boolean aboveName = false; |
109 |
private boolean aboveIntervals = true; |
110 |
private boolean aboveDescription = false; |
111 |
private int dependenceIndex = -1; |
112 |
private int numDec = 0; |
113 |
|
114 |
/**
|
115 |
* Creates a new FFrameScaleBar object.
|
116 |
*/
|
117 |
public FFrameScaleBar() {
|
118 |
} |
119 |
|
120 |
/**
|
121 |
* Inserta el FFrameView sobre el que obtener la escala gr?fica.
|
122 |
*
|
123 |
* @param f FFrameView sobre el que obtener la escala.
|
124 |
*/
|
125 |
public void setFFrameDependence(IFFrame f) { |
126 |
fframeview = (FFrameView) f; |
127 |
setMapUnits(fframeview.getMapUnits()); |
128 |
setHeight(f.getBoundBox().height); |
129 |
} |
130 |
|
131 |
/**
|
132 |
* Devuelve el FFrameView que se representa con la escala.
|
133 |
*
|
134 |
* @return FFrameView a representar.
|
135 |
*/
|
136 |
public IFFrame getFFrameDependence() {
|
137 |
return fframeview;
|
138 |
} |
139 |
|
140 |
/**
|
141 |
* Devuelve el FMap de la vista que se representa en la escala.
|
142 |
*
|
143 |
* @return FMap.
|
144 |
*/
|
145 |
public FMap getFMap() {
|
146 |
return fframeview.getFMap();
|
147 |
} |
148 |
|
149 |
/**
|
150 |
* Rellenar el estilo de barra de escala que se elige.
|
151 |
*
|
152 |
* @param s entero que representa el tipo de barra seleccionada.
|
153 |
*/
|
154 |
public void setStyle(int s) { |
155 |
m_style = s; |
156 |
} |
157 |
|
158 |
/**
|
159 |
* Devuelve el tipo de escala a dibujar.
|
160 |
*
|
161 |
* @return entero.
|
162 |
*/
|
163 |
public int getStyle() { |
164 |
return m_style;
|
165 |
} |
166 |
|
167 |
/**
|
168 |
* Rellenar el tama?o de un intervalo.
|
169 |
*
|
170 |
* @param s tama?o de un intervalo.
|
171 |
*/
|
172 |
public void setInterval(double s) { |
173 |
m_interval = s; |
174 |
|
175 |
if (m_numleft != 0) { |
176 |
m_hasleft = 1;
|
177 |
} |
178 |
|
179 |
Rectangle2D.Double rect = getBoundBox();
|
180 |
double difL = (rect.width / DIFL);
|
181 |
double difR = (rect.width / DIFR);
|
182 |
double n = (rect.width - difL - difR);
|
183 |
m_numUnit = (m_interval * m_typeUnit) / getScaleView(); |
184 |
m_numinterval = (int) (n / m_numUnit) - m_hasleft;
|
185 |
m_dif = 1;
|
186 |
} |
187 |
|
188 |
/**
|
189 |
* Devuelve el valor del intervalo.
|
190 |
*
|
191 |
* @return long.
|
192 |
*/
|
193 |
public String obtainInterval() { |
194 |
if (fframeview != null) { |
195 |
Rectangle2D.Double rect = getBoundBox();
|
196 |
|
197 |
if (m_numleft != 0) { |
198 |
m_hasleft = 1;
|
199 |
} |
200 |
|
201 |
double difL = (rect.width / DIFL);
|
202 |
double difR = (rect.width / DIFR);
|
203 |
double n = (rect.width - difL - difR);
|
204 |
m_numUnit = n / (m_numinterval + m_hasleft); |
205 |
|
206 |
double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
|
207 |
m_dif = getExact(scaleXunit); |
208 |
m_numUnit = m_numUnit * m_dif; |
209 |
m_interval = scaleXunit; |
210 |
|
211 |
///m_interval = (scaleXunit * m_dif);
|
212 |
return format(m_interval);
|
213 |
} |
214 |
|
215 |
return "0"; |
216 |
} |
217 |
|
218 |
/**
|
219 |
* Rellenar el n?mero de intervalos.
|
220 |
*
|
221 |
* @param s n?mero de intervalos.
|
222 |
*/
|
223 |
public void setNumInterval(int s) { |
224 |
m_numinterval = s; |
225 |
|
226 |
if (m_numleft != 0) { |
227 |
m_hasleft = 1;
|
228 |
} |
229 |
|
230 |
Rectangle2D.Double rect = getBoundBox();
|
231 |
double difL = (rect.width / DIFL);
|
232 |
double difR = (rect.width / DIFR);
|
233 |
double n = (rect.width - difL - difR);
|
234 |
m_numUnit = n / (m_numinterval + m_hasleft); |
235 |
|
236 |
double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
|
237 |
m_dif = getExact(scaleXunit); |
238 |
m_numUnit = m_numUnit * m_dif; |
239 |
m_interval = (scaleXunit * m_dif); |
240 |
} |
241 |
|
242 |
/**
|
243 |
* Devuelve el n?mero de intervalos por encima del cero.
|
244 |
*
|
245 |
* @return entero.
|
246 |
*/
|
247 |
public int getNumInterval() { |
248 |
return m_numinterval;
|
249 |
} |
250 |
|
251 |
/**
|
252 |
* Rellenar el n?mero de intervalos a la izquierda del cero.
|
253 |
*
|
254 |
* @param s n?mero de intervalos a la izquierda.
|
255 |
*/
|
256 |
public void setNumLeft(int s) { |
257 |
m_numleft = s; |
258 |
} |
259 |
|
260 |
/**
|
261 |
* Devuelve el n?mero de intervalos en los que se quiere particionar el
|
262 |
* intervalo que se queda por debajo del cero.
|
263 |
*
|
264 |
* @return entero.
|
265 |
*/
|
266 |
public int getNumLeft() { |
267 |
return m_numleft;
|
268 |
} |
269 |
|
270 |
/**
|
271 |
* Seleccionar ,a true, si se quiere o, a false, si no mantener los
|
272 |
* intervalos.
|
273 |
*
|
274 |
* @param b boolean a true si se quiere mantener los intervalos.
|
275 |
*/
|
276 |
public void setIntervalSet(boolean b) { |
277 |
m_bIntervalSet = b; |
278 |
} |
279 |
|
280 |
/**
|
281 |
* Seleccionar la unidad de medida a representar en la barra de escala.
|
282 |
*
|
283 |
* @param s entero que representa la unidad de medida que se selecciona.
|
284 |
*/
|
285 |
public void setUnits(int s) { |
286 |
m_units = s; |
287 |
m_typeUnit = Attributes.CHANGE[s];
|
288 |
m_nameUnit = Attributes.NAMES[s];
|
289 |
} |
290 |
|
291 |
/**
|
292 |
* Devuelve un entero que representa el tipo de unidades que representamos.
|
293 |
*
|
294 |
* @return entero.
|
295 |
*/
|
296 |
public int getUnits() { |
297 |
return m_units;
|
298 |
} |
299 |
|
300 |
/**
|
301 |
* Devuelve el long que representa el intervalo.
|
302 |
*
|
303 |
* @return Intervalo.
|
304 |
*/
|
305 |
public String getInterval() { |
306 |
return format(m_interval);
|
307 |
} |
308 |
|
309 |
/**
|
310 |
* Rellenar el rect?ngulo de la vista sobre la que se obtiene la escala.
|
311 |
*
|
312 |
* @param d Rect?ngulo.
|
313 |
*/
|
314 |
public void setHeight(double d) { |
315 |
m_height = d; |
316 |
} |
317 |
|
318 |
/**
|
319 |
* Rellena la unidad de medida en la que est? la vista.
|
320 |
*
|
321 |
* @param i entero que representa la unidad de medida de la vista.
|
322 |
*/
|
323 |
public void setMapUnits(int i) { |
324 |
m_mapUnits = i; |
325 |
} |
326 |
|
327 |
/**
|
328 |
* Devuelve la escala de la vista seleccionada.
|
329 |
*
|
330 |
* @return la escala de la vista.
|
331 |
*/
|
332 |
private long getScaleView() { |
333 |
if (fframeview == null) { |
334 |
return 1; |
335 |
} |
336 |
|
337 |
return fframeview.getScale();
|
338 |
} |
339 |
|
340 |
/**
|
341 |
* M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
|
342 |
* la transformada afin que se debe de aplicar y el rect?ngulo que se debe
|
343 |
* de dibujar.
|
344 |
*
|
345 |
* @param g Graphics
|
346 |
* @param at Transformada afin.
|
347 |
* @param rv rect?ngulo sobre el que hacer un clip.
|
348 |
* @param imgBase Image para acelerar el dibujado.
|
349 |
*/
|
350 |
public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
351 |
BufferedImage imgBase) {
|
352 |
Rectangle2D.Double r = getBoundingBox(at);
|
353 |
g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), |
354 |
r.y + (r.height / 2));
|
355 |
|
356 |
if (intersects(rv, r)) {
|
357 |
if ((fframeview == null) || (fframeview.getFMap() == null)) { |
358 |
drawEmpty(g); |
359 |
} else {
|
360 |
switch (m_style) {
|
361 |
case (NUMERO):
|
362 |
|
363 |
double scalex = r.getWidth() / (8); |
364 |
|
365 |
if (scalex > (r.getHeight() / (8))) { |
366 |
scalex = r.getHeight() / (2);
|
367 |
} |
368 |
|
369 |
g.setColor(textcolor); |
370 |
|
371 |
if (m_f != null) { |
372 |
m_f = new Font(m_f.getFontName(), m_f.getStyle(), |
373 |
(int) (scalex));
|
374 |
g.setFont(m_f); |
375 |
} |
376 |
|
377 |
FontMetrics fm = g.getFontMetrics();
|
378 |
double d = r.getWidth();
|
379 |
long scl=getScaleView();
|
380 |
if (scl<1){ |
381 |
String unknowScale=PluginServices.getText(this,"escala_desconocida"); |
382 |
if (fm.stringWidth(unknowScale) > (d * 0.8)) { |
383 |
double dif = fm.stringWidth(unknowScale) / (d * 0.8); |
384 |
m_f = new Font(m_f.getName(), m_f.getStyle(), |
385 |
(int) (m_f.getSize() / dif));
|
386 |
g.setFont(m_f); |
387 |
} |
388 |
g.drawString(unknowScale, (int) r.x,
|
389 |
(int) (r.y + (r.height / 2))); |
390 |
return;
|
391 |
} |
392 |
String scale = " 1:" + scl; |
393 |
|
394 |
if (fm.stringWidth(String.valueOf(m_interval)) > (d * 0.8)) { |
395 |
double dif = fm.stringWidth(String.valueOf( |
396 |
m_interval)) / (d * 0.8);
|
397 |
m_f = new Font(m_f.getName(), m_f.getStyle(), |
398 |
(int) (m_f.getSize() / dif));
|
399 |
g.setFont(m_f); |
400 |
} |
401 |
|
402 |
g.drawString(scale, (int) r.x,
|
403 |
(int) (r.y + (r.height / 2))); |
404 |
|
405 |
break;
|
406 |
|
407 |
case (BARRA1):
|
408 |
case (BARRA2):
|
409 |
case (BARRA3):
|
410 |
case (BARRA4):
|
411 |
drawBar(m_style, g, at); |
412 |
|
413 |
break;
|
414 |
} |
415 |
} |
416 |
} |
417 |
|
418 |
g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2), |
419 |
r.y + (r.height / 2));
|
420 |
} |
421 |
|
422 |
/**
|
423 |
* Rellena con el rect?ngulo que se pasa como par?metro el boundBox(en
|
424 |
* cent?metros) del fframe del cual con una transformaci?n se podr?
|
425 |
* calcular el BoundingBox (en pixels).
|
426 |
*
|
427 |
* @param r Rect?ngulo en cent?metros.
|
428 |
*/
|
429 |
public void setBoundBox(Rectangle2D.Double r) { |
430 |
if ((m_numUnit < 1) || (fframeview == null) || |
431 |
(fframeview.getFMap() == null)) {
|
432 |
super.setBoundBox(r);
|
433 |
|
434 |
return;
|
435 |
} |
436 |
|
437 |
double difL = (r.width / DIFL);
|
438 |
double difR = (r.width / DIFR);
|
439 |
|
440 |
if (m_bIntervalSet) {
|
441 |
m_numinterval = (int) (((r.width - (difL + difR)) * m_dif) / m_numUnit) -
|
442 |
m_hasleft; |
443 |
} |
444 |
|
445 |
if (m_numinterval < 1) { |
446 |
m_numinterval = 1;
|
447 |
r.width = ((m_numinterval + m_hasleft) * m_numUnit) + difL + difR; |
448 |
} |
449 |
|
450 |
getBoundBox().setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight()); |
451 |
} |
452 |
|
453 |
/**
|
454 |
* Dibuja sobre el Graphics la escala gr?fica.
|
455 |
*
|
456 |
* @param type Tipo de barra.
|
457 |
* @param g Graphics sobre el que dibujar.
|
458 |
* @param at Matriz de transformaci?n.
|
459 |
*/
|
460 |
private void drawBar(int type, Graphics2D g, AffineTransform at) { |
461 |
Rectangle2D.Double rect = getBoundBox();
|
462 |
Rectangle2D.Double r = getBoundingBox(at);
|
463 |
double numleft = m_numleft;
|
464 |
initDistances(); |
465 |
//drawOrder(g,r);
|
466 |
double difDown = (rect.height / DIFDOWN);
|
467 |
double difUp = (rect.height / DIFUP);
|
468 |
double difL = (rect.width / DIFL);
|
469 |
double difR = (rect.width / DIFR);
|
470 |
double n = (rect.width - difL - difR);
|
471 |
|
472 |
//setDescripcion("escala 1:" + String.valueOf(fframeview.getScale()));
|
473 |
g.setStroke(new BasicStroke(0)); |
474 |
|
475 |
if (!m_bIntervalSet) {
|
476 |
m_numUnit = n / (m_numinterval + m_hasleft); |
477 |
|
478 |
double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
|
479 |
m_dif = getExact(scaleXunit); |
480 |
m_numUnit = m_numUnit * m_dif; |
481 |
m_interval = (scaleXunit * m_dif); |
482 |
} |
483 |
|
484 |
if (m_bIntervalSet) {
|
485 |
m_numUnit = (m_interval * m_typeUnit) / (m_dif * getScaleView()); |
486 |
m_numinterval = (int) (((rect.width - (difL + difR)) * m_dif) / m_numUnit) -
|
487 |
m_hasleft; |
488 |
} |
489 |
|
490 |
if (m_numinterval < 1) { |
491 |
m_numinterval = 1;
|
492 |
rect.width = ((m_numinterval + m_hasleft) * m_numUnit) + difL + |
493 |
difR; |
494 |
} |
495 |
|
496 |
double h = 0; |
497 |
|
498 |
if (type == BARRA1) {
|
499 |
h = (rect.height - (difUp + difDown)); |
500 |
} else if ((type == BARRA2) || (type == BARRA3)) { |
501 |
h = (rect.height - (difUp + difDown)) / 2;
|
502 |
} |
503 |
|
504 |
//Dibujar el rect?ngulo que bordea todo.
|
505 |
Rectangle2D.Double rectotal = (FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x + |
506 |
difL), (rect.y + difUp), |
507 |
m_numUnit * (m_hasleft + m_numinterval), h), at)); |
508 |
g.setColor(barcolor); |
509 |
g.fillRect((int) rectotal.x, (int) rectotal.y, (int) (rectotal.width), |
510 |
(int) rectotal.height);
|
511 |
g.setColor(Color.white);
|
512 |
g.fillRect((int) rectotal.x+1, (int) rectotal.y+1, (int) (rectotal.width-2), |
513 |
(int) rectotal.height-2); |
514 |
g.setColor(barcolor); |
515 |
|
516 |
if (m_f != null) { |
517 |
m_f = new Font(m_f.getFontName(), m_f.getStyle(), |
518 |
(int) (r.getHeight() / 4)); |
519 |
} else {
|
520 |
m_f = new Font("SansSerif", Font.PLAIN, (int) (r.getHeight() / 4)); |
521 |
} |
522 |
|
523 |
g.setFont(m_f); |
524 |
Double interval=new Double(m_interval); |
525 |
if (interval.isNaN()) {
|
526 |
String unknowScale=PluginServices.getText(this,"escala_desconocida"); |
527 |
FontMetrics fm = g.getFontMetrics();
|
528 |
double d = r.getWidth();
|
529 |
if (fm.stringWidth(unknowScale) > (d * 0.8)) { |
530 |
double dif = fm.stringWidth(unknowScale) / (d * 0.8); |
531 |
m_f = new Font(m_f.getName(), m_f.getStyle(), |
532 |
(int) (m_f.getSize() / dif));
|
533 |
g.setFont(m_f); |
534 |
} |
535 |
g.drawString(unknowScale, (int) r.x,
|
536 |
(int) (r.y + (r.height / 2))); |
537 |
return;
|
538 |
} |
539 |
|
540 |
FontMetrics fm = g.getFontMetrics();
|
541 |
String formatInterval = format(m_interval);
|
542 |
double d = (rectotal.getWidth() / m_numinterval) + m_hasleft;
|
543 |
double difpos = ((r.getHeight() / 4) * formatInterval.length()) / 4; |
544 |
|
545 |
if (fm.stringWidth(formatInterval) > (d * 0.7)) { |
546 |
double dif = fm.stringWidth(formatInterval) / (d * 0.7); |
547 |
difpos = (d * 0.7) / 2; |
548 |
m_f = new Font(m_f.getName(), m_f.getStyle(), |
549 |
(int) (m_f.getSize() / dif));
|
550 |
g.setFont(m_f); |
551 |
} |
552 |
|
553 |
//Derecha del cero
|
554 |
for (int i = 0; i < m_numinterval; i++) { |
555 |
Rectangle2D.Double recder = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x + |
556 |
(difL) + ((m_numUnit * i) + (m_hasleft * m_numUnit))), |
557 |
(rect.y + (difUp)), (m_numUnit), |
558 |
(rect.height - (difUp + difDown)) / 2), at);
|
559 |
Rectangle2D.Double recderB = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x + |
560 |
(difL) + ((m_numUnit * i) + (m_hasleft * m_numUnit))), |
561 |
(rect.y + difUp) + |
562 |
((rect.height - (difUp + difDown)) / 2), (m_numUnit),
|
563 |
((rect.height - (difUp + difDown)) / 2)), at);
|
564 |
|
565 |
// Correcci?n cuando la altura en pixels del rect?ngulo es impar.
|
566 |
rectotal.y = recder.y; |
567 |
recderB.height = rectotal.height - recder.height + 0.5;
|
568 |
|
569 |
/**
|
570 |
* if (i == (m_numinterval - 1)) { if (recder.getMaxX() !=
|
571 |
* rectotal.getMaxX()) { recder.width = (recder.width +
|
572 |
* recder.getMaxX()) - rectotal.getMaxX(); } if (recderB.getMaxX()
|
573 |
* != rectotal.getMaxX()) { recderB.width = (recderB.width +
|
574 |
* recderB.getMaxX()) - rectotal.getMaxX(); }} if
|
575 |
* (recderB.getMaxY() != rectotal.getMaxY()) { recderB.height =
|
576 |
* (recderB.height + recderB.getMaxY()) - rectotal.getMaxY(); }
|
577 |
*/
|
578 |
if ((m_numleft % 2) == 0) { |
579 |
if ((i % 2) == 0) { |
580 |
if ((type == BARRA1) || (type == BARRA2)) {
|
581 |
fillRect(g, recder); |
582 |
} else if (type == BARRA3) { |
583 |
g.drawRect((int) recder.x, (int) recder.y, |
584 |
(int) recder.width, (int) recder.height); |
585 |
} |
586 |
} else if (type == BARRA1) { |
587 |
fillRect(g, recderB); |
588 |
} |
589 |
} else {
|
590 |
if ((i % 2) != 0) { |
591 |
if ((type == BARRA1) || (type == BARRA2)) {
|
592 |
fillRect(g, recder); |
593 |
} else if (type == BARRA3) { |
594 |
g.drawRect((int) recderB.x, (int) recderB.y, |
595 |
(int) recderB.width, (int) recderB.height); |
596 |
} |
597 |
} else if (type == BARRA1) { |
598 |
fillRect(g, recderB); |
599 |
} |
600 |
} |
601 |
|
602 |
String interString = format(m_interval * i);
|
603 |
Point2D.Double p = null; |
604 |
|
605 |
if (isAboveIntervals()) {
|
606 |
p = new Point2D.Double(recder.x - difpos, |
607 |
r.getMinY() + (r.getHeight() / DIFUP)); |
608 |
} else {
|
609 |
p = new Point2D.Double(recder.x - difpos, |
610 |
((r.getHeight() / 4) + r.getMaxY()) -
|
611 |
(r.getHeight() / DIFDOWN)); |
612 |
} |
613 |
|
614 |
//Para dibujar el 0 centrado en su sitio.
|
615 |
if (i == 0) { |
616 |
double dif0 = recder.x - (fm.stringWidth(interString) / 2); |
617 |
p = new Point2D.Double(dif0, p.getY()); |
618 |
} |
619 |
|
620 |
drawInterval(g, interString, p); |
621 |
} |
622 |
|
623 |
//?ltimo n?mero a dibujar.
|
624 |
String interString = format(m_interval * m_numinterval);
|
625 |
|
626 |
Point2D.Double p = null; |
627 |
|
628 |
if (isAboveIntervals()) {
|
629 |
p = new Point2D.Double(rectotal.getMaxX() - difpos, |
630 |
r.getMinY() + (r.getHeight() / DIFUP)); |
631 |
} else {
|
632 |
p = new Point2D.Double(rectotal.getMaxX() - difpos, |
633 |
((r.getHeight() / 4) + r.getMaxY()) -
|
634 |
(r.getHeight() / DIFDOWN)); |
635 |
} |
636 |
|
637 |
drawInterval(g, interString, p); |
638 |
|
639 |
//Izquierda del cero
|
640 |
for (int i = 0; i < m_numleft; i++) { |
641 |
Rectangle2D.Double reciz = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x + |
642 |
difL + ((m_numUnit / m_numleft) * i)), |
643 |
(rect.y + difUp), (m_numUnit / numleft), |
644 |
(rect.height - (difUp + difDown)) / 2), at);
|
645 |
Rectangle2D.Double recizB = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x + |
646 |
difL + ((m_numUnit / m_numleft) * i)), |
647 |
(rect.y + difUp) + |
648 |
((rect.height - (difUp + difDown)) / 2),
|
649 |
(m_numUnit / numleft), |
650 |
((rect.height - (difUp + difDown)) / 2)), at);
|
651 |
|
652 |
//Correcci?n cuando la altura en pixels del rectangulo es impar.
|
653 |
reciz.y = rectotal.y; |
654 |
recizB.height = rectotal.height - reciz.height + 0.5;
|
655 |
|
656 |
if ((i % 2) == 0) { |
657 |
if ((type == BARRA1) || (type == BARRA2)) {
|
658 |
fillRect(g, reciz); |
659 |
} else if (type == BARRA3) { |
660 |
g.drawRect((int) reciz.x, (int) reciz.y, (int) reciz.width, |
661 |
(int) reciz.height);
|
662 |
} |
663 |
} else if (type == BARRA1) { |
664 |
fillRect(g, recizB); |
665 |
} |
666 |
} |
667 |
|
668 |
if (m_numleft > 0) { |
669 |
interString = format(m_interval); |
670 |
|
671 |
if (isAboveIntervals()) {
|
672 |
p = new Point2D.Double(rectotal.x - difpos, |
673 |
r.getMinY() + (r.getHeight() / DIFUP)); |
674 |
} else {
|
675 |
p = new Point2D.Double(rectotal.x - difpos, |
676 |
((r.getHeight() / 4) + r.getMaxY()) -
|
677 |
(r.getHeight() / DIFDOWN)); |
678 |
} |
679 |
|
680 |
drawInterval(g, interString, p); |
681 |
} |
682 |
|
683 |
//En el caso de que se pida como n?mro de intervalos a la izquierda del 0, se reajusta el tama?o del rect?ngulo exterior de la escala gr?fica.
|
684 |
if (m_numleft == 0) { |
685 |
Rectangle2D.Double recAux = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x + |
686 |
difL + ((m_numUnit / 1) * 0)), (rect.y + difUp), |
687 |
(m_numUnit / 1), (rect.height - (difUp + difDown)) / 2), |
688 |
at); |
689 |
rectotal.x = rectotal.x + recAux.width; |
690 |
rectotal.width = rectotal.width - recAux.width; |
691 |
} |
692 |
|
693 |
//Se dibuja el rect?ngulo que bordea toda la escala gr?fica.
|
694 |
g.drawRect((int) rectotal.x, (int) rectotal.y, (int) (rectotal.width), |
695 |
(int) rectotal.height);
|
696 |
|
697 |
drawNameUnitsAndDescriptions(g, r); |
698 |
//drawDescription(g, r);
|
699 |
} |
700 |
|
701 |
/**
|
702 |
* Inicializa las distancias de la barra de escala.
|
703 |
*/
|
704 |
private void initDistances() { |
705 |
int numUp = 0; |
706 |
int numDown = 0; |
707 |
|
708 |
DIFDOWN = 30;
|
709 |
DIFL = 40;
|
710 |
DIFR = 40;
|
711 |
DIFUP = 30;
|
712 |
|
713 |
if (isAboveName()) {
|
714 |
numUp++; |
715 |
} else {
|
716 |
numDown++; |
717 |
} |
718 |
|
719 |
if (isAboveIntervals()) {
|
720 |
numUp++; |
721 |
} else {
|
722 |
numDown++; |
723 |
} |
724 |
|
725 |
if (isAboveDescription()) {
|
726 |
numUp++; |
727 |
} else {
|
728 |
numDown++; |
729 |
} |
730 |
|
731 |
if (numDown == 1) { |
732 |
DIFDOWN = 3;
|
733 |
} else if (numDown == 2) { |
734 |
DIFDOWN = 2;
|
735 |
} else if (numDown == 3) { |
736 |
DIFDOWN = 1.2;
|
737 |
} |
738 |
|
739 |
if (numUp == 1) { |
740 |
DIFUP = 3;
|
741 |
} else if (numUp == 2) { |
742 |
DIFUP = 2;
|
743 |
} else if (numUp == 3) { |
744 |
DIFUP = 1.2;
|
745 |
} |
746 |
} |
747 |
|
748 |
/**
|
749 |
* Dibuja sobre el Graphics el nombre de la unidad de medida de la escala y la descripci?n,
|
750 |
* siendo por defecto la escala 1:.
|
751 |
*
|
752 |
* @param g Graphics sobre el que se dibuja.
|
753 |
* @param rec Rect?ngulo que ocupa la escala gr?fica.
|
754 |
*/
|
755 |
private void drawNameUnitsAndDescriptions(Graphics g, Rectangle2D.Double rec) { |
756 |
FontMetrics fm = g.getFontMetrics();
|
757 |
Point2D.Double pD = null; |
758 |
Point2D.Double pU = null; |
759 |
g.setColor(textcolor); |
760 |
switch (getFormat()) {
|
761 |
case DUIB:
|
762 |
pD = new Point2D.Double(rec.getCenterX() - |
763 |
(fm.stringWidth(getDescription()) / 2),
|
764 |
(rec.getMinY() + (rec.getHeight() / 9) +
|
765 |
(fm.getHeight() / 2)));
|
766 |
pU = new Point2D.Double(rec.getCenterX() - |
767 |
(fm.stringWidth(m_nameUnit) / 2),
|
768 |
(rec.getMinY() + (rec.getHeight() / 3) +
|
769 |
(fm.getHeight() / 2)));
|
770 |
|
771 |
break;
|
772 |
case DUBI:
|
773 |
pD = new Point2D.Double(rec.getCenterX() - |
774 |
(fm.stringWidth(getDescription()) / 2),
|
775 |
(rec.getMinY() + (rec.getHeight() / 9) +
|
776 |
(fm.getHeight() / 2)));
|
777 |
pU = new Point2D.Double(rec.getCenterX() - |
778 |
(fm.stringWidth(m_nameUnit) / 2),
|
779 |
(rec.getMinY() + (rec.getHeight() / 3) +
|
780 |
(fm.getHeight() / 2)));
|
781 |
break;
|
782 |
case DBIU:
|
783 |
pD = new Point2D.Double(rec.getCenterX() - |
784 |
(fm.stringWidth(getDescription()) / 2),
|
785 |
(rec.getMinY() + (rec.getHeight() / 9) +
|
786 |
(fm.getHeight() / 2)));
|
787 |
pU = new Point2D.Double(rec.getCenterX() - |
788 |
(fm.stringWidth(m_nameUnit) / 2),
|
789 |
(rec.getMaxY() - (rec.getHeight() / 9) +
|
790 |
(fm.getHeight() / 3)));
|
791 |
break;
|
792 |
case DIBU:
|
793 |
pD = new Point2D.Double(rec.getCenterX() - |
794 |
(fm.stringWidth(getDescription()) / 2),
|
795 |
(rec.getMinY() + (rec.getHeight() / 9) +
|
796 |
(fm.getHeight() / 2)));
|
797 |
pU = new Point2D.Double(rec.getCenterX() - |
798 |
(fm.stringWidth(m_nameUnit) / 2),
|
799 |
(rec.getMaxY() - (rec.getHeight() / 9) +
|
800 |
(fm.getHeight() / 3)));
|
801 |
break;
|
802 |
case UIBD:
|
803 |
pD = new Point2D.Double(rec.getCenterX() - |
804 |
(fm.stringWidth(getDescription()) / 2),
|
805 |
(rec.getMaxY() - (rec.getHeight() / 9) +
|
806 |
(fm.getHeight() / 3)));
|
807 |
pU = new Point2D.Double(rec.getCenterX() - |
808 |
(fm.stringWidth(m_nameUnit) / 2),
|
809 |
(rec.getMinY() + (rec.getHeight() / 9) +
|
810 |
(fm.getHeight() / 2)));
|
811 |
break;
|
812 |
case UBID:
|
813 |
pD = new Point2D.Double(rec.getCenterX() - |
814 |
(fm.stringWidth(getDescription()) / 2),
|
815 |
(rec.getMaxY() - (rec.getHeight() / 9) +
|
816 |
(fm.getHeight() / 3)));
|
817 |
pU = new Point2D.Double(rec.getCenterX() - |
818 |
(fm.stringWidth(m_nameUnit) / 2),
|
819 |
(rec.getMinY() + (rec.getHeight() / 9) +
|
820 |
(fm.getHeight() / 2)));
|
821 |
break;
|
822 |
case IBUD:
|
823 |
pD = new Point2D.Double(rec.getCenterX() - |
824 |
(fm.stringWidth(getDescription()) / 2),
|
825 |
(rec.getMaxY() - (rec.getHeight() / 3) +
|
826 |
(fm.getHeight() / 3)));
|
827 |
pU = new Point2D.Double(rec.getCenterX() - |
828 |
(fm.stringWidth(m_nameUnit) / 2),
|
829 |
(rec.getMaxY() - (rec.getHeight() / 9) +
|
830 |
(fm.getHeight() / 3)));
|
831 |
|
832 |
break;
|
833 |
case BIUD:
|
834 |
pD = new Point2D.Double(rec.getCenterX() - |
835 |
(fm.stringWidth(getDescription()) / 2),
|
836 |
(rec.getMaxY() - (rec.getHeight() / 3) +
|
837 |
(fm.getHeight() / 3)));
|
838 |
pU = new Point2D.Double(rec.getCenterX() - |
839 |
(fm.stringWidth(m_nameUnit) / 2),
|
840 |
(rec.getMaxY() - (rec.getHeight() / 9) +
|
841 |
(fm.getHeight() / 3)));
|
842 |
break;
|
843 |
} |
844 |
if (isShowNameUnits()) {
|
845 |
g.drawString(m_nameUnit, (int) pU.x, (int) pU.y); |
846 |
} |
847 |
if (isShowDescription()) {
|
848 |
g.drawString(getDescription(), (int) pD.x, (int) pD.y); |
849 |
} |
850 |
} |
851 |
/**
|
852 |
* Rellena la fuente utilizada para dibujar los intervalos y la unidad de
|
853 |
* medida utilizada.
|
854 |
*
|
855 |
* @param f fuente a utilizar.
|
856 |
*/
|
857 |
public void setFont(Font f) { |
858 |
m_f = f; |
859 |
} |
860 |
|
861 |
/**
|
862 |
* Devuelve la fuente con la que se est? dibujando sobre el graphics.
|
863 |
*
|
864 |
* @return fuente utilizada.
|
865 |
*/
|
866 |
public Font getFont() { |
867 |
return new Font(m_f.getFontName(), m_f.getStyle(), 9); |
868 |
} |
869 |
|
870 |
/**
|
871 |
* Devuelve si el intervalo es variable o si por el contrario es fijo.
|
872 |
*
|
873 |
* @return true si el intervalo es fijo.
|
874 |
*/
|
875 |
public boolean isbIntervalSet() { |
876 |
return m_bIntervalSet;
|
877 |
} |
878 |
|
879 |
/**
|
880 |
* Especificar si el intervalo se debe mantener o es variable.
|
881 |
*
|
882 |
* @param b si se quiere mantener el intervalo especificado.
|
883 |
*/
|
884 |
public void setbIntervalSet(boolean b) { |
885 |
m_bIntervalSet = b; |
886 |
} |
887 |
|
888 |
/**
|
889 |
* Devuelve el porcentaje por el cual hay que multiplicar el intervalo
|
890 |
* para conseguir un intervalo redondeado, de momento con una cifra
|
891 |
* significativas(NUM=1).
|
892 |
*
|
893 |
* @param total intervalo.
|
894 |
*
|
895 |
* @return Porcentaje
|
896 |
*/
|
897 |
private double getExact(double total) { |
898 |
int NUM = 1; |
899 |
double t = 0; |
900 |
double dif = 1; |
901 |
Double d = new Double(total); |
902 |
Long l = new Long(d.longValue()); |
903 |
int num = l.toString().length();
|
904 |
t = ((long) (total / Math.pow(10, num - NUM)) * Math.pow(10, num - NUM)); |
905 |
dif = t / total; |
906 |
|
907 |
if (dif == 0) { |
908 |
return 1; |
909 |
} |
910 |
|
911 |
return dif;
|
912 |
} |
913 |
|
914 |
/**
|
915 |
* Rellena un rect?ngulo.
|
916 |
*
|
917 |
* @param g Graphics sobre el que dibujar.
|
918 |
* @param r Rect?ngulo a rellenar.
|
919 |
*/
|
920 |
private void fillRect(Graphics2D g, Rectangle2D.Double r) { |
921 |
g.fillRect((int) r.x, (int) r.y, (int) r.width, (int) r.height); |
922 |
} |
923 |
|
924 |
/**
|
925 |
* Escribe sobre el Graphics y en la posici?n indicada el tama?o del
|
926 |
* intervalo.
|
927 |
*
|
928 |
* @param g Graphics sobre el que dibujar.
|
929 |
* @param inter Valor del intervalo.
|
930 |
* @param p Punto donde dibujarlo.
|
931 |
*/
|
932 |
private void drawInterval(Graphics2D g, String inter, Point2D.Double p) { |
933 |
//Double l = new Double(inter);
|
934 |
g.setColor(textcolor); |
935 |
g.drawString(inter, (int) p.x, (int) p.y); |
936 |
g.setColor(barcolor); |
937 |
} |
938 |
|
939 |
/**
|
940 |
* DOCUMENT ME!
|
941 |
*
|
942 |
* @return DOCUMENT ME!
|
943 |
*
|
944 |
* @throws SaveException
|
945 |
*
|
946 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
|
947 |
*/
|
948 |
public XMLEntity getXMLEntity() throws SaveException { |
949 |
XMLEntity xml = super.getXMLEntity();
|
950 |
|
951 |
try {
|
952 |
xml.putProperty("type", Layout.RECTANGLESCALEBAR);
|
953 |
xml.putProperty("m_bIntervalSet", m_bIntervalSet);
|
954 |
xml.putProperty("m_dif", m_dif);
|
955 |
xml.putProperty("m_hasleft", m_hasleft);
|
956 |
xml.putProperty("m_nameUnit", m_nameUnit);
|
957 |
xml.putProperty("m_numUnit", m_numUnit);
|
958 |
|
959 |
xml.putProperty("m_height", m_height);
|
960 |
|
961 |
xml.putProperty("m_style", m_style);
|
962 |
xml.putProperty("m_units", m_units);
|
963 |
xml.putProperty("m_interval", m_interval);
|
964 |
xml.putProperty("m_numinterval", m_numinterval);
|
965 |
xml.putProperty("m_numleft", m_numleft);
|
966 |
xml.putProperty("m_mapUnits", m_mapUnits);
|
967 |
xml.putProperty("fontName", m_f.getFontName());
|
968 |
xml.putProperty("fontStyle", m_f.getStyle());
|
969 |
xml.putProperty("numDec", numDec);
|
970 |
xml.putProperty("m_units", m_units);
|
971 |
|
972 |
if (fframeview != null) { |
973 |
Layout layout = fframeview.getLayout(); |
974 |
IFFrame[] fframes = layout.getAllFFrames();
|
975 |
|
976 |
for (int i = 0; i < fframes.length; i++) { |
977 |
if (fframeview.getName().equals(fframes[i].getName())) {
|
978 |
xml.putProperty("index", i);
|
979 |
} |
980 |
} |
981 |
} |
982 |
|
983 |
xml.putProperty("barcolor", StringUtilities.color2String(barcolor));
|
984 |
xml.putProperty("textcolor", StringUtilities.color2String(textcolor));
|
985 |
xml.putProperty("showNameUnits", showNameUnits);
|
986 |
xml.putProperty("showDescription", showDescription);
|
987 |
xml.putProperty("aboveName", aboveName);
|
988 |
xml.putProperty("aboveIntervals", aboveIntervals);
|
989 |
xml.putProperty("aboveDescription", aboveDescription);
|
990 |
} catch (Exception e) { |
991 |
throw new SaveException(e, this.getClass().getName()); |
992 |
} |
993 |
|
994 |
return xml;
|
995 |
} |
996 |
|
997 |
/**
|
998 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
|
999 |
* com.iver.cit.gvsig.project.Project)
|
1000 |
*/
|
1001 |
public void setXMLEntity03(XMLEntity xml, Layout l) { |
1002 |
if (xml.getIntProperty("m_Selected") != 0) { |
1003 |
this.setSelected(true); |
1004 |
} else {
|
1005 |
this.setSelected(false); |
1006 |
} |
1007 |
|
1008 |
this.m_bIntervalSet = xml.getBooleanProperty("m_bIntervalSet"); |
1009 |
this.m_dif = xml.getDoubleProperty("m_dif"); |
1010 |
this.m_hasleft = xml.getIntProperty("m_hasleft"); |
1011 |
this.m_nameUnit = xml.getStringProperty("m_nameUnit"); |
1012 |
this.m_numUnit = xml.getDoubleProperty("m_numUnit"); |
1013 |
|
1014 |
this.m_height = xml.getDoubleProperty("m_height"); |
1015 |
|
1016 |
this.m_style = xml.getIntProperty("m_style"); |
1017 |
this.m_interval = xml.getLongProperty("m_interval"); |
1018 |
this.m_numinterval = xml.getIntProperty("m_numinterval"); |
1019 |
this.m_numleft = xml.getIntProperty("m_numleft"); |
1020 |
this.m_mapUnits = xml.getIntProperty("m_mapUnits"); |
1021 |
this.m_f = new Font(xml.getStringProperty("fontName"), |
1022 |
xml.getIntProperty("fontStyle"), 9); |
1023 |
|
1024 |
fframeview = (FFrameView) l.getFFrame(xml.getIntProperty("index"));
|
1025 |
|
1026 |
if (xml.contains("description")) { //Comprobar que es de la versi?n que cambia el di?logo. |
1027 |
this.barcolor = StringUtilities.string2Color(xml.getStringProperty(
|
1028 |
"barcolor"));
|
1029 |
this.textcolor = StringUtilities.string2Color(xml.getStringProperty(
|
1030 |
"textcolor"));
|
1031 |
this.showNameUnits = xml.getBooleanProperty("showNameUnits"); |
1032 |
this.showDescription = xml.getBooleanProperty("showDescription"); |
1033 |
this.aboveName = xml.getBooleanProperty("aboveName"); |
1034 |
this.aboveIntervals = xml.getBooleanProperty("aboveIntervals"); |
1035 |
this.aboveDescription = xml.getBooleanProperty("aboveDescription"); |
1036 |
} |
1037 |
} |
1038 |
|
1039 |
/**
|
1040 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
|
1041 |
* com.iver.cit.gvsig.project.Project)
|
1042 |
*/
|
1043 |
public void setXMLEntity(XMLEntity xml) { |
1044 |
if (xml.getIntProperty("m_Selected") != 0) { |
1045 |
this.setSelected(true); |
1046 |
} else {
|
1047 |
this.setSelected(false); |
1048 |
} |
1049 |
|
1050 |
this.m_bIntervalSet = xml.getBooleanProperty("m_bIntervalSet"); |
1051 |
this.m_dif = xml.getDoubleProperty("m_dif"); |
1052 |
this.m_hasleft = xml.getIntProperty("m_hasleft"); |
1053 |
this.m_nameUnit = xml.getStringProperty("m_nameUnit"); |
1054 |
this.m_numUnit = xml.getDoubleProperty("m_numUnit"); |
1055 |
|
1056 |
this.m_height = xml.getDoubleProperty("m_height"); |
1057 |
|
1058 |
this.m_style = xml.getIntProperty("m_style"); |
1059 |
this.m_interval = xml.getDoubleProperty("m_interval"); |
1060 |
this.m_numinterval = xml.getIntProperty("m_numinterval"); |
1061 |
this.m_numleft = xml.getIntProperty("m_numleft"); |
1062 |
this.m_mapUnits = xml.getIntProperty("m_mapUnits"); |
1063 |
this.m_f = new Font(xml.getStringProperty("fontName"), |
1064 |
xml.getIntProperty("fontStyle"), 9); |
1065 |
setRotation(xml.getDoubleProperty("m_rotation"));
|
1066 |
|
1067 |
if (xml.contains("m_units")) { //Comprobaci?n por versi?n 0.5 |
1068 |
setUnits(xml.getIntProperty("m_units"));
|
1069 |
} |
1070 |
|
1071 |
if (xml.contains("index")) { |
1072 |
dependenceIndex = xml.getIntProperty("index");
|
1073 |
} |
1074 |
|
1075 |
|
1076 |
if (xml.contains("showDescription")) { //Comprobar que es de la versi?n que cambia el di?logo. |
1077 |
this.barcolor = StringUtilities.string2Color(xml.getStringProperty(
|
1078 |
"barcolor"));
|
1079 |
|
1080 |
this.textcolor = StringUtilities.string2Color(xml.getStringProperty(
|
1081 |
"textcolor"));
|
1082 |
this.showNameUnits = xml.getBooleanProperty("showNameUnits"); |
1083 |
this.showDescription = xml.getBooleanProperty("showDescription"); |
1084 |
this.aboveName = xml.getBooleanProperty("aboveName"); |
1085 |
this.aboveIntervals = xml.getBooleanProperty("aboveIntervals"); |
1086 |
this.aboveDescription = xml.getBooleanProperty("aboveDescription"); |
1087 |
} |
1088 |
|
1089 |
if (xml.contains("numDec")) { |
1090 |
setNumDec(xml.getIntProperty("numDec"));
|
1091 |
} |
1092 |
} |
1093 |
|
1094 |
/**
|
1095 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNameFFrame()
|
1096 |
*/
|
1097 |
public String getNameFFrame() { |
1098 |
return PluginServices.getText(this, "escala")+ num; |
1099 |
} |
1100 |
|
1101 |
/**
|
1102 |
* Inserta el color de la escala gr?fica.
|
1103 |
*
|
1104 |
* @param color Color de la escala gr?fica.
|
1105 |
*/
|
1106 |
public void setBarColor(Color color) { |
1107 |
barcolor = color; |
1108 |
} |
1109 |
|
1110 |
/**
|
1111 |
* Inserta el color del texto.
|
1112 |
*
|
1113 |
* @param color Color del texto.
|
1114 |
*/
|
1115 |
public void setTextColor(Color color) { |
1116 |
textcolor = color; |
1117 |
} |
1118 |
|
1119 |
/**
|
1120 |
* Devuelve el color de la escala gr?fica.
|
1121 |
*
|
1122 |
* @return Color de la escala gr?fica.
|
1123 |
*/
|
1124 |
public Color getBarColor() { |
1125 |
return barcolor;
|
1126 |
} |
1127 |
|
1128 |
/**
|
1129 |
* Devuelve el color del texto.
|
1130 |
*
|
1131 |
* @return Color del texto.
|
1132 |
*/
|
1133 |
public Color getTextColor() { |
1134 |
return textcolor;
|
1135 |
} |
1136 |
|
1137 |
/**
|
1138 |
* Devuelve true si se debe mostrar el nombre de las unidades de medida de
|
1139 |
* la escala gr?fica.
|
1140 |
*
|
1141 |
* @return True si se muestra las unidades de medida.
|
1142 |
*/
|
1143 |
public boolean isShowNameUnits() { |
1144 |
return showNameUnits;
|
1145 |
} |
1146 |
|
1147 |
/**
|
1148 |
* Inserta si se debe de mostrar el nombre de las unidades de medida o no.
|
1149 |
*
|
1150 |
* @param showNameUnits True si se muestra el nombre de las unidades de
|
1151 |
* medida.
|
1152 |
*/
|
1153 |
public void setShowNameUnits(boolean showNameUnits) { |
1154 |
this.showNameUnits = showNameUnits;
|
1155 |
} |
1156 |
|
1157 |
/**
|
1158 |
* Devuelve true si se muestra la descripci?n a la parte de arriba de la
|
1159 |
* escala gr?fica.
|
1160 |
*
|
1161 |
* @return True si se muestra arriba de la escala gr?fica.
|
1162 |
*/
|
1163 |
public boolean isAboveDescription() { |
1164 |
return aboveDescription;
|
1165 |
} |
1166 |
|
1167 |
/**
|
1168 |
* Introduce true si se muestra arriba de la escala gr?fica la descripci?n.
|
1169 |
*
|
1170 |
* @param aboveDescription True si se muestra arriba la descripci?n.
|
1171 |
*/
|
1172 |
public void setAboveDescription(boolean aboveDescription) { |
1173 |
this.aboveDescription = aboveDescription;
|
1174 |
} |
1175 |
|
1176 |
/**
|
1177 |
* Devuelve true si se muestran a la parte de arriba los valores de los
|
1178 |
* intervalos.
|
1179 |
*
|
1180 |
* @return True si se muestran arriba de la escala gr?fica.
|
1181 |
*/
|
1182 |
public boolean isAboveIntervals() { |
1183 |
return aboveIntervals;
|
1184 |
} |
1185 |
|
1186 |
/**
|
1187 |
* Inserta si se muestran los valores de los intervalos a la parte de
|
1188 |
* arriba de la escala o debajo.
|
1189 |
*
|
1190 |
* @param aboveIntervals True si se muestran los valores de los intervalos
|
1191 |
* a la parte de arriba de la escala gr?fica.
|
1192 |
*/
|
1193 |
public void setAboveIntervals(boolean aboveIntervals) { |
1194 |
this.aboveIntervals = aboveIntervals;
|
1195 |
} |
1196 |
|
1197 |
/**
|
1198 |
* Devuelve si se muestra a la parte de arriba de la escala gr?fica el
|
1199 |
* nombre de las unidades de medida o debajo.
|
1200 |
*
|
1201 |
* @return True si se muestra a la parte de arriba de la escala gr?fica.
|
1202 |
*/
|
1203 |
public boolean isAboveName() { |
1204 |
return aboveName;
|
1205 |
} |
1206 |
|
1207 |
/**
|
1208 |
* Inserta si el nombre se muestra a la parte de arriba de la escala
|
1209 |
* gr?fica o a la parte de abajo.
|
1210 |
*
|
1211 |
* @param aboveName True si se muestra a la parte de arriba de la escala
|
1212 |
* gr?fica.
|
1213 |
*/
|
1214 |
public void setAboveName(boolean aboveName) { |
1215 |
this.aboveName = aboveName;
|
1216 |
} |
1217 |
|
1218 |
/**
|
1219 |
* Devuelve si se debe mostrar la descripci?n o no.
|
1220 |
*
|
1221 |
* @return True si se muestra la descripci?n.
|
1222 |
*/
|
1223 |
public boolean isShowDescription() { |
1224 |
return showDescription;
|
1225 |
} |
1226 |
|
1227 |
/**
|
1228 |
* Inserta si se muestra o no la descripci?n.
|
1229 |
*
|
1230 |
* @param showDescription True si se muestra la descripci?n.
|
1231 |
*/
|
1232 |
public void setShowDescription(boolean showDescription) { |
1233 |
this.showDescription = showDescription;
|
1234 |
} |
1235 |
|
1236 |
/**
|
1237 |
* Devuelve la descripci?n de la escala.
|
1238 |
*
|
1239 |
* @return Descripci?n de la escala.
|
1240 |
*/
|
1241 |
public String getDescription() { |
1242 |
if (fframeview!=null) |
1243 |
return "1:" + String.valueOf(fframeview.getScale()); |
1244 |
return "1:"; |
1245 |
} |
1246 |
|
1247 |
/**
|
1248 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#print(java.awt.Graphics2D,
|
1249 |
* java.awt.geom.AffineTransform)
|
1250 |
*/
|
1251 |
public void print(Graphics2D g, AffineTransform at) |
1252 |
throws DriverException {
|
1253 |
draw(g, at, null, null); |
1254 |
} |
1255 |
|
1256 |
/**
|
1257 |
* Update the dependences that have this FFrame with the other FFrame.
|
1258 |
*
|
1259 |
* @param fframes Other FFrames.
|
1260 |
*/
|
1261 |
public void initDependence(IFFrame[] fframes) { |
1262 |
if ((dependenceIndex != -1) && |
1263 |
fframes[dependenceIndex] instanceof FFrameView) {
|
1264 |
fframeview = (FFrameView) fframes[dependenceIndex]; |
1265 |
} |
1266 |
} |
1267 |
|
1268 |
/**
|
1269 |
* DOCUMENT ME!
|
1270 |
*
|
1271 |
* @param d DOCUMENT ME!
|
1272 |
*
|
1273 |
* @return DOCUMENT ME!
|
1274 |
*/
|
1275 |
public String format(double d) { |
1276 |
NumberFormat nf = NumberFormat.getInstance(); |
1277 |
|
1278 |
if ((d % (long) d) != 0) { |
1279 |
nf.setMaximumFractionDigits(getNumDec()); |
1280 |
} else {
|
1281 |
nf.setMaximumFractionDigits(0);
|
1282 |
} |
1283 |
|
1284 |
//String s = String.valueOf(nf.format(d));
|
1285 |
//s=s.replace('.','*');
|
1286 |
//s = s.replace(',', '.');
|
1287 |
//s=s.replace('*',',');
|
1288 |
return nf.format(d); //(Double.valueOf(s).doubleValue()); |
1289 |
} |
1290 |
|
1291 |
/**
|
1292 |
* DOCUMENT ME!
|
1293 |
*
|
1294 |
* @return DOCUMENT ME!
|
1295 |
*/
|
1296 |
public int getNumDec() { |
1297 |
return numDec;
|
1298 |
} |
1299 |
|
1300 |
/**
|
1301 |
* DOCUMENT ME!
|
1302 |
*
|
1303 |
* @param numDec DOCUMENT ME!
|
1304 |
*/
|
1305 |
public void setNumDec(int numDec) { |
1306 |
this.numDec = numDec;
|
1307 |
} |
1308 |
|
1309 |
public void initialize() { |
1310 |
// TODO Auto-generated method stub
|
1311 |
|
1312 |
} |
1313 |
private final static int DUIB=0; |
1314 |
private final static int DUBI=1; |
1315 |
private final static int DBIU=2; |
1316 |
private final static int DIBU=3; |
1317 |
private final static int UIBD=4; |
1318 |
private final static int UBID=5; |
1319 |
private final static int IBUD=6; |
1320 |
private final static int BIUD=7; |
1321 |
private int getFormat(){ |
1322 |
if (isAboveDescription()){
|
1323 |
if (isAboveName()){
|
1324 |
if (isAboveIntervals()){
|
1325 |
return DUIB;
|
1326 |
} |
1327 |
return DUBI;
|
1328 |
} |
1329 |
if (isAboveIntervals()){
|
1330 |
return DIBU;
|
1331 |
} |
1332 |
return DBIU;
|
1333 |
} |
1334 |
if (isAboveName()){
|
1335 |
if (isAboveIntervals()){
|
1336 |
return UIBD;
|
1337 |
} |
1338 |
return UBID;
|
1339 |
} |
1340 |
if (isAboveIntervals()){
|
1341 |
return IBUD;
|
1342 |
} |
1343 |
return BIUD;
|
1344 |
} |
1345 |
} |