Statistics
| Revision:

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

History | View | Annotate | Download (44.9 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.hardcode.gdbms.driver.exceptions.ReadDriverException;
60
import com.iver.andami.PluginServices;
61
import com.iver.cit.gvsig.fmap.MapContext;
62
import com.iver.cit.gvsig.fmap.core.FShape;
63
import com.iver.cit.gvsig.project.documents.exceptions.SaveException;
64
import com.iver.cit.gvsig.project.documents.layout.Attributes;
65
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities;
66
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameScaleBarDialog;
67
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.IFFrameDialog;
68
import com.iver.cit.gvsig.project.documents.layout.gui.Layout;
69
import com.iver.utiles.StringUtilities;
70
import com.iver.utiles.XMLEntity;
71

    
72

    
73

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

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

    
121
    /**
122
     * Inserta el FFrameView sobre el que obtener la escala gr?fica.
123
     *
124
     * @param f FFrameView sobre  el que obtener la escala.
125
     */
126
    public void setFFrameDependence(IFFrame f) {
127
        fframeview = (FFrameView) f;
128
        if (fframeview==null)
129
                return;
130
        setMapUnits(fframeview.getMapUnits());
131
        setHeight(f.getBoundBox().height);
132
    }
133

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

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

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

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

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

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

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

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

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

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

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

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

    
218
        return "0";
219
    }
220

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

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

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

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

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

    
254
    /**
255
     * Rellenar el n?mero de intervalos a la izquierda del cero.
256
     *
257
     * @param s n?mero de intervalos a la izquierda.
258
     */
259
    public void setNumLeft(int s) {
260
        m_numleft = s;
261
        if (m_numleft != 0) {
262
            m_hasleft = 1;
263
        }else{
264
                m_hasleft=0;
265
        }
266
    }
267

    
268
    /**
269
     * Devuelve el n?mero de intervalos  en los que se quiere particionar el
270
     * intervalo  que se queda por debajo del cero.
271
     *
272
     * @return entero.
273
     */
274
    public int getNumLeft() {
275
        return m_numleft;
276
    }
277

    
278
    /**
279
     * Seleccionar ,a true, si se quiere o, a false, si no mantener los
280
     * intervalos.
281
     *
282
     * @param b boolean a true si se quiere mantener los intervalos.
283
     */
284
    public void setIntervalSet(boolean b) {
285
        m_bIntervalSet = b;
286
    }
287

    
288
    /**
289
     * Seleccionar la unidad de medida a representar en la barra de escala.
290
     *
291
     * @param s entero que representa la unidad de medida que se selecciona.
292
     */
293
    public void setUnits(int s) {
294
        m_units = s;
295
        m_typeUnit = Attributes.CHANGE[s];
296
        m_nameUnit = PluginServices.getText(this,Attributes.NAMES[s]);
297
    }
298

    
299
    /**
300
     * Devuelve un entero que representa el tipo de unidades que representamos.
301
     *
302
     * @return entero.
303
     */
304
    public int getUnits() {
305
        return m_units;
306
    }
307

    
308
    /**
309
     * Devuelve el long que representa el intervalo.
310
     *
311
     * @return Intervalo.
312
     */
313
    public String getInterval() {
314
        return format(m_interval);
315
    }
316

    
317
    /**
318
     * Rellenar el rect?ngulo de la vista sobre la que se obtiene la escala.
319
     *
320
     * @param d Rect?ngulo.
321
     */
322
    public void setHeight(double d) {
323
        m_height = d;
324
    }
325

    
326
    /**
327
     * Rellena la unidad de medida en la que est? la vista.
328
     *
329
     * @param i entero que representa la unidad de medida de la vista.
330
     */
331
    public void setMapUnits(int i) {
332
        m_mapUnits = i;
333
    }
334

    
335
    /**
336
     * Devuelve la escala de la vista seleccionada.
337
     *
338
     * @return la escala de la vista.
339
     */
340
    private long getScaleView() {
341
        if (fframeview == null) {
342
            return 1;
343
        }
344

    
345
        return fframeview.getScale();
346
    }
347

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

    
364
        if (intersects(rv, r)) {
365
            if ((fframeview == null) || (fframeview.getMapContext() == null)) {
366
                drawEmpty(g);
367
            } else {
368
                switch (m_style) {
369
                    case (NUMERO):
370

    
371
                        double scalex = r.getWidth() / (8);
372

    
373
                        if (scalex > (r.getHeight() / (8))) {
374
                            scalex = r.getHeight() / (2);
375
                        }
376

    
377
                        g.setColor(textcolor);
378

    
379
                        if (m_f != null) {
380
                            m_f = new Font(m_f.getFontName(), m_f.getStyle(),
381
                                    (int) (scalex));
382
                            g.setFont(m_f);
383
                        }
384

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

    
402
                        if (fm.stringWidth(String.valueOf(m_interval)) > (d * 0.8)) {
403
                            double dif = fm.stringWidth(String.valueOf(
404
                                        m_interval)) / (d * 0.8);
405
                            m_f = new Font(m_f.getName(), m_f.getStyle(),
406
                                    (int) (m_f.getSize() / dif));
407
                            g.setFont(m_f);
408
                        }
409

    
410
                        g.drawString(scale, (int) r.x,
411
                            (int) (r.y + (r.height / 2)));
412

    
413
                        break;
414

    
415
                    case (BARRA1):
416
                    case (BARRA2):
417
                    case (BARRA3):
418
                    case (BARRA4):
419
                        drawBar(m_style, g, at);
420

    
421
                        break;
422
                }
423
            }
424
        }
425

    
426
        g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2),
427
            r.y + (r.height / 2));
428
    }
429

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

    
442
            return;
443
        }
444

    
445
        double difL = (r.width / DIFL);
446
        double difR = (r.width / DIFR);
447

    
448
        if (m_bIntervalSet) {
449
            m_numinterval = (int) (((r.width - (difL + difR)) * m_dif) / m_numUnit) -
450
                m_hasleft;
451
        }
452

    
453
        if (m_numinterval < 1) {
454
            m_numinterval = 1;
455
            r.width = ((m_numinterval + m_hasleft) * m_numUnit) + difL + difR;
456
        }
457

    
458
        getBoundBox().setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
459
    }
460

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

    
480
        //setDescripcion("escala 1:" + String.valueOf(fframeview.getScale()));
481
        g.setStroke(new BasicStroke(0));
482

    
483
        if (!m_bIntervalSet) {
484
            m_numUnit = n / (m_numinterval + m_hasleft);
485

    
486
            double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
487
            m_dif = getExact(scaleXunit);
488
            m_numUnit = m_numUnit * m_dif;
489
            m_interval = (scaleXunit * m_dif);
490
        }
491

    
492
        if (m_bIntervalSet) {
493
            m_numUnit = (m_interval * m_typeUnit) / (m_dif * getScaleView());
494
            m_numinterval = (int) (((rect.width - (difL + difR)) * m_dif) / m_numUnit) -
495
                m_hasleft;
496
        }
497

    
498
        if (m_numinterval < 1) {
499
            m_numinterval = 1;
500
            rect.width = ((m_numinterval + m_hasleft) * m_numUnit) + difL +
501
                difR;
502
        }
503

    
504
        double h = 0;
505

    
506
        if (type == BARRA1) {
507
            h = (rect.height - (difUp + difDown));
508
        } else if ((type == BARRA2) || (type == BARRA3)) {
509
            h = (rect.height - (difUp + difDown)) / 2;
510
        }
511

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

    
524
        if (m_f != null) {
525
            m_f = new Font(m_f.getFontName(), m_f.getStyle(),
526
                    (int) (r.getHeight() / 4));
527
        } else {
528
            m_f = new Font("SansSerif", Font.PLAIN, (int) (r.getHeight() / 4));
529
        }
530

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

    
548
        FontMetrics fm = g.getFontMetrics();
549
        String formatInterval = format(m_interval);
550
        double d = (rectotal.getWidth() / m_numinterval) + m_hasleft;
551
        double difpos = ((r.getHeight() / 4) * formatInterval.length()) / 4;
552

    
553
        if (fm.stringWidth(formatInterval) > (d * 0.7)) {
554
            double dif = fm.stringWidth(formatInterval) / (d * 0.7);
555
            difpos = (d * 0.7) / 2;
556
            m_f = new Font(m_f.getName(), m_f.getStyle(),
557
                    (int) (m_f.getSize() / dif));
558
            g.setFont(m_f);
559
        }
560

    
561
        //Derecha del cero
562
        for (int i = 0; i < m_numinterval; i++) {
563
            Rectangle2D.Double recder = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
564
                        (difL) + ((m_numUnit * i) + (m_hasleft * m_numUnit))),
565
                        (rect.y + (difUp)), (m_numUnit),
566
                        (rect.height - (difUp + difDown)) / 2), at);
567
            Rectangle2D.Double recderB = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
568
                        (difL) + ((m_numUnit * i) + (m_hasleft * m_numUnit))),
569
                        (rect.y + difUp) +
570
                        ((rect.height - (difUp + difDown)) / 2), (m_numUnit),
571
                        ((rect.height - (difUp + difDown)) / 2)), at);
572

    
573
            //                        Correcci?n cuando la altura en pixels del rect?ngulo es impar.
574
            rectotal.y = recder.y;
575
            recderB.height = rectotal.height - recder.height + 0.5;
576

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

    
610
            String interString = format(m_interval * i);
611
            Point2D.Double p = null;
612

    
613
            if (isAboveIntervals()) {
614
                p = new Point2D.Double(recder.x - difpos,
615
                        r.getMinY() + (r.getHeight() / DIFUP));
616
            } else {
617
                p = new Point2D.Double(recder.x - difpos,
618
                        ((r.getHeight() / 4) + r.getMaxY()) -
619
                        (r.getHeight() / DIFDOWN));
620
            }
621

    
622
            //Para dibujar el 0 centrado en su sitio.
623
            if (i == 0) {
624
                double dif0 = recder.x - (fm.stringWidth(interString) / 2);
625
                p = new Point2D.Double(dif0, p.getY());
626
            }
627

    
628
            drawInterval(g, interString, p);
629
        }
630

    
631
        //?ltimo n?mero a dibujar.
632
        String interString = format(m_interval * m_numinterval);
633

    
634
        Point2D.Double p = null;
635

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

    
645
        drawInterval(g, interString, p);
646

    
647
        //Izquierda del cero
648
        for (int i = 0; i < m_numleft; i++) {
649
            Rectangle2D.Double reciz = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
650
                        difL + ((m_numUnit / m_numleft) * i)),
651
                        (rect.y + difUp), (m_numUnit / numleft),
652
                        (rect.height - (difUp + difDown)) / 2), at);
653
            Rectangle2D.Double recizB = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
654
                        difL + ((m_numUnit / m_numleft) * i)),
655
                        (rect.y + difUp) +
656
                        ((rect.height - (difUp + difDown)) / 2),
657
                        (m_numUnit / numleft),
658
                        ((rect.height - (difUp + difDown)) / 2)), at);
659

    
660
            //Correcci?n cuando la altura en pixels del rectangulo es impar.
661
            reciz.y = rectotal.y;
662
            recizB.height = rectotal.height - reciz.height + 0.5;
663

    
664
            if ((i % 2) == 0) {
665
                if ((type == BARRA1) || (type == BARRA2)) {
666
                    fillRect(g, reciz);
667
                } else if (type == BARRA3) {
668
                    g.drawRect((int) reciz.x, (int) reciz.y, (int) reciz.width,
669
                        (int) reciz.height);
670
                }
671
            } else if (type == BARRA1) {
672
                fillRect(g, recizB);
673
            }
674
        }
675

    
676
        if (m_numleft > 0) {
677
            interString = format(m_interval);
678

    
679
            if (isAboveIntervals()) {
680
                p = new Point2D.Double(rectotal.x - difpos,
681
                        r.getMinY() + (r.getHeight() / DIFUP));
682
            } else {
683
                p = new Point2D.Double(rectotal.x - difpos,
684
                        ((r.getHeight() / 4) + r.getMaxY()) -
685
                        (r.getHeight() / DIFDOWN));
686
            }
687

    
688
            drawInterval(g, interString, p);
689
        }
690

    
691
        //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.
692
        if (m_numleft == 0) {
693
            Rectangle2D.Double recAux = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
694
                        difL + ((m_numUnit / 1) * 0)), (rect.y + difUp),
695
                        (m_numUnit / 1), (rect.height - (difUp + difDown)) / 2),
696
                    at);
697
            rectotal.x = rectotal.x + recAux.width;
698
            rectotal.width = rectotal.width - recAux.width;
699
        }
700

    
701
        //Se dibuja el rect?ngulo que bordea toda la escala gr?fica.
702
        g.drawRect((int) rectotal.x, (int) rectotal.y, (int) (rectotal.width),
703
            (int) rectotal.height);
704

    
705
        drawNameUnitsAndDescriptions(g, r);
706
        //drawDescription(g, r);
707
    }
708

    
709
    /**
710
     * Inicializa las distancias de la barra de escala.
711
     */
712
    private void initDistances() {
713
        int numUp = 0;
714
        int numDown = 0;
715

    
716
        DIFDOWN = 30;
717
        DIFL = 40;
718
        DIFR = 40;
719
        DIFUP = 30;
720

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

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

    
733
        if (isAboveDescription()) {
734
            numUp++;
735
        } else {
736
            numDown++;
737
        }
738

    
739
        if (numDown == 1) {
740
            DIFDOWN = 3;
741
        } else if (numDown == 2) {
742
            DIFDOWN = 2;
743
        } else if (numDown == 3) {
744
            DIFDOWN = 1.2;
745
        }
746

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

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

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

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

    
869
    /**
870
     * Devuelve la fuente con la que se est? dibujando sobre el graphics.
871
     *
872
     * @return fuente utilizada.
873
     */
874
    public Font getFont() {
875
        return new Font(m_f.getFontName(), m_f.getStyle(), 9);
876
    }
877

    
878
    /**
879
     * Devuelve si el intervalo es variable o si por el contrario es fijo.
880
     *
881
     * @return true si el intervalo es fijo.
882
     */
883
    public boolean isbIntervalSet() {
884
        return m_bIntervalSet;
885
    }
886

    
887
    /**
888
     * Especificar si el intervalo se debe mantener o es variable.
889
     *
890
     * @param b si se quiere mantener el intervalo especificado.
891
     */
892
    public void setbIntervalSet(boolean b) {
893
        m_bIntervalSet = b;
894
    }
895

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

    
915
        if (dif == 0) {
916
            return 1;
917
        }
918

    
919
        return dif;
920
    }
921

    
922
    /**
923
     * Rellena un rect?ngulo.
924
     *
925
     * @param g Graphics sobre el que dibujar.
926
     * @param r Rect?ngulo a rellenar.
927
     */
928
    private void fillRect(Graphics2D g, Rectangle2D.Double r) {
929
        g.fillRect((int) r.x, (int) r.y, (int) r.width, (int) r.height);
930
    }
931

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

    
947
    /**
948
     * DOCUMENT ME!
949
     *
950
     * @return DOCUMENT ME!
951
     *
952
     * @throws SaveException
953
     *
954
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getXMLEntity()
955
     */
956
    public XMLEntity getXMLEntity() throws SaveException {
957
        XMLEntity xml = super.getXMLEntity();
958

    
959
        try {
960
//            xml.putProperty("type", Layout.RECTANGLESCALEBAR);
961
            xml.putProperty("m_bIntervalSet", m_bIntervalSet);
962
            xml.putProperty("m_dif", m_dif);
963
            xml.putProperty("m_hasleft", m_hasleft);
964
            xml.putProperty("m_nameUnit", m_nameUnit);
965
            xml.putProperty("m_numUnit", m_numUnit);
966

    
967
            xml.putProperty("m_height", m_height);
968

    
969
            xml.putProperty("m_style", m_style);
970
            xml.putProperty("m_units", m_units);
971
            xml.putProperty("m_interval", m_interval);
972
            xml.putProperty("m_numinterval", m_numinterval);
973
            xml.putProperty("m_numleft", m_numleft);
974
            xml.putProperty("m_mapUnits", m_mapUnits);
975
            xml.putProperty("fontName", m_f.getFontName());
976
            xml.putProperty("fontStyle", m_f.getStyle());
977
            xml.putProperty("numDec", numDec);
978
            xml.putProperty("m_units", m_units);
979

    
980
            if (fframeview != null) {
981
                Layout layout = fframeview.getLayout();
982
                IFFrame[] fframes = layout.getLayoutContext().getAllFFrames();
983

    
984
                for (int i = 0; i < fframes.length; i++) {
985
                    if (fframeview.getName().equals(fframes[i].getName())) {
986
                        xml.putProperty("index", i);
987
                    }
988
                }
989
            }
990

    
991
            xml.putProperty("barcolor", StringUtilities.color2String(barcolor));
992
            xml.putProperty("textcolor", StringUtilities.color2String(textcolor));
993
            xml.putProperty("showNameUnits", showNameUnits);
994
            xml.putProperty("showDescription", showDescription);
995
            xml.putProperty("aboveName", aboveName);
996
            xml.putProperty("aboveIntervals", aboveIntervals);
997
            xml.putProperty("aboveDescription", aboveDescription);
998
        } catch (Exception e) {
999
            throw new SaveException(e, this.getClass().getName());
1000
        }
1001

    
1002
        return xml;
1003
    }
1004

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

    
1016
        this.m_bIntervalSet = xml.getBooleanProperty("m_bIntervalSet");
1017
        this.m_dif = xml.getDoubleProperty("m_dif");
1018
        this.m_hasleft = xml.getIntProperty("m_hasleft");
1019
        this.m_nameUnit = xml.getStringProperty("m_nameUnit");
1020
        this.m_numUnit = xml.getDoubleProperty("m_numUnit");
1021

    
1022
        this.m_height = xml.getDoubleProperty("m_height");
1023

    
1024
        this.m_style = xml.getIntProperty("m_style");
1025
        this.m_interval = xml.getLongProperty("m_interval");
1026
        this.m_numinterval = xml.getIntProperty("m_numinterval");
1027
        this.m_numleft = xml.getIntProperty("m_numleft");
1028
        this.m_mapUnits = xml.getIntProperty("m_mapUnits");
1029
        this.m_f = new Font(xml.getStringProperty("fontName"),
1030
                xml.getIntProperty("fontStyle"), 9);
1031

    
1032
        fframeview = (FFrameView) l.getLayoutContext().getFFrame(xml.getIntProperty("index"));
1033

    
1034
        if (xml.contains("description")) { //Comprobar que es de la versi?n que cambia el di?logo.
1035
            this.barcolor = StringUtilities.string2Color(xml.getStringProperty(
1036
                        "barcolor"));
1037
            this.textcolor = StringUtilities.string2Color(xml.getStringProperty(
1038
                        "textcolor"));
1039
            this.showNameUnits = xml.getBooleanProperty("showNameUnits");
1040
            this.showDescription = xml.getBooleanProperty("showDescription");
1041
            this.aboveName = xml.getBooleanProperty("aboveName");
1042
            this.aboveIntervals = xml.getBooleanProperty("aboveIntervals");
1043
            this.aboveDescription = xml.getBooleanProperty("aboveDescription");
1044
        }
1045
    }
1046

    
1047
    /**
1048
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
1049
     *      com.iver.cit.gvsig.project.Project)
1050
     */
1051
    public void setXMLEntity(XMLEntity xml) {
1052
        if (xml.getIntProperty("m_Selected") != 0) {
1053
            this.setSelected(true);
1054
        } else {
1055
            this.setSelected(false);
1056
        }
1057

    
1058
        this.m_bIntervalSet = xml.getBooleanProperty("m_bIntervalSet");
1059
        this.m_dif = xml.getDoubleProperty("m_dif");
1060
        this.m_hasleft = xml.getIntProperty("m_hasleft");
1061
        this.m_nameUnit = xml.getStringProperty("m_nameUnit");
1062
        this.m_numUnit = xml.getDoubleProperty("m_numUnit");
1063

    
1064
        this.m_height = xml.getDoubleProperty("m_height");
1065

    
1066
        this.m_style = xml.getIntProperty("m_style");
1067
        this.m_interval = xml.getDoubleProperty("m_interval");
1068
        this.m_numinterval = xml.getIntProperty("m_numinterval");
1069
        this.m_numleft = xml.getIntProperty("m_numleft");
1070
        this.m_mapUnits = xml.getIntProperty("m_mapUnits");
1071
        this.m_f = new Font(xml.getStringProperty("fontName"),
1072
                xml.getIntProperty("fontStyle"), 9);
1073
        setRotation(xml.getDoubleProperty("m_rotation"));
1074

    
1075
        if (xml.contains("m_units")) { //Comprobaci?n por versi?n 0.5
1076
            setUnits(xml.getIntProperty("m_units"));
1077
        }
1078

    
1079
        if (xml.contains("index")) {
1080
            dependenceIndex = xml.getIntProperty("index");
1081
        }
1082

    
1083

    
1084
        if (xml.contains("showDescription")) { //Comprobar que es de la versi?n que cambia el di?logo.
1085
            this.barcolor = StringUtilities.string2Color(xml.getStringProperty(
1086
            "barcolor"));
1087

    
1088
            this.textcolor = StringUtilities.string2Color(xml.getStringProperty(
1089
                        "textcolor"));
1090
            this.showNameUnits = xml.getBooleanProperty("showNameUnits");
1091
            this.showDescription = xml.getBooleanProperty("showDescription");
1092
            this.aboveName = xml.getBooleanProperty("aboveName");
1093
            this.aboveIntervals = xml.getBooleanProperty("aboveIntervals");
1094
            this.aboveDescription = xml.getBooleanProperty("aboveDescription");
1095
        }
1096

    
1097
        if (xml.contains("numDec")) {
1098
            setNumDec(xml.getIntProperty("numDec"));
1099
        }
1100
    }
1101

    
1102
    /**
1103
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getNameFFrame()
1104
     */
1105
    public String getNameFFrame() {
1106
        return PluginServices.getText(this, "escala")+ num;
1107
    }
1108

    
1109
    /**
1110
     * Inserta el color de la escala gr?fica.
1111
     *
1112
     * @param color Color de la escala gr?fica.
1113
     */
1114
    public void setBarColor(Color color) {
1115
        barcolor = color;
1116
    }
1117

    
1118
    /**
1119
     * Inserta el color del texto.
1120
     *
1121
     * @param color Color del texto.
1122
     */
1123
    public void setTextColor(Color color) {
1124
        textcolor = color;
1125
    }
1126

    
1127
    /**
1128
     * Devuelve el color de la escala gr?fica.
1129
     *
1130
     * @return Color de la escala gr?fica.
1131
     */
1132
    public Color getBarColor() {
1133
        return barcolor;
1134
    }
1135

    
1136
    /**
1137
     * Devuelve el color del texto.
1138
     *
1139
     * @return Color del texto.
1140
     */
1141
    public Color getTextColor() {
1142
        return textcolor;
1143
    }
1144

    
1145
    /**
1146
     * Devuelve true si se debe mostrar el nombre de las unidades de medida de
1147
     * la escala gr?fica.
1148
     *
1149
     * @return True si se muestra las unidades de medida.
1150
     */
1151
    public boolean isShowNameUnits() {
1152
        return showNameUnits;
1153
    }
1154

    
1155
    /**
1156
     * Inserta si se debe de mostrar el nombre de las unidades de medida o no.
1157
     *
1158
     * @param showNameUnits True si se muestra el nombre de las unidades de
1159
     *        medida.
1160
     */
1161
    public void setShowNameUnits(boolean showNameUnits) {
1162
        this.showNameUnits = showNameUnits;
1163
    }
1164

    
1165
    /**
1166
     * Devuelve true si se muestra la descripci?n a la parte de arriba de la
1167
     * escala gr?fica.
1168
     *
1169
     * @return True si se muestra arriba de la escala gr?fica.
1170
     */
1171
    public boolean isAboveDescription() {
1172
        return aboveDescription;
1173
    }
1174

    
1175
    /**
1176
     * Introduce true si se muestra arriba de la escala gr?fica la descripci?n.
1177
     *
1178
     * @param aboveDescription True si se muestra arriba la descripci?n.
1179
     */
1180
    public void setAboveDescription(boolean aboveDescription) {
1181
        this.aboveDescription = aboveDescription;
1182
    }
1183

    
1184
    /**
1185
     * Devuelve true si se muestran a la parte de arriba los valores de los
1186
     * intervalos.
1187
     *
1188
     * @return True si se muestran arriba de la escala gr?fica.
1189
     */
1190
    public boolean isAboveIntervals() {
1191
        return aboveIntervals;
1192
    }
1193

    
1194
    /**
1195
     * Inserta si se muestran los valores de los intervalos a la parte de
1196
     * arriba de la escala o debajo.
1197
     *
1198
     * @param aboveIntervals True si se muestran los valores de los intervalos
1199
     *        a la parte de arriba de la escala gr?fica.
1200
     */
1201
    public void setAboveIntervals(boolean aboveIntervals) {
1202
        this.aboveIntervals = aboveIntervals;
1203
    }
1204

    
1205
    /**
1206
     * Devuelve si se muestra a la parte de arriba de la escala gr?fica el
1207
     * nombre de las unidades de medida o debajo.
1208
     *
1209
     * @return True si se muestra a la parte de arriba de la escala gr?fica.
1210
     */
1211
    public boolean isAboveName() {
1212
        return aboveName;
1213
    }
1214

    
1215
    /**
1216
     * Inserta si el nombre se muestra a la parte de arriba de la escala
1217
     * gr?fica o a la parte de abajo.
1218
     *
1219
     * @param aboveName True si se muestra a la parte de arriba de la escala
1220
     *        gr?fica.
1221
     */
1222
    public void setAboveName(boolean aboveName) {
1223
        this.aboveName = aboveName;
1224
    }
1225

    
1226
    /**
1227
     * Devuelve si se debe mostrar la descripci?n o no.
1228
     *
1229
     * @return True si se muestra la descripci?n.
1230
     */
1231
    public boolean isShowDescription() {
1232
        return showDescription;
1233
    }
1234

    
1235
    /**
1236
     * Inserta si se muestra o no la descripci?n.
1237
     *
1238
     * @param showDescription True si se muestra la descripci?n.
1239
     */
1240
    public void setShowDescription(boolean showDescription) {
1241
        this.showDescription = showDescription;
1242
    }
1243

    
1244
    /**
1245
     * Devuelve la descripci?n de la escala.
1246
     *
1247
     * @return Descripci?n de la escala.
1248
     */
1249
    public String getDescription() {
1250
        if (fframeview!=null){
1251
                if (fframeview.getScale()==0){
1252
                        return PluginServices.getText(this,"escala_desconocida");
1253
                }
1254
            return "1:" + String.valueOf(fframeview.getScale());
1255
        }
1256
            return "1:";
1257
    }
1258

    
1259
    /**
1260
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#print(java.awt.Graphics2D,
1261
     *      java.awt.geom.AffineTransform)
1262
     */
1263
    public void print(Graphics2D g, AffineTransform at, FShape shape)
1264
        throws ReadDriverException {
1265
        draw(g, at, null, null);
1266
    }
1267

    
1268
    /**
1269
     * Update the dependences that have this FFrame with the other FFrame.
1270
     *
1271
     * @param fframes Other FFrames.
1272
     */
1273
    public void initDependence(IFFrame[] fframes) {
1274
        if ((dependenceIndex != -1) &&
1275
                fframes[dependenceIndex] instanceof FFrameView) {
1276
            fframeview = (FFrameView) fframes[dependenceIndex];
1277
        }
1278
    }
1279

    
1280
    /**
1281
     * DOCUMENT ME!
1282
     *
1283
     * @param d DOCUMENT ME!
1284
     *
1285
     * @return DOCUMENT ME!
1286
     */
1287
    public String format(double d) {
1288
        if ((d % (long) d) != 0) {
1289
            numberFormat.setMaximumFractionDigits(getNumDec());
1290
        } else {
1291
            numberFormat.setMaximumFractionDigits(0);
1292
        }
1293

    
1294
        //String s = String.valueOf(nf.format(d));
1295
        //s=s.replace('.','*');
1296
        //s = s.replace(',', '.');
1297
        //s=s.replace('*',',');
1298
        return numberFormat.format(d); //(Double.valueOf(s).doubleValue());
1299
    }
1300

    
1301
    /**
1302
     * DOCUMENT ME!
1303
     *
1304
     * @return DOCUMENT ME!
1305
     */
1306
    public int getNumDec() {
1307
        return numDec;
1308
    }
1309

    
1310
    /**
1311
     * DOCUMENT ME!
1312
     *
1313
     * @param numDec DOCUMENT ME!
1314
     */
1315
    public void setNumDec(int numDec) {
1316
        this.numDec = numDec;
1317
    }
1318

    
1319
    public void initialize() {
1320
        // TODO Auto-generated method stub
1321

    
1322
    }
1323
    private final static int DUIB=0;
1324
    private final static int DUBI=1;
1325
    private final static int DBIU=2;
1326
    private final static int DIBU=3;
1327
    private final static int UIBD=4;
1328
    private final static int UBID=5;
1329
    private final static int IBUD=6;
1330
    private final static int BIUD=7;
1331

    
1332
    private int getFormat(){
1333
        if (isAboveDescription()){
1334
            if (isAboveName()){
1335
                if (isAboveIntervals()){
1336
                    return DUIB;
1337
                }
1338
                return DUBI;
1339
            }
1340
            if (isAboveIntervals()){
1341
                    return DIBU;
1342
                }
1343
                return DBIU;
1344
        }
1345
        if (isAboveName()){
1346
            if (isAboveIntervals()){
1347
                return UIBD;
1348
            }
1349
            return UBID;
1350
        }
1351
        if (isAboveIntervals()){
1352
            return IBUD;
1353
        }
1354
        return BIUD;
1355
    }
1356

    
1357
        public void cloneActions(IFFrame frame) {
1358
                // TODO Auto-generated method stub
1359

    
1360
        }
1361

    
1362
        public IFFrameDialog getPropertyDialog() {
1363
                return new FFrameScaleBarDialog(getLayout(),this);
1364
        }
1365
}