Revision 25807 trunk/extensions/extSymbology/src/org/gvsig/symbology/gui/styling/editortools/LabelStyleNewTextFieldTool.java

View differences:

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