Revision 11009 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/styling/LabelClass.java

View differences:

LabelClass.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.2  2007-03-09 08:33:43  jaume
46
* Revision 1.3  2007-04-02 16:34:56  jaume
47
* Styled labeling (start commiting)
48
*
49
* Revision 1.2  2007/03/09 08:33:43  jaume
47 50
* *** empty log message ***
48 51
*
49 52
* Revision 1.1.2.6  2007/02/15 16:23:44  jaume
......
68 71
*/
69 72
package com.iver.cit.gvsig.fmap.rendering.styling;
70 73

  
74
import java.awt.Graphics;
75
import java.awt.Graphics2D;
76
import java.awt.Point;
77
import java.awt.Rectangle;
78
import java.awt.geom.AffineTransform;
79

  
80
import com.iver.cit.gvsig.fmap.core.FPoint2D;
81
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
82
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
83
import com.iver.cit.gvsig.fmap.core.FShape;
84
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
85
import com.iver.cit.gvsig.fmap.core.IGeometry;
71 86
import com.iver.cit.gvsig.fmap.core.styles.ILabelStyle;
72
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
73 87
import com.iver.cit.gvsig.fmap.core.symbols.ITextSymbol;
74 88
import com.iver.cit.gvsig.fmap.core.symbols.SimpleTextSymbol;
75 89

  
......
132 146
	public String toString() {
133 147
		return name;
134 148
	}
149

  
150
	public void drawInsideRectangle(Graphics2D graphics, Rectangle bounds, String[] texts) {
151
		bounds.y = bounds.y - bounds.height;
152
		if (labelStyle != null) {
153
			labelStyle.drawInsideRectangle(graphics, bounds);
154
			for (int i = 0; i < texts.length; i++) {
155
				getLabelSymbol().setText(texts[i]);
156
				getLabelSymbol().drawInsideRectangle(graphics, null, labelStyle.getTextBounds()[i]);
157
			}
158
		} else {
159
			getLabelSymbol().setText(texts[0]);
160
			getLabelSymbol().drawInsideRectangle(graphics, null, bounds);
161
		}
162
	}
163

  
164
	public FShape getShape(Graphics2D g, /*AffineTransform at,*/ IGeometry geom) {
165
		if (labelStyle == null) {
166
			// shape is defined by the symbol
167
			FShape shp = null;
168

  
169
			switch (geom.getGeometryType()) {
170
			case FShape.POINT:
171
				shp = new FPoint2D((Point) geom.getInternalShape());
172
				break;
173
			case FShape.LINE:
174
				shp = new FPolyline2D(new GeneralPathX(geom.getInternalShape()));
175
				break;
176
			case FShape.POLYGON:
177
				shp = new FPolygon2D(new GeneralPathX(geom.getInternalShape()));
178
				break;
179
			}
180
			return getLabelSymbol().getTextWrappingShape(g, shp);
181
		} else {
182
			// shape is defined by the style
183
			// maybe this is incorrect but for the moment we'll go with it
184
			Rectangle bounds = labelStyle.getBounds();
185
			return new FPolygon2D(new GeneralPathX(bounds));
186
		}
187
	}
135 188
}

Also available in: Unified diff