Revision: 6166
http://sourceforge.net/p/jump-pilot/code/6166
Author: ma15569
Date: 2019-04-05 16:08:04 +0000 (Fri, 05 Apr 2019)
Log Message:
-----------
Some enhenced plugin that will add more tools to OpenJUMP ones (poosibly to
substitute)
CropWarpPlugIn: Crop or Warp a raster to different target objects (any type of
layer, a single geometry, a view)
KernelAnalysis: a valid plugin to perform a kernel (filter) analysis both on
single or multiple bands rasters
ManageDataPlugIn: a set of tools to perfom some operations on raster, currently
done by the NoData Raster tools: filter by nodata, filter by an interval of
values, change no data, restore nodata tag, change data type (double to
integer, reduce decimals, etc)
Added Paths:
-----------
core/trunk/src/org/openjump/core/ui/plugin/raster/CropWarpPlugIn.java
core/trunk/src/org/openjump/core/ui/plugin/raster/KernelAnalysisPlugIn.java
core/trunk/src/org/openjump/core/ui/plugin/raster/ManageDataPlugIn.java
Added: core/trunk/src/org/openjump/core/ui/plugin/raster/CropWarpPlugIn.java
===================================================================
--- core/trunk/src/org/openjump/core/ui/plugin/raster/CropWarpPlugIn.java
(rev 0)
+++ core/trunk/src/org/openjump/core/ui/plugin/raster/CropWarpPlugIn.java
2019-04-05 16:08:04 UTC (rev 6166)
@@ -0,0 +1,513 @@
+package org.openjump.core.ui.plugin.raster;
+
+import it.betastudio.adbtoolbox.libs.FileOperations;
+
+import java.awt.Dimension;
+import java.awt.GridBagLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.geom.NoninvertibleTransformException;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Vector;
+
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import javax.swing.JFileChooser;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.WindowConstants;
+
+import org.openjump.core.apitools.LayerTools;
+import org.openjump.core.rasterimage.RasterImageLayer;
+import org.openjump.core.rasterimage.algorithms.GenericRasterAlgorithm;
+import org.openjump.core.ui.io.file.FileNameExtensionFilter;
+import org.saig.core.gui.swing.sldeditor.util.FormUtils;
+
+import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.geom.Envelope;
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.geom.GeometryFactory;
+import com.vividsolutions.jump.I18N;
+import com.vividsolutions.jump.feature.Feature;
+import com.vividsolutions.jump.feature.FeatureUtil;
+import com.vividsolutions.jump.task.TaskMonitor;
+import com.vividsolutions.jump.util.FileUtil;
+import com.vividsolutions.jump.workbench.JUMPWorkbench;
+import com.vividsolutions.jump.workbench.model.Category;
+import com.vividsolutions.jump.workbench.model.Layer;
+import com.vividsolutions.jump.workbench.model.Layerable;
+import com.vividsolutions.jump.workbench.model.StandardCategoryNames;
+import com.vividsolutions.jump.workbench.model.WMSLayer;
+import com.vividsolutions.jump.workbench.plugin.EnableCheck;
+import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
+import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
+import com.vividsolutions.jump.workbench.plugin.PlugInContext;
+import com.vividsolutions.jump.workbench.plugin.ThreadedBasePlugIn;
+import com.vividsolutions.jump.workbench.ui.GUIUtil;
+import com.vividsolutions.jump.workbench.ui.MultiInputDialog;
+import com.vividsolutions.jump.workbench.ui.SelectionManager;
+import com.vividsolutions.jump.workbench.ui.SelectionManagerProxy;
+import com.vividsolutions.jump.workbench.ui.Viewport;
+import com.vividsolutions.jump.workbench.ui.WorkbenchFrame;
+import com.vividsolutions.jump.workbench.ui.images.IconLoader;
+
+import de.latlon.deejump.wfs.jump.WFSLayer;
+
+public class CropWarpPlugIn extends ThreadedBasePlugIn {
+
+ private final String SELECTED = I18N
+
.get("jump.plugin.edit.PolygonizerPlugIn.Use-selected-features-only");
+ private final String VIEW = I18N.get("ui.MenuNames.VIEW");
+ private final String LAYER = I18N.get("ui.MenuNames.LAYER");
+ private final String PROCESSING = I18N
+ .get("jump.plugin.edit.NoderPlugIn.processing");
+ private final String CLAYER = I18N.get("ui.GenericNames.Source-Layer");
+ private final String OUTPUT_FILE = I18N
+ .get("driver.DriverManager.file-to-save");
+
+ private final ImageIcon icon16 = IconLoader
+ .icon("fugue/folder-horizontal-open_16.png");
+
+ private JLabel cutLayerLabel, cutObjectLabel;
+ JTextField jTextField_RasterOut = new JTextField();
+ JTextField jTextField_RasterIn = new JTextField();
+ private JPanel cropPanel;
+ private RasterImageLayer rLayer;
+ private JComboBox<String> comboBox = new JComboBox<String>();
+ private JComboBox<String> cropComboBox = new JComboBox<String>();
+ private JComboBox<Object> layerComboBox = new JComboBox<Object>();
+ private JComboBox<RasterImageLayer> layerableComboBox = new
JComboBox<RasterImageLayer>();
+ private String ACTION;
+ private String CROP;
+ private String path;
+ Envelope envWanted = new Envelope();
+ Envelope fix = new Envelope();
+ GenericRasterAlgorithm IO = new GenericRasterAlgorithm();
+ List<RasterImageLayer> fLayers = new ArrayList<RasterImageLayer>();
+ private MultiInputDialog dialog;
+ public static WorkbenchFrame frame =
JUMPWorkbench.getInstance().getFrame();
+ private JPanel coordsPanel;
+
+ private final String NAME = RasterMenuNames.C_NAME;
+ private final String Target_OBJECT = RasterMenuNames.C_TARGET_OBJECT;
+ private final String CROP_RASTER = RasterMenuNames.C_CROP_RASTER;
+ private final String CROP_RASTER_TIP = RasterMenuNames.C_CROP_RASTER_TIP;
+ private final String WARP_RASTER = RasterMenuNames.C_WARP_RASTER;
+ private final String WARP_RASTER_TIP = RasterMenuNames.C_WARP_RASTER_TIP;
+ private final String CUT_LAYER = RasterMenuNames.C_CUT_LAYER;
+ private final String WARP_LAYER = RasterMenuNames.C_WARP_LAYER;
+ private final String NO_INTERSECTION = RasterMenuNames.C_NO_INTERSECTION;
+
+ private final String CHECK = RasterMenuNames.Check_field;
+ private final String ACTION_LABEL = RasterMenuNames.Choose_an_action;
+
+ private void updateGUI1(ActionEvent evt, MultiInputDialog dialog) {
+ switch (cropComboBox.getSelectedIndex()) {
+ case 0:
+ cutLayerLabel.setEnabled(true);
+ layerComboBox.setEnabled(true);
+ break;
+ case 1:
+ cutLayerLabel.setEnabled(false);
+ layerComboBox.setEnabled(false);
+ break;
+ case 2:
+ cutLayerLabel.setEnabled(false);
+ layerComboBox.setEnabled(false);
+ break;
+ }
+ }
+
+ private JPanel jBasePanel() {
+ cropPanel = new JPanel(new GridBagLayout());
+ final ArrayList<String> array = new ArrayList<String>();
+ array.add(LAYER);
+ array.add(SELECTED);
+ array.add(VIEW);
+ cropComboBox = new JComboBox<>(new Vector<>(array));
+ cropComboBox.setSelectedItem(array.get(0));
+ cropComboBox.setSize(200, cropComboBox.getPreferredSize().height);
+ cropComboBox.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ updateGUI1(e, dialog);
+ dialog.pack();
+ dialog.repaint();
+ }
+ });
+ cutObjectLabel = new JLabel(Target_OBJECT);
+ FormUtils.addRowInGBL(cropPanel, 1, 0, cutObjectLabel, cropComboBox);
+ final List<Layerable> layerables = JUMPWorkbench.getInstance()
+ .getContext().getLayerManager().getLayerables(Layerable.class);
+ layerComboBox = new JComboBox<>(new Vector<>(layerables));
+ layerComboBox.setSelectedItem(layerables.get(0));
+ layerComboBox.setSize(200, layerComboBox.getPreferredSize().height);
+ cutLayerLabel = new JLabel(CUT_LAYER);
+ FormUtils.addRowInGBL(cropPanel, 2, 0, cutLayerLabel, layerComboBox);
+ return cropPanel;
+ }
+
+ private void setDialogValues(PlugInContext context) throws IOException {
+ dialog.setSideBarDescription(CROP_RASTER_TIP);
+ if (!context.getLayerNamePanel().selectedNodes(RasterImageLayer.class)
+ .isEmpty()) {
+ rLayer = (RasterImageLayer) LayerTools.getSelectedLayerable(
+ context, RasterImageLayer.class);
+ } else {
+ rLayer = context.getTask().getLayerManager()
+ .getLayerables(RasterImageLayer.class).get(0);
+ }
+ fLayers = context.getTask().getLayerManager()
+ .getLayerables(RasterImageLayer.class);
+ layerableComboBox = dialog.addLayerableComboBox(CLAYER, rLayer, "",
+ fLayers);
+ layerableComboBox.setSize(200,
+ layerableComboBox.getPreferredSize().height);
+ layerableComboBox.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ dialog.pack();
+ dialog.repaint();
+ }
+ });
+ final ArrayList<String> srsArray = new ArrayList<String>();
+ srsArray.add(CROP_RASTER);
+ srsArray.add(WARP_RASTER);
+ comboBox = dialog.addComboBox(ACTION_LABEL, srsArray.get(0), srsArray,
+ null);
+ comboBox.setSize(200, comboBox.getPreferredSize().height);
+ comboBox.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ updateGUI(e, dialog);
+ dialog.pack();
+ dialog.repaint();
+ }
+ });
+ dialog.addRow("base", jBasePanel(), null, null);
+ final FileNameExtensionFilter filter;
+ filter = new FileNameExtensionFilter("TIF", "tif");
+ dialog.addRow("Save", new JLabel(OUTPUT_FILE + ":"),
+ createOutputFilePanel(filter), saveCheck, null);
+ }
+
+ private final EnableCheck[] saveCheck = new EnableCheck[] { new
EnableCheck() {
+ @Override
+ public String check(JComponent component) {
+ return jTextField_RasterOut.getText().isEmpty() ? CHECK
+ .concat(OUTPUT_FILE) : null;
+ }
+ } };
+
+ private final EnableCheck[] cropCheck = new EnableCheck[] { new
EnableCheck() {
+ @Override
+ public String check(JComponent component) {
+ return fix.isNull() ? NO_INTERSECTION : null;
+ }
+ } };
+
+ private void getDialogValues(MultiInputDialog dialog) {
+ rLayer = (RasterImageLayer) dialog.getLayerable(CLAYER);
+ ACTION = dialog.getText(ACTION_LABEL);
+ CROP = cropComboBox.getSelectedItem().toString();
+ getCroppedEnvelope();
+ path = getOutputFilePath();
+ final int i = path.lastIndexOf('.');
+ if (i > 0) {
+ path = path.substring(0, path.length() - path.length() + i);
+ }
+ }
+
+ @Override
+ public boolean execute(PlugInContext context) throws Exception {
+ reportNothingToUndoYet(context);
+ dialog = new MultiInputDialog(context.getWorkbenchFrame(), NAME, true);
+ setDialogValues(context);
+ GUIUtil.centreOnWindow(dialog);
+ dialog.setVisible(true);
+ dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
+ if (!dialog.wasOKPressed()) {
+ return false;
+ } else if (dialog.wasOKPressed()) {
+ getDialogValues(dialog);
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void run(TaskMonitor monitor, PlugInContext context)
+ throws Exception {
+ monitor.report(PROCESSING);
+ reportNothingToUndoYet(context);
+ final File outFile = FileUtil.addExtensionIfNone(new File(path),
"tif");
+ if (ACTION.equals(CROP_RASTER)) {
+
+ IO.save_CropToEnvelope(outFile, rLayer, fix);
+
+ } else if (ACTION.equals(WARP_RASTER)) {
+ IO.save_WarpToEnvelope(outFile, rLayer, envWanted);
+ }
+ String catName = StandardCategoryNames.WORKING;
+ try {
+ catName = ((Category) context.getLayerNamePanel()
+ .getSelectedCategories().toArray()[0]).getName();
+ } catch (final RuntimeException e1) {
+ }
+ IO.load(outFile, catName);
+ return;
+ }
+
+ private void getCroppedEnvelope() {
+ envWanted = new Envelope();
+ fix = new Envelope();
+ if (CROP.equals(LAYER)) {
+ final Layerable slayer = (Layerable) layerComboBox
+ .getSelectedItem();
+ if (slayer instanceof WMSLayer) {
+ envWanted.expandToInclude(((WMSLayer) slayer).getEnvelope());
+ } else if (slayer instanceof WFSLayer) {
+ envWanted.expandToInclude(((WFSLayer) slayer)
+ .getFeatureCollectionWrapper().getEnvelope());
+ } else if (slayer instanceof Layer) {
+ envWanted.expandToInclude(((Layer) slayer)
+ .getFeatureCollectionWrapper().getEnvelope());
+ } else if (slayer instanceof RasterImageLayer) {
+ envWanted.expandToInclude(((RasterImageLayer) slayer)
+ .getWholeImageEnvelope());
+ }
+ fix = envWanted.intersection(rLayer.getWholeImageEnvelope());
+ } else if (CROP.equals(SELECTED)) {
+ final SelectionManager smgr = ((SelectionManagerProxy) frame
+ .getActiveInternalFrame()).getSelectionManager();
+ final Collection<Feature> features = smgr
+ .getFeaturesWithSelectedItems();
+ final Feature feature = features.iterator().next().clone();
+ final GeometryFactory factory = new GeometryFactory();
+ feature.setGeometry(factory.createGeometryCollection(FeatureUtil
+ .toGeometries(features).toArray(
+ new Geometry[features.size()])));
+ envWanted = feature.getGeometry().getEnvelopeInternal();
+ fix = envWanted.intersection(rLayer.getWholeImageEnvelope());
+ } else if (CROP.equals(VIEW)) {
+ final Viewport viewport = frame.getContext().getLayerViewPanel()
+ .getViewport();
+ envWanted = viewport.getEnvelopeInModelCoordinates();
+ fix = envWanted.intersection(rLayer.getWholeImageEnvelope());
+ }
+ }
+
+ private void updateGUI(ActionEvent evt, MultiInputDialog dialog) {
+ switch (comboBox.getSelectedIndex()) {
+ case 0:
+ dialog.setSideBarDescription(CROP_RASTER_TIP);
+ cutLayerLabel.setText(CUT_LAYER);
+ cutObjectLabel.setText(Target_OBJECT);
+ break;
+ case 1:
+ dialog.setSideBarDescription(WARP_RASTER_TIP);
+ cutLayerLabel.setText(WARP_LAYER);
+ cutObjectLabel.setText(Target_OBJECT);
+ break;
+ }
+ }
+
+ public JPanel createOutputFilePanel(FileNameExtensionFilter filter) {
+ JPanel jPanel = new JPanel(new GridBagLayout());
+ jPanel = new javax.swing.JPanel();
+ jTextField_RasterOut = new JTextField();
+ final JButton jButton_Dir = new JButton();
+ jTextField_RasterOut.setText("");
+ jButton_Dir.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent evt) {
+ File outputPathFile = null;
+ final JFileChooser chooser = new
GUIUtil.FileChooserWithOverwritePrompting();
+ chooser.setDialogTitle(getName());
+ chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
+ chooser.setSelectedFile(FileOperations.lastVisitedFolder);
+ chooser.setDialogType(JFileChooser.SAVE_DIALOG);
+ GUIUtil.removeChoosableFileFilters(chooser);
+ chooser.setFileFilter(filter);
+ final int ret = chooser.showOpenDialog(null);
+ if (ret == JFileChooser.APPROVE_OPTION) {
+ outputPathFile = FileUtil.removeExtensionIfAny(chooser
+ .getSelectedFile());
+ jTextField_RasterOut.setText(outputPathFile.getPath()
+ .concat(".tif"));
+ FileOperations.lastVisitedFolder = outputPathFile;
+ }
+ }
+ });
+ jTextField_RasterOut.setEditable(true);
+ jButton_Dir.setIcon(icon16);
+ jTextField_RasterOut.setPreferredSize(new Dimension(250, 20));
+ FormUtils.addRowInGBL(jPanel, 3, 0, jTextField_RasterOut);
+ FormUtils.addRowInGBL(jPanel, 3, 1, jButton_Dir);
+ return jPanel;
+ }
+
+ public JPanel createInputFilePanel() {
+ final FileNameExtensionFilter filter;
+ filter = new FileNameExtensionFilter("GDAL raster", new String[] {
+ "asc", "bil", "bip", "bsq", "bmp", "ecw", "flt", "gif", "gis",
+ "grd", "img", "jpg", "jpeg", "jp2", "j2k", "lan", "map", "mpr",
+ "mpl", "pdf", "sid", "raw", "xyz", "sid", "tiff", "tif" });
+ JPanel jPanel = new JPanel(new GridBagLayout());
+ jPanel = new javax.swing.JPanel();
+ jTextField_RasterIn = new JTextField();
+ final JButton jButton_Dir = new JButton();
+ jTextField_RasterIn.setText("");
+ jButton_Dir.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent evt) {
+ File outputPathFile = null;
+ final JFileChooser chooser = new
GUIUtil.FileChooserWithOverwritePrompting();
+ chooser.setDialogTitle(getName());
+ chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
+ chooser.setSelectedFile(FileOperations.lastVisitedFolder);
+ chooser.setDialogType(JFileChooser.SAVE_DIALOG);
+ GUIUtil.removeChoosableFileFilters(chooser);
+ chooser.setFileFilter(filter);
+ final int ret = chooser.showOpenDialog(null);
+ if (ret == JFileChooser.APPROVE_OPTION) {
+ outputPathFile = chooser.getSelectedFile();
+ jTextField_RasterIn.setText(outputPathFile.getPath()
+ .concat(".tif"));
+ FileOperations.lastVisitedFolder = outputPathFile;
+ }
+ }
+ });
+ jTextField_RasterIn.setEditable(false);
+ jButton_Dir.setIcon(icon16);
+ jTextField_RasterIn.setPreferredSize(new Dimension(250, 20));
+ FormUtils.addRowInGBL(jPanel, 3, 0, jTextField_RasterIn);
+ FormUtils.addRowInGBL(jPanel, 3, 1, jButton_Dir);
+ return jPanel;
+ }
+
+ public String getOutputFilePath() {
+ return jTextField_RasterOut.getText();
+ }
+
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+ public static MultiEnableCheck check() {
+ final EnableCheckFactory checkFactory = EnableCheckFactory
+ .getInstance();
+ return new MultiEnableCheck()
+ .add(checkFactory
+
.createWindowWithAssociatedTaskFrameMustBeActiveCheck())
+ .add(checkFactory.createAtLeastNLayerablesOfTypeMustExistCheck(
+ 1, RasterImageLayer.class));
+ }
+
+ public static final String MINX_KEY = I18N
+
.get("org.openjump.core.ui.plugin.layer.pirolraster.RasterImageWizardPanel.minx");
+ public static final String MAXX_KEY = I18N
+
.get("org.openjump.core.ui.plugin.layer.pirolraster.RasterImageWizardPanel.maxx");
+ public static final String MINY_KEY = I18N
+
.get("org.openjump.core.ui.plugin.layer.pirolraster.RasterImageWizardPanel.miny");
+ public static final String MAXY_KEY = I18N
+
.get("org.openjump.core.ui.plugin.layer.pirolraster.RasterImageWizardPanel.maxy");
+ private final JLabel minxLabel = new JLabel();
+ public static JTextField minxTextField = new JTextField();
+ private final JLabel maxxLabel = new JLabel();
+ public static JTextField maxxTextField = new JTextField();
+ private final JLabel minyLabel = new JLabel();
+ public static JTextField minyTextField = new JTextField();
+ private final JLabel maxyLabel = new JLabel();
+ public static JTextField maxyTextField = new JTextField();
+
+ private JPanel jcoordsPanel(MultiInputDialog dialog) {
+ coordsPanel = new JPanel(new GridBagLayout());
+ minxTextField.setPreferredSize(new Dimension(100, 21));
+ minxTextField.setCaretPosition(minxTextField.getText().length());
+ maxxTextField.setPreferredSize(new Dimension(100, 21));
+ maxxTextField.setCaretPosition(maxxTextField.getText().length());
+ minyTextField.setPreferredSize(new Dimension(100, 21));
+ minyTextField.setCaretPosition(minyTextField.getText().length());
+ maxyTextField.setPreferredSize(new Dimension(100, 21));
+ maxyTextField.setCaretPosition(maxyTextField.getText().length());
+
+ minxLabel.setText("X:");
+ maxxLabel.setText("X:");
+ minyLabel.setText("Y:");
+ maxyLabel.setText("Y:");
+
+ final JButton ulbutton = new JButton();
+ ulbutton.setIcon(IconLoader.icon("Select.gif"));
+ ulbutton.setPreferredSize(new Dimension(22, 22));
+ ulbutton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ try {
+ final Coordinate c1 = frame
+ .getContext()
+ .getLayerViewPanel()
+ .getViewport()
+ .toModelCoordinate(
+ frame.getContext().getLayerViewPanel()
+ .getLastClickedPoint());
+ minxTextField.setText(Double.toString(c1.x));
+ maxyTextField.setText(Double.toString(c1.y));
+ dialog.pack();
+ dialog.repaint();
+ } catch (final NoninvertibleTransformException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+ }
+ });
+
+ final JButton lrbutton = new JButton();
+ lrbutton.setIcon(IconLoader.icon("Select.gif"));
+ lrbutton.setPreferredSize(new Dimension(22, 22));
+ ulbutton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ try {
+ final Coordinate c2 = frame
+ .getContext()
+ .getLayerViewPanel()
+ .getViewport()
+ .toModelCoordinate(
+ frame.getContext().getLayerViewPanel()
+ .getLastClickedPoint());
+ maxxTextField.setText(Double.toString(c2.x));
+ minyTextField.setText(Double.toString(c2.y));
+ dialog.pack();
+ dialog.repaint();
+ } catch (final NoninvertibleTransformException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+ }
+ });
+
+ FormUtils.addRowInGBL(coordsPanel, 1, 0, new ImageIcon(getClass()
+ .getResource("lowright.png")), minxLabel, minxTextField,
+ maxyLabel, maxyTextField);
+ FormUtils.addRowInGBL(coordsPanel, 1, 5, lrbutton);
+
+ FormUtils.addRowInGBL(coordsPanel, 0, 0, new ImageIcon(getClass()
+ .getResource("upleft.png")), maxxLabel, maxxTextField,
+ minyLabel, minyTextField);
+ FormUtils.addRowInGBL(coordsPanel, 0, 5, ulbutton);
+ return coordsPanel;
+
+ }
+
+}
\ No newline at end of file
Property changes on:
core/trunk/src/org/openjump/core/ui/plugin/raster/CropWarpPlugIn.java
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added:
core/trunk/src/org/openjump/core/ui/plugin/raster/KernelAnalysisPlugIn.java
===================================================================
--- core/trunk/src/org/openjump/core/ui/plugin/raster/KernelAnalysisPlugIn.java
(rev 0)
+++ core/trunk/src/org/openjump/core/ui/plugin/raster/KernelAnalysisPlugIn.java
2019-04-05 16:08:04 UTC (rev 6166)
@@ -0,0 +1,396 @@
+package org.openjump.core.ui.plugin.raster;
+
+import it.betastudio.adbtoolbox.libs.FileOperations;
+
+import java.awt.Dimension;
+import java.awt.GridBagLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import javax.swing.JFileChooser;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.JTextField;
+import javax.swing.table.DefaultTableModel;
+import javax.swing.table.TableModel;
+
+import org.openjump.core.apitools.LayerTools;
+import org.openjump.core.rasterimage.RasterImageLayer;
+import org.openjump.core.rasterimage.algorithms.KernelAlgorithm;
+import org.openjump.core.ui.io.file.FileNameExtensionFilter;
+import org.saig.core.gui.swing.sldeditor.util.FormUtils;
+
+import com.vividsolutions.jump.I18N;
+import com.vividsolutions.jump.task.TaskMonitor;
+import com.vividsolutions.jump.util.FileUtil;
+import com.vividsolutions.jump.workbench.model.Category;
+import com.vividsolutions.jump.workbench.plugin.EnableCheck;
+import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
+import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
+import com.vividsolutions.jump.workbench.plugin.PlugInContext;
+import com.vividsolutions.jump.workbench.plugin.ThreadedBasePlugIn;
+import com.vividsolutions.jump.workbench.ui.GUIUtil;
+import com.vividsolutions.jump.workbench.ui.MultiInputDialog;
+import com.vividsolutions.jump.workbench.ui.images.IconLoader;
+
+public class KernelAnalysisPlugIn extends ThreadedBasePlugIn {
+
+ public static String dimension = I18N
+
.get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.dimension");
+
+ private final String CLAYER = RasterMenuNames.Source_Layer;
+ private final String OUTPUT_FILE = RasterMenuNames.Output_file;
+ private final String CHECK = RasterMenuNames.Check_field;
+ private final String KernelAnalysis = RasterMenuNames.KERNEL_NAME;
+ private final String defaultKernels = RasterMenuNames.KERNEL_DEFAULT;
+ private final String PROCESSING = RasterMenuNames.PROCESSING;
+
+ private JComboBox<RasterImageLayer> layerableComboBox = new
JComboBox<RasterImageLayer>();
+ private RasterImageLayer rLayer;
+ private final ImageIcon icon16 = IconLoader
+ .icon("fugue/folder-horizontal-open_16.png");
+ List<RasterImageLayer> fLayers = new ArrayList<RasterImageLayer>();
+ private JComboBox<String> kernelComboBox = new JComboBox<String>();
+
+ JTextField jTextField_RasterOut = new JTextField();
+
+ private JScrollPane jScrollPane1;
+ private JTable jTable;
+ private DefaultTableModel dtm = null;
+ FileNameExtensionFilter filter;
+ private String path;
+ private String nameKernel;
+
+ public float[] array1d;
+
+ public float[][] array2d;
+
+ final KernelAlgorithm fil = new KernelAlgorithm();
+ String hmKey = new String();
+
+ LinkedHashMap<String, float[]> Map = new LinkedHashMap<String, float[]>();
+ LinkedHashMap<String, String> Map2 = new LinkedHashMap<String, String>();
+
+ @Override
+ public String getName() {
+ return KernelAnalysis;
+ }
+
+ private void setDialogValues(final MultiInputDialog dialog,
+ PlugInContext context) throws IOException {
+ dialog.setSideBarDescription(KernelAnalysis);
+ if (!context.getLayerNamePanel().selectedNodes(RasterImageLayer.class)
+ .isEmpty()) {
+ rLayer = (RasterImageLayer) LayerTools.getSelectedLayerable(
+ context, RasterImageLayer.class);
+ } else {
+ rLayer = context.getTask().getLayerManager()
+ .getLayerables(RasterImageLayer.class).get(0);
+ }
+ fLayers = context.getTask().getLayerManager()
+ .getLayerables(RasterImageLayer.class);
+ layerableComboBox = dialog.addLayerableComboBox(CLAYER, rLayer, "",
+ fLayers);
+ layerableComboBox.setSize(200,
+ layerableComboBox.getPreferredSize().height);
+ final ArrayList<String> srsArray = new ArrayList<String>();
+ Map = fil.createDataMap();
+ Map2 = fil.createTextMap();
+ final Iterator<Map.Entry<String, float[]>> itr = Map.entrySet()
+ .iterator();
+ while (itr.hasNext()) {
+ srsArray.add(itr.next().getKey());
+ }
+ kernelComboBox = dialog.addComboBox(defaultKernels, srsArray.get(0),
+ srsArray, null);
+ kernelComboBox.setSize(200, kernelComboBox.getPreferredSize().height);
+ kernelComboBox.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent evt) {
+ fixTable(dialog);
+ jTable.setVisible(true);
+ // kernelComboBoxActionPerformed(evt);
+ }
+ });
+ jTable = new JTable();
+ jScrollPane1 = new JScrollPane();
+ jTable.setModel(new DefaultTableModel(new Object[][] {
+ { null, null, null, null }, { null, null, null, null },
+ { null, null, null, null }, { null, null, null, null } },
+ new String[] { "Title 1", "Title 2", "Title 3", "Title 4" }));
+ GUIUtil.chooseGoodColumnWidths(jTable);
+ jScrollPane1.setViewportView(jTable);
+ dialog.addRow("Table", jScrollPane1, fillCheck, null);
+ filter = new FileNameExtensionFilter("TIFF", "tif");
+ dialog.addRow("Save", createOutputFilePanel(filter), saveCheck, null);
+ fixComponents(dialog);
+ }
+
+ private void fixComponents(MultiInputDialog dialog) {
+ final String test =
fil.S_gradientEast;//dialog.getText(defaultKernels);
+ array1d = Map.get(test);
+ final String description = Map2.get(test);
+ final Double dim = Math.sqrt(array1d.length);
+ final int val = dim.intValue();
+ array2d = new float[val][val];
+
+ for (int i = 0; i < val; i++) {
+ System.arraycopy(array1d, (i * val), array2d[i], 0, val);
+ }
+
+ final int columns = array2d[0].length;
+ dtm = new DefaultTableModel(0, columns) {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Override
+ public Class getColumnClass(int column) {
+ return Float.class; // number will be displayed right aligned
+ }
+
+ // @Override
+ // public boolean isCellEditable(int row, int column) {
+ //all cells false
+ // return false;
+ // }
+ };
+
+ for (final float[] rowData : array2d) {
+ final Vector<Object> row = new Vector<Object>(columns);
+ for (final float element : rowData) {
+ row.addElement(new Float(element));
+ }
+
+ dtm.addRow(row);
+ }
+ path = getOutputFilePath();
+ final int it = path.lastIndexOf('.');
+ if (it > 0) {
+ path = path.substring(0, path.length() - path.length() + it);
+ }
+ dialog.setSideBarDescription(description);
+ jTable.setModel(dtm);
+ }
+
+ private void fixTable(MultiInputDialog dialog) {
+ final String test =
dialog.getText(defaultKernels);//dialog.getText(defaultKernels);
+ array1d = Map.get(test);
+ final String description = Map2.get(test);
+ final Double dim = Math.sqrt(array1d.length);
+ final int val = dim.intValue();
+ array2d = new float[val][val];
+
+ for (int i = 0; i < val; i++) {
+ System.arraycopy(array1d, (i * val), array2d[i], 0, val);
+ }
+
+ final int columns = array2d[0].length;
+ dtm = new DefaultTableModel(0, columns) {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Override
+ public Class getColumnClass(int column) {
+ return Float.class; // number will be displayed right aligned
+ }
+ };
+
+ for (final float[] rowData : array2d) {
+ final Vector<Object> row = new Vector<Object>(columns);
+ for (final float element : rowData) {
+ row.addElement(new Float(element));
+ }
+
+ dtm.addRow(row);
+ }
+ path = getOutputFilePath();
+ final int it = path.lastIndexOf('.');
+ if (it > 0) {
+ path = path.substring(0, path.length() - path.length() + it);
+ }
+ dialog.setSideBarDescription(description);
+
+ jTable.setModel(dtm);
+ }
+
+ public float[][] getTableData(JTable table) {
+ final TableModel dtm = table.getModel();
+ final int nRow = dtm.getRowCount(), nCol = dtm.getColumnCount();
+ final float[][] tableData = new float[nRow][nCol];
+ for (int i = 0; i < nRow; i++) {
+ for (int j = 0; j < nCol; j++) {
+ tableData[i][j] = (float) dtm.getValueAt(i, j);
+ }
+ }
+ return tableData;
+ }
+
+ private void getDialogValues(MultiInputDialog dialog) {
+ rLayer = (RasterImageLayer) dialog.getLayerable(CLAYER);
+
+ nameKernel =
dialog.getText(defaultKernels);//dialog.getText(defaultKernels);
+
+ final float[][] fl2d = getTableData(jTable);
+
+ final int rows = fl2d.length, cols = fl2d[0].length;
+ final float[] mono = new float[(rows * cols)];
+ for (int i = 0; i < rows; i++) {
+ System.arraycopy(fl2d[i], 0, mono, (i * cols), cols);
+ }
+
+ array1d = mono;//Map.get(nameKernel);
+ path = getOutputFilePath();
+ final int it = path.lastIndexOf('.');
+ if (it > 0) {
+ path = path.substring(0, path.length() - path.length() + it);
+ }
+ }
+
+ @Override
+ public boolean execute(PlugInContext context) throws Exception {
+ reportNothingToUndoYet(context);
+ final MultiInputDialog dialog = new MultiInputDialog(
+ context.getWorkbenchFrame(), KernelAnalysis, true);
+ setDialogValues(dialog, context);
+ if (fLayers.isEmpty()) {
+ return false;
+ }
+ GUIUtil.centreOnWindow(dialog);
+ dialog.setVisible(true);
+ if (!dialog.wasOKPressed()) {
+ return false;
+ } else if (dialog.wasOKPressed()) {
+ getDialogValues(dialog);
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void run(TaskMonitor monitor, PlugInContext context)
+ throws Exception {
+ monitor.report(PROCESSING);
+ reportNothingToUndoYet(context);
+
+ final File outFile = FileUtil.addExtensionIfNone(new File(path),
"tif");
+ fil.filterRaster(outFile, rLayer, array1d);
+ String catName = KernelAnalysis;
+ try {
+ catName = ((Category) context.getLayerNamePanel()
+ .getSelectedCategories().toArray()[0]).getName();
+ } catch (final RuntimeException e1) {
+ }
+ fil.load(outFile, nameKernel, catName);
+
+ return;
+ }
+
+ private final EnableCheck[] saveCheck = new EnableCheck[] { new
EnableCheck() {
+ @Override
+ public String check(JComponent component) {
+ return jTextField_RasterOut.getText().isEmpty() ? CHECK
+ .concat(OUTPUT_FILE) : null;
+ }
+ } };
+
+ private final EnableCheck[] fillCheck = new EnableCheck[] { new
EnableCheck() {
+ @Override
+ public String check(JComponent component) {
+
+ final int nTabRows = jTable.getRowCount();
+ final int nTabCols = jTable.getColumnCount();
+
+ for (int r = 0; r < nTabRows; r++) {
+ for (int c = 0; c < nTabCols; c++) {
+
+ return jTable.getValueAt(r, c).equals("")
+ || jTable.getValueAt(r, c).equals(null) ||
+
+ !isNumeric(jTable.getValueAt(r, c).toString())
+
+ ? CHECK.concat("Table") : null;
+
+ }
+ }
+ return CHECK;
+
+ }
+ } };
+
+ public static boolean isNumeric(String str) {
+ return str.matches("-?\\d+(\\.\\d+)?"); //match a number with optional
'-' and decimal.
+ }
+
+ public JPanel createOutputFilePanel(FileNameExtensionFilter filter) {
+ JPanel jPanel = new JPanel(new GridBagLayout());
+ jPanel = new javax.swing.JPanel();
+ final JLabel jLabel3 = new javax.swing.JLabel();
+ jTextField_RasterOut = new JTextField();
+ final JButton jButton_Dir = new JButton();
+ jTextField_RasterOut.setText("");
+ jButton_Dir.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent evt) {
+ File outputPathFile = null;
+ final JFileChooser chooser = new
GUIUtil.FileChooserWithOverwritePrompting();
+ chooser.setDialogTitle(getName());
+ chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
+
+ chooser.setSelectedFile(FileOperations.lastVisitedFolder);
+ chooser.setDialogType(JFileChooser.SAVE_DIALOG);
+ GUIUtil.removeChoosableFileFilters(chooser);
+ chooser.setFileFilter(filter);
+ final int ret = chooser.showOpenDialog(null);
+ if (ret == JFileChooser.APPROVE_OPTION) {
+ outputPathFile = FileUtil.removeExtensionIfAny(chooser
+ .getSelectedFile());
+ jTextField_RasterOut.setText(outputPathFile.getPath()
+ .concat(".tif"));
+ FileOperations.lastVisitedFolder = outputPathFile;
+ }
+ }
+ });
+ jLabel3.setText(OUTPUT_FILE);
+ jTextField_RasterOut.setEditable(true);
+ jButton_Dir.setIcon(icon16);
+ jTextField_RasterOut.setPreferredSize(new Dimension(250, 20));
+ FormUtils.addRowInGBL(jPanel, 3, 0, OUTPUT_FILE, jTextField_RasterOut);
+ FormUtils.addRowInGBL(jPanel, 3, 2, jButton_Dir);
+ return jPanel;
+ }
+
+ public String getOutputFilePath() {
+ return jTextField_RasterOut.getText();
+ }
+
+ public static MultiEnableCheck check() {
+ final EnableCheckFactory checkFactory = EnableCheckFactory
+ .getInstance();
+ return new MultiEnableCheck()
+ .add(checkFactory
+
.createWindowWithAssociatedTaskFrameMustBeActiveCheck())
+ .add(checkFactory.createAtLeastNLayerablesOfTypeMustExistCheck(
+ 1, RasterImageLayer.class));
+ }
+
+}
Property changes on:
core/trunk/src/org/openjump/core/ui/plugin/raster/KernelAnalysisPlugIn.java
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: core/trunk/src/org/openjump/core/ui/plugin/raster/ManageDataPlugIn.java
===================================================================
--- core/trunk/src/org/openjump/core/ui/plugin/raster/ManageDataPlugIn.java
(rev 0)
+++ core/trunk/src/org/openjump/core/ui/plugin/raster/ManageDataPlugIn.java
2019-04-05 16:08:04 UTC (rev 6166)
@@ -0,0 +1,619 @@
+/*
+* Copyright (C) 2019 Giuseppe Aruta
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*
+* ******************************************************************
+*/
+package org.openjump.core.ui.plugin.raster;
+
+import static com.vividsolutions.jump.I18N.get;
+import it.betastudio.adbtoolbox.libs.FileOperations;
+
+import java.awt.Dimension;
+import java.awt.GridBagLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.swing.BorderFactory;
+import javax.swing.ButtonGroup;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import javax.swing.JFileChooser;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JRadioButton;
+import javax.swing.JSpinner;
+import javax.swing.JTextField;
+import javax.swing.SpinnerModel;
+import javax.swing.SpinnerNumberModel;
+
+import org.openjump.core.apitools.LayerTools;
+import org.openjump.core.rasterimage.RasterImageLayer;
+import org.openjump.core.rasterimage.algorithms.GenericRasterAlgorithm;
+import org.openjump.core.ui.io.file.FileNameExtensionFilter;
+import org.openjump.core.ui.util.LayerableUtil;
+import org.saig.core.gui.swing.sldeditor.util.FormUtils;
+
+import com.vividsolutions.jts.geom.Envelope;
+import com.vividsolutions.jump.I18N;
+import com.vividsolutions.jump.task.TaskMonitor;
+import com.vividsolutions.jump.util.FileUtil;
+import com.vividsolutions.jump.workbench.JUMPWorkbench;
+import com.vividsolutions.jump.workbench.WorkbenchContext;
+import com.vividsolutions.jump.workbench.model.Category;
+import com.vividsolutions.jump.workbench.model.StandardCategoryNames;
+import com.vividsolutions.jump.workbench.plugin.EnableCheck;
+import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
+import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
+import com.vividsolutions.jump.workbench.plugin.PlugInContext;
+import com.vividsolutions.jump.workbench.plugin.ThreadedBasePlugIn;
+import com.vividsolutions.jump.workbench.ui.GUIUtil;
+import com.vividsolutions.jump.workbench.ui.MultiInputDialog;
+import com.vividsolutions.jump.workbench.ui.WorkbenchFrame;
+import com.vividsolutions.jump.workbench.ui.images.IconLoader;
+
+public class ManageDataPlugIn extends ThreadedBasePlugIn {
+ /**
+ *
+ * @author Giuseppe Aruta 2019_25_03
+ * A comprensive class/plugin to manage data of a single raster layer
+ */
+ public static WorkbenchFrame frame =
JUMPWorkbench.getInstance().getFrame();
+
+ private final String CHANGE_NODATA = I18N
+
.get("org.openjump.core.ui.plugin.raster.nodata.ChangeNoDataValuePlugIn.name");
+ private final String CHANGE_INTERVAL_TO_NODATA = I18N
+
.get("org.openjump.core.ui.plugin.raster.nodata.ChangeRangeValuesToNoDataPlugIn.name");
+ private final String FROM = I18N
+ .get("org.openjump.core.ui.plugin.raster.nodata.from");
+ private final String TO = I18N
+ .get("org.openjump.core.ui.plugin.raster.nodata.to");
+ private final String LOWER_VALUE = I18N
+ .get("com.vividsolutions.jump.util.Frequency.lower-value");
+ private final String UPPER_VALUE = I18N
+ .get("com.vividsolutions.jump.util.Frequency.upper-value");
+ private final String STATISTICS = I18N
+ .get("org.openjump.core.ui.plugin.raster.nodata.CellStatistics");
+ private final String NODATA = I18N
+ .get("org.openjump.core.ui.plugin.raster.nodata.nodata");
+ private final String MIN = I18N
+ .get("org.openjump.core.ui.plugin.raster.nodata.min");
+ private final String MAX = I18N
+ .get("org.openjump.core.ui.plugin.raster.nodata.max");
+ private final String ERROR = I18N.get("ui.GenericNames.Error");
+ private final String SELECT_BAND = I18N
+
.get("org.openjump.core.ui.plugin.raster.HistogramPlugIn.select-one-band");
+
+ private final ImageIcon icon16 = IconLoader
+ .icon("fugue/folder-horizontal-open_16.png");
+ private JTextField target_nodata, source_nodata, lv_field, uv_field, nd,
+ max, min;
+ private JLabel source_NoData_label, target_NoData_label, lv_label,
+ uv_label;
+ JTextField jTextField_RasterOut = new JTextField();
+ private JPanel mainPanel, rangePanel, resetPanel, decimalPanel;
+ private RasterImageLayer rLayer;
+ private JComboBox<String> comboBox = new JComboBox<String>();
+ private JComboBox<RasterImageLayer> layerableComboBox = new
JComboBox<RasterImageLayer>();
+ private String UNIT;
+ private JRadioButton radioMin = new JRadioButton();
+ private JRadioButton radioMax = new JRadioButton();
+ boolean minval = true;
+ boolean maxval = false;
+ double min_value, max_value;
+ private String path;
+ private final SpinnerModel dimensionModel = new SpinnerNumberModel(2, //
initial
+ // value
+ 0, // min
+ 25, // max
+ 1);
+ private JSpinner dimensionSpinner = new JSpinner();
+ private Integer dimension;
+ Envelope envWanted = new Envelope();
+ Envelope fix = new Envelope();
+
+ private final String CLAYER = RasterMenuNames.Source_Layer;
+ private final String OUTPUT_FILE = RasterMenuNames.Output_file;
+ private final String CHECK = RasterMenuNames.Check_field;
+ private final String ACTION = RasterMenuNames.Choose_an_action;
+ private final String CHANGE_NODATA_TIP = RasterMenuNames.CHANGE_NODATA_TIP;
+ private final String CHANGE_INTERVAL_TO_NODATA_TIP =
RasterMenuNames.CHANGE_INTERVAL_TO_NODATA_TIP;
+ private final String EXTRACT_INTERVAL_TIP =
RasterMenuNames.EXTRACT_INTERVAL_TIP;
+ private final String EXTRACT_INTERVAL = RasterMenuNames.EXTRACT_INTERVAL;
+ private final String RESET_NODATA_TAG_TIP =
RasterMenuNames.RESET_NODATA_TAG_TIP;
+ private final String RESET_NODATA_TAG = RasterMenuNames.RESET_NODATA_TAG;
+ private final String SET_DECIMAL = RasterMenuNames.SET_DECIMAL;
+ private final String SET_DECIMAL_TIP = RasterMenuNames.SET_DECIMAL_TIP;
+ private final String RESET_TO_MIN = RasterMenuNames.RESET_TO_MIN;
+ private final String RESET_TO_MAX = RasterMenuNames.RESET_TO_MAX;
+ private final String NAME = RasterMenuNames.DATA_NAME;
+ private final String PROCESSING = RasterMenuNames.PROCESSING;
+ private final static String CHECK_FILE = RasterMenuNames.SINGLE_BAND_EXIST;
+
+ List<RasterImageLayer> fLayers = new ArrayList<RasterImageLayer>();
+
+ public static MultiEnableCheck createEnableCheck(
+ WorkbenchContext workbenchContext) {
+ final EnableCheckFactory checkFactory = new EnableCheckFactory(
+ workbenchContext);
+ return new MultiEnableCheck()
+ .add(checkFactory
+
.createWindowWithAssociatedTaskFrameMustBeActiveCheck())
+ .add(checkFactory.createAtLeastNLayerablesOfTypeMustExistCheck(
+ 1, RasterImageLayer.class)).add(new EnableCheck() {
+ @Override
+ public String check(JComponent component) {
+ final List<RasterImageLayer> mLayer = new
ArrayList<RasterImageLayer>();
+ final Collection<RasterImageLayer> rlayers =
workbenchContext
+ .getLayerManager().getLayerables(
+ RasterImageLayer.class);
+ for (final RasterImageLayer currentLayer : rlayers) {
+ if (LayerableUtil.isMonoband(currentLayer)) {
+ mLayer.add(currentLayer);
+ }
+ }
+ if (!mLayer.isEmpty()) {
+ return null;
+ }
+ String msg = null;
+ if (mLayer.isEmpty()) {
+ msg = get(CHECK_FILE);
+ }
+ return msg;
+ }
+ });
+ }
+
+ private void setDialogValues(final MultiInputDialog dialog,
+ PlugInContext context) throws IOException {
+ dialog.setSideBarDescription(CHANGE_NODATA_TIP);
+
+ if (!context.getLayerNamePanel().selectedNodes(RasterImageLayer.class)
+ .isEmpty()) {
+ rLayer = (RasterImageLayer) LayerTools.getSelectedLayerable(
+ context, RasterImageLayer.class);
+ } else {
+ rLayer = context.getTask().getLayerManager()
+ .getLayerables(RasterImageLayer.class).get(0);
+ }
+ min_value = rLayer.getMetadata().getStats().getMin(0);
+ max_value = rLayer.getMetadata().getStats().getMax(0);
+
+ fLayers = context.getTask().getLayerManager()
+ .getLayerables(RasterImageLayer.class);
+ layerableComboBox = dialog.addLayerableComboBox(CLAYER, rLayer, "",
+ fLayers);
+ layerableComboBox.setSize(200,
+ layerableComboBox.getPreferredSize().height);
+ layerableComboBox.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ updateValues(e, dialog);
+ dialog.pack();
+ dialog.repaint();
+ }
+ });
+ final ArrayList<String> srsArray = new ArrayList<String>();
+ srsArray.add(CHANGE_NODATA);
+ srsArray.add(CHANGE_INTERVAL_TO_NODATA);
+ srsArray.add(EXTRACT_INTERVAL);
+ srsArray.add(RESET_NODATA_TAG);
+ srsArray.add(SET_DECIMAL);
+ comboBox = dialog.addComboBox(ACTION, "", srsArray, null);
+ comboBox.setSize(200, comboBox.getPreferredSize().height);
+ comboBox.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ updateGUI(e, dialog);
+ updateValues(e, dialog);
+ dialog.pack();
+ dialog.repaint();
+ }
+ });
+ dialog.addRow(statisticPanel());
+ dialog.addRow("ChangeNoData", changeNoDataValuePanel(),
+ chengeNoDataCheck, null);
+ dialog.addRow("ChangeData", changeRangeToNoDataPanel(),
+ chengeDataCheck, null);
+ dialog.addRow(resetNoDataPanel());
+ dialog.addRow(decimalPanel());
+ rangePanel.setEnabled(false);
+ rangePanel.setVisible(false);
+ resetPanel.setVisible(false);
+ decimalPanel.setEnabled(false);
+ decimalPanel.setVisible(false);
+ final FileNameExtensionFilter filter;
+ filter = new FileNameExtensionFilter("TIF", "tif");
+ dialog.addRow("Save", createOutputFilePanel(filter), saveCheck, null);
+
+ }
+
+ private final EnableCheck[] chengeDataCheck = new EnableCheck[] {
+ new EnableCheck() {
+ @Override
+ public String check(JComponent component) {
+ return uv_field.getText().isEmpty() ? CHECK
+ .concat(UPPER_VALUE) : null;
+ }
+ }, new EnableCheck() {
+ @Override
+ public String check(JComponent component) {
+ return lv_field.getText().isEmpty() ? CHECK
+ .concat(LOWER_VALUE) : null;
+ }
+ }, new EnableCheck() {
+ @Override
+ public String check(JComponent component) {
+ return Double.parseDouble(lv_field.getText()) > Double
+ .parseDouble(uv_field.getText()) ? ERROR + " :"
+ + LOWER_VALUE + ">" + UPPER_VALUE + "!" : null;
+ }
+ }
+
+ };
+
+ private final EnableCheck[] chengeNoDataCheck = new EnableCheck[] { new
EnableCheck() {
+ @Override
+ public String check(JComponent component) {
+ return target_nodata.getText().isEmpty() ? CHECK.concat(TO) : null;
+ }
+ } };
+
+ private final EnableCheck[] saveCheck = new EnableCheck[] { new
EnableCheck() {
+ @Override
+ public String check(JComponent component) {
+ return jTextField_RasterOut.getText().isEmpty() ? CHECK
+ .concat(OUTPUT_FILE) : null;
+ }
+ } };
+
+ private void getDialogValues(MultiInputDialog dialog) {
+ rLayer = (RasterImageLayer) dialog.getLayerable(CLAYER);
+ UNIT = dialog.getText(ACTION);
+ if (UNIT.equals(RESET_NODATA_TAG)) {
+ minval = dialog.getBoolean(RESET_TO_MIN);
+ maxval = dialog.getBoolean(RESET_TO_MAX);
+ }
+ dimension = (Integer) dimensionSpinner.getValue();
+ path = getOutputFilePath();
+ final int i = path.lastIndexOf('.');
+ if (i > 0) {
+ path = path.substring(0, path.length() - path.length() + i);
+ }
+ }
+
+ @Override
+ public boolean execute(PlugInContext context) throws Exception {
+ reportNothingToUndoYet(context);
+ final MultiInputDialog dialog = new MultiInputDialog(
+ context.getWorkbenchFrame(), NAME, true);
+ setDialogValues(dialog, context);
+ if (fLayers.isEmpty()) {
+ return false;
+ }
+ GUIUtil.centreOnWindow(dialog);
+ dialog.setVisible(true);
+ if (!dialog.wasOKPressed()) {
+ return false;
+ } else if (dialog.wasOKPressed()) {
+ getDialogValues(dialog);
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void run(TaskMonitor monitor, PlugInContext context)
+ throws Exception {
+ monitor.report(PROCESSING);
+ reportNothingToUndoYet(context);
+ final GenericRasterAlgorithm IO = new GenericRasterAlgorithm();
+ int band = 0;
+ if (rLayer.getNumBands() > 1) {
+ final String[] bands = { "0", "1", "2" };
+ final String stringInput = (String) JOptionPane.showInputDialog(
+ JUMPWorkbench.getInstance().getFrame(), SELECT_BAND,
+ getName(), JOptionPane.PLAIN_MESSAGE, null, bands, "0");
+ try {
+ band = Integer.parseInt(stringInput);
+ } catch (final NumberFormatException e) {
+ return; // The typed text was not an integer
+ // band = 0;
+ }
+ }
+
+ final File outFile = FileUtil.addExtensionIfNone(new File(path),
"tif");
+ if (UNIT.equals(CHANGE_NODATA)) {
+ final double newdata = Double.parseDouble(target_nodata.getText());
+ final double olddata = rLayer.getNoDataValue();
+ IO.save_ChangeNoData(outFile, rLayer, band, olddata, newdata);
+ } else if (UNIT.equals(CHANGE_INTERVAL_TO_NODATA)) {
+ final double mindata = Double.parseDouble(lv_field.getText());
+ final double maxdata = Double.parseDouble(uv_field.getText());
+ IO.save_LimitValidData(outFile, rLayer, band, mindata, maxdata);
+ } else if (UNIT.equals(EXTRACT_INTERVAL)) {
+ final double mindata = Double.parseDouble(lv_field.getText());
+ final double maxdata = Double.parseDouble(uv_field.getText());
+ IO.save_ExtractValidData(outFile, rLayer, band, mindata, maxdata);
+ } else if (UNIT.equals(RESET_NODATA_TAG)) {
+ if (minval) {
+ IO.save_ResetNoDataTag(outFile, rLayer, band,
rLayer.getMetadata()
+ .getStats().getMin(0));
+ } else if (maxval) {
+ IO.save_ResetNoDataTag(outFile, rLayer, band,
rLayer.getMetadata()
+ .getStats().getMax(0));
+ }
+ } else if (UNIT.equals(SET_DECIMAL)) {
+ IO.save_ChangeDecimalValues(outFile, rLayer, band, dimension);
+ }
+ String catName = StandardCategoryNames.WORKING;
+ try {
+ catName = ((Category) context.getLayerNamePanel()
+ .getSelectedCategories().toArray()[0]).getName();
+ } catch (final RuntimeException e1) {
+ }
+ IO.load(outFile, catName);
+ return;
+ }
+
+ private void updateValues(ActionEvent evt, MultiInputDialog dialog) {
+ final RasterImageLayer rasLayer = (RasterImageLayer) dialog
+ .getLayerable(CLAYER);
+ min.setText(rasLayer.getMetadata().getStats().getMin(0) + "");
+ max.setText(rasLayer.getMetadata().getStats().getMax(0) + "");
+ nd.setText(rasLayer.getNoDataValue() + "");
+ source_nodata.setText(rasLayer.getNoDataValue() + "");
+ lv_field.setText(min_value + "");
+ uv_field.setText(max_value + "");
+ }
+
+ private void updateGUI(ActionEvent evt, MultiInputDialog dialog) {
+ switch (comboBox.getSelectedIndex()) {
+ case 0:
+ dialog.setSideBarDescription(CHANGE_NODATA_TIP);
+ mainPanel.setEnabled(true);
+ mainPanel.setVisible(true);
+ rangePanel.setEnabled(false);
+ rangePanel.setVisible(false);
+ resetPanel.setEnabled(false);
+ resetPanel.setVisible(false);
+ decimalPanel.setVisible(false);
+ decimalPanel.setEnabled(false);
+ break;
+ case 1:
+ dialog.setSideBarDescription(CHANGE_INTERVAL_TO_NODATA_TIP);
+ rangePanel.setEnabled(true);
+ rangePanel.setVisible(true);
+ rangePanel.setBorder(BorderFactory
+ .createTitledBorder(CHANGE_INTERVAL_TO_NODATA));
+ mainPanel.setEnabled(false);
+ mainPanel.setVisible(false);
+ resetPanel.setEnabled(false);
+ resetPanel.setVisible(false);
+ decimalPanel.setVisible(false);
+ decimalPanel.setEnabled(false);
+ break;
+ case 2:
+ dialog.setSideBarDescription(EXTRACT_INTERVAL_TIP);
+ rangePanel.setEnabled(true);
+ rangePanel.setVisible(true);
+ rangePanel.setBorder(BorderFactory
+ .createTitledBorder(EXTRACT_INTERVAL));
+ mainPanel.setEnabled(false);
+ mainPanel.setVisible(false);
+ resetPanel.setEnabled(false);
+ resetPanel.setVisible(false);
+ decimalPanel.setEnabled(false);
+ decimalPanel.setVisible(false);
+ break;
+ case 3:
+ dialog.setSideBarDescription(RESET_NODATA_TAG_TIP);
+ resetPanel.setEnabled(true);
+ resetPanel.setVisible(true);
+ mainPanel.setEnabled(false);
+ mainPanel.setVisible(false);
+ rangePanel.setEnabled(false);
+ rangePanel.setVisible(false);
+ decimalPanel.setEnabled(false);
+ decimalPanel.setVisible(false);
+ break;
+ case 4:
+ dialog.setSideBarDescription(SET_DECIMAL_TIP);
+ decimalPanel.setEnabled(true);
+ decimalPanel.setVisible(true);
+ resetPanel.setEnabled(false);
+ resetPanel.setVisible(false);
+ mainPanel.setEnabled(false);
+ mainPanel.setVisible(false);
+ rangePanel.setEnabled(false);
+ rangePanel.setVisible(false);
+ break;
+
+ }
+ }
+
+ private JPanel statisticPanel() {
+ final JPanel jPanel1 = new JPanel(new GridBagLayout());
+ jPanel1.setBorder(BorderFactory.createTitledBorder(STATISTICS));
+ nd = new JTextField(String.valueOf(rLayer.getNoDataValue()));
+ nd.setEditable(false);
+ max = new JTextField(min_value + "");
+ max.setEditable(false);
+ min = new JTextField(max_value + "");
+ min.setEditable(false);
+ final JLabel nd_label = new JLabel(NODATA);
+ final JLabel min_label = new JLabel(MIN);
+ final JLabel max_label = new JLabel(MAX);
+ FormUtils.addRowInGBL(jPanel1, 1, 0, nd_label, nd);
+ FormUtils.addRowInGBL(jPanel1, 1, 2, min_label, min);
+ FormUtils.addRowInGBL(jPanel1, 1, 4, max_label, max);
+ return jPanel1;
+ }
+
+ private JPanel resetNoDataPanel() {
+ resetPanel = new JPanel(new GridBagLayout());
+ resetPanel
+ .setBorder(BorderFactory.createTitledBorder(RESET_NODATA_TAG));
+ radioMin = new JRadioButton(RESET_TO_MIN);
+ radioMin.setSelected(true);
+ radioMax = new JRadioButton(RESET_TO_MAX);
+ final ButtonGroup group = new ButtonGroup();
+ group.add(radioMin);
+ group.add(radioMax);
+ FormUtils.addRowInGBL(resetPanel, 1, 0, radioMin);
+ FormUtils.addRowInGBL(resetPanel, 2, 0, radioMax);
+ return resetPanel;
+ }
+
+ private JPanel decimalPanel() {
+ decimalPanel = new JPanel(new GridBagLayout());
+ decimalPanel.setBorder(BorderFactory.createTitledBorder(SET_DECIMAL));
+ dimensionSpinner = new JSpinner(dimensionModel);
+ dimensionSpinner.setSize(20, 10);
+ FormUtils.addRowInGBL(decimalPanel, 1, 0, dimensionSpinner);
+ return decimalPanel;
+ }
+
+ public JPanel changeNoDataValuePanel() {
+ mainPanel = new JPanel(new GridBagLayout());
+ source_NoData_label = new JLabel(FROM);
+ target_NoData_label = new JLabel(TO);
+ source_nodata = new
JTextField(String.valueOf(rLayer.getNoDataValue()));
+ source_nodata.setEditable(false);
+ target_nodata = new JTextField(String.valueOf("-99999"));
+ source_nodata.addKeyListener(new java.awt.event.KeyAdapter() {
+ @Override
+ public void keyTyped(KeyEvent e) {
+ final char vChar = e.getKeyChar();
+ if (!(Character.isDigit(vChar) || (vChar == KeyEvent.VK_PERIOD)
+ || (vChar == KeyEvent.VK_BACK_SPACE) || (vChar ==
KeyEvent.VK_DELETE))) {
+ e.consume();
+ }
+ }
+ });
+ target_nodata.addKeyListener(new java.awt.event.KeyAdapter() {
+ @Override
+ public void keyTyped(KeyEvent e) {
+ final char vChar = e.getKeyChar();
+ if (!(Character.isDigit(vChar) || (vChar == KeyEvent.VK_PERIOD)
+ || (vChar == KeyEvent.VK_BACK_SPACE)
+ || (vChar == KeyEvent.VK_DELETE) || (vChar ==
KeyEvent.VK_MINUS))) {
+ e.consume();
+ }
+ }
+ });
+ mainPanel.setBorder(BorderFactory.createTitledBorder(CHANGE_NODATA));
+ FormUtils.addRowInGBL(mainPanel, 2, 0, source_NoData_label,
+ source_nodata);
+ FormUtils.addRowInGBL(mainPanel, 2, 3, target_NoData_label,
+ target_nodata);
+ return mainPanel;
+ }
+
+ public JPanel changeRangeToNoDataPanel() {
+ rangePanel = new JPanel(new GridBagLayout());
+ lv_field = new JTextField(String.valueOf(rLayer.getMetadata()
+ .getStats().getMin(0)));
+ lv_field.addKeyListener(new java.awt.event.KeyAdapter() {
+ @Override
+ public void keyTyped(KeyEvent e) {
+ final char vChar = e.getKeyChar();
+ if (!(Character.isDigit(vChar) || (vChar == KeyEvent.VK_PERIOD)
+ || (vChar == KeyEvent.VK_BACK_SPACE)
+ || (vChar == KeyEvent.VK_DELETE) || (vChar ==
KeyEvent.VK_MINUS))) {
+ e.consume();
+ }
+ }
+ });
+ uv_field = new JTextField(String.valueOf(rLayer.getMetadata()
+ .getStats().getMax(0)));
+ uv_field.addKeyListener(new java.awt.event.KeyAdapter() {
+ @Override
+ public void keyTyped(KeyEvent e) {
+ final char vChar = e.getKeyChar();
+ if (!(Character.isDigit(vChar) || (vChar == KeyEvent.VK_PERIOD)
+ || (vChar == KeyEvent.VK_BACK_SPACE)
+ || (vChar == KeyEvent.VK_DELETE) || (vChar ==
KeyEvent.VK_MINUS))) {
+ e.consume();
+ }
+ }
+ });
+ lv_label = new JLabel(LOWER_VALUE);
+ uv_label = new JLabel(UPPER_VALUE);
+ rangePanel.setBorder(BorderFactory
+ .createTitledBorder(CHANGE_INTERVAL_TO_NODATA));
+ FormUtils.addRowInGBL(rangePanel, 2, 0, lv_label, lv_field);
+ FormUtils.addRowInGBL(rangePanel, 2, 2, uv_label, uv_field);
+ return rangePanel;
+ }
+
+ public JPanel createOutputFilePanel(FileNameExtensionFilter filter) {
+ JPanel jPanel = new JPanel(new GridBagLayout());
+ jPanel = new javax.swing.JPanel();
+ final JLabel jLabel3 = new javax.swing.JLabel();
+ jTextField_RasterOut = new JTextField();
+ final JButton jButton_Dir = new JButton();
+ jTextField_RasterOut.setText("");
+ jButton_Dir.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent evt) {
+ File outputPathFile = null;
+ final JFileChooser chooser = new
GUIUtil.FileChooserWithOverwritePrompting();
+ chooser.setDialogTitle(getName());
+ chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
+
+ chooser.setSelectedFile(FileOperations.lastVisitedFolder);
+ chooser.setDialogType(JFileChooser.SAVE_DIALOG);
+ GUIUtil.removeChoosableFileFilters(chooser);
+ chooser.setFileFilter(filter);
+ final int ret = chooser.showOpenDialog(null);
+ if (ret == JFileChooser.APPROVE_OPTION) {
+ outputPathFile = FileUtil.removeExtensionIfAny(chooser
+ .getSelectedFile());
+ jTextField_RasterOut.setText(outputPathFile.getPath()
+ .concat(".tif"));
+ FileOperations.lastVisitedFolder = outputPathFile;
+ }
+ }
+ });
+ jLabel3.setText(OUTPUT_FILE);
+ jTextField_RasterOut.setEditable(false);
+ jButton_Dir.setIcon(icon16);
+ jTextField_RasterOut.setPreferredSize(new Dimension(250, 20));
+ FormUtils.addRowInGBL(jPanel, 3, 0, OUTPUT_FILE, jTextField_RasterOut);
+ FormUtils.addRowInGBL(jPanel, 3, 2, jButton_Dir);
+ return jPanel;
+ }
+
+ public String getOutputFilePath() {
+ return jTextField_RasterOut.getText();
+ }
+
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+}
\ No newline at end of file
Property changes on:
core/trunk/src/org/openjump/core/ui/plugin/raster/ManageDataPlugIn.java
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
_______________________________________________
Jump-pilot-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel