Revision 3883 trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/CADToolAdapter.java

View differences:

CADToolAdapter.java
3 3
import java.awt.Color;
4 4
import java.awt.Cursor;
5 5
import java.awt.Graphics;
6
import java.awt.Image;
6 7
import java.awt.Point;
8
import java.awt.Toolkit;
7 9
import java.awt.event.MouseEvent;
8 10
import java.awt.event.MouseWheelEvent;
9 11
import java.awt.geom.Point2D;
12
import java.awt.geom.Rectangle2D;
13
import java.awt.image.MemoryImageSource;
10 14
import java.io.IOException;
11 15
import java.util.Stack;
12 16

  
13 17
import com.iver.andami.PluginServices;
18
import com.iver.cit.gvsig.CADExtension;
19
import com.iver.cit.gvsig.fmap.DriverException;
14 20
import com.iver.cit.gvsig.fmap.ViewPort;
21
import com.iver.cit.gvsig.fmap.core.Handler;
22
import com.iver.cit.gvsig.fmap.core.IFeature;
23
import com.iver.cit.gvsig.fmap.core.IGeometry;
15 24
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
16 25
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
17 26
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
......
23 32
import com.iver.cit.gvsig.gui.View;
24 33
import com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool;
25 34

  
26
/**
27
 * DOCUMENT ME!
28
 *
29
 * @author Fernando Gonz?lez Cort?s
30
 */
31 35
public class CADToolAdapter extends Behavior {
32 36
	private Stack cadToolStack = new Stack();
33 37

  
......
42 46
	private boolean adjustSnapping = false;
43 47
	private VectorialEditableAdapter vea;
44 48
	private CADGrid cadgrid=new CADGrid();
49

  
45 50
	/**
46 51
	 * Pinta de alguna manera especial las geometrias seleccionadas para la
47 52
	 * edici?n. En caso de que el snapping est? activado, pintar? el efecto
......
52 57
	public void paintComponent(Graphics g) {
53 58
		super.paintComponent(g);
54 59
		drawCursor(g);
55

  
60
		getGrid().drawGrid(g);
56 61
		if (adjustedPoint != null) {
57 62
			Point2D p=null;
58 63
			if (mapAdjustedPoint != null) {
......
69 74
	 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
70 75
	 */
71 76
	public void mouseClicked(MouseEvent e) throws BehaviorException {
72

  
77
		if (e.getButton()==MouseEvent.BUTTON3){
78
			CADExtension.showPopup(e);
79
		}
73 80
	}
74 81

  
75 82
	/**
......
113 120
	 */
114 121
	private double adjustToHandler(Point2D point,
115 122
		Point2D mapHandlerAdjustedPoint) {
116
	/***	//if (selection.cardinality() > 0) {
123
		//if (selection.cardinality() > 0) {
117 124
		double rw=getMapControl().getViewPort().toMapDistance(5);
118 125
		try {
119 126
			Point2D mapPoint = point;
......
127 134
			Point2D mapArgmin = null;
128 135

  
129 136
			for (int i = 0; i < indexes.length; i++) {
130
				IFeature fea;
131
				fea = vea.getFeature(indexes[i]);
137
				IFeature fea=null;
138
					fea = vea.getFeature(indexes[i]);
139
				Handler[] handlers = fea.getGeometry().getHandlers(IGeometry.SELECTHANDLER);
132 140

  
133
				Handler[] handlers = fea.getGeometry().getHandlers(FGeometry.SELECTHANDLER);
134

  
135 141
				for (int j = 0; j < handlers.length; j++) {
136 142
					Point2D handlerPoint = handlers[j].getPoint();
137 143
					//System.err.println("handlerPoint= "+ handlerPoint);
138 144
					Point2D handlerImagePoint = handlerPoint;
139 145
					double dist = handlerImagePoint.distance(point);
140
					if ((dist < getMapControl().getViewPort().toMapDistance(SelectionCadTool.tolerance)) &&
146
					if ((dist < getMapControl().getViewPort().toMapDistance(SelectionCADTool.tolerance)) &&
141 147
							(dist < min)) {
142 148
						min = dist;
143 149
						argmin = handlerImagePoint;
......
156 162

  
157 163
				return min;
158 164
			}
159
		} catch (IOException e) {
165
		} catch (DriverException e) {
160 166
			e.printStackTrace();
161
		} catch (DriverIOException e) {
162
			e.printStackTrace();
163 167
		}
164
	***/
168

  
165 169
		return Double.MAX_VALUE;
166 170

  
167 171
	}
......
170 174
	 * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
171 175
	 */
172 176
	public void mouseReleased(MouseEvent e) throws BehaviorException {
177
		getMapControl().repaint();
173 178
	}
174 179

  
175 180
	/**
......
186 191
	 * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
187 192
	 */
188 193
	public void mouseMoved(MouseEvent e) throws BehaviorException {
194

  
189 195
		lastX = e.getX();
190 196
		lastY = e.getY();
191 197

  
......
193 199

  
194 200
		getMapControl().repaint();
195 201
	}
196

  
202
	private void clearMouseImage(){
203
		int[] pixels = new int[16 * 16];
204
		Image image = Toolkit.getDefaultToolkit().createImage(
205
			new MemoryImageSource(16, 16, pixels, 0, 16));
206
		Cursor transparentCursor =
207
			Toolkit.getDefaultToolkit().createCustomCursor
208
			    (image, new Point(0,0), "invisiblecursor");
209
		View view=CADExtension.getView();
210
		view.setCursor(transparentCursor);
211
	}
197 212
	/**
198 213
	 * DOCUMENT ME!
199 214
	 *
200 215
	 * @param g DOCUMENT ME!
201 216
	 */
202 217
	private void drawCursor(Graphics g) {
218
		clearMouseImage();
203 219
		Point2D p = adjustedPoint;
204 220

  
205 221
		if (p == null) {
......
218 234
		if (adjustedPoint != null) {
219 235
			if (adjustSnapping) {
220 236
				g.setColor(Color.ORANGE);
221
				g.drawRect((int) (adjustedPoint.getX() - 5),
222
					(int) (adjustedPoint.getY() - 5), 10, 10);
237
				g.drawRect((int) (adjustedPoint.getX() - 6),
238
					(int) (adjustedPoint.getY() - 6), 12, 12);
223 239
				g.drawRect((int) (adjustedPoint.getX() - 3),
224 240
					(int) (adjustedPoint.getY() - 3), 6, 6);
225 241
				g.setColor(Color.MAGENTA);
......
244 260

  
245 261
		Point2D gridAdjustedPoint = getMapControl().getViewPort().toMapPoint(point);
246 262
		double minDistance = Double.MAX_VALUE;
247

  
248
	/***	if (cadToolStack.peek() instanceof SelectionCadTool && ((SelectionCadTool)cadToolStack.peek()).getAutomaton().getStatus()==0){
263
		CADTool ct=(CADTool)cadToolStack.peek();
264
		if (ct instanceof SelectionCADTool && ((SelectionCADTool)ct).getStatus().equals("ExecuteMap.Initial")){
249 265
			mapAdjustedPoint=gridAdjustedPoint;
250 266
			adjustedPoint=(Point2D)point.clone();
251 267
		}else{
252
***/
268

  
253 269
			minDistance= getGrid().adjustToGrid(gridAdjustedPoint);
254 270
			if (minDistance < Double.MAX_VALUE) {
255 271
				adjustedPoint = getMapControl().getViewPort().fromMapPoint(gridAdjustedPoint);
......
257 273
			} else {
258 274
				mapAdjustedPoint = null;
259 275
			}
260
	/***	}***/
276
		}
261 277
		Point2D handlerAdjustedPoint = null;
262 278

  
263 279
		//Se comprueba el ajuste a los handlers
......
330 346
				}
331 347
			//}
332 348
		}
349

  
333 350
	}
334 351

  
335 352
	/**
......
339 356
	 */
340 357
	public void transition(String text) {
341 358
		transition( vea, text);
342
		configureMenu();
359

  
343 360
	}
344 361

  
345 362
	/**
346 363
	 * DOCUMENT ME!
347 364
	 */
348
	private void configureMenu() {
349
	/***	String[] desc = ((CADTool) cadToolStack.peek()).getAutomaton()
350
						 .getCurrentTransitionDescriptions();
351
		String[] labels = ((CADTool) cadToolStack.peek()).getAutomaton()
352
						   .getCurrentTransitions();
353
		getMapControl().clearMenu();
365
	public void configureMenu() {
366
		String[] desc = ((CADTool) cadToolStack.peek()).getDescriptions();
367
		//String[] labels = ((CADTool) cadToolStack.peek()).getCurrentTransitions();
368
		CADExtension.clearMenu();
354 369

  
355 370
		for (int i = 0; i < desc.length; i++) {
356 371
			if (desc[i] != null) {
357
				getMapControl().addMenuEntry(desc[i], labels[i]);
372
				CADExtension.addMenuEntry(desc[i]);//, labels[i]);
358 373
			}
359 374
		}
360
		***/
375

  
361 376
	}
362 377

  
363 378
	/**
......
411 426
				configureMenu();*/
412 427
		    }
413 428
		}
414
		PluginServices.getMainFrame().enableControls();
429
		configureMenu();
430
		//PluginServices.getMainFrame().enableControls();
415 431
	}
416 432
	/**
417 433
	 * DOCUMENT ME!
......
429 445
		    ct.transition(value);
430 446
			askQuestion();
431 447
		    }
432

  
448
		configureMenu();
433 449
		PluginServices.getMainFrame().enableControls();
434 450
	}
435 451
	private void transition(VectorialEditableAdapter source,
......
440 456
			    ct.transition(option);
441 457
				askQuestion();
442 458
			    }
443
			PluginServices.getMainFrame().enableControls();
459
			configureMenu();
460
			//PluginServices.getMainFrame().enableControls();
444 461
	}
445 462
	/**
446 463
	 * DOCUMENT ME!
......
511 528
		cadToolStack.push(cadTool);
512 529
		cadTool.setCadToolAdapter(this);
513 530
		//cadTool.initializeStatus();
514
		cadTool.setVectorialAdapter(vea);
531
		//cadTool.setVectorialAdapter(vea);
515 532
		/*int ret = cadTool.transition(null, editableFeatureSource, selection,
516 533
				new double[0]);
517 534

  
......
657 674
				pushCadTool(new SelectionCADTool());
658 675
				getVectorialAdapter().getSelection().clear();
659 676
				getMapControl().drawMap(false);
660
				/***PluginServices.getMainFrame().setSelectedTool("selection");***/
677
				PluginServices.getMainFrame().setSelectedTool("SELCAD");
661 678
				askQuestion();
662 679
			}
663 680
		}

Also available in: Unified diff