[udig-devel] ellipsetool patch
Jesse Eichar
jeichar at refractions.net
Mon Jan 7 08:42:12 PST 2008
Awesome thanks. I will try this out... I think I'll have time
tomorrow. :). But I'm making a bug report for this as I write this.
http://jira.codehaus.org/browse/UDIG-1347
Jesse
On 7-Jan-08, at 2:29 AM, Piebe de Vries wrote:
> Hi,
>
> I thought that somebody might be interested in the attached patch
> (for RC12). It changes the ellipseTool such that the first click is
> the centre of the ellipse (instead of a non existing corner).
> Resulting in a, for many users, more intuitive interface.
>
> Furthermore when the shift key is pushed then a circle is drawn
> instead of an ellipse (or a square instead of a rectangle). Warning:
> with this last part of the code is platform specific (Windows) and
> the shift key is only detected at the start of drawing the geometry.
> If anybody has a suggestion to improve this...
>
> greetings,
> Piebe
>
> --
> --------------------------- ----------------------------
> Piebe de Vries piebe.de.vries at geodan.nl
> Geodan IT b.v. Tel: +31 (0)73 - 6925 151
> President Kennedylaan 1 Fax: +31 (0)73 - 5711 333
> 1079 MB Amsterdam (NL) http://www.geodan.nl
> --------------------------- ----------------------------
>
>
> Index: src/net/refractions/udig/tools/edit/behaviour/
> ShapeCreationBehaviour.java
> ===================================================================
> --- src/net/refractions/udig/tools/edit/behaviour/
> ShapeCreationBehaviour.java (revision 27805)
> +++ src/net/refractions/udig/tools/edit/behaviour/
> ShapeCreationBehaviour.java (working copy)
> @@ -44,19 +44,19 @@
> import com.vividsolutions.jts.geom.MultiLineString;
>
> /**
> - * <p>Requirements:
> - * <ul>
> + * <p>Requirements:
> + * <ul>
> * <li>Mouse Dragged</li>
> * <li>CurrentState == NONE</li>
> * <li>Mouse button 1 down</li>
> - * </ul>
> - * </p>
> - * <p>Action:
> - * <ul>
> + * </ul>
> + * </p>
> + * <p>Action:
> + * <ul>
> * <li>draws a shape as the mouse is dragged</li>
> * <li>creates a feature on the current layer when mouse is
> released</li>
> - * </ul>
> - * </p>
> + * </ul>
> + * </p>
> * @author jones
> * @since 1.1.0
> */
> @@ -69,7 +69,8 @@
> * @since 1.1.0
> */
> public static abstract class ShapeFactory {
> - /**
> + protected boolean middleAsOrigin = false;
> + /**
> * Creates a GeneralPath with the top left corner at 0,0 and
> * a total width and height as indicated
> *
> @@ -79,11 +80,18 @@
> * a total width and height as indicated
> */
> public abstract GeneralPath create(int width, int height);
> + public boolean useMiddleAsOrigin() {
> + return middleAsOrigin;
> + }
> + public void setMiddleAsOrigin(boolean middleAsOrigin) {
> + this.middleAsOrigin = middleAsOrigin;
> + }
> }
>
> private ShapeFactory factory;
> private GeneralPath path;
> private DrawShapeCommand drawCommand;
> +
>
> /**
> * @param factory
> @@ -101,7 +109,7 @@
>
> return !e.modifiersDown() && legalState &&
> e.buttons==MapMouseEvent.BUTTON1 && eventType==EventType.DRAGGED;
> }
> -
> +
> public UndoableMapCommand getCommand( EditToolHandler handler,
> MapMouseEvent e,
> EventType eventType ) {
> if( path==null ){
> @@ -110,11 +118,34 @@
> handler.lock(this);
> }
> MouseTracker tracker=handler.getMouseTracker();
> - int translationX=Math.min(tracker.getDragStarted().getX(),
> e.x);
> - int translationY=Math.min(tracker.getDragStarted().getY(),
> e.y);
> + int translationX;
> + int translationY;
> + if (factory.useMiddleAsOrigin())
> + {
> + translationX=tracker.getDragStarted().getX();
> + translationY=tracker.getDragStarted().getY();
> + }
> + else
> + {
> + translationX=Math.min(tracker.getDragStarted().getX(), e.x);
> + translationY=Math.min(tracker.getDragStarted().getY(),
> e.y);
> + }
> int scaleX=Math.abs(tracker.getDragStarted().getX()-e.x);
> int scaleY=Math.abs(tracker.getDragStarted().getY()-e.y);
>
> + //force square/circle if shift is activated
> + if
> (org
> .eclipse
> .swt
> .internal
> .win32.OS.GetKeyState(org.eclipse.swt.internal.win32.OS.VK_SHIFT) !=
> 0) //TODO: This is windows specific, how to do this cross-platform?
> + {
> + if (scaleX > scaleY)
> + {
> + scaleY = scaleX;
> + }
> + else
> + {
> + scaleX = scaleY;
> + }
> + }
> +
> AffineTransform
> transform=AffineTransform.getTranslateInstance(translationX,
> translationY);
> transform.scale(scaleX, scaleY);
> Shape transformedShape =
> path.createTransformedShape(transform);
> Index: src/net/refractions/udig/tools/edit/impl/EllipseTool.java
> ===================================================================
> --- src/net/refractions/udig/tools/edit/impl/EllipseTool.java
> (revision 27805)
> +++ src/net/refractions/udig/tools/edit/impl/EllipseTool.java
> (working copy)
> @@ -29,15 +29,15 @@
> public class EllipseTool extends RectangleTool {
> @Override
> protected ShapeFactory getShapeFactory() {
> - return new ShapeCreationBehaviour.ShapeFactory(){
> -
> + ShapeFactory ret = new ShapeCreationBehaviour.ShapeFactory() {
> @Override
> public GeneralPath create(int width, int height) {
> GeneralPath path=new GeneralPath();
> - path.append(new Ellipse2D.Float(0,0,width, height),
> false);
> + path.append(new Ellipse2D.Float(-width, -height,
> 2*width, 2*height), false);
> return path;
> }
> -
> };
> + ret.setMiddleAsOrigin(true);
> + return ret;
> }
> }
> _______________________________________________
> User-friendly Desktop Internet GIS (uDig)
> http://udig.refractions.net
> http://lists.refractions.net/mailman/listinfo/udig-devel
More information about the udig-devel
mailing list