Revision 1005 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/v02/FGraphicUtilities.java

View differences:

FGraphicUtilities.java
6 6
 */
7 7
package com.iver.cit.gvsig.fmap.core.v02;
8 8

  
9
import java.awt.Font;
10
import java.awt.FontMetrics;
11
import java.awt.Graphics2D;
12
import java.awt.Rectangle;
13
import java.awt.geom.AffineTransform;
14
import java.awt.geom.Point2D;
15

  
16
import org.apache.batik.ext.awt.geom.PathLength;
17

  
18
import com.iver.cit.gvsig.fmap.core.FGeometry;
19 9
import com.iver.cit.gvsig.fmap.core.FPoint2D;
20 10
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
21 11
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
22 12
import com.iver.cit.gvsig.fmap.core.FShape;
23 13
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
24
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
14

  
25 15
import com.vividsolutions.jts.geom.Geometry;
26 16
import com.vividsolutions.jts.geom.Point;
27 17

  
18
import org.apache.batik.ext.awt.geom.PathLength;
28 19

  
20
import java.awt.Font;
21
import java.awt.FontMetrics;
22
import java.awt.Graphics2D;
23
import java.awt.Rectangle;
24
import java.awt.geom.AffineTransform;
25
import java.awt.geom.Point2D;
26

  
27

  
29 28
/**
30
 * DOCUMENT ME!
29
 * Clase con m?todos est?ticos para dibujar sobre el Graphics que se les pase
30
 * como par?metro.
31 31
 *
32
 * @author fjp To change the template for this generated type comment go to
33
 *         Window>Preferences>Java>Code Generation>Code and
34
 *         Comments
32
 * @author fjp
35 33
 */
36 34
public class FGraphicUtilities {
37
    /**
38
     * DOCUMENT ME!
39
     *
40
     * @param g2 DOCUMENT ME!
41
     * @param mT2 DOCUMENT ME!
42
     * @param r DOCUMENT ME!
43
     * @param symbol DOCUMENT ME!
44
     */
45
    public static void DrawSymbol(Graphics2D g2, AffineTransform mT2,
46
        Rectangle r, FSymbol symbol) {
47
        FShape shp;
35
	/**
36
	 * Dibuja el s?mbolo que se le pasa como par?metro en el Graphics.
37
	 *
38
	 * @param g2 Graphics2D sobre el que dibujar.
39
	 * @param mT2 Matriz de transformaci?n.
40
	 * @param r Rect?ngulo.
41
	 * @param symbol S?mbolo a dibujar.
42
	 */
43
	public static void DrawSymbol(Graphics2D g2, AffineTransform mT2,
44
		Rectangle r, FSymbol symbol) {
45
		FShape shp;
48 46

  
49
        AffineTransform mT = new AffineTransform();
50
        mT.setToIdentity();
51
        Rectangle r2 = new Rectangle(r.x + 2 + r.width/3, r.y, r.width/3, r.height);
52
        Rectangle r3 = new Rectangle(r.x + 2 + 2*r.width/3, r.y, r.width/3, r.height);
47
		AffineTransform mT = new AffineTransform();
48
		mT.setToIdentity();
53 49

  
54
        // g2.clearRect(r.x, r.y, r.width, r.height);
55
        // System.out.println("r = " + r.toString() + " Color preview:" + symbol.m_Color.toString());
56
        // System.out.println("symbol.m_symbolType= "+symbol.m_symbolType);
57
        switch (symbol.getSymbolType()) {
58
            case FConstant.SYMBOL_TYPE_POINT:
59
                shp = new FPoint2D(r.x + (r.width / 2),
60
                        r.y + (r.height / 2));
50
		Rectangle r2 = new Rectangle(r.x + 2 + (r.width / 3), r.y, r.width / 3,
51
				r.height);
52
		Rectangle r3 = new Rectangle(r.x + 2 + ((2 * r.width) / 3), r.y,
53
				r.width / 3, r.height);
61 54

  
62
                //  Para no tener que clonarlo si viene en unidades de mapa
63
                boolean bAux2 = symbol.isSizeInPixels();
64
                int alturaMetros = symbol.getSize(); // Nota: Cambiar m_Size a float
55
		// g2.clearRect(r.x, r.y, r.width, r.height);
56
		// System.out.println("r = " + r.toString() + " Color preview:" + symbol.m_Color.toString());
57
		// System.out.println("symbol.m_symbolType= "+symbol.m_symbolType);
58
		switch (symbol.getSymbolType()) {
59
			case FConstant.SYMBOL_TYPE_POINT:
60
				shp = new FPoint2D(r.x + (r.width / 2), r.y + (r.height / 2));
65 61

  
66
                if (!bAux2) {
67
                    symbol.setSizeInPixels(true);
68
                    symbol.setSize(8); // tama?o fijo
69
                }
62
				//  Para no tener que clonarlo si viene en unidades de mapa
63
				boolean bAux2 = symbol.isSizeInPixels();
64
				int alturaMetros = symbol.getSize(); // Nota: Cambiar m_Size a float
70 65

  
71
                FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
66
				if (!bAux2) {
67
					symbol.setSizeInPixels(true);
68
					symbol.setSize(8); // tama?o fijo
69
				}
72 70

  
73
                if (!bAux2) {
74
                    symbol.setSize(alturaMetros);
75
                    symbol.setSizeInPixels(bAux2);
76
                }
71
				FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
77 72

  
78
                if (symbol.getFont() != null) {
79
                    // Para no tener que clonarlo si viene en unidades de mapa
80
                    boolean bAux = symbol.isFontSizeInPixels();
81
                    symbol.setFontSizeInPixels(true);
82
                    FGraphicUtilities.DrawLabel(g2, mT, shp, symbol,
83
                        new FLabel("Abcd"));
84
                    symbol.setFontSizeInPixels(bAux);
85
                }
73
				if (!bAux2) {
74
					symbol.setSize(alturaMetros);
75
					symbol.setSizeInPixels(bAux2);
76
				}
86 77

  
87
                break;
88
            case FConstant.SYMBOL_TYPE_LINE:
89
                Rectangle rect = mT2.createTransformedShape(r).getBounds();
90
                GeneralPathX line = new GeneralPathX();
91
                line.moveTo(rect.x, rect.y + (rect.height / 2));
78
				if (symbol.getFont() != null) {
79
					// Para no tener que clonarlo si viene en unidades de mapa
80
					boolean bAux = symbol.isFontSizeInPixels();
81
					symbol.setFontSizeInPixels(true);
82
					FGraphicUtilities.DrawLabel(g2, mT, shp, symbol,
83
						new FLabel("Abcd"));
84
					symbol.setFontSizeInPixels(bAux);
85
				}
92 86

  
93
                // line.lineTo(rect.x + rect.width/3, rect.y + rect.height);								
94
                // line.lineTo(rect.x + 2*rect.width/3, rect.y);				
95
                // line.lineTo(rect.x + rect.width, rect.y + rect.height/2);
96
                line.curveTo(rect.x + (rect.width / 3),
97
                    rect.y + (2 * rect.height),
98
                    rect.x + ((2 * rect.width) / 3), rect.y - rect.height,
99
                    rect.x + rect.width, rect.y + (rect.height / 2));
87
				break;
100 88

  
101
                shp = new FPolyline2D(line);
102
                FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
89
			case FConstant.SYMBOL_TYPE_LINE:
103 90

  
104
                break;
91
				Rectangle rect = mT2.createTransformedShape(r).getBounds();
92
				GeneralPathX line = new GeneralPathX();
93
				line.moveTo(rect.x, rect.y + (rect.height / 2));
105 94

  
106
            case FConstant.SYMBOL_TYPE_FILL:
95
				// line.lineTo(rect.x + rect.width/3, rect.y + rect.height);								
96
				// line.lineTo(rect.x + 2*rect.width/3, rect.y);				
97
				// line.lineTo(rect.x + rect.width, rect.y + rect.height/2);
98
				line.curveTo(rect.x + (rect.width / 3),
99
					rect.y + (2 * rect.height),
100
					rect.x + ((2 * rect.width) / 3), rect.y - rect.height,
101
					rect.x + rect.width, rect.y + (rect.height / 2));
107 102

  
108
                GeneralPathX rectAux = new GeneralPathX(r);
109
                rectAux.transform(mT2);
110
                shp = new FPolygon2D( rectAux);
103
				shp = new FPolyline2D(line);
104
				FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
111 105

  
112
                // System.out.println("rect = "+rectAux.getBounds());
113
                FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
106
				break;
114 107

  
115
                break;
116
            case FShape.MULTI:
117
            	// Pol?gono
118
            	r.resize(r.width/3, r.height);
119
                GeneralPathX rectAux2 = new GeneralPathX(r);
120
                rectAux2.transform(mT2);
121
                shp = new FPolygon2D( rectAux2);
122
                FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
123
                // L?nea
124
                rect = mT2.createTransformedShape(r2).getBounds();
125
                line = new GeneralPathX();
126
                line.moveTo(rect.x, rect.y + (rect.height / 2));
108
			case FConstant.SYMBOL_TYPE_FILL:
127 109

  
128
                line.curveTo(rect.x + (rect.width / 3),
129
                    rect.y + (2 * rect.height),
130
                    rect.x + ((2 * rect.width) / 3), rect.y - rect.height,
131
                    rect.x + rect.width, rect.y + (rect.height / 2));
110
				GeneralPathX rectAux = new GeneralPathX(r);
111
				rectAux.transform(mT2);
112
				shp = new FPolygon2D(rectAux);
132 113

  
133
                shp = new FPolyline2D(line);
134
                FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
135
                // Punto:
136
                shp = new FPoint2D(r3.x + (r3.width / 2),
137
                        r3.y + (r3.height / 2));
114
				// System.out.println("rect = "+rectAux.getBounds());
115
				FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
138 116

  
139
                //  Para no tener que clonarlo si viene en unidades de mapa
140
                bAux2 = symbol.isSizeInPixels();
141
                alturaMetros = symbol.getSize(); // Nota: Cambiar m_Size a float
117
				break;
142 118

  
143
                if (!bAux2) {
144
                    symbol.setSizeInPixels(true);
145
                    symbol.setSize(4); // tama?o fijo
146
                }
119
			case FShape.MULTI:
147 120

  
148
                FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
121
				// Pol?gono
122
				r.resize(r.width / 3, r.height);
149 123

  
150
                if (!bAux2) {
151
                    symbol.setSize(alturaMetros);
152
                    symbol.setSizeInPixels(bAux2);
153
                }
124
				GeneralPathX rectAux2 = new GeneralPathX(r);
125
				rectAux2.transform(mT2);
126
				shp = new FPolygon2D(rectAux2);
127
				FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
154 128

  
155
                if (symbol.getFont() != null) {
156
                    // Para no tener que clonarlo si viene en unidades de mapa
157
                    boolean bAux = symbol.isFontSizeInPixels();
158
                    symbol.setFontSizeInPixels(true);
159
                    FGraphicUtilities.DrawLabel(g2, mT, shp, symbol,
160
                        new FLabel("Abcd"));
161
                    symbol.setFontSizeInPixels(bAux);
162
                }
129
				// L?nea
130
				rect = mT2.createTransformedShape(r2).getBounds();
131
				line = new GeneralPathX();
132
				line.moveTo(rect.x, rect.y + (rect.height / 2));
163 133

  
134
				line.curveTo(rect.x + (rect.width / 3),
135
					rect.y + (2 * rect.height),
136
					rect.x + ((2 * rect.width) / 3), rect.y - rect.height,
137
					rect.x + rect.width, rect.y + (rect.height / 2));
164 138

  
139
				shp = new FPolyline2D(line);
140
				FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
165 141

  
166
                break;
167
                
168
        }
169
    }
142
				// Punto:
143
				shp = new FPoint2D(r3.x + (r3.width / 2), r3.y +
144
						(r3.height / 2));
170 145

  
171
    /**
172
     * DOCUMENT ME!
173
     *
174
     * @param g2 DOCUMENT ME!
175
     * @param mT DOCUMENT ME!
176
     * @param shp DOCUMENT ME!
177
     * @param theSymbol DOCUMENT ME!
178
     */
179
    public static void DrawShape(Graphics2D g2, AffineTransform mT, FShape shp,
180
        FSymbol theSymbol) {
181
        // Hacemos la transformaci?n del shape aqu? dentro... por ahora.
182
        if (shp == null) {
183
            return;
184
        }
146
				//  Para no tener que clonarlo si viene en unidades de mapa
147
				bAux2 = symbol.isSizeInPixels();
148
				alturaMetros = symbol.getSize(); // Nota: Cambiar m_Size a float
185 149

  
186
        g2.setColor(theSymbol.getColor());
187
        
188
        /* if (shp instanceof FPolygon2D)
189
        {
190
        	System.out.println("Entra pol?gono");
191
        } */
150
				if (!bAux2) {
151
					symbol.setSizeInPixels(true);
152
					symbol.setSize(4); // tama?o fijo
153
				}
192 154

  
193
        switch (shp.getShapeType()) {
194
            case FShape.POINT: //Tipo punto
195
                drawSymbolPoint(g2, mT, (FPoint2D) shp, theSymbol);
155
				FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
196 156

  
197
                break;
198
            case FShape.LINE:
157
				if (!bAux2) {
158
					symbol.setSize(alturaMetros);
159
					symbol.setSizeInPixels(bAux2);
160
				}
199 161

  
200
                // Shape theShp = mT.createTransformedShape(shp.m_Polyline);
201
                // g2.setColor(theSymbol.m_Color);
202
                if (theSymbol.getStroke() != null) {
203
                    g2.setStroke(theSymbol.getStroke());
204
                }
162
				if (symbol.getFont() != null) {
163
					// Para no tener que clonarlo si viene en unidades de mapa
164
					boolean bAux = symbol.isFontSizeInPixels();
165
					symbol.setFontSizeInPixels(true);
166
					FGraphicUtilities.DrawLabel(g2, mT, shp, symbol,
167
						new FLabel("Abcd"));
168
					symbol.setFontSizeInPixels(bAux);
169
				}
205 170

  
206
                g2.draw(shp);
171
				break;
172
		}
173
	}
207 174

  
208
                break;
209
                
175
	/**
176
	 * Dibuja el shape que se pasa como par?metro con las caracter?sticas que
177
	 * aporta el s?mbolo sobre el Graphics2D.
178
	 *
179
	 * @param g2 Graphics2D sobre el que dibujar.
180
	 * @param mT Matriz de transformaci?n.
181
	 * @param shp FShape a dibujar.
182
	 * @param theSymbol S?mbolo.
183
	 */
184
	public static void DrawShape(Graphics2D g2, AffineTransform mT, FShape shp,
185
		FSymbol theSymbol) {
186
		// Hacemos la transformaci?n del shape aqu? dentro... por ahora.
187
		if (shp == null) {
188
			return;
189
		}
210 190

  
211
            case FShape.POLYGON:
212
                g2.setPaint(theSymbol.getFill());
191
		g2.setColor(theSymbol.getColor());
213 192

  
214
                if (theSymbol.getColor() != null) {
215
                    g2.fill(shp);
216
                }
193
		/* if (shp instanceof FPolygon2D)
194
		   {
195
		           System.out.println("Entra pol?gono");
196
		   } */
197
		switch (shp.getShapeType()) {
198
			case FShape.POINT: //Tipo punto
199
				drawSymbolPoint(g2, mT, (FPoint2D) shp, theSymbol);
217 200

  
218
                if (theSymbol.isOutlined()) {
219
                    g2.setColor(theSymbol.getOutlineColor());
201
				break;
220 202

  
221
                    if (theSymbol.getStroke() != null) {
222
                        g2.setStroke(theSymbol.getStroke());
223
                    }
203
			case FShape.LINE:
224 204

  
225
                    g2.draw(shp);
226
                }
205
				// Shape theShp = mT.createTransformedShape(shp.m_Polyline);
206
				// g2.setColor(theSymbol.m_Color);
207
				if (theSymbol.getStroke() != null) {
208
					g2.setStroke(theSymbol.getStroke());
209
				}
227 210

  
228
                break;
229
        }
230
    }
211
				g2.draw(shp);
231 212

  
232
    public static void DrawLabel(Graphics2D g2, AffineTransform mT, FShape shp,
233
        FSymbol theSymbol, FLabel theLabel) {
234
        float angle;
235
        float x;
236
        float y;
237
        Point2D pAux = null;
213
				break;
238 214

  
239
        // USAR TEXTLAYOUT SI QUEREMOS PERMITIR SELECCIONAR UN TEXTO
240
        // Y/O EDITARLO "IN SITU"
215
			case FShape.POLYGON:
216
				g2.setPaint(theSymbol.getFill());
241 217

  
242
        /* if (m_labelValues[numReg].length() > 0)
243
           {
244
                   TextLayout layout = new TextLayout(m_labelValues[numReg], font, frc);
245
                   layout.draw(g2, x, y);
246
           } */
247
        if (shp == null) {
248
            return;
249
        }
218
				if (theSymbol.getColor() != null) {
219
					g2.fill(shp);
220
				}
250 221

  
251
        // Las etiquetas que pongamos a nulo ser? porque no la queremos dibujar.
252
        // ?til para cuando queramos eliminar duplicados.
253
        if (theLabel.getString() == null) {
254
            return;
255
        }
222
				if (theSymbol.isOutlined()) {
223
					g2.setColor(theSymbol.getOutlineColor());
256 224

  
257
        FontMetrics metrics = g2.getFontMetrics();
258
        int width = metrics.stringWidth(theLabel.getString());
259
        int height = metrics.getMaxAscent();
225
					if (theSymbol.getStroke() != null) {
226
						g2.setStroke(theSymbol.getStroke());
227
					}
260 228

  
261
        // int height = metrics.getHeight();
262
        g2.setFont(theSymbol.getFont());
263
        g2.setColor(theSymbol.getFontColor());
229
					g2.draw(shp);
230
				}
264 231

  
265
        // Aqu? hay que mirar m_Size y m_useSize...
266
        if (!theSymbol.isFontSizeInPixels()) {
267
            // Suponemos que m_Size viene en coordenadas de mundo real
268
            // Esto habr? que cambiarlo. Probablemente usar Style2d de geotools en lugar
269
            // de FSymbol.
270
            // CAMBIO: La altura del texto la miramos en FLabel
271
            // float alturaPixels = (float) (theSymbol.m_FontSize * mT.getScaleX());
272
            float alturaPixels = (float) (theLabel.getHeight() * mT.getScaleX());
232
				break;
233
		}
234
	}
273 235

  
274
            /* System.out.println("m_bUseSize = " + theSymbol.m_bUseSize +
275
               " Escala: " + mT.getScaleX() + " alturaPixels = " + alturaPixels); */
276
            if (alturaPixels < 3) {
277
                return; // No leemos nada
278
            }
236
	/**
237
	 * Dibuja el FLabel que se pasa como par?metro sobre el Graphics2D.
238
	 *
239
	 * @param g2 Graphics2D sobre el que dibujar.
240
	 * @param mT Matriz de transformaci?n.
241
	 * @param shp FShape a dibujar.
242
	 * @param theSymbol S?mbolo para aplicar.
243
	 * @param theLabel FLabel que contiene el texto que se debe dibujar.
244
	 */
245
	public static void DrawLabel(Graphics2D g2, AffineTransform mT, FShape shp,
246
		FSymbol theSymbol, FLabel theLabel) {
247
		float angle;
248
		float x;
249
		float y;
250
		Point2D pAux = null;
279 251

  
280
            Font nuevaFuente = theSymbol.getFont().deriveFont(alturaPixels);
281
            g2.setFont(nuevaFuente);
282
            width = g2.getFontMetrics().stringWidth(theLabel.getString());
283
        }
252
		// USAR TEXTLAYOUT SI QUEREMOS PERMITIR SELECCIONAR UN TEXTO
253
		// Y/O EDITARLO "IN SITU"
284 254

  
285
        switch (shp.getShapeType()) {
286
            case FShape.POINT: //Tipo punto
287
            	
288
            	pAux = new Point2D.Double(((FPoint2D)shp).getX(), ((FPoint2D)shp).getY());
289
                pAux = mT.transform(pAux, null);
255
		/* if (m_labelValues[numReg].length() > 0)
256
		   {
257
		           TextLayout layout = new TextLayout(m_labelValues[numReg], font, frc);
258
		           layout.draw(g2, x, y);
259
		   } */
260
		if (shp == null) {
261
			return;
262
		}
290 263

  
291
                break;
264
		// Las etiquetas que pongamos a nulo ser? porque no la queremos dibujar.
265
		// ?til para cuando queramos eliminar duplicados.
266
		if (theLabel.getString() == null) {
267
			return;
268
		}
292 269

  
293
            case FShape.LINE:
270
		FontMetrics metrics = g2.getFontMetrics();
271
		int width = metrics.stringWidth(theLabel.getString());
272
		int height = metrics.getMaxAscent();
294 273

  
295
                // 
296
                if (theLabel.getOrig() == null) // Calculamos el punto y la orientaci?n solo la primera vez
297
                 {
298
                    PathLength pathLen = new PathLength(shp);
274
		// int height = metrics.getHeight();
275
		g2.setFont(theSymbol.getFont());
276
		g2.setColor(theSymbol.getFontColor());
299 277

  
300
                    // if (pathLen.lengthOfPath() < width / mT.getScaleX()) return;
301
                    float midDistance = pathLen.lengthOfPath() / 2;
302
                    pAux = pathLen.pointAtLength(midDistance);
303
                    angle = pathLen.angleAtLength(midDistance);
278
		// Aqu? hay que mirar m_Size y m_useSize...
279
		if (!theSymbol.isFontSizeInPixels()) {
280
			// Suponemos que m_Size viene en coordenadas de mundo real
281
			// Esto habr? que cambiarlo. Probablemente usar Style2d de geotools en lugar
282
			// de FSymbol.
283
			// CAMBIO: La altura del texto la miramos en FLabel
284
			// float alturaPixels = (float) (theSymbol.m_FontSize * mT.getScaleX());
285
			float alturaPixels = (float) (theLabel.getHeight() * mT.getScaleX());
304 286

  
305
                    if (angle < 0) {
306
                        angle = angle + (float) (2 * Math.PI);
307
                    }
287
			/* System.out.println("m_bUseSize = " + theSymbol.m_bUseSize +
288
			   " Escala: " + mT.getScaleX() + " alturaPixels = " + alturaPixels); */
289
			if (alturaPixels < 3) {
290
				return; // No leemos nada
291
			}
308 292

  
309
                    if ((angle > (Math.PI / 2)) &&
310
                            (angle < ((3 * Math.PI) / 2))) {
311
                        angle = angle - (float) Math.PI;
312
                    }
293
			Font nuevaFuente = theSymbol.getFont().deriveFont(alturaPixels);
294
			g2.setFont(nuevaFuente);
295
			width = g2.getFontMetrics().stringWidth(theLabel.getString());
296
		}
313 297

  
314
                    theLabel.setRotation(Math.toDegrees(angle));
315
                    theLabel.setOrig(pAux);
316
                }
298
		switch (shp.getShapeType()) {
299
			case FShape.POINT: //Tipo punto
300
				pAux = new Point2D.Double(((FPoint2D) shp).getX(),
301
						((FPoint2D) shp).getY());
302
				pAux = mT.transform(pAux, null);
317 303

  
318
                pAux = mT.transform(theLabel.getOrig(), null);
304
				break;
319 305

  
320
                // pAux = theLabel.getOrig();
321
                // GlyphVector theGlyphs = theSymbol.m_Font.createGlyphVector(g2.getFontRenderContext(), theLabel);
322
                // Shape txtShp = TextPathLayout.layoutGlyphVector(theGlyphs, shp.m_Polyline,TextPathLayout.ALIGN_MIDDLE);				
323
                // g2.draw(txtShp);
324
                // System.out.println("Pintando etiqueta " + theLabel );
325
                break;
306
			case FShape.LINE:
326 307

  
327
            case FShape.POLYGON:
328
                if (theLabel.getOrig() == null) // Calculamos el punto solo la primera vez
329
                 {
330
                    Geometry geo = FConverter.java2d_to_jts(shp);
308
				// 
309
				if (theLabel.getOrig() == null) // Calculamos el punto y la orientaci?n solo la primera vez
310
				 {
311
					PathLength pathLen = new PathLength(shp);
331 312

  
332
                    // System.out.println("Area de " + m_labelValues[numReg] + " = "
333
                    //   + geo.getArea());
334
                    //   System.out.println(geo.toText()); 
335
                    Point pJTS = geo.getInteriorPoint();
336
                    FShape pLabel = FConverter.jts_to_java2d(pJTS);
337
                    theLabel.setRotation(0);
338
                    theLabel.setOrig(new Point2D.Double(((FPoint2D)pLabel).getX(), ((FPoint2D)pLabel).getX()));
339
                }
313
					// if (pathLen.lengthOfPath() < width / mT.getScaleX()) return;
314
					float midDistance = pathLen.lengthOfPath() / 2;
315
					pAux = pathLen.pointAtLength(midDistance);
316
					angle = pathLen.angleAtLength(midDistance);
340 317

  
341
                pAux = mT.transform(theLabel.getOrig(), null);
318
					if (angle < 0) {
319
						angle = angle + (float) (2 * Math.PI);
320
					}
342 321

  
343
                break;
344
        }
322
					if ((angle > (Math.PI / 2)) &&
323
							(angle < ((3 * Math.PI) / 2))) {
324
						angle = angle - (float) Math.PI;
325
					}
345 326

  
346
        AffineTransform ant = g2.getTransform();
327
					theLabel.setRotation(Math.toDegrees(angle));
328
					theLabel.setOrig(pAux);
329
				}
347 330

  
348
        x = (float) pAux.getX();
349
        y = (float) pAux.getY();
331
				pAux = mT.transform(theLabel.getOrig(), null);
350 332

  
351
        AffineTransform Tx = (AffineTransform) ant.clone();
352
        Tx.translate(x, y); // S3: final translation
353
        Tx.rotate(Math.toRadians(-theLabel.getRotation())); // S2: rotate around anchor
354
        g2.setTransform(Tx);
333
				// pAux = theLabel.getOrig();
334
				// GlyphVector theGlyphs = theSymbol.m_Font.createGlyphVector(g2.getFontRenderContext(), theLabel);
335
				// Shape txtShp = TextPathLayout.layoutGlyphVector(theGlyphs, shp.m_Polyline,TextPathLayout.ALIGN_MIDDLE);				
336
				// g2.draw(txtShp);
337
				// System.out.println("Pintando etiqueta " + theLabel );
338
				break;
355 339

  
356
        switch (theLabel.getJustification()) {
357
            case FLabel.LEFT_BOTTOM:
358
                g2.drawString(theLabel.getString(), 0, 0 - 3);
340
			case FShape.POLYGON:
359 341

  
360
                break;
342
				if (theLabel.getOrig() == null) // Calculamos el punto solo la primera vez
343
				 {
344
					Geometry geo = FConverter.java2d_to_jts(shp);
361 345

  
362
            case FLabel.LEFT_CENTER:
363
                g2.drawString(theLabel.getString(), 0, 0 - (height / 2));
346
					// System.out.println("Area de " + m_labelValues[numReg] + " = "
347
					//   + geo.getArea());
348
					//   System.out.println(geo.toText()); 
349
					Point pJTS = geo.getInteriorPoint();
350
					FShape pLabel = FConverter.jts_to_java2d(pJTS);
351
					theLabel.setRotation(0);
352
					theLabel.setOrig(new Point2D.Double(
353
							((FPoint2D) pLabel).getX(),
354
							((FPoint2D) pLabel).getX()));
355
				}
364 356

  
365
                break;
357
				pAux = mT.transform(theLabel.getOrig(), null);
366 358

  
367
            case FLabel.LEFT_TOP:
368
                g2.drawString(theLabel.getString(), 0, 0 - height);
359
				break;
360
		}
369 361

  
370
                break;
362
		AffineTransform ant = g2.getTransform();
371 363

  
372
            case FLabel.CENTER_BOTTOM:
373
                g2.drawString(theLabel.getString(), 0 - (width / 2), 0 - 3);
364
		x = (float) pAux.getX();
365
		y = (float) pAux.getY();
374 366

  
375
                break;
367
		AffineTransform Tx = (AffineTransform) ant.clone();
368
		Tx.translate(x, y); // S3: final translation
369
		Tx.rotate(Math.toRadians(-theLabel.getRotation())); // S2: rotate around anchor
370
		g2.setTransform(Tx);
376 371

  
377
            case FLabel.CENTER_CENTER:
378
                g2.drawString(theLabel.getString(), 0 - (width / 2),
379
                    0 - (height / 2));
372
		switch (theLabel.getJustification()) {
373
			case FLabel.LEFT_BOTTOM:
374
				g2.drawString(theLabel.getString(), 0, 0 - 3);
380 375

  
381
                break;
376
				break;
382 377

  
383
            case FLabel.CENTER_TOP:
384
                g2.drawString(theLabel.getString(), 0 - (width / 2), 0 -
385
                    height);
378
			case FLabel.LEFT_CENTER:
379
				g2.drawString(theLabel.getString(), 0, 0 - (height / 2));
386 380

  
387
                break;
381
				break;
388 382

  
389
            case FLabel.RIGHT_BOTTOM:
390
                g2.drawString(theLabel.getString(), 0 - width, 0 - 3);
383
			case FLabel.LEFT_TOP:
384
				g2.drawString(theLabel.getString(), 0, 0 - height);
391 385

  
392
                break;
386
				break;
393 387

  
394
            case FLabel.RIGHT_CENTER:
395
                g2.drawString(theLabel.getString(), 0 - width, 0 -
396
                    (height / 2));
388
			case FLabel.CENTER_BOTTOM:
389
				g2.drawString(theLabel.getString(), 0 - (width / 2), 0 - 3);
397 390

  
398
                break;
391
				break;
399 392

  
400
            case FLabel.RIGHT_TOP:
401
                g2.drawString(theLabel.getString(), 0 - width, 0 - height);
393
			case FLabel.CENTER_CENTER:
394
				g2.drawString(theLabel.getString(), 0 - (width / 2),
395
					0 - (height / 2));
402 396

  
403
                break;
404
        }
397
				break;
405 398

  
406
        // Restauramos
407
        g2.setTransform(ant);
408
    }
399
			case FLabel.CENTER_TOP:
400
				g2.drawString(theLabel.getString(), 0 - (width / 2), 0 -
401
					height);
409 402

  
410
    /**
411
     * DOCUMENT ME!
412
     *
413
     * @param g2 DOCUMENT ME!
414
     * @param mT DOCUMENT ME!
415
     * @param shp DOCUMENT ME!
416
     * @param theSymbol DOCUMENT ME!
417
     */
418
    private static void drawSymbolPoint(Graphics2D g2, AffineTransform mT, FPoint2D pAux, FSymbol theSymbol) {
419
        int x;
420
        int y;
421
        x = (int) pAux.getX();
422
        y = (int) pAux.getY();
403
				break;
404

  
405
			case FLabel.RIGHT_BOTTOM:
406
				g2.drawString(theLabel.getString(), 0 - width, 0 - 3);
407

  
408
				break;
409

  
410
			case FLabel.RIGHT_CENTER:
411
				g2.drawString(theLabel.getString(), 0 - width, 0 -
412
					(height / 2));
413

  
414
				break;
415

  
416
			case FLabel.RIGHT_TOP:
417
				g2.drawString(theLabel.getString(), 0 - width, 0 - height);
418

  
419
				break;
420
		}
421

  
422
		// Restauramos
423
		g2.setTransform(ant);
424
	}
425

  
426
	/**
427
	 * Dibuja un punto sobre el Graphics2D que se pasa como par?metro.
428
	 *
429
	 * @param g2 Graphics2D sobre el que dibujar.
430
	 * @param mT MAtriz de transformaci?n.
431
	 * @param pAux punto a dibujar.
432
	 * @param theSymbol S?mbolo a aplicar.
433
	 */
434
	private static void drawSymbolPoint(Graphics2D g2, AffineTransform mT,
435
		FPoint2D pAux, FSymbol theSymbol) {
436
		int x;
437
		int y;
438
		x = (int) pAux.getX();
439
		y = (int) pAux.getY();
440

  
423 441
		/*if (x==0){
424
			x=100;
442
		   x=100;
443
		   }
444
		   if (y==0){
445
		           y=100;
446
		   }
447
		 */
448
		Rectangle rectAux = new Rectangle();
449

  
450
		// Aqu? hay que mirar m_Size y m_useSize...
451
		float radio_simbolo;
452
		radio_simbolo = theSymbol.getSize() / 2;
453

  
454
		if (!theSymbol.isSizeInPixels()) {
455
			// Suponemos que m_Size viene en coordenadas de mundo real
456
			radio_simbolo = (float) (theSymbol.getSize() * mT.getScaleX());
457

  
458
			/* System.out.println("m_bUseSize = " + theSymbol.m_bUseSize +
459
			   " Escala: " + mT.getScaleX() + " alturaPixels = " + alturaPixels); */
460
			// if (radio_simbolo < 1) return; // No dibujamos nada
461
			rectAux.setRect(x - radio_simbolo, y - radio_simbolo,
462
				radio_simbolo * 2, radio_simbolo * 2);
463
		} else {
464
			// m_Size viene en pixels
465
			rectAux.setRect(x - radio_simbolo, y - radio_simbolo,
466
				theSymbol.getSize(), theSymbol.getSize());
425 467
		}
426
		if (y==0){
427
			y=100;
468

  
469
		// 	continue; //radioSimbolo_en_pixels = 3;
470
		if (theSymbol.getFill() != null) {
471
			g2.setPaint(theSymbol.getFill());
428 472
		}
429
		*/
430
        Rectangle rectAux = new Rectangle();
431 473

  
432
        // Aqu? hay que mirar m_Size y m_useSize...
433
        float radio_simbolo;
434
        radio_simbolo = theSymbol.getSize() / 2;
474
		if (theSymbol.getStroke() != null) {
475
			g2.setStroke(theSymbol.getStroke());
476
		}
435 477

  
436
        if (!theSymbol.isSizeInPixels()) {
437
            // Suponemos que m_Size viene en coordenadas de mundo real
438
            radio_simbolo = (float) (theSymbol.getSize() * mT.getScaleX());
478
		if (radio_simbolo < 2) {
479
			g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height);
439 480

  
440
            /* System.out.println("m_bUseSize = " + theSymbol.m_bUseSize +
441
               " Escala: " + mT.getScaleX() + " alturaPixels = " + alturaPixels); */
442
            // if (radio_simbolo < 1) return; // No dibujamos nada
443
            rectAux.setRect(x - radio_simbolo, y - radio_simbolo,
444
                radio_simbolo * 2, radio_simbolo * 2);
445
        } else {
446
            // m_Size viene en pixels
447
            rectAux.setRect(x - radio_simbolo, y - radio_simbolo,
448
                theSymbol.getSize(), theSymbol.getSize());
449
        }
481
			return;
482
		}
450 483

  
451
        // 	continue; //radioSimbolo_en_pixels = 3;
452
        if (theSymbol.getFill() != null) {
453
            g2.setPaint(theSymbol.getFill());
454
        }
484
		switch (theSymbol.getStyle()) {
485
			case FConstant.SYMBOL_STYLE_MARKER_CIRCLE: // Circulito
455 486

  
456
        if (theSymbol.getStroke() != null) {
457
            g2.setStroke(theSymbol.getStroke());
458
        }
487
				if (theSymbol.getColor() != null) {
488
					g2.fillOval(rectAux.x, rectAux.y, rectAux.width,
489
						rectAux.height);
490
				}
459 491

  
460
        if (radio_simbolo < 2) {
461
            g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height);
492
				if (theSymbol.isOutlined()) {
493
					g2.setColor(theSymbol.getOutlineColor());
494
					g2.drawOval(rectAux.x, rectAux.y, rectAux.width,
495
						rectAux.height);
496
				}
462 497

  
463
            return;
464
        }
498
				break;
465 499

  
466
        switch (theSymbol.getStyle()) {
467
            case FConstant.SYMBOL_STYLE_MARKER_CIRCLE: // Circulito
500
			case FConstant.SYMBOL_STYLE_MARKER_SQUARE: // Cuadrado
501
				g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height);
468 502

  
469
                if (theSymbol.getColor() != null) {
470
                    g2.fillOval(rectAux.x, rectAux.y, rectAux.width,
471
                        rectAux.height);
472
                }
503
				if (theSymbol.isOutlined()) {
504
					g2.setColor(theSymbol.getOutlineColor());
505
					g2.drawRect(rectAux.x, rectAux.y, rectAux.width,
506
						rectAux.height);
507
				}
473 508

  
474
                if (theSymbol.isOutlined()) {
475
                    g2.setColor(theSymbol.getOutlineColor());
476
                    g2.drawOval(rectAux.x, rectAux.y, rectAux.width,
477
                        rectAux.height);
478
                }
509
				break;
479 510

  
480
                break;
511
			case FConstant.SYMBOL_STYLE_MARKER_TRIANGLE: // Triangulo
481 512

  
482
            case FConstant.SYMBOL_STYLE_MARKER_SQUARE: // Cuadrado
483
                g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height);
513
				// y = r*sin30, x = r*cos30
514
				GeneralPathX genPath = new GeneralPathX();
515
				genPath.moveTo(x - (int) (radio_simbolo * 0.866),
516
					y + (int) (radio_simbolo * 0.5));
517
				genPath.lineTo(x + (int) (radio_simbolo * 0.866),
518
					y + (int) (radio_simbolo * 0.5));
519
				genPath.lineTo(x, y - (float) radio_simbolo);
520
				genPath.closePath();
484 521

  
485
                if (theSymbol.isOutlined()) {
486
                    g2.setColor(theSymbol.getOutlineColor());
487
                    g2.drawRect(rectAux.x, rectAux.y, rectAux.width,
488
                        rectAux.height);
489
                }
522
				g2.fill(genPath);
490 523

  
491
                break;
524
				break;
492 525

  
493
            case FConstant.SYMBOL_STYLE_MARKER_TRIANGLE: // Triangulo
526
			case FConstant.SYMBOL_STYLE_MARKER_CROSS: // Cruz
494 527

  
495
                // y = r*sin30, x = r*cos30
496
                GeneralPathX genPath = new GeneralPathX();
497
                genPath.moveTo(x - (int) (radio_simbolo * 0.866),
498
                    y + (int) (radio_simbolo * 0.5));
499
                genPath.lineTo(x + (int) (radio_simbolo * 0.866),
500
                    y + (int) (radio_simbolo * 0.5));
501
                genPath.lineTo(x, y - (float) radio_simbolo);
502
                genPath.closePath();
528
				GeneralPathX genPathCruz = new GeneralPathX();
529
				genPathCruz.moveTo(x, y - radio_simbolo);
530
				genPathCruz.lineTo(x, y + radio_simbolo);
531
				genPathCruz.moveTo(x - radio_simbolo, y);
532
				genPathCruz.lineTo(x + radio_simbolo, y);
533
				g2.draw(genPathCruz);
503 534

  
504
                g2.fill(genPath);
535
				break;
505 536

  
506
                break;
537
			case 34: // TrueType marker
507 538

  
508
            case FConstant.SYMBOL_STYLE_MARKER_CROSS: // Cruz
539
			/* lf.lfHeight = -radioSimbolo_en_pixels;
540
			   angulo = pSimbolo->m_Rotation;  // En radianes, de -pi a pi
541
			   angulo = -180.0 * angulo / PI;
542
			
543
			   lf.lfEscapement = (long) angulo*10;
544
			   lf.lfOrientation = (long) angulo*10;
545
			
546
			   fuente.CreateFontIndirect(&lf);
547
			   pOldFont = pDC->SelectObject(&fuente);
548
			
549
			   pDC->TextOut(pAPI.x, pAPI.y+radioSimbolo_en_pixels/2,elChar,1);
550
			
551
			   pDC->SelectObject(pOldFont);
552
			   fuente.DeleteObject();
553
			
554
			   break; */
555
			case FConstant.SYMBOL_STYLE_MARKER_IMAGEN: // Icono
556
			 {
557
				if (theSymbol.getIcon() != null) {
558
					float w;
559
					float h;
509 560

  
510
                GeneralPathX genPathCruz = new GeneralPathX();
511
                genPathCruz.moveTo(x, y - radio_simbolo);
512
                genPathCruz.lineTo(x, y + radio_simbolo);
513
                genPathCruz.moveTo(x - radio_simbolo, y);
514
                genPathCruz.lineTo(x + radio_simbolo, y);
515
                g2.draw(genPathCruz);
561
					if (theSymbol.isSizeInPixels()) {
562
						// Suponemos que m_Size viene en coordenadas de mundo real
563
						// Por ejemplo, nos valemos del ancho para fijar la escala
564
						w = (float) (theSymbol.getSize() * mT.getScaleX());
565
						h = (theSymbol.getIcon().getHeight(null) * w) / theSymbol.getIcon()
566
																				 .getWidth(null);
516 567

  
517
                break;
568
						rectAux.setRect(x - w, y - h, w * 2, h * 2);
569
					} else {
570
						// m_Size viene en pixels
571
						w = theSymbol.getSize();
572
						h = (theSymbol.getIcon().getHeight(null) * w) / theSymbol.getIcon()
573
																				 .getWidth(null);
574
						rectAux.setRect(x - w, y - h, w, h);
575
					}
518 576

  
519
            case 34: // TrueType marker
577
					g2.drawImage(theSymbol.getIcon(), rectAux.x, rectAux.y,
578
						rectAux.width, rectAux.height, null);
579
				} else {
580
					String strImg = "Image"; // Utilities.getMessage(FGraphicUtilities.class,"imagen"); 
581
					FontMetrics metrics = g2.getFontMetrics();
582
					int width = metrics.stringWidth(strImg);
583
					int height = metrics.getMaxAscent();
520 584

  
521
            /* lf.lfHeight = -radioSimbolo_en_pixels;
522
               angulo = pSimbolo->m_Rotation;  // En radianes, de -pi a pi
523
               angulo = -180.0 * angulo / PI;
524
            
525
               lf.lfEscapement = (long) angulo*10;
526
               lf.lfOrientation = (long) angulo*10;
527
            
528
               fuente.CreateFontIndirect(&lf);
529
               pOldFont = pDC->SelectObject(&fuente);
530
            
531
               pDC->TextOut(pAPI.x, pAPI.y+radioSimbolo_en_pixels/2,elChar,1);
532
            
533
               pDC->SelectObject(pOldFont);
534
               fuente.DeleteObject();
535
            
536
               break; */
537
            case FConstant.SYMBOL_STYLE_MARKER_IMAGEN: // Icono
538
            {
539
            	if (theSymbol.getIcon() != null)
540
            	{
541
            		float w, h;
542
                    if (theSymbol.isSizeInPixels()) {
543
                        // Suponemos que m_Size viene en coordenadas de mundo real
544
                    	// Por ejemplo, nos valemos del ancho para fijar la escala
545
                        w = (float) (theSymbol.getSize() * mT.getScaleX());
546
                        h = theSymbol.getIcon().getHeight(null) * w / theSymbol.getIcon().getWidth(null);  
585
					g2.drawString(strImg, x - (width / 2), y - 2 +
586
						(height / 2));
587
				}
547 588

  
548
                        rectAux.setRect(x - w, y - h,
549
                            w * 2, h * 2);
550
                    } else {
551
                        // m_Size viene en pixels
552
                    	w = theSymbol.getSize();
553
                        h = theSymbol.getIcon().getHeight(null) * w / theSymbol.getIcon().getWidth(null);                    	
554
                        rectAux.setRect(x - w, y - h, w, h);
555
                    }
556
            		
557
            		g2.drawImage(theSymbol.getIcon(), rectAux.x, rectAux.y, rectAux.width, rectAux.height, null);
558
            	}
559
            	else
560
            	{
561
            		String strImg = "Image"; // Utilities.getMessage(FGraphicUtilities.class,"imagen"); 
562
                    FontMetrics metrics = g2.getFontMetrics();
563
                    int width = metrics.stringWidth(strImg);
564
                    int height = metrics.getMaxAscent();
589
				break;
590
			}
565 591

  
566
            		g2.drawString(strImg, x - width/2, y -2 + height/2);
567
            	}
568
            	break;
569
            }
592
			/* DrawIconEx(pDC->m_hDC, pAPI.x-(pSimbolo->m_widthIco/2), pAPI.y-(pSimbolo->m_heightIco/2),
593
			   pSimbolo->m_hIcon, pSimbolo->m_widthIco, pSimbolo->m_heightIco, 0 , NULL, DI_NORMAL);
594
			   break; */
595
			case FConstant.SYMBOL_STYLE_POINTZ: // Circulito
570 596

  
571
            /* DrawIconEx(pDC->m_hDC, pAPI.x-(pSimbolo->m_widthIco/2), pAPI.y-(pSimbolo->m_heightIco/2),
572
               pSimbolo->m_hIcon, pSimbolo->m_widthIco, pSimbolo->m_heightIco, 0 , NULL, DI_NORMAL);
573
               break; */
574
            case FConstant.SYMBOL_STYLE_POINTZ: // Circulito
597
				if (theSymbol.getColor() != null) {
598
					g2.fillOval(rectAux.x, rectAux.y, rectAux.width,
599
						rectAux.height);
600
				}
575 601

  
576
                if (theSymbol.getColor() != null) {
577
                    g2.fillOval(rectAux.x, rectAux.y, rectAux.width,
578
                        rectAux.height);
579
                }
602
				if (theSymbol.isOutlined()) {
603
					g2.setColor(theSymbol.getOutlineColor());
604
					g2.drawOval(rectAux.x, rectAux.y, rectAux.width,
605
						rectAux.height);
606
				}
580 607

  
581
                if (theSymbol.isOutlined()) {
582
                    g2.setColor(theSymbol.getOutlineColor());
583
                    g2.drawOval(rectAux.x, rectAux.y, rectAux.width,
584
                        rectAux.height);
585
                }
586

  
587
                break;
588
        } // del switch estilo
589
    }
608
				break;
609
		} // del switch estilo
610
	}
590 611
}

Also available in: Unified diff