Revision 25807

View differences:

trunk/extensions/extSymbology/src/org/gvsig/symbology/fmap/styles/SimpleLabelStyle.java
226 226
		}
227 227
		if (xml.contains("sizeW"))
228 228
			sz=new Dimension(xml.getIntProperty("sizeW"),xml.getIntProperty("sizeH"));
229
	}
229
		}
230 230

  
231 231
	public Rectangle2D[] getTextBounds() {
232 232
		return (Rectangle2D[]) textFieldAreas.toArray(new Rectangle2D[textFieldAreas.size()]);
......
265 265
		if(getBackgroundFileStyle() != null)
266 266
			getBackgroundFileStyle().drawOutline(g, r);
267 267

  
268

  
269 268
		final double[] xy = new double[2];
270 269
		// draw the pointer
271 270
		{
......
296 295
			outline.setLineColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), 100));
297 296
			sym.setOutline(outline);
298 297
			for (int i = 0; i < textFieldAreas.size(); i++) {
299
				Rectangle2D textFieldArea = (Rectangle2D) textFieldAreas.get(i);
300
				xy[0] = textFieldArea.getX();
301
				xy[1] = textFieldArea.getY();
298
				//FIXME: Esto es un parche, habr?a que cambiar el API de los simbolos y/o estilos
299
				//pero mientras tanto
300
				if(getBackgroundFileStyle() == null){
301
					Rectangle2D textFieldArea = (Rectangle2D) textFieldAreas.get(i);
302
					xy[0] = textFieldArea.getX();
303
					xy[1] = textFieldArea.getY();
302 304

  
303
				int x = (int) Math.round(((r.width) * xy[0]));
304
				int y = (int) Math.round((r.height) * xy[1]);
305
					int x = (int) Math.round(((r.width) * xy[0]));
306
					int y = (int) Math.round((r.height) * xy[1]);
305 307

  
306
				xy[0] = textFieldArea.getMaxX();
307
				xy[1] = textFieldArea.getMaxY();
308
					xy[0] = textFieldArea.getMaxX();
309
					xy[1] = textFieldArea.getMaxY();
308 310

  
309
				int width = (int) Math.round((r.width * xy[0]) -x);
310
				int height = (int) Math.round((r.height * xy[1]) - y) ;
311
					int width = (int) Math.round((r.width * xy[0]) -x);
312
					int height = (int) Math.round((r.height * xy[1]) - y) ;
311 313

  
312
				Rectangle aux = new Rectangle(x, y, width, height);
313
				FShape shp = new FPolygon2D(new GeneralPathX(aux));
314
				sym.draw(g, null, shp, null);
315
				g.setColor(Color.BLACK);
316
				g.drawString(String.valueOf(i+1), x+5, y + 10); // start with 1
314
					Rectangle aux = new Rectangle(x, y, width, height);
315
					FShape shp = new FPolygon2D(new GeneralPathX(aux));
316
					sym.draw(g, null, shp, null);
317
					g.setColor(Color.BLACK);
318
					g.drawString(String.valueOf(i+1), x+5, y + 10); // start with 1
319
				} else {
320
					double xOffset = 0;
321
					double yOffset = 0;
322
					double scale = 1;
323
					Dimension backgroundBounds = getSize();
324
					if (backgroundBounds.getWidth()>backgroundBounds.getHeight()) {
325
						scale = r.getWidth()/backgroundBounds.getWidth();
326
						yOffset = 0.5*(r.getHeight() - backgroundBounds.getHeight()*scale);
327
					} else {
328
						scale = r.getHeight()/backgroundBounds.getHeight();
329
						xOffset = 0.5*(r.getWidth() - backgroundBounds.getWidth()*scale);
330
					}
331

  
332
					Rectangle2D textFieldArea = (Rectangle2D) textFieldAreas.get(i);
333
					xy[0] = textFieldArea.getX();
334
					xy[1] = textFieldArea.getY();
335

  
336
					int x = (int) Math.round(xy[0]*backgroundBounds.getWidth()*scale+xOffset);
337
					int y = (int) Math.round(xy[1]*backgroundBounds.getHeight()*scale+yOffset);
338

  
339
					xy[0] = textFieldArea.getMaxX();
340
					xy[1] = textFieldArea.getMaxY();
341

  
342
					int width = (int) Math.round((xy[0]*backgroundBounds.getWidth()*scale+xOffset)-x);
343
					int height = (int) Math.round((xy[1]*backgroundBounds.getHeight()*scale+yOffset)-y);
344

  
345
					Rectangle aux = new Rectangle(x, y, width, height);
346
					FShape shp = new FPolygon2D(new GeneralPathX(aux));
347
					sym.draw(g, null, shp, null);
348
					g.setColor(Color.BLACK);
349
					g.drawString(String.valueOf(i+1), x+5, y + 10); // start with 1
350

  
351
				}
317 352
			}
318 353
		}
319 354
	}
trunk/extensions/extSymbology/src/org/gvsig/symbology/gui/styling/editortools/LabelStyleNewTextFieldTool.java
51 51
import javax.swing.JComponent;
52 52
import javax.swing.JToggleButton;
53 53

  
54
import org.gvsig.symbology.fmap.styles.SimpleLabelStyle;
55

  
54 56
import com.iver.andami.PluginServices;
55 57
import com.iver.cit.gvsig.fmap.core.styles.ILabelStyle;
58
import com.iver.cit.gvsig.fmap.core.styles.IStyle;
56 59
import com.iver.cit.gvsig.gui.styling.EditorTool;
57 60
import com.iver.cit.gvsig.gui.styling.StyleEditor;
61
import com.iver.cit.gvsig.gui.styling.StylePreviewer;
58 62

  
59 63
public class LabelStyleNewTextFieldTool extends EditorTool {
60 64
	private Point pIni, pEnd;
......
115 119
			height = -height;
116 120
		}
117 121

  
122
		StylePreviewer sp = ((StyleEditor) owner).getStylePreviewer();
123
		Dimension bounds = sp.getSize();
118 124

  
119
		Dimension bounds = ((StyleEditor) owner).getStylePreviewer().getSize();
125
		IStyle style = sp.getStyle();
126
		Dimension backgroundBounds = null;
127
		if (style instanceof SimpleLabelStyle){
128
			backgroundBounds = ((SimpleLabelStyle)style).getSize();
129
		}
130
		//FIXME: Esto es un parche, habr?a que cambiar la API de los estilos y simbolos
131
		//pero mientras tanto
132
		Rectangle2D rect;
133
		if (backgroundBounds == null){
134
			rect = new Rectangle2D.Double(
135
					minx/(bounds.getWidth()-sp.getHGap()/2), //OJO, aqu? pon?a cuatro 10's a pi?on fijo
136
					miny/(bounds.getHeight()-sp.getVGap()/2),
137
					width/(bounds.getWidth()-sp.getHGap()),
138
					height/(bounds.getHeight()-sp.getVGap())
139
			);
140
		} else {
120 141

  
121
		Rectangle2D rect = new Rectangle2D.Double(
122
				minx/(bounds.getWidth()-10),
123
				miny/(bounds.getHeight()-10),
124
				width/(bounds.getWidth()-10),
125
				height/(bounds.getHeight()-10)
126
				);
142
			double xOffset = 0;
143
			double yOffset = 0;
144
			double scale = 1;
145
			if (backgroundBounds.getWidth()>backgroundBounds.getHeight()) {
146
				scale = (bounds.getWidth()-sp.getHGap())/backgroundBounds.getWidth();
147
				yOffset = 0.5*(bounds.getHeight()-sp.getVGap() - backgroundBounds.getHeight()*scale);
148
			} else {
149
				scale = (bounds.getHeight()-sp.getVGap())/backgroundBounds.getHeight();
150
				xOffset = 0.5*(bounds.getWidth()-sp.getHGap() - backgroundBounds.getWidth()*scale);
151
			}
152

  
153
			rect = new Rectangle2D.Double(
154
					((minx-(sp.getHGap()/2)-xOffset)/scale)/backgroundBounds.getWidth(),
155
					((miny-(sp.getVGap()/2)-yOffset)/scale)/backgroundBounds.getHeight(),
156
					(width/scale)/backgroundBounds.getWidth(),
157
					(height/scale)/backgroundBounds.getHeight()
158
			);
159
		}
160

  
127 161
		return rect;
128 162
	}
129 163

  

Also available in: Unified diff