Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / fframes / FFrameScaleBar.java @ 28368

History | View | Annotate | Download (46 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
import javax.print.attribute.standard.PrintQuality;
61

    
62
import com.iver.andami.PluginServices;
63
import com.iver.cit.gvsig.fmap.MapContext;
64
import com.iver.cit.gvsig.fmap.core.FShape;
65
import com.iver.cit.gvsig.project.documents.exceptions.SaveException;
66
import com.iver.cit.gvsig.project.documents.layout.Attributes;
67
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities;
68
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameScaleBarDialog;
69
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.IFFrameDialog;
70
import com.iver.cit.gvsig.project.documents.layout.gui.Layout;
71
import com.iver.utiles.StringUtilities;
72
import com.iver.utiles.XMLEntity;
73

    
74

    
75

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
230
        return "0";
231
    }
232

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
357
        return fframeview.getScale();
358
    }
359

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

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

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

    
385
                        if (scalex > (r.getHeight() / (8))) {
386
                            scalex = r.getHeight() / (2);
387
                        }
388
                        if (properties!=null){
389
                            PrintQuality pq = (PrintQuality) properties.get(PrintQuality.class);
390
                                            if (pq.equals(PrintQuality.NORMAL)){
391
                                                    scalex *= (double) 300/72;
392
                                            }else if (pq.equals(PrintQuality.HIGH)){
393
                                                    scalex *= (double) 600/72;
394
                                            }else if (pq.equals(PrintQuality.DRAFT)){
395
                                            //        unitFactor *= 72; (which is the same than doing nothing)
396
                                            }
397
                            }
398
                        g.setColor(textcolor);
399

    
400
                        if (m_f != null) {
401
                            m_f = new Font(m_f.getFontName(), m_f.getStyle(),
402
                                    (int) (scalex));
403
                            g.setFont(m_f);
404
                        }
405

    
406
                        FontMetrics fm = g.getFontMetrics();
407
                        double d = r.getWidth();
408
                        long scl=getScaleView();
409
                        if (scl<1){
410
                            String unknowScale=PluginServices.getText(this,"escala_desconocida");
411
                            if (fm.stringWidth(unknowScale) > (d * 0.8)) {
412
                                double dif = fm.stringWidth(unknowScale) / (d * 0.8);
413
                                m_f = new Font(m_f.getName(), m_f.getStyle(),
414
                                        (int) (m_f.getSize() / dif));
415
                                g.setFont(m_f);
416
                            }
417
                               g.drawString(unknowScale, (int) r.x,
418
                                    (int) (r.y + (r.height / 2)));
419
                               return;
420
                        }
421
                        String scale = " 1:" + scl;
422

    
423
                        if (fm.stringWidth(String.valueOf(m_interval)) > (d * 0.8)) {
424
                            double dif = fm.stringWidth(String.valueOf(
425
                                        m_interval)) / (d * 0.8);
426
                            m_f = new Font(m_f.getName(), m_f.getStyle(),
427
                                    (int) (m_f.getSize() / dif));
428
                            g.setFont(m_f);
429
                        }
430

    
431
                        g.drawString(scale, (int) r.x,
432
                            (int) (r.y + (r.height / 2)));
433

    
434
                        break;
435

    
436
                    case (BARRA1):
437
                    case (BARRA2):
438
                    case (BARRA3):
439
                    case (BARRA4):
440
                        drawBar(m_style, g, at);
441

    
442
                        break;
443
                }
444
            }
445
        }
446

    
447
        g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2),
448
            r.y + (r.height / 2));
449
    }
450

    
451
    /**
452
     * Rellena con el rect?ngulo que se pasa como par?metro el boundBox(en
453
     * cent?metros) del fframe del cual con una transformaci?n se podr?
454
     * calcular el BoundingBox (en pixels).
455
     *
456
     * @param r Rect?ngulo en cent?metros.
457
     */
458
    public void setBoundBox(Rectangle2D.Double r) {
459
        if ((m_numUnit < 1) || (fframeview == null) ||
460
                (fframeview.getMapContext() == null)) {
461
            super.setBoundBox(r);
462

    
463
            return;
464
        }
465

    
466
        double difL = (r.width / DIFL);
467
        double difR = (r.width / DIFR);
468

    
469
        if (m_bIntervalSet) {
470
            m_numinterval = (int) (((r.width - (difL + difR)) * m_dif) / m_numUnit) -
471
                m_hasleft;
472
        }
473

    
474
        if (m_numinterval < 1) {
475
            m_numinterval = 1;
476
            r.width = ((m_numinterval + m_hasleft) * m_numUnit) + difL + difR;
477
        }
478

    
479
        getBoundBox().setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
480
    }
481

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

    
501
        //setDescripcion("escala 1:" + String.valueOf(fframeview.getScale()));
502
        g.setStroke(new BasicStroke(0));
503

    
504
        if (!m_bIntervalSet) {
505
            m_numUnit = n / (m_numinterval + m_hasleft);
506

    
507
            double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
508
            m_dif = getExact(scaleXunit);
509
            m_numUnit = m_numUnit * m_dif;
510
            m_interval = (scaleXunit * m_dif);
511
        }
512

    
513
        if (m_bIntervalSet) {
514
            m_numUnit = (m_interval * m_typeUnit) / (m_dif * getScaleView());
515
            m_numinterval = (int) (((rect.width - (difL + difR)) * m_dif) / m_numUnit) -
516
                m_hasleft;
517
        }
518

    
519
        if (m_numinterval < 1) {
520
            m_numinterval = 1;
521
            rect.width = ((m_numinterval + m_hasleft) * m_numUnit) + difL +
522
                difR;
523
        }
524

    
525
        double h = 0;
526

    
527
        if (type == BARRA1) {
528
            h = (rect.height - (difUp + difDown));
529
        } else if ((type == BARRA2) || (type == BARRA3)) {
530
            h = (rect.height - (difUp + difDown)) / 2;
531
        }
532

    
533
        //Dibujar el rect?ngulo que bordea todo.
534
        Rectangle2D.Double rectotal = (FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
535
                    difL), (rect.y + difUp),
536
                    m_numUnit * (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, (int) (rectotal.width-3),
542
                (int) rectotal.height-4);
543
        g.setColor(barcolor);
544

    
545
        if (m_f != null) {
546
            m_f = new Font(m_f.getFontName(), m_f.getStyle(),
547
                    (int) (r.getHeight() / 4));
548
        } else {
549
            m_f = new Font("SansSerif", Font.PLAIN, (int) (r.getHeight() / 4));
550
        }
551

    
552
        g.setFont(m_f);
553
        Double interval=new Double(m_interval);
554
        if (interval.isNaN()) {
555
            String unknowScale=PluginServices.getText(this,"escala_desconocida");
556
            FontMetrics fm = g.getFontMetrics();
557
             double d = r.getWidth();
558
            if (fm.stringWidth(unknowScale) > (d * 0.8)) {
559
                double dif = fm.stringWidth(unknowScale) / (d * 0.8);
560
                m_f = new Font(m_f.getName(), m_f.getStyle(),
561
                        (int) (m_f.getSize() / dif));
562
                g.setFont(m_f);
563
            }
564
               g.drawString(unknowScale, (int) r.x,
565
                    (int) (r.y + (r.height / 2)));
566
               return;
567
        }
568

    
569
        FontMetrics fm = g.getFontMetrics();
570
        String formatInterval = format(m_interval);
571
        double d = (rectotal.getWidth() / m_numinterval) + m_hasleft;
572
        double difpos = ((r.getHeight() / 4) * formatInterval.length()) / 4;
573

    
574
        if (fm.stringWidth(formatInterval) > (d * 0.7)) {
575
            double dif = fm.stringWidth(formatInterval) / (d * 0.7);
576
            difpos = (d * 0.7) / 2;
577
            m_f = new Font(m_f.getName(), m_f.getStyle(),
578
                    (int) (m_f.getSize() / dif));
579
            g.setFont(m_f);
580
        }
581

    
582
        //Derecha del cero
583
        for (int i = 0; i < m_numinterval; i++) {
584
            Rectangle2D.Double recder = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
585
                        (difL) + ((m_numUnit * i) + (m_hasleft * m_numUnit))),
586
                        (rect.y + (difUp)), (m_numUnit),
587
                        (rect.height - (difUp + difDown)) / 2), at);
588
            Rectangle2D.Double recderB = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
589
                        (difL) + ((m_numUnit * i) + (m_hasleft * m_numUnit))),
590
                        (rect.y + difUp) +
591
                        ((rect.height - (difUp + difDown)) / 2), (m_numUnit),
592
                        ((rect.height - (difUp + difDown)) / 2)), at);
593

    
594
            //                        Correcci?n cuando la altura en pixels del rect?ngulo es impar.
595
            rectotal.y = recder.y;
596
            recderB.height = rectotal.height - recder.height + 0.5;
597

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

    
631
            String interString = format(m_interval * i);
632
            Point2D.Double p = null;
633

    
634
            if (isAboveIntervals()) {
635
                p = new Point2D.Double(recder.x - difpos,
636
                        r.getMinY() + (r.getHeight() / DIFUP));
637
            } else {
638
                p = new Point2D.Double(recder.x - difpos,
639
                        ((r.getHeight() / 4) + r.getMaxY()) -
640
                        (r.getHeight() / DIFDOWN));
641
            }
642

    
643
            //Para dibujar el 0 centrado en su sitio.
644
            if (i == 0) {
645
                double dif0 = recder.x - (fm.stringWidth(interString) / 2);
646
                p = new Point2D.Double(dif0, p.getY());
647
            }
648

    
649
            drawInterval(g, interString, p);
650
        }
651

    
652
        //?ltimo n?mero a dibujar.
653
        String interString = format(m_interval * m_numinterval);
654

    
655
        Point2D.Double p = null;
656

    
657
        if (isAboveIntervals()) {
658
            p = new Point2D.Double(rectotal.getMaxX() - difpos,
659
                    r.getMinY() + (r.getHeight() / DIFUP));
660
        } else {
661
            p = new Point2D.Double(rectotal.getMaxX() - difpos,
662
                    ((r.getHeight() / 4) + r.getMaxY()) -
663
                    (r.getHeight() / DIFDOWN));
664
        }
665

    
666
        drawInterval(g, interString, p);
667

    
668
        //Izquierda del cero
669
        for (int i = 0; i < m_numleft; i++) {
670
            Rectangle2D.Double reciz = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
671
                        difL + ((m_numUnit / m_numleft) * i)),
672
                        (rect.y + difUp), (m_numUnit / numleft),
673
                        (rect.height - (difUp + difDown)) / 2), at);
674
            Rectangle2D.Double recizB = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
675
                        difL + ((m_numUnit / m_numleft) * i)),
676
                        (rect.y + difUp) +
677
                        ((rect.height - (difUp + difDown)) / 2),
678
                        (m_numUnit / numleft),
679
                        ((rect.height - (difUp + difDown)) / 2)), at);
680

    
681
            //Correcci?n cuando la altura en pixels del rectangulo es impar.
682
            reciz.y = rectotal.y;
683
            recizB.height = rectotal.height - reciz.height + 0.5;
684

    
685
            if ((i % 2) == 0) {
686
                if ((type == BARRA1) || (type == BARRA2)) {
687
                    fillRect(g, reciz);
688
                } else if (type == BARRA3) {
689
                    g.drawRect((int) reciz.x, (int) reciz.y, (int) reciz.width,
690
                        (int) reciz.height);
691
                }
692
            } else if (type == BARRA1) {
693
                fillRect(g, recizB);
694
            }
695
        }
696

    
697
        if (m_numleft > 0) {
698
            interString = format(m_interval);
699

    
700
            if (isAboveIntervals()) {
701
                p = new Point2D.Double(rectotal.x - difpos,
702
                        r.getMinY() + (r.getHeight() / DIFUP));
703
            } else {
704
                p = new Point2D.Double(rectotal.x - difpos,
705
                        ((r.getHeight() / 4) + r.getMaxY()) -
706
                        (r.getHeight() / DIFDOWN));
707
            }
708

    
709
            drawInterval(g, interString, p);
710
        }
711

    
712
        //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.
713
        if (m_numleft == 0) {
714
            Rectangle2D.Double recAux = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
715
                        difL + ((m_numUnit / 1) * 0)), (rect.y + difUp),
716
                        (m_numUnit / 1), (rect.height - (difUp + difDown)) / 2),
717
                    at);
718
            rectotal.x = rectotal.x + recAux.width;
719
            rectotal.width = rectotal.width - recAux.width;
720
        }
721

    
722
        //Se dibuja el rect?ngulo que bordea toda la escala gr?fica.
723
        g.drawRect((int) rectotal.x, (int) rectotal.y, (int) (rectotal.width),
724
            (int) rectotal.height);
725

    
726
        drawNameUnitsAndDescriptions(g, r);
727
        //drawDescription(g, r);
728
    }
729

    
730
    /**
731
     * Inicializa las distancias de la barra de escala.
732
     */
733
    private void initDistances() {
734
        int numUp = 0;
735
        int numDown = 0;
736

    
737
        DIFDOWN = 30;
738
        DIFL = 40;
739
        DIFR = 40;
740
        DIFUP = 30;
741

    
742
        if (isAboveName()) {
743
            numUp++;
744
        } else {
745
            numDown++;
746
        }
747

    
748
        if (isAboveIntervals()) {
749
            numUp++;
750
        } else {
751
            numDown++;
752
        }
753

    
754
        if (isAboveDescription()) {
755
            numUp++;
756
        } else {
757
            numDown++;
758
        }
759

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

    
768
        if (numUp == 1) {
769
            DIFUP = 3;
770
        } else if (numUp == 2) {
771
            DIFUP = 2;
772
        } else if (numUp == 3) {
773
            DIFUP = 1.2;
774
        }
775
    }
776

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

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

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

    
890
    /**
891
     * Devuelve la fuente con la que se est? dibujando sobre el graphics.
892
     *
893
     * @return fuente utilizada.
894
     */
895
    public Font getFont() {
896
        return new Font(m_f.getFontName(), m_f.getStyle(), 9);
897
    }
898

    
899
    /**
900
     * Devuelve si el intervalo es variable o si por el contrario es fijo.
901
     *
902
     * @return true si el intervalo es fijo.
903
     */
904
    public boolean isbIntervalSet() {
905
        return m_bIntervalSet;
906
    }
907

    
908
    /**
909
     * Especificar si el intervalo se debe mantener o es variable.
910
     *
911
     * @param b si se quiere mantener el intervalo especificado.
912
     */
913
    public void setbIntervalSet(boolean b) {
914
        m_bIntervalSet = b;
915
    }
916

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

    
936
        if (dif == 0) {
937
            return 1;
938
        }
939

    
940
        return dif;
941
    }
942

    
943
    /**
944
     * Rellena un rect?ngulo.
945
     *
946
     * @param g Graphics sobre el que dibujar.
947
     * @param r Rect?ngulo a rellenar.
948
     */
949
    private void fillRect(Graphics2D g, Rectangle2D.Double r) {
950
        g.fillRect((int) r.x, (int) r.y, (int) r.width, (int) r.height);
951
    }
952

    
953
    /**
954
     * Escribe sobre el Graphics y en la posici?n indicada el tama?o del
955
     * intervalo.
956
     *
957
     * @param g Graphics sobre el que dibujar.
958
     * @param inter Valor del intervalo.
959
     * @param p Punto donde dibujarlo.
960
     */
961
    private void drawInterval(Graphics2D g, String inter, Point2D.Double p) {
962
        //Double l = new Double(inter);
963
        g.setColor(textcolor);
964
        g.drawString(inter, (int) p.x, (int) p.y);
965
        g.setColor(barcolor);
966
    }
967

    
968
    /**
969
     * DOCUMENT ME!
970
     *
971
     * @return DOCUMENT ME!
972
     *
973
     * @throws SaveException
974
     *
975
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getXMLEntity()
976
     */
977
    public XMLEntity getXMLEntity() throws SaveException {
978
        XMLEntity xml = super.getXMLEntity();
979

    
980
        try {
981
//            xml.putProperty("type", Layout.RECTANGLESCALEBAR);
982
            xml.putProperty("m_bIntervalSet", m_bIntervalSet);
983
            xml.putProperty("m_dif", m_dif);
984
            xml.putProperty("m_hasleft", m_hasleft);
985
            xml.putProperty("m_nameUnit", m_nameUnit);
986
            xml.putProperty("m_numUnit", m_numUnit);
987

    
988
            xml.putProperty("m_height", m_height);
989

    
990
            xml.putProperty("m_style", m_style);
991
            xml.putProperty("m_units", m_units);
992
            xml.putProperty("m_interval", m_interval);
993
            xml.putProperty("m_numinterval", m_numinterval);
994
            xml.putProperty("m_numleft", m_numleft);
995
            xml.putProperty("m_mapUnits", m_mapUnits);
996
            xml.putProperty("fontName", m_f.getFontName());
997
            xml.putProperty("fontStyle", m_f.getStyle());
998
            xml.putProperty("numDec", numDec);
999
            xml.putProperty("m_units", m_units);
1000

    
1001
            if (fframeview != null) {
1002
                Layout layout = fframeview.getLayout();
1003
                IFFrame[] fframes = layout.getLayoutContext().getAllFFrames();
1004

    
1005
                for (int i = 0; i < fframes.length; i++) {
1006
                         if (fframeview.equals(fframes[i])) {
1007
                        xml.putProperty("index", i);
1008
                        break;
1009
                    }
1010
                }
1011
            }
1012

    
1013
            xml.putProperty("barcolor", StringUtilities.color2String(barcolor));
1014
            xml.putProperty("textcolor", StringUtilities.color2String(textcolor));
1015
            xml.putProperty("showNameUnits", showNameUnits);
1016
            xml.putProperty("showDescription", showDescription);
1017
            xml.putProperty("aboveName", aboveName);
1018
            xml.putProperty("aboveIntervals", aboveIntervals);
1019
            xml.putProperty("aboveDescription", aboveDescription);
1020
        } catch (Exception e) {
1021
            throw new SaveException(e, this.getClass().getName());
1022
        }
1023

    
1024
        return xml;
1025
    }
1026

    
1027
    /**
1028
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
1029
     *      com.iver.cit.gvsig.project.Project)
1030
     */
1031
    public void setXMLEntity03(XMLEntity xml, Layout l) {
1032
        if (xml.getIntProperty("m_Selected") != 0) {
1033
            this.setSelected(true);
1034
        } else {
1035
            this.setSelected(false);
1036
        }
1037

    
1038
        this.m_bIntervalSet = xml.getBooleanProperty("m_bIntervalSet");
1039
        this.m_dif = xml.getDoubleProperty("m_dif");
1040
        this.m_hasleft = xml.getIntProperty("m_hasleft");
1041
        this.m_nameUnit = xml.getStringProperty("m_nameUnit");
1042
        this.m_numUnit = xml.getDoubleProperty("m_numUnit");
1043

    
1044
        this.m_height = xml.getDoubleProperty("m_height");
1045

    
1046
        this.m_style = xml.getIntProperty("m_style");
1047
        this.m_interval = xml.getLongProperty("m_interval");
1048
        this.m_numinterval = xml.getIntProperty("m_numinterval");
1049
        this.m_numleft = xml.getIntProperty("m_numleft");
1050
        this.m_mapUnits = xml.getIntProperty("m_mapUnits");
1051
        this.m_f = new Font(xml.getStringProperty("fontName"),
1052
                xml.getIntProperty("fontStyle"), 9);
1053

    
1054
        fframeview = (FFrameView) l.getLayoutContext().getFFrame(xml.getIntProperty("index"));
1055

    
1056
        if (xml.contains("description")) { //Comprobar que es de la versi?n que cambia el di?logo.
1057
            this.barcolor = StringUtilities.string2Color(xml.getStringProperty(
1058
                        "barcolor"));
1059
            this.textcolor = StringUtilities.string2Color(xml.getStringProperty(
1060
                        "textcolor"));
1061
            this.showNameUnits = xml.getBooleanProperty("showNameUnits");
1062
            this.showDescription = xml.getBooleanProperty("showDescription");
1063
            this.aboveName = xml.getBooleanProperty("aboveName");
1064
            this.aboveIntervals = xml.getBooleanProperty("aboveIntervals");
1065
            this.aboveDescription = xml.getBooleanProperty("aboveDescription");
1066
        }
1067
    }
1068

    
1069
    /**
1070
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
1071
     *      com.iver.cit.gvsig.project.Project)
1072
     */
1073
    public void setXMLEntity(XMLEntity xml) {
1074
        if (xml.getIntProperty("m_Selected") != 0) {
1075
            this.setSelected(true);
1076
        } else {
1077
            this.setSelected(false);
1078
        }
1079

    
1080
        this.m_bIntervalSet = xml.getBooleanProperty("m_bIntervalSet");
1081
        this.m_dif = xml.getDoubleProperty("m_dif");
1082
        this.m_hasleft = xml.getIntProperty("m_hasleft");
1083
        this.m_nameUnit = xml.getStringProperty("m_nameUnit");
1084
        this.m_numUnit = xml.getDoubleProperty("m_numUnit");
1085

    
1086
        this.m_height = xml.getDoubleProperty("m_height");
1087

    
1088
        this.m_style = xml.getIntProperty("m_style");
1089
        this.m_interval = xml.getDoubleProperty("m_interval");
1090
        this.m_numinterval = xml.getIntProperty("m_numinterval");
1091
        this.m_numleft = xml.getIntProperty("m_numleft");
1092
        this.m_mapUnits = xml.getIntProperty("m_mapUnits");
1093
        this.m_f = new Font(xml.getStringProperty("fontName"),
1094
                xml.getIntProperty("fontStyle"), 9);
1095
        setRotation(xml.getDoubleProperty("m_rotation"));
1096

    
1097
        if (xml.contains("m_units")) { //Comprobaci?n por versi?n 0.5
1098
            setUnits(xml.getIntProperty("m_units"));
1099
        }
1100

    
1101
        if (xml.contains("index")) {
1102
            dependenceIndex = xml.getIntProperty("index");
1103
        }
1104

    
1105

    
1106
        if (xml.contains("showDescription")) { //Comprobar que es de la versi?n que cambia el di?logo.
1107
            this.barcolor = StringUtilities.string2Color(xml.getStringProperty(
1108
            "barcolor"));
1109

    
1110
            this.textcolor = StringUtilities.string2Color(xml.getStringProperty(
1111
                        "textcolor"));
1112
            this.showNameUnits = xml.getBooleanProperty("showNameUnits");
1113
            this.showDescription = xml.getBooleanProperty("showDescription");
1114
            this.aboveName = xml.getBooleanProperty("aboveName");
1115
            this.aboveIntervals = xml.getBooleanProperty("aboveIntervals");
1116
            this.aboveDescription = xml.getBooleanProperty("aboveDescription");
1117
        }
1118

    
1119
        if (xml.contains("numDec")) {
1120
            setNumDec(xml.getIntProperty("numDec"));
1121
        }
1122
    }
1123

    
1124
    /**
1125
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getNameFFrame()
1126
     */
1127
    public String getNameFFrame() {
1128
        return PluginServices.getText(this, "escala")+ num;
1129
    }
1130

    
1131
    /**
1132
     * Inserta el color de la escala gr?fica.
1133
     *
1134
     * @param color Color de la escala gr?fica.
1135
     */
1136
    public void setBarColor(Color color) {
1137
        barcolor = color;
1138
    }
1139

    
1140
    /**
1141
     * Inserta el color del texto.
1142
     *
1143
     * @param color Color del texto.
1144
     */
1145
    public void setTextColor(Color color) {
1146
        textcolor = color;
1147
    }
1148

    
1149
    /**
1150
     * Devuelve el color de la escala gr?fica.
1151
     *
1152
     * @return Color de la escala gr?fica.
1153
     */
1154
    public Color getBarColor() {
1155
        return barcolor;
1156
    }
1157

    
1158
    /**
1159
     * Devuelve el color del texto.
1160
     *
1161
     * @return Color del texto.
1162
     */
1163
    public Color getTextColor() {
1164
        return textcolor;
1165
    }
1166

    
1167
    /**
1168
     * Devuelve true si se debe mostrar el nombre de las unidades de medida de
1169
     * la escala gr?fica.
1170
     *
1171
     * @return True si se muestra las unidades de medida.
1172
     */
1173
    public boolean isShowNameUnits() {
1174
        return showNameUnits;
1175
    }
1176

    
1177
    /**
1178
     * Inserta si se debe de mostrar el nombre de las unidades de medida o no.
1179
     *
1180
     * @param showNameUnits True si se muestra el nombre de las unidades de
1181
     *        medida.
1182
     */
1183
    public void setShowNameUnits(boolean showNameUnits) {
1184
        this.showNameUnits = showNameUnits;
1185
    }
1186

    
1187
    /**
1188
     * Devuelve true si se muestra la descripci?n a la parte de arriba de la
1189
     * escala gr?fica.
1190
     *
1191
     * @return True si se muestra arriba de la escala gr?fica.
1192
     */
1193
    public boolean isAboveDescription() {
1194
        return aboveDescription;
1195
    }
1196

    
1197
    /**
1198
     * Introduce true si se muestra arriba de la escala gr?fica la descripci?n.
1199
     *
1200
     * @param aboveDescription True si se muestra arriba la descripci?n.
1201
     */
1202
    public void setAboveDescription(boolean aboveDescription) {
1203
        this.aboveDescription = aboveDescription;
1204
    }
1205

    
1206
    /**
1207
     * Devuelve true si se muestran a la parte de arriba los valores de los
1208
     * intervalos.
1209
     *
1210
     * @return True si se muestran arriba de la escala gr?fica.
1211
     */
1212
    public boolean isAboveIntervals() {
1213
        return aboveIntervals;
1214
    }
1215

    
1216
    /**
1217
     * Inserta si se muestran los valores de los intervalos a la parte de
1218
     * arriba de la escala o debajo.
1219
     *
1220
     * @param aboveIntervals True si se muestran los valores de los intervalos
1221
     *        a la parte de arriba de la escala gr?fica.
1222
     */
1223
    public void setAboveIntervals(boolean aboveIntervals) {
1224
        this.aboveIntervals = aboveIntervals;
1225
    }
1226

    
1227
    /**
1228
     * Devuelve si se muestra a la parte de arriba de la escala gr?fica el
1229
     * nombre de las unidades de medida o debajo.
1230
     *
1231
     * @return True si se muestra a la parte de arriba de la escala gr?fica.
1232
     */
1233
    public boolean isAboveName() {
1234
        return aboveName;
1235
    }
1236

    
1237
    /**
1238
     * Inserta si el nombre se muestra a la parte de arriba de la escala
1239
     * gr?fica o a la parte de abajo.
1240
     *
1241
     * @param aboveName True si se muestra a la parte de arriba de la escala
1242
     *        gr?fica.
1243
     */
1244
    public void setAboveName(boolean aboveName) {
1245
        this.aboveName = aboveName;
1246
    }
1247

    
1248
    /**
1249
     * Devuelve si se debe mostrar la descripci?n o no.
1250
     *
1251
     * @return True si se muestra la descripci?n.
1252
     */
1253
    public boolean isShowDescription() {
1254
        return showDescription;
1255
    }
1256

    
1257
    /**
1258
     * Inserta si se muestra o no la descripci?n.
1259
     *
1260
     * @param showDescription True si se muestra la descripci?n.
1261
     */
1262
    public void setShowDescription(boolean showDescription) {
1263
        this.showDescription = showDescription;
1264
    }
1265

    
1266
    /**
1267
     * Devuelve la descripci?n de la escala.
1268
     *
1269
     * @return Descripci?n de la escala.
1270
     */
1271
    public String getDescription() {
1272
        if (fframeview!=null){
1273
                if (fframeview.getScale()==0){
1274
                        return PluginServices.getText(this,"escala_desconocida");
1275
                }
1276
            return "1:" + String.valueOf(fframeview.getScale());
1277
        }
1278
            return "1:";
1279
    }
1280

    
1281
    /**
1282
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#print(java.awt.Graphics2D,
1283
     *      java.awt.geom.AffineTransform)
1284
     */
1285
    public void print(Graphics2D g, AffineTransform at, FShape shape, PrintRequestAttributeSet properties) {
1286
               this.properties=properties;
1287
        draw(g, at, null, null);
1288
        this.properties=null;
1289

    
1290
    }
1291

    
1292
    /**
1293
     * Update the dependences that have this FFrame with the other FFrame.
1294
     *
1295
     * @param fframes Other FFrames.
1296
     */
1297
    public void initDependence(IFFrame[] fframes) {
1298
        if ((dependenceIndex != -1) &&
1299
                fframes[dependenceIndex] instanceof FFrameView) {
1300
            fframeview = (FFrameView) fframes[dependenceIndex];
1301
        }
1302
    }
1303

    
1304
    /**
1305
     * DOCUMENT ME!
1306
     *
1307
     * @param d DOCUMENT ME!
1308
     *
1309
     * @return DOCUMENT ME!
1310
     */
1311
    public String format(double d) {
1312
        if ((d % (long) d) != 0) {
1313
            numberFormat.setMaximumFractionDigits(getNumDec());
1314
        } else {
1315
            numberFormat.setMaximumFractionDigits(0);
1316
        }
1317

    
1318
        //String s = String.valueOf(nf.format(d));
1319
        //s=s.replace('.','*');
1320
        //s = s.replace(',', '.');
1321
        //s=s.replace('*',',');
1322
        return numberFormat.format(d); //(Double.valueOf(s).doubleValue());
1323
    }
1324

    
1325
    /**
1326
     * DOCUMENT ME!
1327
     *
1328
     * @return DOCUMENT ME!
1329
     */
1330
    public int getNumDec() {
1331
        return numDec;
1332
    }
1333

    
1334
    /**
1335
     * DOCUMENT ME!
1336
     *
1337
     * @param numDec DOCUMENT ME!
1338
     */
1339
    public void setNumDec(int numDec) {
1340
        this.numDec = numDec;
1341
    }
1342

    
1343
    public void initialize() {
1344
        // TODO Auto-generated method stub
1345

    
1346
    }
1347
    private final static int DUIB=0;
1348
    private final static int DUBI=1;
1349
    private final static int DBIU=2;
1350
    private final static int DIBU=3;
1351
    private final static int UIBD=4;
1352
    private final static int UBID=5;
1353
    private final static int IBUD=6;
1354
    private final static int BIUD=7;
1355

    
1356
    private int getFormat(){
1357
        if (isAboveDescription()){
1358
            if (isAboveName()){
1359
                if (isAboveIntervals()){
1360
                    return DUIB;
1361
                }
1362
                return DUBI;
1363
            }
1364
            if (isAboveIntervals()){
1365
                    return DIBU;
1366
                }
1367
                return DBIU;
1368
        }
1369
        if (isAboveName()){
1370
            if (isAboveIntervals()){
1371
                return UIBD;
1372
            }
1373
            return UBID;
1374
        }
1375
        if (isAboveIntervals()){
1376
            return IBUD;
1377
        }
1378
        return BIUD;
1379
    }
1380

    
1381
        public void cloneActions(IFFrame frame) {
1382
                // TODO Auto-generated method stub
1383

    
1384
        }
1385

    
1386
        public IFFrameDialog getPropertyDialog() {
1387
                return new FFrameScaleBarDialog(getLayout(),this);
1388
        }
1389
}