Revision 11051 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/styles/SimpleLabelStyle.java

View differences:

SimpleLabelStyle.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.5  2007-04-02 16:34:56  jaume
46
* Revision 1.6  2007-04-04 15:41:05  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.5  2007/04/02 16:34:56  jaume
47 50
* Styled labeling (start commiting)
48 51
*
49 52
* Revision 1.4  2007/04/02 00:10:04  jaume
......
65 68
*/
66 69
package com.iver.cit.gvsig.fmap.core.styles;
67 70

  
71
import java.awt.Color;
72
import java.awt.Dimension;
68 73
import java.awt.Graphics2D;
74
import java.awt.Point;
69 75
import java.awt.Rectangle;
76
import java.awt.geom.AffineTransform;
77
import java.awt.geom.Point2D;
70 78
import java.awt.geom.Rectangle2D;
71 79

  
80
import com.iver.cit.gvsig.fmap.Messages;
72 81
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
73 82
import com.iver.utiles.XMLEntity;
74 83

  
......
78 87
 */
79 88
public class SimpleLabelStyle extends SVGStyle implements ILabelStyle{
80 89
	private String text;
90
	private Point2D markerPoint = new Point2D.Double();
81 91

  
82 92
	public int getFieldCount() {
83 93
		return 1;
......
132 142
	public Rectangle getBounds() {
133 143
		return super.getBounds();
134 144
	}
145

  
146
	public Point2D getMarkerPoint() {
147
		return markerPoint;
148
	}
149

  
150
	public void setMarkerPoint(Point2D p) throws IllegalArgumentException {
151
		if (p.getX()<0 || p.getX()>1)
152
			throw new IllegalArgumentException("X must be >=0 and <=1 ("+p.getX()+")");
153
		if (p.getY()<0 || p.getY()>1)
154
			throw new IllegalArgumentException("Y must be >=0 and <=1 ("+p.getY()+")");
155
		// the marker represents the point labeled in relative percent units
156
		this.markerPoint = p;
157
	}
158

  
159
	public void drawOutline(Graphics2D g, Rectangle r) {
160
		super.drawOutline(g, r);
161
		Rectangle labelSz = getBounds();
162

  
163
		double ratioLabel = labelSz.getWidth()/labelSz.getHeight();
164
		double ratioViewPort = r.getWidth() / r.getWidth();
165

  
166
		int x;
167
		int y;
168
		if (ratioViewPort > ratioLabel) {
169
			// size is defined by the viewport height
170
			y = (int) (r.height*markerPoint.getY());
171
			x = (int) ((0.5*r.width) - (0.5-markerPoint.getX())*(ratioLabel*r.height));
172
		} else {
173
			// size is defined by the viewport width
174
			x = (int) (r.width * markerPoint.getX());
175
			y = (int) ((0.5 * r.height) - (0.5-markerPoint.getY())*(r.width/ratioLabel));
176
		}
177
		y = r.height - y;
178

  
179
		int size = 3;
180
		g.setColor(Color.RED);
181
		g.fillOval(x, y, size, size);
182
		g.drawString(Messages.getString("labeled_point"), x + size + 5, y);
183
	}
184

  
185
	public Dimension getPreferredSize() {
186
		return new Dimension(getBounds().width, getBounds().height);
187
	}
135 188
}

Also available in: Unified diff