Revision: 5900
          http://sourceforge.net/p/jump-pilot/code/5900
Author:   ma15569
Date:     2018-06-26 09:16:12 +0000 (Tue, 26 Jun 2018)
Log Message:
-----------
Substitute output HTMLDoc to JTable.   Allow selection of more than one layer 
on plugin dialog

Modified Paths:
--------------
    
core/trunk/src/org/openjump/core/ui/plugin/raster/statistics/DEMStatisticsPlugIn.java

Modified: 
core/trunk/src/org/openjump/core/ui/plugin/raster/statistics/DEMStatisticsPlugIn.java
===================================================================
--- 
core/trunk/src/org/openjump/core/ui/plugin/raster/statistics/DEMStatisticsPlugIn.java
       2018-06-26 09:14:40 UTC (rev 5899)
+++ 
core/trunk/src/org/openjump/core/ui/plugin/raster/statistics/DEMStatisticsPlugIn.java
       2018-06-26 09:16:12 UTC (rev 5900)
@@ -32,28 +32,42 @@
 
 package org.openjump.core.ui.plugin.raster.statistics;
 
-import java.awt.Color;
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.Font;
 import java.awt.image.Raster;
 import java.io.IOException;
 import java.text.DecimalFormat;
 import java.text.NumberFormat;
-import java.util.Iterator;
+import java.util.Collection;
 import java.util.Locale;
 
+import javax.swing.DefaultListModel;
 import javax.swing.Icon;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.ListSelectionModel;
+import javax.swing.ScrollPaneConstants;
+import javax.swing.table.DefaultTableModel;
 
 import org.openjump.core.rasterimage.RasterImageLayer;
 import 
org.openjump.core.rasterimage.RasterImageLayer.RasterDataNotFoundException;
+import org.openjump.core.rasterimage.Stats;
 import org.openjump.sextante.gui.additionalResults.AdditionalResults;
 
 import com.vividsolutions.jts.geom.Envelope;
 import com.vividsolutions.jump.I18N;
+import com.vividsolutions.jump.task.TaskMonitor;
 import com.vividsolutions.jump.workbench.WorkbenchContext;
-import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
 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.HTMLPanel;
+import com.vividsolutions.jump.workbench.plugin.ThreadedBasePlugIn;
+import com.vividsolutions.jump.workbench.ui.GUIUtil;
+import com.vividsolutions.jump.workbench.ui.LayerNameRenderer;
+import com.vividsolutions.jump.workbench.ui.MultiInputDialog;
 import com.vividsolutions.jump.workbench.ui.images.IconLoader;
 
 /**
@@ -66,17 +80,20 @@
  * @author Giuseppe Aruta [2015_05_16] Added X*Y Cell size
  * @author Giuseppe Aruta [2018_01_19] Removed depency to
  *         OpenJUMPSextanteRasterLayer class. Clean the code
+ * @author Giuseppe Aruta [2018_06_26] Substitute output HTMLDoc to JTable.
+ *         Allow selection of multiple layers on plugin dialog.
  */
-public class DEMStatisticsPlugIn extends AbstractPlugIn {
-
-    private final static String MAX = I18N
-            
.get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.cell.max");
-    private final static String MIN = I18N
-            
.get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.cell.min");
+public class DEMStatisticsPlugIn extends ThreadedBasePlugIn {
+    private static final String R_MAX = I18N
+            
.get("org.openjump.core.ui.plugin.tools.JoinAttributesSpatiallyPlugIn.maximum");
+    private static final String R_MIN = I18N
+            
.get("org.openjump.core.ui.plugin.tools.JoinAttributesSpatiallyPlugIn.minimum");
+    private static final String R_MEAN = I18N
+            
.get("org.openjump.core.ui.plugin.tools.JoinAttributesSpatiallyPlugIn.mean");
+    private static final String R_STD = I18N
+            
.get("org.openjump.core.ui.plugin.tools.JoinAttributesSpatiallyPlugIn.standard-dev");
     private final static String NODATA = I18N
             
.get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.cell.nodata");
-    private final static String NUM_LAYER = I18N
-            
.get("org.openjump.core.ui.plugin.layer.LayerPropertiesPlugIn.Number-of-Layers");
     private final static String NODATACELLS = I18N
             
.get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.nodatacell");
     private final static String VALIDCELLS = I18N
@@ -91,9 +108,10 @@
             
.get("org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.columns");
     private final static String ROWS = I18N
             
.get("org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.rows");
-    private final static String LAYERS = I18N
-            
.get("org.openjump.core.ui.plugin.queries.SimpleQuery.selected-layers")
-            + " :";
+    private final static String RASTER_BANDS = I18N
+            
.get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.file.bands_number");
+    private final static String AREA = I18N
+            .get("ui.plugin.LayerStatisticsPlugIn.area");
 
     public static MultiEnableCheck createEnableCheck(
             WorkbenchContext workbenchContext) {
@@ -101,11 +119,9 @@
                 workbenchContext);
         return new MultiEnableCheck()
                 .add(checkFactory
-                        .createWindowWithLayerNamePanelMustBeActiveCheck())
-                .add(checkFactory.createAtLeastNLayerablesMustBeSelectedCheck(
-                        1, RasterImageLayer.class))
-                .add(checkFactory
-                        .createRasterImageLayerExactlyNBandsMustExistCheck(1));
+                        
.createWindowWithAssociatedTaskFrameMustBeActiveCheck())
+                .add(checkFactory.createAtLeastNLayerablesOfTypeMustExistCheck(
+                        1, RasterImageLayer.class));
     }
 
     /*
@@ -130,117 +146,60 @@
         return counter;
     }
 
+    public static MultiInputDialog dialog;
+    public static JPanel panel;
+    private JList<RasterImageLayer> list;
+    private final DefaultListModel<RasterImageLayer> listModel = new 
DefaultListModel<RasterImageLayer>();
+    private JScrollPane scroller;
+    private static final Dimension scroller_size = new Dimension(400, 200);
+
     @Override
     public boolean execute(PlugInContext context) throws Exception {
+        dialog = new MultiInputDialog(context.getWorkbenchFrame(), getName(),
+                true);
+        setDialogValues(dialog, context);
+        GUIUtil.centreOnWindow(dialog);
+        dialog.setVisible(true);
+        return true;
 
-        final Locale locale = new Locale("en", "UK");
-        final String pattern = "###.########";
-        final DecimalFormat df = (DecimalFormat) NumberFormat
-                .getNumberInstance(locale);
-        df.applyPattern(pattern);
-        final WorkbenchContext wbcontext = context.getWorkbenchContext();
-        final int ras = wbcontext.getLayerNamePanel()
-                .selectedNodes(RasterImageLayer.class).size();
-        final HTMLPanel out = new HTMLPanel();
-        out.setRecordNavigationControlVisible(false);
-        out.createNewDocument();
-        out.setBackground(Color.lightGray);
-        out.addHeader(1, NUM_LAYER + ": " + ras);
-        out.append("<table border='1'>");
-        out.append("<tr><td bgcolor=#CCCCCC align='center'> "
-                + I18N.get("ui.plugin.LayerStatisticsPlugIn.layer")
-                + "</td><td bgcolor=#CCCCCC align='center'> " + MIN
-                + "</td><td bgcolor=#CCCCCC align='center'> " + MAX
-                + "</td><td bgcolor=#CCCCCC align='center'> " + NODATA
-                + "</td><td bgcolor=#CCCCCC align='center'> " + VALIDCELLS
-                + "</td><td bgcolor=#CCCCCC align='center'> " + NODATACELLS
-                + "</td><td bgcolor=#CCCCCC align='center'> " + COLUMNS
-                + "</td><td bgcolor=#CCCCCC align='center'> " + ROWS
-                + "</td><td bgcolor=#CCCCCC align='center'> " + XMIN
-                + "</td><td bgcolor=#CCCCCC align='center'> " + YMIN
-                + "</td><td bgcolor=#CCCCCC align='center'> " + CELL_SIZE
-                + "</td></tr>");
-        for (final Iterator i = wbcontext.getLayerNamePanel()
-                .selectedNodes(RasterImageLayer.class).iterator(); 
i.hasNext();) {
-            final RasterImageLayer slayer = (RasterImageLayer) i.next();
-            final Raster raster = slayer.getRasterData(null);
-            final Double nodata = slayer.getNoDataValue();
-            final double minRas = slayer.getMetadata().getStats().getMin(0);
-            final double maxRas = slayer.getMetadata().getStats().getMax(0);
-            final double meanRas = slayer.getMetadata().getStats().getMean(0);
-            final Envelope extent = slayer.getWholeImageEnvelope(); // Envelope
-                                                                    // of
-            // layer
-            String min = df.format(minRas);// Min value of
-                                           // cells
-            final String max = df.format(maxRas);// Max value of
-            df.format(meanRas);
+    }
 
-            final Locale locale1 = new Locale("en", "UK");
-            final String pattern1 = "###.## ";
-            final DecimalFormat df1 = (DecimalFormat) NumberFormat
-                    .getNumberInstance(locale1);
-            df.applyPattern(pattern1);
-            final String cellSizex = df1.format(cellSizeX(raster, extent));// 
Cell
-            // size
-            final String cellSizey = df1.format(cellSizeY(raster, extent));
-            final String cellSize = cellSizex + "x" + cellSizey;
-            final String minx = df.format(extent.getMinX());
-            final String miny = df.format(extent.getMinY());
-            final int X = raster.getWidth(); // Number of columns
-            final int Y = raster.getHeight(); // Number of rows
+    @SuppressWarnings("unchecked")
+    private void setDialogValues(final MultiInputDialog dialog,
+            PlugInContext context) {
+        final Collection<RasterImageLayer> rlayers = context.getTask()
+                .getLayerManager().getLayerables(RasterImageLayer.class);
+        dialog.addSubTitle(I18N.get("ui.GenericNames.select-layers"));
+        dialog.addLabel(I18N
+                
.get("org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers"));
+        listModel.removeAllElements();
+        for (final RasterImageLayer currentLayer : rlayers) {
+            listModel.addElement(currentLayer);
 
-            /*
-             * Giuseppe Aruta Nov. 2015 workaround for OpenJUMP bug 410
-             * (Sextante), If nodata value is -3.40282346639E38 and min value
-             * -9999, -99999 or 1.70141E38. Those two values are displayed in
-             * red on DEMStatistic table
-             */
-            String nodataText = null;
-            final String texmin = df.format(minRas);
-            final double nda = slayer.getNoDataValue();
-            final String begin = "<b><font color='red'>";
-            final String end = "</font></b>";
-            if (nda == -3.40282346639E38 || nodata == -1.79769313486E308) {
-                if (minRas == -9999 || minRas == -99999 || minRas == 
1.70141E38) {
-                    nodataText = begin + nodata + end;
-                    min = begin + texmin + end;
-                } else {
-                    nodataText = Double.toString(nda);
-                    min = texmin;
-                }
+        }
 
-            } else {
-                nodataText = Double.toString(nda);
-                min = texmin;
+        list = new JList<RasterImageLayer>(listModel);
+        // list.setBorder(new MatteBorder(1, 1, 1, 1, dialog.getForeground()));
+        list.setFont(new Font(dialog.getFont().getName(), Font.BOLD, 13));
+        list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
+        final LayerNameRenderer layerListCellRenderer = new 
LayerNameRenderer();
+        layerListCellRenderer.setCheckBoxVisible(false);
+        layerListCellRenderer.setProgressIconLabelVisible(false);
+        list.setCellRenderer(layerListCellRenderer);
 
-            }
-            final int nodatacells = nodata(raster, nodata);// number of no data
-            // cells
-            final int validcells = X * Y - nodatacells;// Number of
-            // valid
-            // cells
+        panel = new JPanel(new BorderLayout());
+        panel.setMinimumSize(scroller_size);
+        panel.setPreferredSize(scroller_size);
+        panel.add(list);
+        scroller = new JScrollPane(panel,
+                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
+                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
 
-            out.append("</td><td align='right'>" + slayer.getName()
-                    + "</td><td align='right'>" + min
-                    + "</td><td align='right'>" + max
-                    + "</td><td align='right'>" + nodataText
-                    + "</td><td align='right'>" + validcells
-                    + "</td><td align='right'>" + nodatacells
-                    + "</td><td align='right'>" + X + "</td><td align='right'>"
-                    + Y + "</td><td align='right'>" + minx
-                    + "</td><td align='right'>" + miny
-                    + "</td><td align='right'>" + cellSize + "</td></tr>");
+        dialog.addRow(scroller);
 
-        }
-        out.append("</table>");
-        AdditionalResults.addAdditionalResultAndShow(getName() + "[" + LAYERS
-                + +ras + "]", out);
+        dialog.setResizable(false);
+        dialog.pack();
 
-        // out.setPreferredSize(new Dimension(800, 100));
-        // out.setMinimumSize(new Dimension(800, 100));
-        // out.surface();
-        return true;
     }
 
     @Override
@@ -264,4 +223,148 @@
         return env.getHeight() / r.getHeight();
     }
 
+    @Override
+    public void run(TaskMonitor monitor, PlugInContext context)
+            throws Exception {
+
+        monitor.allowCancellationRequests();
+        monitor.report(getName()
+                + ": "
+                + 
I18N.get("org.openjump.core.ui.plugin.edittoolbox.cursortools.FillPolygonTool.computing"));
+        final Locale locale = new Locale("en", "UK");
+        final String pattern = "###.########";
+        final DecimalFormat df = (DecimalFormat) NumberFormat
+                .getNumberInstance(locale);
+        df.applyPattern(pattern);
+        final JTable jTable = new JTable();
+        if (!dialog.wasOKPressed()) {
+            return;
+        } else {
+            final Collection<RasterImageLayer> rLayers = list
+                    .getSelectedValuesList();
+            String min;
+            String max;
+            String mean;
+            String stddev;
+            String bands;
+            final DefaultTableModel dtm = (DefaultTableModel) 
jTable.getModel();
+
+            final Object[] header = new Object[] { XMIN, YMIN, COLUMNS, ROWS,
+                    CELL_SIZE, AREA, RASTER_BANDS, R_MIN, R_MAX, R_MEAN, R_STD,
+                    NODATA, VALIDCELLS, NODATACELLS };
+            dtm.addColumn(I18N.get("jump.plugin.qa.DiffGeometryPlugIn.Layer")
+                    .toUpperCase(), header);
+            // .getSelectedObjects();
+
+            for (final Object name2 : rLayers) {
+                final RasterImageLayer slayer = (RasterImageLayer) name2;
+                final Stats stats = slayer.getMetadata().getStats();
+                final Raster raster = slayer.getRasterData(null);
+                final Double nodata = slayer.getNoDataValue();
+                bands = "" + slayer.getNumBands();
+                if (slayer.getNumBands() > 1) {
+                    min = df.format(stats.getMin(0)) + "-"
+                            + df.format(stats.getMin(1)) + "-"
+                            + df.format(stats.getMin(2));
+                    max = df.format(stats.getMax(0)) + "-"
+                            + df.format(stats.getMax(1)) + "-"
+                            + df.format(stats.getMax(2));
+                    mean = df.format(stats.getMean(0)) + "-"
+                            + df.format(stats.getMean(1)) + "-"
+                            + df.format(stats.getMean(2));
+                    stddev = df.format(stats.getStdDev(0)) + "-"
+                            + df.format(stats.getStdDev(1)) + "-"
+                            + df.format(stats.getStdDev(2));
+                } else {
+                    min = df.format(stats.getMin(0));
+                    max = df.format(stats.getMax(0));
+                    mean = df.format(stats.getMean(0));
+                    stddev = df.format(stats.getStdDev(0));
+                }
+                final Envelope extent = slayer.getWholeImageEnvelope(); // 
Envelope
+                                                                        // of
+
+                // final Locale locale1 = new Locale("en", "UK");
+                final String pattern1 = "###.## ";
+                // final DecimalFormat df1 = (DecimalFormat) NumberFormat
+                // .getNumberInstance(locale1);
+                df.applyPattern(pattern1);
+                final double cellSizeX = cellSizeX(raster, extent);
+                final double cellSizeY = cellSizeY(raster, extent);
+
+                final String CELLSIZEX = df.format(cellSizeX);// Cell
+
+                final String CELLSIZEY = df.format(cellSizeY);
+                final String cellSize = CELLSIZEX + "x" + CELLSIZEY;
+                final String minx = df.format(extent.getMinX());
+                final String miny = df.format(extent.getMinY());
+                final int X = raster.getWidth(); // Number of columns
+                final int Y = raster.getHeight(); // Number of rows
+                /*
+                 * Giuseppe Aruta Nov. 2015 workaround for OpenJUMP bug 410
+                 * (Sextante), If nodata value is -3.40282346639E38 and min
+                 * value -9999, -99999 or 1.70141E38. Those two values are
+                 * displayed in red on DEMStatistic table
+                 */
+                String nodataText = null;
+                final String texmin = df.format(stats.getMin(0));
+                final double nda = slayer.getNoDataValue();
+                final String begin = "<b><font color='red'>";
+                final String end = "</font></b>";
+                if (nda == -3.40282346639E38 || nodata == -1.79769313486E308) {
+                    if (stats.getMin(0) == -9999 || stats.getMin(0) == -99999
+                            || stats.getMin(0) == 1.70141E38) {
+                        nodataText = begin + nodata + end;
+                        min = begin + texmin + end;
+                    } else {
+                        nodataText = Double.toString(nda);
+                        min = texmin;
+                    }
+
+                } else {
+                    nodataText = Double.toString(nda);
+                    min = texmin;
+
+                }
+                final int nodatacells = nodata(raster, nodata);// number of no
+                                                               // data
+                // cells
+                final int validcells = X * Y - nodatacells;// Number of
+                // valid
+                // cells
+                final double area = raster.getWidth() * raster.getHeight()
+                        * cellSizeX * cellSizeY;
+                final String TOT_AREA = df.format(area);
+                final Object[] layers = new Object[] { minx, miny, X, Y,
+                        cellSize, TOT_AREA, bands, min, max, mean, stddev,
+                        nodataText, validcells, nodatacells };
+
+                dtm.addColumn(slayer.getName().toUpperCase(), layers);
+
+            }
+
+            final JTable table = new JTable(dtm) {
+
+                private static final long serialVersionUID = 1L;
+
+                @Override
+                public boolean isCellEditable(int row, int column) {
+                    return false;
+                }
+
+            };
+
+            // final JTable table = new JTable(dtm);
+
+            table.setRowHeight(22);
+            final JScrollPane scrollPane = new JScrollPane(table);
+            table.setPreferredScrollableViewportSize(new Dimension(500, 300));
+
+            AdditionalResults.addAdditionalResultAndShow(getName(), 
scrollPane);
+
+            return;
+
+        }
+    }
+
 }


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