Revision 11104

View differences:

trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/styling/SimpleLabeling.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.4  2007-04-02 16:34:56  jaume
46
* Revision 1.5  2007-04-10 16:34:01  jaume
47
* towards a styled labeling
48
*
49
* Revision 1.4  2007/04/02 16:34:56  jaume
47 50
* Styled labeling (start commiting)
48 51
*
49 52
* Revision 1.3  2007/03/28 16:48:01  jaume
......
80 83
*/
81 84
package com.iver.cit.gvsig.fmap.rendering.styling;
82 85

  
86
import java.awt.Color;
83 87
import java.awt.Graphics2D;
84 88
import java.awt.geom.AffineTransform;
85 89
import java.awt.geom.Rectangle2D;
......
181 185
					 for (int j = 0; j < places.length; j++) {
182 186
						 places[j].transform(viewPort.getAffineTransform());
183 187
						 lc.drawInsideRectangle(g, places[j].getBounds(), texts);
188
						 g.setColor(Color.BLUE);
189
						 g.draw(places[j]);
190

  
184 191
					 }
185 192
				 }
186 193
			 }
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/styling/LabelClass.java
40 40
 */
41 41

  
42 42
/* CVS MESSAGES:
43
*
44
* $Id$
45
* $Log$
46
* Revision 1.4  2007-04-05 16:07:14  jaume
47
* Styled labeling stuff
48
*
49
* Revision 1.3  2007/04/02 16:34:56  jaume
50
* Styled labeling (start commiting)
51
*
52
* Revision 1.2  2007/03/09 08:33:43  jaume
53
* *** empty log message ***
54
*
55
* Revision 1.1.2.6  2007/02/15 16:23:44  jaume
56
* *** empty log message ***
57
*
58
* Revision 1.1.2.5  2007/02/09 07:47:05  jaume
59
* Isymbol moved
60
*
61
* Revision 1.1.2.4  2007/02/02 16:21:24  jaume
62
* start commiting labeling stuff
63
*
64
* Revision 1.1.2.3  2007/02/01 17:46:49  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.1.2.2  2007/02/01 11:42:47  jaume
68
* *** empty log message ***
69
*
70
* Revision 1.1.2.1  2007/01/30 18:10:45  jaume
71
* start commiting labeling stuff
72
*
73
*
74
*/
43
 *
44
 * $Id$
45
 * $Log$
46
 * Revision 1.5  2007-04-10 16:34:01  jaume
47
 * towards a styled labeling
48
 *
49
 * Revision 1.4  2007/04/05 16:07:14  jaume
50
 * Styled labeling stuff
51
 *
52
 * Revision 1.3  2007/04/02 16:34:56  jaume
53
 * Styled labeling (start commiting)
54
 *
55
 * Revision 1.2  2007/03/09 08:33:43  jaume
56
 * *** empty log message ***
57
 *
58
 * Revision 1.1.2.6  2007/02/15 16:23:44  jaume
59
 * *** empty log message ***
60
 *
61
 * Revision 1.1.2.5  2007/02/09 07:47:05  jaume
62
 * Isymbol moved
63
 *
64
 * Revision 1.1.2.4  2007/02/02 16:21:24  jaume
65
 * start commiting labeling stuff
66
 *
67
 * Revision 1.1.2.3  2007/02/01 17:46:49  jaume
68
 * *** empty log message ***
69
 *
70
 * Revision 1.1.2.2  2007/02/01 11:42:47  jaume
71
 * *** empty log message ***
72
 *
73
 * Revision 1.1.2.1  2007/01/30 18:10:45  jaume
74
 * start commiting labeling stuff
75
 *
76
 *
77
 */
75 78
package com.iver.cit.gvsig.fmap.rendering.styling;
76 79

  
77 80
import java.awt.Graphics2D;
78 81
import java.awt.Point;
79 82
import java.awt.Rectangle;
83
import java.awt.geom.AffineTransform;
84
import java.awt.geom.Point2D;
80 85
import java.awt.geom.Rectangle2D;
81 86

  
82 87
import com.iver.cit.gvsig.fmap.core.FPoint2D;
......
89 94
import com.iver.cit.gvsig.fmap.core.symbols.ITextSymbol;
90 95
import com.iver.cit.gvsig.fmap.core.symbols.SimpleTextSymbol;
91 96

  
92

  
93 97
/**
94
 * @author   jaume dominguez faus - jaume.dominguez@iver.es
98
 * @author jaume dominguez faus - jaume.dominguez@iver.es
95 99
 */
96 100
public final class LabelClass {
97 101
	private String name;
102

  
98 103
	private ITextSymbol label;
104

  
99 105
	private String labelExpression;
106

  
100 107
	private boolean isVisible;
108

  
101 109
	private ILabelStyle labelStyle;
102 110

  
103 111
	public boolean isVisible() {
......
124 132
	}
125 133

  
126 134
	public void setSymbol(ITextSymbol textSymbol) {
127
		label =  textSymbol;
135
		label = textSymbol;
128 136
		if (label == null)
129 137
			label = new SimpleTextSymbol();
130 138
	}
......
149 157
		return name;
150 158
	}
151 159

  
152
	public void drawInsideRectangle(Graphics2D graphics, Rectangle bounds, String[] texts) {
153
		bounds.y = bounds.y - bounds.height;
160
	public void drawInsideRectangle(Graphics2D graphics, Rectangle bounds,
161
			String[] texts) {
154 162
		if (labelStyle != null) {
155 163
			labelStyle.drawInsideRectangle(graphics, bounds);
164
			Point2D offset = new Point2D.Double(bounds.getMinX(), bounds
165
					.getMinY());
166
			graphics.translate(offset.getX(), offset.getY());
156 167
			for (int i = 0; i < texts.length; i++) {
157 168
				getLabelSymbol().setText(texts[i]);
158 169
				Rectangle2D textArea = labelStyle.getTextBounds()[i];
159
				Rectangle textRect = new Rectangle(
160
						(int) (bounds.x * textArea.getX()),
161
						(int) (bounds.y * textArea.getY()),
170

  
171
				Rectangle textRect = new Rectangle((int) (bounds.x * textArea
172
						.getX()), (int) (bounds.y * textArea.getY()),
162 173
						(int) (bounds.width * textArea.getWidth()),
163
						(int) (bounds.height * textArea.getHeight())
164
						);
174
						(int) (bounds.height * textArea.getHeight()));
165 175

  
166 176
				getLabelSymbol().drawInsideRectangle(graphics, null, textRect);
167 177
			}
178
			graphics.translate(-bounds.getX(), -bounds.getY());
168 179
		} else {
169 180
			getLabelSymbol().setText(texts[0]);
170 181
			getLabelSymbol().drawInsideRectangle(graphics, null, bounds);
171 182
		}
172 183
	}
173 184

  
174
	public FShape getShape(Graphics2D g, /*AffineTransform at,*/ IGeometry geom) {
185
	public FShape getShape(Graphics2D g, /* AffineTransform at, */IGeometry geom) {
175 186
		if (labelStyle == null) {
176 187
			// shape is defined by the symbol
177 188
			FShape shp = null;
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/styling/AttrInTableLabeling.java
141 141
					g.setColor(Color.GREEN);
142 142
					for (int j = 0; j < aux.length; j++) {
143 143
						FPoint2D p = new FPoint2D(aux[j].getOrig());
144
						sym.draw(g, viewPort.getAffineTransform(), p);
144
						p.transform(viewPort.getAffineTransform());
145
						sym.draw(g, null, p);
145 146
					}
146 147
				}
147 148
			} catch (VisitorException e) {
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/symbols/SimpleTextSymbol.java
86 86

  
87 87
		Point2D p = null;
88 88
		double rot=0;
89
		shp.transform(affineTransform);
89
//		shp.transform(affineTransform);
90 90
		switch (shp.getShapeType()) {
91 91
		case FShape.POINT:
92 92
			FPoint2D fp=(FPoint2D) shp;
......
137 137
			AffineTransform scaleInstance, Rectangle r) {
138 138
		FontRenderContext frc = g.getFontRenderContext();
139 139
		GlyphVector gv = font.createGlyphVector(frc, text);
140
		gv.
141
		float fontSize = getFont().getSize();
140
				float fontSize = getFont().getSize();
142 141
		float fontScaleFactor = (float) ((getText().length()*fontSize) * 0.8) // text length with a 20% margin
143 142
								/ r.width;
144 143

  
145
		fontSize = fontSize * fontScaleFactor;
144
		fontSize = fontSize / fontScaleFactor;
145
//		if (fontSize > r.height)
146
//			fontSize = r.height;
146 147
		g.setFont(getFont().deriveFont(fontSize));
147
		System.out.println(r);
148
		g.drawString(getText(), r.x*0.9F, ( r.height*0.5F) + (fontSize*0.5F));
148
		g.drawString(getText(), r.x*0.9F, ( r.height*0.5F) + (fontSize));
149
//		g.drawString(getText(), r.x, r.height);//( r.height*0.5F) + (fontSize*0.5F));
149 150

  
150 151

  
151 152
	}
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/styles/SimpleLabelStyle.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.8  2007-04-05 16:07:14  jaume
46
* Revision 1.9  2007-04-10 16:34:01  jaume
47
* towards a styled labeling
48
*
49
* Revision 1.8  2007/04/05 16:07:14  jaume
47 50
* Styled labeling stuff
48 51
*
49 52
* Revision 1.7  2007/04/04 15:42:03  jaume
......
257 260
			}
258 261
		}
259 262
	}
263

  
260 264
	public void setTextFieldArea(int index, Rectangle2D rect) {
261 265
		// patch, please remove it
262 266
		if (textFieldAreas.size()==0)

Also available in: Unified diff