Revision: 5885 http://sourceforge.net/p/jump-pilot/code/5885 Author: ma15569 Date: 2018-06-21 07:51:36 +0000 (Thu, 21 Jun 2018) Log Message: ----------- Updated Profile plugin: * Plugin recognizes layer unit. * Absolute or relative slope output * Added capability to compute travel time on route depending to input flat, uphill and downhill speeds
Modified Paths: -------------- core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileGraphPlugIn.java Modified: core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileGraphPlugIn.java =================================================================== --- core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileGraphPlugIn.java 2018-06-21 07:45:30 UTC (rev 5884) +++ core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileGraphPlugIn.java 2018-06-21 07:51:36 UTC (rev 5885) @@ -33,13 +33,25 @@ package org.openjump.core.ui.plugin.raster; +import java.awt.Color; +import java.awt.FlowLayout; +import java.awt.Graphics; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import javax.swing.DefaultListCellRenderer; import javax.swing.Icon; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; import javax.swing.JRadioButton; +import javax.swing.JTextField; +import org.openjump.core.ccordsys.Unit; import org.openjump.core.rasterimage.RasterImageLayer; import com.vividsolutions.jts.geom.Coordinate; @@ -48,6 +60,7 @@ import com.vividsolutions.jump.I18N; import com.vividsolutions.jump.feature.Feature; import com.vividsolutions.jump.task.TaskMonitor; +import com.vividsolutions.jump.workbench.JUMPWorkbench; import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory; import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck; import com.vividsolutions.jump.workbench.plugin.PlugInContext; @@ -69,34 +82,56 @@ * dimension, cell statistics. */ - private final List<Coordinate> savedCoordinates = new ArrayList<Coordinate>(); - - final static String drawn = I18N + private final String DRAWN = I18N .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.draw-linstring-as-trace"); - final static String selected = I18N + private final String SELECTED = I18N .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.use-selected-linstring-as-trace");; + private final String sName = I18N .get("org.openjump.core.ui.plugin.raster.ProfileGraphPlugIn.Profile-Graph"); - private final String warning = I18N + private final String WARNING = I18N .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.select-one-linstring"); - public final static String PROFILE_INFO = I18N + public final String PROFILE_INFO = I18N .get("org.openjump.core.ui.plugin.layer.LayerPropertiesPlugIn.Info"); - public final static String PLOT = I18N + public final String PLOT = I18N .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.Profile-Plot"); + private final String OPTIONS = I18N + .get("com.vividsolutions.jump.workbench.ui.plugin.OptionsPlugIn"); + public static String HEIGHT = I18N + .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.values"); + public static String WIDTH = I18N + .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.2d-distance"); + public final String DESCRIPTION = I18N + .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.Description"); + private static String SELECT_BAND = I18N + .get("org.openjump.core.ui.plugin.raster.HistogramPlugIn.select-one-band"); + private static String LAYER_UNIT = I18N + .get("org.openjump.core.ui.plugin.file.ProjectInfoPlugIn.srs-unit"); + private static String VERICAL_AXES_LABEL = I18N + .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.vertical-axes-label"); + private static String HORIZONTAL_AXES_LABEL = I18N + .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.horizontal-axes-label"); - public final static String SLOPE = I18N - .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.Calculate-slope-profile"); - public final static String DESCRIPTION = I18N - .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.Description"); - final static String MONITOR_STRING = "Calculating profile..."; + private final List<Coordinate> savedCoordinates = new ArrayList<Coordinate>(); public static String CLAYER = GenericNames.SELECT_LAYER; private boolean drawnType = true; private boolean selectedType = false; + public static String UNIT; + + public static RasterImageLayer rLayer; + + public static int numband; + public static JTextField unitfiled = new JTextField(""); + public static MultiInputDialog dialog; - // public static JCheckBox infoBox; - JRadioButton radioButton1 = new JRadioButton(drawn, drawnType); - JRadioButton radioButton2 = new JRadioButton(selected, selectedType); + JRadioButton radioButton1 = new JRadioButton(DRAWN, drawnType); + JRadioButton radioButton2 = new JRadioButton(SELECTED, selectedType); + JComboBox<RasterImageLayer> box; + JComboBox<String> comboBox = new JComboBox<String>(); + JPanel panel1 = new JPanel(new FlowLayout()); + JLabel label1; + @Override public void initialize(PlugInContext context) throws Exception { @@ -116,8 +151,12 @@ } private void getDialogValues(MultiInputDialog dialog) { - drawnType = dialog.getBoolean(drawn); - selectedType = dialog.getBoolean(selected); + drawnType = dialog.getBoolean(DRAWN); + selectedType = dialog.getBoolean(SELECTED); + HEIGHT = dialog.getText(HORIZONTAL_AXES_LABEL); + WIDTH = dialog.getText(VERICAL_AXES_LABEL); + UNIT = dialog.getText(LAYER_UNIT); + rLayer = (RasterImageLayer) dialog.getLayerable(CLAYER); } @@ -124,26 +163,94 @@ private void setDialogValues(MultiInputDialog dialog, PlugInContext context) { final Collection<RasterImageLayer> rlayers = context.getTask() .getLayerManager().getLayerables(RasterImageLayer.class); + final ArrayList<String> srsArray = new ArrayList<String>(); + srsArray.add("metre"); + srsArray.add("foot"); + for (final RasterImageLayer currentLayer : rlayers) { + final String srs = currentLayer.getSRSInfo().getUnit().toString(); + + if (!srsArray.contains(srs)) { + srsArray.add(Unit.find(srs).toString()); + } + + } + + final RasterImageLayer firstElement = (RasterImageLayer) rlayers + .toArray()[0]; + final String srsCode = firstElement.getSRSInfo().getUnit().toString(); + final String OUTPUT_GROUP = "Match Type"; - dialog.setSideBarDescription(DESCRIPTION); - dialog.addLayerableComboBox(CLAYER, context.getLayerManager() + dialog.addSubTitle(PLOT); + box = dialog.addLayerableComboBox(CLAYER, context.getLayerManager() .getRasterImageLayers().get(0), "", rlayers); + // box.setSelectedItem(srsCode); - dialog.addRadioButton(drawn, OUTPUT_GROUP, drawnType, null); + // unitfiled = dialog.addTextField(LAYER_UNIT, srsCode, 20, null, null); + // unitfiled.setBorder(javax.swing.BorderFactory.createEmptyBorder()); + // unitfiled.setEditable(false); + comboBox = dialog.addComboBox(LAYER_UNIT, "", srsArray, null); + // Arrays.asList("metre", "foot", "Unknown"), null); + comboBox.setRenderer(new DefaultListCellRenderer() { + /** + * + */ + private static final long serialVersionUID = 1L; + @Override + public void paint(Graphics g) { + setForeground(Color.BLACK); + super.paint(g); + } + }); + comboBox.setEnabled(srsCode.equals("Unknown")); + + comboBox.setSelectedItem(srsCode); + + dialog.addRadioButton(DRAWN, OUTPUT_GROUP, drawnType, null); + final Collection<Feature> features = context.getLayerViewPanel() .getSelectionManager().getFeaturesWithSelectedItems(); if (features.size() == 0 || features.size() > 1) { - dialog.addRadioButton(selected, OUTPUT_GROUP, selectedType, null) + dialog.addRadioButton(SELECTED, OUTPUT_GROUP, selectedType, null) .setEnabled(false); } else { - dialog.addRadioButton(selected, OUTPUT_GROUP, selectedType, null) + dialog.addRadioButton(SELECTED, OUTPUT_GROUP, selectedType, null) .setEnabled(true); } + dialog.addSubTitle(OPTIONS); + + dialog.addTextField(HORIZONTAL_AXES_LABEL, WIDTH, 20, null, null); + dialog.addTextField(VERICAL_AXES_LABEL, HEIGHT, 20, null, null); + box.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + final String layerUnit = getLayer().getSRSInfo().getUnit() + .toString(); + + unitfiled.setText(layerUnit); + updateComponents(); + dialog.repaint(); + + } + }); + } + public void updateComponents() { + + final String layerUnit = getLayer().getSRSInfo().getUnit().toString(); + comboBox.setEnabled(layerUnit.equals("Unknown")); + comboBox.setSelectedItem(layerUnit); + + } + + public static RasterImageLayer getLayer() { + return dialog.getRasterLayer(ProfileGraphPlugIn.CLAYER); + + } + public Icon getIcon() { return IconLoader.icon("profile.png"); } @@ -162,9 +269,14 @@ @Override public void run(TaskMonitor monitor, PlugInContext context) throws Exception { - if (ProfileUtils.resultFC != null || ProfileUtils.nPoints > 0) { - ProfileUtils.resultFC.clear(); - ProfileUtils.nPoints = 0; + + monitor.allowCancellationRequests(); + monitor.report(getName() + + ": " + + I18N.get("org.openjump.core.ui.plugin.edittoolbox.cursortools.FillPolygonTool.computing")); + if (ProfileGraphGUI.resultFC != null || ProfileGraphGUI.nPoints > 0) { + ProfileGraphGUI.resultFC.clear(); + ProfileGraphGUI.nPoints = 0; } savedCoordinates.clear(); getDialogValues(dialog); @@ -182,9 +294,29 @@ return; } + final RasterImageLayer selLayer = dialog + .getRasterLayer(ProfileGraphPlugIn.CLAYER); + + numband = 0; + if (selLayer.getNumBands() > 1) { + final String[] bands = { "0", "1", "2" }; + final String stringInput = (String) JOptionPane.showInputDialog( + JUMPWorkbench.getInstance().getFrame(), SELECT_BAND, sName, + JOptionPane.PLAIN_MESSAGE, null, bands, "0"); + + try { + numband = Integer.parseInt(stringInput); + } catch (final NumberFormatException e) { + return; // The typed text was not an integer + // band = 0; + } + } + if (drawnType) { final ProfileGraphTool profileTool = new ProfileGraphTool(); + context.getLayerViewPanel().setCurrentCursorTool(profileTool); + } else if (selectedType) { @@ -203,10 +335,11 @@ if (geom instanceof LineString) { final Coordinate[] coords = geom.getCoordinates(); - ProfileUtils.calculateProfile(coords); + ProfileGraphGUI.calculateProfile(coords); } else { - context.getWorkbenchFrame().warnUser(warning); + context.getWorkbenchFrame().warnUser(WARNING); + } } @@ -213,4 +346,12 @@ } } + + /* + * Return type of the Sextante Raster Layer as String + */ + public String filetype(String ext) { + return Unit.find(ext).toString(); + } + } ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel