Revision 1386
branches/pilotoDWG/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/cad/CADToolAdapter.java | ||
---|---|---|
1 |
/* Generated by Together */ |
|
2 | 1 |
package com.iver.cit.gvsig.fmap.edition.cad; |
3 | 2 |
|
4 | 3 |
import com.iver.cit.gvsig.fmap.ViewPort; |
5 | 4 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
6 | 5 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
7 | 6 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
8 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbolFactory; |
|
9 | 7 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
10 | 8 |
import com.iver.cit.gvsig.fmap.edition.EditableFeatureSource; |
11 | 9 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
12 |
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D; |
|
13 | 10 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
14 | 11 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
15 | 12 |
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener; |
13 |
|
|
16 | 14 |
import com.iver.utiles.console.InvalidResponseException; |
17 | 15 |
import com.iver.utiles.console.JConsole; |
18 | 16 |
import com.iver.utiles.console.ResponseListener; |
... | ... | |
25 | 23 |
import java.awt.event.MouseEvent; |
26 | 24 |
import java.awt.event.MouseWheelEvent; |
27 | 25 |
import java.awt.geom.Point2D; |
26 |
|
|
28 | 27 |
import java.io.IOException; |
29 | 28 |
|
30 | 29 |
|
... | ... | |
37 | 36 |
private CadTool cadTool; |
38 | 37 |
private FBitSet selection = new FBitSet(); |
39 | 38 |
private EditableFeatureSource editableFeatureSource; |
39 |
|
|
40 | 40 |
//Para pasarle las coordenadas cuando se produce un evento textEntered |
41 | 41 |
private int lastX; |
42 | 42 |
private int lastY; |
43 |
|
|
44 | 43 |
private FSymbol symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, Color.RED); |
45 | 44 |
private JConsole console; |
46 |
|
|
45 |
|
|
47 | 46 |
/** |
48 | 47 |
* Pinta de alguna manera especial las geometrias seleccionadas para la |
49 | 48 |
* edici?n. En caso de que el snapping est? activado, pintar? el efecto |
... | ... | |
53 | 52 |
*/ |
54 | 53 |
public void paintComponent(Graphics g) { |
55 | 54 |
super.paintComponent(g); |
56 |
for(int i=selection.nextSetBit(0); i>=0; i=selection.nextSetBit(i+1)) { |
|
55 |
|
|
56 |
for (int i = selection.nextSetBit(0); i >= 0; |
|
57 |
i = selection.nextSetBit(i + 1)) { |
|
57 | 58 |
try { |
58 | 59 |
IGeometry geom = editableFeatureSource.getGeometry(i); |
59 |
geom.draw((Graphics2D)g, getMapControl().getViewPort(), symbol); |
|
60 |
geom.draw((Graphics2D) g, getMapControl().getViewPort(), symbol);
|
|
60 | 61 |
} catch (IOException e) { |
61 | 62 |
e.printStackTrace(); |
62 | 63 |
} catch (DriverIOException e) { |
63 | 64 |
e.printStackTrace(); |
64 | 65 |
} |
65 |
|
|
66 | 66 |
} |
67 |
|
|
67 | 68 |
//cadTool.drawOperation(g,editableFeatureSource,selection,lastX,lastY); |
68 | 69 |
} |
69 | 70 |
|
70 |
public Point getLastMousePosition(){ |
|
71 |
/** |
|
72 |
* DOCUMENT ME! |
|
73 |
* |
|
74 |
* @return DOCUMENT ME! |
|
75 |
*/ |
|
76 |
public Point getLastMousePosition() { |
|
71 | 77 |
return new Point(lastX, lastY); |
72 | 78 |
} |
73 |
|
|
79 |
|
|
74 | 80 |
/** |
75 | 81 |
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) |
76 | 82 |
*/ |
... | ... | |
96 | 102 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
97 | 103 |
Point2D p2 = vp.toMapPoint(e.getPoint()); |
98 | 104 |
|
99 |
transition("punto", editableFeatureSource, selection, new double[]{p2.getX(), p2.getY()}); |
|
105 |
transition("punto", editableFeatureSource, selection, |
|
106 |
new double[] { p2.getX(), p2.getY() }); |
|
100 | 107 |
} |
101 | 108 |
|
102 | 109 |
/** |
... | ... | |
135 | 142 |
public void textEntered(String text) { |
136 | 143 |
String[] numbers = text.split(","); |
137 | 144 |
double[] values = null; |
138 |
try{ |
|
139 |
if (numbers.length == 2){ |
|
145 |
|
|
146 |
try { |
|
147 |
if (numbers.length == 2) { |
|
140 | 148 |
//punto |
141 |
values = new double[]{Double.parseDouble(numbers[0]), Double.parseDouble(numbers[1])}; |
|
149 |
values = new double[] { |
|
150 |
Double.parseDouble(numbers[0]), |
|
151 |
Double.parseDouble(numbers[1]) |
|
152 |
}; |
|
142 | 153 |
transition("punto", editableFeatureSource, selection, values); |
143 |
}else if (numbers.length == 1){
|
|
154 |
} else if (numbers.length == 1) {
|
|
144 | 155 |
//valor |
145 |
values = new double[]{Double.parseDouble(numbers[0])};
|
|
156 |
values = new double[] { Double.parseDouble(numbers[0]) };
|
|
146 | 157 |
transition("numero", editableFeatureSource, selection, values); |
147 | 158 |
} |
148 |
}catch (NumberFormatException e) { |
|
159 |
} catch (NumberFormatException e) {
|
|
149 | 160 |
transition(text, editableFeatureSource, selection, new double[0]); |
150 | 161 |
} |
151 | 162 |
} |
152 |
|
|
153 |
private void transition(String text, EditableFeatureSource source, FBitSet sel, double[] values){ |
|
163 |
|
|
164 |
/** |
|
165 |
* DOCUMENT ME! |
|
166 |
* |
|
167 |
* @param text DOCUMENT ME! |
|
168 |
* @param source DOCUMENT ME! |
|
169 |
* @param sel DOCUMENT ME! |
|
170 |
* @param values DOCUMENT ME! |
|
171 |
*/ |
|
172 |
private void transition(String text, EditableFeatureSource source, |
|
173 |
FBitSet sel, double[] values) { |
|
154 | 174 |
cadTool.transition(text, source, sel, values); |
155 | 175 |
|
156 |
console.askQuestion(cadTool.getQuestion(), new ResponseListener() { |
|
157 |
public void acceptResponse(String response) |
|
176 |
console.askQuestion(cadTool.getQuestion(), |
|
177 |
new ResponseListener() { |
|
178 |
public void acceptResponse(String response) |
|
158 | 179 |
throws InvalidResponseException { |
159 |
//Si no se ha cancelado |
|
160 |
if (response != null) |
|
161 |
textEntered(response); |
|
162 |
} |
|
163 |
}); |
|
164 |
|
|
180 |
//Si no se ha cancelado |
|
181 |
if (response != null) { |
|
182 |
textEntered(response); |
|
183 |
} |
|
184 |
} |
|
185 |
}); |
|
186 |
|
|
165 | 187 |
getMapControl().drawMap(false); |
166 | 188 |
} |
167 | 189 |
|
... | ... | |
187 | 209 |
*/ |
188 | 210 |
public ToolListener getListener() { |
189 | 211 |
return new ToolListener() { |
190 |
/** |
|
191 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor() |
|
192 |
*/ |
|
193 |
public Cursor getCursor() { |
|
194 |
return null; |
|
195 |
} |
|
212 |
/**
|
|
213 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
|
|
214 |
*/
|
|
215 |
public Cursor getCursor() {
|
|
216 |
return null;
|
|
217 |
}
|
|
196 | 218 |
|
197 |
/** |
|
198 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing() |
|
199 |
*/ |
|
200 |
public boolean cancelDrawing() { |
|
201 |
return false; |
|
202 |
} |
|
203 |
}; |
|
219 |
/**
|
|
220 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
|
221 |
*/
|
|
222 |
public boolean cancelDrawing() {
|
|
223 |
return false;
|
|
224 |
}
|
|
225 |
};
|
|
204 | 226 |
} |
227 |
|
|
228 |
/** |
|
229 |
* DOCUMENT ME! |
|
230 |
* |
|
231 |
* @return DOCUMENT ME! |
|
232 |
*/ |
|
205 | 233 |
public CadTool getCadTool() { |
206 | 234 |
return cadTool; |
207 | 235 |
} |
236 |
|
|
237 |
/** |
|
238 |
* DOCUMENT ME! |
|
239 |
* |
|
240 |
* @param cadTool DOCUMENT ME! |
|
241 |
*/ |
|
208 | 242 |
public void setCadTool(CadTool cadTool) { |
209 | 243 |
console.cancelQuestion(); |
210 | 244 |
this.cadTool = cadTool; |
211 | 245 |
cadTool.transition(null, editableFeatureSource, selection, new double[0]); |
212 |
console.askQuestion(cadTool.getQuestion(), new ResponseListener() { |
|
213 |
public void acceptResponse(String response) |
|
246 |
console.askQuestion(cadTool.getQuestion(), |
|
247 |
new ResponseListener() { |
|
248 |
public void acceptResponse(String response) |
|
214 | 249 |
throws InvalidResponseException { |
215 |
if (response != null) |
|
216 |
textEntered(response); |
|
217 |
} |
|
218 |
}); |
|
250 |
if (response != null) { |
|
251 |
textEntered(response); |
|
252 |
} |
|
253 |
} |
|
254 |
}); |
|
219 | 255 |
} |
256 |
|
|
257 |
/** |
|
258 |
* DOCUMENT ME! |
|
259 |
* |
|
260 |
* @return DOCUMENT ME! |
|
261 |
*/ |
|
220 | 262 |
public EditableFeatureSource getEditableFeatureSource() { |
221 | 263 |
return editableFeatureSource; |
222 | 264 |
} |
265 |
|
|
266 |
/** |
|
267 |
* DOCUMENT ME! |
|
268 |
* |
|
269 |
* @param editableFeatureSource DOCUMENT ME! |
|
270 |
*/ |
|
223 | 271 |
public void setEditableFeatureSource( |
224 |
EditableFeatureSource editableFeatureSource) {
|
|
272 |
EditableFeatureSource editableFeatureSource) { |
|
225 | 273 |
this.editableFeatureSource = editableFeatureSource; |
226 | 274 |
} |
227 | 275 |
|
228 | 276 |
/** |
277 |
* DOCUMENT ME! |
|
278 |
* |
|
229 | 279 |
* @param console |
230 | 280 |
*/ |
231 | 281 |
public void setConsole(JConsole console) { |
Also available in: Unified diff