Revision 2762 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/layout/fframes/FFrameScaleBar.java

View differences:

FFrameScaleBar.java
44 44
 */
45 45
package com.iver.cit.gvsig.gui.layout.fframes;
46 46

  
47
import com.iver.andami.PluginServices;
48

  
49
import com.iver.cit.gvsig.LayoutControls;
50
import com.iver.cit.gvsig.fmap.DriverException;
51
import com.iver.cit.gvsig.fmap.FMap;
52
import com.iver.cit.gvsig.gui.layout.Attributes;
53
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities;
54
import com.iver.cit.gvsig.gui.layout.Layout;
55

  
56
import com.iver.utiles.StringUtilities;
57
import com.iver.utiles.XMLEntity;
58

  
47 59
import java.awt.BasicStroke;
48 60
import java.awt.Color;
49 61
import java.awt.Font;
......
53 65
import java.awt.geom.Point2D;
54 66
import java.awt.geom.Rectangle2D;
55 67
import java.awt.image.BufferedImage;
68

  
56 69
import java.util.ArrayList;
57 70

  
58
import com.iver.andami.PluginServices;
59
import com.iver.cit.gvsig.LayoutControls;
60
import com.iver.cit.gvsig.fmap.DriverException;
61
import com.iver.cit.gvsig.fmap.FMap;
62
import com.iver.cit.gvsig.gui.layout.Attributes;
63
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities;
64
import com.iver.cit.gvsig.gui.layout.Layout;
65
import com.iver.utiles.StringUtilities;
66
import com.iver.utiles.XMLEntity;
67 71

  
68

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

  
94
	//private FMap m_fmap = null;
95
	private FFrameView fframeview = null;
96
	private double m_typeUnit = Attributes.CHANGE[1]; //METROS;
97
	private String m_nameUnit = null;
98
	private double m_numUnit = 0;
99
	private double m_dif = 1;
100
	private int m_hasleft = 0;
101
	private Font m_f = new Font("SansSerif", Font.PLAIN, 9);
102
	
103
	private Color barcolor = Color.black;
104
	private Color textcolor = Color.black;
105
	private boolean showNameUnits = true;
106
	private boolean showDescription = false;
107
	private boolean aboveName = false;
108
	private boolean aboveIntervals = true;
109
	private boolean aboveDescription = false;
110
	private String description = "";
111
    /**
112
     * Creates a new FFrameScaleBar object.
113
     */
114
    public FFrameScaleBar() {
115
    }
111 116

  
112
	/**
113
	 * Creates a new FFrameScaleBar object.
114
	 */
115
	public FFrameScaleBar() {
116
	}
117
    /**
118
     * Inserta el FFrameView sobre el que obtener la escala gr?fica.
119
     *
120
     * @param f FFrameView sobre  el que obtener la escala.
121
     */
122
    public void setFFrameView(FFrameView f) {
123
        fframeview = f;
124
        setMapUnits(f.getMapUnits());
125
        setHeight(f.getBoundBox().height);
126
        description = "escala 1:" + String.valueOf(fframeview.getScale());
127
    }
117 128

  
118
	/**
119
	 * Inserta el FFrameView sobre el que obtener la escala gr?fica.
120
	 *
121
	 * @param f FFrameView sobre  el que obtener la escala.
122
	 */
123
	public void setFFrameView(FFrameView f) {
124
		fframeview = f;
125
		//view = f.getView();
126
		setMapUnits(f.getMapUnits());
129
    /**
130
     * Devuelve el FFrameView que se representa con la escala.
131
     *
132
     * @return FFrameView a representar.
133
     */
134
    public FFrameView getFFrameView() {
135
        return fframeview;
136
    }
127 137

  
128
		//setFMap(f.getFMap());
129
		setHeight(f.getBoundBox().height);
130
		description = "escala 1:" + String.valueOf(fframeview.getScale());
138
    /**
139
     * Devuelve el FMap de la vista que se representa en la escala.
140
     *
141
     * @return FMap.
142
     */
143
    public FMap getFMap() {
144
        return fframeview.getFMap();
145
    }
131 146

  
132
		/*if (f.getTypeScale()!=0){
133
		   isFixed=true;
134
		   }else{
135
		           isFixed=false;
136
		   }
137
		 */
138
	}
147
    /**
148
     * Rellenar el estilo de barra de escala que se elige.
149
     *
150
     * @param s entero que representa el tipo de barra seleccionada.
151
     */
152
    public void setStyle(int s) {
153
        m_style = s;
154
    }
139 155

  
140
	/**
141
	 * Devuelve el FFrameView que se representa con la escala.
142
	 *
143
	 * @return FFrameView a representar.
144
	 */
145
	public FFrameView getFFrameView() {
146
		return fframeview;
147
	}
156
    /**
157
     * Devuelve el tipo de escala a dibujar.
158
     *
159
     * @return entero.
160
     */
161
    public int getStyle() {
162
        return m_style;
163
    }
148 164

  
149
	/**
150
	 * Pone el FMap de la vista que representa a la escala.
151
	 *
152
	 * @return DOCUMENT ME!
153
	 */
165
    /**
166
     * Rellenar el tama?o de un intervalo.
167
     *
168
     * @param s tama?o de un intervalo.
169
     */
170
    public void setInterval(long s) {
171
        m_interval = s;
154 172

  
155
	/*  public void setFMap(FMap map) {
156
	   m_fmap = map;
157
	   }
158
	 */
173
        if (m_numleft != 0) {
174
            m_hasleft = 1;
175
        }
159 176

  
160
	/**
161
	 * Devuelve el FMap de la vista que se representa en la escala.
162
	 *
163
	 * @return FMap.
164
	 */
165
	public FMap getFMap() {
166
		return fframeview.getFMap();
167
	}
177
        Rectangle2D.Double rect = getBoundBox();
178
        double difL = (rect.width / DIFL);
179
        double difR = (rect.width / DIFR);
180
        double n = (rect.width - difL - difR);
181
        m_numUnit = (m_interval * m_typeUnit) / getScaleView();
182
        m_numinterval = (int) (n / m_numUnit) - m_hasleft;
183
        m_dif = 1;
184
    }
168 185

  
169
	/**
170
	 * Rellenar el estilo de barra de escala que se elige.
171
	 *
172
	 * @param s entero que representa el tipo de barra seleccionada.
173
	 */
174
	public void setStyle(int s) {
175
		m_style = s;
176
	}
186
    /**
187
     * Devuelve el valor del intervalo.
188
     *
189
     * @return long.
190
     */
191
    public long obtainInterval() {
192
        if (fframeview != null) {
193
            Rectangle2D.Double rect = getBoundBox();
177 194

  
178
	/**
179
	 * Devuelve el tipo de escala a dibujar.
180
	 *
181
	 * @return entero.
182
	 */
183
	public int getStyle() {
184
		return m_style;
185
	}
195
            if (m_numleft != 0) {
196
                m_hasleft = 1;
197
            }
186 198

  
187
	/**
188
	 * Rellenar el tama?o de un intervalo.
189
	 *
190
	 * @param s tama?o de un intervalo.
191
	 */
192
	public void setInterval(long s) {
193
		m_interval = s;
199
            double difL = (rect.width / DIFL);
200
            double difR = (rect.width / DIFR);
201
            double n = (rect.width - difL - difR);
202
            m_numUnit = n / (m_numinterval + m_hasleft);
194 203

  
195
		if (m_numleft != 0) {
196
			m_hasleft = 1;
197
		}
204
            double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
205
            m_dif = getExact(scaleXunit);
206
            m_numUnit = m_numUnit * m_dif;
207
            m_interval = (long) (scaleXunit * m_dif);
198 208

  
199
		Rectangle2D.Double rect = getBoundBox();
200
		//double difUp = (rect.height / DIFUP);
201
		double difL = (rect.width / DIFL);
202
		double difR = (rect.width / DIFR);
203
		double n = (rect.width - difL - difR);
204
		m_numUnit = (m_interval * m_typeUnit) / getScaleView();
205
		m_numinterval = (int) (n / m_numUnit) - m_hasleft;
206
		m_dif = 1;
207
	}
209
            return m_interval;
210
        }
208 211

  
209
	/**
210
	 * Devuelve el valor del intervalo.
211
	 *
212
	 * @return long.
213
	 */
214
	public long obtainInterval() {
215
		if (fframeview!=null){
216
		Rectangle2D.Double rect = getBoundBox();
212
        return 0;
213
    }
217 214

  
218
		if (m_numleft != 0) {
219
			m_hasleft = 1;
220
		}
215
    /**
216
     * Rellenar el n?mero de intervalos.
217
     *
218
     * @param s n?mero de intervalos.
219
     */
220
    public void setNumInterval(int s) {
221
        m_numinterval = s;
221 222

  
222
		//double difUp = (rect.height / DIFUP);
223
		double difL = (rect.width / DIFL);
224
		double difR = (rect.width / DIFR);
225
		double n = (rect.width - difL - difR);
226
		m_numUnit = n / (m_numinterval + m_hasleft);
223
        if (m_numleft != 0) {
224
            m_hasleft = 1;
225
        }
227 226

  
228
		double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
229
		m_dif = getExact(scaleXunit);
230
		m_numUnit = m_numUnit * m_dif;
231
		m_interval = (long) (scaleXunit * m_dif);
227
        Rectangle2D.Double rect = getBoundBox();
228
        double difL = (rect.width / DIFL);
229
        double difR = (rect.width / DIFR);
230
        double n = (rect.width - difL - difR);
231
        m_numUnit = n / (m_numinterval + m_hasleft);
232 232

  
233
		return m_interval;
234
		}
235
		return 0;
236
	}
233
        double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
234
        m_dif = getExact(scaleXunit);
235
        m_numUnit = m_numUnit * m_dif;
236
        m_interval = (long) (scaleXunit * m_dif);
237
    }
237 238

  
238
	/**
239
	 * Rellenar el n?mero de intervalos.
240
	 *
241
	 * @param s n?mero de intervalos.
242
	 */
243
	public void setNumInterval(int s) {
244
		m_numinterval = s;
239
    /**
240
     * Devuelve el n?mero de intervalos por encima del cero.
241
     *
242
     * @return entero.
243
     */
244
    public int getNumInterval() {
245
        return m_numinterval;
246
    }
245 247

  
246
		if (m_numleft != 0) {
247
			m_hasleft = 1;
248
		}
248
    /**
249
     * Rellenar el n?mero de intervalos a la izquierda del cero.
250
     *
251
     * @param s n?mero de intervalos a la izquierda.
252
     */
253
    public void setNumLeft(int s) {
254
        m_numleft = s;
255
    }
249 256

  
250
		Rectangle2D.Double rect = getBoundBox();
251
		//double difUp = (rect.height / DIFUP);
252
		double difL = (rect.width / DIFL);
253
		double difR = (rect.width / DIFR);
254
		double n = (rect.width - difL - difR);
255
		m_numUnit = n / (m_numinterval + m_hasleft);
257
    /**
258
     * Devuelve el n?mero de intervalos  en los que se quiere particionar el
259
     * intervalo  que se queda por debajo del cero.
260
     *
261
     * @return entero.
262
     */
263
    public int getNumLeft() {
264
        return m_numleft;
265
    }
256 266

  
257
		double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
258
		m_dif = getExact(scaleXunit);
259
		m_numUnit = m_numUnit * m_dif;
260
		m_interval = (long) (scaleXunit * m_dif);
261
	}
267
    /**
268
     * Seleccionar ,a true, si se quiere o, a false, si no mantener los
269
     * intervalos.
270
     *
271
     * @param b boolean a true si se quiere mantener los intervalos.
272
     */
273
    public void setIntervalSet(boolean b) {
274
        m_bIntervalSet = b;
275
    }
262 276

  
263
	/**
264
	 * Devuelve el n?mero de intervalos por encima del cero.
265
	 *
266
	 * @return entero.
267
	 */
268
	public int getNumInterval() {
269
		return m_numinterval;
270
	}
277
    /**
278
     * Seleccionar la unidad de medida a representar en la barra de escala.
279
     *
280
     * @param s entero que representa la unidad de medida que se selecciona.
281
     */
282
    public void setUnits(int s) {
283
        m_units = s;
284
        m_typeUnit = Attributes.CHANGE[s];
285
        m_nameUnit = Attributes.NAMES[s];
286
    }
271 287

  
272
	/**
273
	 * Rellenar el n?mero de intervalos a la izquierda del cero.
274
	 *
275
	 * @param s n?mero de intervalos a la izquierda.
276
	 */
277
	public void setNumLeft(int s) {
278
		m_numleft = s;
279
	}
288
    /**
289
     * Devuelve un entero que representa el tipo de unidades que representamos.
290
     *
291
     * @return entero.
292
     */
293
    public int getUnits() {
294
        return m_units;
295
    }
280 296

  
281
	/**
282
	 * Devuelve el n?mero de intervalos  en los que se quiere particionar el
283
	 * intervalo  que se queda por debajo del cero.
284
	 *
285
	 * @return entero.
286
	 */
287
	public int getNumLeft() {
288
		return m_numleft;
289
	}
297
    /**
298
     * Devuelve el long que representa el intervalo.
299
     *
300
     * @return Intervalo.
301
     */
302
    public long getInterval() {
303
        return m_interval;
304
    }
290 305

  
291
	/**
292
	 * Seleccionar ,a true, si se quiere o, a false, si no mantener los
293
	 * intervalos.
294
	 *
295
	 * @param b boolean a true si se quiere mantener los intervalos.
296
	 */
297
	public void setIntervalSet(boolean b) {
298
		m_bIntervalSet = b;
299
	}
306
    /**
307
     * Rellenar el rect?ngulo de la vista sobre la que se obtiene la escala.
308
     *
309
     * @param d Rect?ngulo.
310
     */
311
    public void setHeight(double d) {
312
        m_height = d;
313
    }
300 314

  
301
	/**
302
	 * Seleccionar la unidad de medida a representar en la barra de escala.
303
	 *
304
	 * @param s entero que representa la unidad de medida que se selecciona.
305
	 */
306
	public void setUnits(int s) {
307
		m_units = s;
308
		m_typeUnit = Attributes.CHANGE[s];
309
		m_nameUnit = Attributes.NAMES[s];
310
	}
315
    /**
316
     * Rellena la unidad de medida en la que est? la vista.
317
     *
318
     * @param i entero que representa la unidad de medida de la vista.
319
     */
320
    public void setMapUnits(int i) {
321
        m_mapUnits = i;
322
    }
311 323

  
312
	/**
313
	 * Devuelve un entero que representa el tipo de unidades que representamos.
314
	 *
315
	 * @return entero.
316
	 */
317
	public int getUnits() {
318
		return m_units;
319
	}
324
    /**
325
     * Devuelve la escala de la vista seleccionada.
326
     *
327
     * @return la escala de la vista.
328
     */
329
    private long getScaleView() {
330
        return fframeview.getScale();
331
    }
320 332

  
321
	/**
322
	 * Devuelve el long que representa el intervalo.
323
	 *
324
	 * @return Intervalo.
325
	 */
326
	public long getInterval() {
327
		return m_interval;
328
	}
333
    /**
334
     * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
335
     * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
336
     * de dibujar.
337
     *
338
     * @param g Graphics
339
     * @param at Transformada afin.
340
     * @param rv rect?ngulo sobre el que hacer un clip.
341
     * @param imgBase Image para acelerar el dibujado.
342
     */
343
    public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,
344
        BufferedImage imgBase) {
345
        Rectangle2D.Double r = getBoundingBox(at);
346
        g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2),
347
            r.y + (r.height / 2));
329 348

  
330
	/**
331
	 * Rellenar el rect?ngulo de la vista sobre la que se obtiene la escala.
332
	 *
333
	 * @param d Rect?ngulo.
334
	 */
335
	public void setHeight(double d) {
336
		m_height = d;
337
	}
349
        if (intersects(rv, r)) {
350
            if ((fframeview == null) || (fframeview.getFMap() == null)) {
351
                drawEmpty(g);
352
            } else {
353
                switch (m_style) {
354
                    case (NUMERO):
338 355

  
339
	/**
340
	 * Rellena la unidad de medida en la que est? la vista.
341
	 *
342
	 * @param i entero que representa la unidad de medida de la vista.
343
	 */
344
	public void setMapUnits(int i) {
345
		m_mapUnits = i;
346
	}
356
                        double scalex = r.getWidth() / (8);
357
                        g.setColor(textcolor);
347 358

  
348
	/*public void setIsFixed(boolean b){
349
	   isFixed=b;
350
	   }*/
351
	/*public void setScaleView(long l){
352
	   m_scaleView=l;
353
	   }
354
	 */
359
                        if (m_f != null) {
360
                            m_f = new Font(m_f.getFontName(), m_f.getStyle(),
361
                                    (int) (scalex));
362
                            g.setFont(m_f);
363
                        }
355 364

  
356
	/**
357
	 * Devuelve la escala de la vista seleccionada.
358
	 *
359
	 * @return la escala de la vista.
360
	 */
361
	private long getScaleView() {
362
		return fframeview.getScale();
365
                        g.drawString(" 1:" + getScaleView(), (int) r.x,
366
                            (int) (r.y + (r.height / 2)));
363 367

  
364
		/*        if (isFixed){
365
		   return m_scaleView;
366
		   }
367
		   return FLayoutUtilities.getScaleView(m_fmap, m_height);
368
		 */
369
	}
368
                        break;
370 369

  
371
	/**
372
	 * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
373
	 * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
374
	 * de dibujar.
375
	 *
376
	 * @param g Graphics
377
	 * @param at Transformada afin.
378
	 * @param rv rect?ngulo sobre el que hacer un clip.
379
	 * @param imgBase Image para acelerar el dibujado.
380
	 */
381
	public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,
382
		BufferedImage imgBase) {
383
		Rectangle2D.Double r = getBoundingBox(at);
384
		g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2),
385
				r.y + (r.height / 2));
386
		if (intersects(rv, r)) {
387
			if ((fframeview == null) || (fframeview.getFMap() == null)) {
388
				drawEmpty(g);
389
			} else {
390
				switch (m_style) {
391
					case (NUMERO):
370
                    case (BARRA1):
371
                    case (BARRA2):
372
                    case (BARRA3):
373
                    case (BARRA4):
374
                        drawBar(m_style, g, at);
392 375

  
393
						double scalex = r.getWidth() / (8);
394
						g.setColor(textcolor);
376
                        break;
377
                }
378
            }
379
        }
395 380

  
396
						if (m_f != null) {
397
							m_f = new Font(m_f.getFontName(), m_f.getStyle(),
398
									(int) (scalex));
399
							g.setFont(m_f);
400
						}
381
        g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2),
382
            r.y + (r.height / 2));
383
    }
401 384

  
402
						g.drawString(" 1:" + getScaleView(), (int) r.x,
403
							(int) (r.y + (r.height / 2)));
385
    /**
386
     * Rellena con el rect?ngulo que se pasa como par?metro el boundBox(en
387
     * cent?metros) del fframe del cual con una transformaci?n se podr?
388
     * calcular el BoundingBox (en pixels).
389
     *
390
     * @param r Rect?ngulo en cent?metros.
391
     */
392
    public void setBoundBox(Rectangle2D.Double r) {
393
        if ((m_numUnit < 1) || (fframeview == null) ||
394
                (fframeview.getFMap() == null)) {
395
            super.setBoundBox(r);
404 396

  
405
						//System.out.println("Escala real  " + getScaleView());
406
						break;
397
            return;
398
        }
407 399

  
408
					case (BARRA1):
409
					case (BARRA2):
410
					case (BARRA3):
411
					case (BARRA4):
412
						drawBar(m_style, g, at);
400
        double difL = (r.width / DIFL);
401
        double difR = (r.width / DIFR);
413 402

  
414
						break;
415
				}
416
			}
417
		}
418
		g.rotate(Math.toRadians(-getRotation()),
419
				r.x + (r.width / 2), r.y + (r.height / 2));
420
	}
403
        if (m_bIntervalSet) {
404
            m_numinterval = (int) (((r.width - (difL + difR)) * m_dif) / m_numUnit) -
405
                m_hasleft;
406
        }
421 407

  
422
	/**
423
	 * Rellena con el rect?ngulo que se pasa como par?metro el boundBox(en
424
	 * cent?metros) del fframe del cual con una transformaci?n se podr?
425
	 * calcular el BoundingBox (en pixels).
426
	 *
427
	 * @param r Rect?ngulo en cent?metros.
428
	 */
429
	public void setBoundBox(Rectangle2D.Double r) {
430
		if ((m_numUnit < 1) || (fframeview==null) || (fframeview.getFMap() == null)) {
431
			super.setBoundBox(r);
408
        if (m_numinterval < 1) {
409
            m_numinterval = 1;
410
            r.width = ((m_numinterval + m_hasleft) * m_numUnit) + difL + difR;
411
        }
432 412

  
433
			return;
434
		}
413
        getBoundBox().setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
414
    }
435 415

  
436
		double difL = (r.width / DIFL);
437
		double difR = (r.width / DIFR);
416
    /**
417
     * Dibuja sobre el Graphics la escala gr?fica.
418
     *
419
     * @param type Tipo de barra.
420
     * @param g Graphics sobre el que dibujar.
421
     * @param at Matriz de transformaci?n.
422
     */
423
    private void drawBar(int type, Graphics2D g, AffineTransform at) {
424
        Rectangle2D.Double rect = getBoundBox();
425
        Rectangle2D.Double r = getBoundingBox(at);
426
        double numleft = m_numleft;
427
        initDistances();
438 428

  
439
		if (m_bIntervalSet) {
440
			m_numinterval = (int) (((r.width - (difL + difR)) * m_dif) / m_numUnit) -
441
				m_hasleft;
442
		}
429
        double difDown = (rect.height / DIFDOWN);
430
        double difUp = (rect.height / DIFUP);
431
        double difL = (rect.width / DIFL);
432
        double difR = (rect.width / DIFR);
433
        double n = (rect.width - difL - difR);
443 434

  
444
		if (m_numinterval < 1) {
445
			m_numinterval = 1;
446
			r.width = ((m_numinterval + m_hasleft) * m_numUnit) + difL + difR;
447
		}
435
        setDescripcion("escala 1:" + String.valueOf(fframeview.getScale()));
436
        g.setStroke(new BasicStroke(0));
448 437

  
449
		getBoundBox().setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
450
	}
438
        if (!m_bIntervalSet) {
439
            m_numUnit = n / (m_numinterval + m_hasleft);
451 440

  
452
	/**
453
	 * Dibuja sobre el Graphics la escala gr?fica.
454
	 *
455
	 * @param type Tipo de barra.
456
	 * @param g Graphics sobre el que dibujar.
457
	 * @param at Matriz de transformaci?n.
458
	 */
459
	private void drawBar(int type, Graphics2D g, AffineTransform at) {
460
		Rectangle2D.Double rect = getBoundBox();
461
		Rectangle2D.Double r = getBoundingBox(at);
462
		double numleft = m_numleft;
463
		initDistances();
441
            double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
442
            m_dif = getExact(scaleXunit);
443
            m_numUnit = m_numUnit * m_dif;
444
            m_interval = (long) (scaleXunit * m_dif);
445
        }
464 446

  
465
		double difDown = (rect.height / DIFDOWN);
466
		double difUp = (rect.height / DIFUP);
467
		double difL = (rect.width / DIFL);
468
		double difR = (rect.width / DIFR);
447
        if (m_bIntervalSet) {
448
            m_numUnit = (m_interval * m_typeUnit) / (m_dif * getScaleView());
449
            m_numinterval = (int) (((rect.width - (difL + difR)) * m_dif) / m_numUnit) -
450
                m_hasleft;
451
        }
469 452

  
470
		//double difUp = (rect.height / DIFUP);
471
		//double difL = (rect.width / DIFL);
472
		//double difR = (rect.width / DIFR);
473
		double n = (rect.width - difL - difR);
453
        if (m_numinterval < 1) {
454
            m_numinterval = 1;
455
            rect.width = ((m_numinterval + m_hasleft) * m_numUnit) + difL +
456
                difR;
457
        }
474 458

  
475
		//double scalex = r.getWidth() / (8);
476
		setDescripcion("escala 1:" + String.valueOf(fframeview.getScale()));
477
		g.setStroke(new BasicStroke(0));
459
        double h = 0;
478 460

  
479
		if (!m_bIntervalSet) {
480
			m_numUnit = n / (m_numinterval + m_hasleft);
461
        if (type == BARRA1) {
462
            h = (rect.height - (difUp + difDown));
463
        } else if ((type == BARRA2) || (type == BARRA3)) {
464
            h = (rect.height - (difUp + difDown)) / 2;
465
        }
481 466

  
482
			double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
483
			m_dif = getExact(scaleXunit);
484
			m_numUnit = m_numUnit * m_dif;
485
			m_interval = (long) (scaleXunit * m_dif);
486
		}
467
        //Dibujar el rect?ngulo que bordea todo.
468
        Rectangle2D.Double rectotal = (FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
469
                    difL), (rect.y + difUp),
470
                    m_numUnit * (m_hasleft + m_numinterval), h), at));
471
        g.setColor(Color.white);
472
        g.fillRect((int) rectotal.x, (int) rectotal.y, (int) (rectotal.width),
473
            (int) rectotal.height);
474
        g.setColor(barcolor);
487 475

  
488
		if (m_bIntervalSet) {
489
			m_numUnit = (m_interval * m_typeUnit) / (m_dif * getScaleView());
490
			m_numinterval = (int) (((rect.width - (difL + difR)) * m_dif) / m_numUnit) -
491
				m_hasleft;
492
		}
476
        if (m_f != null) {
477
            m_f = new Font(m_f.getFontName(), m_f.getStyle(),
478
                    (int) (r.getHeight() / 4));
479
        } else {
480
            m_f = new Font("SansSerif", Font.PLAIN, (int) (r.getHeight() / 4));
481
        }
493 482

  
494
		if (m_numinterval < 1) {
495
			m_numinterval = 1;
496
			rect.width = ((m_numinterval + m_hasleft) * m_numUnit) + difL +
497
				difR;
498
		}
483
        g.setFont(m_f);
499 484

  
500
		double h = 0;
485
        //Derecha del cero
486
        for (int i = 0; i < m_numinterval; i++) {
487
            Rectangle2D.Double recder = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
488
                        (difL) + ((m_numUnit * i) + (m_hasleft * m_numUnit))),
489
                        (rect.y + (difUp)), (m_numUnit),
490
                        (rect.height - (difUp + difDown)) / 2), at);
491
            Rectangle2D.Double recderB = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
492
                        (difL) + ((m_numUnit * i) + (m_hasleft * m_numUnit))),
493
                        (rect.y + difUp) +
494
                        ((rect.height - (difUp + difDown)) / 2), (m_numUnit),
495
                        ((rect.height - (difUp + difDown)) / 2)), at);
501 496

  
502
		if (type == BARRA1) {
503
			h = (rect.height - (difUp + difDown));
504
		} else if ((type == BARRA2) || (type == BARRA3)) {
505
			h = (rect.height - (difUp + difDown)) / 2;
506
		}
497
            //			Correcci?n cuando la altura en pixels del rect?ngulo es impar.
498
            rectotal.y = recder.y;
499
            recderB.height = rectotal.height - recder.height + 0.5;
507 500

  
508
		//Dibujar el rect?ngulo que bordea todo.
509
		Rectangle2D.Double rectotal = (FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
510
					difL), (rect.y + difUp),
511
					m_numUnit * (m_hasleft + m_numinterval), h), at));
512
		g.setColor(Color.white);
513
		g.fillRect((int) rectotal.x, (int) rectotal.y, (int) (rectotal.width),
514
			(int) rectotal.height);
515
		g.setColor(barcolor);
501
            /**
502
             * if (i == (m_numinterval - 1)) { if (recder.getMaxX() !=
503
             * rectotal.getMaxX()) { recder.width = (recder.width +
504
             * recder.getMaxX()) - rectotal.getMaxX(); } if (recderB.getMaxX()
505
             * != rectotal.getMaxX()) { recderB.width = (recderB.width +
506
             * recderB.getMaxX()) - rectotal.getMaxX(); }} if
507
             * (recderB.getMaxY() != rectotal.getMaxY()) { recderB.height =
508
             * (recderB.height + recderB.getMaxY()) - rectotal.getMaxY(); }
509
             */
510
            if ((m_numleft % 2) == 0) {
511
                if ((i % 2) == 0) {
512
                    if ((type == BARRA1) || (type == BARRA2)) {
513
                        fillRect(g, recder);
514
                    } else if (type == BARRA3) {
515
                        g.drawRect((int) recder.x, (int) recder.y,
516
                            (int) recder.width, (int) recder.height);
517
                    }
518
                } else if (type == BARRA1) {
519
                    fillRect(g, recderB);
520
                }
521
            } else {
522
                if ((i % 2) != 0) {
523
                    if ((type == BARRA1) || (type == BARRA2)) {
524
                        fillRect(g, recder);
525
                    } else if (type == BARRA3) {
526
                        g.drawRect((int) recderB.x, (int) recderB.y,
527
                            (int) recderB.width, (int) recderB.height);
528
                    }
529
                } else if (type == BARRA1) {
530
                    fillRect(g, recderB);
531
                }
532
            }
516 533

  
517
		/*if (m_f!=null){
518
		   m_f = new Font(m_f.getFontName(), m_f.getStyle(),
519
		           (int) ((r.getWidth() / 8) / (m_numinterval + m_hasleft)));
520
		   }else{
521
		           m_f=new Font("SansSerif", Font.PLAIN, (int) ((r.getWidth() / 8) / (m_numinterval + m_hasleft)));
522
		   }*/
523
		if (m_f != null) {
524
			m_f = new Font(m_f.getFontName(), m_f.getStyle(),
525
					(int) (r.getHeight() / 4));
526
		} else {
527
			m_f = new Font("SansSerif", Font.PLAIN, (int) (r.getHeight() / 4));
528
		}
534
            long inter = (long) (m_interval * i);
535
            Long l = new Long(inter);
529 536

  
530
		g.setFont(m_f);
537
            int pos = ((int) (r.getHeight() / 4) * l.toString().length()) / 4;
531 538

  
532
		//Derecha del cero
533
		for (int i = 0; i < m_numinterval; i++) {
534
			Rectangle2D.Double recder = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
535
						(difL) + ((m_numUnit * i) + (m_hasleft * m_numUnit))),
536
						(rect.y + (difUp)), (m_numUnit),
537
						(rect.height - (difUp + difDown)) / 2), at);
538
			Rectangle2D.Double recderB = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
539
						(difL) + ((m_numUnit * i) + (m_hasleft * m_numUnit))),
540
						(rect.y + difUp) +
541
						((rect.height - (difUp + difDown)) / 2), (m_numUnit),
542
						((rect.height - (difUp + difDown)) / 2)), at);
539
            Point2D.Double p = null;
543 540

  
544
			//			Correcci?n cuando la altura en pixels del rect?ngulo es impar.
545
			rectotal.y = recder.y;
546
			recderB.height = rectotal.height - recder.height + 0.5;
541
            if (isAboveIntervals()) {
542
                p = new Point2D.Double(recder.x - pos,
543
                        r.getMinY() + (r.getHeight() / DIFUP));
544
            } else {
545
                p = new Point2D.Double(recder.x - pos,
546
                        ((r.getHeight() / 4) + r.getMaxY()) -
547
                        (r.getHeight() / DIFDOWN));
548
            }
547 549

  
548
			/**
549
			 * if (i == (m_numinterval - 1)) { if (recder.getMaxX() !=
550
			 * rectotal.getMaxX()) { recder.width = (recder.width +
551
			 * recder.getMaxX()) - rectotal.getMaxX(); } if (recderB.getMaxX()
552
			 * != rectotal.getMaxX()) { recderB.width = (recderB.width +
553
			 * recderB.getMaxX()) - rectotal.getMaxX(); }} if
554
			 * (recderB.getMaxY() != rectotal.getMaxY()) { recderB.height =
555
			 * (recderB.height + recderB.getMaxY()) - rectotal.getMaxY(); }
556
			 */
557
			if ((m_numleft % 2) == 0) {
558
				if ((i % 2) == 0) {
559
					if ((type == BARRA1) || (type == BARRA2)) {
560
						fillRect(g, recder);
561
					} else if (type == BARRA3) {
562
						g.drawRect((int) recder.x, (int) recder.y,
563
							(int) recder.width, (int) recder.height);
564
					}
565
				} else if (type == BARRA1) {
566
					fillRect(g, recderB);
567
				}
568
			} else {
569
				if ((i % 2) != 0) {
570
					if ((type == BARRA1) || (type == BARRA2)) {
571
						fillRect(g, recder);
572
					} else if (type == BARRA3) {
573
						g.drawRect((int) recderB.x, (int) recderB.y,
574
							(int) recderB.width, (int) recderB.height);
575
					}
576
				} else if (type == BARRA1) {
577
					fillRect(g, recderB);
578
				}
579
			}
550
            drawInterval(g, inter, p);
551
        }
580 552

  
581
			long inter = (long) (m_interval * i);
582
			Long l = new Long(inter);
553
        //?ltimo n?mero a dibujar.
554
        long inter = (long) (m_interval * m_numinterval);
555
        Long l = new Long(inter);
583 556

  
584
			/* int pos = ((int) (r.getWidth() / (m_numinterval + m_hasleft)) * l.toString()
585
			   .length()) / 24;
586
			 */
587
			int pos = ((int) (r.getHeight() / 4) * l.toString().length()) / 4;
557
        int pos = ((int) (r.getHeight() / 4) * l.toString().length()) / 4;
588 558

  
589
			///Point2D.Double p = new Point2D.Double(recder.x - pos, recder.y);
590
			Point2D.Double p = null;
559
        Point2D.Double p = null;
591 560

  
592
			if (isAboveIntervals()) {
593
				p = new Point2D.Double(recder.x - pos,
594
						r.getMinY() + (r.getHeight() / DIFUP));
595
			} else {
596
				p = new Point2D.Double(recder.x - pos,
597
						((r.getHeight() / 4) + r.getMaxY()) -
598
						(r.getHeight() / DIFDOWN));
599
			}
561
        if (isAboveIntervals()) {
562
            p = new Point2D.Double(rectotal.getMaxX() - pos,
563
                    r.getMinY() + (r.getHeight() / DIFUP));
564
        } else {
565
            p = new Point2D.Double(rectotal.getMaxX() - pos,
566
                    ((r.getHeight() / 4) + r.getMaxY()) -
567
                    (r.getHeight() / DIFDOWN));
568
        }
600 569

  
601
			drawInterval(g, inter, p);
602
		}
570
        drawInterval(g, inter, p);
603 571

  
604
		//?ltimo n?mero a dibujar.
605
		long inter = (long) (m_interval * m_numinterval);
606
		Long l = new Long(inter);
572
        //Izquierda del cero
573
        for (int i = 0; i < m_numleft; i++) {
574
            Rectangle2D.Double reciz = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
575
                        difL + ((m_numUnit / m_numleft) * i)),
576
                        (rect.y + difUp), (m_numUnit / numleft),
577
                        (rect.height - (difUp + difDown)) / 2), at);
578
            Rectangle2D.Double recizB = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
579
                        difL + ((m_numUnit / m_numleft) * i)),
580
                        (rect.y + difUp) +
581
                        ((rect.height - (difUp + difDown)) / 2),
582
                        (m_numUnit / numleft),
583
                        ((rect.height - (difUp + difDown)) / 2)), at);
607 584

  
608
		/* int pos = ((int) (r.getWidth() / (m_numinterval + m_hasleft)) * l.toString()
609
		   .length()) / 24;
610
		 */
611
		int pos = ((int) (r.getHeight() / 4) * l.toString().length()) / 4;
612
		Point2D.Double p = null;
585
            //Correcci?n cuando la altura en pixels del rectangulo es impar.
586
            reciz.y = rectotal.y;
587
            recizB.height = rectotal.height - reciz.height + 0.5;
613 588

  
614
		if (isAboveIntervals()) {
615
			p = new Point2D.Double(rectotal.getMaxX() - pos,
616
					r.getMinY() + (r.getHeight() / DIFUP));
617
		} else {
618
			p = new Point2D.Double(rectotal.getMaxX() - pos,
619
					((r.getHeight() / 4) + r.getMaxY()) -
620
					(r.getHeight() / DIFDOWN));
621
		}
589
            if ((i % 2) == 0) {
590
                if ((type == BARRA1) || (type == BARRA2)) {
591
                    fillRect(g, reciz);
592
                } else if (type == BARRA3) {
593
                    g.drawRect((int) reciz.x, (int) reciz.y, (int) reciz.width,
594
                        (int) reciz.height);
595
                }
596
            } else if (type == BARRA1) {
597
                fillRect(g, recizB);
598
            }
599
        }
622 600

  
623
		/* Point2D.Double p = new Point2D.Double(rectotal.getMaxX() - pos,
624
		   rectotal.y);
625
		 */
626
		drawInterval(g, inter, p);
601
        if (m_numleft > 0) {
602
            inter = (long) (m_interval);
603
            l = new Long(inter);
627 604

  
628
		//Izquierda del cero
629
		for (int i = 0; i < m_numleft; i++) {
630
			Rectangle2D.Double reciz = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
631
						difL + ((m_numUnit / m_numleft) * i)),
632
						(rect.y + difUp), (m_numUnit / numleft),
633
						(rect.height - (difUp + difDown)) / 2), at);
634
			Rectangle2D.Double recizB = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
635
						difL + ((m_numUnit / m_numleft) * i)),
636
						(rect.y + difUp) +
637
						((rect.height - (difUp + difDown)) / 2),
638
						(m_numUnit / numleft),
639
						((rect.height - (difUp + difDown)) / 2)), at);
605
            pos = ((int) (r.getHeight() / 4) * l.toString().length()) / 4;
640 606

  
641
			//Correcci?n cuando la altura en pixels del rectangulo es impar.
642
			reciz.y = rectotal.y;
643
			recizB.height = rectotal.height - reciz.height + 0.5;
607
            if (isAboveIntervals()) {
608
                p = new Point2D.Double(rectotal.x - pos,
609
                        r.getMinY() + (r.getHeight() / DIFUP));
610
            } else {
611
                p = new Point2D.Double(rectotal.x - pos,
612
                        ((r.getHeight() / 4) + r.getMaxY()) -
613
                        (r.getHeight() / DIFDOWN));
614
            }
644 615

  
645
			if ((i % 2) == 0) {
646
				if ((type == BARRA1) || (type == BARRA2)) {
647
					fillRect(g, reciz);
648
				} else if (type == BARRA3) {
649
					g.drawRect((int) reciz.x, (int) reciz.y, (int) reciz.width,
650
						(int) reciz.height);
651
				}
652
			} else if (type == BARRA1) {
653
				fillRect(g, recizB);
654
			}
655
		}
616
            drawInterval(g, inter, p);
617
        }
656 618

  
657
		if (m_numleft > 0) {
658
			inter = (long) (m_interval);
659
			l = new Long(inter);
619
        //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.
620
        if (m_numleft == 0) {
621
            Rectangle2D.Double recAux = FLayoutUtilities.fromSheetRect(new Rectangle2D.Double((rect.x +
622
                        difL + ((m_numUnit / 1) * 0)), (rect.y + difUp),
623
                        (m_numUnit / 1), (rect.height - (difUp + difDown)) / 2),
624
                    at);
625
            rectotal.x = rectotal.x + recAux.width;
626
            rectotal.width = rectotal.width - recAux.width;
627
        }
660 628

  
661
			/*pos = ((int) (r.getWidth() / (m_numinterval + m_hasleft)) * l.toString()
662
			   .length()) / 24;
663
			 */
664
			pos = ((int) (r.getHeight() / 4) * l.toString().length()) / 4;
629
        //Se dibuja el rect?ngulo que bordea toda la escala gr?fica.
630
        g.drawRect((int) rectotal.x, (int) rectotal.y, (int) (rectotal.width),
631
            (int) rectotal.height);
665 632

  
666
			if (isAboveIntervals()) {
667
				p = new Point2D.Double(rectotal.x - pos,
668
						r.getMinY() + (r.getHeight() / DIFUP));
669
			} else {
670
				p = new Point2D.Double(rectotal.x - pos,
671
						((r.getHeight() / 4) + r.getMaxY()) -
672
						(r.getHeight() / DIFDOWN));
673
			}
633
        drawNameUnits(g, rect, at);
634
        drawDescription(g, rect, at);
635
    }
674 636

  
675
			/// Point2D.Double p1 = new Point2D.Double(rectotal.x - pos, rectotal.y);
676
			drawInterval(g, inter, p);
677
		}
637
    /**
638
     * Inicializa las distancias de la barra de escala.
639
     */
640
    private void initDistances() {
641
        int numUp = 0;
642
        int numDown = 0;
678 643

  
679
		//Se dibuja el rect?ngulo que bordea toda la escala gr?fica.
680
		g.drawRect((int) rectotal.x, (int) rectotal.y, (int) (rectotal.width),
681
			(int) rectotal.height);
644
        DIFDOWN = 30;
645
        DIFL = 40;
646
        DIFR = 40;
647
        DIFUP = 30;
682 648

  
683
		drawNameUnits(g, rect, at);
684
		drawDescription(g, rect, at);
685
	}
649
        if (isAboveName()) {
650
            numUp++;
651
        } else {
652
            numDown++;
653
        }
686 654

  
687
	/**
688
	 * Inicializa las distancias de la barra de escala.
689
	 */
690
	private void initDistances() {
691
		int numUp = 0;
692
		int numDown = 0;
655
        if (isAboveIntervals()) {
656
            numUp++;
657
        } else {
658
            numDown++;
659
        }
693 660

  
694
		DIFDOWN = 30;
695
		DIFL = 40;
696
		DIFR = 40;
697
		DIFUP = 30;
661
        if (isAboveDescription()) {
662
            numUp++;
663
        } else {
664
            numDown++;
665
        }
698 666

  
699
		if (isAboveName()) {
700
			numUp++;
701
		} else {
702
			numDown++;
703
		}
667
        if (numDown == 1) {
668
            DIFDOWN = 3;
669
        } else if (numDown == 2) {
670
            DIFDOWN = 2;
671
        } else if (numDown == 3) {
672
            DIFDOWN = 1.2;
673
        }
704 674

  
705
		if (isAboveIntervals()) {
706
			numUp++;
707
		} else {
708
			numDown++;
709
		}
675
        if (numUp == 1) {
676
            DIFUP = 3;
677
        } else if (numUp == 2) {
678
            DIFUP = 2;
679
        } else if (numUp == 3) {
680
            DIFUP = 1.2;
681
        }
682
    }
710 683

  
711
		if (isAboveDescription()) {
712
			numUp++;
713
		} else {
714
			numDown++;
715
		}
684
    /**
685
     * Dibuja sobre el Graphics el nombre de la unidad de medida de la escala.
686
     *
687
     * @param g Graphics sobre el que se dibuja.
688
     * @param rec Rect?ngulo que ocupa la escala gr?fica.
689
     * @param at Matriz de transformaci?n.
690
     */
691
    private void drawNameUnits(Graphics g, Rectangle2D.Double rec,
692
        AffineTransform at) {
693
        //	Nombre de las unidades utilizadas.
694
        Point2D.Double p = null;
716 695

  
717
		if (numDown == 1) {
718
			DIFDOWN = 3;
719
		} else if (numDown == 2) {
720
			DIFDOWN = 2;
721
		} else if (numDown == 3) {
722
			DIFDOWN = 1.2;
723
		}
696
        if (isShowNameUnits()) {
697
            if (isAboveName()) {
698
                p = new Point2D.Double(rec.getCenterX() -
699
                        ((rec.getHeight() * (m_nameUnit.length() / 6)) / 4),
700
                        (rec.getMinY() + (rec.getHeight() / (DIFUP))) -
701
                        (rec.getHeight() / 2));
702
            } else {
703
                p = new Point2D.Double(rec.getCenterX() -
704
                        ((rec.getHeight() * (m_nameUnit.length() / 6)) / 4),
705
                        (rec.getHeight() / 1.4) +
706
                        (rec.getMaxY() - (rec.getHeight() / (DIFDOWN))));
707
            }
724 708

  
725
		if (numUp == 1) {
726
			DIFUP = 3;
727
		} else if (numUp == 2) {
728
			DIFUP = 2;
729
		} else if (numUp == 3) {
730
			DIFUP = 1.2;
731
		}
709
            p = FLayoutUtilities.fromSheetPoint(p, at);
710
            g.setColor(textcolor);
711
            g.drawString(m_nameUnit, (int) p.x, (int) p.y);
712
        }
713
    }
732 714

  
733
		//DIFDOWN=numDown;
734
		//DIFUP=numUp;
735
	}
715
    /**
716
     * Dibuja sobre el Graphics la descripci?n que por defecto sera la escala.
717
     *
718
     * @param g Graphics sobre el que se dibuja.
719
     * @param rec Rect?ngulo que ocupa la escala gr?fica.
720
     * @param at Matriz de transformaci?n.
721
     */
722
    private void drawDescription(Graphics g, Rectangle2D.Double rec,
723
        AffineTransform at) {
724
        Point2D.Double p = null;
736 725

  
737
	/**
738
	 * Dibuja sobre el Graphics el nombre de la unidad de medida de la escala.
739
	 *
740
	 * @param g Graphics sobre el que se dibuja.
741
	 * @param rec Rect?ngulo que ocupa la escala gr?fica.
742
	 * @param at Matriz de transformaci?n.
743
	 */
744
	private void drawNameUnits(Graphics g, Rectangle2D.Double rec,
745
		AffineTransform at) {
746
		//	Nombre de las unidades utilizadas.
747
		Point2D.Double p = null;
726
        if (isShowDescription()) {
727
            if (isAboveDescription()) {
728
                p = new Point2D.Double(rec.getCenterX() -
729
                        ((rec.getHeight() * (getDescripcion().length() / 6)) / 4),
730
                        (rec.getMinY() + (rec.getHeight() / (DIFUP))) -
731
                        (rec.getHeight() / 5));
732
            } else {
733
                p = new Point2D.Double(rec.getCenterX() -
734
                        ((rec.getHeight() * (getDescripcion().length() / 6)) / 4),
735
                        (rec.getHeight() / 2) +
736
                        (rec.getMaxY() - (rec.getHeight() / (DIFDOWN))));
737
            }
748 738

  
749
		if (isShowNameUnits()) {
750
			if (isAboveName()) {
751
				p = new Point2D.Double(rec.getCenterX() -
752
						((rec.getHeight() * (m_nameUnit.length() / 6)) / 4),
753
						
754
					//(m_nameUnit.length() / 6),
755
					(rec.getMinY() + (rec.getHeight() / (DIFUP))) -
756
						(rec.getHeight() / 2));
757
			} else {
758
				p = new Point2D.Double(rec.getCenterX() -
759
						((rec.getHeight() * (m_nameUnit.length() / 6)) / 4),
760
						(
761
					//(m_nameUnit.length() / 6),
762
					rec.getHeight() / 1.4) +
763
						(rec.getMaxY() - (rec.getHeight() / (DIFDOWN))));
764
			}
739
            p = FLayoutUtilities.fromSheetPoint(p, at);
740
            g.setColor(textcolor);
741
            g.drawString(getDescripcion(), (int) p.x, (int) p.y);
742
        }
743
    }
765 744

  
766
			p = FLayoutUtilities.fromSheetPoint(p, at);
767
			g.setColor(textcolor);
768
			g.drawString(m_nameUnit, (int) p.x, (int) p.y);
769
		}
770
	}
745
    /**
746
     * Rellena la fuente utilizada para dibujar los intervalos y la unidad de
747
     * medida utilizada.
748
     *
749
     * @param f fuente a utilizar.
750
     */
751
    public void setFont(Font f) {
752
        m_f = f;
753
    }
771 754

  
772
	/**
773
	 * Dibuja sobre el Graphics la descripci?n que por defecto sera la escala.
774
	 *
775
	 * @param g Graphics sobre el que se dibuja.
776
	 * @param rec Rect?ngulo que ocupa la escala gr?fica.
777
	 * @param at Matriz de transformaci?n.
778
	 */
779
	private void drawDescription(Graphics g, Rectangle2D.Double rec,
780
		AffineTransform at) {
781
		Point2D.Double p = null;
755
    /**
756
     * Devuelve la fuente con la que se est? dibujando sobre el graphics.
757
     *
758
     * @return fuente utilizada.
759
     */
760
    public Font getFont() {
761
        return new Font(m_f.getFontName(), m_f.getStyle(), 9);
762
    }
782 763

  
783
		if (isShowDescription()) {
784
			if (isAboveDescription()) {
785
				p = new Point2D.Double(rec.getCenterX() -
786
						((rec.getHeight() * (getDescripcion().length() / 6)) / 4),
787
						
788
					//(getDescripcion().length() / 6),
789
					(rec.getMinY() + (rec.getHeight() / (DIFUP))) -
790
						(rec.getHeight() / 5));
791
			} else {
792
				p = new Point2D.Double(rec.getCenterX() -
793
						((rec.getHeight() * (getDescripcion().length() / 6)) / 4),
794
						(
795
					//(getDescripcion().length() / 6),
796
					rec.getHeight() / 2) +
797
						(rec.getMaxY() - (rec.getHeight() / (DIFDOWN))));
798
			}
764
    /**
765
     * Devuelve si el intervalo es variable o si por el contrario es fijo.
766
     *
767
     * @return true si el intervalo es fijo.
768
     */
769
    public boolean isbIntervalSet() {
770
        return m_bIntervalSet;
771
    }
799 772

  
800
			p = FLayoutUtilities.fromSheetPoint(p, at);
801
			g.setColor(textcolor);
802
			g.drawString(getDescripcion(), (int) p.x, (int) p.y);
803
		}
804
	}
773
    /**
774
     * Especificar si el intervalo se debe mantener o es variable.
775
     *
776
     * @param b si se quiere mantener el intervalo especificado.
777
     */
778
    public void setbIntervalSet(boolean b) {
779
        m_bIntervalSet = b;
780
    }
805 781

  
806
	/**
807
	 * Rellena la fuente utilizada para dibujar los intervalos y la unidad de
808
	 * medida utilizada.
809
	 *
810
	 * @param f fuente a utilizar.
811
	 */
812
	public void setFont(Font f) {
813
		m_f = f;
814
	}
782
    /**
783
     * Devuelve el porcentaje por el cual hay que multiplicar  el intervalo
784
     * para conseguir un intervalo redondeado,  de momento con una cifra
785
     * significativas(NUM=1).
786
     *
787
     * @param total intervalo.
788
     *
789
     * @return Porcentaje
790
     */
791
    private double getExact(double total) {
792
        int NUM = 1;
793
        double t = 0;
794
        double dif = 1;
795
        Double d = new Double(total);
796
        Long l = new Long(d.longValue());
797
        int num = l.toString().length();
798
        t = ((long) (total / Math.pow(10, num - NUM)) * Math.pow(10, num - NUM));
799
        dif = t / total;
815 800

  
816
	/**
817
	 * Devuelve la fuente con la que se est? dibujando sobre el graphics.
818
	 *
819
	 * @return fuente utilizada.
820
	 */
821
	public Font getFont() {
822
		return new Font(m_f.getFontName(), m_f.getStyle(), 9);
823
	}
801
        return dif;
802
    }
824 803

  
825
	/**
826
	 * Devuelve si el intervalo es variable o si por el contrario es fijo.
827
	 *
828
	 * @return true si el intervalo es fijo.
829
	 */
830
	public boolean isbIntervalSet() {
831
		return m_bIntervalSet;
832
	}
804
    /**
805
     * Rellena un rect?ngulo.
806
     *
807
     * @param g Graphics sobre el que dibujar.
808
     * @param r Rect?ngulo a rellenar.
809
     */
810
    private void fillRect(Graphics2D g, Rectangle2D.Double r) {
811
        g.fillRect((int) r.x, (int) r.y, (int) r.width, (int) r.height);
812
    }
833 813

  
834
	/**
835
	 * Especificar si el intervalo se debe mantener o es variable.
836
	 *
837
	 * @param b si se quiere mantener el intervalo especificado.
838
	 */
839
	public void setbIntervalSet(boolean b) {
840
		m_bIntervalSet = b;
841
	}
814
    /**
815
     * Escribe sobre el Graphics y en la posici?n indicada el tama?o del
816
     * intervalo.
817
     *
818
     * @param g Graphics sobre el que dibujar.
819
     * @param inter Valor del intervalo.
820
     * @param p Punto donde dibujarlo.
821
     */
822
    private void drawInterval(Graphics2D g, long inter, Point2D.Double p) {
823
        Long l = new Long(inter);
824
        g.setColor(textcolor);
825
        g.drawString(l.toString(), (int) p.x, (int) p.y);
826
        g.setColor(barcolor);
827
    }
842 828

  
843
	/**
844
	 * Devuelve el porcentaje por el cual hay que multiplicar  el intervalo
845
	 * para conseguir un intervalo redondeado,  de momento con una cifra
846
	 * significativas(NUM=1).
847
	 *
848
	 * @param total intervalo.
849
	 *
850
	 * @return Porcentaje
851
	 */
852
	private double getExact(double total) {
853
		int NUM = 1;
854
		double t = 0;
855
		double dif = 1;
856
		Double d = new Double(total);
857
		Long l = new Long(d.longValue());
858
		int num = l.toString().length();
859
		t = ((long) (total / Math.pow(10, num - NUM)) * Math.pow(10, num - NUM));
860
		dif = t / total;
829
    /**
830
     * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
831
     */
832
    public XMLEntity getXMLEntity() {
833
        XMLEntity xml = new XMLEntity();
834
        xml.putProperty("className", this.getClass().getName());
835
        xml.putProperty("m_name", m_name);
836
        xml.putProperty("x", getBoundBox().x);
837
        xml.putProperty("y", getBoundBox().y);
838
        xml.putProperty("w", getBoundBox().width);
839
        xml.putProperty("h", getBoundBox().height);
840
        xml.putProperty("m_Selected", m_Selected);
841
        xml.putProperty("type", Layout.RECTANGLESCALEBAR);
842
        xml.putProperty("m_bIntervalSet", m_bIntervalSet);
843
        xml.putProperty("m_dif", m_dif);
844
        xml.putProperty("m_hasleft", m_hasleft);
845
        xml.putProperty("m_nameUnit", m_nameUnit);
846
        xml.putProperty("m_numUnit", m_numUnit);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff