Revision: 6106
http://sourceforge.net/p/jump-pilot/code/6106
Author: ma15569
Date: 2019-01-19 11:03:24 +0000 (Sat, 19 Jan 2019)
Log Message:
-----------
Added (hopefully the last) monitoring to raster tools
Modified Paths:
--------------
plug-ins/OpenKLEM/OpenKLEMOpenJUMP/trunk/src/com/geomaticaeambiente/klemgui/plugin/rastertools/CutRasterPlugin.java
plug-ins/OpenKLEM/OpenKLEMOpenJUMP/trunk/src/com/geomaticaeambiente/klemgui/plugin/rastertools/RasterizeVectorLayerPlugIn.java
plug-ins/OpenKLEM/OpenKLEMOpenJUMP/trunk/src/com/geomaticaeambiente/klemgui/plugin/rastertools/ReclassRasterPlugin.java
Modified:
plug-ins/OpenKLEM/OpenKLEMOpenJUMP/trunk/src/com/geomaticaeambiente/klemgui/plugin/rastertools/CutRasterPlugin.java
===================================================================
---
plug-ins/OpenKLEM/OpenKLEMOpenJUMP/trunk/src/com/geomaticaeambiente/klemgui/plugin/rastertools/CutRasterPlugin.java
2019-01-19 10:32:18 UTC (rev 6105)
+++
plug-ins/OpenKLEM/OpenKLEMOpenJUMP/trunk/src/com/geomaticaeambiente/klemgui/plugin/rastertools/CutRasterPlugin.java
2019-01-19 11:03:24 UTC (rev 6106)
@@ -1,28 +1,35 @@
package com.geomaticaeambiente.klemgui.plugin.rastertools;
-import com.geomaticaeambiente.klemgui.utils.PluginUtils;
+import java.io.File;
+
+import javax.swing.JButton;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+
+import org.openjump.core.rasterimage.RasterImageLayer;
+
import com.geomaticaeambiente.klemgui.ui.CustomComboBox;
-import com.geomaticaeambiente.openjump.klem.grid.DoubleBasicGrid;
-import com.geomaticaeambiente.openjump.klem.rastertools.RasterClipper;
import com.geomaticaeambiente.klemgui.ui.GUIUtils;
import com.geomaticaeambiente.klemgui.ui.InitialDialog;
+import com.geomaticaeambiente.klemgui.ui.LayerablesList;
import com.geomaticaeambiente.klemgui.ui.MainPanel;
-import com.geomaticaeambiente.klemgui.ui.LayerablesList;
+import com.geomaticaeambiente.klemgui.utils.AbstractInputKlemPlugin;
+import com.geomaticaeambiente.klemgui.utils.ActionObject;
import com.geomaticaeambiente.klemgui.utils.ComponentsTreeMap;
import com.geomaticaeambiente.klemgui.utils.InitialData;
-import com.geomaticaeambiente.klemgui.utils.AbstractInputKlemPlugin;
-import com.geomaticaeambiente.klemgui.utils.ActionObject;
+import com.geomaticaeambiente.klemgui.utils.PluginUtils;
import com.geomaticaeambiente.klemgui.utils.RasterUtils;
+import com.geomaticaeambiente.openjump.klem.grid.DoubleBasicGrid;
+import com.geomaticaeambiente.openjump.klem.rastertools.RasterClipper;
+import com.vividsolutions.jump.task.TaskMonitor;
import com.vividsolutions.jump.util.StringUtil;
+import com.vividsolutions.jump.workbench.Logger;
+import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
import com.vividsolutions.jump.workbench.plugin.PlugInContext;
+import com.vividsolutions.jump.workbench.plugin.ThreadedBasePlugIn;
import com.vividsolutions.jump.workbench.ui.ErrorDialog;
-import java.awt.geom.NoninvertibleTransformException;
-import java.io.File;
-import javax.swing.JButton;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JTextField;
-import org.openjump.core.rasterimage.RasterImageLayer;
+import com.vividsolutions.jump.workbench.ui.task.TaskMonitorManager;
/**
* Plugin for cutting a raster with another raster. The raster must be loaded
on
@@ -32,7 +39,8 @@
*/
public class CutRasterPlugin extends AbstractInputKlemPlugin {
- public CutRasterPlugin(PlugInContext context, InitialDialog initialDialog,
LayerablesList layerablesList) {
+ public CutRasterPlugin(PlugInContext context, InitialDialog initialDialog,
+ LayerablesList layerablesList) {
super(context, initialDialog);
this.context = context;
this.layerablesList = layerablesList;
@@ -41,88 +49,210 @@
@Override
public InitialData setInitialData() {
-// ar_rasterImageLayers =
PluginUtils.getRasterImageLayers(layerablesList.getLayerables());
+ // ar_rasterImageLayers =
PluginUtils.getRasterImageLayers(layerablesList.getLayerables());
- InitialData initialData = new InitialData();
+ final InitialData initialData = new InitialData();
//input data
- initialData.setParam_Label_TextBox(
- GUIUtils.setGUILabel(RASTER_IN),
-
PluginUtils.getRasterImageLayers(layerablesList.getLayerables()),
- GUIUtils.INPUT);//combobox with rasterImageLayer
- initialData.setParam_Label_TextBox(GUIUtils.setGUILabel(RASTER_MASK),
PluginUtils.getRasterImageLayers(layerablesList.getLayerables()),
GUIUtils.INPUT);//combobox with rasterImageLayer
+ initialData
+ .setParam_Label_TextBox(GUIUtils.setGUILabel(RASTER_IN),
+ PluginUtils.getRasterImageLayers(layerablesList
+ .getLayerables()), GUIUtils.INPUT);//combobox
with rasterImageLayer
+ initialData
+ .setParam_Label_TextBox(GUIUtils.setGUILabel(RASTER_MASK),
+ PluginUtils.getRasterImageLayers(layerablesList
+ .getLayerables()), GUIUtils.INPUT);//combobox
with rasterImageLayer
//output data
-
initialData.setParam_Label_TextBox_Button(GUIUtils.setGUILabel(RASTER_OUT), "",
new ActionObject(""), GUIUtils.OUTPUT); //JTextField
+ initialData.setParam_Label_TextBox_Button(
+ GUIUtils.setGUILabel(RASTER_OUT), "", new ActionObject(""),
+ GUIUtils.OUTPUT); //JTextField
return initialData;
}
@Override
- public ComponentsTreeMap setComponentsActions(ComponentsTreeMap
personalTreeMap) {
+ public ComponentsTreeMap setComponentsActions(
+ ComponentsTreeMap personalTreeMap) {
- final JTextField outputTextField = (JTextField)
personalTreeMap.getComponent("00", GUIUtils.OUTPUT, 1);
- JButton outputButton = (JButton) personalTreeMap.getComponent("00",
GUIUtils.OUTPUT, 2);
+ final JTextField outputTextField = (JTextField) personalTreeMap
+ .getComponent("00", GUIUtils.OUTPUT, 1);
+ final JButton outputButton = (JButton) personalTreeMap.getComponent(
+ "00", GUIUtils.OUTPUT, 2);
outputButton.setIcon(PluginUtils.getFolderIcon());
-
outputButton.addActionListener(GUIUtils.setSaveRasterTif(outputTextField));
+ outputButton.addActionListener(GUIUtils
+ .setSaveRasterTif(outputTextField));
return personalTreeMap;
}
+ public void cutRasterCommand(final ComponentsTreeMap componentsWithActions)
+ throws Exception {
+ //get input raster names
+ final String rasterSelected1 = GUIUtils
+ .getStringValue(componentsWithActions.getComponent("00",
+ GUIUtils.INPUT, 1));
+ final String rasterSelected2 = GUIUtils
+ .getStringValue(componentsWithActions.getComponent("01",
+ GUIUtils.INPUT, 1));
+
+ //get output raster name
+ final String outRasterName = GUIUtils
+ .getStringValue(componentsWithActions.getComponent("00",
+ GUIUtils.OUTPUT, 1));
+
+ //check input values
+ GUIUtils.checkStringValue(rasterSelected1, RASTER_IN);
+ GUIUtils.checkStringValue(rasterSelected2, RASTER_MASK);
+
+ //check output values
+ GUIUtils.checkFileValue(outRasterName, RASTER_OUT);
+
+ //get input raster as rasterImageLayer from string
+ final RasterImageLayer inputRasterSelected = PluginUtils
+ .getRasterImageLayerSelected((CustomComboBox.RasterComboBox)
componentsWithActions
+ .getComponent("00", GUIUtils.INPUT, 1));
+ final DoubleBasicGrid inputGrid = RasterUtils
+ .getDoubleBasicGrid(inputRasterSelected);
+
+ //get mask raster as rasterImageLayer from string
+ final RasterImageLayer maskRasterSelected = PluginUtils
+ .getRasterImageLayerSelected((CustomComboBox.RasterComboBox)
componentsWithActions
+ .getComponent("01", GUIUtils.INPUT, 1));
+ final DoubleBasicGrid clipperGrid = RasterUtils
+ .getDoubleBasicGrid(maskRasterSelected);
+
+ //Clip raster
+ final DoubleBasicGrid clippedRaster = RasterClipper.clip(inputGrid,
+ clipperGrid);
+
+ //Create the output file and display on OJ
+ //Save grid as tiff
+ RasterUtils.saveOutputRasterAsTiff(clippedRaster, new File(
+ outRasterName));
+ //Display raster on OJ from file
+ RasterUtils.displayRasterFileOnOJ(context.getWorkbenchContext(),
+ new File(outRasterName), null);
+
+ JOptionPane.showMessageDialog(super.getInitialDialog(), PluginUtils
+ .getResources().getString("SetWorkspacePlugin.Done.message"),
+ PluginUtils.plugInName, JOptionPane.INFORMATION_MESSAGE);
+ }
+
@Override
public JPanel buildPluginPanel(final ComponentsTreeMap
componentsWithActions) {
- if(this.mainPanel != null) {
- return this.mainPanel;
+ if (mainPanel != null) {
+ return mainPanel;
}
- this.mainPanel = new MainPanel(super.getInitialDialog(),
componentsWithActions, false, false, true,
-
PluginUtils.getResources().getString("MainPanel.ExecuteButton.text"),
layerablesList) {
+ mainPanel = new MainPanel(super.getInitialDialog(),
+ componentsWithActions, false, false, true, PluginUtils
+ .getResources().getString(
+ "MainPanel.ExecuteButton.text"),
layerablesList) {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
@Override
public void rightButton() {
try {
+ try {
+ AbstractPlugIn.toActionListener(
+ new ThreadedBasePlugIn() {
+ @Override
+ public String getName() {
+ return null;
+ }
+
+ @Override
+ public boolean execute(PlugInContext
context)
+ throws Exception {
+ return true;
+ }
+
+ @Override
+ public void run(TaskMonitor monitor,
+ PlugInContext context)
+ throws Exception {
+ monitor.report(PluginUtils
+ .getResources()
+ .getString(
+
"OpenKlem.executing-process"));
+ // monitor.allowCancellationRequests();
+ reportNothingToUndoYet(context);
+ try {
+
cutRasterCommand(componentsWithActions);
+ } catch (final Exception ex) {
+ Logger.error(getName(), ex);
+ }
+ }
+ }, context.getWorkbenchContext(),
+ new
TaskMonitorManager()).actionPerformed(null);
+ } catch (final Exception ex) {
+ ErrorDialog.show(super.getInitialDialog(),
+ PluginUtils.plugInName, ex.toString(),
+ StringUtil.stackTrace(ex));
+ }
+
//get input raster names
- String rasterSelected1 =
GUIUtils.getStringValue(componentsWithActions.getComponent("00",
GUIUtils.INPUT, 1));
- String rasterSelected2 =
GUIUtils.getStringValue(componentsWithActions.getComponent("01",
GUIUtils.INPUT, 1));
+ /* final String rasterSelected1 = GUIUtils
+
.getStringValue(componentsWithActions.getComponent(
+ "00", GUIUtils.INPUT, 1));
+ final String rasterSelected2 = GUIUtils
+
.getStringValue(componentsWithActions.getComponent(
+ "01", GUIUtils.INPUT, 1));
- //get output raster name
- String outRasterName =
GUIUtils.getStringValue(componentsWithActions.getComponent("00",
GUIUtils.OUTPUT, 1));
+ //get output raster name
+ final String outRasterName = GUIUtils
+
.getStringValue(componentsWithActions.getComponent(
+ "00", GUIUtils.OUTPUT, 1));
- //check input values
- GUIUtils.checkStringValue(rasterSelected1, RASTER_IN);
- GUIUtils.checkStringValue(rasterSelected2, RASTER_MASK);
+ //check input values
+ GUIUtils.checkStringValue(rasterSelected1,
RASTER_IN);
+ GUIUtils.checkStringValue(rasterSelected2,
RASTER_MASK);
- //check output values
- GUIUtils.checkFileValue(outRasterName, RASTER_OUT);
+ //check output values
+ GUIUtils.checkFileValue(outRasterName,
RASTER_OUT);
- //get input raster as rasterImageLayer from string
- RasterImageLayer inputRasterSelected =
PluginUtils.getRasterImageLayerSelected((CustomComboBox.RasterComboBox)
componentsWithActions.getComponent("00", GUIUtils.INPUT, 1));
- DoubleBasicGrid inputGrid =
RasterUtils.getDoubleBasicGrid(inputRasterSelected);
+ //get input raster as rasterImageLayer from
string
+ final RasterImageLayer inputRasterSelected =
PluginUtils
+
.getRasterImageLayerSelected((CustomComboBox.RasterComboBox)
componentsWithActions
+ .getComponent("00",
GUIUtils.INPUT, 1));
+ final DoubleBasicGrid inputGrid = RasterUtils
+
.getDoubleBasicGrid(inputRasterSelected);
- //get mask raster as rasterImageLayer from string
- RasterImageLayer maskRasterSelected =
PluginUtils.getRasterImageLayerSelected((CustomComboBox.RasterComboBox)
componentsWithActions.getComponent("01", GUIUtils.INPUT, 1));
- DoubleBasicGrid clipperGrid =
RasterUtils.getDoubleBasicGrid(maskRasterSelected);
+ //get mask raster as rasterImageLayer from
string
+ final RasterImageLayer maskRasterSelected =
PluginUtils
+
.getRasterImageLayerSelected((CustomComboBox.RasterComboBox)
componentsWithActions
+ .getComponent("01",
GUIUtils.INPUT, 1));
+ final DoubleBasicGrid clipperGrid = RasterUtils
+ .getDoubleBasicGrid(maskRasterSelected);
- //Clip raster
- DoubleBasicGrid clippedRaster =
RasterClipper.clip(inputGrid, clipperGrid);
+ //Clip raster
+ final DoubleBasicGrid clippedRaster =
RasterClipper.clip(
+ inputGrid, clipperGrid);
- //Create the output file and display on OJ
- //Save grid as tiff
- RasterUtils.saveOutputRasterAsTiff(clippedRaster, new
File(outRasterName));
- //Display raster on OJ from file
- RasterUtils.displayRasterFileOnOJ(
- context.getWorkbenchContext(),
- new File(outRasterName),
- null);
+ //Create the output file and display on OJ
+ //Save grid as tiff
+
RasterUtils.saveOutputRasterAsTiff(clippedRaster, new File(
+ outRasterName));
+ //Display raster on OJ from file
+ RasterUtils.displayRasterFileOnOJ(context
+ .getWorkbenchContext(), new
File(outRasterName),
+ null);
- JOptionPane.showMessageDialog(super.getInitialDialog(),
-
PluginUtils.getResources().getString("SetWorkspacePlugin.Done.message"),
PluginUtils.plugInName, JOptionPane.INFORMATION_MESSAGE);
+ JOptionPane.showMessageDialog(
+ super.getInitialDialog(),
+ PluginUtils.getResources().getString(
+
"SetWorkspacePlugin.Done.message"),
+ PluginUtils.plugInName,
+ JOptionPane.INFORMATION_MESSAGE);*/
- } catch (Exception ex) {
- ErrorDialog.show(
- super.getInitialDialog(),
- PluginUtils.plugInName,
- ex.toString(),
+ } catch (final Exception ex) {
+ ErrorDialog.show(super.getInitialDialog(),
+ PluginUtils.plugInName, ex.toString(),
StringUtil.stackTrace(ex));
}
}
@@ -137,21 +267,25 @@
};
- return this.mainPanel;
+ return mainPanel;
}
@Override
public String toString() {
- return
PluginUtils.getResources().getString("CutRasterPlugIn.PlugInName.label");
+ return PluginUtils.getResources().getString(
+ "CutRasterPlugIn.PlugInName.label");
}
private final PlugInContext context;
private MainPanel mainPanel;
-// private RasterImageLayer[] ar_rasterImageLayers;
- private final String RASTER_IN =
PluginUtils.getResources().getString("KlemGUI.InputRaster.label");
- private final String RASTER_MASK =
PluginUtils.getResources().getString("CutRasterPlugIn.InputData.MaskRaster");
- private final String RASTER_OUT =
PluginUtils.getResources().getString("CutRasterPlugIn.OutputData.OutputRaster");
+ // private RasterImageLayer[] ar_rasterImageLayers;
+ private final String RASTER_IN = PluginUtils.getResources().getString(
+ "KlemGUI.InputRaster.label");
+ private final String RASTER_MASK = PluginUtils.getResources().getString(
+ "CutRasterPlugIn.InputData.MaskRaster");
+ private final String RASTER_OUT = PluginUtils.getResources().getString(
+ "CutRasterPlugIn.OutputData.OutputRaster");
private final LayerablesList layerablesList;
Modified:
plug-ins/OpenKLEM/OpenKLEMOpenJUMP/trunk/src/com/geomaticaeambiente/klemgui/plugin/rastertools/RasterizeVectorLayerPlugIn.java
===================================================================
---
plug-ins/OpenKLEM/OpenKLEMOpenJUMP/trunk/src/com/geomaticaeambiente/klemgui/plugin/rastertools/RasterizeVectorLayerPlugIn.java
2019-01-19 10:32:18 UTC (rev 6105)
+++
plug-ins/OpenKLEM/OpenKLEMOpenJUMP/trunk/src/com/geomaticaeambiente/klemgui/plugin/rastertools/RasterizeVectorLayerPlugIn.java
2019-01-19 11:03:24 UTC (rev 6106)
@@ -1,10 +1,26 @@
package com.geomaticaeambiente.klemgui.plugin.rastertools;
+import java.awt.Cursor;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+
+import org.openjump.core.rasterimage.RasterImageLayer;
+
import com.geomaticaeambiente.klemgui.exceptions.WarningException;
-import com.geomaticaeambiente.klemgui.utils.PluginUtils;
import com.geomaticaeambiente.klemgui.ui.CustomComboBox;
-import com.geomaticaeambiente.openjump.klem.grid.DoubleBasicGrid;
-import com.geomaticaeambiente.openjump.klem.rastertools.Rasterizer;
import com.geomaticaeambiente.klemgui.ui.GUIUtils;
import com.geomaticaeambiente.klemgui.ui.InitialDialog;
import com.geomaticaeambiente.klemgui.ui.LayerablesList;
@@ -12,8 +28,11 @@
import com.geomaticaeambiente.klemgui.utils.AbstractInputKlemPlugin;
import com.geomaticaeambiente.klemgui.utils.ActionObject;
import com.geomaticaeambiente.klemgui.utils.ComponentsTreeMap;
+import com.geomaticaeambiente.klemgui.utils.InitialData;
+import com.geomaticaeambiente.klemgui.utils.PluginUtils;
import com.geomaticaeambiente.klemgui.utils.RasterUtils;
-import com.geomaticaeambiente.klemgui.utils.InitialData;
+import com.geomaticaeambiente.openjump.klem.grid.DoubleBasicGrid;
+import com.geomaticaeambiente.openjump.klem.rastertools.Rasterizer;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jump.feature.Feature;
@@ -22,22 +41,6 @@
import com.vividsolutions.jump.workbench.model.Layer;
import com.vividsolutions.jump.workbench.plugin.PlugInContext;
import com.vividsolutions.jump.workbench.ui.ErrorDialog;
-import java.awt.Cursor;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.io.File;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import javax.swing.JButton;
-import javax.swing.JCheckBox;
-import javax.swing.JComboBox;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JTextField;
-import org.openjump.core.rasterimage.RasterImageLayer;
/**
*
@@ -45,10 +48,11 @@
*/
public class RasterizeVectorLayerPlugIn extends AbstractInputKlemPlugin {
- public RasterizeVectorLayerPlugIn(PlugInContext context, InitialDialog
initialDialog, LayerablesList rasterLayersList) {
+ public RasterizeVectorLayerPlugIn(PlugInContext context,
+ InitialDialog initialDialog, LayerablesList rasterLayersList) {
super(context, initialDialog);
this.context = context;
- this.layerablesList = rasterLayersList;
+ layerablesList = rasterLayersList;
}
@Override
@@ -56,28 +60,39 @@
layers = PluginUtils.getLayers(layerablesList.getLayerables());
- String[] attributes = new String[0];
+ final String[] attributes = new String[0];
- InitialData initialData = new InitialData();
+ final InitialData initialData = new InitialData();
//input data
-
initialData.setParam_Label_TextBox(GUIUtils.setGUILabel(VECTOR_LAYER_LABEL),
layers, GUIUtils.INPUT);
-
initialData.setParam_Label_TextBox(GUIUtils.setGUILabel(ATTRIBUTE_LABEL),
attributes, GUIUtils.INPUT);
- initialData.setParam_Label_TextBox(GUIUtils.setGUILabel(CELL_LABEL),
"10", GUIUtils.INPUT);
+ initialData.setParam_Label_TextBox(
+ GUIUtils.setGUILabel(VECTOR_LAYER_LABEL), layers,
+ GUIUtils.INPUT);
+ initialData.setParam_Label_TextBox(
+ GUIUtils.setGUILabel(ATTRIBUTE_LABEL), attributes,
+ GUIUtils.INPUT);
+ initialData.setParam_Label_TextBox(GUIUtils.setGUILabel(CELL_LABEL),
+ "10", GUIUtils.INPUT);
// Snapping
- initialData.setParam_Action(new ActionObject(false,
PluginUtils.getResources().getString("RasterizeVectorLayerPlugIn.SnapRasterCheckbox.text")),
GUIUtils.INPUT);
-
-// initialData.setInputParam_RadioButton(
-// new boolean[]{true,false},
-// new ActionObject(),
-// new
String[]{bundle.getString("RasterizeVectorLayerPlugIn.OnCellRadioButton.text"),
-//
bundle.getString("RasterizeVectorLayerPlugIn.OnRasterRadioButton.text")});
- initialData.setParam_Label_TextBox(SNAP_RASTER_LABEL,
PluginUtils.getRasterImageLayers(layerablesList.getLayerables()),
GUIUtils.INPUT);
-// initialData.setInputParam_CheckBox(false, new ActionObject(),
bundle.getString("RasterizeVectorLayerPlugIn.SameRasterExtentCheckBox.text"));
-
+ initialData.setParam_Action(
+ new ActionObject(false, PluginUtils.getResources().getString(
+ "RasterizeVectorLayerPlugIn.SnapRasterCheckbox.text")),
+ GUIUtils.INPUT);
+ // initialData.setInputParam_RadioButton(
+ // new boolean[]{true,false},
+ // new ActionObject(),
+ // new
String[]{bundle.getString("RasterizeVectorLayerPlugIn.OnCellRadioButton.text"),
+ //
bundle.getString("RasterizeVectorLayerPlugIn.OnRasterRadioButton.text")});
+ initialData.setParam_Label_TextBox(SNAP_RASTER_LABEL, PluginUtils
+ .getRasterImageLayers(layerablesList.getLayerables()),
+ GUIUtils.INPUT);
+ // initialData.setInputParam_CheckBox(false, new
ActionObject(),
bundle.getString("RasterizeVectorLayerPlugIn.SameRasterExtentCheckBox.text"));
+
//output information
-
initialData.setParam_Label_TextBox_Button(GUIUtils.getOutputRasterLabel(), "",
new ActionObject(""), GUIUtils.OUTPUT);
+ initialData.setParam_Label_TextBox_Button(
+ GUIUtils.getOutputRasterLabel(), "", new ActionObject(""),
+ GUIUtils.OUTPUT);
// Visibility
return initialData;
@@ -84,17 +99,20 @@
}
@Override
- public ComponentsTreeMap setComponentsActions(ComponentsTreeMap
personalTreeMap) {
+ public ComponentsTreeMap setComponentsActions(
+ ComponentsTreeMap personalTreeMap) {
- final CustomComboBox.LayerComboBox jComboBox_layer =
(CustomComboBox.LayerComboBox) personalTreeMap.getComponent("00",
GUIUtils.INPUT, 1);
+ final CustomComboBox.LayerComboBox jComboBox_layer =
(CustomComboBox.LayerComboBox) personalTreeMap
+ .getComponent("00", GUIUtils.INPUT, 1);
- final JComboBox jComboBox_attribute = (JComboBox)
personalTreeMap.getComponent("01", GUIUtils.INPUT, 1);
+ final JComboBox jComboBox_attribute = (JComboBox) personalTreeMap
+ .getComponent("01", GUIUtils.INPUT, 1);
jComboBox_attribute.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
-// listLayerAttribute(jComboBox_attribute, jComboBox_layer);
-// System.out.println("hello");
+ // listLayerAttribute(jComboBox_attribute,
jComboBox_layer);
+ // System.out.println("hello");
}
});
@@ -103,161 +121,263 @@
@Override
public void actionPerformed(ActionEvent e) {
- GUIUtils.listLayerAttribute(context, jComboBox_attribute,
jComboBox_layer);
+ GUIUtils.listLayerAttribute(context, jComboBox_attribute,
+ jComboBox_layer);
}
});
// IN STAND-BY
//input data for snap to raster > there aren't in this version of
rasterize
-// final JComboBox rasterComboBox = (JComboBox)
personalTreeMap.getComponent("Input5", 1);
-// final JLabel rasterLabel = (JLabel)
personalTreeMap.getComponent("Input5", 0);
-//
- final JCheckBox jCheckBox_Extent = (JCheckBox)
personalTreeMap.getComponent("03", GUIUtils.INPUT, 0);
- final JComboBox jComboBox_SnapRaster = (JComboBox)
personalTreeMap.getComponent("04", GUIUtils.INPUT, 1);
+ // final JComboBox rasterComboBox = (JComboBox)
personalTreeMap.getComponent("Input5", 1);
+ // final JLabel rasterLabel = (JLabel)
personalTreeMap.getComponent("Input5", 0);
+ //
+ final JCheckBox jCheckBox_Extent = (JCheckBox) personalTreeMap
+ .getComponent("03", GUIUtils.INPUT, 0);
+ final JComboBox jComboBox_SnapRaster = (JComboBox) personalTreeMap
+ .getComponent("04", GUIUtils.INPUT, 1);
jComboBox_SnapRaster.setEnabled(false);
-
- jCheckBox_Extent.addActionListener(new ActionListener(){
+
+ jCheckBox_Extent.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
jComboBox_SnapRaster.setEnabled(jCheckBox_Extent.isSelected());
}
});
-
-
-// final JRadioButton rbOnCell = (JRadioButton)
personalTreeMap.getComponent("Input4", 0);
-// rbOnCell.setEnabled(false);
-//
-// final JRadioButton rbOnRaster = (JRadioButton)
personalTreeMap.getComponent("Input4", 1);
-// rbOnRaster.setEnabled(false);
-// rbOnRaster.addActionListener(new ActionListener() {
-//
-// @Override
-// public void actionPerformed(ActionEvent e) {
-// rasterLabel.setEnabled(rbOnRaster.isSelected());
-// rasterComboBox.setEnabled(rbOnRaster.isSelected());
-// }
-// });
-//
-// final JCheckBox jCheckBox = (JCheckBox)
personalTreeMap.getComponent("Input3", 0);
-// jCheckBox.addActionListener(new ActionListener() {
-//
-// @Override
-// public void actionPerformed(ActionEvent e) {
-// rbOnCell.setEnabled(jCheckBox.isSelected());
-// rbOnRaster.setEnabled(jCheckBox.isSelected());
-// checkExtent.setEnabled(jCheckBox.isSelected());
-// }
-// });
- final JTextField outputTextField = (JTextField)
personalTreeMap.getComponent("00", GUIUtils.OUTPUT, 1);
- JButton outputButton = (JButton) personalTreeMap.getComponent("00",
GUIUtils.OUTPUT, 2);
+
+ // final JRadioButton rbOnCell = (JRadioButton)
personalTreeMap.getComponent("Input4", 0);
+ // rbOnCell.setEnabled(false);
+ //
+ // final JRadioButton rbOnRaster = (JRadioButton)
personalTreeMap.getComponent("Input4", 1);
+ // rbOnRaster.setEnabled(false);
+ // rbOnRaster.addActionListener(new ActionListener() {
+ //
+ // @Override
+ // public void actionPerformed(ActionEvent e) {
+ // rasterLabel.setEnabled(rbOnRaster.isSelected());
+ // rasterComboBox.setEnabled(rbOnRaster.isSelected());
+ // }
+ // });
+ //
+ // final JCheckBox jCheckBox = (JCheckBox)
personalTreeMap.getComponent("Input3", 0);
+ // jCheckBox.addActionListener(new ActionListener() {
+ //
+ // @Override
+ // public void actionPerformed(ActionEvent e) {
+ // rbOnCell.setEnabled(jCheckBox.isSelected());
+ // rbOnRaster.setEnabled(jCheckBox.isSelected());
+ // checkExtent.setEnabled(jCheckBox.isSelected());
+ // }
+ // });
+ final JTextField outputTextField = (JTextField) personalTreeMap
+ .getComponent("00", GUIUtils.OUTPUT, 1);
+ final JButton outputButton = (JButton) personalTreeMap.getComponent(
+ "00", GUIUtils.OUTPUT, 2);
outputButton.setIcon(PluginUtils.getFolderIcon());
-
outputButton.addActionListener(GUIUtils.setSaveRasterTif(outputTextField));
+ outputButton.addActionListener(GUIUtils
+ .setSaveRasterTif(outputTextField));
return personalTreeMap;
}
+ public void rasterizeCommand(final ComponentsTreeMap componentsWithActions)
+ throws Exception {
+ final String layerSelected = GUIUtils
+ .getStringValue(componentsWithActions.getComponent("00",
+ GUIUtils.INPUT, 1));
+ final String attributeSelected = GUIUtils
+ .getStringValue(componentsWithActions.getComponent("01",
+ GUIUtils.INPUT, 1));
+ final double cellDimension = GUIUtils
+ .getDoubleValue(componentsWithActions.getComponent("02",
+ GUIUtils.INPUT, 1));
+
+ // Snapping
+ Envelope clipEnvelope = null;
+ final boolean snap = GUIUtils.getBooleanValue(componentsWithActions
+ .getComponent("03", GUIUtils.INPUT, 0));
+ String snapRasterName = null;
+ if (snap) {
+ snapRasterName = GUIUtils.getStringValue(componentsWithActions
+ .getComponent("04", GUIUtils.INPUT, 1));
+ }
+
+ //get output raster name
+ final String outRasterName = GUIUtils
+ .getStringValue(componentsWithActions.getComponent("00",
+ GUIUtils.OUTPUT, 1));
+
+ // Check input and output values
+ checksValues(layerSelected, attributeSelected, snapRasterName,
+ outRasterName);
+
+ if (snap) {
+ final RasterImageLayer ril = PluginUtils
+
.getRasterImageLayerSelected((CustomComboBox.RasterComboBox)
componentsWithActions
+ .getComponent("04", GUIUtils.INPUT, 1));
+ clipEnvelope = ril.getActualImageEnvelope();
+ }
+
+ //from name to Layer
+ final Layer layer = PluginUtils
+ .getLayerSelected((CustomComboBox.LayerComboBox)
componentsWithActions
+ .getComponent("00", GUIUtils.INPUT, 1));
+
+ // Get selected features, or all features if none selected, or return
error if none present
+ Collection<Feature> features = context.getLayerViewPanel()
+ .getSelectionManager().getFeatureSelection()
+ .getFeaturesWithSelectedItems(layer);
+
+ if (features.isEmpty()) {
+ features = layer.getFeatureCollectionWrapper().getFeatures();
+ }
+
+ final Feature[] ar_features = new Feature[features.size()];
+ final Iterator<Feature> iter = features.iterator();
+ int count = 0;
+ while (iter.hasNext()) {
+ ar_features[count] = iter.next();
+ count++;
+ }
+
+ //get information about attribute selected
+ final FeatureSchema featureSchema = layer.getFeatureCollectionWrapper()
+ .getFeatureSchema();
+ final int fieldsCount = featureSchema
+ .getAttributeIndex(attributeSelected);
+
+ final Geometry[] ar_geoms = new Geometry[ar_features.length];
+ final double[] ar_attributes = new double[ar_features.length];
+
+ for (int f = 0; f < ar_features.length; f++) {
+ ar_geoms[f] = ar_features[f].getGeometry();
+ ar_attributes[f] = Double.parseDouble(ar_features[f]
+ .getString(fieldsCount));
+ }
+
+ // Rasterize
+ final DoubleBasicGrid rasterized = Rasterizer.rasterize(ar_geoms,
+ ar_attributes, clipEnvelope, cellDimension);
+
+ //Create the output file and display on OJ
+ //Save grid as tiff
+ RasterUtils.saveOutputRasterAsTiff(rasterized, new
File(outRasterName));
+ //Display raster on OJ from file
+ RasterUtils.displayRasterFileOnOJ(context.getWorkbenchContext(),
+ new File(outRasterName), null);
+
+ JOptionPane.showMessageDialog(super.getInitialDialog(), PluginUtils
+ .getResources().getString("SetWorkspacePlugin.Done.message"),
+ PluginUtils.plugInName, JOptionPane.INFORMATION_MESSAGE);
+ }
+
@Override
public JPanel buildPluginPanel(final ComponentsTreeMap
componentsWithActions) {
- if(this.mainPanel != null) {
- return this.mainPanel;
+ if (mainPanel != null) {
+ return mainPanel;
}
- this.mainPanel = new MainPanel(super.getInitialDialog(),
componentsWithActions, false, false, true,
-
PluginUtils.getResources().getString("MainPanel.ExecuteButton.text"),
layerablesList) {
+ mainPanel = new MainPanel(super.getInitialDialog(),
+ componentsWithActions, false, false, true, PluginUtils
+ .getResources().getString(
+ "MainPanel.ExecuteButton.text"),
layerablesList) {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
@Override
- @SuppressWarnings("empty-statement")
public void rightButton() {
+
try {
+ rasterizeCommand(componentsWithActions);
+ /* super.getInitialDialog().setCursor(new
Cursor(Cursor.WAIT_CURSOR));
+
+ //get input information
+ String layerSelected =
GUIUtils.getStringValue(componentsWithActions.getComponent("00",
GUIUtils.INPUT, 1));
+ String attributeSelected =
GUIUtils.getStringValue(componentsWithActions.getComponent("01",
GUIUtils.INPUT, 1));
+ double cellDimension =
GUIUtils.getDoubleValue(componentsWithActions.getComponent("02",
GUIUtils.INPUT, 1));
- super.getInitialDialog().setCursor(new
Cursor(Cursor.WAIT_CURSOR));
-
- //get input information
- String layerSelected =
GUIUtils.getStringValue(componentsWithActions.getComponent("00",
GUIUtils.INPUT, 1));
- String attributeSelected =
GUIUtils.getStringValue(componentsWithActions.getComponent("01",
GUIUtils.INPUT, 1));
- double cellDimension =
GUIUtils.getDoubleValue(componentsWithActions.getComponent("02",
GUIUtils.INPUT, 1));
+ // Snapping
+ Envelope clipEnvelope = null;
+ boolean snap =
GUIUtils.getBooleanValue(componentsWithActions.getComponent("03",
GUIUtils.INPUT, 0));
+ String snapRasterName = null;
+ if(snap) {
+ snapRasterName =
GUIUtils.getStringValue(componentsWithActions.getComponent("04",
GUIUtils.INPUT, 1));
+ }
+
+ //get output raster name
+ String outRasterName =
GUIUtils.getStringValue(componentsWithActions.getComponent("00",
GUIUtils.OUTPUT, 1));
+
+ // Check input and output values
+ checksValues(layerSelected, attributeSelected,
snapRasterName, outRasterName);
- // Snapping
- Envelope clipEnvelope = null;
- boolean snap =
GUIUtils.getBooleanValue(componentsWithActions.getComponent("03",
GUIUtils.INPUT, 0));
- String snapRasterName = null;
- if(snap) {
- snapRasterName =
GUIUtils.getStringValue(componentsWithActions.getComponent("04",
GUIUtils.INPUT, 1));
- }
-
- //get output raster name
- String outRasterName =
GUIUtils.getStringValue(componentsWithActions.getComponent("00",
GUIUtils.OUTPUT, 1));
-
- // Check input and output values
- checksValues(layerSelected, attributeSelected,
snapRasterName, outRasterName);
+ if(snap) {
+ RasterImageLayer ril =
PluginUtils.getRasterImageLayerSelected((CustomComboBox.RasterComboBox)
componentsWithActions.getComponent("04", GUIUtils.INPUT, 1));
+ clipEnvelope = ril.getActualImageEnvelope();
+ }
+
+ //from name to Layer
+ Layer layer =
PluginUtils.getLayerSelected((CustomComboBox.LayerComboBox)
componentsWithActions.getComponent("00", GUIUtils.INPUT, 1));
- if(snap) {
- RasterImageLayer ril =
PluginUtils.getRasterImageLayerSelected((CustomComboBox.RasterComboBox)
componentsWithActions.getComponent("04", GUIUtils.INPUT, 1));
- clipEnvelope = ril.getActualImageEnvelope();
- }
-
- //from name to Layer
- Layer layer =
PluginUtils.getLayerSelected((CustomComboBox.LayerComboBox)
componentsWithActions.getComponent("00", GUIUtils.INPUT, 1));
+ // Get selected features, or all features if none
selected, or return error if none present
+ Collection<Feature> features =
context.getLayerViewPanel().getSelectionManager().getFeatureSelection().getFeaturesWithSelectedItems(layer);
- // Get selected features, or all features if none
selected, or return error if none present
- Collection features =
context.getLayerViewPanel().getSelectionManager().getFeatureSelection().getFeaturesWithSelectedItems(layer);
+ if (features.isEmpty()) {
+ features =
layer.getFeatureCollectionWrapper().getFeatures();
+ }
- if (features.isEmpty()) {
- features =
layer.getFeatureCollectionWrapper().getFeatures();
- }
+ Feature[] ar_features = new
Feature[features.size()];
+ Iterator<Feature> iter = features.iterator();
+ int count = 0;
+ while (iter.hasNext()) {
+ ar_features[count] = (Feature) iter.next();
+ count++;
+ }
- Feature[] ar_features = new Feature[features.size()];
- Iterator iter = features.iterator();
- int count = 0;
- while (iter.hasNext()) {
- ar_features[count] = (Feature) iter.next();
- count++;
- }
+ //get information about attribute selected
+ FeatureSchema featureSchema =
layer.getFeatureCollectionWrapper().getFeatureSchema();
+ int fieldsCount =
featureSchema.getAttributeIndex(attributeSelected);
- //get information about attribute selected
- FeatureSchema featureSchema =
layer.getFeatureCollectionWrapper().getFeatureSchema();
- int fieldsCount =
featureSchema.getAttributeIndex(attributeSelected);
+ Geometry[] ar_geoms = new
Geometry[ar_features.length];
+ double[] ar_attributes = new
double[ar_features.length];
+
+ for(int f=0; f<ar_features.length; f++) {
+ ar_geoms[f] = ar_features[f].getGeometry();
+ ar_attributes[f] =
Double.parseDouble(ar_features[f].getString(fieldsCount));
+ }
+
+ // Rasterize
+ DoubleBasicGrid rasterized = Rasterizer.rasterize(
+ ar_geoms, ar_attributes, clipEnvelope,
cellDimension);
- Geometry[] ar_geoms = new Geometry[ar_features.length];
- double[] ar_attributes = new double[ar_features.length];
-
- for(int f=0; f<ar_features.length; f++) {
- ar_geoms[f] = ar_features[f].getGeometry();
- ar_attributes[f] =
Double.parseDouble(ar_features[f].getString(fieldsCount));
- }
-
- // Rasterize
- DoubleBasicGrid rasterized = Rasterizer.rasterize(
- ar_geoms, ar_attributes, clipEnvelope,
cellDimension);
+ //Create the output file and display on OJ
+ //Save grid as tiff
+ RasterUtils.saveOutputRasterAsTiff(rasterized, new
File(outRasterName));
+ //Display raster on OJ from file
+ RasterUtils.displayRasterFileOnOJ(
+ context.getWorkbenchContext(),
+ new File(outRasterName),
+ null);
- //Create the output file and display on OJ
- //Save grid as tiff
- RasterUtils.saveOutputRasterAsTiff(rasterized, new
File(outRasterName));
- //Display raster on OJ from file
- RasterUtils.displayRasterFileOnOJ(
- context.getWorkbenchContext(),
- new File(outRasterName),
- null);
-
- JOptionPane.showMessageDialog(super.getInitialDialog(),
-
PluginUtils.getResources().getString("SetWorkspacePlugin.Done.message"),
PluginUtils.plugInName, JOptionPane.INFORMATION_MESSAGE);
-
- } catch (OutOfMemoryError out) {
- ErrorDialog.show(
- super.getInitialDialog(),
- PluginUtils.plugInName,
- out.toString(),
+
JOptionPane.showMessageDialog(super.getInitialDialog(),
+
PluginUtils.getResources().getString("SetWorkspacePlugin.Done.message"),
PluginUtils.plugInName, JOptionPane.INFORMATION_MESSAGE);
+ */
+ } catch (final OutOfMemoryError out) {
+ ErrorDialog.show(super.getInitialDialog(),
+ PluginUtils.plugInName, out.toString(),
StringUtil.stackTrace(out));
- } catch (WarningException ex) {
- JOptionPane.showMessageDialog(super.getInitialDialog(),
ex.getMessage(), PluginUtils.plugInName, JOptionPane.WARNING_MESSAGE);
- } catch (Exception ex) {
- ErrorDialog.show(
- super.getInitialDialog(),
- PluginUtils.plugInName,
- ex.toString(),
+ } catch (final WarningException ex) {
+ JOptionPane.showMessageDialog(super.getInitialDialog(),
+ ex.getMessage(), PluginUtils.plugInName,
+ JOptionPane.WARNING_MESSAGE);
+ } catch (final Exception ex) {
+ ErrorDialog.show(super.getInitialDialog(),
+ PluginUtils.plugInName, ex.toString(),
StringUtil.stackTrace(ex));
} finally {
- super.getInitialDialog().setCursor(new
Cursor(Cursor.DEFAULT_CURSOR));
+ super.getInitialDialog().setCursor(
+ new Cursor(Cursor.DEFAULT_CURSOR));
}
}
@@ -272,20 +392,22 @@
}
};
- return this.mainPanel;
+ return mainPanel;
}
@Override
public String toString() {
- return
PluginUtils.getResources().getString("RasterizeVectorLayerPlugin.PlugInName.label");
+ return PluginUtils.getResources().getString(
+ "RasterizeVectorLayerPlugin.PlugInName.label");
}
- private void checksValues(String vectorLayer, String attributes, String
snapRaster, String outRaster) throws IOException, Exception {
+ private void checksValues(String vectorLayer, String attributes,
+ String snapRaster, String outRaster) throws IOException, Exception
{
GUIUtils.checkStringValue(vectorLayer, VECTOR_LAYER_LABEL);
GUIUtils.checkStringValue(attributes, ATTRIBUTE_LABEL);
- if(snapRaster != null) {
+ if (snapRaster != null) {
GUIUtils.checkStringValue(snapRaster, SNAP_RASTER_LABEL);
}
GUIUtils.checkFileValue(outRaster, GUIUtils.getOutputRasterString());
@@ -297,11 +419,15 @@
private Layer[] layers;
private final Map<Integer, Integer> attribHt = new HashMap<Integer,
Integer>();
- private final String VECTOR_LAYER_LABEL =
PluginUtils.getResources().getString("RasterizeCevtorLayerPlugin.ComboBox1Label.text");
- private final String ATTRIBUTE_LABEL =
PluginUtils.getResources().getString("RasterizeCevtorLayerPlugin.ComboBox2Label.text");
- private final String CELL_LABEL =
PluginUtils.getResources().getString("RasterizeVectorLayerPlugIn.CellDimensionLabel.text");
- private final String SNAP_RASTER_LABEL =
GUIUtils.setGUILabel(PluginUtils.getResources().getString("KlemGUI.Raster.label"));
-
+ private final String VECTOR_LAYER_LABEL = PluginUtils.getResources()
+ .getString("RasterizeCevtorLayerPlugin.ComboBox1Label.text");
+ private final String ATTRIBUTE_LABEL = PluginUtils.getResources()
+ .getString("RasterizeCevtorLayerPlugin.ComboBox2Label.text");
+ private final String CELL_LABEL = PluginUtils.getResources().getString(
+ "RasterizeVectorLayerPlugIn.CellDimensionLabel.text");
+ private final String SNAP_RASTER_LABEL = GUIUtils.setGUILabel(PluginUtils
+ .getResources().getString("KlemGUI.Raster.label"));
+
private final LayerablesList layerablesList;
}
Modified:
plug-ins/OpenKLEM/OpenKLEMOpenJUMP/trunk/src/com/geomaticaeambiente/klemgui/plugin/rastertools/ReclassRasterPlugin.java
===================================================================
---
plug-ins/OpenKLEM/OpenKLEMOpenJUMP/trunk/src/com/geomaticaeambiente/klemgui/plugin/rastertools/ReclassRasterPlugin.java
2019-01-19 10:32:18 UTC (rev 6105)
+++
plug-ins/OpenKLEM/OpenKLEMOpenJUMP/trunk/src/com/geomaticaeambiente/klemgui/plugin/rastertools/ReclassRasterPlugin.java
2019-01-19 11:03:24 UTC (rev 6106)
@@ -1,27 +1,5 @@
package com.geomaticaeambiente.klemgui.plugin.rastertools;
-import com.geomaticaeambiente.klemgui.utils.PluginUtils;
-import com.geomaticaeambiente.klemgui.ui.CustomComboBox;
-import com.geomaticaeambiente.klemgui.ui.CustomComboBox.RasterComboBox;
-import com.geomaticaeambiente.openjump.klem.grid.DoubleBasicGrid;
-import com.geomaticaeambiente.klemgui.ui.GUIUtils;
-import com.geomaticaeambiente.klemgui.ui.InitialDialog;
-import com.geomaticaeambiente.klemgui.utils.ActionObject;
-import com.geomaticaeambiente.klemgui.utils.ComponentsTreeMap;
-import com.geomaticaeambiente.klemgui.ui.MainPanel;
-import com.geomaticaeambiente.klemgui.ui.PersonalTableComponents;
-import com.geomaticaeambiente.klemgui.ui.LayerablesList;
-import com.geomaticaeambiente.klemgui.ui.YourTableCellRenderer1;
-import com.geomaticaeambiente.klemgui.utils.AbstractInputKlemPlugin;
-import com.geomaticaeambiente.klemgui.utils.RasterUtils;
-import com.geomaticaeambiente.klemgui.utils.PersonalTable;
-import com.geomaticaeambiente.klemgui.utils.InitialData;
-import com.geomaticaeambiente.openjump.klem.rastertools.RasterReclassifier;
-import com.geomaticaeambiente.openjump.klem.rastertools.ReclassTuple;
-import com.vividsolutions.jump.util.StringUtil;
-import com.vividsolutions.jump.workbench.plugin.PlugInContext;
-import com.vividsolutions.jump.workbench.ui.ErrorDialog;
-
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@@ -41,6 +19,33 @@
import org.openjump.core.rasterimage.RasterImageLayer;
+import com.geomaticaeambiente.klemgui.ui.CustomComboBox;
+import com.geomaticaeambiente.klemgui.ui.CustomComboBox.RasterComboBox;
+import com.geomaticaeambiente.klemgui.ui.GUIUtils;
+import com.geomaticaeambiente.klemgui.ui.InitialDialog;
+import com.geomaticaeambiente.klemgui.ui.LayerablesList;
+import com.geomaticaeambiente.klemgui.ui.MainPanel;
+import com.geomaticaeambiente.klemgui.ui.PersonalTableComponents;
+import com.geomaticaeambiente.klemgui.ui.YourTableCellRenderer1;
+import com.geomaticaeambiente.klemgui.utils.AbstractInputKlemPlugin;
+import com.geomaticaeambiente.klemgui.utils.ActionObject;
+import com.geomaticaeambiente.klemgui.utils.ComponentsTreeMap;
+import com.geomaticaeambiente.klemgui.utils.InitialData;
+import com.geomaticaeambiente.klemgui.utils.PersonalTable;
+import com.geomaticaeambiente.klemgui.utils.PluginUtils;
+import com.geomaticaeambiente.klemgui.utils.RasterUtils;
+import com.geomaticaeambiente.openjump.klem.grid.DoubleBasicGrid;
+import com.geomaticaeambiente.openjump.klem.rastertools.RasterReclassifier;
+import com.geomaticaeambiente.openjump.klem.rastertools.ReclassTuple;
+import com.vividsolutions.jump.task.TaskMonitor;
+import com.vividsolutions.jump.util.StringUtil;
+import com.vividsolutions.jump.workbench.Logger;
+import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
+import com.vividsolutions.jump.workbench.plugin.PlugInContext;
+import com.vividsolutions.jump.workbench.plugin.ThreadedBasePlugIn;
+import com.vividsolutions.jump.workbench.ui.ErrorDialog;
+import com.vividsolutions.jump.workbench.ui.task.TaskMonitorManager;
+
/**
*
* @author Geomatica
@@ -47,7 +52,8 @@
*/
public class ReclassRasterPlugin extends AbstractInputKlemPlugin {
- public ReclassRasterPlugin(PlugInContext context, InitialDialog
initialDialog, LayerablesList layerablesList) {
+ public ReclassRasterPlugin(PlugInContext context,
+ InitialDialog initialDialog, LayerablesList layerablesList) {
super(context, initialDialog);
this.context = context;
this.layerablesList = layerablesList;
@@ -56,37 +62,44 @@
@Override
public InitialData setInitialData() {
-// rasterImageLayers = PluginUtils.getRasterImageLayers(context);
+ // rasterImageLayers =
PluginUtils.getRasterImageLayers(context);
- methods = new String[]{
- ST_DEV_METHOD,
- FIXED_INTERV_METHOD,
- INTERVAL_METHOD,
- UNIQUE_METHOD
- };
+ methods = new String[] { ST_DEV_METHOD, FIXED_INTERV_METHOD,
+ INTERVAL_METHOD, UNIQUE_METHOD };
final Integer[] classes = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 26, 28, 29, 30 };
- Integer[] stDevClasses = new Integer[]{1, 2, 3, 4, 5};
+ final Integer[] stDevClasses = new Integer[] { 1, 2, 3, 4, 5 };
- PersonalTable personalTable = new PersonalTable(reclassTableModel(),
null,
- false, false, true, false, true, null, null, true);
+ final PersonalTable personalTable = new PersonalTable(
+ reclassTableModel(), null, false, false, true, false, true,
+ null, null, true);
- InitialData initialData = new InitialData();
+ final InitialData initialData = new InitialData();
//input data
-
initialData.setParam_Label_TextBox(GUIUtils.setGUILabel(RASTER_IN_LABEL),
PluginUtils.getRasterImageLayers(layerablesList.getLayerables()),
GUIUtils.INPUT); //Raster input
-
initialData.setParam_Label_TextBox_Button(GUIUtils.setGUILabel(METHOD_LABEL),
+ initialData.setParam_Label_TextBox(GUIUtils
+ .setGUILabel(RASTER_IN_LABEL), PluginUtils
+ .getRasterImageLayers(layerablesList.getLayerables()),
+ GUIUtils.INPUT); //Raster input
+ initialData.setParam_Label_TextBox_Button(
+ GUIUtils.setGUILabel(METHOD_LABEL),
methods,
- new
ActionObject(PluginUtils.getResources().getString("ReclassRasterPlugin.FindValues.button")),
GUIUtils.INPUT); //method
-
initialData.setParam_Label_TextBox(GUIUtils.setGUILabel(CLASSES_LABEL),
classes, GUIUtils.INPUT); //classes
- initialData.setParam_Label_TextBox(GUIUtils.setGUILabel(STDEV_LABEL),
stDevClasses, GUIUtils.INPUT); //st dev
-
initialData.setParam_Label_TextBox(GUIUtils.setGUILabel(INTERVAL_LABEL), "",
GUIUtils.INPUT);//interval
+ new ActionObject(PluginUtils.getResources().getString(
+ "ReclassRasterPlugin.FindValues.button")),
+ GUIUtils.INPUT); //method
+ initialData.setParam_Label_TextBox(GUIUtils.setGUILabel(CLASSES_LABEL),
+ classes, GUIUtils.INPUT); //classes
+ initialData.setParam_Label_TextBox(GUIUtils.setGUILabel(STDEV_LABEL),
+ stDevClasses, GUIUtils.INPUT); //st dev
+ initialData.setParam_Label_TextBox(
+ GUIUtils.setGUILabel(INTERVAL_LABEL), "",
GUIUtils.INPUT);//interval
initialData.setParam_PersonalTable(personalTable, null,
GUIUtils.INPUT);//table
//output data
initialData.setParam_Label_TextBox_Button(
- GUIUtils.setGUILabel(GUIUtils.getOutputRasterLabel()), "", new
ActionObject(""), GUIUtils.OUTPUT);
+ GUIUtils.setGUILabel(GUIUtils.getOutputRasterLabel()), "",
+ new ActionObject(""), GUIUtils.OUTPUT);
return initialData;
@@ -93,11 +106,14 @@
}
@Override
- public ComponentsTreeMap setComponentsActions(ComponentsTreeMap
personalTreeMap) {
+ public ComponentsTreeMap setComponentsActions(
+ ComponentsTreeMap personalTreeMap) {
- JButton jButton_findValue = (JButton)
personalTreeMap.getComponent("01", GUIUtils.INPUT, 2); //Find values button //
01 input= row 2=column
+ final JButton jButton_findValue = (JButton) personalTreeMap
+ .getComponent("01", GUIUtils.INPUT, 2); //Find values button
// 01 input= row 2=column
- final CustomComboBox.RasterComboBox raster =
(CustomComboBox.RasterComboBox) (JComboBox) personalTreeMap.getComponent("00",
GUIUtils.INPUT, 1);//raster in combobox action
+ final CustomComboBox.RasterComboBox raster =
(CustomComboBox.RasterComboBox) (JComboBox) personalTreeMap
+ .getComponent("00", GUIUtils.INPUT, 1);//raster in combobox
action
raster.addActionListener(new ActionListener() {
@Override
@@ -106,16 +122,24 @@
}
});
- final JComboBox jCombobox_method = (JComboBox)
personalTreeMap.getComponent("01", GUIUtils.INPUT, 1); //method combobox
- final JComboBox jCombobox_classes = (JComboBox)
personalTreeMap.getComponent("02", GUIUtils.INPUT, 1); //classes combobox
- final JComboBox jcCombobox_StDev = (JComboBox)
personalTreeMap.getComponent("03", GUIUtils.INPUT, 1); //st. dev. combobox
- final JTextField jTextFiedl_interval = (JTextField)
personalTreeMap.getComponent("04", GUIUtils.INPUT, 1);
- final PersonalTableComponents personalComp_Table =
(PersonalTableComponents) personalTreeMap.getComponent("05", GUIUtils.INPUT,
0); //table
-
- final JLabel jLabel_classes = (JLabel)
personalTreeMap.getComponent("02", GUIUtils.INPUT, 0);
- final JLabel jLabel_StDev = (JLabel)
personalTreeMap.getComponent("03", GUIUtils.INPUT, 0);
- final JLabel jLabel_interval = (JLabel)
personalTreeMap.getComponent("04", GUIUtils.INPUT, 0);
+ final JComboBox jCombobox_method = (JComboBox) personalTreeMap
+ .getComponent("01", GUIUtils.INPUT, 1); //method combobox
+ final JComboBox jCombobox_classes = (JComboBox) personalTreeMap
+ .getComponent("02", GUIUtils.INPUT, 1); //classes combobox
+ final JComboBox jcCombobox_StDev = (JComboBox) personalTreeMap
+ .getComponent("03", GUIUtils.INPUT, 1); //st. dev. combobox
+ final JTextField jTextFiedl_interval = (JTextField) personalTreeMap
+ .getComponent("04", GUIUtils.INPUT, 1);
+ final PersonalTableComponents personalComp_Table =
(PersonalTableComponents) personalTreeMap
+ .getComponent("05", GUIUtils.INPUT, 0); //table
+ final JLabel jLabel_classes = (JLabel) personalTreeMap.getComponent(
+ "02", GUIUtils.INPUT, 0);
+ final JLabel jLabel_StDev = (JLabel) personalTreeMap.getComponent("03",
+ GUIUtils.INPUT, 0);
+ final JLabel jLabel_interval = (JLabel) personalTreeMap.getComponent(
+ "04", GUIUtils.INPUT, 0);
+
//find raster values
jButton_findValue.addActionListener(new ActionListener() {
@@ -122,13 +146,12 @@
@Override
public void actionPerformed(ActionEvent e) {
try {
- findValues(raster, jCombobox_method, jCombobox_classes,
jcCombobox_StDev, jTextFiedl_interval, personalComp_Table);
- } catch (Exception ex) {
- JOptionPane.showMessageDialog(
- mainPanel,
- ex.getMessage(),
- PluginUtils.plugInName,
- JOptionPane.WARNING_MESSAGE);
+ findValues(raster, jCombobox_method, jCombobox_classes,
+ jcCombobox_StDev, jTextFiedl_interval,
+ personalComp_Table);
+ } catch (final Exception ex) {
+ JOptionPane.showMessageDialog(mainPanel, ex.getMessage(),
+ PluginUtils.plugInName,
JOptionPane.WARNING_MESSAGE);
}
}
});
@@ -138,81 +161,204 @@
@Override
public void actionPerformed(ActionEvent e) {
- enableElement(jCombobox_method, jLabel_classes,
jCombobox_classes, jLabel_StDev, jcCombobox_StDev, jLabel_interval,
jTextFiedl_interval);
+ enableElement(jCombobox_method, jLabel_classes,
+ jCombobox_classes, jLabel_StDev, jcCombobox_StDev,
+ jLabel_interval, jTextFiedl_interval);
}
});
//output
- final JTextField outputTextField = (JTextField)
personalTreeMap.getComponent("00", GUIUtils.OUTPUT, 1);
- JButton outputButton = (JButton) personalTreeMap.getComponent("00",
GUIUtils.OUTPUT, 2);
+ final JTextField outputTextField = (JTextField) personalTreeMap
+ .getComponent("00", GUIUtils.OUTPUT, 1);
+ final JButton outputButton = (JButton) personalTreeMap.getComponent(
+ "00", GUIUtils.OUTPUT, 2);
outputButton.setIcon(PluginUtils.getFolderIcon());
-
outputButton.addActionListener(GUIUtils.setSaveRasterTif(outputTextField));
+ outputButton.addActionListener(GUIUtils
+ .setSaveRasterTif(outputTextField));
return personalTreeMap;
}
+ public void reclassRasterCommand(
+ final ComponentsTreeMap componentsWithActions) throws Exception {
+ //input values
+ final String rasterSelected = GUIUtils
+ .getStringValue(componentsWithActions.getComponent("00",
+ GUIUtils.INPUT, 1));
+ final String methodSelected = GUIUtils
+ .getStringValue(componentsWithActions.getComponent("01",
+ GUIUtils.INPUT, 1));
+ final String classesSelected = GUIUtils
+ .getStringValue(componentsWithActions.getComponent("02",
+ GUIUtils.INPUT, 1));
+ final String stDevSelected = GUIUtils
+ .getStringValue(componentsWithActions.getComponent("03",
+ GUIUtils.INPUT, 1));
+ final String intervalSelected = GUIUtils
+ .getStringValue(componentsWithActions.getComponent("04",
+ GUIUtils.INPUT, 1));
+
+ //get output raster name
+ final String outRasterName = GUIUtils
+ .getStringValue(componentsWithActions.getComponent("00",
+ GUIUtils.OUTPUT, 1));
+
+ //check input and output values
+ checkValues(rasterSelected, methodSelected, classesSelected,
+ stDevSelected, intervalSelected, outRasterName);
+
+ //extract raster selected from combobox
+ final RasterImageLayer inputRasterSelected = PluginUtils
+ .getRasterImageLayerSelected((RasterComboBox)
componentsWithActions
+ .getComponent("00", GUIUtils.INPUT, 1));
+ final DoubleBasicGrid rasterDBG = RasterUtils
+ .getDoubleBasicGrid(inputRasterSelected);
+
+ //extract values from table
+ final String newValuesTable = GUIUtils
+ .getStringValue(componentsWithActions.getComponent("05",
+ GUIUtils.INPUT, 0)); //TODO: CHECK
+ final ReclassTuple[] reclassPair = PluginUtils
+ .getReclassPairFromString(newValuesTable);
+
+ //exceute reclassification
+ final RasterReclassifier reclassifier = new RasterReclassifier();
+ final DoubleBasicGrid reclassRaster = reclassifier.reclassify(
+ rasterDBG, reclassPair);
+
+ ///Create the output rasterImageLayer and display on OJ
+ //Save grid as tiff
+ RasterUtils.saveOutputRasterAsTiff(reclassRaster, new File(
+ outRasterName));
+ //Display raster on OJ from file
+ RasterUtils.displayRasterFileOnOJ(context.getWorkbenchContext(),
+ new File(outRasterName), null);
+
+ JOptionPane.showMessageDialog(super.getInitialDialog(), PluginUtils
+ .getResources().getString("SetWorkspacePlugin.Done.message"),
+ PluginUtils.plugInName, JOptionPane.INFORMATION_MESSAGE);
+ }
+
@Override
public JPanel buildPluginPanel(final ComponentsTreeMap
componentsWithActions) {
- if(this.mainPanel != null) {
- return this.mainPanel;
+ if (mainPanel != null) {
+ return mainPanel;
}
- this.mainPanel = new MainPanel(super.getInitialDialog(),
componentsWithActions, false, false, true,
-
PluginUtils.getResources().getString("MainPanel.ExecuteButton.text"),
layerablesList) {
+ mainPanel = new MainPanel(super.getInitialDialog(),
+ componentsWithActions, false, false, true, PluginUtils
+ .getResources().getString(
+ "MainPanel.ExecuteButton.text"),
layerablesList) {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
@Override
public void rightButton() {
try {
+ AbstractPlugIn.toActionListener(new ThreadedBasePlugIn() {
+ @Override
+ public String getName() {
+ return null;
+ }
+
+ @Override
+ public boolean execute(PlugInContext context)
+ throws Exception {
+ return true;
+ }
+
+ @Override
+ public void run(TaskMonitor monitor,
+ PlugInContext context) throws Exception {
+ monitor.report(PluginUtils.getResources()
+ .getString("OpenKlem.executing-process"));
+ // monitor.allowCancellationRequests();
+ reportNothingToUndoYet(context);
+ try {
+ reclassRasterCommand(componentsWithActions);
+ } catch (final Exception ex) {
+ Logger.error(getName(), ex);
+ }
+ }
+ }, context.getWorkbenchContext(), new TaskMonitorManager())
+ .actionPerformed(null);
+
//input values
- String rasterSelected =
GUIUtils.getStringValue(componentsWithActions.getComponent("00",
GUIUtils.INPUT, 1));
- String methodSelected =
GUIUtils.getStringValue(componentsWithActions.getComponent("01",
GUIUtils.INPUT, 1));
- String classesSelected =
GUIUtils.getStringValue(componentsWithActions.getComponent("02",
GUIUtils.INPUT, 1));
- String stDevSelected =
GUIUtils.getStringValue(componentsWithActions.getComponent("03",
GUIUtils.INPUT, 1));
- String intervalSelected =
GUIUtils.getStringValue(componentsWithActions.getComponent("04",
GUIUtils.INPUT, 1));
+ /* final String rasterSelected = GUIUtils
+
.getStringValue(componentsWithActions.getComponent(
+ "00", GUIUtils.INPUT, 1));
+ final String methodSelected = GUIUtils
+
.getStringValue(componentsWithActions.getComponent(
+ "01", GUIUtils.INPUT, 1));
+ final String classesSelected = GUIUtils
+
.getStringValue(componentsWithActions.getComponent(
+ "02", GUIUtils.INPUT, 1));
+ final String stDevSelected = GUIUtils
+
.getStringValue(componentsWithActions.getComponent(
+ "03", GUIUtils.INPUT, 1));
+ final String intervalSelected = GUIUtils
+
.getStringValue(componentsWithActions.getComponent(
+ "04", GUIUtils.INPUT, 1));
- //get output raster name
- String outRasterName =
GUIUtils.getStringValue(componentsWithActions.getComponent("00",
GUIUtils.OUTPUT, 1));
+ //get output raster name
+ final String outRasterName = GUIUtils
+
.getStringValue(componentsWithActions.getComponent(
+ "00", GUIUtils.OUTPUT, 1));
- //check input and output values
- checkValues(rasterSelected, methodSelected,
classesSelected, stDevSelected, intervalSelected, outRasterName);
+ //check input and output values
+ checkValues(rasterSelected, methodSelected,
+ classesSelected, stDevSelected,
intervalSelected,
+ outRasterName);
- //extract raster selected from combobox
- RasterImageLayer inputRasterSelected =
PluginUtils.getRasterImageLayerSelected((RasterComboBox)
componentsWithActions.getComponent("00", GUIUtils.INPUT, 1));
- DoubleBasicGrid rasterDBG =
RasterUtils.getDoubleBasicGrid(inputRasterSelected);
+ //extract raster selected from combobox
+ final RasterImageLayer inputRasterSelected =
PluginUtils
+
.getRasterImageLayerSelected((RasterComboBox) componentsWithActions
+ .getComponent("00", GUIUtils.INPUT,
1));
+ final DoubleBasicGrid rasterDBG = RasterUtils
+ .getDoubleBasicGrid(inputRasterSelected);
- //extract values from table
- String newValuesTable =
GUIUtils.getStringValue(componentsWithActions.getComponent("05",
GUIUtils.INPUT, 0)); //TODO: CHECK
- ReclassTuple[] reclassPair =
PluginUtils.getReclassPairFromString(newValuesTable);
+ //extract values from table
+ final String newValuesTable = GUIUtils
+
.getStringValue(componentsWithActions.getComponent(
+ "05", GUIUtils.INPUT, 0)); //TODO:
CHECK
+ final ReclassTuple[] reclassPair = PluginUtils
+ .getReclassPairFromString(newValuesTable);
- //exceute reclassification
- RasterReclassifier reclassifier = new RasterReclassifier();
- DoubleBasicGrid reclassRaster =
reclassifier.reclassify(rasterDBG, reclassPair);
+ //exceute reclassification
+ final RasterReclassifier reclassifier = new
RasterReclassifier();
+ final DoubleBasicGrid reclassRaster = reclassifier
+ .reclassify(rasterDBG, reclassPair);
- ///Create the output rasterImageLayer and display on OJ
- //Save grid as tiff
- RasterUtils.saveOutputRasterAsTiff(reclassRaster, new
File(outRasterName));
- //Display raster on OJ from file
- RasterUtils.displayRasterFileOnOJ(
- context.getWorkbenchContext(),
- new File(outRasterName),
- null);
+ ///Create the output rasterImageLayer and display on
OJ
+ //Save grid as tiff
+ RasterUtils.saveOutputRasterAsTiff(reclassRaster,
new File(
+ outRasterName));
+ //Display raster on OJ from file
+ RasterUtils.displayRasterFileOnOJ(context
+ .getWorkbenchContext(), new
File(outRasterName),
+ null);
- JOptionPane.showMessageDialog(super.getInitialDialog(),
-
PluginUtils.getResources().getString("SetWorkspacePlugin.Done.message"),
PluginUtils.plugInName, JOptionPane.INFORMATION_MESSAGE);
+ JOptionPane.showMessageDialog(
+ super.getInitialDialog(),
+ PluginUtils.getResources().getString(
+ "SetWorkspacePlugin.Done.message"),
+ PluginUtils.plugInName,
+ JOptionPane.INFORMATION_MESSAGE);*/
- } catch (Exception ex) {
- ErrorDialog.show(
- super.getInitialDialog(),
- PluginUtils.plugInName,
- ex.toString(),
+ } catch (final Exception ex) {
+ ErrorDialog.show(super.getInitialDialog(),
+ PluginUtils.plugInName, ex.toString(),
StringUtil.stackTrace(ex));
}
}
;
-
+
@Override
public void leftButton() {
@@ -225,28 +371,29 @@
};
- return this.mainPanel;
+ return mainPanel;
}
@Override
public String toString() {
- return
PluginUtils.getResources().getString("ReclassRasterPlugin.PlugInName.text");
+ return PluginUtils.getResources().getString(
+ "ReclassRasterPlugin.PlugInName.text");
}
private DefaultTableModel reclassTableModel() {
- String col[] = {FROM_LABEL, TO_LABEL, NEW_LABEL};
+ final String col[] = { FROM_LABEL, TO_LABEL, NEW_LABEL };
- String data[][] = {{null, null, null}};
+ final String data[][] = { { null, null, null } };
- DefaultTableModel dtm = new DefaultTableModel(data, col);
+ final DefaultTableModel dtm = new DefaultTableModel(data, col);
// Empty table
for (int r = dtm.getRowCount() - 1; r >= 0; --r) {
boolean toRemove = true;
for (int c = 0; c < dtm.getColumnCount(); c++) {
- Object cellCont = dtm.getValueAt(r, c);
+ final Object cellCont = dtm.getValueAt(r, c);
if (cellCont != null) {
toRemove = false;
break;
@@ -261,24 +408,28 @@
}
- private void findValues(RasterComboBox raster, JComboBox metodo, JComboBox
classi, JComboBox dev, JTextField interval, PersonalTableComponents ptc) throws
Exception {
+ private void findValues(RasterComboBox raster, JComboBox metodo,
+ JComboBox classi, JComboBox dev, JTextField interval,
+ PersonalTableComponents ptc) throws Exception {
try {
- String rasterIn = raster.getSelectedItem().toString();
- String methodSelected = metodo.getSelectedItem().toString();
- String classSelected = classi.getSelectedItem().toString();
- String devSelected = dev.getSelectedItem().toString();
- String intervalSelected = interval.getText();
+ final String rasterIn = raster.getSelectedItem().toString();
+ final String methodSelected = metodo.getSelectedItem().toString();
+ final String classSelected = classi.getSelectedItem().toString();
+ final String devSelected = dev.getSelectedItem().toString();
+ final String intervalSelected = interval.getText();
//check input values
- checkValues(rasterIn, methodSelected, classSelected, devSelected,
intervalSelected, null);
+ checkValues(rasterIn, methodSelected, classSelected, devSelected,
+ intervalSelected, null);
- RasterImageLayer ril =
PluginUtils.getRasterImageLayerSelected(raster);
+ final RasterImageLayer ril = PluginUtils
+ .getRasterImageLayerSelected(raster);
rasterChanged = true;
// Read values
- ArrayList<Double> valsUnique = new ArrayList<Double>();
+ final ArrayList<Double> valsUnique = new ArrayList<Double>();
double valSum;
double valCount;
double valSumSquare;
@@ -289,13 +440,13 @@
// Read data only if new flt selected
if (rasterChanged || metodo.getSelectedIndex() == 4) {
- Raster raster_ = ril.getRasterData(null);
+ final Raster raster_ = ril.getRasterData(null);
- int width = raster_.getWidth();
- int height = raster_.getHeight();
+ final int width = raster_.getWidth();
+ final int height = raster_.getHeight();
// Transfer vals to arraylist
- ArrayList<Double> vals = new ArrayList<Double>();
+ final ArrayList<Double> vals = new ArrayList<Double>();
double val;
valSum = 0;
@@ -330,8 +481,9 @@
}
}
- double valMean = valSum / valCount;
- valStDev = Math.sqrt(valSumSquare / valCount - valMean *
valMean);
+ final double valMean = valSum / valCount;
+ valStDev = Math.sqrt(valSumSquare / valCount - valMean
+ * valMean);
// Only for unique values
if (metodo.getSelectedIndex() == 4) {
@@ -351,7 +503,7 @@
// Add values to table
// Remove all rows
- DefaultTableModel dtm = (DefaultTableModel) ptc.getTabelModel();
+ final DefaultTableModel dtm = ptc.getTabelModel();
for (int i = dtm.getRowCount() - 1; i >= 0; --i) {
dtm.removeRow(i);
@@ -360,163 +512,178 @@
// Add rows
switch (metodo.getSelectedIndex()) {
- // StandardDev
- case 1:
- int nrStDev =
Integer.parseInt((dev.getSelectedItem()).toString());
+ // StandardDev
+ case 1:
+ final int nrStDev = Integer.parseInt((dev.getSelectedItem())
+ .toString());
- // Fill up rows
- double valSpan = valStDev / nrStDev;
- int intvCount = (int) ((valMax - valMin) / valSpan);
+ // Fill up rows
+ double valSpan = valStDev / nrStDev;
+ int intvCount = (int) ((valMax - valMin) / valSpan);
- if (intvCount > 100) {
- int res = JOptionPane.showConfirmDialog(
- super.getInitialDialog(),
-
PluginUtils.getResources().getString("ReclassRasterPlugin.MoreThen100.message"),
- PluginUtils.plugInName,
- JOptionPane.YES_NO_OPTION);
- if (res != 0) {
- return;
- }
+ if (intvCount > 100) {
+ final int res = JOptionPane.showConfirmDialog(
+ super.getInitialDialog(),
+ PluginUtils.getResources().getString(
+ "ReclassRasterPlugin.MoreThen100.message"),
+ PluginUtils.plugInName, JOptionPane.YES_NO_OPTION);
+ if (res != 0) {
+ return;
}
+ }
- double valStart;
- double valEnd;
+ double valStart;
+ double valEnd;
- // First interval
- valEnd = valMin;
- // Following intervals
- for (int i = 0; i <= intvCount; i++) {
- valStart = valEnd;
- valEnd = valStart + valSpan;
- if (valEnd >= valMax) {
- valEnd = valMax;
- }
+ // First interval
+ valEnd = valMin;
+ // Following intervals
+ for (int i = 0; i <= intvCount; i++) {
+ valStart = valEnd;
+ valEnd = valStart + valSpan;
+ if (valEnd >= valMax) {
+ valEnd = valMax;
+ }
- dtm.addRow(new Object[]{valStart, valEnd, null});
+ dtm.addRow(new Object[] { valStart, valEnd, null });
- }
+ }
- dtm.addRow(new Object[]{-9999.0, -9999.0, -9999.0});
- setCellRenderer(intvCount + 1, ptc);
+ dtm.addRow(new Object[] { -9999.0, -9999.0, -9999.0 });
+ setCellRenderer(intvCount + 1, ptc);
+ break;
+
+ // Equal interval
+ case 2:
+
+ try {
+ valSpan = Double.parseDouble(interval.getText());
+ } catch (final Exception ex1) {
+ JOptionPane
+ .showMessageDialog(
+ super.getInitialDialog(),
+ PluginUtils
+ .getResources()
+ .getString(
+
"ReclassRasterPlugin.VerifyIntervalsNo.message"),
+ PluginUtils.plugInName,
+ JOptionPane.WARNING_MESSAGE);
break;
+ }
- // Equal interval
- case 2:
-
- try {
- valSpan = Double.parseDouble(interval.getText());
- } catch (Exception ex1) {
- JOptionPane.showMessageDialog(
- super.getInitialDialog(),
-
PluginUtils.getResources().getString("ReclassRasterPlugin.VerifyIntervalsNo.message"),
- PluginUtils.plugInName,
- JOptionPane.WARNING_MESSAGE);
- break;
+ valMin = Math.floor(valMin / valSpan) * valSpan;
+ valMax = Math.ceil(valMax / valSpan) * valSpan;
+ intvCount = (int) ((valMax - valMin) / valSpan);
+ if (intvCount > 100) {
+ final int res = JOptionPane
+ .showConfirmDialog(
+ super.getInitialDialog(),
+ PluginUtils
+ .getResources()
+ .getString(
+
"ReclassRasterPlugin.FoundMoreThen100Classes.message"),
+ PluginUtils.plugInName,
+ JOptionPane.YES_NO_OPTION);
+ if (res != 0) {
+ return;
}
+ }
- valMin = Math.floor(valMin/valSpan) * valSpan;
- valMax = Math.ceil(valMax/valSpan) * valSpan;
- intvCount = (int) ((valMax - valMin) / valSpan);
- if (intvCount > 100) {
- int res = JOptionPane.showConfirmDialog(
- super.getInitialDialog(),
-
PluginUtils.getResources().getString("ReclassRasterPlugin.FoundMoreThen100Classes.message"),
- PluginUtils.plugInName,
- JOptionPane.YES_NO_OPTION);
- if (res != 0) {
- return;
- }
+ // Following intervals
+ valEnd = valMin;
+ for (int i = 0; i < intvCount; i++) {
+ valStart = valEnd;
+ valEnd = valStart + valSpan;
+ if (valEnd >= valMax) {
+ valEnd = valMax;
}
- // Following intervals
- valEnd = valMin;
- for (int i = 0; i < intvCount; i++) {
- valStart = valEnd;
- valEnd = valStart + valSpan;
- if (valEnd >= valMax) {
- valEnd = valMax;
- }
+ dtm.addRow(new Object[] { valStart, valEnd, null });
- dtm.addRow(new Object[]{valStart, valEnd, null});
+ }
+ dtm.addRow(new Object[] { -9999.0, -9999.0, -9999.0 });
+ setCellRenderer(intvCount + 1, ptc);
+ break;
+
+ // Intervals
+ case 3:
+ intvCount = classi.getSelectedIndex() - 1;
+ if (intvCount > 100) {
+ final int res = JOptionPane
+ .showConfirmDialog(
+ super.getInitialDialog(),
+ PluginUtils
+ .getResources()
+ .getString(
+
"ReclassRasterPlugin.FoundMoreThen100Classes.message"),
+ PluginUtils.plugInName,
+ JOptionPane.YES_NO_OPTION);
+ if (res != 0) {
+ return;
}
+ }
- dtm.addRow(new Object[]{-9999.0, -9999.0, -9999.0});
- setCellRenderer(intvCount + 1, ptc);
- break;
+ valSpan = (int) ((valMax - valMin) / intvCount);
- // Intervals
- case 3:
- intvCount = classi.getSelectedIndex() - 1;
- if (intvCount > 100) {
- int res = JOptionPane.showConfirmDialog(
- super.getInitialDialog(),
-
PluginUtils.getResources().getString("ReclassRasterPlugin.FoundMoreThen100Classes.message"),
- PluginUtils.plugInName,
- JOptionPane.YES_NO_OPTION);
- if (res != 0) {
- return;
- }
+ // First interval
+ valEnd = valMin;
+ // Following intervals
+ for (int i = 0; i <= intvCount; i++) {
+ valStart = valEnd;
+ valEnd = valStart + valSpan;
+ if (valEnd >= valMax) {
+ valEnd = valMax;
}
- valSpan = (int) ((valMax - valMin) / intvCount);
+ dtm.addRow(new Object[] { valStart, valEnd, null });
+ }
- // First interval
- valEnd = valMin;
- // Following intervals
- for (int i = 0; i <= intvCount; i++) {
- valStart = valEnd;
- valEnd = valStart + valSpan;
- if (valEnd >= valMax) {
- valEnd = valMax;
- }
+ dtm.addRow(new Object[] { -9999.0, -9999.0, -9999.0 });
+ setCellRenderer(intvCount + 1, ptc);
+ break;
- dtm.addRow(new Object[]{valStart, valEnd, null});
+ case 4:
+ // Unique integer values
+ intvCount = valsUnique.size();
+ if (intvCount > 100) {
+ final int res = JOptionPane
+ .showConfirmDialog(
+ super.getInitialDialog(),
+ PluginUtils
+ .getResources()
+ .getString(
+
"ReclassRasterPlugin.FoundMoreThen100Classes.message"),
+ PluginUtils.plugInName,
+ JOptionPane.YES_NO_OPTION);
+ if (res != 0) {
+ return;
}
+ }
+ for (int i = 0; i < intvCount; i++) {
+ dtm.addRow(new Object[] { valsUnique.get(i),
+ valsUnique.get(i), null });
+ }
- dtm.addRow(new Object[]{-9999.0, -9999.0, -9999.0});
- setCellRenderer(intvCount + 1, ptc);
- break;
+ dtm.addRow(new Object[] { -9999.0, -9999.0, -9999.0 });
- case 4:
- // Unique integer values
- intvCount = valsUnique.size();
- if (intvCount > 100) {
- int res = JOptionPane.showConfirmDialog(
- super.getInitialDialog(),
-
PluginUtils.getResources().getString("ReclassRasterPlugin.FoundMoreThen100Classes.message"),
- PluginUtils.plugInName,
- JOptionPane.YES_NO_OPTION);
- if (res != 0) {
- return;
- }
- }
- for (int i = 0; i < intvCount; i++) {
- dtm.addRow(new Object[]{valsUnique.get(i),
valsUnique.get(i), null});
- }
+ //System.out.println(intvCount);
+ setCellRenderer(intvCount, ptc);
+ break;
- dtm.addRow(new Object[]{-9999.0, -9999.0, -9999.0});
-
- //System.out.println(intvCount);
- setCellRenderer(intvCount, ptc);
- break;
-
}
rasterChanged = false;
- } catch (Exception ex) {
- ErrorDialog.show(
- super.getInitialDialog(),
- PluginUtils.plugInName,
- ex.toString(),
- StringUtil.stackTrace(ex));
+ } catch (final Exception ex) {
+ ErrorDialog.show(super.getInitialDialog(), PluginUtils.plugInName,
+ ex.toString(), StringUtil.stackTrace(ex));
}
}
private static void setCellRenderer(int row, PersonalTableComponents ptc) {
- YourTableCellRenderer1 ytcr = new YourTableCellRenderer1();
+ final YourTableCellRenderer1 ytcr = new YourTableCellRenderer1();
ytcr.setRow(row);
ytcr.setForeColour(Color.BLUE);
for (int c = 0; c < ptc.getTabel().getColumnCount(); c++) {
@@ -525,57 +692,61 @@
}
- private void enableElement(JComboBox method, JLabel classesLabel,
JComboBox classes, JLabel stdevLabel, JComboBox stDev, JLabel intervalLabel,
JTextField intervals) {
+ private void enableElement(JComboBox method, JLabel classesLabel,
+ JComboBox classes, JLabel stdevLabel, JComboBox stDev,
+ JLabel intervalLabel, JTextField intervals) {
switch (method.getSelectedIndex()) {
- /* Standard deviations */
- case 1:
+ /* Standard deviations */
+ case 1:
- classesLabel.setEnabled(false);
- classes.setEnabled(false);
- stdevLabel.setEnabled(true);
- stDev.setEnabled(true);
- intervalLabel.setEnabled(false);
- intervals.setEnabled(false);
+ classesLabel.setEnabled(false);
+ classes.setEnabled(false);
+ stdevLabel.setEnabled(true);
+ stDev.setEnabled(true);
+ intervalLabel.setEnabled(false);
+ intervals.setEnabled(false);
- break;
- /* Equal Interval */
- case 2:
+ break;
+ /* Equal Interval */
+ case 2:
- classesLabel.setEnabled(false);
- classes.setEnabled(false);
- stdevLabel.setEnabled(false);
- stDev.setEnabled(false);
- intervalLabel.setEnabled(true);
- intervals.setEnabled(true);
+ classesLabel.setEnabled(false);
+ classes.setEnabled(false);
+ stdevLabel.setEnabled(false);
+ stDev.setEnabled(false);
+ intervalLabel.setEnabled(true);
+ intervals.setEnabled(true);
- break;
+ break;
- /* Intevals */
- case 3:
+ /* Intevals */
+ case 3:
- classesLabel.setEnabled(true);
- classes.setEnabled(true);
- stdevLabel.setEnabled(false);
- stDev.setEnabled(false);
- intervalLabel.setEnabled(false);
- intervals.setEnabled(false);
+ classesLabel.setEnabled(true);
+ classes.setEnabled(true);
+ stdevLabel.setEnabled(false);
+ stDev.setEnabled(false);
+ intervalLabel.setEnabled(false);
+ intervals.setEnabled(false);
- break;
- /* manual */
- case 4:
- classesLabel.setEnabled(false);
- classes.setEnabled(false);
- stdevLabel.setEnabled(false);
- stDev.setEnabled(false);
- intervalLabel.setEnabled(false);
- intervals.setEnabled(false);
- break;
+ break;
+ /* manual */
+ case 4:
+ classesLabel.setEnabled(false);
+ classes.setEnabled(false);
+ stdevLabel.setEnabled(false);
+ stDev.setEnabled(false);
+ intervalLabel.setEnabled(false);
+ intervals.setEnabled(false);
+ break;
}
}
- private void checkValues(String raster, String method, String classes,
String stDev, String interval, String rasterOut) throws IOException, Exception {
+ private void checkValues(String raster, String method, String classes,
+ String stDev, String interval, String rasterOut)
+ throws IOException, Exception {
GUIUtils.checkStringValue(raster, RASTER_IN_LABEL);
GUIUtils.checkStringValue(method, METHOD_LABEL);
@@ -600,21 +771,33 @@
}
-// private RasterImageLayer[] rasterImageLayers;
+ // private RasterImageLayer[] rasterImageLayers;
private final PlugInContext context;
private MainPanel mainPanel;
- private final String ST_DEV_METHOD =
PluginUtils.getResources().getString("ReclassRasterPlugin.StDev.text");
- private final String FIXED_INTERV_METHOD =
PluginUtils.getResources().getString("ReclassRasterPlugin.FixedInterval.text");
- private final String INTERVAL_METHOD =
PluginUtils.getResources().getString("ReclassRasterPlugin.IntervalsNumber.text");
- private final String UNIQUE_METHOD =
PluginUtils.getResources().getString("ReclassRasterPlugin.UniqueValues.text");
- private final String RASTER_IN_LABEL =
PluginUtils.getResources().getString("KlemGUI.InputRaster.label");
- private final String METHOD_LABEL =
PluginUtils.getResources().getString("ReclassRasterPlugin.MethodLabel.text");
- private final String CLASSES_LABEL =
PluginUtils.getResources().getString("ReclassRasterPlugin.ClassesLabel.text");
- private final String STDEV_LABEL =
PluginUtils.getResources().getString("ReclassRasterPlugin.StDevClassesLabel.text");
- private final String INTERVAL_LABEL =
PluginUtils.getResources().getString("ReclassRasterPlugin.IntervalLabel.text");
- private final String FROM_LABEL =
PluginUtils.getResources().getString("KlemGUI.From.label");
- private final String TO_LABEL =
PluginUtils.getResources().getString("KlemGUI.To.label");
- private final String NEW_LABEL =
PluginUtils.getResources().getString("KlemGUI.NewValue.label");
+ private final String ST_DEV_METHOD = PluginUtils.getResources().getString(
+ "ReclassRasterPlugin.StDev.text");
+ private final String FIXED_INTERV_METHOD = PluginUtils.getResources()
+ .getString("ReclassRasterPlugin.FixedInterval.text");
+ private final String INTERVAL_METHOD = PluginUtils.getResources()
+ .getString("ReclassRasterPlugin.IntervalsNumber.text");
+ private final String UNIQUE_METHOD = PluginUtils.getResources().getString(
+ "ReclassRasterPlugin.UniqueValues.text");
+ private final String RASTER_IN_LABEL = PluginUtils.getResources()
+ .getString("KlemGUI.InputRaster.label");
+ private final String METHOD_LABEL = PluginUtils.getResources().getString(
+ "ReclassRasterPlugin.MethodLabel.text");
+ private final String CLASSES_LABEL = PluginUtils.getResources().getString(
+ "ReclassRasterPlugin.ClassesLabel.text");
+ private final String STDEV_LABEL = PluginUtils.getResources().getString(
+ "ReclassRasterPlugin.StDevClassesLabel.text");
+ private final String INTERVAL_LABEL = PluginUtils.getResources().getString(
+ "ReclassRasterPlugin.IntervalLabel.text");
+ private final String FROM_LABEL = PluginUtils.getResources().getString(
+ "KlemGUI.From.label");
+ private final String TO_LABEL = PluginUtils.getResources().getString(
+ "KlemGUI.To.label");
+ private final String NEW_LABEL = PluginUtils.getResources().getString(
+ "KlemGUI.NewValue.label");
private boolean rasterChanged = false;
private String[] methods;
_______________________________________________
Jump-pilot-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel