Revision 21826

View differences:

branches/Mobile_Compatible_milestone2/libraries/libFMap_mapcontext/src/org/gvsig/fmap/geometry/operation/DrawInts.java
1
package org.gvsig.fmap.geometry.operation;
2

  
3
import java.awt.Graphics2D;
4
import java.awt.geom.AffineTransform;
5
import java.awt.geom.PathIterator;
6

  
7
import org.apache.log4j.Logger;
8
import org.gvsig.fmap.geom.Geometry;
9
import org.gvsig.fmap.geom.GeometryManager;
10
import org.gvsig.fmap.geom.operation.GeometryOperation;
11
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
12
import org.gvsig.fmap.geom.primitive.Curve2D;
13
import org.gvsig.fmap.geom.primitive.GeneralPathX;
14
import org.gvsig.fmap.geom.primitive.Surface2D;
15
import org.gvsig.fmap.mapcontext.ViewPort;
16
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
17
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
18

  
19
import com.iver.utiles.swing.threads.Cancellable;
20

  
21
public class DrawInts extends GeometryOperation {
22

  
23
	private static Logger logger = Logger.getLogger(DrawInts.class);
24

  
25
	public static final int CODE = GeometryManager.getInstance()
26
			.registerGeometryOperation("drawInts", new DrawInts());
27

  
28
	public Object invoke(Geometry geom, GeometryOperationContext ctx) {
29
		DrawOperationContext doc=(DrawOperationContext)ctx;
30
		ViewPort viewPort = doc.getViewPort();
31
		ISymbol symbol = doc.getSymbol();
32
		Graphics2D g=doc.getGraphics();
33
		Cancellable cancel=doc.getCancellable();
34
//		 make the symbol to resize itself with the current rendering context
35
		if (doc.hasDPI()){
36
			double previousSize = ((CartographicSupport)symbol).
37
			toCartographicSize(viewPort, doc.getDPI(), geom);
38
			// draw it as normally
39
			Geometry decimatedShape = transformToInts(geom, viewPort.getAffineTransform());
40
			symbol.draw(g, viewPort.getAffineTransform(), decimatedShape,cancel);
41
			// restore previous size
42
			((CartographicSupport)symbol).setCartographicSize(previousSize, geom);
43
		}else{
44
			Geometry decimatedShape = transformToInts(geom, viewPort.getAffineTransform());
45
			symbol.draw(g, viewPort.getAffineTransform(), decimatedShape,cancel);
46
		}
47
		return null;
48
	}
49

  
50
	public int getOperationIndex() {
51
		return CODE;
52
	}
53
	private static Geometry transformToInts(Geometry gp, AffineTransform at) {
54
	        GeneralPathX newGp = new GeneralPathX();
55
	        double[] theData = new double[6];
56
	        double[] aux = new double[6];
57

  
58
	        // newGp.reset();
59
	        PathIterator theIterator;
60
	        int theType;
61
	        int numParts = 0;
62

  
63
	        java.awt.geom.Point2D ptDst = new java.awt.geom.Point2D.Double();
64
	        java.awt.geom.Point2D ptSrc = new java.awt.geom.Point2D.Double();
65
	        boolean bFirst = true;
66
	        int xInt, yInt, antX = -1, antY = -1;
67

  
68

  
69
	        theIterator = gp.getPathIterator(null); //, flatness);
70
	        int numSegmentsAdded = 0;
71
	        while (!theIterator.isDone()) {
72
	            theType = theIterator.currentSegment(theData);
73

  
74
	            switch (theType) {
75
	                case PathIterator.SEG_MOVETO:
76
	                    numParts++;
77
	                    ptSrc.setLocation(theData[0], theData[1]);
78
	                    at.transform(ptSrc, ptDst);
79
	                    antX = (int) ptDst.getX();
80
	                    antY = (int) ptDst.getY();
81
	                    newGp.moveTo(antX, antY);
82
	                    numSegmentsAdded++;
83
	                    bFirst = true;
84
	                    break;
85

  
86
	                case PathIterator.SEG_LINETO:
87
	                    ptSrc.setLocation(theData[0], theData[1]);
88
	                    at.transform(ptSrc, ptDst);
89
	                    xInt = (int) ptDst.getX();
90
	                    yInt = (int) ptDst.getY();
91
	                    if ((bFirst) || ((xInt != antX) || (yInt != antY)))
92
	                    {
93
	                        newGp.lineTo(xInt, yInt);
94
	                        antX = xInt;
95
	                        antY = yInt;
96
	                        bFirst = false;
97
	                        numSegmentsAdded++;
98
	                    }
99
	                    break;
100

  
101
	                case PathIterator.SEG_QUADTO:
102
	                    at.transform(theData,0,aux,0,2);
103
	                    newGp.quadTo(aux[0], aux[1], aux[2], aux[3]);
104
	                    numSegmentsAdded++;
105
	                    break;
106

  
107
	                case PathIterator.SEG_CUBICTO:
108
	                    at.transform(theData,0,aux,0,3);
109
	                    newGp.curveTo(aux[0], aux[1], aux[2], aux[3], aux[4], aux[5]);
110
	                    numSegmentsAdded++;
111
	                    break;
112

  
113
	                case PathIterator.SEG_CLOSE:
114
	                    if (numSegmentsAdded < 3)
115
	                        newGp.lineTo(antX, antY);
116
	                    newGp.closePath();
117

  
118
	                    break;
119
	            } //end switch
120

  
121
	            theIterator.next();
122
	        } //end while loop
123

  
124
	        Geometry geom = null;
125
	        switch (gp.getType())
126
	        {
127
	            case Geometry.TYPES.POINT: //Tipo punto
128
	            case Geometry.TYPES.POINT + Geometry.TYPES.Z:
129
	                geom = new org.gvsig.fmap.geom.primitive.Point2D(null, null, ptDst.getX(), ptDst.getY());
130
	                break;
131

  
132
	            case Geometry.TYPES.CURVE:
133
	            case Geometry.TYPES.CURVE + Geometry.TYPES.Z:
134
	            case Geometry.TYPES.ARC:
135
	            	geom = new Curve2D(null, null, newGp);
136
	                break;
137

  
138
	            case Geometry.TYPES.SURFACE:
139
	            case Geometry.TYPES.SURFACE + Geometry.TYPES.Z:
140
	            case Geometry.TYPES.CIRCLE:
141
	            case Geometry.TYPES.ELLIPSE:
142

  
143
	                geom = new Surface2D(null, null, newGp);
144
	                break;
145
	        }
146
	        return geom;
147
	    }
148

  
149

  
150
}
branches/Mobile_Compatible_milestone2/libraries/libFMap_mapcontext/src/org/gvsig/fmap/geometry/operation/CreateLabelsOperationContext.java
1
package org.gvsig.fmap.geometry.operation;
2

  
3
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
4

  
5
public class CreateLabelsOperationContext extends GeometryOperationContext{
6

  
7
	private int position;
8
	private boolean dublicates;
9
	public boolean isDublicates() {
10
		return dublicates;
11
	}
12
	public void setDublicates(boolean dublicates) {
13
		this.dublicates = dublicates;
14
	}
15
	public int getPosition() {
16
		return position;
17
	}
18
	public void setPosition(int position) {
19
		this.position = position;
20
	}
21

  
22

  
23
}
branches/Mobile_Compatible_milestone2/libraries/libFMap_mapcontext/src/org/gvsig/fmap/geometry/operation/Draw.java
1
package org.gvsig.fmap.geometry.operation;
2

  
3
import java.awt.geom.AffineTransform;
4

  
5
import org.gvsig.fmap.geom.Geometry;
6
import org.gvsig.fmap.geom.GeometryManager;
7
import org.gvsig.fmap.geom.operation.GeometryOperation;
8
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
9
import org.gvsig.fmap.geom.operation.GeometryOperationException;
10

  
11
public class Draw extends GeometryOperation{
12
	public static final int CODE = GeometryManager.getInstance()
13
	.registerGeometryOperation("draw", new Draw());
14

  
15
	public Object invoke(Geometry geom, GeometryOperationContext ctx) throws GeometryOperationException {
16
		DrawOperationContext doc=(DrawOperationContext)ctx;
17
		AffineTransform at=doc.getViewPort().getAffineTransform();
18
		geom.transform(at);
19
		doc.getSymbol().draw(doc.getGraphics(), at, geom, doc.getCancellable());
20
		return null;
21
	}
22

  
23
	public int getOperationIndex() {
24
		return CODE;
25
	}
26

  
27
}
branches/Mobile_Compatible_milestone2/libraries/libFMap_mapcontext/src/org/gvsig/fmap/geometry/operation/DrawOperationContext.java
1
package org.gvsig.fmap.geometry.operation;
2

  
3
import java.awt.Graphics2D;
4

  
5
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
6
import org.gvsig.fmap.mapcontext.ViewPort;
7
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
8

  
9
import com.iver.utiles.swing.threads.Cancellable;
10

  
11
public class DrawOperationContext extends GeometryOperationContext{
12
	private ISymbol symbol=null;
13
	private Graphics2D graphics=null;
14
	private Cancellable cancellable;
15
	private double dpi;
16
	private boolean hasDPI=false;
17
	private ViewPort viewPort;
18
	public ViewPort getViewPort() {
19
		return viewPort;
20
	}
21
	public void setViewPort(ViewPort viewPort) {
22
		this.viewPort = viewPort;
23
	}
24
	public Graphics2D getGraphics() {
25
		return graphics;
26
	}
27
	public void setGraphics(Graphics2D graphics) {
28
		this.graphics = graphics;
29
	}
30
	public ISymbol getSymbol() {
31
		return symbol;
32
	}
33
	public void setSymbol(ISymbol symbol) {
34
		this.symbol = symbol;
35
	}
36
	public void setCancellable(Cancellable cancel) {
37
		this.cancellable=cancel;
38

  
39
	}
40
	public Cancellable getCancellable() {
41
		return cancellable;
42
	}
43
	public void setDPI(double dpi) {
44
		this.hasDPI=true;
45
		this.dpi=dpi;
46
	}
47
	public double getDPI(){
48
		return dpi;
49
	}
50
	public boolean hasDPI() {
51
		return hasDPI;
52
	}
53

  
54
}
branches/Mobile_Compatible_milestone2/libraries/libFMap_mapcontext/src/org/gvsig/fmap/geometry/operation/CreateLabels.java
1
package org.gvsig.fmap.geometry.operation;
2

  
3
import org.gvsig.fmap.geom.Geometry;
4
import org.gvsig.fmap.geom.GeometryManager;
5
import org.gvsig.fmap.geom.operation.GeometryOperation;
6
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
7
import org.gvsig.fmap.geom.operation.GeometryOperationException;
8
import org.gvsig.fmap.geometry.utils.FLabel;
9

  
10
public class CreateLabels extends GeometryOperation{
11
	public static final int CODE = GeometryManager.getInstance()
12
			.registerGeometryOperation("createLabels", new CreateLabels());
13

  
14
	public Object invoke(Geometry geom, GeometryOperationContext ctx)
15
			throws GeometryOperationException {
16
		CreateLabelsOperationContext cloc = (CreateLabelsOperationContext) ctx;
17
		return createLabels(geom, cloc.getPosition(), cloc.isDublicates());
18
	}
19

  
20
	public int getOperationIndex() {
21
		return CODE;
22
	}
23

  
24
	private FLabel[] createLabels(Geometry geom, int position,
25
			boolean duplicates) {
26
		FLabel[] aux = new FLabel[1];
27
		aux[0] = FLabel.createFLabel(geom);
28

  
29
		return aux;
30
	}
31
}
branches/Mobile_Compatible_milestone2/libraries/libFMap_mapcontext/src/org/gvsig/fmap/geometry/utils/FConstant.java
1
/*
2
 * Created on 02-mar-2004
3
 *
4
 * To change the template for this generated file go to
5
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
6
 */
7
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 *
25
 * For more information, contact:
26
 *
27
 *  Generalitat Valenciana
28
 *   Conselleria d'Infraestructures i Transport
29
 *   Av. Blasco Ib??ez, 50
30
 *   46010 VALENCIA
31
 *   SPAIN
32
 *
33
 *      +34 963862235
34
 *   gvsig@gva.es
35
 *      www.gvsig.gva.es
36
 *
37
 *    or
38
 *
39
 *   IVER T.I. S.A
40
 *   Salamanca 50
41
 *   46005 Valencia
42
 *   Spain
43
 *
44
 *   +34 963163400
45
 *   dac@iver.es
46
 */
47
package org.gvsig.fmap.geometry.utils;
48

  
49

  
50
/**
51
  * Clase utilizada para almacenar las variables est?ticas.
52
 *
53
 * @author Vicente Caballero Navarro
54
 */
55
public class FConstant {
56
	/** Nombre de las unidades de medida, utilizadas. */
57
	public static String[] NAMES = null;
58
	public final static int SHAPE_TYPE_NULL = 0;
59
	public final static int SHAPE_TYPE_POINT = 1;
60
	public final static int SHAPE_TYPE_POLYLINE = 3;
61
	public final static int SHAPE_TYPE_POLYGON = 5;
62
	public final static int SHAPE_TYPE_MULTIPOINT = 8;
63
	public final static int SHAPE_TYPE_POINTZ = 11;
64
	public final static int SHAPE_TYPE_POLYLINEZ = 13;
65
	public final static int SHAPE_TYPE_POLYGONZ = 15;
66
	public final static int SHAPE_TYPE_MULTIPOINTZ = 18;
67
	public final static int SHAPE_TYPE_POINTM = 21;
68
	public final static int SHAPE_TYPE_POLYLINEM = 23;
69
	public final static int SHAPE_TYPE_POLYGONM = 25;
70
	public final static int SHAPE_TYPE_MULTIPOINTM = 28;
71
	public final static int LAYER_TYPE_DGN = 1;
72
	public final static int LAYER_TYPE_DWG = 2;
73
	public final static int LAYER_TYPE_DXF = 3;
74
	public final static int LAYER_TYPE_JPEG2000 = 4;
75
	public final static int LAYER_TYPE_SHP = 5;
76
	public final static int LAYER_TYPE_WMS = 6;
77
	public final static int LEGEND_TYPE_BREAK = 3;
78
	public final static int LEGEND_TYPE_DEFAULT = 1;
79
	public final static int LEGEND_TYPE_VALUE = 2;
80
	public final static int SYMBOL_TYPE_DEFAULT = 5;
81
	public final static int SYMBOL_TYPE_POINT = 1;
82
	public final static int SYMBOL_TYPE_LINE = 2;
83
	public final static int SYMBOL_TYPE_FILL = 4;
84
	public final static int SYMBOL_TYPE_TEXT = 7;
85
	public final static int SYMBOL_TYPE_ICON = 9;
86
	public final static int SYMBOL_TYPE_POINTZ = 11;
87
	public final static int SYMBOL_TYPE_MULTIPOINT = 8;
88
	public final static int SYMBOL_STYLE_POINTZ = 0;
89
	public final static int SYMBOL_TYPE_POLYLINEZ = 13;
90
	public final static int SYMBOL_TYPE_POLYGONZ = 15;
91

  
92

  
93

  
94

  
95
	/**
96
	 * If you want to obtain a 12-pixel height font you have to apply this
97
	 * scale factor. <br>
98
	 * So, it would be: <br>
99
	 * 	<b> font.setSize(FONT_SCALE_FACTOR*size)</b>
100
	 */
101
	public static final double FONT_HEIGHT_SCALE_FACTOR = 1.4;
102
	public static final double DEGREE_TO_RADIANS = Math.PI/180D;
103

  
104

  
105
	static {
106
		new FConstant();
107
	}
108

  
109
	/**
110
	 * 050211, jmorell: Se han a?adido los Grados.
111
	 * Crea un nuevo FConstant.
112
	 */
113
	public FConstant() {
114
		if (NAMES == null) {
115
			int i = 0;
116
			NAMES = new String[10];
117
			NAMES[i++] = "Kilometros";
118
			NAMES[i++] = "Metros";
119
			NAMES[i++] = "Centimetros";
120
			NAMES[i++] = "Milimetros";
121
			NAMES[i++] = "Millas";
122
			NAMES[i++] = "Yardas";
123
			NAMES[i++] = "Pies";
124
			NAMES[i++] = "Pulgadas";
125
			NAMES[i++] = "Grados";
126
			NAMES[i++] = "Coordenadas";
127
		}
128
	}
129
}
branches/Mobile_Compatible_milestone2/libraries/libFMap_mapcontext/src/org/gvsig/fmap/geometry/utils/FLabel.java
1
/*
2
 * Created on 13-jul-2004
3
 *
4
 * TODO To change the template for this generated file go to
5
 * Window - Preferences - Java - Code Generation - Code and Comments
6
 */
7
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 *
25
 * For more information, contact:
26
 *
27
 *  Generalitat Valenciana
28
 *   Conselleria d'Infraestructures i Transport
29
 *   Av. Blasco Ib??ez, 50
30
 *   46010 VALENCIA
31
 *   SPAIN
32
 *
33
 *      +34 963862235
34
 *   gvsig@gva.es
35
 *      www.gvsig.gva.es
36
 *
37
 *    or
38
 *
39
 *   IVER T.I. S.A
40
 *   Salamanca 50
41
 *   46005 Valencia
42
 *   Spain
43
 *
44
 *   +34 963163400
45
 *   dac@iver.es
46
 */
47
package org.gvsig.fmap.geometry.utils;
48

  
49
import java.awt.Color;
50
import java.awt.Font;
51
import java.awt.Graphics2D;
52
import java.awt.Shape;
53
import java.awt.geom.AffineTransform;
54
import java.awt.geom.Point2D;
55
import java.awt.geom.Rectangle2D;
56

  
57
import org.apache.batik.ext.awt.geom.PathLength;
58
import org.gvsig.fmap.geom.aggregate.MultiPoint2D;
59
import org.gvsig.fmap.geom.primitive.FShape;
60
import org.gvsig.fmap.geom.util.Converter;
61
import org.gvsig.fmap.mapcontext.ViewPort;
62
import org.gvsig.fmap.mapcontext.rendering.symbols.FGraphicUtilities;
63
import org.gvsig.fmap.mapcontext.rendering.symbols.FSymbol;
64
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
65

  
66
import com.iver.utiles.XMLEntity;
67
import com.vividsolutions.jts.geom.Geometry;
68
import com.vividsolutions.jts.geom.Point;
69

  
70

  
71
/**
72
 * Se utiliza para etiquetar. Las capas vectoriales tienen un arrayList
73
 * (m_labels) de FLabel, un FLabel por cada registro.
74
 *
75
 * @author FJP
76
 */
77
public class FLabel implements Cloneable {
78
	public final static byte LEFT_TOP = 0;
79
	public final static byte LEFT_CENTER = 1;
80
	public final static byte LEFT_BOTTOM = 2;
81
	public final static byte CENTER_TOP = 6;
82
	public final static byte CENTER_CENTER = 7;
83
	public final static byte CENTER_BOTTOM = 8;
84
	public final static byte RIGHT_TOP = 12;
85
	public final static byte RIGHT_CENTER = 13;
86
	public final static byte RIGHT_BOTTOM = 14;
87
	private String m_Str = null;
88
	private Point2D m_Orig = null;
89
	private double m_Height;
90
	public static final double SQUARE = Math.sqrt(2.0);
91
	/**
92
	 * <code>m_rotation</code> en grados, NO en radianes. Se convierte en
93
	 * radianes al dibujar.
94
	 */
95
	private double m_rotation;
96

  
97
	/**
98
	 * Valores posibles para <code>m_Justification</code>: Left/Top = 0
99
	 * Center/Top = 6                Right/Top = 12 Left/Center = 1
100
	 * Center/Center = 7            Right/Center = 13 Left/Bottom = 2
101
	 * Center/Bottom = 8            Right/Bottom = 14
102
	 */
103
	private byte m_Justification = LEFT_BOTTOM; // Por defecto
104
	private int m_Style;
105
	private Rectangle2D boundBox;
106
	private Color color;
107
	private static Font font=new Font("Dialog",Font.PLAIN,12);
108
	/**
109
	 * Crea un nuevo FLabel.
110
	 */
111
	public FLabel() {
112
	}
113

  
114
	/**
115
	 * Crea un nuevo FLabel.
116
	 *
117
	 * @param str DOCUMENT ME!
118
	 */
119
	public FLabel(String str) {
120
		m_Str = str;
121
	}
122

  
123
	/**
124
	 * Crea un nuevo FLabel.
125
	 *
126
	 * @param str
127
	 * @param pOrig
128
	 * @param heightText
129
	 * @param rotation
130
	 */
131
	public FLabel(String str, Point2D pOrig, double heightText, double rotation) {
132
		m_Str = str;
133
		m_Orig = pOrig;
134
		m_Height = heightText;
135
		m_rotation = rotation;
136
	}
137

  
138
	/**
139
	 * Introduce un nuevo FLabel al ya existente.
140
	 *
141
	 * @param label
142
	 */
143
	public void setFLabel(FLabel label) {
144
		m_Str = label.m_Str;
145
		m_Orig = label.m_Orig;
146
		m_Height = label.m_Height;
147
		m_rotation = label.m_rotation;
148
	}
149

  
150
	/**
151
	 * Clona el FLabel.
152
	 *
153
	 * @return Object clonado.
154
	 */
155
	public Object clone() {
156
		FLabel label=new FLabel(m_Str, m_Orig, m_Height, m_rotation);
157
		label.boundBox=(Rectangle2D)boundBox.clone();
158
		return label;
159
	}
160

  
161
	/**
162
	 * Devuelve la altura del Label.
163
	 *
164
	 * @return Returns the m_Height.
165
	 */
166
	public double getHeight() {
167
		return m_Height;
168
	}
169

  
170
	/**
171
	 * Devuelve el punto de origen.
172
	 *
173
	 * @return Returns the m_Orig.
174
	 */
175
	public Point2D getOrig() {
176
		return m_Orig;
177
	}
178

  
179
	/**
180
	 * Devuelve la rotaci?n.
181
	 *
182
	 * @return Returns the m_rotation.
183
	 */
184
	public double getRotation() {
185
		return m_rotation;
186
	}
187

  
188
	/**
189
	 * Devuelve un String con el texto del Label.
190
	 *
191
	 * @return Returns the m_Str.
192
	 */
193
	public String getString() {
194
		return m_Str;
195
	}
196

  
197
	/**
198
	 * Introduce la altura del Label.
199
	 *
200
	 * @param height The m_Height to set.
201
	 */
202
	public void setHeight(double height) {
203
		m_Height = height;
204
	}
205

  
206
	/**
207
	 * Introduce el punto de origen del Label.
208
	 *
209
	 * @param orig The m_Orig to set.
210
	 */
211
	public void setOrig(Point2D orig) {
212
		m_Orig = orig;
213
	}
214

  
215
	/**
216
	 * Introduce la rotaci?n a aplicar al Label.
217
	 *
218
	 * @param m_rotation The m_rotation to set.
219
	 */
220
	public void setRotation(double m_rotation) {
221
		this.m_rotation = Math.toRadians(-m_rotation);
222
	}
223

  
224
	/**
225
	 * Introduce el texto del Label.
226
	 *
227
	 * @param str The m_Str to set.
228
	 */
229
	public void setString(String str) {
230
		m_Str = str;
231
	}
232

  
233
	/**
234
	 * Valores posibles para <code>m_Justification</code>: Left/Top = 0
235
	 * Center/Top = 6                Right/Top = 12 Left/Center = 1
236
	 * Center/Center = 7            Right/Center = 13 Left/Bottom = 2
237
	 * Center/Bottom = 8            Right/Bottom = 14
238
	 *
239
	 * @return byte.
240
	 */
241
	public byte getJustification() {
242
		return m_Justification;
243
	}
244

  
245
	/**
246
	 * Valores posibles para <code>m_Justification</code>: Left/Top = 0
247
	 * Center/Top = 6                Right/Top = 12 Left/Center = 1
248
	 * Center/Center = 7            Right/Center = 13 Left/Bottom = 2
249
	 * Center/Bottom = 8            Right/Bottom = 14
250
	 *
251
	 * @param justification byte
252
	 */
253
	public void setJustification(byte justification) {
254
		m_Justification = justification;
255
	}
256

  
257
	/**
258
	 * Devuelve un Objeto XMLEntity con la informaci?n los atributos necesarios
259
	 * para poder despu?s volver a crear el objeto original.
260
	 *
261
	 * @return XMLEntity.
262
	 */
263
	public XMLEntity getXMLEntity() {
264
		XMLEntity xml = new XMLEntity();
265
		xml.putProperty("className",this.getClass().getName());
266
		xml.setName("flabel");
267
		xml.putProperty("m_Height", m_Height);
268
		xml.putProperty("m_Justification", (int) m_Justification);
269
		xml.putProperty("m_OrigX", m_Orig.getX());
270
		xml.putProperty("m_OrigY", m_Orig.getY());
271
		xml.putProperty("m_rotation", m_rotation);
272
		xml.putProperty("m_Str", m_Str);
273

  
274
		return xml;
275
	}
276

  
277
	/**
278
	 * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
279
	 *
280
	 * @param xml XMLEntity
281
	 *
282
	 * @return Objeto de esta clase.
283
	 */
284
	public static FLabel createFLabel(XMLEntity xml) {
285
		FLabel label = new FLabel();
286
		label.setHeight(xml.getDoubleProperty("m_Height"));
287
		label.setJustification((byte) xml.getIntProperty("m_Justification"));
288
		label.setOrig(new Point2D.Double(xml.getDoubleProperty("m_OrigX"),
289
				xml.getDoubleProperty("m_OrigY")));
290
		label.setString("m_Str");
291

  
292
		return label;
293
	}
294

  
295
	/**
296
	 * M?todo est?tico que crea un FLabel a partir de un FShape.
297
	 *
298
	 * @param shp FShape.
299
	 *
300
	 * @return nuevo FLabel creado.
301
	 */
302
	public static FLabel createFLabel(org.gvsig.fmap.geom.Geometry geom) {
303
		float angle;
304
		Point2D pAux = createLabelPoint(geom);
305

  
306
		FLabel label = new FLabel();
307
		label.setOrig(pAux);
308
		switch (geom.getType()) {
309
			case org.gvsig.fmap.geom.Geometry.TYPES.CURVE:
310
            case org.gvsig.fmap.geom.Geometry.TYPES.CURVE + org.gvsig.fmap.geom.Geometry.TYPES.Z:
311
				PathLength pathLen = new PathLength(geom);
312
				float midDistance = pathLen.lengthOfPath() / 2;
313
				angle = pathLen.angleAtLength(midDistance);
314

  
315
				if (angle < 0) {
316
					angle = angle + (float) (2 * Math.PI);
317
				}
318
				if ((angle > (Math.PI / 2)) && (angle < ((3 * Math.PI) / 2))) {
319
					angle = angle - (float) Math.PI;
320
				}
321
				label.setRotation(Math.toDegrees(angle));
322
				break;
323
		} // switch
324

  
325
		return label;
326
	}
327
	public static Point2D createLabelPoint(org.gvsig.fmap.geom.Geometry geom) {
328
		Point2D pAux = null;
329
		switch (geom.getType()) {
330
			case org.gvsig.fmap.geom.Geometry.TYPES.POINT:
331
            case org.gvsig.fmap.geom.Geometry.TYPES.POINT + org.gvsig.fmap.geom.Geometry.TYPES.Z:
332
				pAux = new Point2D.Double(((org.gvsig.fmap.geom.primitive.Point2D) geom).getX(),
333
						((org.gvsig.fmap.geom.primitive.Point2D) geom).getY());
334
				return pAux;
335

  
336
			case org.gvsig.fmap.geom.Geometry.TYPES.CURVE:
337
            case org.gvsig.fmap.geom.Geometry.TYPES.CURVE + org.gvsig.fmap.geom.Geometry.TYPES.Z:
338
				PathLength pathLen = new PathLength(geom);
339

  
340
				// if (pathLen.lengthOfPath() < width / mT.getScaleX()) return;
341
				float midDistance = pathLen.lengthOfPath() / 2;
342
				pAux = pathLen.pointAtLength(midDistance);
343
				return pAux;
344

  
345
			case org.gvsig.fmap.geom.Geometry.TYPES.SURFACE:
346
            case org.gvsig.fmap.geom.Geometry.TYPES.SURFACE + org.gvsig.fmap.geom.Geometry.TYPES.Z:
347
				Geometry geo = Converter.java2d_to_jts((FShape)geom);
348

  
349
				if (geo == null) {
350
					return null;
351
				}
352

  
353
				Point pJTS = geo.getCentroid();
354

  
355
				if (pJTS != null) {
356
					FShape pLabel = Converter.jts_to_java2d(pJTS);
357
					return new Point2D.Double(((org.gvsig.fmap.geom.primitive.Point2D) pLabel).getX(),
358
							((org.gvsig.fmap.geom.primitive.Point2D) pLabel).getY());
359
				}
360
				break;
361
            case org.gvsig.fmap.geom.Geometry.TYPES.MULTIPOINT:
362
            	int num=((MultiPoint2D)geom).getPrimitivesNumber();
363
    			Rectangle2D r=null;
364
    			if (num>0){
365
    				r= ((MultiPoint2D)geom).getPoint(0).getBounds2D();
366
    				for (int i=1;i<num;i++){
367
    					org.gvsig.fmap.geom.primitive.Point2D fp=((MultiPoint2D)geom).getPoint(i);
368
    					r.add(new Point2D.Double(fp.getX(),fp.getY()));
369
    				}
370
    			}
371
    			if (r!=null)
372
    			return new Point2D.Double(r.getCenterX(),r.getCenterY());
373
    			break;
374

  
375
		} // switch
376
				return null;
377
	}
378
	public void setTypeFont(String t) {
379
		font=Font.getFont(t,font);
380
	}
381
	public int getStyle() {
382
		return m_Style;
383
	}
384

  
385
	public void setBoundBox(Rectangle2D boundBox) {
386
		this.boundBox=boundBox;
387

  
388
	}
389
	public Rectangle2D getBoundBox(){
390
		return boundBox;
391
	}
392

  
393
	public Rectangle2D getBoundingBox(ViewPort vp) {
394
		return vp.fromMapRectangle(boundBox);
395
	}
396

  
397
	public void setColor(int i) {
398
		color=new Color(i);
399
	}
400

  
401
	public Color getColor() {
402
		return color;
403
	}
404
	/*public Font getFont(AffineTransform at,boolean isInPixels){
405
		if (!isInPixels) {
406
			float alturaPixels = (float) ((getHeight() * at.getScaleX())*SQUARE);
407
			//Font nuevaFuente = font.deriveFont(alturaPixels);//new Font(getTypeFont(),getStyle(),(int)alturaPixels);
408
			return font.deriveFont(alturaPixels);
409
		}
410
		//Font nuevaFuente = font.deriveFont((float)(getHeight()*SQUARE));//new Font(getTypeFont(),getStyle(),(int)(getHeight()*SQUARE));
411
		return font;//font.deriveFont((float)(getHeight()*SQUARE));
412
	}*/
413
	public Font getFont(AffineTransform at,Font font){
414
		float alturaPixels = (float) ((getHeight() * at.getScaleX())*SQUARE);
415
		return font.deriveFont(alturaPixels);
416
	}
417

  
418
	/**
419
	 * Por ahora, para extender el renderizado de etiquetas, habr?a que
420
	 * crear otro FLabel y reimplementar este m?todo para que haga caso
421
	 * a otros s?mbolos. Es decir, NO usar FGraphicUtilities
422
	 * @param g
423
	 * @param affineTransform
424
	 * @param theShape
425
	 * @param theSymbol
426
	 */
427
	public void draw(Graphics2D g, AffineTransform affineTransform, Shape theShape, ISymbol theSymbol) {
428
        FGraphicUtilities.DrawLabel(g, affineTransform,
429
                (org.gvsig.fmap.geom.Geometry) theShape, (FSymbol) theSymbol, this);
430

  
431

  
432
	}
433

  
434
}
branches/Mobile_Compatible_milestone2/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/exceptions/CancelEditingLayerException.java
1
package org.gvsig.fmap.mapcontext.exceptions;
2

  
3
import java.util.Hashtable;
4
import java.util.Map;
5

  
6
import org.gvsig.exceptions.BaseException;
7
/**
8
 * @author Vicente Caballero Navarro
9
 */
10
public class CancelEditingLayerException extends BaseException {
11

  
12
	private String layer = null;
13

  
14
	public CancelEditingLayerException(String layer,Throwable exception) {
15
		this.layer = layer;
16
		init();
17
		initCause(exception);
18
	}
19

  
20
	private void init() {
21
		messageKey = "error_cancel_editing_layer";
22
		formatString = "Can?t cancel editing the layer: %(layer) ";
23
	}
24

  
25
	protected Map values() {
26
		Hashtable params = new Hashtable();
27
		params.put("layer",layer);
28
		return params;
29
	}
30

  
31
}
branches/Mobile_Compatible_milestone2/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/exceptions/ConnectionErrorLayerException.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.fmap.mapcontext.exceptions;
42

  
43

  
44

  
45
/**
46
 * @author Vicente Caballero Navarro
47
 */
48
public class ConnectionErrorLayerException extends LoadLayerException {
49

  
50
	public ConnectionErrorLayerException(String l,Throwable exception) {
51
		super(l,exception);
52
		init();
53
	}
54
	/**
55
	 *
56
	 */
57
	private void init() {
58
		messageKey = "error_connection_layer";
59
		formatString = "Can?t connet the layer: %(layer) ";
60
	}
61
}
branches/Mobile_Compatible_milestone2/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/exceptions/StartEditionLayerException.java
1
package org.gvsig.fmap.mapcontext.exceptions;
2

  
3
import java.util.Hashtable;
4
import java.util.Map;
5

  
6
import org.gvsig.exceptions.BaseException;
7
/**
8
 * @author Vicente Caballero Navarro
9
 */
10
public class StartEditionLayerException extends BaseException {
11
	private String layer;
12
	public StartEditionLayerException(String l,Throwable exception) {
13
		this.layer=l;
14
		init();
15
		initCause(exception);
16
	}
17
	/**
18
	 *
19
	 */
20
	private void init() {
21
		messageKey = "error_start_editing_layer";
22
		formatString = "Can?t start editing the layer: %(tag) ";
23
	}
24

  
25

  
26
	protected Map values() {
27
		Hashtable params = new Hashtable();
28
		params.put("layer",layer);
29
		return params;
30
	}
31

  
32
}
branches/Mobile_Compatible_milestone2/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/exceptions/DriverLayerException.java
1
package org.gvsig.fmap.mapcontext.exceptions;
2

  
3

  
4
/**
5
 * @author Vicente Caballero Navarro
6
 */
7
public class DriverLayerException extends LoadLayerException {
8

  
9
	public DriverLayerException(String l,Throwable exception) {
10
		super(l,exception);
11
		init();
12
	}
13
	/**
14
	 *
15
	 */
16
	private void init() {
17
		messageKey = "error_driver_layer";
18
		formatString = "Can?t load driver of the layer: %(layer) ";
19
	}
20
}
branches/Mobile_Compatible_milestone2/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/exceptions/ProjectionLayerException.java
1
package org.gvsig.fmap.mapcontext.exceptions;
2

  
3

  
4
/**
5
 * @author Vicente Caballero Navarro
6
 */
7
public class ProjectionLayerException extends LoadLayerException {
8

  
9
	public ProjectionLayerException(String l,Throwable exception) {
10
		super(l,exception);
11
		init();
12
	}
13
	/**
14
	 *
15
	 */
16
	private void init() {
17
		messageKey = "error_projection_layer";
18
		formatString = "Can?t project the layer: %(layer) ";
19
	}
20

  
21
}
branches/Mobile_Compatible_milestone2/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/exceptions/LegendLayerException.java
1
package org.gvsig.fmap.mapcontext.exceptions;
2

  
3

  
4
/**
5
 * @author Vicente Caballero Navarro
6
 */
7
public class LegendLayerException extends LoadLayerException {
8

  
9
	public LegendLayerException(String l,Throwable exception) {
10
		super(l,exception);
11
		init();
12
	}
13
	/**
14
	 *
15
	 */
16
	private void init() {
17
		messageKey = "error_legend_layer";
18
		formatString = "Can?t load legend of the layer: %(layer) ";
19
	}
20

  
21
}
branches/Mobile_Compatible_milestone2/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/exceptions/UnsupportedVersionLayerException.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.fmap.mapcontext.exceptions;
42

  
43

  
44

  
45
/**
46
 * Excepci?n provocada por el WMS.
47
 *
48
 * @author Vicente Caballero Navarro
49
 */
50
public class UnsupportedVersionLayerException extends LoadLayerException {
51
	public UnsupportedVersionLayerException(String l,Throwable exception) {
52
		super(l,exception);
53
		init();
54
	}
55
	/**
56
	 *
57
	 */
58
	private void init() {
59
		messageKey = "error_version_layer";
60
		formatString = "Can?t use this version of the layer: %(layer) ";
61
	}
62
}
branches/Mobile_Compatible_milestone2/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/exceptions/FileLayerException.java
1
package org.gvsig.fmap.mapcontext.exceptions;
2

  
3

  
4

  
5
/**
6
 * @author Vicente Caballero Navarro
7
 */
8
public class FileLayerException extends LoadLayerException {
9

  
10
	public FileLayerException(String l,Throwable exception) {
11
		super(l,exception);
12
		init();
13
	}
14
	/**
15
	 *
16
	 */
17
	private void init() {
18
		messageKey = "error_file_layer";
19
		formatString = "Can?t found the file of the layer: %(layer) ";
20
	}
21
}
branches/Mobile_Compatible_milestone2/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/exceptions/LoadLayerException.java
1
package org.gvsig.fmap.mapcontext.exceptions;
2

  
3
import java.util.Hashtable;
4
import java.util.Map;
5

  
6
import org.gvsig.exceptions.BaseException;
7
/**
8
 * @author Vicente Caballero Navarro
9
 */
10
public class LoadLayerException extends BaseException {
11
	private String layer = null;
12

  
13
	public LoadLayerException(String layer,Throwable exception) {
14
		this.layer = layer;
15
		init();
16
		initCause(exception);
17
	}
18

  
19
	private void init() {
20
		messageKey = "error_load_layer";
21
		formatString = "Can?t load the layer: %(layer) ";
22
	}
23

  
24
	protected Map values() {
25
		Hashtable params = new Hashtable();
26
		params.put("layer",layer);
27
		return params;
28
	}
29

  
30
}
branches/Mobile_Compatible_milestone2/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/exceptions/NameLayerException.java
1
package org.gvsig.fmap.mapcontext.exceptions;
2

  
3

  
4
/**
5
 * @author Vicente Caballero Navarro
6
 */
7
public class NameLayerException extends LoadLayerException {
8

  
9
	public NameLayerException(String l,Throwable exception) {
10
		super(l,exception);
11
		init();
12
	}
13
	/**
14
	 *
15
	 */
16
	private void init() {
17
		messageKey = "error_name_layer";
18
		formatString = "Can?t named the layer: %(layer) ";
19
	}
20

  
21
}
branches/Mobile_Compatible_milestone2/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/exceptions/XMLLayerException.java
1
package org.gvsig.fmap.mapcontext.exceptions;
2

  
3

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff