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