Revision 12827

View differences:

trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/v02/FConstant.java
134 134
	 * 	<b> font.setSize(FONT_SCALE_FACTOR*size)</b>
135 135
	 */
136 136
	public static final double FONT_HEIGHT_SCALE_FACTOR = 1.4;
137
	public static final double DEGREE_TO_RADIANS = Math.PI/180D;
138
	
137 139

  
138 140
	static {
139 141
		new FConstant();
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/symbols/LineFillSymbol.java
56 56
import com.iver.cit.gvsig.fmap.core.FShape;
57 57
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
58 58
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
59
import com.iver.utiles.StringUtilities;
59 60
import com.iver.utiles.XMLEntity;
60 61

  
61 62
/**
......
118 119
		g.rotate(angle);
119 120
		while (aux <= radius) {
120 121
			double y = aux;
121
			double x = Math.sqrt(radius*radius - y*y);
122
//			double x1 = - x;
123
//			double x2 = x;
124 122
			double x1 = - radius;
125 123
			double x2 = radius;
126 124
			Line2D line;
......
162 160
	public XMLEntity getXMLEntity() {
163 161
		XMLEntity xml = new XMLEntity();
164 162
		xml.putProperty("className", getClassName());
163
		xml.putProperty("angle", angle);
164
		xml.putProperty("offset", offset);
165
		xml.putProperty("separation", separation);
166
		xml.putProperty("fillColor", StringUtilities.color2String(getFillColor()));
167
		if (lineSymbol!=null) {
168
			XMLEntity xmlLine = lineSymbol.getXMLEntity();
169
			xmlLine.putProperty("id", "fillLine");
170
			xml.addChild(xmlLine);
171
		}
172
		
173
		ILineSymbol outline = getOutline();
174
		if (outline!=null) {
175
			XMLEntity xmlOutline = outline.getXMLEntity();
176
			xmlOutline.putProperty("id", "outline");
177
			xml.addChild(xmlOutline);
178
		}
179
		
165 180
		return xml;
166 181
	}
167 182

  
168 183
	public void setXMLEntity(XMLEntity xml) {
184
		setAngle(xml.getDoubleProperty("angle"));
185
		setOffset(xml.getDoubleProperty("offset"));
186
		setSeparation(xml.getDoubleProperty("separation"));
187
		setFillColor(StringUtilities.string2Color(xml.getStringProperty("fillColor")));
188
		XMLEntity lineSymbolXML = xml.firstChild("id", "fillLine");
189
		if (lineSymbolXML != null) {
190
			setLineSymbol((ILineSymbol) SymbologyFactory.
191
					createSymbolFromXML(lineSymbolXML, "fill symbol"));
192
		}
169 193
		
194
		XMLEntity outlineXML = xml.firstChild("id", "outline");
195
		if (outlineXML != null) {
196
			setOutline((ILineSymbol) SymbologyFactory.
197
					createSymbolFromXML(outlineXML, "outline symbol"));
198
		}
170 199
	}
171 200

  
172 201
	public String getClassName() {
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/symbols/PictureFillSymbol.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 com.iver.cit.gvsig.fmap.core.symbols;
42

  
43
import java.awt.Graphics2D;
44
import java.awt.Paint;
45
import java.awt.Rectangle;
46
import java.awt.Shape;
47
import java.awt.TexturePaint;
48
import java.awt.geom.AffineTransform;
49
import java.awt.image.BufferedImage;
50
import java.io.File;
51
import java.io.IOException;
52

  
53
import javax.imageio.ImageIO;
54
import javax.print.attribute.PrintRequestAttributeSet;
55

  
56
import org.apache.log4j.Logger;
57

  
58
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
59
import com.iver.cit.gvsig.fmap.Messages;
60
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
61
import com.iver.cit.gvsig.fmap.core.FShape;
62
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
63
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
64
import com.iver.cit.gvsig.fmap.core.styles.IMarkerFillProperties;
65
import com.iver.cit.gvsig.fmap.core.styles.MarkerFillProperties;
66
import com.iver.utiles.XMLEntity;
67

  
68
/**
69
 * @author jaume dominguez faus - jaume.dominguez@iver.es
70
 */
71
public class PictureFillSymbol extends AbstractFillSymbol {
72
	private double angle = 0;
73
	private double xScale = 1;
74
	private double yScale = 1;
75
	
76
	private IMarkerFillProperties markerFillProperties = new MarkerFillProperties();
77
	private String imagePath;
78
	private BufferedImage img;
79

  
80
	public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) {
81
		g.setClip(shp);
82
		try{
83
			if (xScale<=0 &&  yScale<=0)
84
				return;
85
			
86
			BufferedImage img = getImg();
87
			AffineTransform scaleInstance = AffineTransform.
88
						getScaleInstance(xScale, yScale);
89
			
90
			final double imageWidth  = img.getWidth()  * xScale;
91
			final double imageHeight = img.getHeight() * yScale;
92
			
93
			if (imageWidth==0 || imageHeight==0) return;
94
			
95
			Rectangle rProv = new Rectangle();
96
			rProv.setFrame(0, 0, imageWidth, imageHeight);
97
			Paint resulPatternFill = null;
98
			
99
			Graphics2D gAux = img.createGraphics();
100

  
101
			double xSeparation = markerFillProperties.getXSeparation(); // TODO apply CartographicSupport
102
			double ySeparation = markerFillProperties.getYSeparation(); // TODO apply CartographicSupport
103
			double xOffset = markerFillProperties.getXOffset();// TODO apply CartographicSupport
104
			double yOffset = markerFillProperties.getYOffset();// TODO apply CartographicSupport
105
			
106
			rProv.setRect(0, 0,
107
					rProv.getWidth() + xSeparation,
108
					rProv.getHeight() + ySeparation);
109

  
110
			BufferedImage bi = new BufferedImage(rProv.width, rProv.height, BufferedImage.TYPE_INT_ARGB);
111
			gAux = bi.createGraphics();
112
			AffineTransform tx = AffineTransform.getScaleInstance(xScale, yScale);
113
			tx.translate(xSeparation*0.5, ySeparation*0.5);
114
			gAux.rotate(angle);
115
			gAux.drawImage(img, tx, null);
116

  
117
			resulPatternFill = new TexturePaint(bi,rProv);
118
			g.translate(xOffset, yOffset);
119
			g.setPaint(resulPatternFill);
120
			g.fill(shp);
121
			
122
		} catch (IOException e) {
123
			Logger.getLogger(this.getClass()).error(Messages.getString("failed_to_read_image_file"), e);
124
		}
125
		g.setClip(null);
126
		if (getOutline()!=null) {
127
			getOutline().draw(g, affineTransform, shp);
128
		}
129
	}
130

  
131
	private BufferedImage getImg() throws IOException {
132
		if (img == null) {
133
			img = ImageIO.read(new File(imagePath));
134
		}
135
		return img;
136
	}
137
	
138
	public void setImage(File imageFile) throws IOException{
139
		img = ImageIO.read(imageFile);
140
		imagePath = imageFile.getAbsolutePath();
141
	}
142
	
143
	public void drawInsideRectangle(Graphics2D g,
144
			AffineTransform scaleInstance, Rectangle r) {
145
		draw(g, null, new FPolygon2D(new GeneralPathX(r)));
146
	}
147

  
148
	public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform,
149
			Shape shp) {
150
		// TODO Auto-generated method stub
151
		throw new Error("Not yet implemented!");
152
	}
153

  
154
	public ISymbol getSymbolForSelection() {
155
		// TODO Auto-generated method stub
156
		throw new Error("Not yet implemented!");
157
	}
158

  
159
	public int getSymbolType() {
160
		return FShape.POLYGON;
161
	}
162

  
163
	public XMLEntity getXMLEntity() {
164
		XMLEntity xml = new XMLEntity();
165
		xml.putProperty("className", getClassName());
166
		xml.putProperty("angle", angle);
167
		xml.putProperty("scaleX", xScale);
168
		xml.putProperty("scaleY", yScale);
169
		xml.putProperty("imagePath", imagePath);
170
		XMLEntity fillPropertiesXML = markerFillProperties.getXMLEntity();
171
		fillPropertiesXML.putProperty("id", "fillProperties");
172
		xml.addChild(fillPropertiesXML);
173
		if (getOutline()!=null) {
174
			XMLEntity outlineXML = getOutline().getXMLEntity();
175
			outlineXML.putProperty("id", "outline symbol");
176
		}
177
		return xml;
178
	}
179

  
180
	public void setXMLEntity(XMLEntity xml) {
181
		File f = new File(xml.getStringProperty("imagePath"));
182
		try {
183
			setImage(f);
184
		setAngle(xml.getDoubleProperty("angle"));
185
		setXScale(xml.getDoubleProperty("scaleX"));
186
		setYScale(xml.getDoubleProperty("scaleY"));
187
		
188
		markerFillProperties = (IMarkerFillProperties) SymbologyFactory.
189
			createStyleFromXML(
190
					xml.firstChild("id", "fillProperties"), "fill properties");
191
		
192
		XMLEntity outlineXML = xml.firstChild("id", "outline symbol");
193
		if (outlineXML != null) {
194
			setOutline((ILineSymbol) SymbologyFactory.createSymbolFromXML(outlineXML, "outline"));
195
		}
196
		}catch (IOException e) {
197
			Logger.getLogger(this.getClass()).error(Messages.getString("failed_to_read_image_file"), e);
198
		}
199
		
200
	}
201

  
202
	public String getClassName() {
203
		return getClass().getName();
204
	}
205

  
206
	public void print(Graphics2D g, AffineTransform at, FShape shape,
207
			PrintRequestAttributeSet properties) throws ReadDriverException {
208
		// TODO Auto-generated method stub
209
		throw new Error("Not yet implemented!");
210
	}
211

  
212
	public IMarkerFillProperties getMarkerFillProperties() {
213
		return markerFillProperties;
214
	}
215
	
216
	public void setMarkerFillProperties(IMarkerFillProperties prop) {
217
		this.markerFillProperties = prop;
218
	}
219

  
220
	public double getAngle() {
221
		return angle;
222
	}
223

  
224
	public void setAngle(double angle) {
225
		this.angle = angle;
226
	}
227

  
228
	public double getXScale() {
229
		return xScale;
230
	}
231

  
232
	public void setXScale(double xScale) {
233
		this.xScale = xScale;
234
	}
235

  
236
	public double getYScale() {
237
		return yScale;
238
	}
239

  
240
	public void setYScale(double yScale) {
241
		this.yScale = yScale;
242
	}
243
	
244
	public String getImagePath() {
245
		return imagePath;
246
	}
247

  
248
}
0 249

  
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/symbols/PictureLineSymbol.java
135 135
	private BufferedImage getImg() throws IOException {
136 136
		if (img == null) {
137 137
			img = ImageIO.read(new File(imagePath));
138
//			imageOutline = null;
139 138
		}
140 139
		return img;
141 140
	}
141
	
142 142
	private BufferedImage getSelImg() throws IOException {
143 143
		if (selImg == null) {
144 144
			if (selImagePath!= null) {
145 145
				selImg = ImageIO.read(new File(selImagePath));
146 146
			} else return getImg();
147
//			imageOutline = null;
148 147
		}
149 148
		return selImg;
150 149
	}
151 150

  
152 151
	public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) {
153
		g.setColor(Color.black);
154 152
		g.setClip(new BasicStroke((float) width, BasicStroke.CAP_ROUND,BasicStroke.CAP_ROUND).createStrokedShape(shp));
155 153

  
156
//		if (true) return;
157 154
		try{
158 155
			BufferedImage img = selected ? getSelImg() : getImg();
159 156
			if (xScale<=0 &&  yScale<=0)

Also available in: Unified diff