Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / fframes / FFrameScaleBar.java @ 9392

History | View | Annotate | Download (44.7 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 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.project.documents.exceptions.SaveException;
63
import com.iver.cit.gvsig.project.documents.layout.Attributes;
64
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities;
65
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameScaleBarDialog;
66
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.IFFrameDialog;
67
import com.iver.cit.gvsig.project.documents.layout.gui.Layout;
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
    /**
121
     * Inserta el FFrameView sobre el que obtener la escala gr?fica.
122
     *
123
     * @param f FFrameView sobre  el que obtener la escala.
124
     */
125
    public void setFFrameDependence(IFFrame f) {
126
        fframeview = (FFrameView) f;
127
        if (fframeview==null)
128
                return;
129
        setMapUnits(fframeview.getMapUnits());
130
        setHeight(f.getBoundBox().height);
131
    }
132

    
133
    /**
134
     * Devuelve el FFrameView que se representa con la escala.
135
     *
136
     * @return FFrameView a representar.
137
     */
138
    public IFFrame getFFrameDependence() {
139
        return fframeview;
140
    }
141

    
142
    /**
143
     * Devuelve el FMap de la vista que se representa en la escala.
144
     *
145
     * @return FMap.
146
     */
147
    public MapContext getFMap() {
148
        return fframeview.getMapContext();
149
    }
150

    
151
    /**
152
     * Rellenar el estilo de barra de escala que se elige.
153
     *
154
     * @param s entero que representa el tipo de barra seleccionada.
155
     */
156
    public void setStyle(int s) {
157
        m_style = s;
158
    }
159

    
160
    /**
161
     * Devuelve el tipo de escala a dibujar.
162
     *
163
     * @return entero.
164
     */
165
    public int getStyle() {
166
        return m_style;
167
    }
168

    
169
    /**
170
     * Rellenar el tama?o de un intervalo.
171
     *
172
     * @param s tama?o de un intervalo.
173
     */
174
    public void setInterval(double s) {
175
        m_interval = s;
176

    
177
        if (m_numleft != 0) {
178
            m_hasleft = 1;
179
        }
180

    
181
        Rectangle2D.Double rect = getBoundBox();
182
        double difL = (rect.width / DIFL);
183
        double difR = (rect.width / DIFR);
184
        double n = (rect.width - difL - difR);
185
        m_numUnit = (m_interval * m_typeUnit) / getScaleView();
186
        m_numinterval = (int) (n / m_numUnit) - m_hasleft;
187
        m_dif = 1;
188
    }
189

    
190
    /**
191
     * Devuelve el valor del intervalo.
192
     *
193
     * @return long.
194
     */
195
    public String obtainInterval() {
196
        if (fframeview != null) {
197
            Rectangle2D.Double rect = getBoundBox();
198

    
199
            if (m_numleft != 0) {
200
                m_hasleft = 1;
201
            }
202

    
203
            double difL = (rect.width / DIFL);
204
            double difR = (rect.width / DIFR);
205
            double n = (rect.width - difL - difR);
206
            m_numUnit = n / (m_numinterval + m_hasleft);
207

    
208
            double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
209
            m_dif = getExact(scaleXunit);
210
            m_numUnit = m_numUnit * m_dif;
211
            m_interval = scaleXunit;
212

    
213
            ///m_interval = (scaleXunit * m_dif);
214
            return format(m_interval);
215
        }
216

    
217
        return "0";
218
    }
219

    
220
    /**
221
     * Rellenar el n?mero de intervalos.
222
     *
223
     * @param s n?mero de intervalos.
224
     */
225
    public void setNumInterval(int s) {
226
        m_numinterval = s;
227

    
228
        if (m_numleft != 0) {
229
            m_hasleft = 1;
230
        }
231

    
232
        Rectangle2D.Double rect = getBoundBox();
233
        double difL = (rect.width / DIFL);
234
        double difR = (rect.width / DIFR);
235
        double n = (rect.width - difL - difR);
236
        m_numUnit = n / (m_numinterval + m_hasleft);
237

    
238
        double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
239
        m_dif = getExact(scaleXunit);
240
        m_numUnit = m_numUnit * m_dif;
241
        m_interval = (scaleXunit * m_dif);
242
    }
243

    
244
    /**
245
     * Devuelve el n?mero de intervalos por encima del cero.
246
     *
247
     * @return entero.
248
     */
249
    public int getNumInterval() {
250
        return m_numinterval;
251
    }
252

    
253
    /**
254
     * Rellenar el n?mero de intervalos a la izquierda del cero.
255
     *
256
     * @param s n?mero de intervalos a la izquierda.
257
     */
258
    public void setNumLeft(int s) {
259
        m_numleft = s;
260
    }
261

    
262
    /**
263
     * Devuelve el n?mero de intervalos  en los que se quiere particionar el
264
     * intervalo  que se queda por debajo del cero.
265
     *
266
     * @return entero.
267
     */
268
    public int getNumLeft() {
269
        return m_numleft;
270
    }
271

    
272
    /**
273
     * Seleccionar ,a true, si se quiere o, a false, si no mantener los
274
     * intervalos.
275
     *
276
     * @param b boolean a true si se quiere mantener los intervalos.
277
     */
278
    public void setIntervalSet(boolean b) {
279
        m_bIntervalSet = b;
280
    }
281

    
282
    /**
283
     * Seleccionar la unidad de medida a representar en la barra de escala.
284
     *
285
     * @param s entero que representa la unidad de medida que se selecciona.
286
     */
287
    public void setUnits(int s) {
288
        m_units = s;
289
        m_typeUnit = Attributes.CHANGE[s];
290
        m_nameUnit = Attributes.NAMES[s];
291
    }
292

    
293
    /**
294
     * Devuelve un entero que representa el tipo de unidades que representamos.
295
     *
296
     * @return entero.
297
     */
298
    public int getUnits() {
299
        return m_units;
300
    }
301

    
302
    /**
303
     * Devuelve el long que representa el intervalo.
304
     *
305
     * @return Intervalo.
306
     */
307
    public String getInterval() {
308
        return format(m_interval);
309
    }
310

    
311
    /**
312
     * Rellenar el rect?ngulo de la vista sobre la que se obtiene la escala.
313
     *
314
     * @param d Rect?ngulo.
315
     */
316
    public void setHeight(double d) {
317
        m_height = d;
318
    }
319

    
320
    /**
321
     * Rellena la unidad de medida en la que est? la vista.
322
     *
323
     * @param i entero que representa la unidad de medida de la vista.
324
     */
325
    public void setMapUnits(int i) {
326
        m_mapUnits = i;
327
    }
328

    
329
    /**
330
     * Devuelve la escala de la vista seleccionada.
331
     *
332
     * @return la escala de la vista.
333
     */
334
    private long getScaleView() {
335
        if (fframeview == null) {
336
            return 1;
337
        }
338

    
339
        return fframeview.getScale();
340
    }
341

    
342
    /**
343
     * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
344
     * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
345
     * de dibujar.
346
     *
347
     * @param g Graphics
348
     * @param at Transformada afin.
349
     * @param rv rect?ngulo sobre el que hacer un clip.
350
     * @param imgBase Image para acelerar el dibujado.
351
     */
352
    public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,
353
        BufferedImage imgBase) {
354
        Rectangle2D.Double r = getBoundingBox(at);
355
        g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2),
356
            r.y + (r.height / 2));
357

    
358
        if (intersects(rv, r)) {
359
            if ((fframeview == null) || (fframeview.getMapContext() == null)) {
360
                drawEmpty(g);
361
            } else {
362
                switch (m_style) {
363
                    case (NUMERO):
364

    
365
                        double scalex = r.getWidth() / (8);
366

    
367
                        if (scalex > (r.getHeight() / (8))) {
368
                            scalex = r.getHeight() / (2);
369
                        }
370

    
371
                        g.setColor(textcolor);
372

    
373
                        if (m_f != null) {
374
                            m_f = new Font(m_f.getFontName(), m_f.getStyle(),
375
                                    (int) (scalex));
376
                            g.setFont(m_f);
377
                        }
378

    
379
                        FontMetrics fm = g.getFontMetrics();
380
                        double d = r.getWidth();
381
                        long scl=getScaleView();
382
                        if (scl<1){
383
                            String unknowScale=PluginServices.getText(this,"escala_desconocida");
384
                            if (fm.stringWidth(unknowScale) > (d * 0.8)) {
385
                                double dif = fm.stringWidth(unknowScale) / (d * 0.8);
386
                                m_f = new Font(m_f.getName(), m_f.getStyle(),
387
                                        (int) (m_f.getSize() / dif));
388
                                g.setFont(m_f);
389
                            }
390
                               g.drawString(unknowScale, (int) r.x,
391
                                    (int) (r.y + (r.height / 2)));
392
                               return;
393
                        }
394
                        String scale = " 1:" + scl;
395

    
396
                        if (fm.stringWidth(String.valueOf(m_interval)) > (d * 0.8)) {
397
                            double dif = fm.stringWidth(String.valueOf(
398
                                        m_interval)) / (d * 0.8);
399
                            m_f = new Font(m_f.getName(), m_f.getStyle(),
400
                                    (int) (m_f.getSize() / dif));
401
                            g.setFont(m_f);
402
                        }
403

    
404
                        g.drawString(scale, (int) r.x,
405
                            (int) (r.y + (r.height / 2)));
406

    
407
                        break;
408

    
409
                    case (BARRA1):
410
                    case (BARRA2):
411
                    case (BARRA3):
412
                    case (BARRA4):
413
                        drawBar(m_style, g, at);
414

    
415
                        break;
416
                }
417
            }
418
        }
419

    
420
        g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2),
421
            r.y + (r.height / 2));
422
    }
423

    
424
    /**
425
     * Rellena con el rect?ngulo que se pasa como par?metro el boundBox(en
426
     * cent?metros) del fframe del cual con una transformaci?n se podr?
427
     * calcular el BoundingBox (en pixels).
428
     *
429
     * @param r Rect?ngulo en cent?metros.
430
     */
431
    public void setBoundBox(Rectangle2D.Double r) {
432
        if ((m_numUnit < 1) || (fframeview == null) ||
433
                (fframeview.getMapContext() == null)) {
434
            super.setBoundBox(r);
435

    
436
            return;
437
        }
438

    
439
        double difL = (r.width / DIFL);
440
        double difR = (r.width / DIFR);
441

    
442
        if (m_bIntervalSet) {
443
            m_numinterval = (int) (((r.width - (difL + difR)) * m_dif) / m_numUnit) -
444
                m_hasleft;
445
        }
446

    
447
        if (m_numinterval < 1) {
448
            m_numinterval = 1;
449
            r.width = ((m_numinterval + m_hasleft) * m_numUnit) + difL + difR;
450
        }
451

    
452
        getBoundBox().setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
453
    }
454

    
455
    /**
456
     * Dibuja sobre el Graphics la escala gr?fica.
457
     *
458
     * @param type Tipo de barra.
459
     * @param g Graphics sobre el que dibujar.
460
     * @param at Matriz de transformaci?n.
461
     */
462
    private void drawBar(int type, Graphics2D g, AffineTransform at) {
463
        Rectangle2D.Double rect = getBoundBox();
464
        Rectangle2D.Double r = getBoundingBox(at);
465
        double numleft = m_numleft;
466
        initDistances();
467
        //drawOrder(g,r);
468
        double difDown = (rect.height / DIFDOWN);
469
        double difUp = (rect.height / DIFUP);
470
        double difL = (rect.width / DIFL);
471
        double difR = (rect.width / DIFR);
472
        double n = (rect.width - difL - difR);
473

    
474
        //setDescripcion("escala 1:" + String.valueOf(fframeview.getScale()));
475
        g.setStroke(new BasicStroke(0));
476

    
477
        if (!m_bIntervalSet) {
478
            m_numUnit = n / (m_numinterval + m_hasleft);
479

    
480
            double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
481
            m_dif = getExact(scaleXunit);
482
            m_numUnit = m_numUnit * m_dif;
483
            m_interval = (scaleXunit * m_dif);
484
        }
485

    
486
        if (m_bIntervalSet) {
487
            m_numUnit = (m_interval * m_typeUnit) / (m_dif * getScaleView());
488
            m_numinterval = (int) (((rect.width - (difL + difR)) * m_dif) / m_numUnit) -
489
                m_hasleft;
490
        }
491

    
492
        if (m_numinterval < 1) {
493
            m_numinterval = 1;
494
            rect.width = ((m_numinterval + m_hasleft) * m_numUnit) + difL +
495
                difR;
496
        }
497

    
498
        double h = 0;
499

    
500
        if (type == BARRA1) {
501
            h = (rect.height - (difUp + difDown));
502
        } else if ((type == BARRA2) || (type == BARRA3)) {
503
            h = (rect.height - (difUp + difDown)) / 2;
504
        }
505

    
506
        //Dibujar el rect?ngulo que bordea todo.
507
        Rectangle2D.Double rectotal = (FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
508
                    difL), (rect.y + difUp),
509
                    m_numUnit * (m_hasleft + m_numinterval), h), at));
510
        g.setColor(barcolor);
511
        g.fillRect((int) rectotal.x, (int) rectotal.y, (int) (rectotal.width),
512
            (int) rectotal.height);
513
        g.setColor(Color.white);
514
        g.fillRect((int) rectotal.x+1, (int) rectotal.y+1, (int) (rectotal.width-2),
515
                (int) rectotal.height-2);
516
        g.setColor(barcolor);
517

    
518
        if (m_f != null) {
519
            m_f = new Font(m_f.getFontName(), m_f.getStyle(),
520
                    (int) (r.getHeight() / 4));
521
        } else {
522
            m_f = new Font("SansSerif", Font.PLAIN, (int) (r.getHeight() / 4));
523
        }
524

    
525
        g.setFont(m_f);
526
        Double interval=new Double(m_interval);
527
        if (interval.isNaN()) {
528
            String unknowScale=PluginServices.getText(this,"escala_desconocida");
529
            FontMetrics fm = g.getFontMetrics();
530
             double d = r.getWidth();
531
            if (fm.stringWidth(unknowScale) > (d * 0.8)) {
532
                double dif = fm.stringWidth(unknowScale) / (d * 0.8);
533
                m_f = new Font(m_f.getName(), m_f.getStyle(),
534
                        (int) (m_f.getSize() / dif));
535
                g.setFont(m_f);
536
            }
537
               g.drawString(unknowScale, (int) r.x,
538
                    (int) (r.y + (r.height / 2)));
539
               return;
540
        }
541

    
542
        FontMetrics fm = g.getFontMetrics();
543
        String formatInterval = format(m_interval);
544
        double d = (rectotal.getWidth() / m_numinterval) + m_hasleft;
545
        double difpos = ((r.getHeight() / 4) * formatInterval.length()) / 4;
546

    
547
        if (fm.stringWidth(formatInterval) > (d * 0.7)) {
548
            double dif = fm.stringWidth(formatInterval) / (d * 0.7);
549
            difpos = (d * 0.7) / 2;
550
            m_f = new Font(m_f.getName(), m_f.getStyle(),
551
                    (int) (m_f.getSize() / dif));
552
            g.setFont(m_f);
553
        }
554

    
555
        //Derecha del cero
556
        for (int i = 0; i < m_numinterval; i++) {
557
            Rectangle2D.Double recder = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
558
                        (difL) + ((m_numUnit * i) + (m_hasleft * m_numUnit))),
559
                        (rect.y + (difUp)), (m_numUnit),
560
                        (rect.height - (difUp + difDown)) / 2), at);
561
            Rectangle2D.Double recderB = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
562
                        (difL) + ((m_numUnit * i) + (m_hasleft * m_numUnit))),
563
                        (rect.y + difUp) +
564
                        ((rect.height - (difUp + difDown)) / 2), (m_numUnit),
565
                        ((rect.height - (difUp + difDown)) / 2)), at);
566

    
567
            //                        Correcci?n cuando la altura en pixels del rect?ngulo es impar.
568
            rectotal.y = recder.y;
569
            recderB.height = rectotal.height - recder.height + 0.5;
570

    
571
            /**
572
             * if (i == (m_numinterval - 1)) { if (recder.getMaxX() !=
573
             * rectotal.getMaxX()) { recder.width = (recder.width +
574
             * recder.getMaxX()) - rectotal.getMaxX(); } if (recderB.getMaxX()
575
             * != rectotal.getMaxX()) { recderB.width = (recderB.width +
576
             * recderB.getMaxX()) - rectotal.getMaxX(); }} if
577
             * (recderB.getMaxY() != rectotal.getMaxY()) { recderB.height =
578
             * (recderB.height + recderB.getMaxY()) - rectotal.getMaxY(); }
579
             */
580
            if ((m_numleft % 2) == 0) {
581
                if ((i % 2) == 0) {
582
                    if ((type == BARRA1) || (type == BARRA2)) {
583
                        fillRect(g, recder);
584
                    } else if (type == BARRA3) {
585
                        g.drawRect((int) recder.x, (int) recder.y,
586
                            (int) recder.width, (int) recder.height);
587
                    }
588
                } else if (type == BARRA1) {
589
                    fillRect(g, recderB);
590
                }
591
            } else {
592
                if ((i % 2) != 0) {
593
                    if ((type == BARRA1) || (type == BARRA2)) {
594
                        fillRect(g, recder);
595
                    } else if (type == BARRA3) {
596
                        g.drawRect((int) recderB.x, (int) recderB.y,
597
                            (int) recderB.width, (int) recderB.height);
598
                    }
599
                } else if (type == BARRA1) {
600
                    fillRect(g, recderB);
601
                }
602
            }
603

    
604
            String interString = format(m_interval * i);
605
            Point2D.Double p = null;
606

    
607
            if (isAboveIntervals()) {
608
                p = new Point2D.Double(recder.x - difpos,
609
                        r.getMinY() + (r.getHeight() / DIFUP));
610
            } else {
611
                p = new Point2D.Double(recder.x - difpos,
612
                        ((r.getHeight() / 4) + r.getMaxY()) -
613
                        (r.getHeight() / DIFDOWN));
614
            }
615

    
616
            //Para dibujar el 0 centrado en su sitio.
617
            if (i == 0) {
618
                double dif0 = recder.x - (fm.stringWidth(interString) / 2);
619
                p = new Point2D.Double(dif0, p.getY());
620
            }
621

    
622
            drawInterval(g, interString, p);
623
        }
624

    
625
        //?ltimo n?mero a dibujar.
626
        String interString = format(m_interval * m_numinterval);
627

    
628
        Point2D.Double p = null;
629

    
630
        if (isAboveIntervals()) {
631
            p = new Point2D.Double(rectotal.getMaxX() - difpos,
632
                    r.getMinY() + (r.getHeight() / DIFUP));
633
        } else {
634
            p = new Point2D.Double(rectotal.getMaxX() - difpos,
635
                    ((r.getHeight() / 4) + r.getMaxY()) -
636
                    (r.getHeight() / DIFDOWN));
637
        }
638

    
639
        drawInterval(g, interString, p);
640

    
641
        //Izquierda del cero
642
        for (int i = 0; i < m_numleft; i++) {
643
            Rectangle2D.Double reciz = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
644
                        difL + ((m_numUnit / m_numleft) * i)),
645
                        (rect.y + difUp), (m_numUnit / numleft),
646
                        (rect.height - (difUp + difDown)) / 2), at);
647
            Rectangle2D.Double recizB = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
648
                        difL + ((m_numUnit / m_numleft) * i)),
649
                        (rect.y + difUp) +
650
                        ((rect.height - (difUp + difDown)) / 2),
651
                        (m_numUnit / numleft),
652
                        ((rect.height - (difUp + difDown)) / 2)), at);
653

    
654
            //Correcci?n cuando la altura en pixels del rectangulo es impar.
655
            reciz.y = rectotal.y;
656
            recizB.height = rectotal.height - reciz.height + 0.5;
657

    
658
            if ((i % 2) == 0) {
659
                if ((type == BARRA1) || (type == BARRA2)) {
660
                    fillRect(g, reciz);
661
                } else if (type == BARRA3) {
662
                    g.drawRect((int) reciz.x, (int) reciz.y, (int) reciz.width,
663
                        (int) reciz.height);
664
                }
665
            } else if (type == BARRA1) {
666
                fillRect(g, recizB);
667
            }
668
        }
669

    
670
        if (m_numleft > 0) {
671
            interString = format(m_interval);
672

    
673
            if (isAboveIntervals()) {
674
                p = new Point2D.Double(rectotal.x - difpos,
675
                        r.getMinY() + (r.getHeight() / DIFUP));
676
            } else {
677
                p = new Point2D.Double(rectotal.x - difpos,
678
                        ((r.getHeight() / 4) + r.getMaxY()) -
679
                        (r.getHeight() / DIFDOWN));
680
            }
681

    
682
            drawInterval(g, interString, p);
683
        }
684

    
685
        //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.
686
        if (m_numleft == 0) {
687
            Rectangle2D.Double recAux = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
688
                        difL + ((m_numUnit / 1) * 0)), (rect.y + difUp),
689
                        (m_numUnit / 1), (rect.height - (difUp + difDown)) / 2),
690
                    at);
691
            rectotal.x = rectotal.x + recAux.width;
692
            rectotal.width = rectotal.width - recAux.width;
693
        }
694

    
695
        //Se dibuja el rect?ngulo que bordea toda la escala gr?fica.
696
        g.drawRect((int) rectotal.x, (int) rectotal.y, (int) (rectotal.width),
697
            (int) rectotal.height);
698

    
699
        drawNameUnitsAndDescriptions(g, r);
700
        //drawDescription(g, r);
701
    }
702

    
703
    /**
704
     * Inicializa las distancias de la barra de escala.
705
     */
706
    private void initDistances() {
707
        int numUp = 0;
708
        int numDown = 0;
709

    
710
        DIFDOWN = 30;
711
        DIFL = 40;
712
        DIFR = 40;
713
        DIFUP = 30;
714

    
715
        if (isAboveName()) {
716
            numUp++;
717
        } else {
718
            numDown++;
719
        }
720

    
721
        if (isAboveIntervals()) {
722
            numUp++;
723
        } else {
724
            numDown++;
725
        }
726

    
727
        if (isAboveDescription()) {
728
            numUp++;
729
        } else {
730
            numDown++;
731
        }
732

    
733
        if (numDown == 1) {
734
            DIFDOWN = 3;
735
        } else if (numDown == 2) {
736
            DIFDOWN = 2;
737
        } else if (numDown == 3) {
738
            DIFDOWN = 1.2;
739
        }
740

    
741
        if (numUp == 1) {
742
            DIFUP = 3;
743
        } else if (numUp == 2) {
744
            DIFUP = 2;
745
        } else if (numUp == 3) {
746
            DIFUP = 1.2;
747
        }
748
    }
749

    
750
    /**
751
     * Dibuja sobre el Graphics el nombre de la unidad de medida de la escala y la descripci?n,
752
     * siendo por defecto la escala 1:.
753
     *
754
     * @param g Graphics sobre el que se dibuja.
755
     * @param rec Rect?ngulo que ocupa la escala gr?fica.
756
     */
757
    private void drawNameUnitsAndDescriptions(Graphics g, Rectangle2D.Double rec) {
758
        FontMetrics fm = g.getFontMetrics();
759
        Point2D.Double pD = null;
760
        Point2D.Double pU = null;
761
        g.setColor(textcolor);
762
               switch (getFormat()) {
763
               case DUIB:
764
                   pD = new Point2D.Double(rec.getCenterX() -
765
                        (fm.stringWidth(getDescription()) / 2),
766
                        (rec.getMinY() + (rec.getHeight() / 9) +
767
                        (fm.getHeight() / 2)));
768
                   pU = new Point2D.Double(rec.getCenterX() -
769
                           (fm.stringWidth(m_nameUnit) / 2),
770
                           (rec.getMinY() + (rec.getHeight() / 3) +
771
                           (fm.getHeight() / 2)));
772

    
773
                   break;
774
               case DUBI:
775
                   pD = new Point2D.Double(rec.getCenterX() -
776
                        (fm.stringWidth(getDescription()) / 2),
777
                        (rec.getMinY() + (rec.getHeight() / 9) +
778
                        (fm.getHeight() / 2)));
779
                   pU = new Point2D.Double(rec.getCenterX() -
780
                           (fm.stringWidth(m_nameUnit) / 2),
781
                           (rec.getMinY() + (rec.getHeight() / 3) +
782
                           (fm.getHeight() / 2)));
783
                   break;
784
               case DBIU:
785
                   pD = new Point2D.Double(rec.getCenterX() -
786
                        (fm.stringWidth(getDescription()) / 2),
787
                        (rec.getMinY() + (rec.getHeight() / 9) +
788
                        (fm.getHeight() / 2)));
789
                   pU = new Point2D.Double(rec.getCenterX() -
790
                            (fm.stringWidth(m_nameUnit) / 2),
791
                            (rec.getMaxY() - (rec.getHeight() / 9) +
792
                            (fm.getHeight() / 3)));
793
                   break;
794
               case DIBU:
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.getMaxY() - (rec.getHeight() / 9) +
802
                            (fm.getHeight() / 3)));
803
                   break;
804
               case UIBD:
805
                   pD = new Point2D.Double(rec.getCenterX() -
806
                            (fm.stringWidth(getDescription()) / 2),
807
                            (rec.getMaxY() - (rec.getHeight() / 9) +
808
                            (fm.getHeight() / 3)));
809
                   pU = new Point2D.Double(rec.getCenterX() -
810
                           (fm.stringWidth(m_nameUnit) / 2),
811
                           (rec.getMinY() + (rec.getHeight() / 9) +
812
                           (fm.getHeight() / 2)));
813
                   break;
814
               case UBID:
815
                   pD = new Point2D.Double(rec.getCenterX() -
816
                        (fm.stringWidth(getDescription()) / 2),
817
                        (rec.getMaxY() - (rec.getHeight() / 9) +
818
                        (fm.getHeight() / 3)));
819
                   pU = new Point2D.Double(rec.getCenterX() -
820
                           (fm.stringWidth(m_nameUnit) / 2),
821
                           (rec.getMinY() + (rec.getHeight() / 9) +
822
                           (fm.getHeight() / 2)));
823
                   break;
824
               case IBUD:
825
                   pD = new Point2D.Double(rec.getCenterX() -
826
                        (fm.stringWidth(getDescription()) / 2),
827
                        (rec.getMaxY() - (rec.getHeight() / 3) +
828
                        (fm.getHeight() / 3)));
829
                   pU = new Point2D.Double(rec.getCenterX() -
830
                            (fm.stringWidth(m_nameUnit) / 2),
831
                            (rec.getMaxY() - (rec.getHeight() / 9) +
832
                            (fm.getHeight() / 3)));
833

    
834
                   break;
835
               case BIUD:
836
                   pD = new Point2D.Double(rec.getCenterX() -
837
                        (fm.stringWidth(getDescription()) / 2),
838
                        (rec.getMaxY() - (rec.getHeight() / 3) +
839
                        (fm.getHeight() / 3)));
840
                   pU = new Point2D.Double(rec.getCenterX() -
841
                            (fm.stringWidth(m_nameUnit) / 2),
842
                            (rec.getMaxY() - (rec.getHeight() / 9) +
843
                            (fm.getHeight() / 3)));
844
                   break;
845
               }
846
               if (isShowNameUnits()) {
847
                   g.drawString(m_nameUnit, (int) pU.x, (int) pU.y);
848
               }
849
            if (isShowDescription()) {
850
                g.drawString(getDescription(), (int) pD.x, (int) pD.y);
851
            }
852
    }
853
    /**
854
     * Rellena la fuente utilizada para dibujar los intervalos y la unidad de
855
     * medida utilizada.
856
     *
857
     * @param f fuente a utilizar.
858
     */
859
    public void setFont(Font f) {
860
        m_f = f;
861
    }
862

    
863
    /**
864
     * Devuelve la fuente con la que se est? dibujando sobre el graphics.
865
     *
866
     * @return fuente utilizada.
867
     */
868
    public Font getFont() {
869
        return new Font(m_f.getFontName(), m_f.getStyle(), 9);
870
    }
871

    
872
    /**
873
     * Devuelve si el intervalo es variable o si por el contrario es fijo.
874
     *
875
     * @return true si el intervalo es fijo.
876
     */
877
    public boolean isbIntervalSet() {
878
        return m_bIntervalSet;
879
    }
880

    
881
    /**
882
     * Especificar si el intervalo se debe mantener o es variable.
883
     *
884
     * @param b si se quiere mantener el intervalo especificado.
885
     */
886
    public void setbIntervalSet(boolean b) {
887
        m_bIntervalSet = b;
888
    }
889

    
890
    /**
891
     * Devuelve el porcentaje por el cual hay que multiplicar  el intervalo
892
     * para conseguir un intervalo redondeado,  de momento con una cifra
893
     * significativas(NUM=1).
894
     *
895
     * @param total intervalo.
896
     *
897
     * @return Porcentaje
898
     */
899
    private double getExact(double total) {
900
            int NUM = 1;
901
            double t = 0;
902
        double dif = 1;
903
        Double d = new Double(total);
904
        Long l = new Long(d.longValue());
905
        int num = l.toString().length();
906
        t = ((long) (total / Math.pow(10, num - NUM)) * Math.pow(10, num - NUM));
907
        dif = t / total;
908

    
909
        if (dif == 0) {
910
            return 1;
911
        }
912

    
913
        return dif;
914
    }
915

    
916
    /**
917
     * Rellena un rect?ngulo.
918
     *
919
     * @param g Graphics sobre el que dibujar.
920
     * @param r Rect?ngulo a rellenar.
921
     */
922
    private void fillRect(Graphics2D g, Rectangle2D.Double r) {
923
        g.fillRect((int) r.x, (int) r.y, (int) r.width, (int) r.height);
924
    }
925

    
926
    /**
927
     * Escribe sobre el Graphics y en la posici?n indicada el tama?o del
928
     * intervalo.
929
     *
930
     * @param g Graphics sobre el que dibujar.
931
     * @param inter Valor del intervalo.
932
     * @param p Punto donde dibujarlo.
933
     */
934
    private void drawInterval(Graphics2D g, String inter, Point2D.Double p) {
935
        //Double l = new Double(inter);
936
        g.setColor(textcolor);
937
        g.drawString(inter, (int) p.x, (int) p.y);
938
        g.setColor(barcolor);
939
    }
940

    
941
    /**
942
     * DOCUMENT ME!
943
     *
944
     * @return DOCUMENT ME!
945
     *
946
     * @throws SaveException
947
     *
948
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getXMLEntity()
949
     */
950
    public XMLEntity getXMLEntity() throws SaveException {
951
        XMLEntity xml = super.getXMLEntity();
952

    
953
        try {
954
//            xml.putProperty("type", Layout.RECTANGLESCALEBAR);
955
            xml.putProperty("m_bIntervalSet", m_bIntervalSet);
956
            xml.putProperty("m_dif", m_dif);
957
            xml.putProperty("m_hasleft", m_hasleft);
958
            xml.putProperty("m_nameUnit", m_nameUnit);
959
            xml.putProperty("m_numUnit", m_numUnit);
960

    
961
            xml.putProperty("m_height", m_height);
962

    
963
            xml.putProperty("m_style", m_style);
964
            xml.putProperty("m_units", m_units);
965
            xml.putProperty("m_interval", m_interval);
966
            xml.putProperty("m_numinterval", m_numinterval);
967
            xml.putProperty("m_numleft", m_numleft);
968
            xml.putProperty("m_mapUnits", m_mapUnits);
969
            xml.putProperty("fontName", m_f.getFontName());
970
            xml.putProperty("fontStyle", m_f.getStyle());
971
            xml.putProperty("numDec", numDec);
972
            xml.putProperty("m_units", m_units);
973

    
974
            if (fframeview != null) {
975
                Layout layout = fframeview.getLayout();
976
                IFFrame[] fframes = layout.getLayoutContext().getAllFFrames();
977

    
978
                for (int i = 0; i < fframes.length; i++) {
979
                    if (fframeview.getName().equals(fframes[i].getName())) {
980
                        xml.putProperty("index", i);
981
                    }
982
                }
983
            }
984

    
985
            xml.putProperty("barcolor", StringUtilities.color2String(barcolor));
986
            xml.putProperty("textcolor", StringUtilities.color2String(textcolor));
987
            xml.putProperty("showNameUnits", showNameUnits);
988
            xml.putProperty("showDescription", showDescription);
989
            xml.putProperty("aboveName", aboveName);
990
            xml.putProperty("aboveIntervals", aboveIntervals);
991
            xml.putProperty("aboveDescription", aboveDescription);
992
        } catch (Exception e) {
993
            throw new SaveException(e, this.getClass().getName());
994
        }
995

    
996
        return xml;
997
    }
998

    
999
    /**
1000
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
1001
     *      com.iver.cit.gvsig.project.Project)
1002
     */
1003
    public void setXMLEntity03(XMLEntity xml, Layout l) {
1004
        if (xml.getIntProperty("m_Selected") != 0) {
1005
            this.setSelected(true);
1006
        } else {
1007
            this.setSelected(false);
1008
        }
1009

    
1010
        this.m_bIntervalSet = xml.getBooleanProperty("m_bIntervalSet");
1011
        this.m_dif = xml.getDoubleProperty("m_dif");
1012
        this.m_hasleft = xml.getIntProperty("m_hasleft");
1013
        this.m_nameUnit = xml.getStringProperty("m_nameUnit");
1014
        this.m_numUnit = xml.getDoubleProperty("m_numUnit");
1015

    
1016
        this.m_height = xml.getDoubleProperty("m_height");
1017

    
1018
        this.m_style = xml.getIntProperty("m_style");
1019
        this.m_interval = xml.getLongProperty("m_interval");
1020
        this.m_numinterval = xml.getIntProperty("m_numinterval");
1021
        this.m_numleft = xml.getIntProperty("m_numleft");
1022
        this.m_mapUnits = xml.getIntProperty("m_mapUnits");
1023
        this.m_f = new Font(xml.getStringProperty("fontName"),
1024
                xml.getIntProperty("fontStyle"), 9);
1025

    
1026
        fframeview = (FFrameView) l.getLayoutContext().getFFrame(xml.getIntProperty("index"));
1027

    
1028
        if (xml.contains("description")) { //Comprobar que es de la versi?n que cambia el di?logo.
1029
            this.barcolor = StringUtilities.string2Color(xml.getStringProperty(
1030
                        "barcolor"));
1031
            this.textcolor = StringUtilities.string2Color(xml.getStringProperty(
1032
                        "textcolor"));
1033
            this.showNameUnits = xml.getBooleanProperty("showNameUnits");
1034
            this.showDescription = xml.getBooleanProperty("showDescription");
1035
            this.aboveName = xml.getBooleanProperty("aboveName");
1036
            this.aboveIntervals = xml.getBooleanProperty("aboveIntervals");
1037
            this.aboveDescription = xml.getBooleanProperty("aboveDescription");
1038
        }
1039
    }
1040

    
1041
    /**
1042
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
1043
     *      com.iver.cit.gvsig.project.Project)
1044
     */
1045
    public void setXMLEntity(XMLEntity xml) {
1046
        if (xml.getIntProperty("m_Selected") != 0) {
1047
            this.setSelected(true);
1048
        } else {
1049
            this.setSelected(false);
1050
        }
1051

    
1052
        this.m_bIntervalSet = xml.getBooleanProperty("m_bIntervalSet");
1053
        this.m_dif = xml.getDoubleProperty("m_dif");
1054
        this.m_hasleft = xml.getIntProperty("m_hasleft");
1055
        this.m_nameUnit = xml.getStringProperty("m_nameUnit");
1056
        this.m_numUnit = xml.getDoubleProperty("m_numUnit");
1057

    
1058
        this.m_height = xml.getDoubleProperty("m_height");
1059

    
1060
        this.m_style = xml.getIntProperty("m_style");
1061
        this.m_interval = xml.getDoubleProperty("m_interval");
1062
        this.m_numinterval = xml.getIntProperty("m_numinterval");
1063
        this.m_numleft = xml.getIntProperty("m_numleft");
1064
        this.m_mapUnits = xml.getIntProperty("m_mapUnits");
1065
        this.m_f = new Font(xml.getStringProperty("fontName"),
1066
                xml.getIntProperty("fontStyle"), 9);
1067
        setRotation(xml.getDoubleProperty("m_rotation"));
1068

    
1069
        if (xml.contains("m_units")) { //Comprobaci?n por versi?n 0.5
1070
            setUnits(xml.getIntProperty("m_units"));
1071
        }
1072

    
1073
        if (xml.contains("index")) {
1074
            dependenceIndex = xml.getIntProperty("index");
1075
        }
1076

    
1077

    
1078
        if (xml.contains("showDescription")) { //Comprobar que es de la versi?n que cambia el di?logo.
1079
            this.barcolor = StringUtilities.string2Color(xml.getStringProperty(
1080
            "barcolor"));
1081

    
1082
            this.textcolor = StringUtilities.string2Color(xml.getStringProperty(
1083
                        "textcolor"));
1084
            this.showNameUnits = xml.getBooleanProperty("showNameUnits");
1085
            this.showDescription = xml.getBooleanProperty("showDescription");
1086
            this.aboveName = xml.getBooleanProperty("aboveName");
1087
            this.aboveIntervals = xml.getBooleanProperty("aboveIntervals");
1088
            this.aboveDescription = xml.getBooleanProperty("aboveDescription");
1089
        }
1090

    
1091
        if (xml.contains("numDec")) {
1092
            setNumDec(xml.getIntProperty("numDec"));
1093
        }
1094
    }
1095

    
1096
    /**
1097
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getNameFFrame()
1098
     */
1099
    public String getNameFFrame() {
1100
        return PluginServices.getText(this, "escala")+ num;
1101
    }
1102

    
1103
    /**
1104
     * Inserta el color de la escala gr?fica.
1105
     *
1106
     * @param color Color de la escala gr?fica.
1107
     */
1108
    public void setBarColor(Color color) {
1109
        barcolor = color;
1110
    }
1111

    
1112
    /**
1113
     * Inserta el color del texto.
1114
     *
1115
     * @param color Color del texto.
1116
     */
1117
    public void setTextColor(Color color) {
1118
        textcolor = color;
1119
    }
1120

    
1121
    /**
1122
     * Devuelve el color de la escala gr?fica.
1123
     *
1124
     * @return Color de la escala gr?fica.
1125
     */
1126
    public Color getBarColor() {
1127
        return barcolor;
1128
    }
1129

    
1130
    /**
1131
     * Devuelve el color del texto.
1132
     *
1133
     * @return Color del texto.
1134
     */
1135
    public Color getTextColor() {
1136
        return textcolor;
1137
    }
1138

    
1139
    /**
1140
     * Devuelve true si se debe mostrar el nombre de las unidades de medida de
1141
     * la escala gr?fica.
1142
     *
1143
     * @return True si se muestra las unidades de medida.
1144
     */
1145
    public boolean isShowNameUnits() {
1146
        return showNameUnits;
1147
    }
1148

    
1149
    /**
1150
     * Inserta si se debe de mostrar el nombre de las unidades de medida o no.
1151
     *
1152
     * @param showNameUnits True si se muestra el nombre de las unidades de
1153
     *        medida.
1154
     */
1155
    public void setShowNameUnits(boolean showNameUnits) {
1156
        this.showNameUnits = showNameUnits;
1157
    }
1158

    
1159
    /**
1160
     * Devuelve true si se muestra la descripci?n a la parte de arriba de la
1161
     * escala gr?fica.
1162
     *
1163
     * @return True si se muestra arriba de la escala gr?fica.
1164
     */
1165
    public boolean isAboveDescription() {
1166
        return aboveDescription;
1167
    }
1168

    
1169
    /**
1170
     * Introduce true si se muestra arriba de la escala gr?fica la descripci?n.
1171
     *
1172
     * @param aboveDescription True si se muestra arriba la descripci?n.
1173
     */
1174
    public void setAboveDescription(boolean aboveDescription) {
1175
        this.aboveDescription = aboveDescription;
1176
    }
1177

    
1178
    /**
1179
     * Devuelve true si se muestran a la parte de arriba los valores de los
1180
     * intervalos.
1181
     *
1182
     * @return True si se muestran arriba de la escala gr?fica.
1183
     */
1184
    public boolean isAboveIntervals() {
1185
        return aboveIntervals;
1186
    }
1187

    
1188
    /**
1189
     * Inserta si se muestran los valores de los intervalos a la parte de
1190
     * arriba de la escala o debajo.
1191
     *
1192
     * @param aboveIntervals True si se muestran los valores de los intervalos
1193
     *        a la parte de arriba de la escala gr?fica.
1194
     */
1195
    public void setAboveIntervals(boolean aboveIntervals) {
1196
        this.aboveIntervals = aboveIntervals;
1197
    }
1198

    
1199
    /**
1200
     * Devuelve si se muestra a la parte de arriba de la escala gr?fica el
1201
     * nombre de las unidades de medida o debajo.
1202
     *
1203
     * @return True si se muestra a la parte de arriba de la escala gr?fica.
1204
     */
1205
    public boolean isAboveName() {
1206
        return aboveName;
1207
    }
1208

    
1209
    /**
1210
     * Inserta si el nombre se muestra a la parte de arriba de la escala
1211
     * gr?fica o a la parte de abajo.
1212
     *
1213
     * @param aboveName True si se muestra a la parte de arriba de la escala
1214
     *        gr?fica.
1215
     */
1216
    public void setAboveName(boolean aboveName) {
1217
        this.aboveName = aboveName;
1218
    }
1219

    
1220
    /**
1221
     * Devuelve si se debe mostrar la descripci?n o no.
1222
     *
1223
     * @return True si se muestra la descripci?n.
1224
     */
1225
    public boolean isShowDescription() {
1226
        return showDescription;
1227
    }
1228

    
1229
    /**
1230
     * Inserta si se muestra o no la descripci?n.
1231
     *
1232
     * @param showDescription True si se muestra la descripci?n.
1233
     */
1234
    public void setShowDescription(boolean showDescription) {
1235
        this.showDescription = showDescription;
1236
    }
1237

    
1238
    /**
1239
     * Devuelve la descripci?n de la escala.
1240
     *
1241
     * @return Descripci?n de la escala.
1242
     */
1243
    public String getDescription() {
1244
        if (fframeview!=null){
1245
                if (fframeview.getScale()==0){
1246
                        return PluginServices.getText(this,"escala_desconocida");
1247
                }
1248
            return "1:" + String.valueOf(fframeview.getScale());
1249
        }
1250
            return "1:";
1251
    }
1252

    
1253
    /**
1254
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#print(java.awt.Graphics2D,
1255
     *      java.awt.geom.AffineTransform)
1256
     */
1257
    public void print(Graphics2D g, AffineTransform at)
1258
        throws DriverException {
1259
        draw(g, at, null, null);
1260
    }
1261

    
1262
    /**
1263
     * Update the dependences that have this FFrame with the other FFrame.
1264
     *
1265
     * @param fframes Other FFrames.
1266
     */
1267
    public void initDependence(IFFrame[] fframes) {
1268
        if ((dependenceIndex != -1) &&
1269
                fframes[dependenceIndex] instanceof FFrameView) {
1270
            fframeview = (FFrameView) fframes[dependenceIndex];
1271
        }
1272
    }
1273

    
1274
    /**
1275
     * DOCUMENT ME!
1276
     *
1277
     * @param d DOCUMENT ME!
1278
     *
1279
     * @return DOCUMENT ME!
1280
     */
1281
    public String format(double d) {
1282
        if ((d % (long) d) != 0) {
1283
            numberFormat.setMaximumFractionDigits(getNumDec());
1284
        } else {
1285
            numberFormat.setMaximumFractionDigits(0);
1286
        }
1287

    
1288
        //String s = String.valueOf(nf.format(d));
1289
        //s=s.replace('.','*');
1290
        //s = s.replace(',', '.');
1291
        //s=s.replace('*',',');
1292
        return numberFormat.format(d); //(Double.valueOf(s).doubleValue());
1293
    }
1294

    
1295
    /**
1296
     * DOCUMENT ME!
1297
     *
1298
     * @return DOCUMENT ME!
1299
     */
1300
    public int getNumDec() {
1301
        return numDec;
1302
    }
1303

    
1304
    /**
1305
     * DOCUMENT ME!
1306
     *
1307
     * @param numDec DOCUMENT ME!
1308
     */
1309
    public void setNumDec(int numDec) {
1310
        this.numDec = numDec;
1311
    }
1312

    
1313
    public void initialize() {
1314
        // TODO Auto-generated method stub
1315

    
1316
    }
1317
    private final static int DUIB=0;
1318
    private final static int DUBI=1;
1319
    private final static int DBIU=2;
1320
    private final static int DIBU=3;
1321
    private final static int UIBD=4;
1322
    private final static int UBID=5;
1323
    private final static int IBUD=6;
1324
    private final static int BIUD=7;
1325

    
1326
    private int getFormat(){
1327
        if (isAboveDescription()){
1328
            if (isAboveName()){
1329
                if (isAboveIntervals()){
1330
                    return DUIB;
1331
                }
1332
                return DUBI;
1333
            }
1334
            if (isAboveIntervals()){
1335
                    return DIBU;
1336
                }
1337
                return DBIU;
1338
        }
1339
        if (isAboveName()){
1340
            if (isAboveIntervals()){
1341
                return UIBD;
1342
            }
1343
            return UBID;
1344
        }
1345
        if (isAboveIntervals()){
1346
            return IBUD;
1347
        }
1348
        return BIUD;
1349
    }
1350

    
1351
        public void cloneActions(IFFrame frame) {
1352
                // TODO Auto-generated method stub
1353

    
1354
        }
1355

    
1356
        public IFFrameDialog getPropertyDialog() {
1357
                return new FFrameScaleBarDialog(getLayout(),this);
1358
        }
1359
}