Revision: 5874 http://sourceforge.net/p/jump-pilot/code/5874 Author: ma15569 Date: 2018-06-11 20:02:46 +0000 (Mon, 11 Jun 2018) Log Message: ----------- Added capability to draw a slope profile
Modified Paths: -------------- core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileGraphPlugIn.java core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileUtils.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-11 19:54:35 UTC (rev 5873) +++ core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileGraphPlugIn.java 2018-06-11 20:02:46 UTC (rev 5874) @@ -40,7 +40,6 @@ import javax.swing.Icon; import javax.swing.JRadioButton; -import org.openjump.core.apitools.LayerTools; import org.openjump.core.rasterimage.RasterImageLayer; import com.vividsolutions.jts.geom.Coordinate; @@ -49,8 +48,6 @@ 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.WorkbenchContext; import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory; import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck; import com.vividsolutions.jump.workbench.plugin.PlugInContext; @@ -74,34 +71,41 @@ private final List<Coordinate> savedCoordinates = new ArrayList<Coordinate>(); - private RasterImageLayer rLayer = null; - final static String drawn = I18N .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.draw-linstring-as-trace"); final static String selected = I18N .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.use-selected-linstring-as-trace");; - private String sName; + private final String sName = I18N + .get("org.openjump.core.ui.plugin.raster.ProfileGraphPlugIn.Profile-Graph"); private final String warning = I18N - .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.select-one-linstring");; + .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.select-one-linstring"); + public final static String PROFILE_INFO = I18N + .get("org.openjump.core.ui.plugin.layer.LayerPropertiesPlugIn.Info"); + public final static String PLOT = I18N + .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.Profile-Plot"); + + 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..."; public static String CLAYER = GenericNames.SELECT_LAYER; private boolean drawnType = true; private boolean selectedType = false; public static MultiInputDialog dialog; + // public static JCheckBox infoBox; JRadioButton radioButton1 = new JRadioButton(drawn, drawnType); JRadioButton radioButton2 = new JRadioButton(selected, selectedType); @Override public void initialize(PlugInContext context) throws Exception { - sName = I18N - .get("org.openjump.core.ui.plugin.raster.ProfileGraphPlugIn.Profile-Graph"); + FeatureInstaller.getInstance().addMainMenuPlugin(this, new String[] { MenuNames.RASTER }, sName + "...", false, - getIcon(), createEnableCheck(context.getWorkbenchContext())); + getIcon(), check()); } - public static MultiEnableCheck createEnableCheck( - WorkbenchContext workbenchContext) { + public static MultiEnableCheck check() { final EnableCheckFactory checkFactory = EnableCheckFactory .getInstance(); return new MultiEnableCheck() @@ -114,7 +118,7 @@ private void getDialogValues(MultiInputDialog dialog) { drawnType = dialog.getBoolean(drawn); selectedType = dialog.getBoolean(selected); - // dialog.getLayer(CLAYER); + } private void setDialogValues(MultiInputDialog dialog, PlugInContext context) { @@ -121,9 +125,11 @@ final Collection<RasterImageLayer> rlayers = context.getTask() .getLayerManager().getLayerables(RasterImageLayer.class); final String OUTPUT_GROUP = "Match Type"; - dialog.setTitle(sName); + + dialog.setSideBarDescription(DESCRIPTION); dialog.addLayerableComboBox(CLAYER, context.getLayerManager() .getRasterImageLayers().get(0), "", rlayers); + dialog.addRadioButton(drawn, OUTPUT_GROUP, drawnType, null); final Collection<Feature> features = context.getLayerViewPanel() @@ -136,8 +142,6 @@ .setEnabled(true); } - dialog.setResizable(false); - } public Icon getIcon() { @@ -162,24 +166,22 @@ ProfileUtils.resultFC.clear(); ProfileUtils.nPoints = 0; } - savedCoordinates.clear(); - rLayer = (RasterImageLayer) LayerTools.getSelectedLayerable(context, - RasterImageLayer.class); - if (rLayer == null) { - context.getLayerViewPanel() - .getContext() - .warnUser( - I18N.get("pirol.plugIns.EditAttributeByFormulaPlugIn.no-layer-selected")); - return; - } + getDialogValues(dialog); + // rLayer = (RasterImageLayer) LayerTools.getSelectedLayerable(context, + // RasterImageLayer.class); + // if (layerName == null) { + // context.getLayerViewPanel() + // .getContext() + // .warnUser( + // I18N.get("pirol.plugIns.EditAttributeByFormulaPlugIn.no-layer-selected")); + // return; + // } if (!dialog.wasOKPressed()) { return; } - getDialogValues(dialog); - if (drawnType) { final ProfileGraphTool profileTool = new ProfileGraphTool(); context.getLayerViewPanel().setCurrentCursorTool(profileTool); @@ -190,9 +192,7 @@ final Collection<Feature> features = context.getLayerViewPanel() .getSelectionManager().getFeaturesWithSelectedItems(); if (features.size() == 0 || features.size() > 1) { - JUMPWorkbench - .getInstance() - .getFrame() + context.getWorkbenchFrame() .warnUser( I18N.getMessage( "com.vividsolutions.jump.workbench.plugin.Exactly-n-features-must-be-selected", //$NON-NLS-1$ @@ -202,9 +202,11 @@ final Geometry geom = features.iterator().next().getGeometry(); if (geom instanceof LineString) { final Coordinate[] coords = geom.getCoordinates(); + ProfileUtils.calculateProfile(coords); + } else { - JUMPWorkbench.getInstance().getFrame().warnUser(warning); + context.getWorkbenchFrame().warnUser(warning); } } Modified: core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileUtils.java =================================================================== --- core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileUtils.java 2018-06-11 19:54:35 UTC (rev 5873) +++ core/trunk/src/org/openjump/core/ui/plugin/raster/ProfileUtils.java 2018-06-11 20:02:46 UTC (rev 5874) @@ -1,19 +1,31 @@ package org.openjump.core.ui.plugin.raster; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.io.IOException; import java.text.DecimalFormat; -import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; -import java.util.Locale; import java.util.Random; +import javax.swing.JButton; +import javax.swing.JInternalFrame; +import javax.swing.JLayeredPane; +import javax.swing.JTable; +import javax.swing.table.DefaultTableModel; + +import org.math.plot.plots.Plot; import org.math.plot.render.AbstractDrawer; import org.openjump.core.attributeoperations.AttributeOp; import org.openjump.core.rasterimage.RasterImageLayer; import org.openjump.core.ui.plot.Plot2DPanelOJ; +import org.openjump.sextante.core.ObjectAndDescription; import org.openjump.sextante.gui.additionalResults.AdditionalResults; +import org.openjump.sextante.gui.additionalResults.AdditionalResultsFrame; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Geometry; @@ -30,8 +42,11 @@ import com.vividsolutions.jump.workbench.JUMPWorkbench; import com.vividsolutions.jump.workbench.WorkbenchContext; import com.vividsolutions.jump.workbench.model.StandardCategoryNames; -import com.vividsolutions.jump.workbench.ui.FeatureCollectionPanel; +import com.vividsolutions.jump.workbench.ui.HTMLFrame; import com.vividsolutions.jump.workbench.ui.HTMLPanel; +import com.vividsolutions.jump.workbench.ui.JTablePanel; +import com.vividsolutions.jump.workbench.ui.TableFrame; +import com.vividsolutions.jump.workbench.ui.images.IconLoader; public class ProfileUtils { @@ -66,6 +81,11 @@ public final static String WIDTH = I18N .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.2d-distance"); + public final static String TIMES = I18N + .get("org.openjump.core.ui.plugin.edittoolbox.cursortools.Travel-time"); + public final static String SLOPE = I18N + .get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.Slope"); + public static WorkbenchContext context = JUMPWorkbench.getInstance() .getFrame().getContext(); @@ -78,11 +98,11 @@ public static GeometryFactory gf = new GeometryFactory(); public static FeatureCollection resultFC = null; public static FeatureSchema resultFSchema = null; - public static double dDist = 0, dHorzDist = 0; + public static double dDist = 0, dHorzDist = 0, dSlope = 0, dY = 0; public static double m_dLastX, m_dLastY, m_dLastZ; + public static int nPoints = 0; public static int n = 0; - public static ArrayList<Coordinate> coordinates = new ArrayList<Coordinate>(); static double max, min, sum, mean, width, height, slope, cellsize, profLenght; @@ -96,31 +116,37 @@ final LineString line = gf.createLineString(coords); if (line.within(rLayer.getWholeImageEnvelopeAsGeometry())) { final Random rand = new Random(); + n = rand.nextInt(100) + 1; processLine(line); if ((resultFC != null) && (resultFC.size() > 0)) { final FeatureDataset fd = new FeatureDataset(resultFSchema); fd.addAll(resultFC.getFeatures()); + max = AttributeOp.evaluateAttributes(AttributeOp.MAX, + fd.getFeatures(), "Z"); + min = AttributeOp.evaluateAttributes(AttributeOp.MIN, + fd.getFeatures(), "Z"); + width = AttributeOp.evaluateAttributes(AttributeOp.MAX, + fd.getFeatures(), "PlaneDist") + - AttributeOp.evaluateAttributes(AttributeOp.MIN, + fd.getFeatures(), "PlaneDist"); + height = max - min; + mean = AttributeOp.evaluateAttributes(AttributeOp.MEAN, + fd.getFeatures(), "Z"); + sum = AttributeOp.evaluateAttributes(AttributeOp.SUM, + fd.getFeatures(), "Z"); + slope = Math.toDegrees(Math.atan((max - min) / width)); + + profLenght = AttributeOp.evaluateAttributes(AttributeOp.MAX, + fd.getFeatures(), "TerrainDist"); + + // featColl().addAll(resultFC.getFeatures()); context.getLayerManager().addLayer( - StandardCategoryNames.RESULT, PROFILEPTS, fd); + StandardCategoryNames.RESULT, + PLOT + "-" + n + " " + PROFILEPTS, fd); } - - final FeatureCollectionPanel fPan = new FeatureCollectionPanel( - resultFC); - fPan.setName("" + n); - fPan.getSouthPanel().setVisible(false); - AdditionalResults.addAdditionalResult(PLOT + "-" + n + " " - + PROFILE_INFO, getStatisticPanel(rLayer)); - AdditionalResults - .addAdditionalResult( - PLOT - + "-" - + n - + " " - + I18N.get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.values"), - fPan); AdditionalResults.addAdditionalResultAndShow(PLOT + "-" + n, - getPlotPanel(resultFC)); + getPlotPanel(resultFC, "" + n)); } else { context.getLayerViewPanel() @@ -188,7 +214,6 @@ resultFSchema.addAttribute("Z", AttributeType.DOUBLE); resultFSchema.addAttribute("PlaneDist", AttributeType.DOUBLE); resultFSchema.addAttribute("TerrainDist", AttributeType.DOUBLE); - // resultFSchema.addAttribute("Section", AttributeType.STRING); resultFC = new FeatureDataset(resultFSchema); } double z; @@ -198,6 +223,7 @@ dDist = 0.0; dHorzDist = 0.0; } else { + dDX = x - m_dLastX; dDY = y - m_dLastY; if (z == getLayer().getNoDataValue() @@ -208,6 +234,7 @@ } dDist += Math.sqrt(dDX * dDX + dDY * dDY); dHorzDist += Math.sqrt(dDX * dDX + dDY * dDY + dDZ * dDZ); + } m_dLastX = x; m_dLastY = y; @@ -225,82 +252,16 @@ fpoint.setAttribute("TerrainDist", new Double(dHorzDist)); final Coordinate coord = new Coordinate(new Double(z), new Double( dHorzDist)); - coordinates.add(coord); resultFC.add(fpoint); } - // Giuseppe Aruta (2018-4-17) Terrain distance from FeatureCollection rather - // then from Geometry - public static HTMLPanel getStatisticPanel(RasterImageLayer rLayer) { - final HTMLPanel outpanel = new HTMLPanel(); - outpanel.getRecordPanel().removeAll(); - final Feature first = resultFC.getFeatures().get(0); - final Feature last = resultFC.getFeatures().get(resultFC.size() - 1); - final double xmin = (double) first.getAttribute("X"); - final double ymin = (double) first.getAttribute("Y"); - final double xmax = (double) last.getAttribute("X"); - final double ymax = (double) last.getAttribute("Y"); - - max = AttributeOp.evaluateAttributes(AttributeOp.MAX, - resultFC.getFeatures(), "Z"); - min = AttributeOp.evaluateAttributes(AttributeOp.MIN, - resultFC.getFeatures(), "Z"); - width = AttributeOp.evaluateAttributes(AttributeOp.MAX, - resultFC.getFeatures(), "PlaneDist") - - AttributeOp.evaluateAttributes(AttributeOp.MIN, - resultFC.getFeatures(), "PlaneDist"); - height = max - min; - mean = AttributeOp.evaluateAttributes(AttributeOp.MEAN, - resultFC.getFeatures(), "Z"); - sum = AttributeOp.evaluateAttributes(AttributeOp.SUM, - resultFC.getFeatures(), "Z"); - /* - * Overwrite Locale to UK Decimal format ####.## - */ - final Locale locale = new Locale("en", "UK"); - final String pattern = "###.###"; - final DecimalFormat df = (DecimalFormat) NumberFormat - .getNumberInstance(locale); - df.applyPattern(pattern); - slope = Math.toDegrees(Math.atan((max - min) / width)); - cellsize = (rLayer.getWholeImageEnvelope().getMaxX() - rLayer - .getWholeImageEnvelope().getMinX()) - / rLayer.getOrigImageWidth(); - profLenght = AttributeOp.evaluateAttributes(AttributeOp.MAX, - resultFC.getFeatures(), "TerrainDist"); - - String htmlString = "<HTML><BODY>"; - htmlString += "<b><font face=\"" + darkLabelFont + "\">" + LAYER_NAME - + ": </b>" + rLayer.getName() + "<br>"; - htmlString += "<b><font face=\"" + darkLabelFont + "\">" - + PROFILE_LENGTH + ": </b>" + df.format(profLenght) + "<br>"; - htmlString += "<b><font face=\"" + darkLabelFont + "\">" + WIDTH - + ": </b>" + df.format(width) + "<br>"; - htmlString += "<b><font face=\"" + darkLabelFont + "\">" + HEIGHT - + ": </b>" + df.format(height) + "<br>"; - htmlString += "<b><font face=\"" + darkLabelFont + "\">" + MEAN_SLOPE - + ": </b>" + df.format(slope) + "\xB0<br>"; - htmlString += "<b><font face=\"" + darkLabelFont + "\">" - + STARTING_POINT + ": </b>" + df.format(xmin) + " - " - + df.format(ymin) + "<br>"; - htmlString += "<b><font face=\"" + darkLabelFont + "\">" + ENDING_POINT - + ": </b>" + df.format(xmax) + " - " + df.format(ymax) + "<br>"; - - htmlString += "<b><font face=\"" + darkLabelFont + "\">" + MIN - + ": </b>" + new Double(min) + "<br>"; - htmlString += "<b><font face=\"" + darkLabelFont + "\">" + MAX - + ": </b>" + new Double(max) + "</font><br>"; - htmlString += "</DIV></BODY></HTML>"; - outpanel.createNewDocument(); - outpanel.append(htmlString); - outpanel.getSaveButton().setVisible(false); - return outpanel; - } - - public static Plot2DPanelOJ getPlotPanel(FeatureCollection fc) { + public static Plot2DPanelOJ getPlotPanel(FeatureCollection fc, String name) { final Plot2DPanelOJ plot2dA = new Plot2DPanelOJ(); + plot2dA.setName(name); plot2dA.removeAllPlots(); + plot2dA.plotToolBar.remove(5); + plot2dA.plotToolBar.remove(4); // Build a 2D data set final double[][] datas1 = new double[fc.size()][2]; @@ -309,14 +270,8 @@ datas1[j][0] = (Double) f.getAttribute("PlaneDist"); datas1[j][1] = (Double) f.getAttribute("Z"); } + plot2dA.addLinePlot("Profile", datas1); - // To avoid that two or more consequiensal plots are drawn together - - // Build the 2D scatterplot of the datas in a Panel - // LINE, SCATTER, BAR, QUANTILE, STAIRCASE, (HISTOGRAMM?) - // Plot2DPanelOJ plot2dA = new Plot2DPanelOJ(); - plot2dA.addLinePlot("graph", datas1); - // plot2dA.addScatterPlot("pts",datas1); // ==================== plot2dA.setAxisLabel(0, WIDTH); @@ -327,9 +282,290 @@ plot2dA.getAxis(1).setLabelPosition(-0.15, 0.5); // change axis title angle relatively to the base of the plot plot2dA.getAxis(1).setLabelAngle(-Math.PI / 2); + + // Table part + double[][] dataTableDouble = null; + Object[][] dataTableObject = null; + for (final Plot plot2 : plot2dA.getPlots()) { + dataTableDouble = plot2.getData(); + } + dataTableObject = plot2dA.plotCanvas.reverseMapedData(dataTableDouble); + final double[][] slopeMatrixData = getRelativeSlope(dataTableObject); + final Object[] slopeData = getXdoubleData(slopeMatrixData); + final Object[] ZData = getYData(dataTableObject); + final Object[] LData = getXData(dataTableObject); + // final Object[] data_3d = get3Ddata(dataTableObject); + + // Buttons/////// + final JButton tableBtn = new JButton(IconLoader.icon("Row_16.gif")); + tableBtn.setToolTipText(PROFILE_INFO); + tableBtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + + final TableFrame freqFrame = new TableFrame(); + freqFrame.setLayout(new BorderLayout()); + freqFrame.setResizable(true); + freqFrame.setClosable(true); + freqFrame.setIconifiable(true); + freqFrame.setMaximizable(true); + freqFrame.setPreferredSize(new Dimension(900, 450)); + freqFrame.setSize(900, 450); + freqFrame.setLayer(JLayeredPane.MODAL_LAYER); + freqFrame.setTitle(PROFILE_INFO); + + final JTable jTable = new JTable(); + + final DefaultTableModel dtm = (DefaultTableModel) jTable + .getModel(); + dtm.addColumn("Z", ZData); + dtm.addColumn("PlaneDist", LData); + dtm.addColumn(SLOPE + " (\xB0)", slopeData); + final JTablePanel jTablePanel = new JTablePanel(dtm); + jTablePanel.getCommandPanel().setVisible(false); + freqFrame.add(jTablePanel); + freqFrame.setVisible(true); + context.getWorkbench().getFrame() + .addInternalFrame(freqFrame, true, true); + } + }); + + final JButton slopeBtn = new JButton( + IconLoader.icon("profileSlope.png")); + slopeBtn.setToolTipText(ProfileGraphPlugIn.SLOPE); + slopeBtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + + final Plot2DPanelOJ plotSlope = new Plot2DPanelOJ(); + plotSlope.plotToolBar.remove(5); + plotSlope.plotToolBar.remove(4); + plotSlope.setName(SLOPE); + plotSlope.addLinePlot(SLOPE, Color.red, slopeMatrixData); + plotSlope.setAxisLabel(0, WIDTH); + plotSlope.setAxisLabel(1, SLOPE + " (\xB0)"); + plotSlope.getAxis(0).setLabelPosition(0.5, -0.15); + plotSlope.getAxis(1).setLabelPosition(-0.15, 0.5); + plotSlope.getAxis(1).setLabelAngle(-Math.PI / 2); + plotSlope.setFixedBounds(0, 0, width); + final ArrayList<ObjectAndDescription> m_Components = new ArrayList<ObjectAndDescription>(); + final ObjectAndDescription ob = new ObjectAndDescription( + "Slope", + // If the string below is activated, slope profile can + // be exported also to dxf + // The main problem is to fix the Y axe scale on + // AdditionalResultsFrame.exportToDxf(..) method + // I18N.get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.Profile-Plot"), + plotSlope); + m_Components.add(ob); + + final AdditionalResultsFrame slopeFrame = new AdditionalResultsFrame( + m_Components); + slopeFrame.setTitle("Slope"); + slopeFrame.setName(I18N.get("Slope")); + slopeFrame.pack(); + final JInternalFrame[] frames = JUMPWorkbench.getInstance() + .getFrame().getInternalFrames(); + final ArrayList<JInternalFrame> list = new ArrayList<JInternalFrame>(); + for (final JInternalFrame iFrame : frames) { + if (iFrame instanceof AdditionalResultsFrame) { + list.add(iFrame); + } + } + + if (list.size() == 1) { + slopeFrame.setSize(plot2dA.getWidth(), plot2dA.getHeight()); + context.getWorkbench().getFrame() + .addInternalFrame(slopeFrame, true, true); + + } else { + // slopeFrame.repaint(); + slopeFrame.toFront(); + + } + final int xpos = 0; + int ypos = 0; + final Dimension deskDim = context.getWorkbench().getFrame() + .getDesktopPane().getSize(); + int deskWidth = deskDim.width; + final int deskHeight = deskDim.height; + deskWidth = deskDim.width; + final int frameWidth = deskWidth; + final int frameHeight = deskHeight / 2; + + for (final JInternalFrame iFrame : JUMPWorkbench.getInstance() + .getFrame().getInternalFrames()) { + if (iFrame instanceof AdditionalResultsFrame) { + ((AdditionalResultsFrame) iFrame).reshape(xpos, ypos, + frameWidth, frameHeight); + ((AdditionalResultsFrame) iFrame).setLocation(xpos, + ypos); + ((AdditionalResultsFrame) iFrame).getSplitPanel() + .setDividerLocation(0); + ((AdditionalResultsFrame) iFrame).moveToFront(); + ypos += frameHeight; + } + } + } + }); + + final JButton infoBtn = new JButton( + IconLoader.icon("information_16x16.png")); + infoBtn.setToolTipText(PROFILE_INFO); + infoBtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + final DecimalFormat df = new DecimalFormat("##.###"); + final HTMLPanel out = new HTMLPanel(); + out.getRecordPanel().removeAll(); + out.createNewDocument(); + out.setBackground(Color.lightGray); + String htmlString = "<HTML><BODY>"; + htmlString += "<h2 align=\"left\">" + PROFILE_INFO + "</h2>"; + htmlString += "<b><font face=\"" + darkLabelFont + "\">" + MIN + + ": </b>" + df.format(min) + "<br>"; + htmlString += "<b><font face=\"" + darkLabelFont + "\">" + MAX + + ": </b>" + df.format(max) + "<br>"; + htmlString += "<b><font face=\"" + darkLabelFont + "\">" + + PROFILE_LENGTH + ": </b>" + df.format(profLenght) + + "<br>"; + htmlString += "<b><font face=\"" + darkLabelFont + "\">" + + WIDTH + ": </b>" + df.format(width) + "<br>"; + htmlString += "<b><font face=\"" + darkLabelFont + "\">" + + HEIGHT + ": </b>" + df.format(height) + "<br>"; + htmlString += "<b><font face=\"" + darkLabelFont + "\">" + + MEAN_SLOPE + ": </b>" + df.format(slope) + "\xB0<br>"; + htmlString += "</DIV></BODY></HTML>"; + out.append(htmlString); + final HTMLFrame frame = new HTMLFrame(); + frame.setTitle(PROFILE_INFO); + frame.add(out); + frame.setClosable(true); + frame.setResizable(true); + frame.setMaximizable(true); + frame.setSize(200, 280); + frame.setVisible(true); + context.getWorkbench().getFrame() + .addInternalFrame(frame, true, true); + } + }); + // To do: giving a downslope/upslope/flat speed, it calculates the + // travel time along the profile + final JButton timeBtn = new JButton(IconLoader.icon("fugue/clock.png")); + timeBtn.setToolTipText(TIMES); + timeBtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + + // final ProfileTimesDialog ptd = new ProfileTimesDialog( + // slopeMatrixData); + // ptd.setLocationRelativeTo(JUMPWorkbench.getInstance() + // .getFrame()); + // ptd.setVisible(true); + } + }); + + plot2dA.plotToolBar.addSeparator(new Dimension(16, 16)); + plot2dA.plotToolBar.add(infoBtn); + plot2dA.plotToolBar.add(tableBtn); + plot2dA.plotToolBar.add(slopeBtn); + // plot2dA.plotToolBar.add(timeBtn); + plot2dA.setFixedBounds(0, 0, width); return plot2dA; } + private static Object[] getXdoubleData(double[][] slopeData) { + final Object[] column = new Object[slopeData.length]; + double value; + for (int i = 0; i < column.length; i++) { + value = ((Double) slopeData[i][1]).doubleValue(); + column[i] = value; + } + return column; + + } + + public static double[][] getRelativeSlope(Object[][] dataTableObject) { + final double[][] column = new double[dataTableObject.length][2]; + for (int i = 0; i < column.length; i++) { + if (i == 0) { + column[i][1] = 0; + column[i][0] = ((Double) dataTableObject[i][0]).doubleValue(); + } else { + final double dDist1 = ((Double) dataTableObject[i][1]) + .doubleValue(); + final double dDist0 = ((Double) dataTableObject[i - 1][1]) + .doubleValue(); + final double Z1 = ((Double) dataTableObject[i][0]) + .doubleValue(); + final double Z0 = ((Double) dataTableObject[i - 1][0]) + .doubleValue(); + double number = 0; + final double slope = Math.atan(((Z1 - Z0) / (dDist1 - dDist0))); + if (slope > 0 || slope == 0) { + number = 90 - Math.toDegrees(slope); + } else if (slope < 0) { + number = -90 - Math.toDegrees(slope); + } + column[i][1] = number; + column[i][0] = Z1; + } + } + return column; + } + + public static Object[] getXData(Object[][] dataTableObject) { + final Object[] column = new Object[dataTableObject.length]; + double value; + for (int i = 0; i < column.length; i++) { + value = ((Double) dataTableObject[i][0]).doubleValue(); + column[i] = value; + } + return column; + } + + public static Object[] getD3Data(Object[][] dataTableObject) { + final Object[] column = new Object[dataTableObject.length]; + + for (int i = 0; i < column.length; i++) { + if (i == 0) { + column[i] = 0; + } else { + final double dDist1 = ((Double) dataTableObject[i][1]) + .doubleValue(); + final double dDist0 = ((Double) dataTableObject[i - 1][1]) + .doubleValue(); + final double Z1 = ((Double) dataTableObject[i][0]) + .doubleValue(); + final double Z0 = ((Double) dataTableObject[i - 1][0]) + .doubleValue(); + column[i] = Math.sqrt(Z1 * Z0 + dDist1 * dDist0); + } + } + return column; + } + + public static Object[] getYData(Object[][] dataTableObject) { + final Object[] column = new Object[dataTableObject.length]; + for (int i = 0; i < column.length; i++) { + final double value = ((Double) dataTableObject[i][1]).doubleValue(); + column[i] = value; + } + return column; + } + + public static double[][] getDataAsDouble(Object[][] dataTableObject) { + final double[][] column = new double[dataTableObject.length][2]; + for (int i = 0; i < column.length; i++) { + final double value1 = ((Double) dataTableObject[i][1]) + .doubleValue(); + final double value0 = ((Double) dataTableObject[i][0]) + .doubleValue(); + column[i][0] = value0; + column[i][1] = value1; + } + return column; + } } ------------------------------------------------------------------------------ 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