Statistics
| Revision:

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

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.fmap.dal.exception.ReadException;
62
import org.gvsig.fmap.geom.Geometry;
63
import org.gvsig.fmap.mapcontext.MapContext;
64

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

    
75

    
76

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

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

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

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

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

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

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

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

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

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

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

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

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

    
232
        return "0";
233
    }
234

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
359
        return fframeview.getScale();
360
    }
361

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

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

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

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

    
391
                        g.setColor(textcolor);
392

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

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

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

    
424
                        g.drawString(scale, (int) r.x,
425
                            (int) (r.y + (r.height / 2)));
426

    
427
                        break;
428

    
429
                    case (BARRA1):
430
                    case (BARRA2):
431
                    case (BARRA3):
432
                    case (BARRA4):
433
                        drawBar(m_style, g, at);
434

    
435
                        break;
436
                }
437
            }
438
        }
439

    
440
        g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2),
441
            r.y + (r.height / 2));
442
    }
443

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

    
456
            return;
457
        }
458

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

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

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

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

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

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

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

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

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

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

    
518
        double h = 0;
519

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
648
        Point2D.Double p = null;
649

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

    
659
        drawInterval(g, interString, p);
660

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
933
        return dif;
934
    }
935

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

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

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

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

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

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

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

    
998
                for (int i = 0; i < fframes.length; i++) {
999
                        if (fframeview.equals(fframes[i])) {
1000
                       xml.putProperty("index", i);
1001
                       break;
1002
                   }
1003
               }
1004
            }
1005

    
1006
            xml.putProperty("barcolor", StringUtilities.color2String(barcolor));
1007
            xml.putProperty("textcolor", StringUtilities.color2String(textcolor));
1008
            xml.putProperty("showNameUnits", showNameUnits);
1009
            xml.putProperty("showDescription", showDescription);
1010
            xml.putProperty("aboveName", aboveName);
1011
            xml.putProperty("aboveIntervals", aboveIntervals);
1012
            xml.putProperty("aboveDescription", aboveDescription);
1013
        } catch (Exception e) {
1014
            throw new SaveException(e, this.getClass().getName());
1015
        }
1016

    
1017
        return xml;
1018
    }
1019

    
1020
    /**
1021
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
1022
     *      com.iver.cit.gvsig.project.Project)
1023
     */
1024
    public void setXMLEntity03(XMLEntity xml, Layout l) {
1025
        if (xml.getIntProperty("m_Selected") != 0) {
1026
            this.setSelected(true);
1027
        } else {
1028
            this.setSelected(false);
1029
        }
1030

    
1031
        this.m_bIntervalSet = xml.getBooleanProperty("m_bIntervalSet");
1032
        this.m_dif = xml.getDoubleProperty("m_dif");
1033
        this.m_hasleft = xml.getIntProperty("m_hasleft");
1034
        this.m_nameUnit = xml.getStringProperty("m_nameUnit");
1035
        this.m_numUnit = xml.getDoubleProperty("m_numUnit");
1036

    
1037
        this.m_height = xml.getDoubleProperty("m_height");
1038

    
1039
        this.m_style = xml.getIntProperty("m_style");
1040
        this.m_interval = xml.getLongProperty("m_interval");
1041
        this.m_numinterval = xml.getIntProperty("m_numinterval");
1042
        this.m_numleft = xml.getIntProperty("m_numleft");
1043
        this.m_mapUnits = xml.getIntProperty("m_mapUnits");
1044
        this.m_f = new Font(xml.getStringProperty("fontName"),
1045
                xml.getIntProperty("fontStyle"), 9);
1046

    
1047
        fframeview = (FFrameView) l.getLayoutContext().getFFrame(xml.getIntProperty("index"));
1048

    
1049
        if (xml.contains("description")) { //Comprobar que es de la versi?n que cambia el di?logo.
1050
            this.barcolor = StringUtilities.string2Color(xml.getStringProperty(
1051
                        "barcolor"));
1052
            this.textcolor = StringUtilities.string2Color(xml.getStringProperty(
1053
                        "textcolor"));
1054
            this.showNameUnits = xml.getBooleanProperty("showNameUnits");
1055
            this.showDescription = xml.getBooleanProperty("showDescription");
1056
            this.aboveName = xml.getBooleanProperty("aboveName");
1057
            this.aboveIntervals = xml.getBooleanProperty("aboveIntervals");
1058
            this.aboveDescription = xml.getBooleanProperty("aboveDescription");
1059
        }
1060
    }
1061

    
1062
    /**
1063
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
1064
     *      com.iver.cit.gvsig.project.Project)
1065
     */
1066
    public void setXMLEntity(XMLEntity xml) {
1067
        if (xml.getIntProperty("m_Selected") != 0) {
1068
            this.setSelected(true);
1069
        } else {
1070
            this.setSelected(false);
1071
        }
1072

    
1073
        this.m_bIntervalSet = xml.getBooleanProperty("m_bIntervalSet");
1074
        this.m_dif = xml.getDoubleProperty("m_dif");
1075
        this.m_hasleft = xml.getIntProperty("m_hasleft");
1076
        this.m_nameUnit = xml.getStringProperty("m_nameUnit");
1077
        this.m_numUnit = xml.getDoubleProperty("m_numUnit");
1078

    
1079
        this.m_height = xml.getDoubleProperty("m_height");
1080

    
1081
        this.m_style = xml.getIntProperty("m_style");
1082
        this.m_interval = xml.getDoubleProperty("m_interval");
1083
        this.m_numinterval = xml.getIntProperty("m_numinterval");
1084
        this.m_numleft = xml.getIntProperty("m_numleft");
1085
        this.m_mapUnits = xml.getIntProperty("m_mapUnits");
1086
        this.m_f = new Font(xml.getStringProperty("fontName"),
1087
                xml.getIntProperty("fontStyle"), 9);
1088
        setRotation(xml.getDoubleProperty("m_rotation"));
1089

    
1090
        if (xml.contains("m_units")) { //Comprobaci?n por versi?n 0.5
1091
            setUnits(xml.getIntProperty("m_units"));
1092
        }
1093

    
1094
        if (xml.contains("index")) {
1095
            dependenceIndex = xml.getIntProperty("index");
1096
        }
1097

    
1098

    
1099
        if (xml.contains("showDescription")) { //Comprobar que es de la versi?n que cambia el di?logo.
1100
            this.barcolor = StringUtilities.string2Color(xml.getStringProperty(
1101
            "barcolor"));
1102

    
1103
            this.textcolor = StringUtilities.string2Color(xml.getStringProperty(
1104
                        "textcolor"));
1105
            this.showNameUnits = xml.getBooleanProperty("showNameUnits");
1106
            this.showDescription = xml.getBooleanProperty("showDescription");
1107
            this.aboveName = xml.getBooleanProperty("aboveName");
1108
            this.aboveIntervals = xml.getBooleanProperty("aboveIntervals");
1109
            this.aboveDescription = xml.getBooleanProperty("aboveDescription");
1110
        }
1111

    
1112
        if (xml.contains("numDec")) {
1113
            setNumDec(xml.getIntProperty("numDec"));
1114
        }
1115
    }
1116

    
1117
    /**
1118
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getNameFFrame()
1119
     */
1120
    public String getNameFFrame() {
1121
        return PluginServices.getText(this, "escala")+ num;
1122
    }
1123

    
1124
    /**
1125
     * Inserta el color de la escala gr?fica.
1126
     *
1127
     * @param color Color de la escala gr?fica.
1128
     */
1129
    public void setBarColor(Color color) {
1130
        barcolor = color;
1131
    }
1132

    
1133
    /**
1134
     * Inserta el color del texto.
1135
     *
1136
     * @param color Color del texto.
1137
     */
1138
    public void setTextColor(Color color) {
1139
        textcolor = color;
1140
    }
1141

    
1142
    /**
1143
     * Devuelve el color de la escala gr?fica.
1144
     *
1145
     * @return Color de la escala gr?fica.
1146
     */
1147
    public Color getBarColor() {
1148
        return barcolor;
1149
    }
1150

    
1151
    /**
1152
     * Devuelve el color del texto.
1153
     *
1154
     * @return Color del texto.
1155
     */
1156
    public Color getTextColor() {
1157
        return textcolor;
1158
    }
1159

    
1160
    /**
1161
     * Devuelve true si se debe mostrar el nombre de las unidades de medida de
1162
     * la escala gr?fica.
1163
     *
1164
     * @return True si se muestra las unidades de medida.
1165
     */
1166
    public boolean isShowNameUnits() {
1167
        return showNameUnits;
1168
    }
1169

    
1170
    /**
1171
     * Inserta si se debe de mostrar el nombre de las unidades de medida o no.
1172
     *
1173
     * @param showNameUnits True si se muestra el nombre de las unidades de
1174
     *        medida.
1175
     */
1176
    public void setShowNameUnits(boolean showNameUnits) {
1177
        this.showNameUnits = showNameUnits;
1178
    }
1179

    
1180
    /**
1181
     * Devuelve true si se muestra la descripci?n a la parte de arriba de la
1182
     * escala gr?fica.
1183
     *
1184
     * @return True si se muestra arriba de la escala gr?fica.
1185
     */
1186
    public boolean isAboveDescription() {
1187
        return aboveDescription;
1188
    }
1189

    
1190
    /**
1191
     * Introduce true si se muestra arriba de la escala gr?fica la descripci?n.
1192
     *
1193
     * @param aboveDescription True si se muestra arriba la descripci?n.
1194
     */
1195
    public void setAboveDescription(boolean aboveDescription) {
1196
        this.aboveDescription = aboveDescription;
1197
    }
1198

    
1199
    /**
1200
     * Devuelve true si se muestran a la parte de arriba los valores de los
1201
     * intervalos.
1202
     *
1203
     * @return True si se muestran arriba de la escala gr?fica.
1204
     */
1205
    public boolean isAboveIntervals() {
1206
        return aboveIntervals;
1207
    }
1208

    
1209
    /**
1210
     * Inserta si se muestran los valores de los intervalos a la parte de
1211
     * arriba de la escala o debajo.
1212
     *
1213
     * @param aboveIntervals True si se muestran los valores de los intervalos
1214
     *        a la parte de arriba de la escala gr?fica.
1215
     */
1216
    public void setAboveIntervals(boolean aboveIntervals) {
1217
        this.aboveIntervals = aboveIntervals;
1218
    }
1219

    
1220
    /**
1221
     * Devuelve si se muestra a la parte de arriba de la escala gr?fica el
1222
     * nombre de las unidades de medida o debajo.
1223
     *
1224
     * @return True si se muestra a la parte de arriba de la escala gr?fica.
1225
     */
1226
    public boolean isAboveName() {
1227
        return aboveName;
1228
    }
1229

    
1230
    /**
1231
     * Inserta si el nombre se muestra a la parte de arriba de la escala
1232
     * gr?fica o a la parte de abajo.
1233
     *
1234
     * @param aboveName True si se muestra a la parte de arriba de la escala
1235
     *        gr?fica.
1236
     */
1237
    public void setAboveName(boolean aboveName) {
1238
        this.aboveName = aboveName;
1239
    }
1240

    
1241
    /**
1242
     * Devuelve si se debe mostrar la descripci?n o no.
1243
     *
1244
     * @return True si se muestra la descripci?n.
1245
     */
1246
    public boolean isShowDescription() {
1247
        return showDescription;
1248
    }
1249

    
1250
    /**
1251
     * Inserta si se muestra o no la descripci?n.
1252
     *
1253
     * @param showDescription True si se muestra la descripci?n.
1254
     */
1255
    public void setShowDescription(boolean showDescription) {
1256
        this.showDescription = showDescription;
1257
    }
1258

    
1259
    /**
1260
     * Devuelve la descripci?n de la escala.
1261
     *
1262
     * @return Descripci?n de la escala.
1263
     */
1264
    public String getDescription() {
1265
        if (fframeview!=null){
1266
                if (fframeview.getScale()==0){
1267
                        return PluginServices.getText(this,"escala_desconocida");
1268
                }
1269
            return "1:" + String.valueOf(fframeview.getScale());
1270
        }
1271
            return "1:";
1272
    }
1273

    
1274
    /**
1275
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#print(java.awt.Graphics2D,
1276
     *      java.awt.geom.AffineTransform)
1277
     */
1278
    public void print(Graphics2D g, AffineTransform at, Geometry geom, PrintRequestAttributeSet properties)
1279
        throws ReadException {
1280
        draw(g, at, null, null);
1281
    }
1282

    
1283
    /**
1284
     * Update the dependences that have this FFrame with the other FFrame.
1285
     *
1286
     * @param fframes Other FFrames.
1287
     */
1288
    public void initDependence(IFFrame[] fframes) {
1289
        if ((dependenceIndex != -1) &&
1290
                fframes[dependenceIndex] instanceof FFrameView) {
1291
            fframeview = (FFrameView) fframes[dependenceIndex];
1292
        }
1293
    }
1294

    
1295
    /**
1296
     * DOCUMENT ME!
1297
     *
1298
     * @param d DOCUMENT ME!
1299
     *
1300
     * @return DOCUMENT ME!
1301
     */
1302
    public String format(double d) {
1303
        if ((d % (long) d) != 0) {
1304
            numberFormat.setMaximumFractionDigits(getNumDec());
1305
        } else {
1306
            numberFormat.setMaximumFractionDigits(0);
1307
        }
1308

    
1309
        //String s = String.valueOf(nf.format(d));
1310
        //s=s.replace('.','*');
1311
        //s = s.replace(',', '.');
1312
        //s=s.replace('*',',');
1313
        return numberFormat.format(d); //(Double.valueOf(s).doubleValue());
1314
    }
1315

    
1316
    /**
1317
     * DOCUMENT ME!
1318
     *
1319
     * @return DOCUMENT ME!
1320
     */
1321
    public int getNumDec() {
1322
        return numDec;
1323
    }
1324

    
1325
    /**
1326
     * DOCUMENT ME!
1327
     *
1328
     * @param numDec DOCUMENT ME!
1329
     */
1330
    public void setNumDec(int numDec) {
1331
        this.numDec = numDec;
1332
    }
1333

    
1334
    public void initialize() {
1335
        // TODO Auto-generated method stub
1336

    
1337
    }
1338
    private final static int DUIB=0;
1339
    private final static int DUBI=1;
1340
    private final static int DBIU=2;
1341
    private final static int DIBU=3;
1342
    private final static int UIBD=4;
1343
    private final static int UBID=5;
1344
    private final static int IBUD=6;
1345
    private final static int BIUD=7;
1346

    
1347
    private int getFormat(){
1348
        if (isAboveDescription()){
1349
            if (isAboveName()){
1350
                if (isAboveIntervals()){
1351
                    return DUIB;
1352
                }
1353
                return DUBI;
1354
            }
1355
            if (isAboveIntervals()){
1356
                    return DIBU;
1357
                }
1358
                return DBIU;
1359
        }
1360
        if (isAboveName()){
1361
            if (isAboveIntervals()){
1362
                return UIBD;
1363
            }
1364
            return UBID;
1365
        }
1366
        if (isAboveIntervals()){
1367
            return IBUD;
1368
        }
1369
        return BIUD;
1370
    }
1371

    
1372
        public void cloneActions(IFFrame frame) {
1373
                // TODO Auto-generated method stub
1374

    
1375
        }
1376

    
1377
        public IFFrameDialog getPropertyDialog() {
1378
                return new FFrameScaleBarDialog(getLayout(),this);
1379
        }
1380
}