Statistics
| Revision:

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

History | View | Annotate | Download (45 KB)

1 9392 caballero
/*
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 10911 jaume
import javax.print.attribute.PrintRequestAttributeSet;
60
61 10626 caballero
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
62 9392 caballero
import com.iver.andami.PluginServices;
63
import com.iver.cit.gvsig.fmap.MapContext;
64 9593 caballero
import com.iver.cit.gvsig.fmap.core.FShape;
65 9392 caballero
import com.iver.cit.gvsig.project.documents.exceptions.SaveException;
66
import com.iver.cit.gvsig.project.documents.layout.Attributes;
67
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities;
68
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameScaleBarDialog;
69
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.IFFrameDialog;
70
import com.iver.cit.gvsig.project.documents.layout.gui.Layout;
71
import com.iver.utiles.StringUtilities;
72
import com.iver.utiles.XMLEntity;
73
74
75
76
/**
77
 * FFrame para introducir una barra de escala en el Layout.
78
 *
79
 * @author Vicente Caballero Navarro
80
 */
81
public class FFrameScaleBar extends FFrame implements IFFrameViewDependence {
82
    private static final int NUMERO = 0;
83
    private static final int BARRA1 = 1;
84
    private static final int BARRA2 = 2;
85
    private static final int BARRA3 = 3;
86
    private static final int BARRA4 = 4;
87
    private double DIFDOWN = 1.5;
88
    private double DIFL = 30;
89
    private double DIFR = 30;
90
    private double DIFUP = 10;
91
    private boolean m_bIntervalSet = false;
92
    private int m_style = NUMERO;
93
    private int m_units = 1; //Metros
94
    private int m_mapUnits = 1; //unidad de medida de la vista(Metros)
95
    private double m_interval = 1;
96
    private int m_numinterval = 3;
97
    private int m_numleft = 2;
98
    private double m_height = 0;
99
    private FFrameView fframeview = null;
100
    private double m_typeUnit = Attributes.CHANGE[1]; //METROS;
101
    private String m_nameUnit = null;
102
    private double m_numUnit = 0;
103
    private double m_dif = 1;
104
    private int m_hasleft = 0;
105
    private Font m_f = new Font("SansSerif", Font.PLAIN, 9);
106
    private Color barcolor = Color.black;
107
    private Color textcolor = Color.black;
108
    private boolean showNameUnits = true;
109
    private boolean showDescription = false;
110
    private boolean aboveName = false;
111
    private boolean aboveIntervals = true;
112
    private boolean aboveDescription = false;
113
    private int dependenceIndex = -1;
114
    private int numDec = 0;
115
    public static NumberFormat numberFormat = NumberFormat.getInstance();
116
117
    /**
118
     * Creates a new FFrameScaleBar object.
119
     */
120
    public FFrameScaleBar() {
121
    }
122
123
    /**
124
     * Inserta el FFrameView sobre el que obtener la escala gr?fica.
125
     *
126
     * @param f FFrameView sobre  el que obtener la escala.
127
     */
128
    public void setFFrameDependence(IFFrame f) {
129
        fframeview = (FFrameView) f;
130
        if (fframeview==null)
131
                return;
132
        setMapUnits(fframeview.getMapUnits());
133
        setHeight(f.getBoundBox().height);
134
    }
135
136
    /**
137
     * Devuelve el FFrameView que se representa con la escala.
138
     *
139
     * @return FFrameView a representar.
140
     */
141
    public IFFrame getFFrameDependence() {
142
        return fframeview;
143
    }
144
145
    /**
146
     * Devuelve el FMap de la vista que se representa en la escala.
147
     *
148
     * @return FMap.
149
     */
150
    public MapContext getFMap() {
151
        return fframeview.getMapContext();
152
    }
153
154
    /**
155
     * Rellenar el estilo de barra de escala que se elige.
156
     *
157
     * @param s entero que representa el tipo de barra seleccionada.
158
     */
159
    public void setStyle(int s) {
160
        m_style = s;
161
    }
162
163
    /**
164
     * Devuelve el tipo de escala a dibujar.
165
     *
166
     * @return entero.
167
     */
168
    public int getStyle() {
169
        return m_style;
170
    }
171
172
    /**
173
     * Rellenar el tama?o de un intervalo.
174
     *
175
     * @param s tama?o de un intervalo.
176
     */
177
    public void setInterval(double s) {
178
        m_interval = s;
179
180
        if (m_numleft != 0) {
181
            m_hasleft = 1;
182
        }
183
184
        Rectangle2D.Double rect = getBoundBox();
185
        double difL = (rect.width / DIFL);
186
        double difR = (rect.width / DIFR);
187
        double n = (rect.width - difL - difR);
188
        m_numUnit = (m_interval * m_typeUnit) / getScaleView();
189
        m_numinterval = (int) (n / m_numUnit) - m_hasleft;
190
        m_dif = 1;
191
    }
192
193
    /**
194
     * Devuelve el valor del intervalo.
195
     *
196
     * @return long.
197
     */
198
    public String obtainInterval() {
199
        if (fframeview != null) {
200
            Rectangle2D.Double rect = getBoundBox();
201
202
            if (m_numleft != 0) {
203
                m_hasleft = 1;
204
            }
205
206
            double difL = (rect.width / DIFL);
207
            double difR = (rect.width / DIFR);
208
            double n = (rect.width - difL - difR);
209
            m_numUnit = n / (m_numinterval + m_hasleft);
210
211
            double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
212
            m_dif = getExact(scaleXunit);
213
            m_numUnit = m_numUnit * m_dif;
214
            m_interval = scaleXunit;
215
216
            ///m_interval = (scaleXunit * m_dif);
217
            return format(m_interval);
218
        }
219
220
        return "0";
221
    }
222
223
    /**
224
     * Rellenar el n?mero de intervalos.
225
     *
226
     * @param s n?mero de intervalos.
227
     */
228
    public void setNumInterval(int s) {
229
        m_numinterval = s;
230
231
        if (m_numleft != 0) {
232
            m_hasleft = 1;
233
        }
234
235
        Rectangle2D.Double rect = getBoundBox();
236
        double difL = (rect.width / DIFL);
237
        double difR = (rect.width / DIFR);
238
        double n = (rect.width - difL - difR);
239
        m_numUnit = n / (m_numinterval + m_hasleft);
240
241
        double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
242
        m_dif = getExact(scaleXunit);
243
        m_numUnit = m_numUnit * m_dif;
244
        m_interval = (scaleXunit * m_dif);
245
    }
246
247
    /**
248
     * Devuelve el n?mero de intervalos por encima del cero.
249
     *
250
     * @return entero.
251
     */
252
    public int getNumInterval() {
253
        return m_numinterval;
254
    }
255
256
    /**
257
     * Rellenar el n?mero de intervalos a la izquierda del cero.
258
     *
259
     * @param s n?mero de intervalos a la izquierda.
260
     */
261
    public void setNumLeft(int s) {
262
        m_numleft = s;
263 10504 caballero
        if (m_numleft != 0) {
264
            m_hasleft = 1;
265
        }else{
266
                m_hasleft=0;
267
        }
268 9392 caballero
    }
269
270
    /**
271
     * Devuelve el n?mero de intervalos  en los que se quiere particionar el
272
     * intervalo  que se queda por debajo del cero.
273
     *
274
     * @return entero.
275
     */
276
    public int getNumLeft() {
277
        return m_numleft;
278
    }
279
280
    /**
281
     * Seleccionar ,a true, si se quiere o, a false, si no mantener los
282
     * intervalos.
283
     *
284
     * @param b boolean a true si se quiere mantener los intervalos.
285
     */
286
    public void setIntervalSet(boolean b) {
287
        m_bIntervalSet = b;
288
    }
289
290
    /**
291
     * Seleccionar la unidad de medida a representar en la barra de escala.
292
     *
293
     * @param s entero que representa la unidad de medida que se selecciona.
294
     */
295
    public void setUnits(int s) {
296
        m_units = s;
297
        m_typeUnit = Attributes.CHANGE[s];
298 11548 jaume
        m_nameUnit = PluginServices.getText(this,MapContext.NAMES[s]);
299 9392 caballero
    }
300
301
    /**
302
     * Devuelve un entero que representa el tipo de unidades que representamos.
303
     *
304
     * @return entero.
305
     */
306
    public int getUnits() {
307
        return m_units;
308
    }
309
310
    /**
311
     * Devuelve el long que representa el intervalo.
312
     *
313
     * @return Intervalo.
314
     */
315
    public String getInterval() {
316
        return format(m_interval);
317
    }
318
319
    /**
320
     * Rellenar el rect?ngulo de la vista sobre la que se obtiene la escala.
321
     *
322
     * @param d Rect?ngulo.
323
     */
324
    public void setHeight(double d) {
325
        m_height = d;
326
    }
327
328
    /**
329
     * Rellena la unidad de medida en la que est? la vista.
330
     *
331
     * @param i entero que representa la unidad de medida de la vista.
332
     */
333
    public void setMapUnits(int i) {
334
        m_mapUnits = i;
335
    }
336
337
    /**
338
     * Devuelve la escala de la vista seleccionada.
339
     *
340
     * @return la escala de la vista.
341
     */
342
    private long getScaleView() {
343
        if (fframeview == null) {
344
            return 1;
345
        }
346
347
        return fframeview.getScale();
348
    }
349
350
    /**
351
     * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
352
     * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
353
     * de dibujar.
354
     *
355
     * @param g Graphics
356
     * @param at Transformada afin.
357
     * @param rv rect?ngulo sobre el que hacer un clip.
358
     * @param imgBase Image para acelerar el dibujado.
359
     */
360
    public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,
361 10626 caballero
        BufferedImage imgBase) throws ReadDriverException {
362 9392 caballero
        Rectangle2D.Double r = getBoundingBox(at);
363
        g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2),
364
            r.y + (r.height / 2));
365
366
        if (intersects(rv, r)) {
367
            if ((fframeview == null) || (fframeview.getMapContext() == null)) {
368
                drawEmpty(g);
369
            } else {
370
                switch (m_style) {
371
                    case (NUMERO):
372
373
                        double scalex = r.getWidth() / (8);
374
375
                        if (scalex > (r.getHeight() / (8))) {
376
                            scalex = r.getHeight() / (2);
377
                        }
378
379
                        g.setColor(textcolor);
380
381
                        if (m_f != null) {
382
                            m_f = new Font(m_f.getFontName(), m_f.getStyle(),
383
                                    (int) (scalex));
384
                            g.setFont(m_f);
385
                        }
386
387
                        FontMetrics fm = g.getFontMetrics();
388
                        double d = r.getWidth();
389
                        long scl=getScaleView();
390
                        if (scl<1){
391
                            String unknowScale=PluginServices.getText(this,"escala_desconocida");
392
                            if (fm.stringWidth(unknowScale) > (d * 0.8)) {
393
                                double dif = fm.stringWidth(unknowScale) / (d * 0.8);
394
                                m_f = new Font(m_f.getName(), m_f.getStyle(),
395
                                        (int) (m_f.getSize() / dif));
396
                                g.setFont(m_f);
397
                            }
398
                               g.drawString(unknowScale, (int) r.x,
399
                                    (int) (r.y + (r.height / 2)));
400
                               return;
401
                        }
402
                        String scale = " 1:" + scl;
403
404
                        if (fm.stringWidth(String.valueOf(m_interval)) > (d * 0.8)) {
405
                            double dif = fm.stringWidth(String.valueOf(
406
                                        m_interval)) / (d * 0.8);
407
                            m_f = new Font(m_f.getName(), m_f.getStyle(),
408
                                    (int) (m_f.getSize() / dif));
409
                            g.setFont(m_f);
410
                        }
411
412
                        g.drawString(scale, (int) r.x,
413
                            (int) (r.y + (r.height / 2)));
414
415
                        break;
416
417
                    case (BARRA1):
418
                    case (BARRA2):
419
                    case (BARRA3):
420
                    case (BARRA4):
421
                        drawBar(m_style, g, at);
422
423
                        break;
424
                }
425
            }
426
        }
427
428
        g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2),
429
            r.y + (r.height / 2));
430
    }
431
432
    /**
433
     * Rellena con el rect?ngulo que se pasa como par?metro el boundBox(en
434
     * cent?metros) del fframe del cual con una transformaci?n se podr?
435
     * calcular el BoundingBox (en pixels).
436
     *
437
     * @param r Rect?ngulo en cent?metros.
438
     */
439
    public void setBoundBox(Rectangle2D.Double r) {
440
        if ((m_numUnit < 1) || (fframeview == null) ||
441
                (fframeview.getMapContext() == null)) {
442
            super.setBoundBox(r);
443
444
            return;
445
        }
446
447
        double difL = (r.width / DIFL);
448
        double difR = (r.width / DIFR);
449
450
        if (m_bIntervalSet) {
451
            m_numinterval = (int) (((r.width - (difL + difR)) * m_dif) / m_numUnit) -
452
                m_hasleft;
453
        }
454
455
        if (m_numinterval < 1) {
456
            m_numinterval = 1;
457
            r.width = ((m_numinterval + m_hasleft) * m_numUnit) + difL + difR;
458
        }
459
460
        getBoundBox().setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
461
    }
462
463
    /**
464
     * Dibuja sobre el Graphics la escala gr?fica.
465
     *
466
     * @param type Tipo de barra.
467
     * @param g Graphics sobre el que dibujar.
468
     * @param at Matriz de transformaci?n.
469
     */
470
    private void drawBar(int type, Graphics2D g, AffineTransform at) {
471
        Rectangle2D.Double rect = getBoundBox();
472
        Rectangle2D.Double r = getBoundingBox(at);
473
        double numleft = m_numleft;
474
        initDistances();
475
        //drawOrder(g,r);
476
        double difDown = (rect.height / DIFDOWN);
477
        double difUp = (rect.height / DIFUP);
478
        double difL = (rect.width / DIFL);
479
        double difR = (rect.width / DIFR);
480
        double n = (rect.width - difL - difR);
481
482
        //setDescripcion("escala 1:" + String.valueOf(fframeview.getScale()));
483
        g.setStroke(new BasicStroke(0));
484
485
        if (!m_bIntervalSet) {
486
            m_numUnit = n / (m_numinterval + m_hasleft);
487
488
            double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
489
            m_dif = getExact(scaleXunit);
490
            m_numUnit = m_numUnit * m_dif;
491
            m_interval = (scaleXunit * m_dif);
492
        }
493
494
        if (m_bIntervalSet) {
495
            m_numUnit = (m_interval * m_typeUnit) / (m_dif * getScaleView());
496
            m_numinterval = (int) (((rect.width - (difL + difR)) * m_dif) / m_numUnit) -
497
                m_hasleft;
498
        }
499
500
        if (m_numinterval < 1) {
501
            m_numinterval = 1;
502
            rect.width = ((m_numinterval + m_hasleft) * m_numUnit) + difL +
503
                difR;
504
        }
505
506
        double h = 0;
507
508
        if (type == BARRA1) {
509
            h = (rect.height - (difUp + difDown));
510
        } else if ((type == BARRA2) || (type == BARRA3)) {
511
            h = (rect.height - (difUp + difDown)) / 2;
512
        }
513
514
        //Dibujar el rect?ngulo que bordea todo.
515
        Rectangle2D.Double rectotal = (FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
516
                    difL), (rect.y + difUp),
517
                    m_numUnit * (m_hasleft + m_numinterval), h), at));
518
        g.setColor(barcolor);
519
        g.fillRect((int) rectotal.x, (int) rectotal.y, (int) (rectotal.width),
520
            (int) rectotal.height);
521
        g.setColor(Color.white);
522
        g.fillRect((int) rectotal.x+1, (int) rectotal.y+1, (int) (rectotal.width-2),
523
                (int) rectotal.height-2);
524
        g.setColor(barcolor);
525
526
        if (m_f != null) {
527
            m_f = new Font(m_f.getFontName(), m_f.getStyle(),
528
                    (int) (r.getHeight() / 4));
529
        } else {
530
            m_f = new Font("SansSerif", Font.PLAIN, (int) (r.getHeight() / 4));
531
        }
532
533
        g.setFont(m_f);
534
        Double interval=new Double(m_interval);
535
        if (interval.isNaN()) {
536
            String unknowScale=PluginServices.getText(this,"escala_desconocida");
537
            FontMetrics fm = g.getFontMetrics();
538
             double d = r.getWidth();
539
            if (fm.stringWidth(unknowScale) > (d * 0.8)) {
540
                double dif = fm.stringWidth(unknowScale) / (d * 0.8);
541
                m_f = new Font(m_f.getName(), m_f.getStyle(),
542
                        (int) (m_f.getSize() / dif));
543
                g.setFont(m_f);
544
            }
545
               g.drawString(unknowScale, (int) r.x,
546
                    (int) (r.y + (r.height / 2)));
547
               return;
548
        }
549
550
        FontMetrics fm = g.getFontMetrics();
551
        String formatInterval = format(m_interval);
552
        double d = (rectotal.getWidth() / m_numinterval) + m_hasleft;
553
        double difpos = ((r.getHeight() / 4) * formatInterval.length()) / 4;
554
555
        if (fm.stringWidth(formatInterval) > (d * 0.7)) {
556
            double dif = fm.stringWidth(formatInterval) / (d * 0.7);
557
            difpos = (d * 0.7) / 2;
558
            m_f = new Font(m_f.getName(), m_f.getStyle(),
559
                    (int) (m_f.getSize() / dif));
560
            g.setFont(m_f);
561
        }
562
563
        //Derecha del cero
564
        for (int i = 0; i < m_numinterval; i++) {
565
            Rectangle2D.Double recder = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
566
                        (difL) + ((m_numUnit * i) + (m_hasleft * m_numUnit))),
567
                        (rect.y + (difUp)), (m_numUnit),
568
                        (rect.height - (difUp + difDown)) / 2), at);
569
            Rectangle2D.Double recderB = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
570
                        (difL) + ((m_numUnit * i) + (m_hasleft * m_numUnit))),
571
                        (rect.y + difUp) +
572
                        ((rect.height - (difUp + difDown)) / 2), (m_numUnit),
573
                        ((rect.height - (difUp + difDown)) / 2)), at);
574
575
            //                        Correcci?n cuando la altura en pixels del rect?ngulo es impar.
576
            rectotal.y = recder.y;
577
            recderB.height = rectotal.height - recder.height + 0.5;
578
579
            /**
580
             * if (i == (m_numinterval - 1)) { if (recder.getMaxX() !=
581
             * rectotal.getMaxX()) { recder.width = (recder.width +
582
             * recder.getMaxX()) - rectotal.getMaxX(); } if (recderB.getMaxX()
583
             * != rectotal.getMaxX()) { recderB.width = (recderB.width +
584
             * recderB.getMaxX()) - rectotal.getMaxX(); }} if
585
             * (recderB.getMaxY() != rectotal.getMaxY()) { recderB.height =
586
             * (recderB.height + recderB.getMaxY()) - rectotal.getMaxY(); }
587
             */
588
            if ((m_numleft % 2) == 0) {
589
                if ((i % 2) == 0) {
590
                    if ((type == BARRA1) || (type == BARRA2)) {
591
                        fillRect(g, recder);
592
                    } else if (type == BARRA3) {
593
                        g.drawRect((int) recder.x, (int) recder.y,
594
                            (int) recder.width, (int) recder.height);
595
                    }
596
                } else if (type == BARRA1) {
597
                    fillRect(g, recderB);
598
                }
599
            } else {
600
                if ((i % 2) != 0) {
601
                    if ((type == BARRA1) || (type == BARRA2)) {
602
                        fillRect(g, recder);
603
                    } else if (type == BARRA3) {
604
                        g.drawRect((int) recderB.x, (int) recderB.y,
605
                            (int) recderB.width, (int) recderB.height);
606
                    }
607
                } else if (type == BARRA1) {
608
                    fillRect(g, recderB);
609
                }
610
            }
611
612
            String interString = format(m_interval * i);
613
            Point2D.Double p = null;
614
615
            if (isAboveIntervals()) {
616
                p = new Point2D.Double(recder.x - difpos,
617
                        r.getMinY() + (r.getHeight() / DIFUP));
618
            } else {
619
                p = new Point2D.Double(recder.x - difpos,
620
                        ((r.getHeight() / 4) + r.getMaxY()) -
621
                        (r.getHeight() / DIFDOWN));
622
            }
623
624
            //Para dibujar el 0 centrado en su sitio.
625
            if (i == 0) {
626
                double dif0 = recder.x - (fm.stringWidth(interString) / 2);
627
                p = new Point2D.Double(dif0, p.getY());
628
            }
629
630
            drawInterval(g, interString, p);
631
        }
632
633
        //?ltimo n?mero a dibujar.
634
        String interString = format(m_interval * m_numinterval);
635
636
        Point2D.Double p = null;
637
638
        if (isAboveIntervals()) {
639
            p = new Point2D.Double(rectotal.getMaxX() - difpos,
640
                    r.getMinY() + (r.getHeight() / DIFUP));
641
        } else {
642
            p = new Point2D.Double(rectotal.getMaxX() - difpos,
643
                    ((r.getHeight() / 4) + r.getMaxY()) -
644
                    (r.getHeight() / DIFDOWN));
645
        }
646
647
        drawInterval(g, interString, p);
648
649
        //Izquierda del cero
650
        for (int i = 0; i < m_numleft; i++) {
651
            Rectangle2D.Double reciz = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
652
                        difL + ((m_numUnit / m_numleft) * i)),
653
                        (rect.y + difUp), (m_numUnit / numleft),
654
                        (rect.height - (difUp + difDown)) / 2), at);
655
            Rectangle2D.Double recizB = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
656
                        difL + ((m_numUnit / m_numleft) * i)),
657
                        (rect.y + difUp) +
658
                        ((rect.height - (difUp + difDown)) / 2),
659
                        (m_numUnit / numleft),
660
                        ((rect.height - (difUp + difDown)) / 2)), at);
661
662
            //Correcci?n cuando la altura en pixels del rectangulo es impar.
663
            reciz.y = rectotal.y;
664
            recizB.height = rectotal.height - reciz.height + 0.5;
665
666
            if ((i % 2) == 0) {
667
                if ((type == BARRA1) || (type == BARRA2)) {
668
                    fillRect(g, reciz);
669
                } else if (type == BARRA3) {
670
                    g.drawRect((int) reciz.x, (int) reciz.y, (int) reciz.width,
671
                        (int) reciz.height);
672
                }
673
            } else if (type == BARRA1) {
674
                fillRect(g, recizB);
675
            }
676
        }
677
678
        if (m_numleft > 0) {
679
            interString = format(m_interval);
680
681
            if (isAboveIntervals()) {
682
                p = new Point2D.Double(rectotal.x - difpos,
683
                        r.getMinY() + (r.getHeight() / DIFUP));
684
            } else {
685
                p = new Point2D.Double(rectotal.x - difpos,
686
                        ((r.getHeight() / 4) + r.getMaxY()) -
687
                        (r.getHeight() / DIFDOWN));
688
            }
689
690
            drawInterval(g, interString, p);
691
        }
692
693
        //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.
694
        if (m_numleft == 0) {
695
            Rectangle2D.Double recAux = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
696
                        difL + ((m_numUnit / 1) * 0)), (rect.y + difUp),
697
                        (m_numUnit / 1), (rect.height - (difUp + difDown)) / 2),
698
                    at);
699
            rectotal.x = rectotal.x + recAux.width;
700
            rectotal.width = rectotal.width - recAux.width;
701
        }
702
703
        //Se dibuja el rect?ngulo que bordea toda la escala gr?fica.
704
        g.drawRect((int) rectotal.x, (int) rectotal.y, (int) (rectotal.width),
705
            (int) rectotal.height);
706
707
        drawNameUnitsAndDescriptions(g, r);
708
        //drawDescription(g, r);
709
    }
710
711
    /**
712
     * Inicializa las distancias de la barra de escala.
713
     */
714
    private void initDistances() {
715
        int numUp = 0;
716
        int numDown = 0;
717
718
        DIFDOWN = 30;
719
        DIFL = 40;
720
        DIFR = 40;
721
        DIFUP = 30;
722
723
        if (isAboveName()) {
724
            numUp++;
725
        } else {
726
            numDown++;
727
        }
728
729
        if (isAboveIntervals()) {
730
            numUp++;
731
        } else {
732
            numDown++;
733
        }
734
735
        if (isAboveDescription()) {
736
            numUp++;
737
        } else {
738
            numDown++;
739
        }
740
741
        if (numDown == 1) {
742
            DIFDOWN = 3;
743
        } else if (numDown == 2) {
744
            DIFDOWN = 2;
745
        } else if (numDown == 3) {
746
            DIFDOWN = 1.2;
747
        }
748
749
        if (numUp == 1) {
750
            DIFUP = 3;
751
        } else if (numUp == 2) {
752
            DIFUP = 2;
753
        } else if (numUp == 3) {
754
            DIFUP = 1.2;
755
        }
756
    }
757
758
    /**
759
     * Dibuja sobre el Graphics el nombre de la unidad de medida de la escala y la descripci?n,
760
     * siendo por defecto la escala 1:.
761
     *
762
     * @param g Graphics sobre el que se dibuja.
763
     * @param rec Rect?ngulo que ocupa la escala gr?fica.
764
     */
765
    private void drawNameUnitsAndDescriptions(Graphics g, Rectangle2D.Double rec) {
766
        FontMetrics fm = g.getFontMetrics();
767
        Point2D.Double pD = null;
768
        Point2D.Double pU = null;
769
        g.setColor(textcolor);
770
               switch (getFormat()) {
771
               case DUIB:
772
                   pD = new Point2D.Double(rec.getCenterX() -
773
                        (fm.stringWidth(getDescription()) / 2),
774
                        (rec.getMinY() + (rec.getHeight() / 9) +
775
                        (fm.getHeight() / 2)));
776
                   pU = new Point2D.Double(rec.getCenterX() -
777
                           (fm.stringWidth(m_nameUnit) / 2),
778
                           (rec.getMinY() + (rec.getHeight() / 3) +
779
                           (fm.getHeight() / 2)));
780
781
                   break;
782
               case DUBI:
783
                   pD = new Point2D.Double(rec.getCenterX() -
784
                        (fm.stringWidth(getDescription()) / 2),
785
                        (rec.getMinY() + (rec.getHeight() / 9) +
786
                        (fm.getHeight() / 2)));
787
                   pU = new Point2D.Double(rec.getCenterX() -
788
                           (fm.stringWidth(m_nameUnit) / 2),
789
                           (rec.getMinY() + (rec.getHeight() / 3) +
790
                           (fm.getHeight() / 2)));
791
                   break;
792
               case DBIU:
793
                   pD = new Point2D.Double(rec.getCenterX() -
794
                        (fm.stringWidth(getDescription()) / 2),
795
                        (rec.getMinY() + (rec.getHeight() / 9) +
796
                        (fm.getHeight() / 2)));
797
                   pU = new Point2D.Double(rec.getCenterX() -
798
                            (fm.stringWidth(m_nameUnit) / 2),
799
                            (rec.getMaxY() - (rec.getHeight() / 9) +
800
                            (fm.getHeight() / 3)));
801
                   break;
802
               case DIBU:
803
                   pD = new Point2D.Double(rec.getCenterX() -
804
                        (fm.stringWidth(getDescription()) / 2),
805
                        (rec.getMinY() + (rec.getHeight() / 9) +
806
                        (fm.getHeight() / 2)));
807
                   pU = new Point2D.Double(rec.getCenterX() -
808
                            (fm.stringWidth(m_nameUnit) / 2),
809
                            (rec.getMaxY() - (rec.getHeight() / 9) +
810
                            (fm.getHeight() / 3)));
811
                   break;
812
               case UIBD:
813
                   pD = new Point2D.Double(rec.getCenterX() -
814
                            (fm.stringWidth(getDescription()) / 2),
815
                            (rec.getMaxY() - (rec.getHeight() / 9) +
816
                            (fm.getHeight() / 3)));
817
                   pU = new Point2D.Double(rec.getCenterX() -
818
                           (fm.stringWidth(m_nameUnit) / 2),
819
                           (rec.getMinY() + (rec.getHeight() / 9) +
820
                           (fm.getHeight() / 2)));
821
                   break;
822
               case UBID:
823
                   pD = new Point2D.Double(rec.getCenterX() -
824
                        (fm.stringWidth(getDescription()) / 2),
825
                        (rec.getMaxY() - (rec.getHeight() / 9) +
826
                        (fm.getHeight() / 3)));
827
                   pU = new Point2D.Double(rec.getCenterX() -
828
                           (fm.stringWidth(m_nameUnit) / 2),
829
                           (rec.getMinY() + (rec.getHeight() / 9) +
830
                           (fm.getHeight() / 2)));
831
                   break;
832
               case IBUD:
833
                   pD = new Point2D.Double(rec.getCenterX() -
834
                        (fm.stringWidth(getDescription()) / 2),
835
                        (rec.getMaxY() - (rec.getHeight() / 3) +
836
                        (fm.getHeight() / 3)));
837
                   pU = new Point2D.Double(rec.getCenterX() -
838
                            (fm.stringWidth(m_nameUnit) / 2),
839
                            (rec.getMaxY() - (rec.getHeight() / 9) +
840
                            (fm.getHeight() / 3)));
841
842
                   break;
843
               case BIUD:
844
                   pD = new Point2D.Double(rec.getCenterX() -
845
                        (fm.stringWidth(getDescription()) / 2),
846
                        (rec.getMaxY() - (rec.getHeight() / 3) +
847
                        (fm.getHeight() / 3)));
848
                   pU = new Point2D.Double(rec.getCenterX() -
849
                            (fm.stringWidth(m_nameUnit) / 2),
850
                            (rec.getMaxY() - (rec.getHeight() / 9) +
851
                            (fm.getHeight() / 3)));
852
                   break;
853
               }
854
               if (isShowNameUnits()) {
855
                   g.drawString(m_nameUnit, (int) pU.x, (int) pU.y);
856
               }
857
            if (isShowDescription()) {
858
                g.drawString(getDescription(), (int) pD.x, (int) pD.y);
859
            }
860
    }
861
    /**
862
     * Rellena la fuente utilizada para dibujar los intervalos y la unidad de
863
     * medida utilizada.
864
     *
865
     * @param f fuente a utilizar.
866
     */
867
    public void setFont(Font f) {
868
        m_f = f;
869
    }
870
871
    /**
872
     * Devuelve la fuente con la que se est? dibujando sobre el graphics.
873
     *
874
     * @return fuente utilizada.
875
     */
876
    public Font getFont() {
877
        return new Font(m_f.getFontName(), m_f.getStyle(), 9);
878
    }
879
880
    /**
881
     * Devuelve si el intervalo es variable o si por el contrario es fijo.
882
     *
883
     * @return true si el intervalo es fijo.
884
     */
885
    public boolean isbIntervalSet() {
886
        return m_bIntervalSet;
887
    }
888
889
    /**
890
     * Especificar si el intervalo se debe mantener o es variable.
891
     *
892
     * @param b si se quiere mantener el intervalo especificado.
893
     */
894
    public void setbIntervalSet(boolean b) {
895
        m_bIntervalSet = b;
896
    }
897
898
    /**
899
     * Devuelve el porcentaje por el cual hay que multiplicar  el intervalo
900
     * para conseguir un intervalo redondeado,  de momento con una cifra
901
     * significativas(NUM=1).
902
     *
903
     * @param total intervalo.
904
     *
905
     * @return Porcentaje
906
     */
907
    private double getExact(double total) {
908
            int NUM = 1;
909
            double t = 0;
910
        double dif = 1;
911
        Double d = new Double(total);
912
        Long l = new Long(d.longValue());
913
        int num = l.toString().length();
914
        t = ((long) (total / Math.pow(10, num - NUM)) * Math.pow(10, num - NUM));
915
        dif = t / total;
916
917
        if (dif == 0) {
918
            return 1;
919
        }
920
921
        return dif;
922
    }
923
924
    /**
925
     * Rellena un rect?ngulo.
926
     *
927
     * @param g Graphics sobre el que dibujar.
928
     * @param r Rect?ngulo a rellenar.
929
     */
930
    private void fillRect(Graphics2D g, Rectangle2D.Double r) {
931
        g.fillRect((int) r.x, (int) r.y, (int) r.width, (int) r.height);
932
    }
933
934
    /**
935
     * Escribe sobre el Graphics y en la posici?n indicada el tama?o del
936
     * intervalo.
937
     *
938
     * @param g Graphics sobre el que dibujar.
939
     * @param inter Valor del intervalo.
940
     * @param p Punto donde dibujarlo.
941
     */
942
    private void drawInterval(Graphics2D g, String inter, Point2D.Double p) {
943
        //Double l = new Double(inter);
944
        g.setColor(textcolor);
945
        g.drawString(inter, (int) p.x, (int) p.y);
946
        g.setColor(barcolor);
947
    }
948
949
    /**
950
     * DOCUMENT ME!
951
     *
952
     * @return DOCUMENT ME!
953
     *
954
     * @throws SaveException
955
     *
956
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getXMLEntity()
957
     */
958
    public XMLEntity getXMLEntity() throws SaveException {
959
        XMLEntity xml = super.getXMLEntity();
960
961
        try {
962
//            xml.putProperty("type", Layout.RECTANGLESCALEBAR);
963
            xml.putProperty("m_bIntervalSet", m_bIntervalSet);
964
            xml.putProperty("m_dif", m_dif);
965
            xml.putProperty("m_hasleft", m_hasleft);
966
            xml.putProperty("m_nameUnit", m_nameUnit);
967
            xml.putProperty("m_numUnit", m_numUnit);
968
969
            xml.putProperty("m_height", m_height);
970
971
            xml.putProperty("m_style", m_style);
972
            xml.putProperty("m_units", m_units);
973
            xml.putProperty("m_interval", m_interval);
974
            xml.putProperty("m_numinterval", m_numinterval);
975
            xml.putProperty("m_numleft", m_numleft);
976
            xml.putProperty("m_mapUnits", m_mapUnits);
977
            xml.putProperty("fontName", m_f.getFontName());
978
            xml.putProperty("fontStyle", m_f.getStyle());
979
            xml.putProperty("numDec", numDec);
980
            xml.putProperty("m_units", m_units);
981
982
            if (fframeview != null) {
983
                Layout layout = fframeview.getLayout();
984
                IFFrame[] fframes = layout.getLayoutContext().getAllFFrames();
985
986
                for (int i = 0; i < fframes.length; i++) {
987
                    if (fframeview.getName().equals(fframes[i].getName())) {
988
                        xml.putProperty("index", i);
989
                    }
990
                }
991
            }
992
993
            xml.putProperty("barcolor", StringUtilities.color2String(barcolor));
994
            xml.putProperty("textcolor", StringUtilities.color2String(textcolor));
995
            xml.putProperty("showNameUnits", showNameUnits);
996
            xml.putProperty("showDescription", showDescription);
997
            xml.putProperty("aboveName", aboveName);
998
            xml.putProperty("aboveIntervals", aboveIntervals);
999
            xml.putProperty("aboveDescription", aboveDescription);
1000
        } catch (Exception e) {
1001
            throw new SaveException(e, this.getClass().getName());
1002
        }
1003
1004
        return xml;
1005
    }
1006
1007
    /**
1008
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
1009
     *      com.iver.cit.gvsig.project.Project)
1010
     */
1011
    public void setXMLEntity03(XMLEntity xml, Layout l) {
1012
        if (xml.getIntProperty("m_Selected") != 0) {
1013
            this.setSelected(true);
1014
        } else {
1015
            this.setSelected(false);
1016
        }
1017
1018
        this.m_bIntervalSet = xml.getBooleanProperty("m_bIntervalSet");
1019
        this.m_dif = xml.getDoubleProperty("m_dif");
1020
        this.m_hasleft = xml.getIntProperty("m_hasleft");
1021
        this.m_nameUnit = xml.getStringProperty("m_nameUnit");
1022
        this.m_numUnit = xml.getDoubleProperty("m_numUnit");
1023
1024
        this.m_height = xml.getDoubleProperty("m_height");
1025
1026
        this.m_style = xml.getIntProperty("m_style");
1027
        this.m_interval = xml.getLongProperty("m_interval");
1028
        this.m_numinterval = xml.getIntProperty("m_numinterval");
1029
        this.m_numleft = xml.getIntProperty("m_numleft");
1030
        this.m_mapUnits = xml.getIntProperty("m_mapUnits");
1031
        this.m_f = new Font(xml.getStringProperty("fontName"),
1032
                xml.getIntProperty("fontStyle"), 9);
1033
1034
        fframeview = (FFrameView) l.getLayoutContext().getFFrame(xml.getIntProperty("index"));
1035
1036
        if (xml.contains("description")) { //Comprobar que es de la versi?n que cambia el di?logo.
1037
            this.barcolor = StringUtilities.string2Color(xml.getStringProperty(
1038
                        "barcolor"));
1039
            this.textcolor = StringUtilities.string2Color(xml.getStringProperty(
1040
                        "textcolor"));
1041
            this.showNameUnits = xml.getBooleanProperty("showNameUnits");
1042
            this.showDescription = xml.getBooleanProperty("showDescription");
1043
            this.aboveName = xml.getBooleanProperty("aboveName");
1044
            this.aboveIntervals = xml.getBooleanProperty("aboveIntervals");
1045
            this.aboveDescription = xml.getBooleanProperty("aboveDescription");
1046
        }
1047
    }
1048
1049
    /**
1050
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
1051
     *      com.iver.cit.gvsig.project.Project)
1052
     */
1053
    public void setXMLEntity(XMLEntity xml) {
1054
        if (xml.getIntProperty("m_Selected") != 0) {
1055
            this.setSelected(true);
1056
        } else {
1057
            this.setSelected(false);
1058
        }
1059
1060
        this.m_bIntervalSet = xml.getBooleanProperty("m_bIntervalSet");
1061
        this.m_dif = xml.getDoubleProperty("m_dif");
1062
        this.m_hasleft = xml.getIntProperty("m_hasleft");
1063
        this.m_nameUnit = xml.getStringProperty("m_nameUnit");
1064
        this.m_numUnit = xml.getDoubleProperty("m_numUnit");
1065
1066
        this.m_height = xml.getDoubleProperty("m_height");
1067
1068
        this.m_style = xml.getIntProperty("m_style");
1069
        this.m_interval = xml.getDoubleProperty("m_interval");
1070
        this.m_numinterval = xml.getIntProperty("m_numinterval");
1071
        this.m_numleft = xml.getIntProperty("m_numleft");
1072
        this.m_mapUnits = xml.getIntProperty("m_mapUnits");
1073
        this.m_f = new Font(xml.getStringProperty("fontName"),
1074
                xml.getIntProperty("fontStyle"), 9);
1075
        setRotation(xml.getDoubleProperty("m_rotation"));
1076
1077
        if (xml.contains("m_units")) { //Comprobaci?n por versi?n 0.5
1078
            setUnits(xml.getIntProperty("m_units"));
1079
        }
1080
1081
        if (xml.contains("index")) {
1082
            dependenceIndex = xml.getIntProperty("index");
1083
        }
1084
1085
1086
        if (xml.contains("showDescription")) { //Comprobar que es de la versi?n que cambia el di?logo.
1087
            this.barcolor = StringUtilities.string2Color(xml.getStringProperty(
1088
            "barcolor"));
1089
1090
            this.textcolor = StringUtilities.string2Color(xml.getStringProperty(
1091
                        "textcolor"));
1092
            this.showNameUnits = xml.getBooleanProperty("showNameUnits");
1093
            this.showDescription = xml.getBooleanProperty("showDescription");
1094
            this.aboveName = xml.getBooleanProperty("aboveName");
1095
            this.aboveIntervals = xml.getBooleanProperty("aboveIntervals");
1096
            this.aboveDescription = xml.getBooleanProperty("aboveDescription");
1097
        }
1098
1099
        if (xml.contains("numDec")) {
1100
            setNumDec(xml.getIntProperty("numDec"));
1101
        }
1102
    }
1103
1104
    /**
1105
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getNameFFrame()
1106
     */
1107
    public String getNameFFrame() {
1108
        return PluginServices.getText(this, "escala")+ num;
1109
    }
1110
1111
    /**
1112
     * Inserta el color de la escala gr?fica.
1113
     *
1114
     * @param color Color de la escala gr?fica.
1115
     */
1116
    public void setBarColor(Color color) {
1117
        barcolor = color;
1118
    }
1119
1120
    /**
1121
     * Inserta el color del texto.
1122
     *
1123
     * @param color Color del texto.
1124
     */
1125
    public void setTextColor(Color color) {
1126
        textcolor = color;
1127
    }
1128
1129
    /**
1130
     * Devuelve el color de la escala gr?fica.
1131
     *
1132
     * @return Color de la escala gr?fica.
1133
     */
1134
    public Color getBarColor() {
1135
        return barcolor;
1136
    }
1137
1138
    /**
1139
     * Devuelve el color del texto.
1140
     *
1141
     * @return Color del texto.
1142
     */
1143
    public Color getTextColor() {
1144
        return textcolor;
1145
    }
1146
1147
    /**
1148
     * Devuelve true si se debe mostrar el nombre de las unidades de medida de
1149
     * la escala gr?fica.
1150
     *
1151
     * @return True si se muestra las unidades de medida.
1152
     */
1153
    public boolean isShowNameUnits() {
1154
        return showNameUnits;
1155
    }
1156
1157
    /**
1158
     * Inserta si se debe de mostrar el nombre de las unidades de medida o no.
1159
     *
1160
     * @param showNameUnits True si se muestra el nombre de las unidades de
1161
     *        medida.
1162
     */
1163
    public void setShowNameUnits(boolean showNameUnits) {
1164
        this.showNameUnits = showNameUnits;
1165
    }
1166
1167
    /**
1168
     * Devuelve true si se muestra la descripci?n a la parte de arriba de la
1169
     * escala gr?fica.
1170
     *
1171
     * @return True si se muestra arriba de la escala gr?fica.
1172
     */
1173
    public boolean isAboveDescription() {
1174
        return aboveDescription;
1175
    }
1176
1177
    /**
1178
     * Introduce true si se muestra arriba de la escala gr?fica la descripci?n.
1179
     *
1180
     * @param aboveDescription True si se muestra arriba la descripci?n.
1181
     */
1182
    public void setAboveDescription(boolean aboveDescription) {
1183
        this.aboveDescription = aboveDescription;
1184
    }
1185
1186
    /**
1187
     * Devuelve true si se muestran a la parte de arriba los valores de los
1188
     * intervalos.
1189
     *
1190
     * @return True si se muestran arriba de la escala gr?fica.
1191
     */
1192
    public boolean isAboveIntervals() {
1193
        return aboveIntervals;
1194
    }
1195
1196
    /**
1197
     * Inserta si se muestran los valores de los intervalos a la parte de
1198
     * arriba de la escala o debajo.
1199
     *
1200
     * @param aboveIntervals True si se muestran los valores de los intervalos
1201
     *        a la parte de arriba de la escala gr?fica.
1202
     */
1203
    public void setAboveIntervals(boolean aboveIntervals) {
1204
        this.aboveIntervals = aboveIntervals;
1205
    }
1206
1207
    /**
1208
     * Devuelve si se muestra a la parte de arriba de la escala gr?fica el
1209
     * nombre de las unidades de medida o debajo.
1210
     *
1211
     * @return True si se muestra a la parte de arriba de la escala gr?fica.
1212
     */
1213
    public boolean isAboveName() {
1214
        return aboveName;
1215
    }
1216
1217
    /**
1218
     * Inserta si el nombre se muestra a la parte de arriba de la escala
1219
     * gr?fica o a la parte de abajo.
1220
     *
1221
     * @param aboveName True si se muestra a la parte de arriba de la escala
1222
     *        gr?fica.
1223
     */
1224
    public void setAboveName(boolean aboveName) {
1225
        this.aboveName = aboveName;
1226
    }
1227
1228
    /**
1229
     * Devuelve si se debe mostrar la descripci?n o no.
1230
     *
1231
     * @return True si se muestra la descripci?n.
1232
     */
1233
    public boolean isShowDescription() {
1234
        return showDescription;
1235
    }
1236
1237
    /**
1238
     * Inserta si se muestra o no la descripci?n.
1239
     *
1240
     * @param showDescription True si se muestra la descripci?n.
1241
     */
1242
    public void setShowDescription(boolean showDescription) {
1243
        this.showDescription = showDescription;
1244
    }
1245
1246
    /**
1247
     * Devuelve la descripci?n de la escala.
1248
     *
1249
     * @return Descripci?n de la escala.
1250
     */
1251
    public String getDescription() {
1252
        if (fframeview!=null){
1253
                if (fframeview.getScale()==0){
1254
                        return PluginServices.getText(this,"escala_desconocida");
1255
                }
1256
            return "1:" + String.valueOf(fframeview.getScale());
1257
        }
1258
            return "1:";
1259
    }
1260
1261
    /**
1262
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#print(java.awt.Graphics2D,
1263
     *      java.awt.geom.AffineTransform)
1264
     */
1265 10911 jaume
    public void print(Graphics2D g, AffineTransform at, FShape shape, PrintRequestAttributeSet properties)
1266 10626 caballero
        throws ReadDriverException {
1267 9392 caballero
        draw(g, at, null, null);
1268
    }
1269
1270
    /**
1271
     * Update the dependences that have this FFrame with the other FFrame.
1272
     *
1273
     * @param fframes Other FFrames.
1274
     */
1275
    public void initDependence(IFFrame[] fframes) {
1276
        if ((dependenceIndex != -1) &&
1277
                fframes[dependenceIndex] instanceof FFrameView) {
1278
            fframeview = (FFrameView) fframes[dependenceIndex];
1279
        }
1280
    }
1281
1282
    /**
1283
     * DOCUMENT ME!
1284
     *
1285
     * @param d DOCUMENT ME!
1286
     *
1287
     * @return DOCUMENT ME!
1288
     */
1289
    public String format(double d) {
1290
        if ((d % (long) d) != 0) {
1291
            numberFormat.setMaximumFractionDigits(getNumDec());
1292
        } else {
1293
            numberFormat.setMaximumFractionDigits(0);
1294
        }
1295
1296
        //String s = String.valueOf(nf.format(d));
1297
        //s=s.replace('.','*');
1298
        //s = s.replace(',', '.');
1299
        //s=s.replace('*',',');
1300
        return numberFormat.format(d); //(Double.valueOf(s).doubleValue());
1301
    }
1302
1303
    /**
1304
     * DOCUMENT ME!
1305
     *
1306
     * @return DOCUMENT ME!
1307
     */
1308
    public int getNumDec() {
1309
        return numDec;
1310
    }
1311
1312
    /**
1313
     * DOCUMENT ME!
1314
     *
1315
     * @param numDec DOCUMENT ME!
1316
     */
1317
    public void setNumDec(int numDec) {
1318
        this.numDec = numDec;
1319
    }
1320
1321
    public void initialize() {
1322
        // TODO Auto-generated method stub
1323
1324
    }
1325
    private final static int DUIB=0;
1326
    private final static int DUBI=1;
1327
    private final static int DBIU=2;
1328
    private final static int DIBU=3;
1329
    private final static int UIBD=4;
1330
    private final static int UBID=5;
1331
    private final static int IBUD=6;
1332
    private final static int BIUD=7;
1333
1334
    private int getFormat(){
1335
        if (isAboveDescription()){
1336
            if (isAboveName()){
1337
                if (isAboveIntervals()){
1338
                    return DUIB;
1339
                }
1340
                return DUBI;
1341
            }
1342
            if (isAboveIntervals()){
1343
                    return DIBU;
1344
                }
1345
                return DBIU;
1346
        }
1347
        if (isAboveName()){
1348
            if (isAboveIntervals()){
1349
                return UIBD;
1350
            }
1351
            return UBID;
1352
        }
1353
        if (isAboveIntervals()){
1354
            return IBUD;
1355
        }
1356
        return BIUD;
1357
    }
1358
1359
        public void cloneActions(IFFrame frame) {
1360
                // TODO Auto-generated method stub
1361
1362
        }
1363
1364
        public IFFrameDialog getPropertyDialog() {
1365
                return new FFrameScaleBarDialog(getLayout(),this);
1366
        }
1367
}