Revision: 6095 http://sourceforge.net/p/jump-pilot/code/6095 Author: ma15569 Date: 2019-01-17 17:11:29 +0000 (Thu, 17 Jan 2019) Log Message: ----------- Added monitoring to process
Modified Paths: -------------- plug-ins/OpenKLEM/OpenKLEMOpenJUMP/trunk/src/com/geomaticaeambiente/klemgui/plugin/rastertools/AggregateRastersPlugin.java plug-ins/OpenKLEM/OpenKLEMOpenJUMP/trunk/src/com/geomaticaeambiente/klemgui/plugin/rastertools/RasterCombPlugIn.java Modified: plug-ins/OpenKLEM/OpenKLEMOpenJUMP/trunk/src/com/geomaticaeambiente/klemgui/plugin/rastertools/AggregateRastersPlugin.java =================================================================== --- plug-ins/OpenKLEM/OpenKLEMOpenJUMP/trunk/src/com/geomaticaeambiente/klemgui/plugin/rastertools/AggregateRastersPlugin.java 2019-01-17 17:04:02 UTC (rev 6094) +++ plug-ins/OpenKLEM/OpenKLEMOpenJUMP/trunk/src/com/geomaticaeambiente/klemgui/plugin/rastertools/AggregateRastersPlugin.java 2019-01-17 17:11:29 UTC (rev 6095) @@ -1,25 +1,5 @@ package com.geomaticaeambiente.klemgui.plugin.rastertools; -import com.geomaticaeambiente.klemgui.utils.PluginUtils; -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.RasterAggregator; -import com.geomaticaeambiente.openjump.klem.rastertools.RasterAggregator.AggregationMethod; -import com.geomaticaeambiente.openjump.klem.rastertools.RasterAggregator.OverlayMethod; -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.Cursor; import java.io.File; @@ -26,6 +6,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; + import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JLabel; @@ -34,6 +15,32 @@ import javax.swing.JTextField; import javax.swing.table.DefaultTableModel; +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.RasterAggregator; +import com.geomaticaeambiente.openjump.klem.rastertools.RasterAggregator.AggregationMethod; +import com.geomaticaeambiente.openjump.klem.rastertools.RasterAggregator.OverlayMethod; +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 @@ -50,41 +57,26 @@ @Override public InitialData setInitialData() { - aggregMethods = new String[]{ - AGG_MIN, - AGG_MAX, - AGG_MEAN, - AGG_SUM, - AGG_MAJORITY - }; - - overlayMethods = new String[]{ - OVER_MAX, - OVER_MIN, - OVER_MEAN, - OVER_MOST_SIGNIFICANT_FIRST, - OVER_MOST_SIGNIFICANT_LAST - }; + aggregMethods = new String[] { AGG_MIN, AGG_MAX, AGG_MEAN, AGG_SUM, + AGG_MAJORITY }; + overlayMethods = new String[] { OVER_MAX, OVER_MIN, OVER_MEAN, + OVER_MOST_SIGNIFICANT_FIRST, OVER_MOST_SIGNIFICANT_LAST }; - PersonalTable personalTable = new PersonalTable(listTableModel(), - null, - false, false, true, true, true, "Raster files", - new String[]{"asc", "flt", "grd", "tiff", "tif"}, true); - InitialData initialData = new InitialData(); + final PersonalTable personalTable = new PersonalTable(listTableModel(), + null, false, false, true, true, true, "Raster files", + new String[] { "asc", "flt", "grd", "tiff", "tif" }, true); + final InitialData initialData = new InitialData(); //input data initialData.setParam_PersonalTable(personalTable, null, GUIUtils.INPUT);//table initialData.setParam_Label_TextBox( - GUIUtils.setGUILabel(AGGREGATION_LABEL), - aggregMethods, + GUIUtils.setGUILabel(AGGREGATION_LABEL), aggregMethods, GUIUtils.INPUT); + initialData.setParam_Label_TextBox(GUIUtils.setGUILabel(OVERLAY_LABEL), + overlayMethods, GUIUtils.INPUT); + initialData.setParam_Label_TextBox( - GUIUtils.setGUILabel(OVERLAY_LABEL), - overlayMethods, - GUIUtils.INPUT); - - initialData.setParam_Label_TextBox( GUIUtils.setGUILabel(CELLSIZE_LABEL), "", GUIUtils.INPUT);//interval //output data @@ -97,116 +89,237 @@ } @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 + // 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 -// raster.addActionListener(new ActionListener() { -// -// @Override -// public void actionPerformed(ActionEvent e) { -// rasterChanged = true; -// } -// }); + // final CustomComboBox.RasterComboBox raster = (CustomComboBox.RasterComboBox) (JComboBox) personalTreeMap.getComponent("00", GUIUtils.INPUT, 1);//raster in combobox action + // raster.addActionListener(new ActionListener() { + // + // @Override + // public void actionPerformed(ActionEvent e) { + // rasterChanged = true; + // } + // }); -// final PersonalTableComponents personalComp_Table = -// (PersonalTableComponents) personalTreeMap.getComponent("00", GUIUtils.INPUT, 0); //table -// final JComboBox jComboBox_Aggregation = (JComboBox) personalTreeMap.getComponent("01", GUIUtils.INPUT, 1); // aggregation methods -// final JComboBox jComboBox_Overlay = (JComboBox) personalTreeMap.getComponent("02", GUIUtils.INPUT, 1); // overlay methods -// final JTextField jTextField_CellSize = (JTextField) personalTreeMap.getComponent("03", GUIUtils.INPUT, 1); -// -// final JLabel jLabel_Aggregation = (JLabel) personalTreeMap.getComponent("01", GUIUtils.INPUT, 0); -// final JLabel jLabel_Overlay = (JLabel) personalTreeMap.getComponent("02", GUIUtils.INPUT, 0); + // final PersonalTableComponents personalComp_Table = + // (PersonalTableComponents) personalTreeMap.getComponent("00", GUIUtils.INPUT, 0); //table + // final JComboBox jComboBox_Aggregation = (JComboBox) personalTreeMap.getComponent("01", GUIUtils.INPUT, 1); // aggregation methods + // final JComboBox jComboBox_Overlay = (JComboBox) personalTreeMap.getComponent("02", GUIUtils.INPUT, 1); // overlay methods + // final JTextField jTextField_CellSize = (JTextField) personalTreeMap.getComponent("03", GUIUtils.INPUT, 1); + // + // final JLabel jLabel_Aggregation = (JLabel) personalTreeMap.getComponent("01", GUIUtils.INPUT, 0); + // final JLabel jLabel_Overlay = (JLabel) personalTreeMap.getComponent("02", GUIUtils.INPUT, 0); - //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 aggregateRastersCommand( + final ComponentsTreeMap componentsWithActions) throws Exception { + //input values + final String newValuesTable = GUIUtils + .getStringValue(componentsWithActions.getComponent("00", + GUIUtils.INPUT, 0)); //TODO: CHECK + final String[] fileNames = newValuesTable.split("_;"); + + final String aggregMethod = GUIUtils + .getStringValue(componentsWithActions.getComponent("01", + GUIUtils.INPUT, 1)); + final String overlayMethod = GUIUtils + .getStringValue(componentsWithActions.getComponent("02", + GUIUtils.INPUT, 1)); + final String cellSize = GUIUtils.getStringValue(componentsWithActions + .getComponent("03", GUIUtils.INPUT, 1)); + + //get output raster name + final String outRasterName = GUIUtils + .getStringValue(componentsWithActions.getComponent("00", + GUIUtils.OUTPUT, 1)); + + //check input and output values + checkValues(fileNames, aggregMethod, overlayMethod, cellSize, + outRasterName); + + //extract raster selected from combobox + super.getInitialDialog().setCursor(new Cursor(Cursor.WAIT_CURSOR)); + + final List<DoubleBasicGrid> inputGrids_l = new ArrayList<DoubleBasicGrid>(); + for (final String fileName : fileNames) { + inputGrids_l.add(RasterUtils.getDoubleBasicGridFromFile(new File( + fileName))); + } + + final DoubleBasicGrid outputGrid = RasterAggregator.aggregateRasters( + inputGrids_l.toArray(new DoubleBasicGrid[inputGrids_l.size()]), + Double.parseDouble(cellSize), + AggregationMethod.valueOf(aggregMethod), + OverlayMethod.valueOf(overlayMethod)); + + //extract values from table + + // //exceute reclassification + + // ///Create the output rasterImageLayer and display on OJ + //Save grid as tiff + RasterUtils.saveOutputRasterAsTiff(outputGrid, 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; + } - //input values - String newValuesTable = GUIUtils.getStringValue(componentsWithActions.getComponent("00", GUIUtils.INPUT, 0)); //TODO: CHECK - String[] fileNames = newValuesTable.split("_;"); + @Override + public boolean execute(PlugInContext context) + throws Exception { + return true; + } - String aggregMethod = GUIUtils.getStringValue(componentsWithActions.getComponent("01", GUIUtils.INPUT, 1)); - String overlayMethod = GUIUtils.getStringValue(componentsWithActions.getComponent("02", GUIUtils.INPUT, 1)); - String cellSize = GUIUtils.getStringValue(componentsWithActions.getComponent("03", GUIUtils.INPUT, 1)); + @Override + public void run(TaskMonitor monitor, + PlugInContext context) throws Exception { + monitor.report(PluginUtils.getResources() + .getString("OpenKlem.executing-process")); + // monitor.allowCancellationRequests(); + reportNothingToUndoYet(context); + try { + aggregateRastersCommand(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)); + } + /* + try { - //get output raster name - String outRasterName = GUIUtils.getStringValue(componentsWithActions.getComponent("00", GUIUtils.OUTPUT, 1)); + //input values + final String newValuesTable = GUIUtils + .getStringValue(componentsWithActions.getComponent( + "00", GUIUtils.INPUT, 0)); //TODO: CHECK + final String[] fileNames = newValuesTable.split("_;"); - //check input and output values - checkValues(fileNames, aggregMethod, overlayMethod, cellSize, outRasterName); + final String aggregMethod = GUIUtils + .getStringValue(componentsWithActions.getComponent( + "01", GUIUtils.INPUT, 1)); + final String overlayMethod = GUIUtils + .getStringValue(componentsWithActions.getComponent( + "02", GUIUtils.INPUT, 1)); + final String cellSize = GUIUtils + .getStringValue(componentsWithActions.getComponent( + "03", GUIUtils.INPUT, 1)); - //extract raster selected from combobox -// RasterImageLayer inputRasterSelected = PluginUtils.getRasterImageLayerSelected((RasterComboBox) componentsWithActions.getComponent("00", GUIUtils.INPUT, 1)); -// DoubleBasicGrid rasterDBG = RasterUtils.getDoubleBasicGrid(inputRasterSelected); + //get output raster name + final String outRasterName = GUIUtils + .getStringValue(componentsWithActions.getComponent( + "00", GUIUtils.OUTPUT, 1)); - super.getInitialDialog().setCursor(new Cursor(Cursor.WAIT_CURSOR)); - - List<DoubleBasicGrid> inputGrids_l = new ArrayList<DoubleBasicGrid>(); - for(String fileName : fileNames) { - inputGrids_l.add(RasterUtils.getDoubleBasicGridFromFile(new File(fileName))); - } - - DoubleBasicGrid outputGrid = RasterAggregator.aggregateRasters( - inputGrids_l.toArray(new DoubleBasicGrid[inputGrids_l.size()]), - Double.parseDouble(cellSize), - AggregationMethod.valueOf(aggregMethod), - OverlayMethod.valueOf(overlayMethod)); - - //extract values from table + //check input and output values + checkValues(fileNames, aggregMethod, overlayMethod, + cellSize, outRasterName); -// //exceute reclassification -// RasterReclassifier reclassifier = new RasterReclassifier(); -// DoubleBasicGrid reclassRaster = reclassifier.reclassify(rasterDBG, reclasPair); -// -// ///Create the output rasterImageLayer and display on OJ - //Save grid as tiff - RasterUtils.saveOutputRasterAsTiff(outputGrid, new File(outRasterName)); - //Display raster on OJ from file - RasterUtils.displayRasterFileOnOJ( - context.getWorkbenchContext(), - new File(outRasterName), - null); + //extract raster selected from combobox + // RasterImageLayer inputRasterSelected = PluginUtils.getRasterImageLayerSelected((RasterComboBox) componentsWithActions.getComponent("00", GUIUtils.INPUT, 1)); + // DoubleBasicGrid rasterDBG = RasterUtils.getDoubleBasicGrid(inputRasterSelected); - JOptionPane.showMessageDialog(super.getInitialDialog(), - PluginUtils.getResources().getString("SetWorkspacePlugin.Done.message"), PluginUtils.plugInName, JOptionPane.INFORMATION_MESSAGE); + super.getInitialDialog().setCursor( + new Cursor(Cursor.WAIT_CURSOR)); -// } catch (NoninvertibleTransformException ex) { -// JOptionPane.showMessageDialog(super.getInitialDialog(), "Error:" + ex, PluginUtils.plugInName, JOptionPane.ERROR_MESSAGE); - } catch (Exception ex) { - ErrorDialog.show( - super.getInitialDialog(), - PluginUtils.plugInName, - ex.toString(), - StringUtil.stackTrace(ex)); - } finally { - super.getInitialDialog().setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); - } + final List<DoubleBasicGrid> inputGrids_l = new ArrayList<DoubleBasicGrid>(); + for (final String fileName : fileNames) { + inputGrids_l + .add(RasterUtils + .getDoubleBasicGridFromFile(new File( + fileName))); + } + + final DoubleBasicGrid outputGrid = RasterAggregator + .aggregateRasters(inputGrids_l + .toArray(new DoubleBasicGrid[inputGrids_l + .size()]), Double + .parseDouble(cellSize), AggregationMethod + .valueOf(aggregMethod), OverlayMethod + .valueOf(overlayMethod)); + + //extract values from table + + // //exceute reclassification + // RasterReclassifier reclassifier = new RasterReclassifier(); + // DoubleBasicGrid reclassRaster = reclassifier.reclassify(rasterDBG, reclasPair); + // + // ///Create the output rasterImageLayer and display on OJ + //Save grid as tiff + RasterUtils.saveOutputRasterAsTiff(outputGrid, 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 (NoninvertibleTransformException ex) { + // JOptionPane.showMessageDialog(super.getInitialDialog(), "Error:" + ex, PluginUtils.plugInName, JOptionPane.ERROR_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)); + }*/ } ; - + @Override public void leftButton() { @@ -219,28 +332,29 @@ }; - return this.mainPanel; + return mainPanel; } @Override public String toString() { - return PluginUtils.getResources().getString("AggregateRastersPlugin.PlugInName.text"); + return PluginUtils.getResources().getString( + "AggregateRastersPlugin.PlugInName.text"); } private DefaultTableModel listTableModel() { - String col[] = {FILE_LABEL}; + final String col[] = { FILE_LABEL }; - String data[][] = {{null}}; + final String data[][] = { { 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; @@ -257,7 +371,7 @@ 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++) { @@ -266,60 +380,63 @@ } - 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[] rasters, String aggMethos, String overlayMethod, - String cellSize, String rasterOut) throws IOException, Exception { + private void checkValues(String[] rasters, String aggMethos, + String overlayMethod, String cellSize, String rasterOut) + throws IOException, Exception { - for(String raster : rasters) { + for (final String raster : rasters) { GUIUtils.checkStringValue(raster, RASTER_IN_LABEL); } GUIUtils.checkStringValue(aggMethos, AGGREGATION_LABEL); @@ -326,14 +443,20 @@ GUIUtils.checkStringValue(overlayMethod, OVERLAY_LABEL); try { - double cellSizeVal = Double.parseDouble(cellSize); - if(cellSizeVal < 0 ) { - throw new IOException (PluginUtils.getResources().getString("Check.CheckStringValue.message").concat(CELLSIZE_LABEL)); + final double cellSizeVal = Double.parseDouble(cellSize); + if (cellSizeVal < 0) { + throw new IOException(PluginUtils.getResources() + .getString("Check.CheckStringValue.message") + .concat(CELLSIZE_LABEL)); } - } catch(NumberFormatException ex) { - throw new IOException (PluginUtils.getResources().getString("Check.CheckStringValue.message").concat(CELLSIZE_LABEL)); - } catch (IOException ex) { - throw new IOException (PluginUtils.getResources().getString("Check.CheckStringValue.message").concat(CELLSIZE_LABEL)); + } catch (final NumberFormatException ex) { + throw new IOException(PluginUtils.getResources() + .getString("Check.CheckStringValue.message") + .concat(CELLSIZE_LABEL)); + } catch (final IOException ex) { + throw new IOException(PluginUtils.getResources() + .getString("Check.CheckStringValue.message") + .concat(CELLSIZE_LABEL)); } if (rasterOut != null) { @@ -342,7 +465,7 @@ } -// private RasterImageLayer[] rasterImageLayers; + // private RasterImageLayer[] rasterImageLayers; private final PlugInContext context; private MainPanel mainPanel; private final String AGG_MIN = "MIN"; //PluginUtils.getResources().getString("ReclassRasterPlugin.StDev.text"); @@ -350,14 +473,15 @@ private final String AGG_MEAN = "MEAN"; private final String AGG_SUM = "SUM"; private final String AGG_MAJORITY = "MAJORITY"; - + private final String OVER_MOST_SIGNIFICANT_FIRST = "MOST_SIGNIFICANT_FIRST"; //PluginUtils.getResources().getString("ReclassRasterPlugin.StDev.text"); private final String OVER_MOST_SIGNIFICANT_LAST = "MOST_SIGNIFICANT_LAST"; private final String OVER_MEAN = "MEAN"; private final String OVER_MAX = "MAX"; private final String OVER_MIN = "MIN"; - - private final String RASTER_IN_LABEL = PluginUtils.getResources().getString("KlemGUI.InputRaster.label"); + + private final String RASTER_IN_LABEL = PluginUtils.getResources() + .getString("KlemGUI.InputRaster.label"); private final String AGGREGATION_LABEL = "Aggregation method"; private final String OVERLAY_LABEL = "Overlay method"; private final String CELLSIZE_LABEL = "Output cell size"; @@ -367,5 +491,5 @@ private String[] overlayMethods; private final LayerablesList layerablesList; - + } Modified: plug-ins/OpenKLEM/OpenKLEMOpenJUMP/trunk/src/com/geomaticaeambiente/klemgui/plugin/rastertools/RasterCombPlugIn.java =================================================================== --- plug-ins/OpenKLEM/OpenKLEMOpenJUMP/trunk/src/com/geomaticaeambiente/klemgui/plugin/rastertools/RasterCombPlugIn.java 2019-01-17 17:04:02 UTC (rev 6094) +++ plug-ins/OpenKLEM/OpenKLEMOpenJUMP/trunk/src/com/geomaticaeambiente/klemgui/plugin/rastertools/RasterCombPlugIn.java 2019-01-17 17:11:29 UTC (rev 6095) @@ -1,34 +1,42 @@ package com.geomaticaeambiente.klemgui.plugin.rastertools; -import com.geomaticaeambiente.klemgui.utils.PluginUtils; -import com.geomaticaeambiente.openjump.klem.grid.DoubleBasicGrid; -import com.geomaticaeambiente.openjump.klem.parallel2.DoubleStripeGrid2; -import com.geomaticaeambiente.openjump.klem.rastertools.RasterComb; +import java.io.File; +import java.io.IOException; +import java.util.LinkedHashMap; +import java.util.UUID; + +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; + +import org.openjump.core.rasterimage.RasterImageLayer; + 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.ui.PersonalRasterCombPanel; 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.RasterCombinationComponent; import com.geomaticaeambiente.klemgui.utils.RasterUtils; -import com.geomaticaeambiente.klemgui.utils.InitialData; import com.geomaticaeambiente.openjump.klem.exceptions.NotSpatiallyConsistentGridsException; +import com.geomaticaeambiente.openjump.klem.grid.DoubleBasicGrid; +import com.geomaticaeambiente.openjump.klem.parallel2.DoubleStripeGrid2; +import com.geomaticaeambiente.openjump.klem.rastertools.RasterComb; +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.io.File; -import java.io.IOException; -import java.util.LinkedHashMap; -import java.util.UUID; -import javax.swing.JButton; -import javax.swing.JComponent; -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; /** * @@ -36,7 +44,8 @@ */ public class RasterCombPlugIn extends AbstractInputKlemPlugin { - public RasterCombPlugIn(PlugInContext context, InitialDialog initialDialog, LayerablesList layerablesList) { + public RasterCombPlugIn(PlugInContext context, InitialDialog initialDialog, + LayerablesList layerablesList) { super(context, initialDialog); this.context = context; this.layerablesList = layerablesList; @@ -45,89 +54,248 @@ @Override public InitialData setInitialData() { -// rasterImageLayers = PluginUtils.getRasterImageLayers(context); + // rasterImageLayers = PluginUtils.getRasterImageLayers(context); - RasterCombinationComponent personalObj = new RasterCombinationComponent(super.getInitialDialog()); + final RasterCombinationComponent personalObj = new RasterCombinationComponent( + super.getInitialDialog()); - InitialData initialData = new InitialData(); - initialData.setParam_RasterComb(context.getWorkbenchContext(), personalObj, GUIUtils.INPUT); + final InitialData initialData = new InitialData(); + initialData.setParam_RasterComb(context.getWorkbenchContext(), + personalObj, GUIUtils.INPUT); //set output - initialData.setParam_Label_TextBox_Button(GUIUtils.getOutputRasterLabel(), "", new ActionObject(""), GUIUtils.OUTPUT); + initialData.setParam_Label_TextBox_Button( + GUIUtils.getOutputRasterLabel(), "", new ActionObject(""), + GUIUtils.OUTPUT); 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 rasterCombCommand(final ComponentsTreeMap componentsWithActions) + throws Exception { + + //get input information + final boolean[] rasterSelected = GUIUtils + .getSelectedRasterFromRasterCombo(componentsWithActions + .getComponent("00", GUIUtils.INPUT, 0)); + final PersonalRasterCombPanel prc = ((PersonalRasterCombPanel) componentsWithActions + .getComponent("00", GUIUtils.INPUT, 0)); + final String expression = GUIUtils + .getExprerssionFromRasterCombo(componentsWithActions + .getComponent("00", GUIUtils.INPUT, 0)); + + final UUID[] uuids = prc.getSelRastersUUIds(); + + //get output raster name + final String outRasterName = GUIUtils + .getStringValue(componentsWithActions.getComponent("00", + GUIUtils.OUTPUT, 1)); + + //check + checkValues(mainPanel, expression, rasterSelected, outRasterName); + + final LinkedHashMap<String, DoubleStripeGrid2> rastersAndNames_m = new LinkedHashMap<String, DoubleStripeGrid2>(); + for (final RasterImageLayer rasterImageLayer : PluginUtils + .getRasterImageLayers(layerablesList.getLayerables())) { + for (final UUID uuid : uuids) { + if (uuid != null + && rasterImageLayer.getUUID().compareTo(uuid) == 0) { + rastersAndNames_m.put(rasterImageLayer.getName(), + RasterUtils.getDoubleStripeGrid(rasterImageLayer)); + } + } + // rastersAndNames_m.put(rasterImageLayer.getName(), RasterUtils.getDoubleStripeGrid((RasterImageLayer) rasterImageLayer)); + } + + final RasterComb rasterComb = new RasterComb(rastersAndNames_m, + expression); + final DoubleBasicGrid outGrid = rasterComb.call(); + + //Create the output file and display on OJ + //Save grid as tiff + RasterUtils.saveOutputRasterAsTiff(outGrid, new File(outRasterName)); + //Display raster on OJ from the file + RasterUtils.displayRasterFileOnOJ(context.getWorkbenchContext(), + new File(outRasterName), null); + + prc.updateRasterList(); + + 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 { + rasterCombCommand(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)); + } + } + + @Override + public void leftButton() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void centerButton() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + }; + return mainPanel; + } + + public JPanel buildPluginPanel_old( + final ComponentsTreeMap componentsWithActions) { + if (mainPanel != null) { + return mainPanel; + } + 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 { + //get input information - boolean[] rasterSelected = GUIUtils.getSelectedRasterFromRasterCombo(componentsWithActions.getComponent("00", GUIUtils.INPUT, 0)); - PersonalRasterCombPanel prc = ((PersonalRasterCombPanel) componentsWithActions.getComponent("00", GUIUtils.INPUT, 0)); - String expression = GUIUtils.getExprerssionFromRasterCombo(componentsWithActions.getComponent("00", GUIUtils.INPUT, 0)); - - UUID[] uuids = prc.getSelRastersUUIds(); - + final boolean[] rasterSelected = GUIUtils + .getSelectedRasterFromRasterCombo(componentsWithActions + .getComponent("00", GUIUtils.INPUT, 0)); + final PersonalRasterCombPanel prc = ((PersonalRasterCombPanel) componentsWithActions + .getComponent("00", GUIUtils.INPUT, 0)); + final String expression = GUIUtils + .getExprerssionFromRasterCombo(componentsWithActions + .getComponent("00", GUIUtils.INPUT, 0)); + + final UUID[] uuids = prc.getSelRastersUUIds(); + //get output raster name - String outRasterName = GUIUtils.getStringValue(componentsWithActions.getComponent("00", GUIUtils.OUTPUT, 1)); + final String outRasterName = GUIUtils + .getStringValue(componentsWithActions.getComponent( + "00", GUIUtils.OUTPUT, 1)); //check checkValues(this, expression, rasterSelected, outRasterName); - LinkedHashMap<String, DoubleStripeGrid2> rastersAndNames_m = new LinkedHashMap<String, DoubleStripeGrid2>(); - for (RasterImageLayer rasterImageLayer : PluginUtils.getRasterImageLayers(layerablesList.getLayerables())) { - for(UUID uuid : uuids) { - if(uuid != null && rasterImageLayer.getUUID().compareTo(uuid) == 0) { - rastersAndNames_m.put(rasterImageLayer.getName(), RasterUtils.getDoubleStripeGrid((RasterImageLayer) rasterImageLayer)); + final LinkedHashMap<String, DoubleStripeGrid2> rastersAndNames_m = new LinkedHashMap<String, DoubleStripeGrid2>(); + for (final RasterImageLayer rasterImageLayer : PluginUtils + .getRasterImageLayers(layerablesList + .getLayerables())) { + for (final UUID uuid : uuids) { + if (uuid != null + && rasterImageLayer.getUUID().compareTo( + uuid) == 0) { + rastersAndNames_m.put(rasterImageLayer + .getName(), RasterUtils + .getDoubleStripeGrid(rasterImageLayer)); } - } -// rastersAndNames_m.put(rasterImageLayer.getName(), RasterUtils.getDoubleStripeGrid((RasterImageLayer) rasterImageLayer)); + } + // rastersAndNames_m.put(rasterImageLayer.getName(), RasterUtils.getDoubleStripeGrid((RasterImageLayer) rasterImageLayer)); } - RasterComb rasterComb = new RasterComb(rastersAndNames_m, expression); - DoubleBasicGrid outGrid = rasterComb.call(); + final RasterComb rasterComb = new RasterComb( + rastersAndNames_m, expression); + final DoubleBasicGrid outGrid = rasterComb.call(); //Create the output file and display on OJ //Save grid as tiff - RasterUtils.saveOutputRasterAsTiff(outGrid, new File(outRasterName)); + RasterUtils.saveOutputRasterAsTiff(outGrid, new File( + outRasterName)); //Display raster on OJ from the file - RasterUtils.displayRasterFileOnOJ( - context.getWorkbenchContext(), - new File(outRasterName), + RasterUtils.displayRasterFileOnOJ(context + .getWorkbenchContext(), new File(outRasterName), null); prc.updateRasterList(); - - JOptionPane.showMessageDialog(super.getInitialDialog(), PluginUtils.getResources().getString("SetWorkspacePlugin.Done.message"), PluginUtils.plugInName, JOptionPane.INFORMATION_MESSAGE); - } catch (NotSpatiallyConsistentGridsException ex) { - JOptionPane.showMessageDialog(super.getInitialDialog(), PluginUtils.getResources().getString("SpatiallyInconsistentRasters"), PluginUtils.plugInName, JOptionPane.WARNING_MESSAGE); - - } catch (Exception ex) { - ErrorDialog.show( + JOptionPane.showMessageDialog( super.getInitialDialog(), + PluginUtils.getResources().getString( + "SetWorkspacePlugin.Done.message"), PluginUtils.plugInName, - ex.toString(), + JOptionPane.INFORMATION_MESSAGE); + + } catch (final NotSpatiallyConsistentGridsException ex) { + JOptionPane + .showMessageDialog( + super.getInitialDialog(), + PluginUtils.getResources().getString( + "SpatiallyInconsistentRasters"), + PluginUtils.plugInName, + JOptionPane.WARNING_MESSAGE); + + } catch (final Exception ex) { + ErrorDialog.show(super.getInitialDialog(), + PluginUtils.plugInName, ex.toString(), StringUtil.stackTrace(ex)); } @@ -144,27 +312,31 @@ } }; - return this.mainPanel; + return mainPanel; } @Override public String toString() { - return PluginUtils.getResources().getString("RasterCombPlugin.PlugInName.label"); + return PluginUtils.getResources().getString( + "RasterCombPlugin.PlugInName.label"); } - private void checkValues(JComponent component, String expression, boolean[] rasterList, String outRaster) throws IOException, Exception { + private void checkValues(JComponent component, String expression, + boolean[] rasterList, String outRaster) throws IOException, + Exception { GUIUtils.checkStringValue(expression, "Expression"); boolean foundRaster = false; - for (int n = 0; n < rasterList.length; n++) { - if (rasterList[n] == true) { + for (final boolean element : rasterList) { + if (element == true) { foundRaster = true; break; } } if (foundRaster == false) { - throw new NullPointerException(PluginUtils.getResources().getString("RasterComboPlugIn.CheckExpression.message")); + throw new NullPointerException(PluginUtils.getResources() + .getString("RasterComboPlugIn.CheckExpression.message")); } GUIUtils.checkFileValue(outRaster, "raster out"); _______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel