Changeset 35030 in osm for applications
- Timestamp:
- 2019-06-08T21:35:57+02:00 (6 years ago)
- Location:
- applications/editors/josm/plugins/piclayer
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/affine/MovePointAction.java
r35027 r35030 9 9 10 10 import org.openstreetmap.josm.data.coor.LatLon; 11 import org.openstreetmap.josm.data.coor.conversion.CoordinateFormatManager;12 import org.openstreetmap.josm.data.coor.conversion.ICoordinateFormat;13 11 import org.openstreetmap.josm.gui.MainApplication; 14 12 import org.openstreetmap.josm.plugins.piclayer.actions.GenericPicTransformAction; … … 77 75 private void setLatLonOriginPoints(Point2D point) { 78 76 LatLon latLonPoint = MainApplication.getMap().mapView.getLatLon(point.getX(), point.getY()); 79 ICoordinateFormat mCoord = CoordinateFormatManager.getDefaultFormat(); 80 double latY = Double.parseDouble(mCoord.latToString(latLonPoint)); 81 double lonX = Double.parseDouble(mCoord.lonToString(latLonPoint)); 77 double latY = latLonPoint.getY(); 78 double lonX = latLonPoint.getX(); 82 79 currentLayer.getTransformer().addLatLonOriginPoint(new Point2D.Double(lonX, latY)); 83 80 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/autocalibrate/AutoCalibrateHandler.java
r35027 r35030 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;29 27 import org.openstreetmap.josm.data.osm.DataSet; 30 28 import org.openstreetmap.josm.data.osm.Node; … … 32 30 import org.openstreetmap.josm.gui.MapViewState.MapViewPoint; 33 31 import org.openstreetmap.josm.gui.help.HelpBrowser; 32 import org.openstreetmap.josm.gui.layer.Layer; 34 33 import org.openstreetmap.josm.plugins.piclayer.actions.transform.affine.MovePointAction; 35 34 import org.openstreetmap.josm.plugins.piclayer.actions.transform.autocalibrate.helper.ObservableArrayList; … … 38 37 import org.openstreetmap.josm.plugins.piclayer.gui.autocalibrate.ReferenceOptionView; 39 38 import org.openstreetmap.josm.plugins.piclayer.gui.autocalibrate.ResultCheckView; 39 import org.openstreetmap.josm.plugins.piclayer.gui.autocalibrate.SelectLayerView; 40 40 import org.openstreetmap.josm.plugins.piclayer.layer.PicLayerAbstract; 41 41 import org.openstreetmap.josm.tools.Logging; … … 55 55 private ReferenceOptionView refOptionView; 56 56 private File referenceFile; 57 private Layer referenceLayer; 57 58 private AutoCalibrator calibrator; 58 59 private ObservableArrayList<Point2D> originPointList; // points set on picture to calibrate, scaled in LatLon … … 69 70 this.distance2To3 = 0.0; 70 71 this.referenceFile = null; 72 this.referenceLayer = null; 71 73 this.currentPicLayer = null; 72 74 this.mainWindow = new CalibrationWindow(); … … 104 106 this.mainWindow.addDistance2FieldListener(new TextField2Listener()); 105 107 this.mainWindow.addOpenFileButtonListener(new OpenFileButtonListener()); 108 this.mainWindow.addSelectLayerButtonListener(new SelectLayerButtonListener()); 106 109 this.mainWindow.addReferencePointButtonListener(new RefPointsButtonListener()); 107 110 this.mainWindow.addCancelButtonListener(new CancelButtonListener()); … … 156 159 157 160 /** 161 * Select layer button listener 162 * @author rebsc 163 * 164 */ 165 private class SelectLayerButtonListener implements ActionListener { 166 private SelectLayerView selector; 167 168 @Override 169 public void actionPerformed(ActionEvent event) { 170 mainWindow.setVisible(false); 171 172 selector = new SelectLayerView(); 173 selector.setVisible(true); 174 175 selector.setOkButtonListener(new SelectorOkButtonListener()); 176 selector.setCancelButtonListener(new SelectorCancelButtonListener()); 177 } 178 179 private class SelectorCancelButtonListener implements ActionListener { 180 @Override 181 public void actionPerformed(ActionEvent e) { 182 selector.getFrame().dispatchEvent(new WindowEvent(selector.getFrame(), WindowEvent.WINDOW_CLOSING)); 183 } 184 } 185 186 private class SelectorOkButtonListener implements ActionListener { 187 @Override 188 public void actionPerformed(ActionEvent e) { 189 String filename = (String) selector.getList().getSelectedValue(); 190 191 if(filename != null) { 192 for(Layer l : MainApplication.getLayerManager().getLayers()) { 193 if(l.getName().equals(filename)) { 194 referenceLayer = l; 195 MainApplication.getLayerManager().setActiveLayer(l); 196 } 197 } 198 } 199 200 if(referenceLayer != null) { 201 mainWindow.setReferenceFileNameValue(filename); 202 } 203 else calibrator.showErrorView(CalibrationErrorView.SELECT_LAYER_ERROR); 204 205 selector.setVisible(false); 206 mainWindow.setVisible(true); 207 } 208 } 209 } 210 211 /** 158 212 * Cancel button listener 159 213 * @author rebsc … … 164 218 public void actionPerformed(ActionEvent e) { 165 219 reset(); 220 removeListChangedListener(); 166 221 } 167 222 } … … 221 276 public void windowClosing(WindowEvent wEvt) { 222 277 reset(); 278 removeListChangedListener(); 223 279 } 280 224 281 }; 225 282 return adapter; … … 349 406 @Override 350 407 public void mouseClicked(MouseEvent e) { 351 if(referenceFile == null ) {408 if(referenceFile == null && referenceLayer == null) { 352 409 MainApplication.getMap().mapView.removeMouseListener(this); 353 410 return; … … 357 414 // add point to reference list in lat/lon scale 358 415 LatLon latLonPoint = MainApplication.getMap().mapView.getLatLon(e.getPoint().getX(),e.getPoint().getY()); 359 ICoordinateFormat mCoord = CoordinateFormatManager.getDefaultFormat(); 360 double latY = Double.parseDouble(mCoord.latToString(latLonPoint)); 361 double lonX = Double.parseDouble(mCoord.lonToString(latLonPoint)); 416 double latY = latLonPoint.getY(); 417 double lonX = latLonPoint.getX(); 362 418 Point2D llPoint = new Point2D.Double(lonX, latY); 363 419 referencePointList.add(llPoint); … … 397 453 @Override 398 454 public void mouseClicked(MouseEvent e) { 399 if(referenceFile == null ) {455 if(referenceFile == null && referenceLayer == null) { 400 456 MainApplication.getMap().mapView.removeMouseListener(this); 401 457 return; … … 405 461 // get pressed point in lat/lon 406 462 LatLon latLonPoint = MainApplication.getMap().mapView.getLatLon(e.getPoint().getX(),e.getPoint().getY()); 407 ICoordinateFormat mCoord = CoordinateFormatManager.getDefaultFormat(); 408 double latY = Double.parseDouble(mCoord.latToString(latLonPoint)); 409 double lonX = Double.parseDouble(mCoord.lonToString(latLonPoint)); 463 double latY = latLonPoint.getY(); 464 double lonX = latLonPoint.getX(); 410 465 Point2D llPoint = new Point2D.Double(lonX, latY); 411 466 … … 470 525 471 526 // HELPER 472 473 private void addFileInNewLayer(File file) {474 List<File> files = new ArrayList<>();475 files.add(file);476 OpenFileAction.openFiles(files);477 }478 527 479 528 public void prepare(PicLayerAbstract layer) { … … 491 540 } 492 541 542 private void reset() { 543 originPointList = new ObservableArrayList<>(3); 544 referencePointList = new ObservableArrayList<>(3); 545 distance1To2 = 0.0; 546 distance2To3 = 0.0; 547 this.referenceFile = null; 548 this.referenceLayer = null; 549 resetLists(); 550 currentPicLayer.clearDrawReferencePoints(); 551 currentPicLayer.invalidate(); 552 mainWindow.setVisible(false); 553 mainWindow = new CalibrationWindow(); 554 addListenerToMainView(); 555 } 556 557 private void resetLists() { 558 currentPicLayer.getTransformer().clearOriginPoints(); 559 currentPicLayer.getTransformer().clearLatLonOriginPoints(); 560 } 561 493 562 private void addListChangedListenerToPointLists() { 494 563 OriginSizePropertyListener originListener = new OriginSizePropertyListener(); … … 496 565 RefSizePropertyListener refListener = new RefSizePropertyListener(); 497 566 this.referencePointList.addPropertyChangeListener(refListener); 567 } 568 569 private void removeListChangedListener() { 570 currentPicLayer.getTransformer().getLatLonOriginPoints().removeAllListener(); 571 referencePointList.removeAllListener(); 498 572 } 499 573 … … 531 605 } 532 606 533 private void reset() { 534 originPointList = new ObservableArrayList<>(3); 535 referencePointList = new ObservableArrayList<>(3); 536 distance1To2 = 0.0; 537 distance2To3 = 0.0; 538 this.referenceFile = null; 539 resetLists(); 540 currentPicLayer.clearDrawReferencePoints(); 541 currentPicLayer.invalidate(); 542 mainWindow.setVisible(false); 543 mainWindow = new CalibrationWindow(); 544 addListenerToMainView(); 545 } 546 547 private void resetLists() { 548 currentPicLayer.getTransformer().clearOriginPoints(); 549 currentPicLayer.getTransformer().clearLatLonOriginPoints(); 550 } 551 607 private void addFileInNewLayer(File file) { 608 List<File> files = new ArrayList<>(); 609 files.add(file); 610 OpenFileAction.openFiles(files); 611 } 552 612 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/autocalibrate/helper/ObservableArrayList.java
r35027 r35030 89 89 } 90 90 91 public void removeAllListener() { 92 PropertyChangeListener[] listener = changes.getPropertyChangeListeners(); 93 int size = listener.length; 94 for(int i=0; i<size; i++) changes.removePropertyChangeListener(listener[i]); 95 } 96 91 97 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/gui/autocalibrate/CalibrationErrorView.java
r35005 r35030 18 18 19 19 public final static String OUTLINE_FILE_ERROR = tr("Could not load outline file!"); 20 public final static String SELECT_LAYER_ERROR = tr("Could not select layer!"); 20 21 public final static String CALIBRATION_ERROR = tr("Calibration failed!"); 21 22 public final static String DIMENSION_ERROR = tr("<html> Calibration failed!<br>" -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/gui/autocalibrate/CalibrationWindow.java
r35005 r35030 59 59 private JButton helpButton; 60 60 private JButton openButton; 61 private JButton selectLayerButton; 61 62 private JButton runButton; 62 63 private JButton cancelButton; … … 114 115 helpButton = new JButton(); 115 116 openButton = new JButton(); 117 selectLayerButton = new JButton(); 116 118 runButton = new JButton(); 117 119 cancelButton = new JButton(); … … 168 170 setRefFileName(); 169 171 setOpenButton(); 172 setSelectLayerButton(); 170 173 setRefPointHeader(); 171 174 setRefPointNamesValues(); … … 238 241 else { 239 242 addEdgePointsButton = new JButton(tr("Add Points...")); 240 contentPanel.add(addEdgePointsButton, new GridBagConstraints(3, 1, 3, 1, 0.0, 0.0,243 contentPanel.add(addEdgePointsButton, new GridBagConstraints(3, 1, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 241 244 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 242 245 new Insets(5, 50, 5, 5), 0, 0)); … … 253 256 private void setDistance1Field() { 254 257 distance1Field.setText("Click here..."); 255 contentPanel.add(distance1Field, new GridBagConstraints(3, 3, 2, 1, 0.0, 0.0,258 contentPanel.add(distance1Field, new GridBagConstraints(3, 3, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 256 259 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 257 260 new Insets(5, 50, 5, 5), 0, 0)); … … 267 270 private void setDistance2Field() { 268 271 distance2Field.setText("Click here..."); 269 contentPanel.add(distance2Field, new GridBagConstraints(3, 4, 2, 1, 0.0, 0.0,272 contentPanel.add(distance2Field, new GridBagConstraints(3, 4, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 270 273 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 271 274 new Insets(5, 50, 5, 5), 0, 0)); … … 280 283 281 284 private void setRefFileName() { 282 refFileName.setText(tr("<html> File Name:"285 refFileName.setText(tr("<html>Reference Name:" 283 286 + "<br>" 284 287 + "<br>" … … 286 289 + "</html>")); 287 290 288 contentPanel.add(refFileName, new GridBagConstraints(0, 6, 3, 1, 0.0, 0.0,291 contentPanel.add(refFileName, new GridBagConstraints(0, 6, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 289 292 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 290 293 new Insets(5, 5, 5, 30), 0, 0)); 294 } 295 296 private void setSelectLayerButton() { 297 String imageName = "layerlist.png"; 298 Image image = null; 299 try { 300 image = ImageIO.read(getClass().getResource("/images/" + imageName)); 301 } catch (Exception ex) { 302 System.out.println("Error: Could not load image " + imageName + "," + ex); 303 } 304 305 selectLayerButton.setToolTipText(tr("Select a layer as reference...")); 306 selectLayerButton.setIcon(new ImageIcon(image)); 307 contentPanel.add(selectLayerButton, new GridBagConstraints(3, 6, 2, 1, 1.0, 0.0, 308 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 309 new Insets(5, 50, 5, 5), 0, 0)); 291 310 } 292 311 … … 300 319 } 301 320 302 openButton = new JButton(tr("Open a File..."));321 openButton.setToolTipText(tr("Open a file as reference...")); 303 322 openButton.setIcon(new ImageIcon(image)); 304 contentPanel.add(openButton, new GridBagConstraints( 3, 6, 2, 1, 0.0, 0.0,305 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 306 new Insets(5, 5 0, 5, 5), 0, 0));323 contentPanel.add(openButton, new GridBagConstraints(6, 6, GridBagConstraints.REMAINDER, 1, 1.0, 0.0, 324 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 325 new Insets(5, 5, 5, 5), 0, 0)); 307 326 } 308 327 … … 341 360 + "</html>")); 342 361 343 contentPanel.add(refPointValues, new GridBagConstraints(3, 8, 3, 1, 0.0, 0.0,362 contentPanel.add(refPointValues, new GridBagConstraints(3, 8, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 344 363 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 345 364 new Insets(5, 5, 5, 30), 0, 0)); … … 347 366 else { 348 367 addRefPointsButton = new JButton(tr("Add Points...")); 349 contentPanel.add(addRefPointsButton, new GridBagConstraints(3, 8, 3, 1, 0.0, 0.0,368 contentPanel.add(addRefPointsButton, new GridBagConstraints(3, 8, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 350 369 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 351 370 new Insets(5, 50, 5, 5), 0, 0)); … … 381 400 Point2D p2 = null; 382 401 Point2D p3 = null; 383 DecimalFormat df = new DecimalFormat("### .###");402 DecimalFormat df = new DecimalFormat("###,###.###"); 384 403 385 404 if(this.originPoints.size() == 3) { … … 391 410 392 411 edgePointValues.setText(tr("<html>" 393 + df.format(p1.getY()) + " , " + df.format(p1.getX()) + "<br>"394 + df.format(p2.getY()) + " , " + df.format(p2.getX()) + "<br>"395 + df.format(p3.getY()) + " , " + df.format(p3.getX()) + "<br>"412 + df.format(p1.getY()) + " , " + df.format(p1.getX()) + "<br>" 413 + df.format(p2.getY()) + " , " + df.format(p2.getX()) + "<br>" 414 + df.format(p3.getY()) + " , " + df.format(p3.getX()) + "<br>" 396 415 + "</html>")); 397 416 … … 434 453 435 454 private void refFileEntered() { 455 contentPanel.remove(selectLayerButton); 436 456 contentPanel.remove(openButton); 437 refFileName.setText(tr("<html> File Name:</html>"));457 refFileName.setText(tr("<html>Reference Name:</html>")); 438 458 refFileNameValue.setText(referenceFileName); 439 459 contentPanel.add(refFileNameValue, new GridBagConstraints(3, 6, 2, 1, 0.0, 0.0, … … 451 471 Point2D p2 = null; 452 472 Point2D p3 = null; 453 DecimalFormat df = new DecimalFormat("### .###");473 DecimalFormat df = new DecimalFormat("###,###.###"); 454 474 455 475 if(this.referencePoints.size() == 3) { … … 461 481 462 482 refPointValues.setText(tr("<html>" 463 + df.format(p1.getY()) + " , " + df.format(p1.getX()) + "<br>"464 + df.format(p2.getY()) + " , " + df.format(p2.getX()) + "<br>"465 + df.format(p3.getY()) + " , " + df.format(p3.getX()) + "<br>"483 + df.format(p1.getY()) + " , " + df.format(p1.getX()) + "<br>" 484 + df.format(p2.getY()) + " , " + df.format(p2.getX()) + "<br>" 485 + df.format(p3.getY()) + " , " + df.format(p3.getX()) + "<br>" 466 486 + "</html>")); 467 487 … … 539 559 if(!valueAsString.equals("")) distance2Entered(); 540 560 updateState(); 541 }542 543 public void setOkButtonListener(ActionListener l) {544 this.runButton.addActionListener(l);545 }546 547 public void setCancelButtonListener(ActionListener l) {548 this.cancelButton.addActionListener(l);549 }550 551 public void setWindowListener(WindowListener l) {552 this.addWindowListener(l);553 561 } 554 562 … … 580 588 // LISTENER 581 589 590 public void setOkButtonListener(ActionListener l) { 591 this.runButton.addActionListener(l); 592 } 593 594 public void setCancelButtonListener(ActionListener l) { 595 this.cancelButton.addActionListener(l); 596 } 597 598 public void setWindowListener(WindowListener l) { 599 this.addWindowListener(l); 600 } 601 582 602 public void addOpenFileButtonListener(ActionListener l) { 583 603 this.openButton.addActionListener(l); 604 } 605 606 public void addSelectLayerButtonListener(ActionListener l) { 607 this.selectLayerButton.addActionListener(l); 584 608 } 585 609 … … 636 660 distance2Field.setEnabled(false); 637 661 openButton.setEnabled(false); 662 selectLayerButton.setEnabled(false); 638 663 addRefPointsButton.setEnabled(false); 639 664 runButton.setEnabled(false); … … 644 669 distance2Field.setEnabled(true); 645 670 } 646 if(dist1Value != null) openButton.setEnabled(true); 671 if(dist1Value != null) { 672 openButton.setEnabled(true); 673 selectLayerButton.setEnabled(true); 674 } 647 675 if(referenceFileName != null) addRefPointsButton.setEnabled(true); 648 676 if(!referencePoints.isEmpty()) runButton.setEnabled(true);
Note:
See TracChangeset
for help on using the changeset viewer.