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