Revision 53
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.circlecr/src/main/java/org/gvsig/vectorediting/lib/prov/circlecr/CircleCREditingProvider.java | ||
---|---|---|
43 | 43 |
"Center", "Center position of circle", TYPE.POSITION); |
44 | 44 |
|
45 | 45 |
private EditingServiceParameter radius = new DefaultEditingServiceParameter( |
46 |
"Radius", "Radius of circle", TYPE.VALUE); |
|
46 |
"Radius", "Radius of circle", TYPE.POSITION, TYPE.VALUE);
|
|
47 | 47 |
|
48 | 48 |
private Map<EditingServiceParameter, Object> values; |
49 | 49 |
|
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.api/src/main/java/org/gvsig/vectorediting/lib/api/EditingServiceParameter.java | ||
---|---|---|
6 | 6 |
*/ |
7 | 7 |
package org.gvsig.vectorediting.lib.api; |
8 | 8 |
|
9 |
import java.util.List; |
|
10 |
|
|
9 | 11 |
public interface EditingServiceParameter { |
10 | 12 |
|
11 | 13 |
public enum TYPE { |
... | ... | |
16 | 18 |
/** |
17 | 19 |
* @return |
18 | 20 |
*/ |
19 |
public TYPE getType();
|
|
21 |
public List<TYPE> getTypes();
|
|
20 | 22 |
|
21 | 23 |
/** |
22 | 24 |
* @return |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.spi/src/main/java/org/gvsig/vectorediting/lib/spi/DefaultEditingServiceParameter.java | ||
---|---|---|
6 | 6 |
*/ |
7 | 7 |
package org.gvsig.vectorediting.lib.spi; |
8 | 8 |
|
9 |
import java.util.Arrays; |
|
10 |
import java.util.List; |
|
11 |
|
|
9 | 12 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
10 | 13 |
|
11 | 14 |
public class DefaultEditingServiceParameter implements EditingServiceParameter { |
... | ... | |
14 | 17 |
|
15 | 18 |
private String description; |
16 | 19 |
|
17 |
private TYPE type;
|
|
20 |
private List<TYPE> types;
|
|
18 | 21 |
|
19 |
public DefaultEditingServiceParameter(String name, String description, TYPE type) {
|
|
22 |
public DefaultEditingServiceParameter(String name, String description, TYPE... types) {
|
|
20 | 23 |
this.name = name; |
21 | 24 |
this.description = description; |
22 |
this.type = type;
|
|
25 |
this.types = Arrays.asList(types);
|
|
23 | 26 |
} |
24 | 27 |
|
25 |
public TYPE getType() {
|
|
26 |
return type; |
|
28 |
public List<TYPE> getTypes() {
|
|
29 |
return types;
|
|
27 | 30 |
} |
28 | 31 |
|
29 | 32 |
public String getName() { |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/DefaultEditingBehavior.java | ||
---|---|---|
13 | 13 |
import java.awt.event.MouseEvent; |
14 | 14 |
import java.awt.geom.Point2D; |
15 | 15 |
import java.awt.image.BufferedImage; |
16 |
import java.util.ArrayList; |
|
16 | 17 |
import java.util.HashMap; |
17 | 18 |
import java.util.Iterator; |
19 |
import java.util.List; |
|
18 | 20 |
import java.util.Map; |
19 | 21 |
|
20 | 22 |
import org.cresques.cts.IProjection; |
21 | 23 |
import org.gvsig.andami.PluginServices; |
22 | 24 |
import org.gvsig.andami.ui.mdiFrame.MainFrame; |
23 | 25 |
import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener; |
26 |
import org.gvsig.fmap.dal.exception.DataException; |
|
24 | 27 |
import org.gvsig.fmap.geom.Geometry; |
25 | 28 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
26 | 29 |
import org.gvsig.fmap.geom.primitive.Point; |
... | ... | |
41 | 44 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
42 | 45 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
43 | 46 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener; |
47 |
import org.gvsig.tools.exception.BaseException; |
|
44 | 48 |
import org.gvsig.utils.console.JConsole; |
45 | 49 |
import org.gvsig.utils.console.JDockPanel; |
46 | 50 |
import org.gvsig.utils.console.ResponseListener; |
... | ... | |
50 | 54 |
import org.gvsig.vectorediting.lib.api.EditingService; |
51 | 55 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
52 | 56 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE; |
57 |
import org.gvsig.vectorediting.lib.prov.circlecr.CircleCREditingProvider; |
|
53 | 58 |
import org.gvsig.vectorediting.swing.api.EditingBehavior; |
59 |
import org.slf4j.Logger; |
|
60 |
import org.slf4j.LoggerFactory; |
|
54 | 61 |
|
62 |
import com.vividsolutions.jts.geomgraph.Position; |
|
63 |
|
|
55 | 64 |
public class DefaultEditingBehavior extends Behavior implements EditingBehavior { |
56 | 65 |
|
66 |
private static final Logger logger = LoggerFactory.getLogger(DefaultEditingBehavior.class); |
|
67 |
|
|
57 | 68 |
private Map<FLyrVect, EditingService> serviceRegistration; |
58 | 69 |
|
59 | 70 |
private MapControl mapControl; |
... | ... | |
159 | 170 |
public void acceptResponse(String response) { |
160 | 171 |
try { |
161 | 172 |
textEntered(response); |
162 |
} catch (RuntimeException ex) {
|
|
173 |
} catch (InvalidEntryException ex) {
|
|
163 | 174 |
getConsolePanel().addText(ex.getMessage(), JConsole.ERROR); |
164 | 175 |
getNextParameter(); |
165 | 176 |
} |
... | ... | |
279 | 290 |
} |
280 | 291 |
|
281 | 292 |
public void mouseClicked(MouseEvent e) throws BehaviorException { |
282 |
// TODO Auto-generated method stub |
|
283 | 293 |
ViewPort vp = mapControl.getViewPort(); |
284 | 294 |
if (activeService != null) { |
285 | 295 |
if (currentParam != null) { |
286 |
switch (currentParam.getType()) { |
|
287 |
case POSITION:
|
|
288 |
case VALUE:
|
|
296 |
|
|
297 |
List<TYPE> typesOfParam = currentParam.getTypes();
|
|
298 |
if (typesOfParam.contains(TYPE.POSITION)) {
|
|
289 | 299 |
Point point; |
290 | 300 |
point = vp.convertToMapPoint(e.getX(), e.getY()); |
291 | 301 |
this.activeService.value(point); |
292 |
|
|
293 |
case LIST_POSITIONS: |
|
294 |
case OPTION: |
|
295 |
case SELECTION: |
|
296 |
case GEOMETRY: |
|
297 | 302 |
} |
298 |
getNextParameter(); |
|
303 |
// TODO: Comprobar el resto de casos: |
|
304 |
// TYPE.VALUE, |
|
305 |
// TYPE.LIST_POSITIONS, |
|
306 |
// TYPE.OPTION, TYPE.SELECTION, |
|
307 |
// TYPE.GEOMETRY: |
|
299 | 308 |
} |
300 |
|
|
309 |
getNextParameter(); |
|
301 | 310 |
} |
302 | 311 |
} |
303 | 312 |
|
... | ... | |
385 | 394 |
|
386 | 395 |
} |
387 | 396 |
|
388 |
private void textEntered(String response) { |
|
397 |
private void textEntered(String response) throws InvalidEntryException {
|
|
389 | 398 |
if (response == null) { |
390 | 399 |
cleanBehavior(); |
391 | 400 |
} else { |
392 |
TYPE type = currentParam.getType(); |
|
393 |
try { |
|
401 |
List<TYPE> types = currentParam.getTypes(); |
|
394 | 402 |
Point point = null; |
395 | 403 |
Double value = null; |
396 |
switch (type) { |
|
397 |
case POSITION: |
|
398 |
point = parsePoint(response); |
|
399 |
if (point != null){ |
|
400 |
this.activeService.value(point); |
|
401 |
} |
|
402 |
break; |
|
403 |
case VALUE: |
|
404 |
boolean insertedValue = false; |
|
405 |
if (!insertedValue && types.contains(TYPE.POSITION)) { |
|
404 | 406 |
try { |
405 | 407 |
point = parsePoint(response); |
406 |
} catch (Exception e) { |
|
407 |
// Do nothing |
|
408 |
} catch (BaseException e) { |
|
409 |
logger.info("Can't parse string as a point", e); |
|
410 |
point = null; |
|
408 | 411 |
} |
409 |
if (point != null){ |
|
412 |
if (point != null) {
|
|
410 | 413 |
this.activeService.value(point); |
411 |
break;
|
|
414 |
insertedValue = true;
|
|
412 | 415 |
} |
413 |
value = Double.valueOf(response); |
|
414 |
this.activeService.value(value); |
|
415 |
break; |
|
416 |
case LIST_POSITIONS: |
|
417 |
case OPTION: |
|
418 |
case SELECTION: |
|
419 |
case GEOMETRY: |
|
420 | 416 |
} |
417 |
if (!insertedValue && types.contains(TYPE.VALUE)) { |
|
418 |
try { |
|
419 |
value = Double.valueOf(response); |
|
420 |
} catch (NumberFormatException e) { |
|
421 |
logger.info(e.getMessage(), e); |
|
422 |
value = null; |
|
423 |
} |
|
424 |
if(value != null){ |
|
425 |
this.activeService.value(value); |
|
426 |
insertedValue = true; |
|
427 |
} |
|
428 |
} |
|
429 |
// TODO: contemplar el resto de casos |
|
430 |
// TYPE.LIST_POSITIONS, |
|
431 |
// TYPE.OPTION, |
|
432 |
// TYPE.SELECTION, |
|
433 |
// TYPE.GEOMETRY |
|
434 |
|
|
435 |
if(!insertedValue){ |
|
436 |
throw new InvalidEntryException("Invalid entry: " + response, null); |
|
437 |
} |
|
421 | 438 |
getNextParameter(); |
422 |
} catch (Exception e) { |
|
423 |
throw new RuntimeException("Datos inv?lidos: " + response); |
|
424 |
} |
|
425 | 439 |
} |
426 | 440 |
} |
427 | 441 |
|
428 |
private Point parsePoint(String response){ |
|
442 |
private Point parsePoint(String response) throws CreateGeometryException, |
|
443 |
ParsePointException, DataException { |
|
429 | 444 |
String[] numbers = new String[1]; |
430 | 445 |
numbers[0] = response; |
431 | 446 |
numbers = response.split(","); |
... | ... | |
438 | 453 |
Double.parseDouble(numbers[1]) }; |
439 | 454 |
|
440 | 455 |
Point point; |
441 |
try { |
|
442 |
point = geomManager.createPoint(values[0], values[1], |
|
443 |
Geometry.SUBTYPES.GEOM2D); |
|
444 |
// TODO: Maybe do util class to get type and subtype of a featureStore |
|
445 |
return point; |
|
446 |
} catch (CreateGeometryException e) { |
|
447 |
new RuntimeException("Can't create a point" + response); |
|
448 |
} |
|
456 |
point = geomManager.createPoint( |
|
457 |
values[0], |
|
458 |
values[1], |
|
459 |
currentLayer.getFeatureStore().getDefaultFeatureType().getDefaultGeometryAttribute().getGeomType().getSubType()); |
|
460 |
// TODO: Maybe do util class to get type and subtype of a featureStore or a method in manager |
|
461 |
return point; |
|
449 | 462 |
} else { |
450 |
throw new RuntimeException("Can't parse a point" + response);
|
|
463 |
throw new ParsePointException("Can't create a point", null);
|
|
451 | 464 |
} |
452 |
return null; |
|
453 | 465 |
} |
454 | 466 |
|
455 | 467 |
private JDockPanel getDockConsole() { |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/ParsePointException.java | ||
---|---|---|
1 |
package org.gvsig.vectorediting.swing.impl; |
|
2 |
|
|
3 |
import org.gvsig.tools.exception.BaseException; |
|
4 |
|
|
5 |
public class ParsePointException extends BaseException { |
|
6 |
|
|
7 |
/** |
|
8 |
* |
|
9 |
*/ |
|
10 |
private static final long serialVersionUID = -5644073447564880045L; |
|
11 |
|
|
12 |
private static final String MESSAGE = |
|
13 |
"Can't parse a point."; |
|
14 |
|
|
15 |
private static final String KEY = "_ParsePointException"; |
|
16 |
|
|
17 |
private String description; |
|
18 |
|
|
19 |
public ParsePointException(String description, Throwable ex) { |
|
20 |
super(MESSAGE, ex, KEY, serialVersionUID); |
|
21 |
this.description= description; |
|
22 |
} |
|
23 |
|
|
24 |
public String getDescription() { |
|
25 |
return description; |
|
26 |
} |
|
27 |
} |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/InvalidEntryException.java | ||
---|---|---|
1 |
package org.gvsig.vectorediting.swing.impl; |
|
2 |
|
|
3 |
import org.gvsig.tools.exception.BaseException; |
|
4 |
|
|
5 |
public class InvalidEntryException extends BaseException { |
|
6 |
|
|
7 |
/** |
|
8 |
* |
|
9 |
*/ |
|
10 |
private static final long serialVersionUID = 1490897907277930987L; |
|
11 |
|
|
12 |
private static final String MESSAGE = |
|
13 |
"Invalid entry."; |
|
14 |
|
|
15 |
private static final String KEY = "_InvalidEntryException"; |
|
16 |
|
|
17 |
private String description; |
|
18 |
|
|
19 |
public InvalidEntryException(String description, Throwable ex) { |
|
20 |
super(MESSAGE, ex, KEY, serialVersionUID); |
|
21 |
this.description= description; |
|
22 |
} |
|
23 |
|
|
24 |
public String getDescription() { |
|
25 |
return description; |
|
26 |
} |
|
27 |
} |
Also available in: Unified diff