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