Revision 1822 branches/gvSIG_CAD_Layout_version/applications/appgvSIG/src/com/iver/cit/gvsig/gui/layout/LayoutCADToolAdapter.java

View differences:

LayoutCADToolAdapter.java
40 40
 */
41 41
package com.iver.cit.gvsig.gui.layout;
42 42

  
43
import com.iver.andami.PluginServices;
44

  
45
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
46
import com.iver.cit.gvsig.fmap.edition.EditableFeatureSource;
47
import com.iver.cit.gvsig.fmap.layers.FBitSet;
43 48
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
44 49
import com.iver.cit.gvsig.gui.cad.CADToolAdapter;
45 50
import com.iver.cit.gvsig.gui.cad.CadTool;
51
import com.iver.cit.gvsig.gui.cad.tools.SelectionCadTool;
52
import com.iver.cit.gvsig.gui.layout.fframes.IFFrame;
46 53

  
54
import com.iver.fsac.Automaton;
55

  
47 56
import java.awt.Color;
48 57
import java.awt.Graphics;
49 58
import java.awt.event.MouseEvent;
......
51 60
import java.awt.geom.Point2D;
52 61
import java.awt.geom.Rectangle2D;
53 62

  
63
import java.io.IOException;
54 64

  
65

  
55 66
/**
56 67
 * CADToolAdapter ajustado a las necesidades del Layout.
57 68
 *
......
91 102
	 * Repinta el Layout.
92 103
	 */
93 104
	public void refresh() {
94
	//	layout.refresh();
105
		//	layout.refresh();
95 106
	}
96 107

  
97 108
	/**
......
99 110
	 * edici?n. En caso de que el snapping est? activado, pintar? el efecto
100 111
	 * del mismo.
101 112
	 *
113
	 * @param g DOCUMENT ME!
102 114
	 */
103 115
	public void paintComponent(Graphics g) {
104
			getCadTool().setAT(getAT());
116
		getCadTool().setAT(getAT());
105 117

  
106
			Point2D.Double paux = new Point2D.Double(adjustedPoint.getX(),
107
					adjustedPoint.getY());
108
			paux = FLayoutUtilities.toSheetPoint(paux, getAT());
109
			getCadTool().drawOperation(g, null, null, paux.getX(), paux.getY());
118
		Point2D.Double paux = new Point2D.Double(adjustedPoint.getX(),
119
				adjustedPoint.getY());
120
		paux = FLayoutUtilities.toSheetPoint(paux, getAT());
121
		getCadTool().drawOperation(g, null, null, paux.getX(), paux.getY());
110 122
	}
111 123

  
112 124
	/**
......
177 189
		grid.setUseGrid(value);
178 190
		grid.setAT(getAT());
179 191
	}
192

  
180 193
	/**
181
	 * DOCUMENT ME!
194
	 * Configura las opciones de men?.
182 195
	 */
183 196
	public void configureMenu() {
184 197
		String[] desc = ((CadTool) cadToolStack.peek()).getAutomaton()
......
193 206
			}
194 207
		}
195 208
	}
196
	
209

  
210
	/**
211
	 * Realiza la transici?n que corresponde con el String que se pasa como
212
	 * par?metro.
213
	 *
214
	 * @param text Texto de la transici?n.
215
	 * @param source EditableFeatureSource.
216
	 * @param sel FBitset con la selecci?n.
217
	 * @param values Valores que se pasan a la transici?n.
218
	 */
219
	protected void transition(String text, EditableFeatureSource source,
220
		FBitSet sel, double[] values) {
221
		int ret = ((CadTool) cadToolStack.peek()).transition(text, source, sel,
222
				values);
223

  
224
		if ((ret & Automaton.AUTOMATON_FINISHED) == Automaton.AUTOMATON_FINISHED) {
225
			popCadTool();
226

  
227
			if (cadToolStack.isEmpty()) {
228
				pushCadTool(new SelectionCadTool());
229
				PluginServices.getMainFrame().selectTool("selection");
230
			}
231

  
232
			if (((CadTool) cadToolStack.peek()).getAutomaton().checkState('c')) {
233
				refresh();
234
			}
235

  
236
			//configureMenu();
237
			PluginServices.getMainFrame().enableControls();
238
		}
239
	}
240

  
241
	/**
242
	 * DOCUMENT ME!
243
	 *
244
	 * @param actionCommand
245
	 */
246
	public void keyPressed(String actionCommand) {
247
		if (actionCommand.equals("eliminar")) {
248
			delete();
249
		} else if (actionCommand.equals("escape")) {
250
			cadToolStack.clear();
251
			pushCadTool(new SelectionCadTool());
252
			selection.clear();
253
			getMapControl().drawMap(false);
254
			PluginServices.getMainFrame().selectTool("selection");
255

  
256
			//askQuestion();
257
		}
258

  
259
		PluginServices.getMainFrame().enableControls();
260
	}
261

  
262
	/**
263
	 * Elimina las geometr?as seleccionadas actualmente
264
	 */
265
	private void delete() {
266
		editableFeatureSource.startComplexGeometry();
267

  
268
		try {
269
			for (int i = selection.nextSetBit(0); i >= 0;
270
					i = selection.nextSetBit(i + 1)) {
271
				editableFeatureSource.removeGeometry(i);
272
			}
273
		} catch (DriverIOException e) {
274
			e.printStackTrace();
275
		} catch (IOException e) {
276
			e.printStackTrace();
277
		} finally {
278
			try {
279
				editableFeatureSource.endComplexGeometry();
280
			} catch (IOException e1) {
281
				e1.printStackTrace();
282
			} catch (DriverIOException e1) {
283
				e1.printStackTrace();
284
			}
285
		}
286

  
287
		selection.clear();
288
		refresh();
289
	}
290

  
291
	/**
292
	 * Devuelve si est? seleccionada la geometr?a que contiene el FFrame que se pasa como par?metro.
293
	 *
294
	 * @param frame FFrame de tipo FFrameGraphic.
295
	 *
296
	 * @return True si la geometr?a est? seleccionada.
297
	 */
298
	public boolean isSelected(IFFrame frame) {
299
		LayoutEditableFeature efs = (LayoutEditableFeature) getEditableFeatureSource();
300
		int index = layout.getAllFFrames().indexOf(frame);
301

  
302
		if (layout.isInvalidate(index)) {
303
			return false;
304
		}
305

  
306
		try {
307
			return selection.get(efs.getIndexGeom(index));
308
		} catch (NullPointerException e) {
309
			return false;
310
		}
311
	}
197 312
}

Also available in: Unified diff