Statistics
| Revision:

root / branches / v10 / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameScaleBar.java @ 20910

History | View | Annotate | Download (45 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.gui.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 com.iver.andami.PluginServices;
60
import com.iver.cit.gvsig.fmap.DriverException;
61
import com.iver.cit.gvsig.fmap.MapContext;
62
import com.iver.cit.gvsig.gui.layout.Attributes;
63
import com.iver.cit.gvsig.gui.layout.Layout;
64
import com.iver.cit.gvsig.project.documents.exceptions.SaveException;
65
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities;
66
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame;
67
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameViewDependence;
68
import com.iver.utiles.StringUtilities;
69
import com.iver.utiles.XMLEntity;
70

    
71

    
72

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

    
114
    /**
115
     * Creates a new FFrameScaleBar object.
116
     */
117
    public FFrameScaleBar() {
118
    }
119

    
120
    public void refreshDependence(IFFrame fant, IFFrame fnew) {
121
            if ((fframeview != null) &&
122
                fframeview.equals(fant)) {
123
            fframeview=(FFrameView)fnew;
124
            if (fframeview==null)
125
                    return;
126
            setMapUnits(fframeview.getMapUnits());
127
            setHeight(fnew.getBoundBox().height);
128
            }
129
    }
130
    /**
131
     * Inserta una FFrameView de donde se obtiene la informaci?n de las capas
132
     * para generar la leyenda.
133
     *
134
     * @param f FFrameView para obtener los nombres de las capas.
135
     */
136
    public void setFFrameDependence(IFFrame fnew) {
137
            fframeview=(FFrameView)fnew;
138
            if (fframeview==null)
139
                return;
140
        setMapUnits(fframeview.getMapUnits());
141
        setHeight(fnew.getBoundBox().height);
142
    }
143
    /**
144
     * Devuelve el FFrameView que se representa con la escala.
145
     *
146
     * @return FFrameView a representar.
147
     */
148
    public IFFrame[] getFFrameDependence() {
149
        return new IFFrame[]{fframeview};
150
    }
151

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

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

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

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

    
187
        if (m_numleft != 0) {
188
            m_hasleft = 1;
189
        }
190

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

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

    
209
            if (m_numleft != 0) {
210
                m_hasleft = 1;
211
            }
212

    
213
            double difL = (rect.width / DIFL);
214
            double difR = (rect.width / DIFR);
215
            double n = (rect.width - difL - difR);
216
            m_numUnit = n / (m_numinterval + m_hasleft);
217

    
218
            double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
219
            m_dif = getExact(scaleXunit);
220
            m_numUnit = m_numUnit * m_dif;
221
            m_interval = scaleXunit;
222

    
223
            ///m_interval = (scaleXunit * m_dif);
224
            return format(m_interval);
225
        }
226

    
227
        return "0";
228
    }
229

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

    
238
        if (m_numleft != 0) {
239
            m_hasleft = 1;
240
        }
241

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

    
248
        double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
249
        m_dif = getExact(scaleXunit);
250
        m_numUnit = m_numUnit * m_dif;
251
        m_interval = (scaleXunit * m_dif);
252
    }
253

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

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

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

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

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

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

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

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

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

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

    
354
        return fframeview.getScale();
355
    }
356

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

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

    
380
                        double scalex = r.getWidth() / (8);
381

    
382
                        if (scalex > (r.getHeight() / (8))) {
383
                            scalex = r.getHeight() / (2);
384
                        }
385

    
386
                        g.setColor(textcolor);
387

    
388
                        if (m_f != null) {
389
                            m_f = new Font(m_f.getFontName(), m_f.getStyle(),
390
                                    (int) (scalex));
391
                            g.setFont(m_f);
392
                        }
393

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

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

    
419
                        g.drawString(scale, (int) r.x,
420
                            (int) (r.y + (r.height / 2)));
421

    
422
                        break;
423

    
424
                    case (BARRA1):
425
                    case (BARRA2):
426
                    case (BARRA3):
427
                    case (BARRA4):
428
                        drawBar(m_style, g, at);
429

    
430
                        break;
431
                }
432
            }
433
        }
434

    
435
        g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2),
436
            r.y + (r.height / 2));
437
    }
438

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

    
451
            return;
452
        }
453

    
454
        double difL = (r.width / DIFL);
455
        double difR = (r.width / DIFR);
456

    
457
        if (m_bIntervalSet) {
458
            m_numinterval = (int) (((r.width - (difL + difR)) * m_dif) / m_numUnit) -
459
                m_hasleft;
460
        }
461

    
462
        if (m_numinterval < 1) {
463
            m_numinterval = 1;
464
            r.width = ((m_numinterval + m_hasleft) * m_numUnit) + difL + difR;
465
        }
466

    
467
        getBoundBox().setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
468
    }
469

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

    
489
        //setDescripcion("escala 1:" + String.valueOf(fframeview.getScale()));
490
        g.setStroke(new BasicStroke(0));
491

    
492
        if (!m_bIntervalSet) {
493
            m_numUnit = n / (m_numinterval + m_hasleft);
494

    
495
            double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
496
            m_dif = getExact(scaleXunit);
497
            m_numUnit = m_numUnit * m_dif;
498
            m_interval = (scaleXunit * m_dif);
499
        }
500

    
501
        if (m_bIntervalSet) {
502
            m_numUnit = (m_interval * m_typeUnit) / (m_dif * getScaleView());
503
            m_numinterval = (int) (((rect.width - (difL + difR)) * m_dif) / m_numUnit) -
504
                m_hasleft;
505
        }
506

    
507
        if (m_numinterval < 1) {
508
            m_numinterval = 1;
509
            rect.width = ((m_numinterval + m_hasleft) * m_numUnit) + difL +
510
                difR;
511
        }
512

    
513
        double h = 0;
514

    
515
        if (type == BARRA1) {
516
            h = (rect.height - (difUp + difDown));
517
        } else if ((type == BARRA2) || (type == BARRA3)) {
518
            h = (rect.height - (difUp + difDown)) / 2;
519
        }
520

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

    
533
        if (m_f != null) {
534
            m_f = new Font(m_f.getFontName(), m_f.getStyle(),
535
                    (int) (r.getHeight() / 4));
536
        } else {
537
            m_f = new Font("SansSerif", Font.PLAIN, (int) (r.getHeight() / 4));
538
        }
539

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

    
557
        FontMetrics fm = g.getFontMetrics();
558
        String formatInterval = format(m_interval);
559
        double d = (rectotal.getWidth() / m_numinterval) + m_hasleft;
560
        double difpos = ((r.getHeight() / 4) * formatInterval.length()) / 4;
561

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

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

    
582
            //                        Correcci?n cuando la altura en pixels del rect?ngulo es impar.
583
            rectotal.y = recder.y;
584
            recderB.height = rectotal.height - recder.height + 0.5;
585

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

    
619
            String interString = format(m_interval * i);
620
            Point2D.Double p = null;
621

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

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

    
637
            drawInterval(g, interString, p);
638
        }
639

    
640
        //?ltimo n?mero a dibujar.
641
        String interString = format(m_interval * m_numinterval);
642

    
643
        Point2D.Double p = null;
644

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

    
654
        drawInterval(g, interString, p);
655

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

    
669
            //Correcci?n cuando la altura en pixels del rectangulo es impar.
670
            reciz.y = rectotal.y;
671
            recizB.height = rectotal.height - reciz.height + 0.5;
672

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

    
685
        if (m_numleft > 0) {
686
            interString = format(m_interval);
687

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

    
697
            drawInterval(g, interString, p);
698
        }
699

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

    
710
        //Se dibuja el rect?ngulo que bordea toda la escala gr?fica.
711
        g.drawRect((int) rectotal.x, (int) rectotal.y, (int) (rectotal.width),
712
            (int) rectotal.height);
713

    
714
        drawNameUnitsAndDescriptions(g, r);
715
        //drawDescription(g, r);
716
    }
717

    
718
    /**
719
     * Inicializa las distancias de la barra de escala.
720
     */
721
    private void initDistances() {
722
        int numUp = 0;
723
        int numDown = 0;
724

    
725
        DIFDOWN = 30;
726
        DIFL = 40;
727
        DIFR = 40;
728
        DIFUP = 30;
729

    
730
        if (isAboveName()) {
731
            numUp++;
732
        } else {
733
            numDown++;
734
        }
735

    
736
        if (isAboveIntervals()) {
737
            numUp++;
738
        } else {
739
            numDown++;
740
        }
741

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

    
748
        if (numDown == 1) {
749
            DIFDOWN = 3;
750
        } else if (numDown == 2) {
751
            DIFDOWN = 2;
752
        } else if (numDown == 3) {
753
            DIFDOWN = 1.2;
754
        }
755

    
756
        if (numUp == 1) {
757
            DIFUP = 3;
758
        } else if (numUp == 2) {
759
            DIFUP = 2;
760
        } else if (numUp == 3) {
761
            DIFUP = 1.2;
762
        }
763
    }
764

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

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

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

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

    
887
    /**
888
     * Devuelve si el intervalo es variable o si por el contrario es fijo.
889
     *
890
     * @return true si el intervalo es fijo.
891
     */
892
    public boolean isbIntervalSet() {
893
        return m_bIntervalSet;
894
    }
895

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

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

    
924
        if (dif == 0) {
925
            return 1;
926
        }
927

    
928
        return dif;
929
    }
930

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

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

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

    
968
        try {
969
            xml.putProperty("type", Layout.RECTANGLESCALEBAR);
970
            xml.putProperty("m_bIntervalSet", m_bIntervalSet);
971
            xml.putProperty("m_dif", m_dif);
972
            xml.putProperty("m_hasleft", m_hasleft);
973
            xml.putProperty("m_nameUnit", m_nameUnit);
974
            xml.putProperty("m_numUnit", m_numUnit);
975

    
976
            xml.putProperty("m_height", m_height);
977

    
978
            xml.putProperty("m_style", m_style);
979
            xml.putProperty("m_units", m_units);
980
            xml.putProperty("m_interval", m_interval);
981
            xml.putProperty("m_numinterval", m_numinterval);
982
            xml.putProperty("m_numleft", m_numleft);
983
            xml.putProperty("m_mapUnits", m_mapUnits);
984
            xml.putProperty("fontName", m_f.getFontName());
985
            xml.putProperty("fontStyle", m_f.getStyle());
986
            xml.putProperty("numDec", numDec);
987
            xml.putProperty("m_units", m_units);
988

    
989
            if (fframeview != null) {
990
                Layout layout = fframeview.getLayout();
991
                IFFrame[] fframes = layout.getAllFFrames();
992

    
993
                for (int i = 0; i < fframes.length; i++) {
994
                    if (fframeview.getName().equals(fframes[i].getName())) {
995
                        xml.putProperty("index", i);
996
                    }
997
                }
998
            }
999

    
1000
            xml.putProperty("barcolor", StringUtilities.color2String(barcolor));
1001
            xml.putProperty("textcolor", StringUtilities.color2String(textcolor));
1002
            xml.putProperty("showNameUnits", showNameUnits);
1003
            xml.putProperty("showDescription", showDescription);
1004
            xml.putProperty("aboveName", aboveName);
1005
            xml.putProperty("aboveIntervals", aboveIntervals);
1006
            xml.putProperty("aboveDescription", aboveDescription);
1007
        } catch (Exception e) {
1008
            throw new SaveException(e, this.getClass().getName());
1009
        }
1010

    
1011
        return xml;
1012
    }
1013

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

    
1025
        this.m_bIntervalSet = xml.getBooleanProperty("m_bIntervalSet");
1026
        this.m_dif = xml.getDoubleProperty("m_dif");
1027
        this.m_hasleft = xml.getIntProperty("m_hasleft");
1028
        this.m_nameUnit = xml.getStringProperty("m_nameUnit");
1029
        this.m_numUnit = xml.getDoubleProperty("m_numUnit");
1030

    
1031
        this.m_height = xml.getDoubleProperty("m_height");
1032

    
1033
        this.m_style = xml.getIntProperty("m_style");
1034
        this.m_interval = xml.getLongProperty("m_interval");
1035
        this.m_numinterval = xml.getIntProperty("m_numinterval");
1036
        this.m_numleft = xml.getIntProperty("m_numleft");
1037
        this.m_mapUnits = xml.getIntProperty("m_mapUnits");
1038
        this.m_f = new Font(xml.getStringProperty("fontName"),
1039
                xml.getIntProperty("fontStyle"), 9);
1040

    
1041
        fframeview = (FFrameView) l.getFFrame(xml.getIntProperty("index"));
1042

    
1043
        if (xml.contains("description")) { //Comprobar que es de la versi?n que cambia el di?logo.
1044
            this.barcolor = StringUtilities.string2Color(xml.getStringProperty(
1045
                        "barcolor"));
1046
            this.textcolor = StringUtilities.string2Color(xml.getStringProperty(
1047
                        "textcolor"));
1048
            this.showNameUnits = xml.getBooleanProperty("showNameUnits");
1049
            this.showDescription = xml.getBooleanProperty("showDescription");
1050
            this.aboveName = xml.getBooleanProperty("aboveName");
1051
            this.aboveIntervals = xml.getBooleanProperty("aboveIntervals");
1052
            this.aboveDescription = xml.getBooleanProperty("aboveDescription");
1053
        }
1054
    }
1055

    
1056
    /**
1057
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
1058
     *      com.iver.cit.gvsig.project.Project)
1059
     */
1060
    public void setXMLEntity(XMLEntity xml) {
1061
        if (xml.getIntProperty("m_Selected") != 0) {
1062
            this.setSelected(true);
1063
        } else {
1064
            this.setSelected(false);
1065
        }
1066

    
1067
        this.m_bIntervalSet = xml.getBooleanProperty("m_bIntervalSet");
1068
        this.m_dif = xml.getDoubleProperty("m_dif");
1069
        this.m_hasleft = xml.getIntProperty("m_hasleft");
1070
        this.m_nameUnit = xml.getStringProperty("m_nameUnit");
1071
        this.m_numUnit = xml.getDoubleProperty("m_numUnit");
1072

    
1073
        this.m_height = xml.getDoubleProperty("m_height");
1074

    
1075
        this.m_style = xml.getIntProperty("m_style");
1076
        this.m_interval = xml.getDoubleProperty("m_interval");
1077
        this.m_numinterval = xml.getIntProperty("m_numinterval");
1078
        this.m_numleft = xml.getIntProperty("m_numleft");
1079
        this.m_mapUnits = xml.getIntProperty("m_mapUnits");
1080
        this.m_f = new Font(xml.getStringProperty("fontName"),
1081
                xml.getIntProperty("fontStyle"), 9);
1082
        setRotation(xml.getDoubleProperty("m_rotation"));
1083

    
1084
        if (xml.contains("m_units")) { //Comprobaci?n por versi?n 0.5
1085
            setUnits(xml.getIntProperty("m_units"));
1086
        }
1087

    
1088
        if (xml.contains("index")) {
1089
            dependenceIndex = xml.getIntProperty("index");
1090
        }
1091

    
1092

    
1093
        if (xml.contains("showDescription")) { //Comprobar que es de la versi?n que cambia el di?logo.
1094
            this.barcolor = StringUtilities.string2Color(xml.getStringProperty(
1095
            "barcolor"));
1096

    
1097
            this.textcolor = StringUtilities.string2Color(xml.getStringProperty(
1098
                        "textcolor"));
1099
            this.showNameUnits = xml.getBooleanProperty("showNameUnits");
1100
            this.showDescription = xml.getBooleanProperty("showDescription");
1101
            this.aboveName = xml.getBooleanProperty("aboveName");
1102
            this.aboveIntervals = xml.getBooleanProperty("aboveIntervals");
1103
            this.aboveDescription = xml.getBooleanProperty("aboveDescription");
1104
        }
1105

    
1106
        if (xml.contains("numDec")) {
1107
            setNumDec(xml.getIntProperty("numDec"));
1108
        }
1109
    }
1110

    
1111
    /**
1112
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getNameFFrame()
1113
     */
1114
    public String getNameFFrame() {
1115
        return PluginServices.getText(this, "escala")+ num;
1116
    }
1117

    
1118
    /**
1119
     * Inserta el color de la escala gr?fica.
1120
     *
1121
     * @param color Color de la escala gr?fica.
1122
     */
1123
    public void setBarColor(Color color) {
1124
        barcolor = color;
1125
    }
1126

    
1127
    /**
1128
     * Inserta el color del texto.
1129
     *
1130
     * @param color Color del texto.
1131
     */
1132
    public void setTextColor(Color color) {
1133
        textcolor = color;
1134
    }
1135

    
1136
    /**
1137
     * Devuelve el color de la escala gr?fica.
1138
     *
1139
     * @return Color de la escala gr?fica.
1140
     */
1141
    public Color getBarColor() {
1142
        return barcolor;
1143
    }
1144

    
1145
    /**
1146
     * Devuelve el color del texto.
1147
     *
1148
     * @return Color del texto.
1149
     */
1150
    public Color getTextColor() {
1151
        return textcolor;
1152
    }
1153

    
1154
    /**
1155
     * Devuelve true si se debe mostrar el nombre de las unidades de medida de
1156
     * la escala gr?fica.
1157
     *
1158
     * @return True si se muestra las unidades de medida.
1159
     */
1160
    public boolean isShowNameUnits() {
1161
        return showNameUnits;
1162
    }
1163

    
1164
    /**
1165
     * Inserta si se debe de mostrar el nombre de las unidades de medida o no.
1166
     *
1167
     * @param showNameUnits True si se muestra el nombre de las unidades de
1168
     *        medida.
1169
     */
1170
    public void setShowNameUnits(boolean showNameUnits) {
1171
        this.showNameUnits = showNameUnits;
1172
    }
1173

    
1174
    /**
1175
     * Devuelve true si se muestra la descripci?n a la parte de arriba de la
1176
     * escala gr?fica.
1177
     *
1178
     * @return True si se muestra arriba de la escala gr?fica.
1179
     */
1180
    public boolean isAboveDescription() {
1181
        return aboveDescription;
1182
    }
1183

    
1184
    /**
1185
     * Introduce true si se muestra arriba de la escala gr?fica la descripci?n.
1186
     *
1187
     * @param aboveDescription True si se muestra arriba la descripci?n.
1188
     */
1189
    public void setAboveDescription(boolean aboveDescription) {
1190
        this.aboveDescription = aboveDescription;
1191
    }
1192

    
1193
    /**
1194
     * Devuelve true si se muestran a la parte de arriba los valores de los
1195
     * intervalos.
1196
     *
1197
     * @return True si se muestran arriba de la escala gr?fica.
1198
     */
1199
    public boolean isAboveIntervals() {
1200
        return aboveIntervals;
1201
    }
1202

    
1203
    /**
1204
     * Inserta si se muestran los valores de los intervalos a la parte de
1205
     * arriba de la escala o debajo.
1206
     *
1207
     * @param aboveIntervals True si se muestran los valores de los intervalos
1208
     *        a la parte de arriba de la escala gr?fica.
1209
     */
1210
    public void setAboveIntervals(boolean aboveIntervals) {
1211
        this.aboveIntervals = aboveIntervals;
1212
    }
1213

    
1214
    /**
1215
     * Devuelve si se muestra a la parte de arriba de la escala gr?fica el
1216
     * nombre de las unidades de medida o debajo.
1217
     *
1218
     * @return True si se muestra a la parte de arriba de la escala gr?fica.
1219
     */
1220
    public boolean isAboveName() {
1221
        return aboveName;
1222
    }
1223

    
1224
    /**
1225
     * Inserta si el nombre se muestra a la parte de arriba de la escala
1226
     * gr?fica o a la parte de abajo.
1227
     *
1228
     * @param aboveName True si se muestra a la parte de arriba de la escala
1229
     *        gr?fica.
1230
     */
1231
    public void setAboveName(boolean aboveName) {
1232
        this.aboveName = aboveName;
1233
    }
1234

    
1235
    /**
1236
     * Devuelve si se debe mostrar la descripci?n o no.
1237
     *
1238
     * @return True si se muestra la descripci?n.
1239
     */
1240
    public boolean isShowDescription() {
1241
        return showDescription;
1242
    }
1243

    
1244
    /**
1245
     * Inserta si se muestra o no la descripci?n.
1246
     *
1247
     * @param showDescription True si se muestra la descripci?n.
1248
     */
1249
    public void setShowDescription(boolean showDescription) {
1250
        this.showDescription = showDescription;
1251
    }
1252

    
1253
    /**
1254
     * Devuelve la descripci?n de la escala.
1255
     *
1256
     * @return Descripci?n de la escala.
1257
     */
1258
    public String getDescription() {
1259
        if (fframeview!=null){
1260
                if (fframeview.getScale()==0){
1261
                        return PluginServices.getText(this,"escala_desconocida");
1262
                }
1263
            return "1:" + String.valueOf(fframeview.getScale());
1264
        }
1265
            return "1:";
1266
    }
1267

    
1268
    /**
1269
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#print(java.awt.Graphics2D,
1270
     *      java.awt.geom.AffineTransform)
1271
     */
1272
    public void print(Graphics2D g, AffineTransform at)
1273
        throws DriverException {
1274
        draw(g, at, null, null);
1275
    }
1276

    
1277
    /**
1278
     * Update the dependences that have this FFrame with the other FFrame.
1279
     *
1280
     * @param fframes Other FFrames.
1281
     */
1282
    public void initDependence(IFFrame[] fframes) {
1283
        if ((dependenceIndex != -1) &&
1284
                fframes[dependenceIndex] instanceof FFrameView) {
1285
            fframeview = (FFrameView) fframes[dependenceIndex];
1286
        }
1287
    }
1288

    
1289
    /**
1290
     * DOCUMENT ME!
1291
     *
1292
     * @param d DOCUMENT ME!
1293
     *
1294
     * @return DOCUMENT ME!
1295
     */
1296
    public String format(double d) {
1297
        if ((d % (long) d) != 0) {
1298
            numberFormat.setMaximumFractionDigits(getNumDec());
1299
        } else {
1300
            numberFormat.setMaximumFractionDigits(0);
1301
        }
1302

    
1303
        //String s = String.valueOf(nf.format(d));
1304
        //s=s.replace('.','*');
1305
        //s = s.replace(',', '.');
1306
        //s=s.replace('*',',');
1307
        return numberFormat.format(d); //(Double.valueOf(s).doubleValue());
1308
    }
1309

    
1310
    /**
1311
     * DOCUMENT ME!
1312
     *
1313
     * @return DOCUMENT ME!
1314
     */
1315
    public int getNumDec() {
1316
        return numDec;
1317
    }
1318

    
1319
    /**
1320
     * DOCUMENT ME!
1321
     *
1322
     * @param numDec DOCUMENT ME!
1323
     */
1324
    public void setNumDec(int numDec) {
1325
        this.numDec = numDec;
1326
    }
1327

    
1328
    public void initialize() {
1329
        // TODO Auto-generated method stub
1330

    
1331
    }
1332
    private final static int DUIB=0;
1333
    private final static int DUBI=1;
1334
    private final static int DBIU=2;
1335
    private final static int DIBU=3;
1336
    private final static int UIBD=4;
1337
    private final static int UBID=5;
1338
    private final static int IBUD=6;
1339
    private final static int BIUD=7;
1340

    
1341
    private int getFormat(){
1342
        if (isAboveDescription()){
1343
            if (isAboveName()){
1344
                if (isAboveIntervals()){
1345
                    return DUIB;
1346
                }
1347
                return DUBI;
1348
            }
1349
            if (isAboveIntervals()){
1350
                    return DIBU;
1351
                }
1352
                return DBIU;
1353
        }
1354
        if (isAboveName()){
1355
            if (isAboveIntervals()){
1356
                return UIBD;
1357
            }
1358
            return UBID;
1359
        }
1360
        if (isAboveIntervals()){
1361
            return IBUD;
1362
        }
1363
        return BIUD;
1364
    }
1365

    
1366
        public void cloneActions(IFFrame frame) {
1367
                // TODO Auto-generated method stub
1368

    
1369
        }
1370
}