Changeset 35104 in osm
- Timestamp:
- 2019-08-25T16:00:12+02:00 (5 years ago)
- Location:
- applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer
- Files:
-
- 7 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerPlugin.java
r35027 r35104 22 22 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 23 23 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 24 import org.openstreetmap.josm.io.session.SessionReader; 25 import org.openstreetmap.josm.io.session.SessionWriter; 24 26 import org.openstreetmap.josm.plugins.Plugin; 25 27 import org.openstreetmap.josm.plugins.PluginInformation; … … 37 39 import org.openstreetmap.josm.plugins.piclayer.actions.transform.affine.TransformPointAction; 38 40 import org.openstreetmap.josm.plugins.piclayer.actions.transform.autocalibrate.AutoCalibratePictureAction; 41 import org.openstreetmap.josm.plugins.piclayer.io.session.FileSessionExporter; 42 import org.openstreetmap.josm.plugins.piclayer.io.session.KMLSessionExporter; 43 import org.openstreetmap.josm.plugins.piclayer.io.session.PicLayerSessionImporter; 39 44 import org.openstreetmap.josm.plugins.piclayer.layer.PicLayerAbstract; 45 import org.openstreetmap.josm.plugins.piclayer.layer.PicLayerFromFile; 46 import org.openstreetmap.josm.plugins.piclayer.layer.PicLayerFromKML; 40 47 41 48 /** … … 66 73 MainApplication.getLayerManager().addLayerChangeListener(this); 67 74 MainApplication.getLayerManager().addActiveLayerChangeListener(this); 75 76 // Session IO 77 SessionWriter.registerSessionLayerExporter(PicLayerFromFile.class, FileSessionExporter.class); 78 SessionWriter.registerSessionLayerExporter(PicLayerFromKML.class, KMLSessionExporter.class); 79 // TODO IO for PicLayerFromClipboard 80 //SessionWriter.registerSessionLayerExporter(PicLayerFromClipboard.class, ClipboardSessionExporter.class); 81 SessionReader.registerSessionLayerImporter("piclayerImage", PicLayerSessionImporter.class); 68 82 } 69 83 -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/autocalibrate/AutoCalibrateHandler.java
r35030 r35104 25 25 import org.openstreetmap.josm.actions.OpenFileAction; 26 26 import org.openstreetmap.josm.data.coor.LatLon; 27 import org.openstreetmap.josm.data.coor.conversion.CoordinateFormatManager; 28 import org.openstreetmap.josm.data.coor.conversion.ICoordinateFormat; 27 29 import org.openstreetmap.josm.data.osm.DataSet; 28 30 import org.openstreetmap.josm.data.osm.Node; … … 42 44 43 45 /** 44 * Class providing functionality of GUIs and also handles connection between {@link AutoCalibratePictureAction} 45 * and GUIs what means is basic class to provide the functionality of calibration. 46 * Class handling connection between {@link AutoCalibratePictureAction} and GUIs. 46 47 * Info at https://wiki.openstreetmap.org/wiki/User:Rebsc 47 48 * @author rebsc … … 414 415 // add point to reference list in lat/lon scale 415 416 LatLon latLonPoint = MainApplication.getMap().mapView.getLatLon(e.getPoint().getX(),e.getPoint().getY()); 416 double latY = latLonPoint.getY(); 417 double lonX = latLonPoint.getX(); 417 ICoordinateFormat mCoord = CoordinateFormatManager.getDefaultFormat(); 418 double latY = Double.parseDouble(mCoord.latToString(latLonPoint)); 419 double lonX = Double.parseDouble(mCoord.lonToString(latLonPoint)); 418 420 Point2D llPoint = new Point2D.Double(lonX, latY); 419 421 referencePointList.add(llPoint); -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/autocalibrate/AutoCalibrator.java
r35027 r35104 18 18 /** 19 19 * Class for image calibration. 20 * The startPositions, endPositions representing points set on the image with using {@link PicLayerPlugin} actions.21 20 * Info at https://wiki.openstreetmap.org/wiki/User:Rebsc 22 21 * @author rebsc … … 61 60 /** 62 61 * Calibrates Image with given data. 63 * Corrects end points by passed real distances between points. 64 * Sets star points to end points. 62 * Sets start points to end points and corrects end points by passed distances between points. 65 63 */ 66 64 public void calibrate() { … … 105 103 106 104 /** 107 * Compare 3 side ratios of first list with 3 side ratios of compare list105 * Compare side ratios before/after calibration 108 106 * @param list with ratios to compare to other list 109 107 * @param compareList with ratios to compare to other list … … 133 131 134 132 /** 135 * Corrects points with given realdistances. Calculates new points on lines133 * Corrects points with given distances. Calculates new points on lines 136 134 * between given points at given distances. 137 135 * @param points need to be corrected -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/gui/autocalibrate/CalibrationWindow.java
r35032 r35104 15 15 import java.awt.event.WindowListener; 16 16 import java.awt.geom.Point2D; 17 import java.text.DecimalFormat;18 17 import java.util.ArrayList; 19 18 import java.util.List; 19 import java.util.Locale; 20 20 21 21 import javax.imageio.ImageIO; … … 32 32 import org.openstreetmap.josm.plugins.piclayer.PicLayerPlugin; 33 33 import org.openstreetmap.josm.plugins.piclayer.actions.transform.autocalibrate.AutoCalibratePictureAction; 34 import org.openstreetmap.josm.tools.I18n; 34 35 35 36 /** … … 40 41 public class CalibrationWindow extends JFrame { 41 42 42 private static final long serialVersionUID = 1L; 43 private static final int FILES_ONLY = 0; 44 45 private JFileChooser fileChooser; 46 private String referenceFileName; 47 private List<Point2D> originPoints; 48 private List<Point2D> referencePoints; 49 private String dist1Value; 50 private String dist2Value; 51 52 private JPanel dialogPane; 53 private JPanel contentPanel; 54 private JPanel infoBar; 55 private JPanel buttonBar; 56 57 private JButton addRefPointsButton; 58 private JButton addEdgePointsButton; 59 private JButton helpButton; 60 private JButton openButton; 61 private JButton selectLayerButton; 62 private JButton runButton; 63 private JButton cancelButton; 64 65 private JLabel infoHeader; 66 private JLabel edgePointHeader; 67 private JLabel edgePointNames; 68 private JLabel edgePointValues; 69 private JLabel distanceHeader; 70 private JLabel distance1; 71 private JLabel distance2; 72 private JTextField distance1Field; 73 private JTextField distance2Field; 74 private JLabel distance1Value; 75 private JLabel distance2Value; 76 private JLabel refFileHeader; 77 private JLabel refFileName; 78 private JLabel refFileNameValue; 79 private JLabel refPointHeader; 80 private JLabel refPointNames; 81 private JLabel refPointValues; 82 83 private JLabel edgePointsChecked; 84 private JLabel distance1Checked; 85 private JLabel distance2Checked; 86 private JLabel fileChecked; 87 private JLabel refPointsChecked; 88 89 public CalibrationWindow() { 90 fileChooser = new JFileChooser(); 91 referenceFileName = null; 92 setFileChooser(); 93 94 originPoints = new ArrayList<>(); 95 referencePoints = new ArrayList<>(); 96 dist1Value = null; 97 dist2Value = null; 98 99 initComponents(); 100 updateState(); 101 } 102 103 /** 104 * initialize components 105 */ 106 private void initComponents() { 107 dialogPane = new JPanel(); 108 contentPanel = new JPanel(); 109 infoBar = new JPanel(); 110 buttonBar = new JPanel(); 111 112 addRefPointsButton = new JButton(); 113 addEdgePointsButton = new JButton(); 114 helpButton = new JButton(); 115 openButton = new JButton(); 116 selectLayerButton = new JButton(); 117 runButton = new JButton(); 118 cancelButton = new JButton(); 119 120 infoHeader = new JLabel(); 121 edgePointHeader = new JLabel(); 122 edgePointNames = new JLabel(); 123 edgePointValues = new JLabel(); 124 distanceHeader = new JLabel(); 125 distance1 = new JLabel(); 126 distance2 = new JLabel(); 127 distance1Field = new JTextField(); 128 distance2Field = new JTextField(); 129 distance1Value = new JLabel(); 130 distance2Value = new JLabel(); 131 refFileHeader = new JLabel(); 132 refFileName = new JLabel(); 133 refFileNameValue = new JLabel(); 134 refPointHeader = new JLabel(); 135 refPointNames = new JLabel(); 136 refPointValues = new JLabel(); 137 138 edgePointsChecked = new JLabel(); 139 distance1Checked = new JLabel(); 140 distance2Checked = new JLabel(); 141 fileChecked = new JLabel(); 142 refPointsChecked = new JLabel(); 143 144 // this 145 setTitle(tr("AutoCalibration")); 146 java.awt.Container contentPane = getContentPane(); 147 contentPane.setLayout(new BorderLayout()); 148 this.setMinimumSize(new Dimension(50, 100)); 149 150 // dialog pane 151 dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12)); 152 dialogPane.setLayout(new BorderLayout()); 153 154 // info bar 155 setInfoBar(); 156 setInfoHeader(); 157 dialogPane.add(infoBar, BorderLayout.NORTH); 158 159 // content panel 160 setContentPanel(); 161 setPointHeader(); 162 setEdgePointNamesValues(); 163 setDistanceHeader(); 164 setDistance1(); 165 setDistance1Field(); 166 setDistance2(); 167 setDistance2Field(); 168 setRefFileHeader(); 169 setRefFileName(); 170 setOpenButton(); 171 setSelectLayerButton(); 172 setRefPointHeader(); 173 setRefPointNamesValues(); 174 dialogPane.add(contentPanel, BorderLayout.CENTER); 175 176 // button bar 177 setButtonBar(); 178 setOKButton(); 179 setCancelButton(); 180 dialogPane.add(buttonBar, BorderLayout.SOUTH); 181 182 // content Pane 183 contentPane.add(dialogPane, BorderLayout.CENTER); 184 pack(); 185 setLocationRelativeTo(getOwner()); 186 } 187 188 189 // COMPONENTS 190 191 private void setInfoBar() { 192 infoBar.setBorder(new EmptyBorder(0, 0, 12, 0)); 193 infoBar.setLayout(new GridBagLayout()); 194 ((GridBagLayout) infoBar.getLayout()).columnWidths = new int[] {0, 85, 80}; 195 ((GridBagLayout) infoBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0}; 196 } 197 198 private void setInfoHeader() { 199 infoHeader.setText(tr("<html>Please enter the required information.</html>")); 200 infoBar.add(infoHeader, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, 201 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 202 new Insets(5, 5, 0, 0), 0, 0)); 203 204 String space = " "; 205 helpButton = new JButton(tr(space + "help" + space)); 206 infoBar.add(helpButton, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, 207 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 208 new Insets(0, 0, 0, 0), 0, 0)); 209 } 210 211 private void setContentPanel() { 212 contentPanel.setLayout(new GridBagLayout()); 213 contentPanel.setBackground(new Color(200, 200, 200)); 214 ((GridBagLayout) contentPanel.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0}; 215 ((GridBagLayout) contentPanel.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0}; 43 private static final long serialVersionUID = 1L; 44 private static final int FILES_ONLY = 0; 45 46 private JFileChooser fileChooser; 47 private String referenceFileName; 48 private List<Point2D> originPoints; 49 private List<Point2D> referencePoints; 50 private String dist1Value; 51 private String dist2Value; 52 53 private JPanel dialogPane; 54 private JPanel contentPanel; 55 private JPanel infoBar; 56 private JPanel buttonBar; 57 58 private JButton addRefPointsButton; 59 private JButton addEdgePointsButton; 60 private JButton helpButton; 61 private JButton openButton; 62 private JButton selectLayerButton; 63 private JButton runButton; 64 private JButton cancelButton; 65 66 private JLabel infoHeader; 67 private JLabel edgePointHeader; 68 private JLabel edgePointNames; 69 private JLabel edgePointValues; 70 private JLabel distanceHeader; 71 private JLabel distance1; 72 private JLabel distance2; 73 private JTextField distance1Field; 74 private JTextField distance2Field; 75 private JLabel distance1Value; 76 private JLabel distance2Value; 77 private JLabel refFileHeader; 78 private JLabel refFileName; 79 private JLabel refFileNameValue; 80 private JLabel refPointHeader; 81 private JLabel refPointNames; 82 private JLabel refPointValues; 83 84 private JLabel edgePointsChecked; 85 private JLabel distance1Checked; 86 private JLabel distance2Checked; 87 private JLabel fileChecked; 88 private JLabel refPointsChecked; 89 90 91 private String separator; 92 private String ws = " "; 93 private Locale language; 94 95 96 public CalibrationWindow() { 97 setLanguageFormat(); 98 fileChooser = new JFileChooser(); 99 referenceFileName = null; 100 setFileChooser(); 101 102 originPoints = new ArrayList<>(); 103 referencePoints = new ArrayList<>(); 104 dist1Value = null; 105 dist2Value = null; 106 107 initComponents(); 108 updateState(); 109 } 110 111 /** 112 * initialize components 113 */ 114 private void initComponents() { 115 dialogPane = new JPanel(); 116 contentPanel = new JPanel(); 117 infoBar = new JPanel(); 118 buttonBar = new JPanel(); 119 120 addRefPointsButton = new JButton(); 121 addEdgePointsButton = new JButton(); 122 helpButton = new JButton(); 123 openButton = new JButton(); 124 selectLayerButton = new JButton(); 125 runButton = new JButton(); 126 cancelButton = new JButton(); 127 128 infoHeader = new JLabel(); 129 edgePointHeader = new JLabel(); 130 edgePointNames = new JLabel(); 131 edgePointValues = new JLabel(); 132 distanceHeader = new JLabel(); 133 distance1 = new JLabel(); 134 distance2 = new JLabel(); 135 distance1Field = new JTextField(); 136 distance2Field = new JTextField(); 137 distance1Value = new JLabel(); 138 distance2Value = new JLabel(); 139 refFileHeader = new JLabel(); 140 refFileName = new JLabel(); 141 refFileNameValue = new JLabel(); 142 refPointHeader = new JLabel(); 143 refPointNames = new JLabel(); 144 refPointValues = new JLabel(); 145 146 edgePointsChecked = new JLabel(); 147 distance1Checked = new JLabel(); 148 distance2Checked = new JLabel(); 149 fileChecked = new JLabel(); 150 refPointsChecked = new JLabel(); 151 152 // this 153 setTitle(tr("AutoCalibration")); 154 java.awt.Container contentPane = getContentPane(); 155 contentPane.setLayout(new BorderLayout()); 156 this.setMinimumSize(new Dimension(50,100)); 157 158 // dialog pane 159 dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12)); 160 dialogPane.setLayout(new BorderLayout()); 161 162 // info bar 163 setInfoBar(); 164 setInfoHeader(); 165 dialogPane.add(infoBar, BorderLayout.NORTH); 166 167 // content panel 168 setContentPanel(); 169 setPointHeader(); 170 setEdgePointNamesValues(); 171 setDistanceHeader(); 172 setDistance1(); 173 setDistance1Field(); 174 setDistance2(); 175 setDistance2Field(); 176 setRefFileHeader(); 177 setRefFileName(); 178 setOpenButton(); 179 setSelectLayerButton(); 180 setRefPointHeader(); 181 setRefPointNamesValues(); 182 dialogPane.add(contentPanel, BorderLayout.CENTER); 183 184 // button bar 185 setButtonBar(); 186 setOKButton(); 187 setCancelButton(); 188 dialogPane.add(buttonBar, BorderLayout.SOUTH); 189 190 // content Pane 191 contentPane.add(dialogPane, BorderLayout.CENTER); 192 pack(); 193 setLocationRelativeTo(getOwner()); 194 } 195 196 private void setLanguageFormat(){ 197 // TODO get application language instead of system language 198 String c = I18n.getOriginalLocale().getCountry(); 199 switch(c) { 200 case "DE": 201 language = Locale.GERMAN; 202 separator = ";"; 203 break; 204 case "FR": 205 language = Locale.FRANCE; 206 separator = ";"; 207 break; 208 case "IT": 209 language = Locale.ITALIAN; 210 separator = ";"; 211 break; 212 default: 213 language = Locale.US; 214 separator = ","; 215 } 216 } 217 218 219 // COMPONENTS 220 221 private void setInfoBar() { 222 infoBar.setBorder(new EmptyBorder(0, 0, 12, 0)); 223 infoBar.setLayout(new GridBagLayout()); 224 ((GridBagLayout) infoBar.getLayout()).columnWidths = new int[] {0, 85, 80}; 225 ((GridBagLayout) infoBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0}; 226 } 227 228 private void setInfoHeader() { 229 infoHeader.setText(tr("<html>Please enter the required information.</html>")); 230 infoBar.add(infoHeader, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, 231 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 232 new Insets(5, 5, 0, 0), 0, 0)); 233 234 String space = " "; 235 helpButton = new JButton(tr(space + "help" + space)); 236 infoBar.add(helpButton, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, 237 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 238 new Insets(0, 0, 0, 0), 0, 0)); 239 } 240 241 private void setContentPanel() { 242 contentPanel.setLayout(new GridBagLayout()); 243 contentPanel.setBackground(new Color(200, 200, 200)); 244 ((GridBagLayout) contentPanel.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0}; 245 ((GridBagLayout) contentPanel.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0}; 216 246 ((GridBagLayout) contentPanel.getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 1.0E-4}; 217 ((GridBagLayout) contentPanel.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4}; 218 } 219 220 private void setPointHeader() { 221 edgePointHeader.setText(tr("<html><b><u>Local Edge Points</u></b></html>")); 222 contentPanel.add(edgePointHeader, new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0, 223 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 224 new Insets(5, 5, 5, 30), 0, 0)); 225 } 226 227 private void setEdgePointNamesValues() { 228 edgePointNames.setText(tr("<html>" 229 + "Point 1 (Lat,Lon):<br>" 230 + "Point 2 (Lat,Lon):<br>" 231 + "Point 3 (Lat,Lon):<br>" 232 + "</html>")); 233 contentPanel.add(edgePointNames, new GridBagConstraints(0, 1, 3, 1, 0.0, 0.0, 234 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 235 new Insets(5, 5, 5, 30), 0, 0)); 236 237 if (!originPoints.isEmpty()) { 238 edgePointValuesEntered(); 239 } else { 240 addEdgePointsButton = new JButton(tr("Add Points...")); 241 contentPanel.add(addEdgePointsButton, new GridBagConstraints(3, 1, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 242 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 243 new Insets(5, 50, 5, 5), 0, 0)); 244 } 245 } 246 247 private void setDistanceHeader() { 248 distanceHeader.setText(tr("<html><b><u>True Distances</u></b></html>")); 249 contentPanel.add(distanceHeader, new GridBagConstraints(0, 2, 3, 1, 0.0, 0.0, 250 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 251 new Insets(5, 5, 5, 30), 0, 0)); 252 } 253 254 private void setDistance1Field() { 255 distance1Field.setText("Click here..."); 256 contentPanel.add(distance1Field, new GridBagConstraints(3, 3, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 257 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 258 new Insets(5, 50, 5, 5), 0, 0)); 259 } 260 261 private void setDistance2() { 262 distance2.setText(tr("Point 2 to Point 3 (meter):")); 263 contentPanel.add(distance2, new GridBagConstraints(0, 4, 3, 1, 0.0, 0.0, 264 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 265 new Insets(5, 5, 5, 30), 0, 0)); 266 } 267 268 private void setDistance2Field() { 269 distance2Field.setText("Click here..."); 270 contentPanel.add(distance2Field, new GridBagConstraints(3, 4, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 271 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 272 new Insets(5, 50, 5, 5), 0, 0)); 273 } 274 275 private void setRefFileHeader() { 276 refFileHeader.setText(tr("<html><b><u>Reference File</u></b></html>")); 277 contentPanel.add(refFileHeader, new GridBagConstraints(0, 5, 3, 1, 0.0, 0.0, 278 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 279 new Insets(5, 5, 5, 30), 0, 0)); 280 } 281 282 private void setRefFileName() { 283 refFileName.setText("<html>"+tr("Reference Name:") 284 + "<br>" 285 + "<br>" 286 + "<br>" 287 + "</html>"); 288 289 contentPanel.add(refFileName, new GridBagConstraints(0, 6, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 290 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 291 new Insets(5, 5, 5, 30), 0, 0)); 292 } 293 294 private void setSelectLayerButton() { 295 String imageName = "layerlist.png"; 296 Image image = null; 297 try { 298 image = ImageIO.read(getClass().getResource("/images/" + imageName)); 299 } catch (Exception ex) { 300 System.out.println("Error: Could not load image " + imageName + "," + ex); 301 } 302 303 selectLayerButton.setToolTipText(tr("Select a layer as reference...")); 304 selectLayerButton.setIcon(new ImageIcon(image)); 305 contentPanel.add(selectLayerButton, new GridBagConstraints(3, 6, 2, 1, 1.0, 0.0, 306 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 307 new Insets(5, 50, 5, 5), 0, 0)); 308 } 309 310 private void setOpenButton() { 311 String imageName = "open.png"; 312 Image image = null; 313 try { 314 image = ImageIO.read(getClass().getResource("/images/" + imageName)); 315 } catch (Exception ex) { 316 System.out.println("Error: Could not load image " + imageName + "," + ex); 317 } 318 319 openButton.setToolTipText(tr("Open a file as reference...")); 320 openButton.setIcon(new ImageIcon(image)); 321 contentPanel.add(openButton, new GridBagConstraints(6, 6, GridBagConstraints.REMAINDER, 1, 1.0, 0.0, 322 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 323 new Insets(5, 5, 5, 5), 0, 0)); 324 } 325 326 private void setRefPointHeader() { 327 refPointHeader.setText("<html><b><u>Reference Points</u></b></html>\""); 328 contentPanel.add(refPointHeader, new GridBagConstraints(0, 7, 3, 1, 0.0, 0.0, 329 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 330 new Insets(5, 5, 5, 30), 0, 0)); 331 } 332 333 private void setRefPointNamesValues() { 334 Point2D rp1 = null; 335 Point2D rp2 = null; 336 Point2D rp3 = null; 337 338 if (!referencePoints.isEmpty()) { 339 rp1 = referencePoints.get(0); 340 rp2 = referencePoints.get(1); 341 rp3 = referencePoints.get(2); 342 } 343 344 refPointNames.setText(tr("<html>" 345 + "Point 1 (Lat,Lon):<br>" 346 + "Point 2 (Lat,Lon):<br>" 347 + "Point 3 (Lat,Lon):<br>" 348 + "</html>")); 349 contentPanel.add(refPointNames, new GridBagConstraints(0, 8, 3, 1, 0.0, 0.0, 350 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 351 new Insets(5, 5, 5, 30), 0, 0)); 352 353 if (!referencePoints.isEmpty()) { 354 refPointValues.setText(tr("<html>" 355 + rp1.getY() + ", " + rp1.getX() + "<br>" 356 + rp2.getY() + ", " + rp2.getX() + "<br>" 357 + rp3.getY() + ", " + rp3.getX() + "<br>" 358 + "</html>")); 359 360 contentPanel.add(refPointValues, new GridBagConstraints(3, 8, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 361 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 362 new Insets(5, 5, 5, 30), 0, 0)); 363 } else { 364 addRefPointsButton = new JButton(tr("Add Points...")); 365 contentPanel.add(addRefPointsButton, new GridBagConstraints(3, 8, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 366 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 367 new Insets(5, 50, 5, 5), 0, 0)); 368 } 369 } 370 371 private void setButtonBar() { 372 buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0)); 373 buttonBar.setLayout(new GridBagLayout()); 374 ((GridBagLayout) buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80}; 375 ((GridBagLayout) buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0}; 376 } 377 378 private void setOKButton() { 379 runButton.setText(tr("Run")); 380 buttonBar.add(runButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, 381 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 382 new Insets(0, 0, 0, 5), 0, 0)); 383 } 384 385 private void setCancelButton() { 386 cancelButton.setText(tr("Cancel")); 387 buttonBar.add(cancelButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, 388 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 389 new Insets(0, 0, 0, 0), 0, 0)); 390 } 391 392 393 // DYNAMIC FIELD CHANGES 394 395 private void edgePointValuesEntered() { 396 Point2D p1 = null; 397 Point2D p2 = null; 398 Point2D p3 = null; 399 DecimalFormat df = new DecimalFormat("###,###.###"); 400 401 if (originPoints.size() == 3) { 402 p1 = originPoints.get(0); 403 p2 = originPoints.get(1); 404 p3 = originPoints.get(2); 405 } else return; 406 407 edgePointValues.setText(tr("<html>" 408 + df.format(p1.getY()) + " , " + df.format(p1.getX()) + "<br>" 409 + df.format(p2.getY()) + " , " + df.format(p2.getX()) + "<br>" 410 + df.format(p3.getY()) + " , " + df.format(p3.getX()) + "<br>" 411 + "</html>")); 412 413 contentPanel.remove(addEdgePointsButton); 414 contentPanel.add(edgePointValues, new GridBagConstraints(3, 1, 3, 1, 0.0, 0.0, 415 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 416 new Insets(5, 5, 5, 30), 0, 0)); 417 418 edgePointsChecked.setIcon(getCheckedIcon()); 419 contentPanel.add(edgePointsChecked, new GridBagConstraints(6, 1, 3, 1, 0.0, 0.0, 420 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 421 new Insets(5, 5, 5, 5), 0, 0)); 422 } 423 424 private void distance1Entered() { 425 contentPanel.remove(distance1Field); 426 distance1Value.setText(dist1Value); 427 contentPanel.add(distance1Value, new GridBagConstraints(3, 3, 2, 1, 0.0, 0.0, 428 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 429 new Insets(5, 5, 5, 30), 0, 0)); 430 431 distance1Checked.setIcon(getCheckedIcon()); 432 contentPanel.add(distance1Checked, new GridBagConstraints(6, 3, 3, 1, 0.0, 0.0, 433 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 434 new Insets(5, 5, 5, 5), 0, 0)); 435 } 436 437 private void distance2Entered() { 438 contentPanel.remove(distance2Field); 439 distance2Value.setText(dist2Value); 440 contentPanel.add(distance2Value, new GridBagConstraints(3, 4, 2, 1, 0.0, 0.0, 441 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 442 new Insets(5, 5, 5, 30), 0, 0)); 443 444 distance2Checked.setIcon(getCheckedIcon()); 445 contentPanel.add(distance2Checked, new GridBagConstraints(6, 4, 3, 1, 0.0, 0.0, 446 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 447 new Insets(5, 5, 5, 5), 0, 0)); 448 } 449 450 private void refFileEntered() { 451 contentPanel.remove(selectLayerButton); 452 contentPanel.remove(openButton); 453 refFileName.setText("<html>"+tr("Reference Name:")+"</html>"); 454 refFileNameValue.setText(referenceFileName); 455 contentPanel.add(refFileNameValue, new GridBagConstraints(3, 6, 2, 1, 0.0, 0.0, 456 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 457 new Insets(5, 5, 5, 30), 0, 0)); 458 459 fileChecked.setIcon(getCheckedIcon()); 460 contentPanel.add(fileChecked, new GridBagConstraints(6, 6, 3, 1, 0.0, 0.0, 461 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 462 new Insets(5, 5, 5, 5), 0, 0)); 463 } 464 465 private void refPointValuesEntered() { 466 Point2D p1 = null; 467 Point2D p2 = null; 468 Point2D p3 = null; 469 DecimalFormat df = new DecimalFormat("###,###.###"); 470 471 if (referencePoints.size() == 3) { 472 p1 = referencePoints.get(0); 473 p2 = referencePoints.get(1); 474 p3 = referencePoints.get(2); 475 } else return; 476 477 refPointValues.setText(tr("<html>" 478 + df.format(p1.getY()) + " , " + df.format(p1.getX()) + "<br>" 479 + df.format(p2.getY()) + " , " + df.format(p2.getX()) + "<br>" 480 + df.format(p3.getY()) + " , " + df.format(p3.getX()) + "<br>" 481 + "</html>")); 482 483 contentPanel.remove(addRefPointsButton); 484 contentPanel.add(refPointValues, new GridBagConstraints(3, 8, 3, 1, 0.0, 0.0, 485 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 486 new Insets(5, 5, 5, 30), 0, 0)); 487 488 refPointsChecked.setIcon(getCheckedIcon()); 489 contentPanel.add(refPointsChecked, new GridBagConstraints(6, 8, 3, 1, 0.0, 0.0, 490 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 491 new Insets(5, 5, 5, 5), 0, 0)); 492 } 493 494 private void setDistance1() { 495 distance1.setText(tr("Point 1 to Point 2 (meter):")); 496 contentPanel.add(distance1, new GridBagConstraints(0, 3, 3, 1, 0.0, 0.0, 497 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 498 new Insets(5, 5, 5, 30), 0, 0)); 499 } 500 501 502 // GETTER / SETTER 503 504 public JButton getOpenButton() { 505 return this.openButton; 506 } 507 508 public JTextField getDistance1Field() { 509 return this.distance1Field; 510 } 511 512 public JTextField getDistance2Field() { 513 return this.distance2Field; 514 } 515 516 public String getDistance1FieldText() { 517 return this.distance1Field.getText(); 518 } 519 520 public String getDistance2FieldText() { 521 return this.distance2Field.getText(); 522 } 523 524 public void setOriginPoints(List<Point2D> points) { 525 this.originPoints = points; 526 edgePointValuesEntered(); 527 updateState(); 528 } 529 530 public void setReferencePoints(List<Point2D> points) { 531 this.referencePoints = points; 532 refPointValuesEntered(); 533 updateState(); 534 } 535 536 public void setDistance1Field(String s) { 537 this.distance1Field.setText(s); 538 updateState(); 539 } 540 541 public void setDistance2Field(String s) { 542 this.distance2Field.setText(s); 543 updateState(); 544 } 545 546 public void setDistance1Value(String valueAsString) { 547 this.dist1Value = valueAsString; 548 if (!valueAsString.equals("")) distance1Entered(); 549 updateState(); 550 } 551 552 public void setDistance2Value(String valueAsString) { 553 this.dist2Value = valueAsString; 554 if (!valueAsString.equals("")) distance2Entered(); 555 updateState(); 556 } 557 558 public void setReferenceFileName(String name) { 559 this.referenceFileName = name; 560 } 561 562 private void setFileChooser() { 563 fileChooser.setFileSelectionMode(FILES_ONLY); 564 FileNameExtensionFilter filter = new FileNameExtensionFilter(".osm, .gpx", "osm", "gpx"); 565 fileChooser.setFileFilter(filter); 566 } 567 568 public void setReferenceFileNameValue(String value) { 569 this.referenceFileName = value; 570 this.refFileNameValue.setText(value); 571 refFileEntered(); 572 updateState(); 573 } 574 575 public JFileChooser getFileChooser() { 576 return this.fileChooser; 577 } 578 579 public String getFileName() { 580 return this.referenceFileName; 581 } 582 583 // LISTENER 584 585 public void setOkButtonListener(ActionListener l) { 586 this.runButton.addActionListener(l); 587 } 588 589 public void setCancelButtonListener(ActionListener l) { 590 this.cancelButton.addActionListener(l); 591 } 592 593 public void setWindowListener(WindowListener l) { 594 this.addWindowListener(l); 595 } 596 597 public void addOpenFileButtonListener(ActionListener l) { 598 this.openButton.addActionListener(l); 599 } 600 601 public void addSelectLayerButtonListener(ActionListener l) { 602 this.selectLayerButton.addActionListener(l); 603 } 604 605 public void addCancelButtonListener(ActionListener l) { 606 this.cancelButton.addActionListener(l); 607 } 608 609 public void addRunButtonListener(ActionListener l) { 610 this.runButton.addActionListener(l); 611 } 612 613 public void addEdgePointButtonListener(ActionListener l) { 614 this.addEdgePointsButton.addActionListener(l); 615 } 616 617 public void addReferencePointButtonListener(ActionListener l) { 618 this.addRefPointsButton.addActionListener(l); 619 } 620 621 public void addFrameWindowListener(WindowAdapter wAdapter) { 622 this.addWindowListener(wAdapter); 623 } 624 625 public void addDistance1FieldListener(FocusListener l) { 626 this.distance1Field.addFocusListener(l); 627 } 628 629 public void addDistance2FieldListener(FocusListener l) { 630 this.distance2Field.addFocusListener(l); 631 } 632 633 public void addHelpButtonListener(ActionListener l) { 634 this.helpButton.addActionListener(l); 635 } 636 637 638 // HELPER 639 640 private ImageIcon getCheckedIcon() { 641 String imageName = "checked.png"; 642 Image image = null; 643 try { 644 image = ImageIO.read(getClass().getResource("/images/" + imageName)); 645 } catch (Exception ex) { 646 System.out.println("Error: Could not load image " + imageName + "," + ex); 647 } 648 return new ImageIcon(image); 649 } 650 651 public void updateState() { 652 if (originPoints.isEmpty()) { 653 // button blink 654 distance1Field.setEnabled(false); 655 distance2Field.setEnabled(false); 656 openButton.setEnabled(false); 657 selectLayerButton.setEnabled(false); 658 addRefPointsButton.setEnabled(false); 659 runButton.setEnabled(false); 660 } else { 661 if (dist1Value == null && dist2Value == null) { 662 distance1Field.setEnabled(true); 663 distance2Field.setEnabled(true); 664 } 665 if (dist1Value != null) { 666 openButton.setEnabled(true); 667 selectLayerButton.setEnabled(true); 668 } 669 if (referenceFileName != null) addRefPointsButton.setEnabled(true); 670 if (!referencePoints.isEmpty()) runButton.setEnabled(true); 671 } 672 } 673 674 public void refresh() { 675 this.setVisible(true); 676 } 247 ((GridBagLayout) contentPanel.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4}; 248 } 249 250 private void setPointHeader() { 251 edgePointHeader.setText(tr("<html><b><u>Local Edge Points</u></b></html>")); 252 contentPanel.add(edgePointHeader, new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0, 253 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 254 new Insets(5, 5, 5, 30), 0, 0)); 255 } 256 257 private void setEdgePointNamesValues() { 258 edgePointNames.setText(tr("<html>" 259 + String.format("Point 1 (Lat%sLon):<br>", separator) 260 + String.format("Point 2 (Lat%sLon):<br>", separator) 261 + String.format("Point 3 (Lat%sLon):<br>", separator) 262 + "</html>")); 263 contentPanel.add(edgePointNames, new GridBagConstraints(0, 1, 3, 1, 0.0, 0.0, 264 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 265 new Insets(5, 5, 5, 30), 0, 0)); 266 267 if(!this.originPoints.isEmpty()) { 268 edgePointValuesEntered(); 269 } 270 else { 271 addEdgePointsButton = new JButton(tr("Add Points...")); 272 contentPanel.add(addEdgePointsButton, new GridBagConstraints(3, 1, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 273 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 274 new Insets(5, 50, 5, 5), 0, 0)); 275 } 276 } 277 278 private void setDistanceHeader() { 279 distanceHeader.setText(tr("<html><b><u>True Distances</u></b></html>")); 280 contentPanel.add(distanceHeader, new GridBagConstraints(0, 2, 3, 1, 0.0, 0.0, 281 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 282 new Insets(5, 5, 5, 30), 0, 0)); 283 } 284 285 private void setDistance1Field() { 286 distance1Field.setText("Click here..."); 287 contentPanel.add(distance1Field, new GridBagConstraints(3, 3, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 288 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 289 new Insets(5, 50, 5, 5), 0, 0)); 290 } 291 292 private void setDistance2() { 293 distance2.setText(tr("Point 2 to Point 3 (meter):")); 294 contentPanel.add(distance2, new GridBagConstraints(0, 4, 3, 1, 0.0, 0.0, 295 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 296 new Insets(5, 5, 5, 30), 0, 0)); 297 } 298 299 private void setDistance2Field() { 300 distance2Field.setText("Click here..."); 301 contentPanel.add(distance2Field, new GridBagConstraints(3, 4, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 302 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 303 new Insets(5, 50, 5, 5), 0, 0)); 304 } 305 306 private void setRefFileHeader() { 307 refFileHeader.setText(tr("<html><b><u>Reference File</u></b></html>")); 308 contentPanel.add(refFileHeader, new GridBagConstraints(0, 5, 3, 1, 0.0, 0.0, 309 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 310 new Insets(5, 5, 5, 30), 0, 0)); 311 } 312 313 private void setRefFileName() { 314 refFileName.setText(tr("<html>Reference Name:" 315 + "<br>" 316 + "<br>" 317 + "<br>" 318 + "</html>")); 319 320 contentPanel.add(refFileName, new GridBagConstraints(0, 6, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 321 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 322 new Insets(5, 5, 5, 30), 0, 0)); 323 } 324 325 private void setSelectLayerButton() { 326 String imageName = "layerlist.png"; 327 Image image = null; 328 try { 329 image = ImageIO.read(getClass().getResource("/images/" + imageName)); 330 } catch (Exception ex) { 331 System.out.println("Error: Could not load image " + imageName + "," + ex); 332 } 333 334 selectLayerButton.setToolTipText(tr("Select a layer as reference...")); 335 selectLayerButton.setIcon(new ImageIcon(image)); 336 contentPanel.add(selectLayerButton, new GridBagConstraints(3, 6, 2, 1, 1.0, 0.0, 337 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 338 new Insets(5, 50, 5, 5), 0, 0)); 339 } 340 341 private void setOpenButton() { 342 String imageName = "open.png"; 343 Image image = null; 344 try { 345 image = ImageIO.read(getClass().getResource("/images/" + imageName)); 346 } catch (Exception ex) { 347 System.out.println("Error: Could not load image " + imageName + "," + ex); 348 } 349 350 openButton.setToolTipText(tr("Open a file as reference...")); 351 openButton.setIcon(new ImageIcon(image)); 352 contentPanel.add(openButton, new GridBagConstraints(6, 6, GridBagConstraints.REMAINDER, 1, 1.0, 0.0, 353 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 354 new Insets(5, 5, 5, 5), 0, 0)); 355 } 356 357 private void setRefPointHeader() { 358 refPointHeader.setText("<html><b><u>Reference Points</u></b></html>\""); 359 contentPanel.add(refPointHeader, new GridBagConstraints(0, 7, 3, 1, 0.0, 0.0, 360 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 361 new Insets(5, 5, 5, 30), 0, 0)); 362 } 363 364 private void setRefPointNamesValues() { 365 refPointNames.setText(tr("<html>" 366 + String.format("Point 1 (Lat%sLon):<br>", separator) 367 + String.format("Point 2 (Lat%sLon):<br>", separator) 368 + String.format("Point 3 (Lat%sLon):<br>", separator) 369 + "</html>")); 370 contentPanel.add(refPointNames, new GridBagConstraints(0, 8, 3, 1, 0.0, 0.0, 371 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 372 new Insets(5, 5, 5, 30), 0, 0)); 373 374 if(!this.referencePoints.isEmpty()) { 375 refPointValuesEntered(); 376 } 377 else { 378 addRefPointsButton = new JButton(tr("Add Points...")); 379 contentPanel.add(addRefPointsButton, new GridBagConstraints(3, 8, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 380 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 381 new Insets(5, 50, 5, 5), 0, 0)); 382 } 383 } 384 385 private void setButtonBar() { 386 buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0)); 387 buttonBar.setLayout(new GridBagLayout()); 388 ((GridBagLayout) buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80}; 389 ((GridBagLayout) buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0}; 390 } 391 392 private void setOKButton() { 393 runButton.setText(tr("Run")); 394 buttonBar.add(runButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, 395 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 396 new Insets(0, 0, 0, 5), 0, 0)); 397 } 398 399 private void setCancelButton() { 400 cancelButton.setText(tr("Cancel")); 401 buttonBar.add(cancelButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, 402 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 403 new Insets(0, 0, 0, 0), 0, 0)); 404 } 405 406 407 // DYNAMIC FIELD CHANGES 408 409 private void edgePointValuesEntered() { 410 Point2D p1 = null; 411 Point2D p2 = null; 412 Point2D p3 = null; 413 414 if(this.originPoints.size() == 3) { 415 p1 = originPoints.get(0); 416 p2 = originPoints.get(1); 417 p3 = originPoints.get(2); 418 } 419 else return; 420 421 edgePointValues.setText(tr("<html>" 422 + formatValue(p1.getY()) + ws + separator + ws + formatValue(p1.getX()) + "<br>" 423 + formatValue(p2.getY()) + ws + separator + ws + formatValue(p2.getX()) + "<br>" 424 + formatValue(p3.getY()) + ws + separator + ws + formatValue(p3.getX()) + "<br>" 425 + "</html>")); 426 427 contentPanel.remove(addEdgePointsButton); 428 contentPanel.add(edgePointValues, new GridBagConstraints(3, 1, 3, 1, 0.0, 0.0, 429 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 430 new Insets(5, 5, 5, 30), 0, 0)); 431 432 edgePointsChecked.setIcon(getCheckedIcon()); 433 contentPanel.add(edgePointsChecked, new GridBagConstraints(6, 1, 3, 1, 0.0, 0.0, 434 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 435 new Insets(5, 5, 5, 5), 0, 0)); 436 } 437 438 private void distance1Entered() { 439 contentPanel.remove(distance1Field); 440 distance1Value.setText(dist1Value); 441 contentPanel.add(distance1Value, new GridBagConstraints(3, 3, 2, 1, 0.0, 0.0, 442 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 443 new Insets(5, 5, 5, 30), 0, 0)); 444 445 distance1Checked.setIcon(getCheckedIcon()); 446 contentPanel.add(distance1Checked, new GridBagConstraints(6, 3, 3, 1, 0.0, 0.0, 447 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 448 new Insets(5, 5, 5, 5), 0, 0)); 449 } 450 451 private void distance2Entered() { 452 contentPanel.remove(distance2Field); 453 distance2Value.setText(dist2Value); 454 contentPanel.add(distance2Value, new GridBagConstraints(3, 4, 2, 1, 0.0, 0.0, 455 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 456 new Insets(5, 5, 5, 30), 0, 0)); 457 458 distance2Checked.setIcon(getCheckedIcon()); 459 contentPanel.add(distance2Checked, new GridBagConstraints(6, 4, 3, 1, 0.0, 0.0, 460 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 461 new Insets(5, 5, 5, 5), 0, 0)); 462 } 463 464 private void refFileEntered() { 465 contentPanel.remove(selectLayerButton); 466 contentPanel.remove(openButton); 467 refFileName.setText(tr("<html>Reference Name:</html>")); 468 refFileNameValue.setText(referenceFileName); 469 contentPanel.add(refFileNameValue, new GridBagConstraints(3, 6, 2, 1, 0.0, 0.0, 470 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 471 new Insets(5, 5, 5, 30), 0, 0)); 472 473 fileChecked.setIcon(getCheckedIcon()); 474 contentPanel.add(fileChecked, new GridBagConstraints(6, 6, 3, 1, 0.0, 0.0, 475 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 476 new Insets(5, 5, 5, 5), 0, 0)); 477 } 478 479 private void refPointValuesEntered() { 480 Point2D p1 = null; 481 Point2D p2 = null; 482 Point2D p3 = null; 483 484 if(this.referencePoints.size() == 3) { 485 p1 = referencePoints.get(0); 486 p2 = referencePoints.get(1); 487 p3 = referencePoints.get(2); 488 } 489 else return; 490 491 refPointValues.setText(tr("<html>" 492 + formatValue(p1.getY()) + ws + separator + ws + formatValue(p1.getX()) + "<br>" 493 + formatValue(p2.getY()) + ws + separator + ws + formatValue(p2.getX()) + "<br>" 494 + formatValue(p3.getY()) + ws + separator + ws + formatValue(p3.getX()) + "<br>" 495 + "</html>")); 496 497 contentPanel.remove(addRefPointsButton); 498 contentPanel.add(refPointValues, new GridBagConstraints(3, 8, 3, 1, 0.0, 0.0, 499 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 500 new Insets(5, 5, 5, 30), 0, 0)); 501 502 refPointsChecked.setIcon(getCheckedIcon()); 503 contentPanel.add(refPointsChecked, new GridBagConstraints(6, 8, 3, 1, 0.0, 0.0, 504 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 505 new Insets(5, 5, 5, 5), 0, 0)); 506 } 507 508 private void setDistance1() { 509 distance1.setText(tr("Point 1 to Point 2 (meter):")); 510 contentPanel.add(distance1, new GridBagConstraints(0, 3, 3, 1, 0.0, 0.0, 511 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 512 new Insets(5, 5, 5, 30), 0, 0)); 513 } 514 515 516 // GETTER / SETTER 517 518 public JButton getOpenButton() { 519 return this.openButton; 520 } 521 522 public JTextField getDistance1Field() { 523 return this.distance1Field; 524 } 525 526 public JTextField getDistance2Field() { 527 return this.distance2Field; 528 } 529 530 public String getDistance1FieldText() { 531 return this.distance1Field.getText(); 532 } 533 534 public String getDistance2FieldText() { 535 return this.distance2Field.getText(); 536 } 537 538 public void setOriginPoints(List<Point2D> points) { 539 this.originPoints = points; 540 edgePointValuesEntered(); 541 updateState(); 542 } 543 544 public void setReferencePoints(List<Point2D> points) { 545 this.referencePoints = points; 546 refPointValuesEntered(); 547 updateState(); 548 } 549 550 public void setDistance1Field(String s) { 551 this.distance1Field.setText(s); 552 updateState(); 553 } 554 555 public void setDistance2Field(String s) { 556 this.distance2Field.setText(s); 557 updateState(); 558 } 559 560 public void setDistance1Value(String valueAsString) { 561 this.dist1Value = valueAsString; 562 if(!valueAsString.equals("")) distance1Entered(); 563 updateState(); 564 } 565 566 public void setDistance2Value(String valueAsString) { 567 this.dist2Value = valueAsString; 568 if(!valueAsString.equals("")) distance2Entered(); 569 updateState(); 570 } 571 572 public void setReferenceFileName(String name) { 573 this.referenceFileName = name; 574 } 575 576 private void setFileChooser() { 577 fileChooser.setFileSelectionMode(FILES_ONLY); 578 FileNameExtensionFilter filter = new FileNameExtensionFilter(".osm, .gpx","osm", "gpx"); 579 fileChooser.setFileFilter(filter); 580 } 581 582 public void setReferenceFileNameValue(String value) { 583 this.referenceFileName = value; 584 this.refFileNameValue.setText(value); 585 refFileEntered(); 586 updateState(); 587 } 588 589 public JFileChooser getFileChooser() { 590 return this.fileChooser; 591 } 592 593 public String getFileName() { 594 return this.referenceFileName; 595 } 596 597 // LISTENER 598 599 public void setOkButtonListener(ActionListener l) { 600 this.runButton.addActionListener(l); 601 } 602 603 public void setCancelButtonListener(ActionListener l) { 604 this.cancelButton.addActionListener(l); 605 } 606 607 public void setWindowListener(WindowListener l) { 608 this.addWindowListener(l); 609 } 610 611 public void addOpenFileButtonListener(ActionListener l) { 612 this.openButton.addActionListener(l); 613 } 614 615 public void addSelectLayerButtonListener(ActionListener l) { 616 this.selectLayerButton.addActionListener(l); 617 } 618 619 public void addCancelButtonListener(ActionListener l) { 620 this.cancelButton.addActionListener(l); 621 } 622 623 public void addRunButtonListener(ActionListener l) { 624 this.runButton.addActionListener(l); 625 } 626 627 public void addEdgePointButtonListener(ActionListener l) { 628 this.addEdgePointsButton.addActionListener(l); 629 } 630 631 public void addReferencePointButtonListener(ActionListener l) { 632 this.addRefPointsButton.addActionListener(l); 633 } 634 635 public void addFrameWindowListener(WindowAdapter wAdapter) { 636 this.addWindowListener(wAdapter); 637 } 638 639 public void addDistance1FieldListener(FocusListener l) { 640 this.distance1Field.addFocusListener(l); 641 } 642 643 public void addDistance2FieldListener(FocusListener l) { 644 this.distance2Field.addFocusListener(l); 645 } 646 647 public void addHelpButtonListener(ActionListener l) { 648 this.helpButton.addActionListener(l); 649 } 650 651 652 // HELPER 653 654 private String formatValue(double value) { 655 return String.format(language, "%.3f", value); 656 } 657 658 private ImageIcon getCheckedIcon() { 659 String imageName = "checked.png"; 660 Image image = null; 661 try { 662 image = ImageIO.read(getClass().getResource("/images/" + imageName)); 663 } catch (Exception ex) { 664 System.out.println("Error: Could not load image " + imageName + "," + ex); 665 } 666 return new ImageIcon(image); 667 } 668 669 public void updateState() { 670 if(originPoints.isEmpty()) { 671 // button blink 672 distance1Field.setEnabled(false); 673 distance2Field.setEnabled(false); 674 openButton.setEnabled(false); 675 selectLayerButton.setEnabled(false); 676 addRefPointsButton.setEnabled(false); 677 runButton.setEnabled(false); 678 } 679 else { 680 if(dist1Value == null && dist2Value == null) { 681 distance1Field.setEnabled(true); 682 distance2Field.setEnabled(true); 683 } 684 if(dist1Value != null) { 685 openButton.setEnabled(true); 686 selectLayerButton.setEnabled(true); 687 } 688 if(referenceFileName != null) addRefPointsButton.setEnabled(true); 689 if(!referencePoints.isEmpty()) runButton.setEnabled(true); 690 } 691 } 692 693 public void refresh() { 694 this.setVisible(true); 695 } 677 696 678 697 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/layer/PicLayerAbstract.java
r35027 r35104 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 5 7 6 import java.awt.BasicStroke; … … 16 15 import java.awt.geom.Point2D; 17 16 import java.io.BufferedReader; 17 import java.io.File; 18 18 import java.io.IOException; 19 19 import java.io.InputStream; … … 39 39 import org.openstreetmap.josm.gui.MapView; 40 40 import org.openstreetmap.josm.gui.layer.Layer; 41 import org.openstreetmap.josm.gui.layer.geoimage.ImageEntry; 41 42 import org.openstreetmap.josm.plugins.piclayer.actions.LoadPictureCalibrationAction; 42 43 import org.openstreetmap.josm.plugins.piclayer.actions.LoadPictureCalibrationFromWorldAction; … … 63 64 private static Image pinTiledImage; 64 65 private static Image pinTiledImageOrange; 66 67 // save file for IO Sessions 68 File imageFile; 65 69 66 70 // Initial position of the image in the real world … … 248 252 public String getToolTipText() { 249 253 return getPicLayerName(); 254 } 255 256 public List<ImageEntry> getImages(){ 257 List<ImageEntry> list = new ArrayList<>(); 258 list.add(new ImageEntry(imageFile)); 259 return list; 250 260 } 251 261 -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/layer/PicLayerFromFile.java
r35027 r35104 40 40 // Remember the file 41 41 m_file = file; 42 super.imageFile = m_file; 42 43 43 44 if ("zip".equalsIgnoreCase(getFileExtension(file))) { … … 229 230 return f.getName().substring(dotIdx+1); 230 231 } 231 232 232 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/layer/PicLayerFromKML.java
r35027 r35104 25 25 26 26 pictureName = calibration.getName(); 27 28 super.imageFile = main; 27 29 28 30 // Set the name of the layer as the base name of the file
Note:
See TracChangeset
for help on using the changeset viewer.