Revision: 6077
          http://sourceforge.net/p/jump-pilot/code/6077
Author:   ma15569
Date:     2019-01-06 16:23:21 +0000 (Sun, 06 Jan 2019)
Log Message:
-----------
Reformatted numeric value in order that exported value on table (file .csv) are 
correctly read from Excell/OpenOffiuce

Modified Paths:
--------------
    
core/trunk/src/org/openjump/core/ui/plugin/tools/statistics/StatisticOverViewPlugIn.java

Modified: 
core/trunk/src/org/openjump/core/ui/plugin/tools/statistics/StatisticOverViewPlugIn.java
===================================================================
--- 
core/trunk/src/org/openjump/core/ui/plugin/tools/statistics/StatisticOverViewPlugIn.java
    2019-01-06 16:19:32 UTC (rev 6076)
+++ 
core/trunk/src/org/openjump/core/ui/plugin/tools/statistics/StatisticOverViewPlugIn.java
    2019-01-06 16:23:21 UTC (rev 6077)
@@ -27,17 +27,26 @@
  */
 package org.openjump.core.ui.plugin.tools.statistics;
 
-import java.awt.Dimension;
+import java.awt.Color;
+import java.awt.Component;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 
 import javax.swing.JScrollPane;
 import javax.swing.JTable;
+import javax.swing.ScrollPaneConstants;
+import javax.swing.table.DefaultTableCellRenderer;
+import javax.swing.table.DefaultTableModel;
 
 import org.openjump.core.apitools.FeatureCollectionTools;
 import org.openjump.sextante.gui.additionalResults.AdditionalResults;
 
 import com.vividsolutions.jump.I18N;
+import com.vividsolutions.jump.feature.AttributeType;
 import com.vividsolutions.jump.feature.Feature;
 import com.vividsolutions.jump.feature.FeatureCollection;
+import com.vividsolutions.jump.feature.FeatureSchema;
+import com.vividsolutions.jump.util.StatisticIndices;
 import com.vividsolutions.jump.workbench.WorkbenchContext;
 import com.vividsolutions.jump.workbench.model.Layer;
 import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
@@ -46,6 +55,8 @@
 import com.vividsolutions.jump.workbench.plugin.PlugInContext;
 import com.vividsolutions.jump.workbench.ui.MenuNames;
 
+import de.fho.jump.pirol.utilities.attributes.AttributeInfo;
+
 /**
  * PlugIn that gives a quick impression on the value ranges, means (modes) and
  * the deviation of the layer features' attribute values.
@@ -98,18 +109,18 @@
                             
I18N.get("org.openjump.core.ui.plugin.tools.statistics.StatisticOverViewPlugIn.Selected-layer-is-empty"));
             return false;
         }
-        final StatisticOverViewTableModel tableModel = new 
StatisticOverViewTableModel(
-                features);
+        // final StatisticOverViewTableModel tableModel = new 
StatisticOverViewTableModel(
+        //       features);
 
         // -- [Giuseppe Aruta 2018-3-12] Statistic table is opened into
         // AdditionalResult frame
-        final JTable table = new JTable(tableModel);
-        table.setRowHeight(22);
+        // final JTable table = new JTable(tableModel);
+        // table.setRowHeight(22);
 
-        final JScrollPane scrollPane = new JScrollPane(table);
-        table.setPreferredScrollableViewportSize(new Dimension(500, 300));
+        // final JScrollPane scrollPane = new JScrollPane(table);
+        // table.setPreferredScrollableViewportSize(new Dimension(500, 300));
 
-        AdditionalResults.addAdditionalResultAndShow(getName(), scrollPane);
+        // AdditionalResults.addAdditionalResultAndShow(getName(), scrollPane);
 
         // StatisticOverViewDialog dialog = new
         // StatisticOverViewDialog(context.getWorkbenchFrame(), this.getName(),
@@ -116,11 +127,120 @@
         // false, features);
 
         // dialog.setVisible(true);
-
+       
+        AdditionalResults.addAdditionalResultAndShow(getName(),
+                pan(features, 3));
         return true;
 
     }
 
+    private static JScrollPane pan(Feature[] features, int scale) {
+        final DefaultTableModel dtm = new DefaultTableModel();
+        final JTable jTable = new JTable();
+
+        jTable.setGridColor(Color.WHITE);
+        jTable.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() 
{
+
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public Component getTableCellRendererComponent(JTable table,
+                    Object value, boolean isSelected, boolean hasFocus,
+                    int row, int column) {
+                final Component c = super.getTableCellRendererComponent(table,
+                        value, isSelected, hasFocus, row, column);
+                c.setBackground(row % 2 == 0 ? Color.white : new Color(230,
+                        230, 230));
+                if (isSelected) {
+                    c.setBackground(Color.black);
+                }
+                return c;
+            };
+        });
+
+        jTable.setModel(dtm);
+        jTable.setEnabled(true);
+
+        final Feature feat = features[0];
+        final FeatureSchema fs = feat.getSchema();
+
+        final AttributeInfo[] attrInfos = AttributeInfo
+                .schema2AttributeInfoArray(fs);
+
+        // we don't use the Geometry
+        final String[] attrToWorkWith = new String[attrInfos.length - 1];
+        int saveAttrIndex = 0;
+
+        for (int i = 0; i < attrInfos.length; i++) {
+            if 
(!attrInfos[i].getAttributeType().equals(AttributeType.GEOMETRY)) {
+                attrToWorkWith[saveAttrIndex] = 
attrInfos[i].getAttributeName();
+                saveAttrIndex++;
+            }
+        }
+
+        saveAttrIndex = 0;
+
+        dtm.addColumn(I18N
+                
.get("org.openjump.core.ui.plugin.queries.SimpleQuery.attribute"));
+        dtm.addColumn(I18N
+                
.get("org.openjump.sigle.plugin.ReplaceValuePlugIn.Attribute-type"));
+
+        dtm.addColumn(I18N
+                
.get("org.openjump.core.ui.plugin.tools.JoinAttributesSpatiallyPlugIn.minimum"));
+        dtm.addColumn(I18N
+                
.get("org.openjump.core.ui.plugin.tools.statistics.StatisticOverViewTableModel.mean-mode"));
+        dtm.addColumn(I18N
+                
.get("org.openjump.core.ui.plugin.tools.JoinAttributesSpatiallyPlugIn.maximum"));
+        dtm.addColumn(I18N
+                
.get("org.openjump.core.ui.plugin.tools.JoinAttributesSpatiallyPlugIn.standard-dev"));
+        dtm.addColumn(I18N
+                
.get("org.openjump.core.ui.plugin.tools.JoinAttributesSpatiallyPlugIn.sum"));
+
+        for (final AttributeInfo attrInfo : attrInfos) {
+            if (attrInfo.getAttributeType().equals(AttributeType.GEOMETRY)) {
+                continue;
+            }
+            if (FeatureCollectionTools.isAttributeTypeNumeric(attrInfo
+                    .getAttributeType())) {
+                // numeric
+
+                final StatisticIndices stat = FeatureCollectionTools
+                        .getStatistics(features, fs,
+                                attrInfo.getAttributeName());
+
+                dtm.addRow(new Object[] {
+                        attrInfo.getAttributeName(),
+                        attrInfo.getAttributeType(),
+                        new BigDecimal(stat.getMin()).setScale(scale,
+                                RoundingMode.CEILING),
+                        new BigDecimal(stat.getMean()).setScale(scale,
+                                RoundingMode.CEILING),
+                        new BigDecimal(stat.getMax()).setScale(scale,
+                                RoundingMode.CEILING),
+                        new BigDecimal(stat.getStdDev()).setScale(scale,
+                                RoundingMode.CEILING),
+                        new BigDecimal(stat.getSum()).setScale(scale,
+                                RoundingMode.CEILING) });
+
+            } else {
+                final Object[] meansModes = FeatureCollectionTools
+                        .getMeanOrModeForAttributes(features, attrToWorkWith);
+
+                dtm.addRow(new Object[] { attrInfo.getAttributeName(),
+                        attrInfo.getAttributeType(), null,
+                        meansModes[saveAttrIndex], null, null, null });
+
+            }
+            saveAttrIndex++;
+        }
+
+        final JScrollPane pane = new JScrollPane(jTable,
+                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
+                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+        return pane;
+
+    }
+
     public MultiEnableCheck createEnableCheck(
             final WorkbenchContext workbenchContext) {
         final EnableCheckFactory checkFactory = new EnableCheckFactory(



_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to