Revision: 5532
          http://sourceforge.net/p/jump-pilot/code/5532
Author:   ma15569
Date:     2017-10-25 11:12:38 +0000 (Wed, 25 Oct 2017)
Log Message:
-----------
Add measurement display to EllipseByDragging tool

Modified Paths:
--------------
    
plug-ins/CADExtension/trunk/src/org/openjump/advancedtools/tools/EllipseByDraggingTool.java

Modified: 
plug-ins/CADExtension/trunk/src/org/openjump/advancedtools/tools/EllipseByDraggingTool.java
===================================================================
--- 
plug-ins/CADExtension/trunk/src/org/openjump/advancedtools/tools/EllipseByDraggingTool.java
 2017-10-25 10:43:55 UTC (rev 5531)
+++ 
plug-ins/CADExtension/trunk/src/org/openjump/advancedtools/tools/EllipseByDraggingTool.java
 2017-10-25 11:12:38 UTC (rev 5532)
@@ -1,10 +1,13 @@
 package org.openjump.advancedtools.tools;
 
 import java.awt.Shape;
+import java.awt.event.MouseEvent;
 import java.awt.geom.Ellipse2D;
 import java.awt.geom.GeneralPath;
 import java.awt.geom.NoninvertibleTransformException;
 import java.awt.geom.Point2D;
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.swing.Icon;
 
@@ -11,15 +14,19 @@
 import org.openjump.advancedtools.config.CADToolsOptionsPanel;
 import org.openjump.advancedtools.icon.IconLoader;
 import org.openjump.advancedtools.language.I18NPlug;
+import org.openjump.advancedtools.utils.CoordinateListMetricsUtils;
 
 import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.geom.CoordinateList;
 import com.vividsolutions.jts.geom.Envelope;
 import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.geom.GeometryFactory;
+import com.vividsolutions.jts.geom.LineString;
 import com.vividsolutions.jts.util.GeometricShapeFactory;
 import com.vividsolutions.jump.I18N;
 import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
 import com.vividsolutions.jump.workbench.ui.LayerNamePanelProxy;
+import com.vividsolutions.jump.workbench.ui.LayerViewPanel;
 import com.vividsolutions.jump.workbench.ui.cursortool.CursorTool;
 import com.vividsolutions.jump.workbench.ui.cursortool.DragTool;
 import 
com.vividsolutions.jump.workbench.ui.cursortool.editing.FeatureDrawingUtil;
@@ -35,6 +42,11 @@
     public final static String NAME = I18NPlug
             .getI18N("org.openjump.core.ui.plugins.Ellipse");
 
+    public static final String Area = I18N
+            .get("ui.cursortool.CoordinateListMetrics.Area");
+    public static final String Diameter = I18N
+            .get("ui.cursortool.CoordinateListMetrics.Diameter");
+
     protected Coordinate tentativeCoordinate;
 
     public EllipseByDraggingTool(int n) {
@@ -55,7 +67,74 @@
                 featureDrawingUtil), true);
     }
 
+    private void display(List coordinates, LayerViewPanel panel)
+            throws NoninvertibleTransformException {
+
+        Envelope e = getBoxInModelCoordinates();
+
+        Coordinate[] coordHeight = new Coordinate[] {
+                new Coordinate(e.getMinX(), e.getMinY()),
+                new Coordinate(e.getMinX(), e.getMaxY()) };
+        Coordinate[] coordWidth = new Coordinate[] {
+                new Coordinate(e.getMinX(), e.getMinY()),
+                new Coordinate(e.getMaxX(), e.getMinY()) };
+
+        LineString lineVertical = new GeometryFactory()
+                .createLineString(coordHeight);
+
+        LineString lineHorizontal = new GeometryFactory()
+                .createLineString(coordWidth);
+
+        double lengthVertical = lineVertical.getLength();
+        double lengthHorizontal = lineHorizontal.getLength();
+        double mean = (lengthVertical + lengthHorizontal) / 2;
+        double circumference = 2 * Math.PI * (mean);
+        double area = Math.PI * Math.pow(mean, 2);
+
+        CoordinateListMetricsUtils.setEllipseMessage(lengthHorizontal,
+                lengthVertical, circumference, area);
+    }
+
+    public void mouseLocationChanged(MouseEvent e) {
+        try {
+            if (isShapeOnScreen()) {
+                ArrayList currentCoordinates = new ArrayList(
+                        getEllipseCoordinates());
+                currentCoordinates.add(getPanel().getViewport()
+                        .toModelCoordinate(e.getPoint()));
+                display(getEllipseCoordinates(), getPanel());
+                // getPanel().getContext().setStatusMessage("");
+            }
+            snap(e.getPoint());
+            // super.mousePressed(e);
+            super.mouseDragged(e);
+
+        } catch (Throwable t) {
+            getPanel().getContext().handleThrowable(t);
+        }
+    }
+
     @Override
+    public void mouseDragged(MouseEvent e) {
+        try {
+            if (isShapeOnScreen()) {
+                ArrayList currentCoordinates = new ArrayList(
+                        getEllipseCoordinates());
+                currentCoordinates.add(getPanel().getViewport()
+                        .toModelCoordinate(e.getPoint()));
+                display(currentCoordinates, getPanel());
+                // getPanel().getContext().setStatusMessage("");
+            }
+            snap(e.getPoint());
+            // super.mousePressed(e);
+            super.mouseDragged(e);
+
+        } catch (Throwable t) {
+            getPanel().getContext().handleThrowable(t);
+        }
+    }
+
+    @Override
     public String getName() {
 
         String tooltip = "";
@@ -155,4 +234,29 @@
         shape.lineTo((maxX + minX) / 2.0D, maxY);
         return shape;
     }
+
+    @SuppressWarnings("unchecked")
+    public CoordinateList getEllipseCoordinates()
+            throws NoninvertibleTransformException {
+
+        Envelope env = new Envelope(getModelSource().x,
+                getModelDestination().x, getModelSource().y,
+                getModelDestination().y);
+        GeometricShapeFactory gsf = new GeometricShapeFactory();
+        gsf.setNumPoints(100);
+        gsf.setEnvelope(env);
+
+        Geometry geom = gsf.createCircle();
+        Coordinate[] coords = geom.getCoordinates();
+        GeometryFactory factory = new GeometryFactory();
+
+        LineString line = factory.createLineString(coords);
+
+        CoordinateList coordinates = new CoordinateList();
+
+        coordinates.add(line.getCoordinates());
+
+        return coordinates;
+    }
+
 }


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to