Changeset 35030 in osm for applications


Ignore:
Timestamp:
2019-06-08T21:35:57+02:00 (5 years ago)
Author:
rebeccas95
Message:

Fixing #josm17788, add ability to use layer as reference, small changes for better use.

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  
    99
    1010import org.openstreetmap.josm.data.coor.LatLon;
    11 import org.openstreetmap.josm.data.coor.conversion.CoordinateFormatManager;
    12 import org.openstreetmap.josm.data.coor.conversion.ICoordinateFormat;
    1311import org.openstreetmap.josm.gui.MainApplication;
    1412import org.openstreetmap.josm.plugins.piclayer.actions.GenericPicTransformAction;
     
    7775    private void setLatLonOriginPoints(Point2D point) {
    7876        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();
    8279        currentLayer.getTransformer().addLatLonOriginPoint(new Point2D.Double(lonX, latY));
    8380    }
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/autocalibrate/AutoCalibrateHandler.java

    r35027 r35030  
    2525import org.openstreetmap.josm.actions.OpenFileAction;
    2626import org.openstreetmap.josm.data.coor.LatLon;
    27 import org.openstreetmap.josm.data.coor.conversion.CoordinateFormatManager;
    28 import org.openstreetmap.josm.data.coor.conversion.ICoordinateFormat;
    2927import org.openstreetmap.josm.data.osm.DataSet;
    3028import org.openstreetmap.josm.data.osm.Node;
     
    3230import org.openstreetmap.josm.gui.MapViewState.MapViewPoint;
    3331import org.openstreetmap.josm.gui.help.HelpBrowser;
     32import org.openstreetmap.josm.gui.layer.Layer;
    3433import org.openstreetmap.josm.plugins.piclayer.actions.transform.affine.MovePointAction;
    3534import org.openstreetmap.josm.plugins.piclayer.actions.transform.autocalibrate.helper.ObservableArrayList;
     
    3837import org.openstreetmap.josm.plugins.piclayer.gui.autocalibrate.ReferenceOptionView;
    3938import org.openstreetmap.josm.plugins.piclayer.gui.autocalibrate.ResultCheckView;
     39import org.openstreetmap.josm.plugins.piclayer.gui.autocalibrate.SelectLayerView;
    4040import org.openstreetmap.josm.plugins.piclayer.layer.PicLayerAbstract;
    4141import org.openstreetmap.josm.tools.Logging;
     
    5555        private ReferenceOptionView refOptionView;
    5656        private File referenceFile;
     57        private Layer referenceLayer;
    5758        private AutoCalibrator calibrator;
    5859        private ObservableArrayList<Point2D> originPointList;           // points set on picture to calibrate, scaled in LatLon
     
    6970                this.distance2To3 = 0.0;
    7071                this.referenceFile = null;
     72                this.referenceLayer = null;
    7173                this.currentPicLayer = null;
    7274                this.mainWindow = new CalibrationWindow();
     
    104106                        this.mainWindow.addDistance2FieldListener(new TextField2Listener());
    105107                        this.mainWindow.addOpenFileButtonListener(new OpenFileButtonListener());
     108                        this.mainWindow.addSelectLayerButtonListener(new SelectLayerButtonListener());
    106109                        this.mainWindow.addReferencePointButtonListener(new RefPointsButtonListener());
    107110                        this.mainWindow.addCancelButtonListener(new CancelButtonListener());
     
    156159
    157160        /**
     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        /**
    158212         * Cancel button listener
    159213         * @author rebsc
     
    164218            public void actionPerformed(ActionEvent e) {
    165219                        reset();
     220                        removeListChangedListener();
    166221            }
    167222        }
     
    221276                public void windowClosing(WindowEvent wEvt) {
    222277                        reset();
     278                        removeListChangedListener();
    223279                }
     280
    224281                };
    225282                return adapter;
     
    349406                @Override
    350407                public void mouseClicked(MouseEvent e) {
    351                         if(referenceFile == null) {
     408                        if(referenceFile == null && referenceLayer == null) {
    352409                                MainApplication.getMap().mapView.removeMouseListener(this);
    353410                                return;
     
    357414                                // add point to reference list in lat/lon scale
    358415                                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();
    362418                                Point2D llPoint = new Point2D.Double(lonX, latY);
    363419                                referencePointList.add(llPoint);
     
    397453                @Override
    398454                public void mouseClicked(MouseEvent e) {
    399                         if(referenceFile == null) {
     455                        if(referenceFile == null && referenceLayer == null) {
    400456                                MainApplication.getMap().mapView.removeMouseListener(this);
    401457                                return;
     
    405461                                // get pressed point in lat/lon
    406462                                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();
    410465                                Point2D llPoint = new Point2D.Double(lonX, latY);
    411466
     
    470525
    471526        // HELPER
    472 
    473         private void addFileInNewLayer(File file) {
    474                 List<File> files = new ArrayList<>();
    475                 files.add(file);
    476                 OpenFileAction.openFiles(files);
    477         }
    478527
    479528        public void prepare(PicLayerAbstract layer) {
     
    491540        }
    492541
     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
    493562        private void addListChangedListenerToPointLists() {
    494563                OriginSizePropertyListener originListener = new OriginSizePropertyListener();
     
    496565                RefSizePropertyListener refListener = new RefSizePropertyListener();
    497566                this.referencePointList.addPropertyChangeListener(refListener);
     567        }
     568
     569        private void removeListChangedListener() {
     570                currentPicLayer.getTransformer().getLatLonOriginPoints().removeAllListener();
     571                referencePointList.removeAllListener();
    498572        }
    499573
     
    531605        }
    532606
    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        }
    552612}
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/autocalibrate/helper/ObservableArrayList.java

    r35027 r35030  
    8989    }
    9090
     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
    9197}
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/gui/autocalibrate/CalibrationErrorView.java

    r35005 r35030  
    1818
    1919        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!");
    2021        public final static String CALIBRATION_ERROR = tr("Calibration failed!");
    2122        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  
    5959         private JButton helpButton;
    6060         private JButton openButton;
     61         private JButton selectLayerButton;
    6162         private JButton runButton;
    6263         private JButton cancelButton;
     
    114115              helpButton = new JButton();
    115116              openButton = new JButton();
     117              selectLayerButton = new JButton();
    116118              runButton = new JButton();
    117119              cancelButton = new JButton();
     
    168170          setRefFileName();
    169171                  setOpenButton();
     172                  setSelectLayerButton();
    170173              setRefPointHeader();
    171174              setRefPointNamesValues();
     
    238241                else {
    239242                    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,
    241244                                  GridBagConstraints.CENTER, GridBagConstraints.BOTH,
    242245                                  new Insets(5, 50, 5, 5), 0, 0));
     
    253256        private void setDistance1Field() {
    254257                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,
    256259                    GridBagConstraints.CENTER, GridBagConstraints.BOTH,
    257260                    new Insets(5, 50, 5, 5), 0, 0));
     
    267270        private void setDistance2Field() {
    268271            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,
    270273                  GridBagConstraints.CENTER, GridBagConstraints.BOTH,
    271274                  new Insets(5, 50, 5, 5), 0, 0));
     
    280283
    281284        private void setRefFileName() {
    282                 refFileName.setText(tr("<html>File Name:"
     285                refFileName.setText(tr("<html>Reference Name:"
    283286                      + "<br>"
    284287                      + "<br>"
     
    286289                      + "</html>"));
    287290
    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,
    289292                                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
    290293                                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));
    291310        }
    292311
     
    300319                }
    301320
    302             openButton = new JButton(tr("Open a File..."));
     321                openButton.setToolTipText(tr("Open a file as reference..."));
    303322            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, 50, 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));
    307326        }
    308327
     
    341360                                                + "</html>"));
    342361
    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,
    344363                                          GridBagConstraints.CENTER, GridBagConstraints.BOTH,
    345364                                      new Insets(5, 5, 5, 30), 0, 0));
     
    347366                 else {
    348367                      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,
    350369                                    GridBagConstraints.CENTER, GridBagConstraints.BOTH,
    351370                                    new Insets(5, 50, 5, 5), 0, 0));
     
    381400                Point2D p2 = null;
    382401                Point2D p3 = null;
    383                 DecimalFormat df = new DecimalFormat("###.###");
     402                DecimalFormat df = new DecimalFormat("###,###.###");
    384403
    385404                if(this.originPoints.size() == 3) {
     
    391410
    392411                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>"
    396415                                        + "</html>"));
    397416
     
    434453
    435454        private void refFileEntered() {
     455                contentPanel.remove(selectLayerButton);
    436456                contentPanel.remove(openButton);
    437                 refFileName.setText(tr("<html>File Name:</html>"));
     457                refFileName.setText(tr("<html>Reference Name:</html>"));
    438458                refFileNameValue.setText(referenceFileName);
    439459                contentPanel.add(refFileNameValue, new GridBagConstraints(3, 6, 2, 1, 0.0, 0.0,
     
    451471                Point2D p2 = null;
    452472                Point2D p3 = null;
    453                 DecimalFormat df = new DecimalFormat("###.###");
     473                DecimalFormat df = new DecimalFormat("###,###.###");
    454474
    455475                if(this.referencePoints.size() == 3) {
     
    461481
    462482                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>"
    466486                                                + "</html>"));
    467487
     
    539559                if(!valueAsString.equals(""))   distance2Entered();
    540560            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);
    553561        }
    554562
     
    580588        // LISTENER
    581589
     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
    582602        public void addOpenFileButtonListener(ActionListener l) {
    583603                this.openButton.addActionListener(l);
     604        }
     605
     606        public void addSelectLayerButtonListener(ActionListener l) {
     607                this.selectLayerButton.addActionListener(l);
    584608        }
    585609
     
    636660                        distance2Field.setEnabled(false);
    637661                        openButton.setEnabled(false);
     662                        selectLayerButton.setEnabled(false);
    638663                        addRefPointsButton.setEnabled(false);
    639664                        runButton.setEnabled(false);
     
    644669                                distance2Field.setEnabled(true);
    645670                        }
    646                         if(dist1Value != null)                  openButton.setEnabled(true);
     671                        if(dist1Value != null) {
     672                                openButton.setEnabled(true);
     673                                selectLayerButton.setEnabled(true);
     674                        }
    647675                        if(referenceFileName != null)   addRefPointsButton.setEnabled(true);
    648676                        if(!referencePoints.isEmpty())  runButton.setEnabled(true);
Note: See TracChangeset for help on using the changeset viewer.