Revision: 5711
          http://sourceforge.net/p/jump-pilot/code/5711
Author:   ma15569
Date:     2018-03-12 15:33:11 +0000 (Mon, 12 Mar 2018)
Log Message:
-----------
LayerStatistics opens into Additional Results frame

Modified Paths:
--------------
    
core/trunk/src/com/vividsolutions/jump/workbench/ui/plugin/LayerStatisticsPlugIn.java

Modified: 
core/trunk/src/com/vividsolutions/jump/workbench/ui/plugin/LayerStatisticsPlugIn.java
===================================================================
--- 
core/trunk/src/com/vividsolutions/jump/workbench/ui/plugin/LayerStatisticsPlugIn.java
       2018-03-12 15:22:08 UTC (rev 5710)
+++ 
core/trunk/src/com/vividsolutions/jump/workbench/ui/plugin/LayerStatisticsPlugIn.java
       2018-03-12 15:33:11 UTC (rev 5711)
@@ -1,4 +1,3 @@
-
 /*
  * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI 
  * for visualizing and manipulating spatial features with geometry and 
attributes.
@@ -35,6 +34,8 @@
 
 import java.util.Iterator;
 
+import org.openjump.sextante.gui.additionalResults.AdditionalResults;
+
 import com.vividsolutions.jts.geom.Coordinate;
 import com.vividsolutions.jts.geom.Envelope;
 import com.vividsolutions.jts.geom.Geometry;
@@ -48,10 +49,9 @@
 import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
 import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
 import com.vividsolutions.jump.workbench.plugin.PlugInContext;
-import com.vividsolutions.jump.workbench.ui.HTMLFrame;
+import com.vividsolutions.jump.workbench.ui.HTMLPanel;
 import com.vividsolutions.jump.workbench.ui.MenuNames;
 
-
 /**
  * Computes various statistics for selected layers.
  */
@@ -60,76 +60,91 @@
     public LayerStatisticsPlugIn() {
     }
 
-    public void initialize(PlugInContext context) throws Exception
-    {
-               FeatureInstaller featureInstaller = new 
FeatureInstaller(context.getWorkbenchContext());
-               featureInstaller.addMainMenuPlugin(
-               this,
-                               new String[] {MenuNames.TOOLS, 
MenuNames.STATISTICS},
-                this.getName() + "...",
-                false,                 //checkbox
-                null,                  //icon
+    @Override
+    public void initialize(PlugInContext context) throws Exception {
+        final FeatureInstaller featureInstaller = new FeatureInstaller(
+                context.getWorkbenchContext());
+        featureInstaller.addMainMenuPlugin(this, new String[] {
+                MenuNames.TOOLS, MenuNames.STATISTICS }, getName() + "...",
+                false, // checkbox
+                null, // icon
                 createEnableCheck(context.getWorkbenchContext()));
     }
-    
-    public static MultiEnableCheck createEnableCheck(WorkbenchContext 
workbenchContext) {
-        EnableCheckFactory checkFactory = new 
EnableCheckFactory(workbenchContext);
 
-        return new MultiEnableCheck()
-                        
.add(checkFactory.createWindowWithLayerNamePanelMustBeActiveCheck())
-                        
.add(checkFactory.createAtLeastNLayersMustBeSelectedCheck(1));
+    public static MultiEnableCheck createEnableCheck(
+            WorkbenchContext workbenchContext) {
+        final EnableCheckFactory checkFactory = new EnableCheckFactory(
+                workbenchContext);
+
+        return new MultiEnableCheck().add(
+                checkFactory.createWindowWithLayerNamePanelMustBeActiveCheck())
+                .add(checkFactory.createAtLeastNLayersMustBeSelectedCheck(1));
     }
-    
+
+    @Override
     public boolean execute(PlugInContext context) throws Exception {
-        //Call #getSelectedLayers before #clear, because #clear will surface
-        //output window. [Jon Aquino]
-        Layer[] selectedLayers = context.getSelectedLayers();
-        HTMLFrame out = context.getOutputFrame();
+        // Call #getSelectedLayers before #clear, because #clear will surface
+        // output window. [Jon Aquino]
+        final Layer[] selectedLayers = context.getSelectedLayers();
+        // HTMLFrame out = context.getOutputFrame();
+        final HTMLPanel out = new HTMLPanel();
+        out.setRecordNavigationControlVisible(false);
         out.createNewDocument();
-        out.addHeader(1, 
I18N.get("ui.plugin.LayerStatisticsPlugIn.layer-statistics"));
+        out.addHeader(1,
+                I18N.get("ui.plugin.LayerStatisticsPlugIn.layer-statistics"));
 
-        LayerStatistics totalStats = new LayerStatistics();
-        Envelope totalEnv = new Envelope();
+        final LayerStatistics totalStats = new LayerStatistics();
+        final Envelope totalEnv = new Envelope();
 
-        for (Layer layer : selectedLayers) {
-            LayerStatistics ls = layerStatistics(layer, totalStats);
+        for (final Layer layer : selectedLayers) {
+            final LayerStatistics ls = layerStatistics(layer, totalStats);
 
-            out.addHeader(2, 
I18N.get("ui.plugin.LayerStatisticsPlugIn.layer")+" " + layer.getName());
+            out.addHeader(2, I18N.get("ui.plugin.LayerStatisticsPlugIn.layer")
+                    + " " + layer.getName());
 
-            Envelope layerEnv = 
layer.getFeatureCollectionWrapper().getEnvelope();
-            out.addField(I18N.get("ui.plugin.LayerStatisticsPlugIn.envelope"), 
layerEnv.toString());
+            final Envelope layerEnv = layer.getFeatureCollectionWrapper()
+                    .getEnvelope();
+            out.addField(I18N.get("ui.plugin.LayerStatisticsPlugIn.envelope"),
+                    layerEnv.toString());
             totalEnv.expandToInclude(layerEnv);
             output(ls, out);
         }
 
         if (selectedLayers.length > 1) {
-            out.addHeader(2, 
I18N.get("ui.plugin.LayerStatisticsPlugIn.summary-for-all-layers"));
-            out.addField(I18N.get("ui.plugin.LayerStatisticsPlugIn.envelope"), 
totalEnv.toString());
+            out.addHeader(
+                    2,
+                    
I18N.get("ui.plugin.LayerStatisticsPlugIn.summary-for-all-layers"));
+            out.addField(I18N.get("ui.plugin.LayerStatisticsPlugIn.envelope"),
+                    totalEnv.toString());
             output(totalStats, out);
         }
-        out.surface();
 
+        AdditionalResults.addAdditionalResultAndShow(getName(), out);
+
+        // out.surface();
+
         return true;
     }
 
     private LayerStatistics layerStatistics(final Layer layer,
-        LayerStatistics totalStats) {
-        LayerStatistics ls = new LayerStatistics();
+            LayerStatistics totalStats) {
+        final LayerStatistics ls = new LayerStatistics();
 
-        for (Iterator i = layer.getFeatureCollectionWrapper().iterator(); 
i.hasNext();) {
-            Feature f = (Feature) i.next();
-            Geometry g = f.getGeometry();
-            double area = g.getArea();
-            double length = g.getLength();
+        for (final Iterator i = 
layer.getFeatureCollectionWrapper().iterator(); i
+                .hasNext();) {
+            final Feature f = (Feature) i.next();
+            final Geometry g = f.getGeometry();
+            final double area = g.getArea();
+            final double length = g.getLength();
 
             // these both need work - need to recurse into geometries
             // work done by mmichaud on 2010-12-12
-            int[] comps_and_holes = new int[]{0,0};
+            int[] comps_and_holes = new int[] { 0, 0 };
             comps_and_holes = recurse(g, comps_and_holes);
-            int comps = comps_and_holes[0];
-            int holes = comps_and_holes[1];
+            final int comps = comps_and_holes[0];
+            final int holes = comps_and_holes[1];
 
-            Coordinate[] pts = g.getCoordinates();
+            final Coordinate[] pts = g.getCoordinates();
 
             ls.addFeature(pts.length, holes, comps, area, length);
             totalStats.addFeature(pts.length, holes, comps, area, length);
@@ -137,50 +152,57 @@
 
         return ls;
     }
-    
+
     private int[] recurse(Geometry g, int[] comps_holes) {
         if (g instanceof GeometryCollection) {
-            for (int i = 0 ; i < g.getNumGeometries() ; i++) {
+            for (int i = 0; i < g.getNumGeometries(); i++) {
                 comps_holes = recurse(g.getGeometryN(i), comps_holes);
             }
-        }
-        else {
+        } else {
             comps_holes[0]++;
             if (g instanceof Polygon) {
-                comps_holes[1] += ((Polygon)g).getNumInteriorRing();
+                comps_holes[1] += ((Polygon) g).getNumInteriorRing();
             }
         }
         return comps_holes;
     }
 
-    public void output(LayerStatistics ls, HTMLFrame out) {
-        //=========  Output  ===============
+    public void output(LayerStatistics ls, HTMLPanel out) {
+        // ========= Output ===============
         out.addField("# Features:", ls.featureCount + "");
 
         out.append("<table border='1'>");
-        out.append(
-            "<tr><td bgcolor=#CCCCCC>&nbsp;</td><td  bgcolor=#CCCCCC 
align='center'> Min </td><td  bgcolor=#CCCCCC align='center'> Max </td><td  
bgcolor=#CCCCCC align='center'> 
"+I18N.get("ui.plugin.LayerStatisticsPlugIn.avg")+" </td><td  bgcolor=#CCCCCC 
align='center'> Total </td></tr>");
-        out.append("<tr><td bgcolor=#CCCCCC> Pts </td><td align='right'>" +
-            ls.minCoord + "</td><td align='right'>" + ls.maxCoord +
-            "</td><td align='right'>" + ls.avgCoord() +
-            "</td><td align='right'>" + ls.totalCoord + "</td></tr>");
-        out.append("<tr><td bgcolor=#CCCCCC> 
"+I18N.get("ui.plugin.LayerStatisticsPlugIn.holes")+" </td><td align='right'>" +
-            ls.minHoles + "</td><td align='right'>" + ls.maxHoles +
-            "</td><td align='right'>" + ls.avgHoles() +
-            "</td><td align='right'>" + ls.totalHoles + "</td></tr>");
-        out.append(
-            "<tr><td bgcolor=#CCCCCC> 
"+I18N.get("ui.plugin.LayerStatisticsPlugIn.components")+" </td><td 
align='right'>" +
-            ls.minComp + "</td><td align='right'>" + ls.maxComp +
-            "</td><td align='right'>" + ls.avgComp() +
-            "</td><td align='right'>" + ls.totalComp + "</td></tr>");
-        out.append("<tr><td bgcolor=#CCCCCC> 
"+I18N.get("ui.plugin.LayerStatisticsPlugIn.area")+" </td><td align='right'>" +
-            ls.minArea + "</td><td align='right'>" + ls.maxArea +
-            "</td><td align='right'>" + ls.avgArea() +
-            "</td><td align='right'>" + ls.totalArea + "</td></tr>");
-        out.append("<tr><td bgcolor=#CCCCCC> 
"+I18N.get("ui.plugin.LayerStatisticsPlugIn.length")+" </td><td align='right'>" 
+
-            ls.minLength + "</td><td align='right'>" + ls.maxLength +
-            "</td><td align='right'>" + ls.avgLength() +
-            "</td><td align='right'>" + ls.totalLength + "</td></tr>");
+        out.append("<tr><td bgcolor=#CCCCCC>&nbsp;</td><td  bgcolor=#CCCCCC 
align='center'> Min </td><td  bgcolor=#CCCCCC align='center'> Max </td><td  
bgcolor=#CCCCCC align='center'> "
+                + I18N.get("ui.plugin.LayerStatisticsPlugIn.avg")
+                + " </td><td  bgcolor=#CCCCCC align='center'> Total 
</td></tr>");
+        out.append("<tr><td bgcolor=#CCCCCC> Pts </td><td align='right'>"
+                + ls.minCoord + "</td><td align='right'>" + ls.maxCoord
+                + "</td><td align='right'>" + ls.avgCoord()
+                + "</td><td align='right'>" + ls.totalCoord + "</td></tr>");
+        out.append("<tr><td bgcolor=#CCCCCC> "
+                + I18N.get("ui.plugin.LayerStatisticsPlugIn.holes")
+                + " </td><td align='right'>" + ls.minHoles
+                + "</td><td align='right'>" + ls.maxHoles
+                + "</td><td align='right'>" + ls.avgHoles()
+                + "</td><td align='right'>" + ls.totalHoles + "</td></tr>");
+        out.append("<tr><td bgcolor=#CCCCCC> "
+                + I18N.get("ui.plugin.LayerStatisticsPlugIn.components")
+                + " </td><td align='right'>" + ls.minComp
+                + "</td><td align='right'>" + ls.maxComp
+                + "</td><td align='right'>" + ls.avgComp()
+                + "</td><td align='right'>" + ls.totalComp + "</td></tr>");
+        out.append("<tr><td bgcolor=#CCCCCC> "
+                + I18N.get("ui.plugin.LayerStatisticsPlugIn.area")
+                + " </td><td align='right'>" + ls.minArea
+                + "</td><td align='right'>" + ls.maxArea
+                + "</td><td align='right'>" + ls.avgArea()
+                + "</td><td align='right'>" + ls.totalArea + "</td></tr>");
+        out.append("<tr><td bgcolor=#CCCCCC> "
+                + I18N.get("ui.plugin.LayerStatisticsPlugIn.length")
+                + " </td><td align='right'>" + ls.minLength
+                + "</td><td align='right'>" + ls.maxLength
+                + "</td><td align='right'>" + ls.avgLength()
+                + "</td><td align='right'>" + ls.totalLength + "</td></tr>");
         out.append("</table>");
     }
 
@@ -204,7 +226,7 @@
         int featureCount = 0;
 
         private void addFeature(int coordCount, int holeCount, int compCount,
-            double area, double length) {
+                double area, double length) {
             featureCount++;
 
             if (isFirst || (coordCount < minCoord)) {
@@ -261,15 +283,18 @@
         }
 
         private double avgCoord() {
-            return (featureCount == 0) ? 0.0 : ((double)totalCoord / 
featureCount);
+            return (featureCount == 0) ? 0.0
+                    : ((double) totalCoord / featureCount);
         }
 
         private double avgHoles() {
-            return (featureCount == 0) ? 0.0 : ((double)totalHoles / 
featureCount);
+            return (featureCount == 0) ? 0.0
+                    : ((double) totalHoles / featureCount);
         }
 
         private double avgComp() {
-            return (featureCount == 0) ? 0.0 : ((double)totalComp / 
featureCount);
+            return (featureCount == 0) ? 0.0
+                    : ((double) totalComp / featureCount);
         }
 
         private double avgArea() {


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