Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / fframes / FFrameScaleBar.java @ 21299

History | View | Annotate | Download (45.3 KB)

1
/*
2
 * Created on 20-feb-2004
3
 *
4
 */
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45
package com.iver.cit.gvsig.project.documents.layout.fframes;
46

    
47
import java.awt.BasicStroke;
48
import java.awt.Color;
49
import java.awt.Font;
50
import java.awt.FontMetrics;
51
import java.awt.Graphics;
52
import java.awt.Graphics2D;
53
import java.awt.geom.AffineTransform;
54
import java.awt.geom.Point2D;
55
import java.awt.geom.Rectangle2D;
56
import java.awt.image.BufferedImage;
57
import java.text.NumberFormat;
58

    
59
import javax.print.attribute.PrintRequestAttributeSet;
60

    
61
import org.gvsig.data.ReadException;
62
import org.gvsig.fmap.geom.Geometry;
63

    
64
import org.gvsig.fmap.mapcontext.MapContext;
65

    
66
import com.iver.andami.PluginServices;
67
import com.iver.cit.gvsig.project.documents.exceptions.SaveException;
68
import com.iver.cit.gvsig.project.documents.layout.Attributes;
69
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities;
70
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameScaleBarDialog;
71
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.IFFrameDialog;
72
import com.iver.cit.gvsig.project.documents.layout.gui.Layout;
73
import com.iver.utiles.StringUtilities;
74
import com.iver.utiles.XMLEntity;
75

    
76

    
77

    
78
/**
79
 * FFrame para introducir una barra de escala en el Layout.
80
 *
81
 * @author Vicente Caballero Navarro
82
 */
83
public class FFrameScaleBar extends FFrame implements IFFrameViewDependence {
84
    private static final int NUMERO = 0;
85
    private static final int BARRA1 = 1;
86
    private static final int BARRA2 = 2;
87
    private static final int BARRA3 = 3;
88
    private static final int BARRA4 = 4;
89
    private double DIFDOWN = 1.5;
90
    private double DIFL = 30;
91
    private double DIFR = 30;
92
    private double DIFUP = 10;
93
    private boolean m_bIntervalSet = false;
94
    private int m_style = NUMERO;
95
    private int m_units = 1; //Metros
96
    private int m_mapUnits = 1; //unidad de medida de la vista(Metros)
97
    private double m_interval = 1;
98
    private int m_numinterval = 3;
99
    private int m_numleft = 2;
100
    private double m_height = 0;
101
    private FFrameView fframeview = null;
102
    private double m_typeUnit = Attributes.CHANGE[1]; //METROS;
103
    private String m_nameUnit = null;
104
    private double m_numUnit = 0;
105
    private double m_dif = 1;
106
    private int m_hasleft = 0;
107
    private Font m_f = new Font("SansSerif", Font.PLAIN, 9);
108
    private Color barcolor = Color.black;
109
    private Color textcolor = Color.black;
110
    private boolean showNameUnits = true;
111
    private boolean showDescription = false;
112
    private boolean aboveName = false;
113
    private boolean aboveIntervals = true;
114
    private boolean aboveDescription = false;
115
    private int dependenceIndex = -1;
116
    private int numDec = 0;
117
    public static NumberFormat numberFormat = NumberFormat.getInstance();
118

    
119
    /**
120
     * Creates a new FFrameScaleBar object.
121
     */
122
    public FFrameScaleBar() {
123
    }
124
    public void refreshDependence(IFFrame fant, IFFrame fnew) {
125
            if ((fframeview != null) &&
126
                fframeview.equals(fant)) {
127
            fframeview=(FFrameView)fnew;
128
            if (fframeview==null)
129
                    return;
130
            setMapUnits(fframeview.getMapUnits());
131
            setHeight(fnew.getBoundBox().height);
132
            }
133
    }
134
    /**
135
     * Inserta el FFrameView sobre el que obtener la escala gr?fica.
136
     *
137
     * @param f FFrameView sobre  el que obtener la escala.
138
     */
139
    public void setFFrameDependence(IFFrame f) {
140
        fframeview = (FFrameView) f;
141
        if (fframeview==null)
142
                return;
143
        setMapUnits(fframeview.getMapUnits());
144
        setHeight(f.getBoundBox().height);
145
    }
146

    
147
    /**
148
     * Devuelve el FFrameView que se representa con la escala.
149
     *
150
     * @return FFrameView a representar.
151
     */
152
    public IFFrame[] getFFrameDependence() {
153
        return new IFFrame[]{fframeview};
154
    }
155

    
156
    /**
157
     * Devuelve el FMap de la vista que se representa en la escala.
158
     *
159
     * @return FMap.
160
     */
161
    public MapContext getFMap() {
162
        return fframeview.getMapContext();
163
    }
164

    
165
    /**
166
     * Rellenar el estilo de barra de escala que se elige.
167
     *
168
     * @param s entero que representa el tipo de barra seleccionada.
169
     */
170
    public void setStyle(int s) {
171
        m_style = s;
172
    }
173

    
174
    /**
175
     * Devuelve el tipo de escala a dibujar.
176
     *
177
     * @return entero.
178
     */
179
    public int getStyle() {
180
        return m_style;
181
    }
182

    
183
    /**
184
     * Rellenar el tama?o de un intervalo.
185
     *
186
     * @param s tama?o de un intervalo.
187
     */
188
    public void setInterval(double s) {
189
        m_interval = s;
190

    
191
        if (m_numleft != 0) {
192
            m_hasleft = 1;
193
        }
194

    
195
        Rectangle2D.Double rect = getBoundBox();
196
        double difL = (rect.width / DIFL);
197
        double difR = (rect.width / DIFR);
198
        double n = (rect.width - difL - difR);
199
        m_numUnit = (m_interval * m_typeUnit) / getScaleView();
200
        m_numinterval = (int) (n / m_numUnit) - m_hasleft;
201
        m_dif = 1;
202
    }
203

    
204
    /**
205
     * Devuelve el valor del intervalo.
206
     *
207
     * @return long.
208
     */
209
    public String obtainInterval() {
210
        if (fframeview != null) {
211
            Rectangle2D.Double rect = getBoundBox();
212

    
213
            if (m_numleft != 0) {
214
                m_hasleft = 1;
215
            }
216

    
217
            double difL = (rect.width / DIFL);
218
            double difR = (rect.width / DIFR);
219
            double n = (rect.width - difL - difR);
220
            m_numUnit = n / (m_numinterval + m_hasleft);
221

    
222
            double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
223
            m_dif = getExact(scaleXunit);
224
            m_numUnit = m_numUnit * m_dif;
225
            m_interval = scaleXunit;
226

    
227
            ///m_interval = (scaleXunit * m_dif);
228
            return format(m_interval);
229
        }
230

    
231
        return "0";
232
    }
233

    
234
    /**
235
     * Rellenar el n?mero de intervalos.
236
     *
237
     * @param s n?mero de intervalos.
238
     */
239
    public void setNumInterval(int s) {
240
        m_numinterval = s;
241

    
242
        if (m_numleft != 0) {
243
            m_hasleft = 1;
244
        }
245

    
246
        Rectangle2D.Double rect = getBoundBox();
247
        double difL = (rect.width / DIFL);
248
        double difR = (rect.width / DIFR);
249
        double n = (rect.width - difL - difR);
250
        m_numUnit = n / (m_numinterval + m_hasleft);
251

    
252
        double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
253
        m_dif = getExact(scaleXunit);
254
        m_numUnit = m_numUnit * m_dif;
255
        m_interval = (scaleXunit * m_dif);
256
    }
257

    
258
    /**
259
     * Devuelve el n?mero de intervalos por encima del cero.
260
     *
261
     * @return entero.
262
     */
263
    public int getNumInterval() {
264
        return m_numinterval;
265
    }
266

    
267
    /**
268
     * Rellenar el n?mero de intervalos a la izquierda del cero.
269
     *
270
     * @param s n?mero de intervalos a la izquierda.
271
     */
272
    public void setNumLeft(int s) {
273
        m_numleft = s;
274
        if (m_numleft != 0) {
275
            m_hasleft = 1;
276
        }else{
277
                m_hasleft=0;
278
        }
279
    }
280

    
281
    /**
282
     * Devuelve el n?mero de intervalos  en los que se quiere particionar el
283
     * intervalo  que se queda por debajo del cero.
284
     *
285
     * @return entero.
286
     */
287
    public int getNumLeft() {
288
        return m_numleft;
289
    }
290

    
291
    /**
292
     * Seleccionar ,a true, si se quiere o, a false, si no mantener los
293
     * intervalos.
294
     *
295
     * @param b boolean a true si se quiere mantener los intervalos.
296
     */
297
    public void setIntervalSet(boolean b) {
298
        m_bIntervalSet = b;
299
    }
300

    
301
    /**
302
     * Seleccionar la unidad de medida a representar en la barra de escala.
303
     *
304
     * @param s entero que representa la unidad de medida que se selecciona.
305
     */
306
    public void setUnits(int s) {
307
        m_units = s;
308
        m_typeUnit = Attributes.CHANGE[s];
309
        m_nameUnit = PluginServices.getText(this,MapContext.getDistanceNames()[s]);
310
    }
311

    
312
    /**
313
     * Devuelve un entero que representa el tipo de unidades que representamos.
314
     *
315
     * @return entero.
316
     */
317
    public int getUnits() {
318
        return m_units;
319
    }
320

    
321
    /**
322
     * Devuelve el long que representa el intervalo.
323
     *
324
     * @return Intervalo.
325
     */
326
    public String getInterval() {
327
        return format(m_interval);
328
    }
329

    
330
    /**
331
     * Rellenar el rect?ngulo de la vista sobre la que se obtiene la escala.
332
     *
333
     * @param d Rect?ngulo.
334
     */
335
    public void setHeight(double d) {
336
        m_height = d;
337
    }
338

    
339
    /**
340
     * Rellena la unidad de medida en la que est? la vista.
341
     *
342
     * @param i entero que representa la unidad de medida de la vista.
343
     */
344
    public void setMapUnits(int i) {
345
        m_mapUnits = i;
346
    }
347

    
348
    /**
349
     * Devuelve la escala de la vista seleccionada.
350
     *
351
     * @return la escala de la vista.
352
     */
353
    private long getScaleView() {
354
        if (fframeview == null) {
355
            return 1;
356
        }
357

    
358
        return fframeview.getScale();
359
    }
360

    
361
    /**
362
     * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
363
     * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
364
     * de dibujar.
365
     *
366
     * @param g Graphics
367
     * @param at Transformada afin.
368
     * @param rv rect?ngulo sobre el que hacer un clip.
369
     * @param imgBase Image para acelerar el dibujado.
370
     */
371
    public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,
372
        BufferedImage imgBase) throws ReadException {
373
        Rectangle2D.Double r = getBoundingBox(at);
374
        g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2),
375
            r.y + (r.height / 2));
376

    
377
        if (intersects(rv, r)) {
378
            if ((fframeview == null) || (fframeview.getMapContext() == null)) {
379
                drawEmpty(g);
380
            } else {
381
                switch (m_style) {
382
                    case (NUMERO):
383

    
384
                        double scalex = r.getWidth() / (8);
385

    
386
                        if (scalex > (r.getHeight() / (8))) {
387
                            scalex = r.getHeight() / (2);
388
                        }
389

    
390
                        g.setColor(textcolor);
391

    
392
                        if (m_f != null) {
393
                            m_f = new Font(m_f.getFontName(), m_f.getStyle(),
394
                                    (int) (scalex));
395
                            g.setFont(m_f);
396
                        }
397

    
398
                        FontMetrics fm = g.getFontMetrics();
399
                        double d = r.getWidth();
400
                        long scl=getScaleView();
401
                        if (scl<1){
402
                            String unknowScale=PluginServices.getText(this,"escala_desconocida");
403
                            if (fm.stringWidth(unknowScale) > (d * 0.8)) {
404
                                double dif = fm.stringWidth(unknowScale) / (d * 0.8);
405
                                m_f = new Font(m_f.getName(), m_f.getStyle(),
406
                                        (int) (m_f.getSize() / dif));
407
                                g.setFont(m_f);
408
                            }
409
                               g.drawString(unknowScale, (int) r.x,
410
                                    (int) (r.y + (r.height / 2)));
411
                               return;
412
                        }
413
                        String scale = " 1:" + scl;
414

    
415
                        if (fm.stringWidth(String.valueOf(m_interval)) > (d * 0.8)) {
416
                            double dif = fm.stringWidth(String.valueOf(
417
                                        m_interval)) / (d * 0.8);
418
                            m_f = new Font(m_f.getName(), m_f.getStyle(),
419
                                    (int) (m_f.getSize() / dif));
420
                            g.setFont(m_f);
421
                        }
422

    
423
                        g.drawString(scale, (int) r.x,
424
                            (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),
440
            r.y + (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 Rect?ngulo en cent?metros.
449
     */
450
    public void setBoundBox(Rectangle2D.Double r) {
451
        if ((m_numUnit < 1) || (fframeview == null) ||
452
                (fframeview.getMapContext() == null)) {
453
            super.setBoundBox(r);
454

    
455
            return;
456
        }
457

    
458
        double difL = (r.width / DIFL);
459
        double difR = (r.width / DIFR);
460

    
461
        if (m_bIntervalSet) {
462
            m_numinterval = (int) (((r.width - (difL + difR)) * m_dif) / m_numUnit) -
463
                m_hasleft;
464
        }
465

    
466
        if (m_numinterval < 1) {
467
            m_numinterval = 1;
468
            r.width = ((m_numinterval + m_hasleft) * m_numUnit) + difL + difR;
469
        }
470

    
471
        getBoundBox().setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
472
    }
473

    
474
    /**
475
     * Dibuja sobre el Graphics la escala gr?fica.
476
     *
477
     * @param type Tipo de barra.
478
     * @param g Graphics sobre el que dibujar.
479
     * @param at Matriz de transformaci?n.
480
     */
481
    private void drawBar(int type, Graphics2D g, AffineTransform at) {
482
        Rectangle2D.Double rect = getBoundBox();
483
        Rectangle2D.Double r = getBoundingBox(at);
484
        double numleft = m_numleft;
485
        initDistances();
486
        //drawOrder(g,r);
487
        double difDown = (rect.height / DIFDOWN);
488
        double difUp = (rect.height / DIFUP);
489
        double difL = (rect.width / DIFL);
490
        double difR = (rect.width / DIFR);
491
        double n = (rect.width - difL - difR);
492

    
493
        //setDescripcion("escala 1:" + String.valueOf(fframeview.getScale()));
494
        g.setStroke(new BasicStroke(0));
495

    
496
        if (!m_bIntervalSet) {
497
            m_numUnit = n / (m_numinterval + m_hasleft);
498

    
499
            double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
500
            m_dif = getExact(scaleXunit);
501
            m_numUnit = m_numUnit * m_dif;
502
            m_interval = (scaleXunit * m_dif);
503
        }
504

    
505
        if (m_bIntervalSet) {
506
            m_numUnit = (m_interval * m_typeUnit) / (m_dif * getScaleView());
507
            m_numinterval = (int) (((rect.width - (difL + difR)) * m_dif) / m_numUnit) -
508
                m_hasleft;
509
        }
510

    
511
        if (m_numinterval < 1) {
512
            m_numinterval = 1;
513
            rect.width = ((m_numinterval + m_hasleft) * m_numUnit) + difL +
514
                difR;
515
        }
516

    
517
        double h = 0;
518

    
519
        if (type == BARRA1) {
520
            h = (rect.height - (difUp + difDown));
521
        } else if ((type == BARRA2) || (type == BARRA3)) {
522
            h = (rect.height - (difUp + difDown)) / 2;
523
        }
524

    
525
        //Dibujar el rect?ngulo que bordea todo.
526
        Rectangle2D.Double rectotal = (FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
527
                    difL), (rect.y + difUp),
528
                    m_numUnit * (m_hasleft + m_numinterval), h), at));
529
        g.setColor(barcolor);
530
        g.fillRect((int) rectotal.x, (int) rectotal.y, (int) (rectotal.width),
531
            (int) rectotal.height);
532
        g.setColor(Color.white);
533
        g.fillRect((int) rectotal.x+2, (int) rectotal.y+2, (int) (rectotal.width-3),
534
                (int) rectotal.height-4);
535
        g.setColor(barcolor);
536

    
537
        if (m_f != null) {
538
            m_f = new Font(m_f.getFontName(), m_f.getStyle(),
539
                    (int) (r.getHeight() / 4));
540
        } else {
541
            m_f = new Font("SansSerif", Font.PLAIN, (int) (r.getHeight() / 4));
542
        }
543

    
544
        g.setFont(m_f);
545
        Double interval=new Double(m_interval);
546
        if (interval.isNaN()) {
547
            String unknowScale=PluginServices.getText(this,"escala_desconocida");
548
            FontMetrics fm = g.getFontMetrics();
549
             double d = r.getWidth();
550
            if (fm.stringWidth(unknowScale) > (d * 0.8)) {
551
                double dif = fm.stringWidth(unknowScale) / (d * 0.8);
552
                m_f = new Font(m_f.getName(), m_f.getStyle(),
553
                        (int) (m_f.getSize() / dif));
554
                g.setFont(m_f);
555
            }
556
               g.drawString(unknowScale, (int) r.x,
557
                    (int) (r.y + (r.height / 2)));
558
               return;
559
        }
560

    
561
        FontMetrics fm = g.getFontMetrics();
562
        String formatInterval = format(m_interval);
563
        double d = (rectotal.getWidth() / m_numinterval) + m_hasleft;
564
        double difpos = ((r.getHeight() / 4) * formatInterval.length()) / 4;
565

    
566
        if (fm.stringWidth(formatInterval) > (d * 0.7)) {
567
            double dif = fm.stringWidth(formatInterval) / (d * 0.7);
568
            difpos = (d * 0.7) / 2;
569
            m_f = new Font(m_f.getName(), m_f.getStyle(),
570
                    (int) (m_f.getSize() / dif));
571
            g.setFont(m_f);
572
        }
573

    
574
        //Derecha del cero
575
        for (int i = 0; i < m_numinterval; i++) {
576
            Rectangle2D.Double recder = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
577
                        (difL) + ((m_numUnit * i) + (m_hasleft * m_numUnit))),
578
                        (rect.y + (difUp)), (m_numUnit),
579
                        (rect.height - (difUp + difDown)) / 2), at);
580
            Rectangle2D.Double recderB = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
581
                        (difL) + ((m_numUnit * i) + (m_hasleft * m_numUnit))),
582
                        (rect.y + difUp) +
583
                        ((rect.height - (difUp + difDown)) / 2), (m_numUnit),
584
                        ((rect.height - (difUp + difDown)) / 2)), at);
585

    
586
            //                        Correcci?n cuando la altura en pixels del rect?ngulo es impar.
587
            rectotal.y = recder.y;
588
            recderB.height = rectotal.height - recder.height + 0.5;
589

    
590
            /**
591
             * if (i == (m_numinterval - 1)) { if (recder.getMaxX() !=
592
             * rectotal.getMaxX()) { recder.width = (recder.width +
593
             * recder.getMaxX()) - rectotal.getMaxX(); } if (recderB.getMaxX()
594
             * != rectotal.getMaxX()) { recderB.width = (recderB.width +
595
             * recderB.getMaxX()) - rectotal.getMaxX(); }} if
596
             * (recderB.getMaxY() != rectotal.getMaxY()) { recderB.height =
597
             * (recderB.height + recderB.getMaxY()) - rectotal.getMaxY(); }
598
             */
599
            if ((m_numleft % 2) == 0) {
600
                if ((i % 2) == 0) {
601
                    if ((type == BARRA1) || (type == BARRA2)) {
602
                        fillRect(g, recder);
603
                    } else if (type == BARRA3) {
604
                        g.drawRect((int) recder.x, (int) recder.y,
605
                            (int) recder.width, (int) recder.height);
606
                    }
607
                } else if (type == BARRA1) {
608
                    fillRect(g, recderB);
609
                }
610
            } else {
611
                if ((i % 2) != 0) {
612
                    if ((type == BARRA1) || (type == BARRA2)) {
613
                        fillRect(g, recder);
614
                    } else if (type == BARRA3) {
615
                        g.drawRect((int) recderB.x, (int) recderB.y,
616
                            (int) recderB.width, (int) recderB.height);
617
                    }
618
                } else if (type == BARRA1) {
619
                    fillRect(g, recderB);
620
                }
621
            }
622

    
623
            String interString = format(m_interval * i);
624
            Point2D.Double p = null;
625

    
626
            if (isAboveIntervals()) {
627
                p = new Point2D.Double(recder.x - difpos,
628
                        r.getMinY() + (r.getHeight() / DIFUP));
629
            } else {
630
                p = new Point2D.Double(recder.x - difpos,
631
                        ((r.getHeight() / 4) + r.getMaxY()) -
632
                        (r.getHeight() / DIFDOWN));
633
            }
634

    
635
            //Para dibujar el 0 centrado en su sitio.
636
            if (i == 0) {
637
                double dif0 = recder.x - (fm.stringWidth(interString) / 2);
638
                p = new Point2D.Double(dif0, p.getY());
639
            }
640

    
641
            drawInterval(g, interString, p);
642
        }
643

    
644
        //?ltimo n?mero a dibujar.
645
        String interString = format(m_interval * m_numinterval);
646

    
647
        Point2D.Double p = null;
648

    
649
        if (isAboveIntervals()) {
650
            p = new Point2D.Double(rectotal.getMaxX() - difpos,
651
                    r.getMinY() + (r.getHeight() / DIFUP));
652
        } else {
653
            p = new Point2D.Double(rectotal.getMaxX() - difpos,
654
                    ((r.getHeight() / 4) + r.getMaxY()) -
655
                    (r.getHeight() / DIFDOWN));
656
        }
657

    
658
        drawInterval(g, interString, p);
659

    
660
        //Izquierda del cero
661
        for (int i = 0; i < m_numleft; i++) {
662
            Rectangle2D.Double reciz = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
663
                        difL + ((m_numUnit / m_numleft) * i)),
664
                        (rect.y + difUp), (m_numUnit / numleft),
665
                        (rect.height - (difUp + difDown)) / 2), at);
666
            Rectangle2D.Double recizB = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
667
                        difL + ((m_numUnit / m_numleft) * i)),
668
                        (rect.y + difUp) +
669
                        ((rect.height - (difUp + difDown)) / 2),
670
                        (m_numUnit / numleft),
671
                        ((rect.height - (difUp + difDown)) / 2)), at);
672

    
673
            //Correcci?n cuando la altura en pixels del rectangulo es impar.
674
            reciz.y = rectotal.y;
675
            recizB.height = rectotal.height - reciz.height + 0.5;
676

    
677
            if ((i % 2) == 0) {
678
                if ((type == BARRA1) || (type == BARRA2)) {
679
                    fillRect(g, reciz);
680
                } else if (type == BARRA3) {
681
                    g.drawRect((int) reciz.x, (int) reciz.y, (int) reciz.width,
682
                        (int) reciz.height);
683
                }
684
            } else if (type == BARRA1) {
685
                fillRect(g, recizB);
686
            }
687
        }
688

    
689
        if (m_numleft > 0) {
690
            interString = format(m_interval);
691

    
692
            if (isAboveIntervals()) {
693
                p = new Point2D.Double(rectotal.x - difpos,
694
                        r.getMinY() + (r.getHeight() / DIFUP));
695
            } else {
696
                p = new Point2D.Double(rectotal.x - difpos,
697
                        ((r.getHeight() / 4) + r.getMaxY()) -
698
                        (r.getHeight() / DIFDOWN));
699
            }
700

    
701
            drawInterval(g, interString, p);
702
        }
703

    
704
        //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.
705
        if (m_numleft == 0) {
706
            Rectangle2D.Double recAux = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
707
                        difL + ((m_numUnit / 1) * 0)), (rect.y + difUp),
708
                        (m_numUnit / 1), (rect.height - (difUp + difDown)) / 2),
709
                    at);
710
            rectotal.x = rectotal.x + recAux.width;
711
            rectotal.width = rectotal.width - recAux.width;
712
        }
713

    
714
        //Se dibuja el rect?ngulo que bordea toda la escala gr?fica.
715
        g.drawRect((int) rectotal.x, (int) rectotal.y, (int) (rectotal.width),
716
            (int) rectotal.height);
717

    
718
        drawNameUnitsAndDescriptions(g, r);
719
        //drawDescription(g, r);
720
    }
721

    
722
    /**
723
     * Inicializa las distancias de la barra de escala.
724
     */
725
    private void initDistances() {
726
        int numUp = 0;
727
        int numDown = 0;
728

    
729
        DIFDOWN = 30;
730
        DIFL = 40;
731
        DIFR = 40;
732
        DIFUP = 30;
733

    
734
        if (isAboveName()) {
735
            numUp++;
736
        } else {
737
            numDown++;
738
        }
739

    
740
        if (isAboveIntervals()) {
741
            numUp++;
742
        } else {
743
            numDown++;
744
        }
745

    
746
        if (isAboveDescription()) {
747
            numUp++;
748
        } else {
749
            numDown++;
750
        }
751

    
752
        if (numDown == 1) {
753
            DIFDOWN = 3;
754
        } else if (numDown == 2) {
755
            DIFDOWN = 2;
756
        } else if (numDown == 3) {
757
            DIFDOWN = 1.2;
758
        }
759

    
760
        if (numUp == 1) {
761
            DIFUP = 3;
762
        } else if (numUp == 2) {
763
            DIFUP = 2;
764
        } else if (numUp == 3) {
765
            DIFUP = 1.2;
766
        }
767
    }
768

    
769
    /**
770
     * Dibuja sobre el Graphics el nombre de la unidad de medida de la escala y la descripci?n,
771
     * siendo por defecto la escala 1:.
772
     *
773
     * @param g Graphics sobre el que se dibuja.
774
     * @param rec Rect?ngulo que ocupa la escala gr?fica.
775
     */
776
    private void drawNameUnitsAndDescriptions(Graphics g, Rectangle2D.Double rec) {
777
        FontMetrics fm = g.getFontMetrics();
778
        Point2D.Double pD = null;
779
        Point2D.Double pU = null;
780
        g.setColor(textcolor);
781
               switch (getFormat()) {
782
               case DUIB:
783
                   pD = new Point2D.Double(rec.getCenterX() -
784
                        (fm.stringWidth(getDescription()) / 2),
785
                        (rec.getMinY() + (rec.getHeight() / 9) +
786
                        (fm.getHeight() / 2)));
787
                   pU = new Point2D.Double(rec.getCenterX() -
788
                           (fm.stringWidth(m_nameUnit) / 2),
789
                           (rec.getMinY() + (rec.getHeight() / 3) +
790
                           (fm.getHeight() / 2)));
791

    
792
                   break;
793
               case DUBI:
794
                   pD = new Point2D.Double(rec.getCenterX() -
795
                        (fm.stringWidth(getDescription()) / 2),
796
                        (rec.getMinY() + (rec.getHeight() / 9) +
797
                        (fm.getHeight() / 2)));
798
                   pU = new Point2D.Double(rec.getCenterX() -
799
                           (fm.stringWidth(m_nameUnit) / 2),
800
                           (rec.getMinY() + (rec.getHeight() / 3) +
801
                           (fm.getHeight() / 2)));
802
                   break;
803
               case DBIU:
804
                   pD = new Point2D.Double(rec.getCenterX() -
805
                        (fm.stringWidth(getDescription()) / 2),
806
                        (rec.getMinY() + (rec.getHeight() / 9) +
807
                        (fm.getHeight() / 2)));
808
                   pU = new Point2D.Double(rec.getCenterX() -
809
                            (fm.stringWidth(m_nameUnit) / 2),
810
                            (rec.getMaxY() - (rec.getHeight() / 9) +
811
                            (fm.getHeight() / 3)));
812
                   break;
813
               case DIBU:
814
                   pD = new Point2D.Double(rec.getCenterX() -
815
                        (fm.stringWidth(getDescription()) / 2),
816
                        (rec.getMinY() + (rec.getHeight() / 9) +
817
                        (fm.getHeight() / 2)));
818
                   pU = new Point2D.Double(rec.getCenterX() -
819
                            (fm.stringWidth(m_nameUnit) / 2),
820
                            (rec.getMaxY() - (rec.getHeight() / 9) +
821
                            (fm.getHeight() / 3)));
822
                   break;
823
               case UIBD:
824
                   pD = new Point2D.Double(rec.getCenterX() -
825
                            (fm.stringWidth(getDescription()) / 2),
826
                            (rec.getMaxY() - (rec.getHeight() / 9) +
827
                            (fm.getHeight() / 3)));
828
                   pU = new Point2D.Double(rec.getCenterX() -
829
                           (fm.stringWidth(m_nameUnit) / 2),
830
                           (rec.getMinY() + (rec.getHeight() / 9) +
831
                           (fm.getHeight() / 2)));
832
                   break;
833
               case UBID:
834
                   pD = new Point2D.Double(rec.getCenterX() -
835
                        (fm.stringWidth(getDescription()) / 2),
836
                        (rec.getMaxY() - (rec.getHeight() / 9) +
837
                        (fm.getHeight() / 3)));
838
                   pU = new Point2D.Double(rec.getCenterX() -
839
                           (fm.stringWidth(m_nameUnit) / 2),
840
                           (rec.getMinY() + (rec.getHeight() / 9) +
841
                           (fm.getHeight() / 2)));
842
                   break;
843
               case IBUD:
844
                   pD = new Point2D.Double(rec.getCenterX() -
845
                        (fm.stringWidth(getDescription()) / 2),
846
                        (rec.getMaxY() - (rec.getHeight() / 3) +
847
                        (fm.getHeight() / 3)));
848
                   pU = new Point2D.Double(rec.getCenterX() -
849
                            (fm.stringWidth(m_nameUnit) / 2),
850
                            (rec.getMaxY() - (rec.getHeight() / 9) +
851
                            (fm.getHeight() / 3)));
852

    
853
                   break;
854
               case BIUD:
855
                   pD = new Point2D.Double(rec.getCenterX() -
856
                        (fm.stringWidth(getDescription()) / 2),
857
                        (rec.getMaxY() - (rec.getHeight() / 3) +
858
                        (fm.getHeight() / 3)));
859
                   pU = new Point2D.Double(rec.getCenterX() -
860
                            (fm.stringWidth(m_nameUnit) / 2),
861
                            (rec.getMaxY() - (rec.getHeight() / 9) +
862
                            (fm.getHeight() / 3)));
863
                   break;
864
               }
865
               if (isShowNameUnits()) {
866
                   g.drawString(m_nameUnit, (int) pU.x, (int) pU.y);
867
               }
868
            if (isShowDescription()) {
869
                g.drawString(getDescription(), (int) pD.x, (int) pD.y);
870
            }
871
    }
872
    /**
873
     * Rellena la fuente utilizada para dibujar los intervalos y la unidad de
874
     * medida utilizada.
875
     *
876
     * @param f fuente a utilizar.
877
     */
878
    public void setFont(Font f) {
879
        m_f = f;
880
    }
881

    
882
    /**
883
     * Devuelve la fuente con la que se est? dibujando sobre el graphics.
884
     *
885
     * @return fuente utilizada.
886
     */
887
    public Font getFont() {
888
        return new Font(m_f.getFontName(), m_f.getStyle(), 9);
889
    }
890

    
891
    /**
892
     * Devuelve si el intervalo es variable o si por el contrario es fijo.
893
     *
894
     * @return true si el intervalo es fijo.
895
     */
896
    public boolean isbIntervalSet() {
897
        return m_bIntervalSet;
898
    }
899

    
900
    /**
901
     * Especificar si el intervalo se debe mantener o es variable.
902
     *
903
     * @param b si se quiere mantener el intervalo especificado.
904
     */
905
    public void setbIntervalSet(boolean b) {
906
        m_bIntervalSet = b;
907
    }
908

    
909
    /**
910
     * Devuelve el porcentaje por el cual hay que multiplicar  el intervalo
911
     * para conseguir un intervalo redondeado,  de momento con una cifra
912
     * significativas(NUM=1).
913
     *
914
     * @param total intervalo.
915
     *
916
     * @return Porcentaje
917
     */
918
    private double getExact(double total) {
919
            int NUM = 1;
920
            double t = 0;
921
        double dif = 1;
922
        Double d = new Double(total);
923
        Long l = new Long(d.longValue());
924
        int num = l.toString().length();
925
        t = ((long) (total / Math.pow(10, num - NUM)) * Math.pow(10, num - NUM));
926
        dif = t / total;
927

    
928
        if (dif == 0) {
929
            return 1;
930
        }
931

    
932
        return dif;
933
    }
934

    
935
    /**
936
     * Rellena un rect?ngulo.
937
     *
938
     * @param g Graphics sobre el que dibujar.
939
     * @param r Rect?ngulo a rellenar.
940
     */
941
    private void fillRect(Graphics2D g, Rectangle2D.Double r) {
942
        g.fillRect((int) r.x, (int) r.y, (int) r.width, (int) r.height);
943
    }
944

    
945
    /**
946
     * Escribe sobre el Graphics y en la posici?n indicada el tama?o del
947
     * intervalo.
948
     *
949
     * @param g Graphics sobre el que dibujar.
950
     * @param inter Valor del intervalo.
951
     * @param p Punto donde dibujarlo.
952
     */
953
    private void drawInterval(Graphics2D g, String inter, Point2D.Double p) {
954
        //Double l = new Double(inter);
955
        g.setColor(textcolor);
956
        g.drawString(inter, (int) p.x, (int) p.y);
957
        g.setColor(barcolor);
958
    }
959

    
960
    /**
961
     * DOCUMENT ME!
962
     *
963
     * @return DOCUMENT ME!
964
     *
965
     * @throws SaveException
966
     *
967
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getXMLEntity()
968
     */
969
    public XMLEntity getXMLEntity() throws SaveException {
970
        XMLEntity xml = super.getXMLEntity();
971

    
972
        try {
973
//            xml.putProperty("type", Layout.RECTANGLESCALEBAR);
974
            xml.putProperty("m_bIntervalSet", m_bIntervalSet);
975
            xml.putProperty("m_dif", m_dif);
976
            xml.putProperty("m_hasleft", m_hasleft);
977
            xml.putProperty("m_nameUnit", m_nameUnit);
978
            xml.putProperty("m_numUnit", m_numUnit);
979

    
980
            xml.putProperty("m_height", m_height);
981

    
982
            xml.putProperty("m_style", m_style);
983
            xml.putProperty("m_units", m_units);
984
            xml.putProperty("m_interval", m_interval);
985
            xml.putProperty("m_numinterval", m_numinterval);
986
            xml.putProperty("m_numleft", m_numleft);
987
            xml.putProperty("m_mapUnits", m_mapUnits);
988
            xml.putProperty("fontName", m_f.getFontName());
989
            xml.putProperty("fontStyle", m_f.getStyle());
990
            xml.putProperty("numDec", numDec);
991
            xml.putProperty("m_units", m_units);
992

    
993
            if (fframeview != null) {
994
                Layout layout = fframeview.getLayout();
995
                IFFrame[] fframes = layout.getLayoutContext().getAllFFrames();
996

    
997
                for (int i = 0; i < fframes.length; i++) {
998
                    if (fframeview.getName().equals(fframes[i].getName())) {
999
                        xml.putProperty("index", i);
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 com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
1020
     *      com.iver.cit.gvsig.project.Project)
1021
     */
1022
    public void setXMLEntity03(XMLEntity xml, Layout 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 com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
1062
     *      com.iver.cit.gvsig.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 com.iver.cit.gvsig.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 com.iver.cit.gvsig.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, PrintRequestAttributeSet properties)
1277
        throws ReadException {
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
}