[udig-devel] [jira] Created: (UDIG-1347) Ellipse tool to work from center.

Jesse Eichar (JIRA) jira at codehaus.org
Mon Jan 7 08:40:57 PST 2008


Ellipse tool to work from center.
---------------------------------

                 Key: UDIG-1347
                 URL: http://jira.codehaus.org/browse/UDIG-1347
             Project: uDIG
          Issue Type: Improvement
          Components: tool edit
    Affects Versions: UDIG 1.1 RC13
            Reporter: Jesse Eichar
            Assignee: Jesse Eichar
            Priority: Minor
             Fix For: UDIG 1.1 RC14



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;
    }
}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the udig-devel mailing list