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