Revision 11192

View differences:

trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/styling/LabelingFactory.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.5  2007-03-28 16:48:01  jaume
46
* Revision 1.6  2007-04-13 11:59:30  jaume
47 47
* *** empty log message ***
48 48
*
49
* Revision 1.5  2007/03/28 16:48:01  jaume
50
* *** empty log message ***
51
*
49 52
* Revision 1.4  2007/03/20 16:16:20  jaume
50 53
* refactored to use ISymbol instead of FSymbol
51 54
*
......
114 117
		Object obj = null;
115 118
		try {
116 119
			clazz = Class.forName(className);
117
			// TODO remove the patch the day we deprecate FSymbol
118 120
			obj = clazz.newInstance();
119 121
			((IPersistance) obj).setXMLEntity(xml);
120 122

  
......
183 185
			return createDefaultStrategy(layer);
184 186

  
185 187
		ILabelingStrategy strat = createDefaultStrategy(layer);
186
		strat.setLabelingMethod(method);
188
		if (method != null)
189
			strat.setLabelingMethod(method);
190
		if (placement != null)
191
			strat.setPlacementConstraints(placement);
187 192
		return strat;
188 193
		/* solament per a proves, ac? falta muntar el sistema expert que
189 194
		 * decidisca quina estrat?gia ?s la millor a partir dels par?metres.
......
208 213
		case FShape.POINT:
209 214
			return new PointPlacementConstraints();
210 215
		}
211
//		throw new Error("Shape type not yet supported");
212
		return null;
216
		throw new Error("Shape type not yet supported");
217
//		return null;
213 218
	}
214 219

  
220
	public static IPlacementConstraints createPlacementConstraints(XMLEntity entity) {
221
		return (IPlacementConstraints) createFromXML(entity);
222
	}
215 223

  
224

  
216 225
}
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/styling/PolygonPlacementConstraints.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.5  2007-04-12 14:28:43  jaume
46
* Revision 1.6  2007-04-13 11:59:30  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.5  2007/04/12 14:28:43  jaume
47 50
* basic labeling support for lines
48 51
*
49 52
* Revision 1.4  2007/04/11 16:01:08  jaume
......
70 73
import com.iver.cit.gvsig.fmap.core.FShape;
71 74
import com.iver.cit.gvsig.fmap.core.IGeometry;
72 75
import com.iver.cit.gvsig.fmap.core.symbols.ITextSymbol;
76
import com.iver.utiles.XMLEntity;
73 77
/**
74 78
 *
75 79
 * @author jaume dominguez faus - jaume.dominguez@iver.es
......
83 87

  
84 88
	}
85 89

  
86
	public void placeLabel(Graphics2D g, IGeometry geom, LabelClass lc, MultiPolygon exclusionZone, AffineTransform transform, String[] labelTexts) {
90
	public void placeLabel(Graphics2D g, IGeometry geom, LabelClass lc, MultiPolygon exclusionZone, AffineTransform transform) {
87 91
		// TODO Implement it
88 92
		throw new Error("Not yet implemented!");
89 93

  
90 94
	}
95

  
96

  
97
	public String getClassName() {
98
		return getClass().getName();
99
	}
100

  
101
	public XMLEntity getXMLEntity() {
102
		XMLEntity xml = super.getXMLEntity();
103
		xml.putProperty("className", getClassName());
104
		return xml;
105
	}
106

  
91 107
}
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/styling/LinePlacementConstraints.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.6  2007-04-12 16:01:11  jaume
46
* Revision 1.7  2007-04-13 11:59:30  jaume
47 47
* *** empty log message ***
48 48
*
49
* Revision 1.6  2007/04/12 16:01:11  jaume
50
* *** empty log message ***
51
*
49 52
* Revision 1.5  2007/04/12 14:28:43  jaume
50 53
* basic labeling support for lines
51 54
*
......
66 69
package com.iver.cit.gvsig.fmap.rendering.styling;
67 70

  
68 71
import java.awt.Graphics2D;
72
import java.awt.Rectangle;
69 73
import java.awt.geom.AffineTransform;
70
import java.awt.geom.Point2D;
71
import java.awt.image.AffineTransformOp;
72 74

  
73 75
import org.apache.batik.ext.awt.geom.PathLength;
74 76
import org.cresques.px.gml.MultiPolygon;
75 77

  
78
import com.iver.cit.gvsig.fmap.core.FPoint2D;
76 79
import com.iver.cit.gvsig.fmap.core.FShape;
77 80
import com.iver.cit.gvsig.fmap.core.IGeometry;
81
import com.iver.utiles.XMLEntity;
78 82
/**
79 83
 *
80 84
 * @author jaume dominguez faus - jaume.dominguez@iver.es
......
86 90
	public FShape[] getLocationsFor(IGeometry geom, FShape labelShape, MultiPolygon exclusionZone) {
87 91
		return new FShape[] { (FShape) geom.getInternalShape() };
88 92
	}
89
	public void placeLabel(Graphics2D g, IGeometry geom, LabelClass lc, MultiPolygon exclusionZone, AffineTransform at, String[] labelTexts) {
90
		Point2D startingPoint = null;
91
		double rot = 0;
93
	
94
	public void placeLabel(Graphics2D g, IGeometry geom, LabelClass lc, MultiPolygon exclusionZone, AffineTransform at) {
95
		Rectangle labelBounds = lc.getShape(g, at, geom).getBounds();
96

  
97

  
98
		FPoint2D startingPoint = null;
99
		double theta = 0;
92 100
		if (isFollowingLine()) {
93 101
			throw new Error("following line option not yet implemented");
94 102
			// 1. create text path
......
107 115
				distance = pathLen.lengthOfPath() * 0.5F;
108 116
			}
109 117

  
110
			startingPoint = pathLen.pointAtLength(distance);
118
			startingPoint = new FPoint2D(pathLen.pointAtLength(distance));
111 119

  
112 120
			if (isParallel()) {
113 121
				// get the line theta and apply it
114
				rot = pathLen.angleAtLength(distance);
122
				theta = -pathLen.angleAtLength(distance);
115 123

  
116 124
			} else if (isPerpendicular()) {
117 125
				// get the line theta with 90 degrees
118
				rot = pathLen.angleAtLength(distance) + HALF_PI;
126
				theta = -pathLen.angleAtLength(distance) + HALF_PI;
119 127
			}
120 128
		}
121 129

  
......
131 139
				// Offset to be on bellow of the line.
132 140
			} else if (isAboveTheLine()) {
133 141
				// Offset to be above the line (inverse offset to under the line)
134

  
135 142
			} else {
136 143
				// No offset.
137 144
			}
138 145

  
139

  
140

  
141 146
			/*
142 147
			 * Now, we'll need to see who is defining the orientation
143 148
			 * either the line or the page.
......
154 159
			// will be better handled by a SmartLinePlacement
155 160
			throw new Error("overlapping detection option not yet implemented");
156 161
		}
157
		AffineTransform old = g.getTransform();
158
		// g.transform(despla?ament, rotaci?, orientaci?)
159
		lc.drawInsideRectangle(g, lc.getShape(g, at, geom).getBounds());
160
		// g.transform(old)
162
		startingPoint.transform(at);
163
		labelBounds.setLocation(0-(int) (labelBounds.width*.5), 0 - (int) (labelBounds.height*.5));
164
		g.translate((int) startingPoint.getX(), (int) startingPoint.getY());
165
		if (theta != 0) {
166
			g.rotate(theta);
167
		}
168
		lc.drawInsideRectangle(g, labelBounds);
169
		if (theta != 0) {
170
			g.rotate(-theta);
171
		}
172
		g.translate(-(int) startingPoint.getX(), -(int) startingPoint.getY());
173

  
161 174
	}
162 175

  
176
	public String getClassName() {
177
		return getClass().getName();
178
	}
179

  
180
	public XMLEntity getXMLEntity() {
181
		XMLEntity xml = super.getXMLEntity();
182
		xml.putProperty("className", getClassName());
183
		return xml;
184
	}
163 185
}
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/styling/IPlacementConstraints.java
43 43
 *
44 44
 * $Id$
45 45
 * $Log$
46
 * Revision 1.6  2007-04-12 16:01:11  jaume
46
 * Revision 1.7  2007-04-13 11:59:30  jaume
47 47
 * *** empty log message ***
48 48
 *
49
 * Revision 1.6  2007/04/12 16:01:11  jaume
50
 * *** empty log message ***
51
 *
49 52
 * Revision 1.5  2007/04/12 14:28:43  jaume
50 53
 * basic labeling support for lines
51 54
 *
......
77 80
import com.iver.cit.gvsig.fmap.core.FShape;
78 81
import com.iver.cit.gvsig.fmap.core.IGeometry;
79 82
import com.iver.cit.gvsig.fmap.core.symbols.ITextSymbol;
83
import com.iver.utiles.IPersistance;
80 84

  
81 85
/**
82 86
 * @author   jaume dominguez faus - jaume.dominguez@iver.es
83 87
 */
84
public interface IPlacementConstraints {
88
public interface IPlacementConstraints extends IPersistance {
85 89

  
86 90
	// constants regarding label duplication
87 91
	public static final int REMOVE_DUPLICATE_LABELS             =       2;
......
110 114
	public abstract void setPlacementMode(int mode);
111 115

  
112 116
	// regarding label position along the line
113
	public abstract boolean isAtTheBeginingOfLine();
114
	public abstract void setAtTheBeginingOfLine(boolean b);
115
	public abstract boolean isAtTheEndOfLine();
116
	public abstract void setAtTheEndOfLine(boolean b);
117 117
	public abstract boolean isBellowTheLine();
118 118
	public abstract void setBellowTheLine(boolean b);
119 119
	public abstract boolean isAboveTheLine();
120 120
	public abstract void setAboveTheLine(boolean b);
121
	public abstract void setLocationAlongTheLine(int location);
121 122

  
123

  
122 124
	// regarding the orientation system
123 125
	public abstract boolean isPageOriented();
124 126
	public abstract void setPageOriented(boolean b);
......
141 143
			MultiPolygon exclusionZone);
142 144

  
143 145
	public abstract void placeLabel(Graphics2D g, IGeometry geom,
144
		LabelClass lc, MultiPolygon exclusionZone, AffineTransform transform, String[] labelTexts);
146
		LabelClass lc, MultiPolygon exclusionZone, AffineTransform transform);
145 147

  
146 148
	public abstract boolean isParallel();
147 149

  
......
151 153

  
152 154
	public abstract boolean isHorizontal();
153 155

  
156

  
154 157
}
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/styling/PointPlacementConstraints.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.6  2007-04-12 14:28:43  jaume
46
* Revision 1.7  2007-04-13 11:59:30  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.6  2007/04/12 14:28:43  jaume
47 50
* basic labeling support for lines
48 51
*
49 52
* Revision 1.5  2007/04/11 16:01:08  jaume
......
73 76
import com.iver.cit.gvsig.fmap.core.FPoint2D;
74 77
import com.iver.cit.gvsig.fmap.core.FShape;
75 78
import com.iver.cit.gvsig.fmap.core.IGeometry;
79
import com.iver.utiles.XMLEntity;
76 80
/**
77 81
 *
78 82
 * @author jaume dominguez faus - jaume.dominguez@iver.es
......
96 100
		}
97 101
	}
98 102

  
99
	public void placeLabel(Graphics2D g, IGeometry geom, LabelClass lc, MultiPolygon exclusionZone, AffineTransform transform, String[] labelTexts) {
103
	public void placeLabel(Graphics2D g, IGeometry geom, LabelClass lc, MultiPolygon exclusionZone, AffineTransform transform) {
100 104
		// TODO Implement it
101 105
		throw new Error("Not yet implemented!");
102 106

  
103 107
	}
108

  
109
	public String getClassName() {
110
		return getClass().getName();
111
	}
112

  
113
	public XMLEntity getXMLEntity() {
114
		XMLEntity xml = super.getXMLEntity();
115
		xml.putProperty("className", getClassName());
116
		return xml;
117
	}
118

  
104 119
}
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/styling/AbstractPlacementConstraints.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.4  2007-04-12 16:01:11  jaume
46
* Revision 1.5  2007-04-13 11:59:30  jaume
47 47
* *** empty log message ***
48 48
*
49
* Revision 1.4  2007/04/12 16:01:11  jaume
50
* *** empty log message ***
51
*
49 52
* Revision 1.3  2007/04/11 16:01:08  jaume
50 53
* maybe a label placer refactor
51 54
*
......
76 79

  
77 80
package com.iver.cit.gvsig.fmap.rendering.styling;
78 81
import com.iver.cit.gvsig.fmap.core.FShape;
82
import com.iver.utiles.XMLEntity;
79 83

  
80 84
/**
81 85
 * @author  jaume dominguez faus - jaume.dominguez@iver.es
......
85 89

  
86 90
	private int duplicateLabelsMode = ONE_LABEL_PER_FEATURE_PART; // default duplicate treatment
87 91
	private int placementMode;
88

  
89
	private boolean atTheBeginingOfLine;
90

  
91
	private boolean atTheEndOfLine;
92

  
93 92
	private boolean bellowTheLine;
94

  
95 93
	private boolean aboveTheLine;
96

  
97 94
	private boolean pageOriented;
95
	private int locationAlongLine;
98 96

  
99 97
	public void setDuplicateLabelsMode(int mode) {
100 98
		if (mode != REMOVE_DUPLICATE_LABELS &&
......
108 106
	}
109 107

  
110 108
	public void setPlacementMode(int mode) {
111
		switch (shapeType) {
112
		case FShape.POINT:
109
		if (this instanceof PointPlacementConstraints) {
113 110
			if (mode != OFFSET_HORIZONTALY_AROUND_THE_POINT &&
114 111
				mode != ON_TOP_OF_THE_POINT &&
115 112
				mode != AT_SPECIFIED_ANGLE &&
......
119 116
						"ON_TOP_OF_THE_POINT, " +
120 117
						"AT_SPECIFIED_ANGLE " +
121 118
						"or AT_ANGLE_SPECIFIED_BY_A_FIELD allowed for points");
122
			break;
123
		case FShape.POLYGON:
119
		}
120

  
121
		if (this instanceof PolygonPlacementConstraints) {
124 122
			if (mode != HORIZONTAL &&
125 123
				mode != PARALLEL )
126 124
					throw new IllegalArgumentException(
127 125
							"Only HORIZONTAL, " +
128 126
							"or PARALEL allowed for polygons");
129
			break;
130
		case FShape.LINE:
131
			if (mode != HORIZONTAL &&
127
		}
128

  
129
		if (this instanceof LinePlacementConstraints) {
130
					if (mode != HORIZONTAL &&
132 131
				mode != PARALLEL &&
133 132
				mode != FOLLOWING_LINE &&
134 133
				mode != PERPENDICULAR)
135 134
				throw new IllegalArgumentException(
136 135
						"Only HORIZONTAL, " +
137 136
						"or PARALEL allowed for lines");
138
			break;
139 137
		}
140 138
		this.placementMode = mode;
141 139
	}
......
168 166
		return placementMode == ON_TOP_OF_THE_POINT;
169 167
	}
170 168

  
171
	public boolean isAtTheBeginingOfLine() {
172
		return atTheBeginingOfLine;
173
	}
174

  
175
	public boolean isAtTheEndOfLine() {
176
		return atTheEndOfLine;
177
	}
178

  
179 169
	public boolean isBellowTheLine() {
180 170
		return bellowTheLine;
181 171
	}
......
187 177
	public boolean isPageOriented() {
188 178
		return pageOriented;
189 179
	}
180

  
190 181
	public void setPageOriented(boolean b) {
191
		this.pageOriented = pageOriented;
182
		this.pageOriented = b;
192 183
	}
193 184

  
185
	public void setBellowTheLine(boolean b) {
186
		this.bellowTheLine = b;
187
	}
194 188

  
195
	public void setAtTheBeginingOfLine(boolean b) {
196
		this.atTheBeginingOfLine = b;
189
	public void setAboveTheLine(boolean b) {
190
		this.aboveTheLine = b;
197 191
	}
198 192

  
199
	public void setAtTheEndOfLine(boolean b) {
200
		this.atTheEndOfLine = b;
193
	public boolean isAtTheEndOfLine() {
194
		return locationAlongLine == AT_THE_END_OF_THE_LINE;
201 195
	}
202 196

  
203
	public void setBellowTheLine(boolean b) {
204
		this.bellowTheLine = b;
197

  
198
	public boolean isAtTheBeginingOfLine() {
199
		return locationAlongLine == AT_THE_BEGINING_OF_THE_LINE;
205 200
	}
206 201

  
207
	public void setAboveTheLine(boolean b) {
208
		this.aboveTheLine = b;
202
	public void setLocationAlongTheLine(int location) {
203
		if (location != IPlacementConstraints.AT_THE_MIDDLE_OF_THE_LINE
204
			&& location != IPlacementConstraints.AT_THE_BEGINING_OF_THE_LINE
205
			&& location != IPlacementConstraints.AT_THE_END_OF_THE_LINE) {
206
			throw new IllegalArgumentException("Only IPlacementConstraints.AT_THE_MIDDLE_OF_THE_LINE, " +
207
					"IPlacementConstraints.AT_THE_BEGINING_OF_THE_LINE, or " +
208
					"IPlacementConstraints.AT_THE_END_OF_THE_LINE values are allowed");
209
		}
210
		this.locationAlongLine = location;
209 211
	}
212

  
213
	public XMLEntity getXMLEntity() {
214
		XMLEntity xml = new XMLEntity();
215
		return xml;
216
	}
217

  
218
	public void setXMLEntity(XMLEntity xml) {
219

  
220
	}
210 221
}
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/styling/SimpleLabeling.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.7  2007-04-12 14:28:43  jaume
46
* Revision 1.8  2007-04-13 11:59:30  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.7  2007/04/12 14:28:43  jaume
47 50
* basic labeling support for lines
48 51
*
49 52
* Revision 1.6  2007/04/11 16:01:08  jaume
......
183 186

  
184 187
				 geom = rv.getShape(i);
185 188
				 lc.setTexts(getText(index, sds));
186
				 FShape labelShape = lc.getShape(g, viewPort.getAffineTransform(), geom);
187
				 g.setColor(Color.RED);
188
				 g.draw(labelShape);
189
//				 FShape labelShape = lc.getShape(g, viewPort.getAffineTransform(), geom);
189 190
				 // refactor
190 191
//				  if (labelShape is big enough)
191 192
				 {
192 193
					 String[] texts = getText(index, sds);
193 194

  
194
					 placementConstraints.placeLabel(g, geom, lc, null, viewPort.getAffineTransform(), texts);
195
					 placementConstraints.placeLabel(g, geom, lc, null, viewPort.getAffineTransform());
195 196
				 }
196 197

  
197 198

  
......
261 262
		return placementConstraints;
262 263
	}
263 264

  
264
	public void setPlacementConstraints(IPlacementConstraints constraints) {}
265
	public void setPlacementConstraints(IPlacementConstraints constraints) {
266
		this.placementConstraints = constraints;
267
	}
265 268

  
266 269
	public IZoomConstraints getZoomConstraints() {
267 270
		return zoomConstraints;

Also available in: Unified diff