Revision 27690

View differences:

trunk/extensions/extSymbology/src/org/gvsig/symbology/gui/styling/editortools/LabelStylePanTool.java
53 53
import javax.swing.JComponent;
54 54
import javax.swing.JToggleButton;
55 55

  
56
import org.gvsig.symbology.fmap.styles.SimpleLabelStyle;
57

  
56 58
import com.iver.andami.PluginServices;
57 59
import com.iver.cit.gvsig.fmap.core.styles.ILabelStyle;
60
import com.iver.cit.gvsig.fmap.core.styles.IStyle;
58 61
import com.iver.cit.gvsig.gui.styling.EditorTool;
59 62
import com.iver.cit.gvsig.gui.styling.StyleEditor;
63
import com.iver.cit.gvsig.gui.styling.StylePreviewer;
60 64
/**
61 65
 *
62 66
 * SimpleLabelStylePanTool.java
......
96 100
		if (cursor == null) {
97 101
			ImageIcon cursorImage = new ImageIcon(PluginServices.getIconTheme().get("hand-icon").getImage());
98 102
			cursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImage.getImage(),
99
					new Point(16, 16), "");
103
					new Point(cursorImage.getIconWidth()/2,
104
							cursorImage.getIconHeight()/2), //16, 16), "");
105
							"");
100 106

  
101 107
		}
102 108
		return cursor;
......
108 114
		pIni = new Point((int) (marker.getX()*(bounds.width-ownerHgap)),(int) (marker.getY()*(bounds.height-ownerVgap)));
109 115
		pEnd = e.getPoint();
110 116

  
111
		Point selectedPoint = new Point((int) (e.getPoint().getX()-ownerHgap),(int) (e.getPoint().getY()-ownerVgap));
117
		Point selectedPoint = new Point((int) (pEnd.getX()-ownerHgap),(int) (pEnd.getY()-ownerVgap));
112 118
		if((Math.abs(pIni.x - selectedPoint.x) < ownerHgap ) && (Math.abs(pIni.y - selectedPoint.y) < ownerVgap )){
113 119
			toolSelected = MARKER_POINT_SELECTED;
114 120
			return;
115 121
		}
116 122

  
123
		Point2D selPoint = screenPointToLabelPoint(pEnd);
124

  
117 125
		for (int i = style.getTextBounds().length - 1; i >= 0 ; i--) {
118

  
119 126
			Rectangle2D rectangle = style.getTextBounds()[i];
120

  
121
			if((selectedPoint.x >= rectangle.getMinX()*(bounds.getWidth() - ownerHgap)) &&
122
					(selectedPoint.x <= (rectangle.getMinX()*(bounds.getWidth() - ownerHgap)+ rectangle.getWidth()*(bounds.getWidth() - ownerHgap))))
123

  
124
				if((selectedPoint.y >= rectangle.getMinY()*(bounds.getHeight() - ownerVgap)) &&
125
						(selectedPoint.y <= (rectangle.getMinY()*(bounds.getHeight() - ownerVgap)+ rectangle.getHeight()*(bounds.getHeight() - ownerVgap)))){
126
					toolSelected = TEXT_FIELD_SELECTED;
127
					textFieldSelected = i;
128
					return;
129
				}
130

  
127
			if((selPoint.getX() >= rectangle.getMinX()) &&
128
					(selPoint.getX() <= rectangle.getMaxX()) &&
129
					(selPoint.getY() >= rectangle.getMinY())&&
130
					(selPoint.getY() <= rectangle.getMaxY())){
131
				toolSelected = TEXT_FIELD_SELECTED;
132
				textFieldSelected = i;
133
				pIni = pEnd;
134
				return;
135
			}
131 136
		}
132

  
133

  
134 137
	}
135 138

  
136 139
	public void mouseReleased(MouseEvent e) {
......
146 149
				(pEnd.getX() < ownerHgap) || ( pEnd.getY() < ownerVgap))
147 150
			return;
148 151

  
152
		Point2D labelEndPoint = screenPointToLabelPoint(pEnd);
149 153

  
150 154
		if(toolSelected == TEXT_FIELD_SELECTED){
151 155
			if(textFieldSelected != NO_SELECTION_ON_STYLE){
152 156

  
153 157
				Rectangle2D rectangle = style.getTextBounds()[textFieldSelected];
154 158

  
155
				double distXMoved = (pEnd.getX()-pIni.getX())/(bounds.getWidth()- ownerHgap);
156
				double distYMoved = (pEnd.getY()-pIni.getY())/(bounds.getHeight()- ownerVgap);
159
				Point2D labelIniPoint = screenPointToLabelPoint(pIni);
160
				Point maxPoint = new Point((int)bounds.getWidth(), (int)bounds.getHeight());
161
				Point2D labelMaxPoint = screenPointToLabelPoint(maxPoint);
157 162

  
158
				double finalXCorner = rectangle.getMinX() + distXMoved ;
159
				double finalYCorner = rectangle.getMinY() + distYMoved ;
163
				Point2D labelZero = screenPointToLabelPoint(new Point(0,0));
164
				double x = rectangle.getX() + labelEndPoint.getX()-labelIniPoint.getX();
165
				if (x<labelZero.getX()){ x=labelZero.getX(); }
166
				if ((x+rectangle.getWidth())>=labelMaxPoint.getX()) { x =  labelMaxPoint.getX()-rectangle.getWidth();}
160 167

  
161
				if(finalXCorner + rectangle.getWidth() > 1)
162
					finalXCorner = 1-rectangle.getWidth();
163
				if(finalXCorner < 0)
164
					finalXCorner = 0;
165
				if(finalYCorner + rectangle.getHeight() > 1)
166
					finalYCorner = 1-rectangle.getHeight();
167
				if(finalYCorner < 0)
168
					finalYCorner = 0;
168
				double y = rectangle.getY() + labelEndPoint.getY()-labelIniPoint.getY();
169
				if (y<labelZero.getY()){ y=labelZero.getY(); }
170
				if ((y+rectangle.getHeight())>=labelMaxPoint.getY()) { y =  labelMaxPoint.getY()-rectangle.getHeight();}
169 171

  
170
				rectangle.setRect(finalXCorner, finalYCorner, rectangle.getWidth(), rectangle.getHeight());
172
				rectangle.setRect(x,
173
						y,
174
						rectangle.getWidth(),
175
						rectangle.getHeight());
171 176
				style.setTextFieldArea(textFieldSelected,rectangle);
172 177
				pIni = pEnd;
173 178
			}
......
187 192
		owner.repaint();
188 193
	}
189 194

  
195
	private Point2D screenPointToLabelPoint(Point pIni) {
196
		//FIXME: Esto es un parche, habr?a que cambiar la API de los estilos y simbolos
197
		//pero mientras tanto
198
		int minx = pIni.x;
199
		int miny = pIni.y;
200

  
201
		StylePreviewer sp = ((StyleEditor) owner).getStylePreviewer();
202
		Dimension bounds = sp.getSize();
203

  
204
		IStyle style = sp.getStyle();
205
		Dimension backgroundBounds = null;
206
		if (style instanceof SimpleLabelStyle){
207
			backgroundBounds = ((SimpleLabelStyle)style).getSize();
208
		}
209
		Point2D p;
210
		if (backgroundBounds == null){
211
			p = new Point2D.Double(
212
					pIni.x/(bounds.getWidth()-sp.getHGap()/2),
213
					pIni.y/(bounds.getHeight()-sp.getVGap()/2));
214
		} else {
215
			double xOffset = 0;
216
			double yOffset = 0;
217
			double scale = 1;
218
			if (backgroundBounds.getWidth()>backgroundBounds.getHeight()) {
219
				scale = (bounds.getWidth()-sp.getHGap())/backgroundBounds.getWidth();
220
				yOffset = 0.5*(bounds.getHeight()-sp.getVGap() - backgroundBounds.getHeight()*scale);
221
			} else {
222
				scale = (bounds.getHeight()-sp.getVGap())/backgroundBounds.getHeight();
223
				xOffset = 0.5*(bounds.getWidth()-sp.getHGap() - backgroundBounds.getWidth()*scale);
224
			}
225
			p = new Point2D.Double(
226
					((minx-(sp.getHGap()/2)-xOffset)/scale)/backgroundBounds.getWidth(),
227
					((miny-(sp.getVGap()/2)-yOffset)/scale)/backgroundBounds.getHeight());
228
		}
229
		return p;
230
	}
231

  
190 232
	@Override
191 233
	public AbstractButton getButton() {
192 234
		return getBtnPan();

Also available in: Unified diff