01: /* uDig - User Friendly Desktop Internet GIS client
02: * http://udig.refractions.net
03: * (C) 2004, Refractions Research Inc.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation;
08: * version 2.1 of the License.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: */
15: package net.refractions.udig.tools.edit.validator;
16:
17: import net.refractions.udig.project.ui.render.displayAdapter.MapMouseEvent;
18: import net.refractions.udig.tool.edit.internal.Messages;
19: import net.refractions.udig.tools.edit.EditToolHandler;
20: import net.refractions.udig.tools.edit.EventType;
21: import net.refractions.udig.tools.edit.behaviour.IEditValidator;
22: import net.refractions.udig.tools.edit.support.EditUtils;
23: import net.refractions.udig.tools.edit.support.Point;
24: import net.refractions.udig.tools.edit.support.PrimitiveShape;
25:
26: /**
27: * Disallows:
28: * <ul>
29: * <li>Self intersections</li>
30: * </ul>
31: * @author Jesse
32: * @since 1.1.0
33: */
34: public class PolygonCreationValidator implements IEditValidator {
35:
36: public String isValid(EditToolHandler handler, MapMouseEvent event,
37: EventType type) {
38:
39: PrimitiveShape shell = handler.getCurrentShape();
40:
41: assert shell == shell.getEditGeom().getShell();
42:
43: Point newPoint = Point.valueOf(event.x, event.y);
44: int lastPointIndex = shell.getNumPoints() - 1;
45: if (shell.getNumPoints() > 2
46: && EditUtils.instance.intersection(shell
47: .getPoint(lastPointIndex), newPoint, shell, 0,
48: lastPointIndex)) {
49: return Messages.ValidHoleValidator_selfIntersection;
50: }
51: return null;
52: }
53:
54: }
|