Revision: 4345 http://sourceforge.net/p/jump-pilot/code/4345 Author: ma15569 Date: 2015-03-22 13:50:21 +0000 (Sun, 22 Mar 2015) Log Message: ----------- Upgrade class: added Raster statistics resume and output file chooser
Modified Paths: -------------- core/trunk/src/org/openjump/core/ui/plugin/raster/nodata/ChangeNoDataValuePlugIn.java Modified: core/trunk/src/org/openjump/core/ui/plugin/raster/nodata/ChangeNoDataValuePlugIn.java =================================================================== --- core/trunk/src/org/openjump/core/ui/plugin/raster/nodata/ChangeNoDataValuePlugIn.java 2015-03-22 13:48:20 UTC (rev 4344) +++ core/trunk/src/org/openjump/core/ui/plugin/raster/nodata/ChangeNoDataValuePlugIn.java 2015-03-22 13:50:21 UTC (rev 4345) @@ -1,5 +1,9 @@ package org.openjump.core.ui.plugin.raster.nodata; +import it.betastudio.adbtoolbox.libs.ExtensionFilter; +import it.betastudio.adbtoolbox.libs.FileOperations; + +import java.awt.Dimension; import java.awt.GridBagLayout; import java.awt.event.KeyEvent; import java.awt.geom.NoninvertibleTransformException; @@ -16,8 +20,11 @@ import java.text.NumberFormat; import java.util.Properties; +import javax.swing.BorderFactory; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JFileChooser; import javax.swing.JLabel; -import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; @@ -38,13 +45,17 @@ import com.vividsolutions.jump.I18N; 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.AbstractPlugIn; import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory; import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck; import com.vividsolutions.jump.workbench.plugin.PlugInContext; +import com.vividsolutions.jump.workbench.ui.GUIUtil; import com.vividsolutions.jump.workbench.ui.GenericNames; import com.vividsolutions.jump.workbench.ui.MenuNames; +import com.vividsolutions.jump.workbench.ui.MultiInputDialog; import com.vividsolutions.jump.workbench.ui.Viewport; +import com.vividsolutions.jump.workbench.ui.images.IconLoader; import com.vividsolutions.jump.workbench.ui.plugin.FeatureInstaller; public class ChangeNoDataValuePlugIn extends AbstractPlugIn { @@ -58,9 +69,12 @@ private static String propertiesFile = LoadSextanteRasterImagePlugIn .getPropertiesFile(); NumberFormat cellFormat = null; - + private String OUTPUT_FILE = I18N.get("driver.DriverManager.file-to-save") + + ": "; private String SUBMENU = I18N .get("org.openjump.core.ui.plugin.raster.nodata.menu"); + private static ImageIcon icon16 = IconLoader + .icon("fugue/folder-horizontal-open_16.png"); public ChangeNoDataValuePlugIn() { @@ -86,7 +100,30 @@ reportNothingToUndoYet(context); RasterImageLayer rLayer = (RasterImageLayer) LayerTools .getSelectedLayerable(context, RasterImageLayer.class); - JPanel firstPanel = new JPanel(new GridBagLayout()); + MultiInputDialog dialog = new MultiInputDialog( + context.getWorkbenchFrame(), getName(), true); + + // Top panel. Visualize nodata/max/min cell values + JPanel jPanel1 = new JPanel(new GridBagLayout()); + jPanel1.setBorder(BorderFactory.createTitledBorder(I18N + .get("ui.plugin.LayerStatisticsPlugIn.layer-statistics"))); + OpenJUMPSextanteRasterLayer rstLayer = new OpenJUMPSextanteRasterLayer(); + rstLayer.create(rLayer); + JTextField nd = new JTextField(String.valueOf(rLayer.getNoDataValue())); + nd.setEditable(false); + JTextField max = new JTextField(String.valueOf(rstLayer.getMaxValue())); + max.setEditable(false); + JTextField min = new JTextField(String.valueOf(rstLayer.getMinValue())); + min.setEditable(false); + JLabel nd_label = new JLabel("nodata:"); + JLabel min_label = new JLabel("min:"); + 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); + + // Main Panel. Set range source-target no data value + JPanel mainPanel = new JPanel(new GridBagLayout()); JLabel source_NoData_label = new JLabel( I18N.get("org.openjump.core.ui.plugin.raster.nodata.ChangeNoDataValuePlugIn.from")); JLabel target_NoData_label = new JLabel( @@ -110,40 +147,59 @@ public void keyTyped(KeyEvent e) { char vChar = e.getKeyChar(); if (!(Character.isDigit(vChar) || (vChar == KeyEvent.VK_PERIOD) - || (vChar == KeyEvent.VK_BACK_SPACE) || (vChar == KeyEvent.VK_DELETE))) { + || (vChar == KeyEvent.VK_BACK_SPACE) + || (vChar == KeyEvent.VK_DELETE) || (vChar == KeyEvent.VK_MINUS))) { e.consume(); } } }); - - FormUtils.addRowInGBL(firstPanel, 2, 0, source_NoData_label, + FormUtils.addRowInGBL(mainPanel, 2, 0, source_NoData_label, source_nodata); - FormUtils.addRowInGBL(firstPanel, 2, 3, target_NoData_label, + FormUtils.addRowInGBL(mainPanel, 2, 3, target_NoData_label, target_nodata); - int option = JOptionPane.showConfirmDialog(null, firstPanel, - PLUGINNAME, JOptionPane.OK_CANCEL_OPTION, - JOptionPane.PLAIN_MESSAGE); + // Lower panel + JPanel jPanel2 = new JPanel(new GridBagLayout()); + jPanel2 = new javax.swing.JPanel(); + JLabel jLabel3 = new javax.swing.JLabel(); + jTextField_RasterOut = new javax.swing.JTextField(); + JButton jButton_Dir = new javax.swing.JButton(); + jTextField_RasterOut.setText(""); + jButton_Dir.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton_RasterOutActionPerformed(evt); + } + }); + jLabel3.setText(OUTPUT_FILE); + jTextField_RasterOut.setEditable(true); + jButton_Dir.setIcon(icon16); + jTextField_RasterOut.setPreferredSize(new Dimension(250, 20)); + // FormUtils.addRowInGBL(jPanel2, 3, 0, jLabel3); + FormUtils.addRowInGBL(jPanel2, 3, 0, OUTPUT_FILE, jTextField_RasterOut); + FormUtils.addRowInGBL(jPanel2, 3, 2, jButton_Dir); + dialog.addRow(jPanel1); + dialog.addRow(mainPanel); + dialog.addRow(jPanel2); - switch (option) { + GUIUtil.centreOnWindow(dialog); + dialog.setVisible(true); - case JOptionPane.CANCEL_OPTION: + if (!dialog.wasOKPressed()) { + return false; + } - break; + else { - case JOptionPane.OK_OPTION: + String path = jTextField_RasterOut.getText(); - String redName = context.getLayerManager().uniqueLayerName( - rLayer.getName()); - int boxToInt = 0; + int band = 0; - File flt_outFile = new File(System.getProperty("java.io.tmpdir") - .concat(File.separator).concat(redName).concat(".flt")); - File hdr_outFile = new File(System.getProperty("java.io.tmpdir") - .concat(File.separator).concat(redName).concat(".hdr")); + File flt_outFile = new File(path.concat(".flt")); + File hdr_outFile = new File(path.concat(".hdr")); + float newdata = Float.parseFloat(target_nodata.getText()); float olddata = (float) rLayer.getNoDataValue(); - saveFLT(flt_outFile, context, rLayer, boxToInt, olddata, newdata); + saveFLT(flt_outFile, context, rLayer, band, olddata, newdata); saveHDR(hdr_outFile, context, rLayer, newdata); loadFLT(flt_outFile, context); } @@ -295,7 +351,7 @@ context.getWorkbenchContext().getLayerManager(), flt_outFile.getAbsolutePath(), imageAndMetadata.getImage(), imageEnvelope); - String catName = "Temp";// StandardCategoryNames.RESULT; + String catName = StandardCategoryNames.WORKING; try { catName = ((Category) context.getLayerNamePanel() .getSelectedCategories().toArray()[0]).getName(); @@ -319,4 +375,26 @@ return multiEnableCheck; } + JTextField jTextField_RasterOut = new JTextField(); + + private void jButton_RasterOutActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton_RasterOutActionPerformed + + File outputPathFile = null; + JFileChooser chooser = new JFileChooser(); + chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + chooser.setSelectedFile(FileOperations.lastVisitedFolder); + chooser.setDialogType(JFileChooser.SAVE_DIALOG); + ExtensionFilter filter = new ExtensionFilter(); + filter.addExtension("flt"); + chooser.setFileFilter(filter); + int ret = chooser.showOpenDialog(null); + if (ret == JFileChooser.APPROVE_OPTION) { + outputPathFile = chooser.getSelectedFile(); + // outputpathString = outputpathFile.getPath(); + jTextField_RasterOut.setText(outputPathFile.getPath()); + FileOperations.lastVisitedFolder = outputPathFile; + } + + } + } \ No newline at end of file ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel