svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameScaleBar.java @ 312
History | View | Annotate | Download (23.4 KB)
1 |
/*
|
---|---|
2 |
* Created on 20-feb-2004
|
3 |
*
|
4 |
* To change the template for this generated file go to
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
6 |
*/
|
7 |
package com.iver.cit.gvsig.gui.layout.fframes; |
8 |
|
9 |
import com.iver.cit.gvsig.fmap.FConstant; |
10 |
import com.iver.cit.gvsig.fmap.FMap; |
11 |
import com.iver.cit.gvsig.gui.layout.Attributes; |
12 |
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities; |
13 |
import com.iver.cit.gvsig.gui.layout.Layout; |
14 |
import com.iver.cit.gvsig.project.Project; |
15 |
import com.iver.cit.gvsig.project.castor.View; |
16 |
|
17 |
import com.iver.utiles.XMLEntity; |
18 |
|
19 |
import org.apache.log4j.Logger; |
20 |
|
21 |
import java.awt.Color; |
22 |
import java.awt.Font; |
23 |
import java.awt.Graphics2D; |
24 |
import java.awt.geom.AffineTransform; |
25 |
import java.awt.geom.Point2D; |
26 |
import java.awt.geom.Rectangle2D; |
27 |
import java.awt.image.BufferedImage; |
28 |
|
29 |
|
30 |
/**
|
31 |
* FFrame para introducir una barra de escala en el Layout.
|
32 |
*
|
33 |
* @author Vicente Caballero Navarro
|
34 |
*/
|
35 |
public class FFrameScaleBar extends FFrame { |
36 |
private static Logger logger = Logger.getLogger(FFrameView.class.getName()); |
37 |
private static final int NUMERO = 0; |
38 |
private static final int BARRA1 = 1; |
39 |
private static final int BARRA2 = 2; |
40 |
private static final int BARRA3 = 3; |
41 |
private static final int BARRA4 = 4; |
42 |
private static final int DIFL = 25; |
43 |
private static final int DIFR = 4; |
44 |
private static final int DIFUP = 4; |
45 |
private boolean m_bIntervalSet = true; |
46 |
private int m_style = NUMERO; |
47 |
private int m_units = 1; //Metros |
48 |
private int m_mapUnits = 1; //unidad de medida de la vista(Metros) |
49 |
private long m_interval = 1; |
50 |
private int m_numinterval = 3; |
51 |
private int m_numleft = 2; |
52 |
private double m_height = 0; |
53 |
//private FMap m_fmap = null;
|
54 |
private FFrameView fframeview = null; |
55 |
private double m_typeUnit = Attributes.CHANGE[1]; //METROS; |
56 |
private String m_nameUnit = null; |
57 |
private double m_numUnit = 0; |
58 |
private double m_dif = 1; |
59 |
private int m_hasleft = 0; |
60 |
private Font m_f = new Font("Monospaced", Font.PLAIN, 9); |
61 |
private int num=0; |
62 |
private View view = null; |
63 |
|
64 |
/**
|
65 |
* Creates a new FFrameScaleBar object.
|
66 |
*/
|
67 |
public FFrameScaleBar() {
|
68 |
} |
69 |
|
70 |
|
71 |
public void setFFrameView(FFrameView f) { |
72 |
fframeview = f; |
73 |
view = f.getView(); |
74 |
setMapUnits(f.getMapUnits()); |
75 |
|
76 |
//setFMap(f.getFMap());
|
77 |
setHeight(f.getBoundBox().height); |
78 |
|
79 |
/*if (f.getTypeScale()!=0){
|
80 |
isFixed=true;
|
81 |
}else{
|
82 |
isFixed=false;
|
83 |
}
|
84 |
*/
|
85 |
} |
86 |
|
87 |
/**
|
88 |
* Devuelve el FFrameView que se representa con la escala.
|
89 |
*
|
90 |
* @return FFrameView a representar.
|
91 |
*/
|
92 |
public FFrameView getFFrameView() {
|
93 |
return fframeview;
|
94 |
} |
95 |
|
96 |
/**
|
97 |
* Pone el FMap de la vista que representa a la escala.
|
98 |
*
|
99 |
* @return DOCUMENT ME!
|
100 |
*/
|
101 |
|
102 |
/* public void setFMap(FMap map) {
|
103 |
m_fmap = map;
|
104 |
}
|
105 |
*/
|
106 |
|
107 |
/**
|
108 |
* Devuelve el FMap de la vista que se representa en la escala.
|
109 |
*
|
110 |
* @return FMap.
|
111 |
*/
|
112 |
public FMap getFMap() {
|
113 |
return fframeview.getFMap();
|
114 |
} |
115 |
|
116 |
/**
|
117 |
* Rellenar el estilo de barra de escala que se elige.
|
118 |
*
|
119 |
* @param s entero que representa el tipo de barra seleccionada.
|
120 |
*/
|
121 |
public void setStyle(int s) { |
122 |
m_style = s; |
123 |
} |
124 |
|
125 |
/**
|
126 |
* Devuelve el tipo de escala a dibujar.
|
127 |
*
|
128 |
* @return entero.
|
129 |
*/
|
130 |
public int getStyle() { |
131 |
return m_style;
|
132 |
} |
133 |
|
134 |
/**
|
135 |
* Rellenar el tama?o de un intervalo.
|
136 |
*
|
137 |
* @param s tama?o de un intervalo.
|
138 |
*/
|
139 |
public void setInterval(long s) { |
140 |
m_interval = s; |
141 |
|
142 |
if (m_numleft != 0) { |
143 |
m_hasleft = 1;
|
144 |
} |
145 |
|
146 |
Rectangle2D.Double rect = getBoundBox();
|
147 |
double difUp = (rect.height / DIFUP);
|
148 |
double difL = (rect.width / DIFL);
|
149 |
double difR = (rect.width / DIFR);
|
150 |
double n = (rect.width - difL - difR);
|
151 |
m_numUnit = (m_interval * m_typeUnit) / getScaleView(); |
152 |
m_numinterval = (int) (n / m_numUnit) - m_hasleft;
|
153 |
m_dif = 1;
|
154 |
} |
155 |
|
156 |
/**
|
157 |
* Devuelve el valor del intervalo.
|
158 |
*
|
159 |
* @return long.
|
160 |
*/
|
161 |
public long obtainInterval() { |
162 |
Rectangle2D.Double rect = getBoundBox();
|
163 |
|
164 |
if (m_numleft != 0) { |
165 |
m_hasleft = 1;
|
166 |
} |
167 |
|
168 |
double difUp = (rect.height / DIFUP);
|
169 |
double difL = (rect.width / DIFL);
|
170 |
double difR = (rect.width / DIFR);
|
171 |
double n = (rect.width - difL - difR);
|
172 |
m_numUnit = n / (m_numinterval + m_hasleft); |
173 |
|
174 |
double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
|
175 |
m_dif = getExact(scaleXunit); |
176 |
m_numUnit = m_numUnit * m_dif; |
177 |
m_interval = (long) (scaleXunit * m_dif);
|
178 |
|
179 |
return m_interval;
|
180 |
} |
181 |
|
182 |
/**
|
183 |
* Rellenar el n?mero de intervalos.
|
184 |
*
|
185 |
* @param s n?mero de intervalos.
|
186 |
*/
|
187 |
public void setNumInterval(int s) { |
188 |
m_numinterval = s; |
189 |
|
190 |
if (m_numleft != 0) { |
191 |
m_hasleft = 1;
|
192 |
} |
193 |
|
194 |
Rectangle2D.Double rect = getBoundBox();
|
195 |
double difUp = (rect.height / DIFUP);
|
196 |
double difL = (rect.width / DIFL);
|
197 |
double difR = (rect.width / DIFR);
|
198 |
double n = (rect.width - difL - difR);
|
199 |
m_numUnit = n / (m_numinterval + m_hasleft); |
200 |
|
201 |
double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
|
202 |
m_dif = getExact(scaleXunit); |
203 |
m_numUnit = m_numUnit * m_dif; |
204 |
m_interval = (long) (scaleXunit * m_dif);
|
205 |
} |
206 |
|
207 |
/**
|
208 |
* Devuelve el n?mero de intervalos por encima del cero.
|
209 |
*
|
210 |
* @return entero.
|
211 |
*/
|
212 |
public int getNumInterval() { |
213 |
return m_numinterval;
|
214 |
} |
215 |
|
216 |
/**
|
217 |
* Rellenar el n?mero de intervalos a la izquierda del cero.
|
218 |
*
|
219 |
* @param s n?mero de intervalos a la izquierda.
|
220 |
*/
|
221 |
public void setNumLeft(int s) { |
222 |
m_numleft = s; |
223 |
} |
224 |
|
225 |
/**
|
226 |
* Devuelve el n?mero de intervalos en los que se quiere particionar el
|
227 |
* intervalo que se queda por debajo del cero.
|
228 |
*
|
229 |
* @return entero.
|
230 |
*/
|
231 |
public int getNumLeft() { |
232 |
return m_numleft;
|
233 |
} |
234 |
|
235 |
/**
|
236 |
* Seleccionar ,a true, si se quiere o, a false, si no mantener los
|
237 |
* intervalos.
|
238 |
*
|
239 |
* @param b boolean a true si se quiere mantener los intervalos.
|
240 |
*/
|
241 |
public void setIntervalSet(boolean b) { |
242 |
m_bIntervalSet = b; |
243 |
} |
244 |
|
245 |
/**
|
246 |
* Seleccionar la unidad de medida a representar en la barra de escala.
|
247 |
*
|
248 |
* @param s entero que representa la unidad de medida que se selecciona.
|
249 |
*/
|
250 |
public void setUnits(int s) { |
251 |
m_units = s; |
252 |
m_typeUnit = Attributes.CHANGE[s];
|
253 |
m_nameUnit = FConstant.NAMES[s]; |
254 |
} |
255 |
|
256 |
/**
|
257 |
* Devuelve un entero que representa el tipo de unidades que representamos.
|
258 |
*
|
259 |
* @return entero.
|
260 |
*/
|
261 |
public int getUnits() { |
262 |
return m_units;
|
263 |
} |
264 |
|
265 |
/**
|
266 |
* Devuelve el long que representa el intervalo.
|
267 |
*
|
268 |
* @return Intervalo.
|
269 |
*/
|
270 |
public long getInterval() { |
271 |
return m_interval;
|
272 |
} |
273 |
|
274 |
/**
|
275 |
* Rellenar el rect?ngulo de la vista sobre la que se obtiene la escala.
|
276 |
*
|
277 |
* @param d Rect?ngulo.
|
278 |
*/
|
279 |
public void setHeight(double d) { |
280 |
m_height = d; |
281 |
} |
282 |
|
283 |
/**
|
284 |
* Rellena la unidad de medida en la que est? la vista.
|
285 |
*
|
286 |
* @param i entero que representa la unidad de medida de la vista.
|
287 |
*/
|
288 |
public void setMapUnits(int i) { |
289 |
m_mapUnits = i; |
290 |
} |
291 |
|
292 |
/*public void setIsFixed(boolean b){
|
293 |
isFixed=b;
|
294 |
}*/
|
295 |
/*public void setScaleView(long l){
|
296 |
m_scaleView=l;
|
297 |
}
|
298 |
*/
|
299 |
|
300 |
/**
|
301 |
* Devuelve la escala de la vista seleccionada.
|
302 |
*
|
303 |
* @return la escala de la vista.
|
304 |
*/
|
305 |
private long getScaleView() { |
306 |
return fframeview.getScale();
|
307 |
|
308 |
/* if (isFixed){
|
309 |
return m_scaleView;
|
310 |
}
|
311 |
return FLayoutUtilities.getScaleView(m_fmap, m_height);
|
312 |
*/
|
313 |
} |
314 |
|
315 |
/**
|
316 |
* M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
|
317 |
* la transformada afin que se debe de aplicar y el rect?ngulo que se debe
|
318 |
* de dibujar.
|
319 |
*
|
320 |
* @param g Graphics
|
321 |
* @param at Transformada afin.
|
322 |
* @param rv rect?ngulo sobre el que hacer un clip.
|
323 |
* @param imgBase DOCUMENT ME!
|
324 |
*/
|
325 |
public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
326 |
BufferedImage imgBase) {
|
327 |
Rectangle2D.Double r = getBoundingBox(at);
|
328 |
|
329 |
if (intersects(rv, r)) {
|
330 |
|
331 |
if (fframeview==null || fframeview.getFMap() == null) { |
332 |
drawEmpty(g); |
333 |
} else {
|
334 |
switch (m_style) {
|
335 |
case (NUMERO):
|
336 |
|
337 |
double scalex = r.getWidth() / (8); |
338 |
g.setColor(Color.black);
|
339 |
if (m_f!=null){ |
340 |
m_f = new Font(m_f.getFontName(), m_f.getStyle(), |
341 |
(int) (scalex));
|
342 |
g.setFont(m_f); |
343 |
} |
344 |
g.drawString(" 1:" + getScaleView(), (int) r.x, |
345 |
(int) (r.y + (r.height / 2))); |
346 |
//System.out.println("Escala real " + getScaleView());
|
347 |
|
348 |
break;
|
349 |
|
350 |
case (BARRA1):
|
351 |
case (BARRA2):
|
352 |
case (BARRA3):
|
353 |
case (BARRA4):
|
354 |
drawBar(m_style, g, at); |
355 |
|
356 |
break;
|
357 |
} |
358 |
} |
359 |
} |
360 |
} |
361 |
|
362 |
/**
|
363 |
* Rellena con el rect?ngulo que se pasa como par?metro el boundBox(en
|
364 |
* cent?metros) del fframe del cual con una transformaci?n se podr?
|
365 |
* calcular el BoundingBox (en pixels).
|
366 |
*
|
367 |
* @param r Rect?ngulo en cent?metros.
|
368 |
*/
|
369 |
public void setBoundBox(Rectangle2D.Double r) { |
370 |
if ((m_numUnit < 1) || (fframeview.getFMap() == null)) { |
371 |
super.setBoundBox(r);
|
372 |
|
373 |
return;
|
374 |
} |
375 |
|
376 |
double difL = (r.width / DIFL);
|
377 |
double difR = (r.width / DIFR);
|
378 |
|
379 |
if (m_bIntervalSet) {
|
380 |
m_numinterval = (int) (((r.width - (difL + difR)) * m_dif) / m_numUnit) -
|
381 |
m_hasleft; |
382 |
} |
383 |
|
384 |
if (m_numinterval < 1) { |
385 |
m_numinterval = 1;
|
386 |
r.width = ((m_numinterval + m_hasleft) * m_numUnit) + difL + difR; |
387 |
} |
388 |
|
389 |
getBoundBox().setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight()); |
390 |
} |
391 |
|
392 |
/**
|
393 |
* Dibuja sobre el Graphics la escala gr?fica.
|
394 |
*
|
395 |
* @param type Tipo de barra.
|
396 |
* @param g Graphics sobre el que dibujar.
|
397 |
* @param at Matriz de transformaci?n.
|
398 |
*/
|
399 |
private void drawBar(int type, Graphics2D g, AffineTransform at) { |
400 |
Rectangle2D.Double rect = getBoundBox();
|
401 |
Rectangle2D.Double r = getBoundingBox(at);
|
402 |
double numleft = m_numleft;
|
403 |
double difUp = (rect.height / DIFUP);
|
404 |
double difL = (rect.width / DIFL);
|
405 |
double difR = (rect.width / DIFR);
|
406 |
double n = (rect.width - difL - difR);
|
407 |
|
408 |
//double scalex = r.getWidth() / (8);
|
409 |
if (!m_bIntervalSet) {
|
410 |
m_numUnit = n / (m_numinterval + m_hasleft); |
411 |
|
412 |
double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
|
413 |
m_dif = getExact(scaleXunit); |
414 |
m_numUnit = m_numUnit * m_dif; |
415 |
m_interval = (long) (scaleXunit * m_dif);
|
416 |
} |
417 |
|
418 |
if (m_bIntervalSet) {
|
419 |
m_numUnit = (m_interval * m_typeUnit) / (m_dif * getScaleView()); |
420 |
m_numinterval = (int) (((rect.width - (difL + difR)) * m_dif) / m_numUnit) -
|
421 |
m_hasleft; |
422 |
} |
423 |
|
424 |
if (m_numinterval < 1) { |
425 |
m_numinterval = 1;
|
426 |
rect.width = ((m_numinterval + m_hasleft) * m_numUnit) + difL + |
427 |
difR; |
428 |
} |
429 |
|
430 |
double h = 0; |
431 |
|
432 |
if (type == BARRA1) {
|
433 |
h = (rect.height - (difUp * 2));
|
434 |
} else if ((type == BARRA2) || (type == BARRA3)) { |
435 |
h = (rect.height - (difUp * 2)) / 2; |
436 |
} |
437 |
|
438 |
//Dibujar el rect?ngulo que bordea todo.
|
439 |
Rectangle2D.Double rectotal = (FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x + |
440 |
difL), (rect.y + difUp), |
441 |
m_numUnit * (m_hasleft + m_numinterval), h), at)); |
442 |
g.setColor(Color.white);
|
443 |
g.fillRect((int) rectotal.x, (int) rectotal.y, (int) (rectotal.width), |
444 |
(int) rectotal.height);
|
445 |
g.setColor(Color.black);
|
446 |
m_f = new Font(m_f.getFontName(), m_f.getStyle(), |
447 |
(int) ((r.getWidth() / 8) / (m_numinterval + m_hasleft))); |
448 |
g.setFont(m_f); |
449 |
|
450 |
//Derecha del cero
|
451 |
for (int i = 0; i < m_numinterval; i++) { |
452 |
Rectangle2D.Double recder = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x + |
453 |
(difL) + ((m_numUnit * i) + (m_hasleft * m_numUnit))), |
454 |
(rect.y + (difUp)), (m_numUnit), |
455 |
(rect.height - (difUp * 2)) / 2), at); |
456 |
Rectangle2D.Double recderB = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x + |
457 |
(difL) + ((m_numUnit * i) + (m_hasleft * m_numUnit))), |
458 |
(rect.y + difUp) + ((rect.height - (difUp * 2)) / 2), |
459 |
(m_numUnit), ((rect.height - (difUp * 2)) / 2)), at); |
460 |
|
461 |
// Correcci?n cuando la altura en pixels del rectangulo es impar.
|
462 |
rectotal.y = recder.y; |
463 |
recderB.height = rectotal.height - recder.height + 0.5;
|
464 |
|
465 |
if (i == (m_numinterval - 1)) { |
466 |
if (recder.getMaxX() != rectotal.getMaxX()) {
|
467 |
recder.width = (recder.width + recder.getMaxX()) - |
468 |
rectotal.getMaxX(); |
469 |
} |
470 |
|
471 |
if (recderB.getMaxX() != rectotal.getMaxX()) {
|
472 |
recderB.width = (recderB.width + recderB.getMaxX()) - |
473 |
rectotal.getMaxX(); |
474 |
} |
475 |
} |
476 |
|
477 |
if (recderB.getMaxY() != rectotal.getMaxY()) {
|
478 |
recderB.height = (recderB.height + recderB.getMaxY()) - |
479 |
rectotal.getMaxY(); |
480 |
} |
481 |
|
482 |
if ((m_numleft % 2) == 0) { |
483 |
if ((i % 2) == 0) { |
484 |
if ((type == BARRA1) || (type == BARRA2)) {
|
485 |
fillRect(g, recder); |
486 |
} else if (type == BARRA3) { |
487 |
g.drawRect((int) recder.x, (int) recder.y, |
488 |
(int) recder.width, (int) recder.height); |
489 |
} |
490 |
} else if (type == BARRA1) { |
491 |
fillRect(g, recderB); |
492 |
} |
493 |
} else {
|
494 |
if ((i % 2) != 0) { |
495 |
if ((type == BARRA1) || (type == BARRA2)) {
|
496 |
fillRect(g, recder); |
497 |
} else if (type == BARRA3) { |
498 |
g.drawRect((int) recderB.x, (int) recderB.y, |
499 |
(int) recderB.width, (int) recderB.height); |
500 |
} |
501 |
} else if (type == BARRA1) { |
502 |
fillRect(g, recderB); |
503 |
} |
504 |
} |
505 |
|
506 |
long inter = (long) (m_interval * i); |
507 |
Long l = new Long(inter); |
508 |
int pos = ((int) (r.getWidth() / (m_numinterval + m_hasleft)) * l.toString() |
509 |
.length()) / 24;
|
510 |
Point2D.Double p = new Point2D.Double(recder.x - pos, recder.y); |
511 |
drawInterval(g, inter, p); |
512 |
} |
513 |
|
514 |
//?ltimo n?mero a dibujar.
|
515 |
long inter = (long) (m_interval * m_numinterval); |
516 |
Long l = new Long(inter); |
517 |
int pos = ((int) (r.getWidth() / (m_numinterval + m_hasleft)) * l.toString() |
518 |
.length()) / 24;
|
519 |
Point2D.Double p = new Point2D.Double(rectotal.getMaxX() - pos, |
520 |
rectotal.y); |
521 |
drawInterval(g, inter, p); |
522 |
|
523 |
//Izquierda del cero
|
524 |
for (int i = 0; i < m_numleft; i++) { |
525 |
Rectangle2D.Double reciz = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x + |
526 |
difL + ((m_numUnit / m_numleft) * i)), |
527 |
(rect.y + difUp), (m_numUnit / numleft), |
528 |
(rect.height - (difUp * 2)) / 2), at); |
529 |
Rectangle2D.Double recizB = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x + |
530 |
difL + ((m_numUnit / m_numleft) * i)), |
531 |
(rect.y + difUp) + ((rect.height - (difUp * 2)) / 2), |
532 |
(m_numUnit / numleft), ((rect.height - (difUp * 2)) / 2)), |
533 |
at); |
534 |
|
535 |
//Correcci?n cuando la altura en pixels del rectangulo es impar.
|
536 |
reciz.y = rectotal.y; |
537 |
recizB.height = rectotal.height - reciz.height + 0.5;
|
538 |
|
539 |
if ((i % 2) == 0) { |
540 |
if ((type == BARRA1) || (type == BARRA2)) {
|
541 |
fillRect(g, reciz); |
542 |
} else if (type == BARRA3) { |
543 |
g.drawRect((int) reciz.x, (int) reciz.y, (int) reciz.width, |
544 |
(int) reciz.height);
|
545 |
} |
546 |
} else if (type == BARRA1) { |
547 |
fillRect(g, recizB); |
548 |
} |
549 |
} |
550 |
|
551 |
if (m_numleft > 0) { |
552 |
inter = (long) (m_interval);
|
553 |
l = new Long(inter); |
554 |
pos = ((int) (r.getWidth() / (m_numinterval + m_hasleft)) * l.toString()
|
555 |
.length()) / 24;
|
556 |
|
557 |
Point2D.Double p1 = new Point2D.Double(rectotal.x - pos, rectotal.y); |
558 |
drawInterval(g, inter, p1); |
559 |
} |
560 |
|
561 |
//Se dibuja el rect?ngulo que bordea toda la escala gr?fica.
|
562 |
g.drawRect((int) rectotal.x, (int) rectotal.y, (int) (rectotal.width), |
563 |
(int) rectotal.height);
|
564 |
|
565 |
//Nombre de las unidades utilizadas.
|
566 |
p = new Point2D.Double(rect.getMaxX() - difR + 0.1, |
567 |
(rect.getMaxY() - difUp)); |
568 |
p = FLayoutUtilities.fromSheetPoint(p, at); |
569 |
g.drawString(m_nameUnit, (int) p.x, (int) p.y); |
570 |
} |
571 |
|
572 |
/**
|
573 |
* Rellena la fuente utilizada para dibujar los intervalos y la unidad de
|
574 |
* medida utilizada.
|
575 |
*
|
576 |
* @param f fuente a utilizar.
|
577 |
*/
|
578 |
public void setFont(Font f) { |
579 |
m_f = f; |
580 |
} |
581 |
|
582 |
/**
|
583 |
* Devuelve la fuente con la que se est? dibujando sobre el graphics.
|
584 |
*
|
585 |
* @return fuente utilizada.
|
586 |
*/
|
587 |
public Font getFont() { |
588 |
return new Font(m_f.getFontName(), m_f.getStyle(), 9); |
589 |
} |
590 |
|
591 |
/**
|
592 |
* Devuelve si el intervalo es variable o si por el contrario es fijo.
|
593 |
*
|
594 |
* @return true si el intervalo es fijo.
|
595 |
*/
|
596 |
public boolean isbIntervalSet() { |
597 |
return m_bIntervalSet;
|
598 |
} |
599 |
|
600 |
/**
|
601 |
* Especificar si el intervalo se debe mantener o es variable.
|
602 |
*
|
603 |
* @param b si se quiere mantener el intervalo especificado.
|
604 |
*/
|
605 |
public void setbIntervalSet(boolean b) { |
606 |
m_bIntervalSet = b; |
607 |
} |
608 |
|
609 |
/**
|
610 |
* Devuelve el porcentaje por el cual hay que multiplicar el intervalo
|
611 |
* para conseguir un intervalo redondeado, de momento con dos cifras
|
612 |
* significativas(NUM=1).
|
613 |
*
|
614 |
* @param total intervalo.
|
615 |
*
|
616 |
* @return Porcentaje
|
617 |
*/
|
618 |
private double getExact(double total) { |
619 |
int NUM = 1; |
620 |
double t = 0; |
621 |
double dif = 1; |
622 |
Double d = new Double(total); |
623 |
Long l = new Long(d.longValue()); |
624 |
int num = l.toString().length();
|
625 |
t = ((long) (total / Math.pow(10, num - NUM)) * Math.pow(10, num - NUM)); |
626 |
dif = t / total; |
627 |
|
628 |
return dif;
|
629 |
} |
630 |
|
631 |
/**
|
632 |
* Rellena un rect?ngulo.
|
633 |
*
|
634 |
* @param g Graphics sobre el que dibujar.
|
635 |
* @param r Rect?ngulo a rellenar.
|
636 |
*/
|
637 |
private void fillRect(Graphics2D g, Rectangle2D.Double r) { |
638 |
g.fillRect((int) r.x, (int) r.y, (int) r.width, (int) r.height); |
639 |
} |
640 |
|
641 |
/**
|
642 |
* Escribe sobre el Graphics y en la posici?n indicada el tama?o del
|
643 |
* intervalo.
|
644 |
*
|
645 |
* @param g Graphics sobre el que dibujar.
|
646 |
* @param inter Valor del intervalo.
|
647 |
* @param p Punto donde dibujarlo.
|
648 |
*/
|
649 |
private void drawInterval(Graphics2D g, long inter, Point2D.Double p) { |
650 |
Long l = new Long(inter); |
651 |
g.drawString(l.toString(), (int) p.x, (int) p.y); |
652 |
} |
653 |
|
654 |
/**
|
655 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
|
656 |
*/
|
657 |
public XMLEntity getXMLEntity() {
|
658 |
XMLEntity xml = super.getXMLEntity();
|
659 |
xml.putProperty("type", Layout.RECTANGLESCALEBAR);
|
660 |
xml.putProperty("m_bIntervalSet", m_bIntervalSet);
|
661 |
xml.putProperty("m_dif", m_dif);
|
662 |
xml.putProperty("m_hasleft", m_hasleft);
|
663 |
xml.putProperty("m_nameUnit", m_nameUnit);
|
664 |
xml.putProperty("m_numUnit", m_numUnit);
|
665 |
|
666 |
xml.putProperty("m_height", m_height);
|
667 |
|
668 |
xml.putProperty("m_style", m_style);
|
669 |
xml.putProperty("m_units", m_units);
|
670 |
xml.putProperty("m_interval", m_interval);
|
671 |
xml.putProperty("m_numinterval", m_numinterval);
|
672 |
xml.putProperty("m_numleft", m_numleft);
|
673 |
xml.putProperty("m_mapUnits", m_mapUnits);
|
674 |
xml.putProperty("fontName", m_f.getFontName());
|
675 |
xml.putProperty("fontStyle", m_f.getStyle());
|
676 |
|
677 |
/*
|
678 |
ProjectExtension pe = (ProjectExtension) App.instance.getPc()
|
679 |
.getExtension(ProjectExtension.class);
|
680 |
ArrayList views = pe.getProject().getViews();
|
681 |
boolean hasIndex = false;
|
682 |
for (int i = 0; i < views.size(); i++) {
|
683 |
if (m_fmap == ((ProjectView) views.get(i)).getMapContext()) {
|
684 |
xml.putProperty("indice", i);
|
685 |
hasIndex = true;
|
686 |
}
|
687 |
}
|
688 |
if (!hasIndex) {
|
689 |
xml.putProperty("indice", -1);
|
690 |
}
|
691 |
*/
|
692 |
xml.addChild(fframeview.getXMLEntity()); |
693 |
|
694 |
return xml;
|
695 |
} |
696 |
|
697 |
/**
|
698 |
* Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
|
699 |
*
|
700 |
* @param xml XMLEntity
|
701 |
* @param p DOCUMENT ME!
|
702 |
*
|
703 |
* @return Objeto de esta clase.
|
704 |
*/
|
705 |
public static FFrameScaleBar createFFrameScaleBar(XMLEntity xml, Project p) { |
706 |
FFrameScaleBar fframe = new FFrameScaleBar();
|
707 |
|
708 |
if (xml.getIntProperty("m_Selected") != 0) { |
709 |
fframe.setSelected(true);
|
710 |
} else {
|
711 |
fframe.setSelected(false);
|
712 |
} |
713 |
|
714 |
fframe.m_bIntervalSet = xml.getBooleanProperty("m_bIntervalSet");
|
715 |
fframe.m_dif = xml.getDoubleProperty("m_dif");
|
716 |
fframe.m_hasleft = xml.getIntProperty("m_hasleft");
|
717 |
fframe.m_nameUnit = xml.getStringProperty("m_nameUnit");
|
718 |
fframe.m_numUnit = xml.getDoubleProperty("m_numUnit");
|
719 |
|
720 |
fframe.m_height = xml.getDoubleProperty("m_height");
|
721 |
|
722 |
fframe.m_style = xml.getIntProperty("m_style");
|
723 |
fframe.m_interval = xml.getLongProperty("m_interval");
|
724 |
fframe.m_numinterval = xml.getIntProperty("m_numinterval");
|
725 |
fframe.m_numleft = xml.getIntProperty("m_numleft");
|
726 |
fframe.m_mapUnits = xml.getIntProperty("m_mapUnits");
|
727 |
fframe.m_f = new Font(xml.getStringProperty("fontName"), |
728 |
xml.getIntProperty("fontStyle"), 9); |
729 |
|
730 |
/*
|
731 |
int indice = xml.getIntProperty("indice");
|
732 |
if (indice != -1) {
|
733 |
ProjectView view = (ProjectView) p.getViews().get(indice);
|
734 |
fframe.m_fmap = view.getMapContext();
|
735 |
}
|
736 |
*/
|
737 |
fframe.setFFrameView((FFrameView) FFrameView.createFFrame(xml.getChild( |
738 |
0), p));
|
739 |
|
740 |
return fframe;
|
741 |
} |
742 |
|
743 |
/**
|
744 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#updateNum()
|
745 |
*/
|
746 |
public void updateNum() { |
747 |
num=Layout.numScaleBar++; |
748 |
} |
749 |
public int getNum(){ |
750 |
return num;
|
751 |
} |
752 |
} |