Ignore:
Timestamp:
2026-02-12T15:12:05+01:00 (8 days ago)
Author:
stoecker
Message:

set eol-style, fix checkstyle issues, add ignores

Location:
applications/editors/josm/plugins
Files:
28 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins

    • Property svn:ignore
      •  

        old new  
        2525validations_testing
        2626wikipedia
         27target
  • applications/editors/josm/plugins/cadastre-fr

    • Property svn:ignore
      •  

        old new  
        77findbugs-josm-cadastre-fr.xml
        88javadoc
         9target
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionBoundaries.java

    • Property svn:eol-style set to native
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionCancelGrab.java

    • Property svn:eol-style set to native
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionGrabPlanImage.java

    • Property svn:eol-style set to native
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionOpenPreferences.java

    • Property svn:eol-style set to native
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionRefineGeoRef.java

    • Property svn:eol-style set to native
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionSaveRasterAs.java

    • Property svn:eol-style set to native
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/mapmode/Address.java

    • Property svn:eol-style set to native
    r36385 r36483  
    182182            }
    183183            setSelectedWay(null);
    184         } else if (houseStreet == null){
     184        } else if (houseStreet == null) {
    185185            // check if the node belongs to an associatedStreet relation
    186186            Way wayInRelationAddr = findWayInRelationAddr(currentMouseNode);
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/mapmode/WMSAdjustAction.java

    • Property svn:eol-style set to native
    r36385 r36483  
    2626    private boolean rasterMoved;
    2727    private EastNorth prevEastNorth;
    28     enum Mode {MOVE_XY, MOVE_Z, ROTATE}
     28    enum Mode { MOVE_XY, MOVE_Z, ROTATE }
    2929
    3030    private static Mode mode;
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/download/CadastreDownloadSourcePanel.java

    r36385 r36483  
    241241            return;
    242242        }
    243 /*
    244         boolean isAreaTooLarge = false;
    245         if (!isDownloadNotes() && !isDownloadOsmData() && !isDownloadGpxData()) {
    246             isAreaTooLarge = false;
    247         } else if (isDownloadNotes() && !isDownloadOsmData() && !isDownloadGpxData()) {
    248             // see max_note_request_area in https://github.com/openstreetmap/openstreetmap-website/blob/master/config/example.application.yml
    249             isAreaTooLarge = bbox.getArea() > Config.getPref().getDouble("osm-server.max-request-area-notes", 25);
    250         } else {
    251             // see max_request_area in https://github.com/openstreetmap/openstreetmap-website/blob/master/config/example.application.yml
    252             isAreaTooLarge = bbox.getArea() > Config.getPref().getDouble("osm-server.max-request-area", 0.25);
    253         }
    254 
    255         displaySizeCheckResult(isAreaTooLarge);*/
    256243    }
    257244
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileGEN.java

    r33659 r36483  
    7272         */
    7373        public Bounds getBounds() {
    74 /*
    75             for (String s : Projections.getAllProjectionCodes()) {
    76                 Projection p = Projections.getProjectionByCode(s);
    77                 LatLon en = p.eastNorth2latlon(min);
    78                 double lat = en.lat();
    79                 double lon = en.lon();
    80                 if (43 <= lat && lat <= 44 && 1.38 <= lon && lon <= 1.45) {
    81                     System.out.println(s + ": " + p);
    82                 }
    83             }
    84 */
    8574            Projection proj = lot.geo.getCoorReference().getProjection();
    8675            return new Bounds(proj.eastNorth2latlon(min), proj.eastNorth2latlon(max));
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/session/CadastreSessionExporter.java

    • Property svn:eol-style set to native
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/session/CadastreSessionImporter.java

    • Property svn:eol-style set to native
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CacheFileLambert4ZoneFilter.java

    • Property svn:eol-style set to native
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CacheFileLambert9ZoneFilter.java

    • Property svn:eol-style set to native
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CacheFileUTM20NFilter.java

    • Property svn:eol-style set to native
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CadastreGrabber.java

    r34223 r36483  
    4444
    4545    private static URL getURLRaster(WMSLayer wmsLayer, EastNorth lambertMin, EastNorth lambertMax) throws MalformedURLException {
    46         // GET /scpc/wms?version=1.1&request=GetMap&layers=CDIF:PMC@QH4480001701&format=image/png&bbox=-1186,0,13555,8830&width=576&height=345&exception=application/vnd.ogc.se_inimage&styles= HTTP/1.1
     46        // GET /scpc/wms?version=1.1&request=GetMap&layers=CDIF:PMC@QH4480001701&format=image/png&bbox=-1186,0,13555,8830
     47        // &width=576&height=345&exception=application/vnd.ogc.se_inimage&styles= HTTP/1.1
    4748        final int cRasterX = CadastrePlugin.imageWidth; // keep width constant and adjust width to original image proportions
    4849        String str = CadastreInterface.BASE_URL+"/scpc/wms?version=1.1&request=GetMap";
     
    5455        str += wmsLayer.eastNorth2raster(lambertMin, lambertMax);
    5556        str += "&width="+cRasterX+"&height="; // maximum allowed by wms server (576/345, 800/378, 1000/634)
    56         str += (int) (cRasterX*(wmsLayer.communeBBox.max.getY() - wmsLayer.communeBBox.min.getY())/(wmsLayer.communeBBox.max.getX() - wmsLayer.communeBBox.min.getX()));
     57        str += (int) (cRasterX*(wmsLayer.communeBBox.max.getY() - wmsLayer.communeBBox.min.getY())
     58            / (wmsLayer.communeBBox.max.getX() - wmsLayer.communeBBox.min.getX()));
    5759        str += "&exception=application/vnd.ogc.se_inimage&styles="; // required for raster images
    5860        Logging.info("URL="+str);
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CadastreInterface.java

    r34668 r36483  
    477477        String line = getHttpClient(searchFormURL).connect().fetchContent();
    478478        parseBBoxCommune(wmsLayer, line);
    479         if (wmsLayer.isRaster() && !wmsLayer.isAlreadyGeoreferenced()) {
    480             parseGeoreferences(wmsLayer, line);
    481         }
    482479    }
    483480
     
    497494    }
    498495
    499     private static void parseGeoreferences(WMSLayer wmsLayer, String input) {
    500         /* commented since cadastre WMS changes mid july 2013
    501          * until new GeoBox coordinates parsing is solved */
    502 //        if (input.lastIndexOf(cBBoxCommunStart) != -1) {
    503 //            input = input.substring(input.lastIndexOf(cBBoxCommunStart));
    504 //            input = input.substring(input.indexOf(cBBoxCommunEnd)+cBBoxCommunEnd.length());
    505 //            int i = input.indexOf(",");
    506 //            int j = input.indexOf(",", i+1);
    507 //            String str = input.substring(i+1, j);
    508 //            double unknown_yet = tryParseDouble(str);
    509 //            int j_ = input.indexOf(",", j+1);
    510 //            double angle = Double.parseDouble(input.substring(j+1, j_));
    511 //            int k = input.indexOf(",", j_+1);
    512 //            double scale_origin = Double.parseDouble(input.substring(j_+1, k));
    513 //            int l = input.indexOf(",", k+1);
    514 //            double dpi = Double.parseDouble(input.substring(k+1, l));
    515 //            int m = input.indexOf(",", l+1);
    516 //            double fX = Double.parseDouble(input.substring(l+1, m));
    517 //            int n = input.indexOf(",", m+1);
    518 //            double fY = Double.parseDouble(input.substring(m+1, n));
    519 //            int o = input.indexOf(",", n+1);
    520 //            double X0 = Double.parseDouble(input.substring(n+1, o));
    521 //            int p = input.indexOf(",", o+1);
    522 //            double Y0 = Double.parseDouble(input.substring(o+1, p));
    523 //            if (X0 != 0.0 && Y0 != 0) {
    524 //                wmsLayer.setAlreadyGeoreferenced(true);
    525 //                wmsLayer.fX = fX;
    526 //                wmsLayer.fY = fY;
    527 //                wmsLayer.angle = angle;
    528 //                wmsLayer.X0 = X0;
    529 //                wmsLayer.Y0 = Y0;
    530 //            }
    531 //            Main.info("parse georef:"+unknown_yet+","+angle+","+scale_origin+","+dpi+","+fX+","+fY+","+X0+","+Y0);
    532 //        }
    533     }
    534 
    535496    private static void checkLayerDuplicates(WMSLayer wmsLayer) throws DuplicateLayerException {
    536497        if (MainApplication.getMap() != null) {
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/DownloadSVGBuilding.java

    • Property svn:eol-style set to native
    r36480 r36483  
    216216    private String grabBoundary(EastNorthBound bbox) throws IOException, OsmTransferException {
    217217        try {
    218             URL url = null;
    219             url = getURLsvg(bbox);
     218            URL url = getURLsvg(bbox);
    220219            return grabSVG(url);
    221220        } catch (MalformedURLException e) {
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/DownloadSVGTask.java

    • Property svn:eol-style set to native
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/DownloadWMSPlanImage.java

    • Property svn:eol-style set to native
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/GrabThread.java

    • Property svn:eol-style set to native
    r34668 r36483  
    77import java.io.IOException;
    88import java.util.ArrayList;
     9import java.util.List;
    910import java.util.concurrent.locks.Lock;
    1011import java.util.concurrent.locks.ReentrantLock;
     
    2627    private Lock lockImagesToGrag = new ReentrantLock();
    2728
    28     private ArrayList<EastNorthBound> imagesToGrab = new ArrayList<>();
     29    private List<EastNorthBound> imagesToGrab = new ArrayList<>();
    2930
    3031    private CacheControl cacheControl = null;
     
    3839     * @param moreImages more images to grab
    3940     */
    40     void addImages(ArrayList<EastNorthBound> moreImages) {
     41    void addImages(List<EastNorthBound> moreImages) {
    4142        lockImagesToGrag.lock();
    4243        try {
     
    6364    }
    6465
    65     ArrayList<EastNorthBound> getImagesToGrabCopy() {
    66         ArrayList<EastNorthBound> copyList = new ArrayList<>();
     66    List<EastNorthBound> getImagesToGrabCopy() {
     67        List<EastNorthBound> copyList = new ArrayList<>();
    6768        lockImagesToGrag.lock();
    6869        try {
     
    9192            while (getImagesToGrabSize() > 0) {
    9293                lockImagesToGrag.lock();
    93                 lockCurrentGrabImage.lock();
    94                 currentGrabImage = imagesToGrab.get(0);
    95                 lockCurrentGrabImage.unlock();
    96                 imagesToGrab.remove(0);
    97                 lockImagesToGrag.unlock();
     94                try {
     95                    lockCurrentGrabImage.lock();
     96                    try {
     97                        currentGrabImage = imagesToGrab.get(0);
     98                        lockCurrentGrabImage.unlock();
     99                    } finally {
     100                        imagesToGrab.remove(0);
     101                    }
     102                } finally {
     103                    lockImagesToGrag.unlock();
     104                }
    98105                if (canceled) {
    99106                    break;
     
    145152            Logging.info("grab thread list empty");
    146153            lockCurrentGrabImage.lock();
    147             currentGrabImage = null;
    148             lockCurrentGrabImage.unlock();
     154            try {
     155                currentGrabImage = null;
     156            } finally {
     157                lockCurrentGrabImage.unlock();
     158            }
    149159            if (canceled) {
    150160                clearImagesToGrab();
     
    168178            getCacheControl().deleteCacheFile();
    169179            wmsLayer.imagesLock.lock();
    170             for (GeorefImage image : wmsLayer.getImages()) {
    171                 getCacheControl().saveCache(image);
    172             }
    173             wmsLayer.imagesLock.unlock();
     180            try {
     181                for (GeorefImage image : wmsLayer.getImages()) {
     182                    getCacheControl().saveCache(image);
     183                }
     184            } finally {
     185                wmsLayer.imagesLock.unlock();
     186            }
    174187        }
    175188    }
     
    204217    void paintBoxesToGrab(Graphics g, MapView mv) {
    205218        if (getImagesToGrabSize() > 0) {
    206             ArrayList<EastNorthBound> imagesToGrab = getImagesToGrabCopy();
     219            List<EastNorthBound> imagesToGrab = getImagesToGrabCopy();
    207220            for (EastNorthBound img : imagesToGrab) {
    208221                paintBox(g, mv, img, Color.red);
     
    210223        }
    211224        lockCurrentGrabImage.lock();
    212         if (currentGrabImage != null) {
    213             paintBox(g, mv, currentGrabImage, Color.orange);
    214         }
    215         lockCurrentGrabImage.unlock();
     225        try {
     226            if (currentGrabImage != null) {
     227                paintBox(g, mv, currentGrabImage, Color.orange);
     228            }
     229        } finally {
     230            lockCurrentGrabImage.unlock();
     231        }
    216232    }
    217233
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/RasterImageGeoreferencer.java

    • Property svn:eol-style set to native
    r34458 r36483  
    4848    }
    4949
    50    /**
    51     *
     50    /**
     51     *
     52     * @param wmsLayer WMS layer
     53     * @return false if all operations are canceled
     54     */
     55    public boolean startCropping(WMSLayer wmsLayer) {
     56        this.wmsLayer = wmsLayer;
     57        mode = cGetCorners;
     58        countMouseClicked = 0;
     59        initialClickDelay = Config.getPref().getInt("cadastrewms.georef-click-delay", 200);
     60        mouseClickedTime = System.currentTimeMillis();
     61        Object[] options = {"OK", "Cancel"};
     62        int ret = GuiHelper.runInEDTAndWaitAndReturn(() -> JOptionPane.showOptionDialog(null,
     63                tr("Click first corner for image cropping\n(two points required)"),
     64                tr("Image cropping"),
     65                JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
     66                null, options, options[0]));
     67        if (ret == JOptionPane.OK_OPTION) {
     68            mouseClickedTime = System.currentTimeMillis();
     69        } else
     70            if (canceledOrRestartCurrAction("image cropping"))
     71                return startCropping(wmsLayer);
     72        return true;
     73    }
     74
     75    /**
    5276    * @param wmsLayer WMS layer
    5377    * @return false if all operations are canceled
    5478    */
    55    public boolean startCropping(WMSLayer wmsLayer) {
    56        this.wmsLayer = wmsLayer;
    57        mode = cGetCorners;
    58        countMouseClicked = 0;
    59        initialClickDelay = Config.getPref().getInt("cadastrewms.georef-click-delay", 200);
    60        mouseClickedTime = System.currentTimeMillis();
    61        Object[] options = {"OK", "Cancel"};
    62        int ret = GuiHelper.runInEDTAndWaitAndReturn(() -> JOptionPane.showOptionDialog(null,
    63                tr("Click first corner for image cropping\n(two points required)"),
    64                tr("Image cropping"),
    65                JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
    66                null, options, options[0]));
    67        if (ret == JOptionPane.OK_OPTION) {
    68            mouseClickedTime = System.currentTimeMillis();
    69        } else
    70            if (canceledOrRestartCurrAction("image cropping"))
    71                return startCropping(wmsLayer);
    72        return true;
    73    }
    74 
    75   /**
    76    * @param wmsLayer WMS layer
    77    * @return false if all operations are canceled
    78    */
    79   public boolean startGeoreferencing(WMSLayer wmsLayer) {
    80       this.wmsLayer = wmsLayer;
    81       countMouseClicked = 0;
    82       mode = cGetLambertCrosspieces;
    83       initialClickDelay = Config.getPref().getInt("cadastrewms.georef-click-delay", 200);
    84       mouseClickedTime = System.currentTimeMillis();
    85       Object[] options = {"OK", "Cancel"};
    86       int ret = JOptionPane.showOptionDialog(null,
    87               tr("Click first Lambert crosspiece for georeferencing\n(two points required)"),
    88               tr("Image georeferencing"),
    89               JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
    90               null, options, options[0]);
    91       if (ret == JOptionPane.OK_OPTION) {
    92           mouseClickedTime = System.currentTimeMillis();
    93       } else
    94           if (canceledOrRestartCurrAction("georeferencing"))
    95               return startGeoreferencing(wmsLayer);
    96       return true;
    97   }
    98 
    99   public boolean isRunning() {
    100       return (countMouseClicked != 0 || mode != 0);
    101   }
    102 
    103   @Override
    104   public void mouseClicked(MouseEvent e) {
    105       if (System.currentTimeMillis() - mouseClickedTime < initialClickDelay) {
    106           Logging.info("mouse click bounce detected");
    107           return; // mouse click anti-bounce
    108       } else
    109           mouseClickedTime = System.currentTimeMillis();
    110       if (e.getButton() != MouseEvent.BUTTON1)
    111           return;
    112       if (ignoreMouseClick) return; // In case we are currently just allowing zooming to read lambert coordinates
    113       EastNorth ea = ProjectionRegistry.getProjection().latlon2eastNorth(MainApplication.getMap().mapView.getLatLon(e.getX(), e.getY()));
    114       Logging.info("click:"+countMouseClicked+" ,"+ea+", mode:"+mode);
    115       if (clickOnTheMap) {
    116           clickOnTheMap = false;
    117           handleNewCoordinates(ea.east(), ea.north());
    118       } else {
    119           // ignore clicks outside the image
    120           if (ea.east() < wmsLayer.getImage(0).min.east() || ea.east() > wmsLayer.getImage(0).max.east()
    121                   || ea.north() < wmsLayer.getImage(0).min.north() || ea.north() > wmsLayer.getImage(0).max.north()) {
    122               Logging.info("ignore click outside the image");
    123               return;
    124           }
    125           countMouseClicked++;
    126           if (mode == cGetCorners) {
    127               if (countMouseClicked == 1) {
    128                   ea1 = ea;
    129                   continueCropping();
    130               }
    131               if (countMouseClicked == 2) {
    132                   wmsLayer.cropImage(ea1, ea);
    133                   wmsLayer.invalidate();
    134                   startGeoreferencing(wmsLayer);
    135               }
    136           } else if (mode == cGetLambertCrosspieces) {
    137               if (countMouseClicked == 1) {
    138                   ea1 = ea;
    139                   inputLambertPosition(); // This will automatically asks for second point and continue the georeferencing
    140               }
    141               if (countMouseClicked == 2) {
    142                   ea2 = ea;
    143                   inputLambertPosition(); // This will automatically ends the georeferencing
    144               }
    145           }
    146       }
    147   }
    148 
    149   /**
    150    *
    151    * @return false if all operations are canceled
    152    */
    153  private boolean canceledOrRestartCurrAction(String action) {
    154      Object[] options = {"Cancel", "Retry"};
    155      int selectedValue = JOptionPane.showOptionDialog(null,
    156              tr("Do you want to cancel completely\n"+
    157                      "or just retry "+action+" ?"), "",
    158              JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
    159              null, options, options[0]);
    160      countMouseClicked = 0;
    161      if (selectedValue == 0) { // "Cancel"
    162          // remove layer
    163          MainApplication.getLayerManager().removeLayer(wmsLayer);
    164          wmsLayer = null;
    165          MainApplication.getMap().mapView.removeMouseListener(this);
    166          return false;
    167      }
    168      return true;
    169  }
    170 
    171  /**
    172   * Use point org1 as anchor for scale, then move org1 to dst1, then rotate org2 on dst2
    173   * around org1/dst1 anchor
    174   * @param org1 first point at original coordinate system (the grabbed image)
    175   * @param org2 second point
    176   * @param dst1 first point at final destination coordinate system (the real east/north coordinate system)
    177   * @param dst2 second point
    178   */
    179  private void affineTransform(EastNorth org1, EastNorth org2, EastNorth dst1, EastNorth dst2) {
    180      // handle an NPE case I'm not able to reproduce
    181      if (org1 == null || org2 == null || dst1 == null || dst2 == null) {
    182          JOptionPane.showMessageDialog(MainApplication.getMainFrame(),
    183                  tr("Ooops. I failed to catch all coordinates\n"+
    184                     "correctly. Retry please."));
    185          Logging.warn("failed to transform: one coordinate missing:"
    186                     +"org1="+org1+", org2="+org2+", dst1="+dst1+", dst2="+dst2);
    187          return;
    188      }
    189      double angle = dst1.heading(dst2) - org1.heading(org2);
    190      double proportion = dst1.distance(dst2)/org1.distance(org2);
    191      // move
    192      double dx = dst1.getX() - org1.getX();
    193      double dy = dst1.getY() - org1.getY();
    194      wmsLayer.getImage(0).shear(dx, dy);
    195      // rotate : dst1 is anchor for rotation and scale
    196      wmsLayer.getImage(0).rotate(dst1, angle);
    197      // scale image from anchor dst1
    198      wmsLayer.getImage(0).scale(dst1, proportion);
    199  }
    200 
    201  /**
    202   * Ends the georeferencing by computing the affine transformation
    203   */
    204  private void endGeoreferencing() {
    205      MainApplication.getMap().mapView.removeMouseListener(this);
    206      affineTransform(ea1, ea2, georefpoint1, georefpoint2);
    207      wmsLayer.grabThread.saveNewCache();
    208      wmsLayer.invalidate();
    209      actionCompleted();
    210      clickOnTheMap = false;
    211      ignoreMouseClick = false;
    212  }
    213 
    214  private void inputLambertPosition() {
    215      JLabel labelEnterPosition = new JLabel(
    216              tr("Enter cadastre east,north position"));
    217      JLabel labelWarning = new JLabel(
    218              tr("(Warning: verify north with arrow !!)"));
    219      JPanel p = new JPanel(new GridBagLayout());
    220      JLabel labelEast = new JLabel(tr("East"));
    221      JLabel labelNorth = new JLabel(tr("North"));
    222      final JTextField inputEast = new JTextField();
    223      final JTextField inputNorth = new JTextField();
    224      p.add(labelEnterPosition, GBC.eol());
    225      p.add(labelWarning, GBC.eol());
    226      p.add(labelEast, GBC.std().insets(0, 0, 10, 0));
    227      p.add(inputEast, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 5, 0, 5));
    228      p.add(labelNorth, GBC.std().insets(0, 0, 10, 0));
    229      p.add(inputNorth, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 5, 0, 5));
    230      final Object[] options = {tr("OK"),
    231              tr("Cancel"),
    232              tr("I use the mouse")};
    233      final JOptionPane pane = new JOptionPane(p,
    234              JOptionPane.INFORMATION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION,
    235              null, options, options[0]);
    236      String number;
    237      if (countMouseClicked == 1)
    238          number = "first";
    239      else
    240          number = "second";
    241      JDialog dialog = pane.createDialog(MainApplication.getMainFrame(), tr(
    242              "Set {0} Lambert coordinates", number));
    243      dialog.setModal(false);
    244      ignoreMouseClick = true; // To avoid mouseClicked from being called
    245                               // during coordinates reading
    246      dialog.setAlwaysOnTop(true);
    247      dialog.setVisible(true);
    248      pane.addPropertyChangeListener(new PropertyChangeListener() {
    249          @Override
    250          public void propertyChange(PropertyChangeEvent evt) {
    251              if (JOptionPane.VALUE_PROPERTY.equals(evt.getPropertyName())) {
    252                  ignoreMouseClick = false;
    253                  // Cancel
    254                  if (pane.getValue().equals(options[1])) {
    255                      if (canceledOrRestartCurrAction("georeferencing"))
    256                          startGeoreferencing(wmsLayer);
    257                  }
    258                  // Click on the map
    259                  if (pane.getValue().equals(options[2])) {
    260                      clickOnTheMap = true;
    261                  } else {
    262                  // OK (coordinates manually entered)
    263                      clickOnTheMap = false;
    264                      if (inputEast.getText().length() != 0
    265                              && inputNorth.getText().length() != 0) {
    266                          double e, n;
    267                          try {
    268                              e = Double.parseDouble(inputEast.getText());
    269                              n = Double.parseDouble(inputNorth.getText());
    270                          } catch (NumberFormatException ex) {
    271                              return;
    272                          }
    273                          handleNewCoordinates(e, n);
    274                      }
    275                  }
    276              }
    277          }
    278      });
    279  }
    280 
    281  /**
    282  *
    283  * @return false if all operations are canceled
    284  */
    285 private boolean continueCropping() {
    286     Object[] options = {"OK", "Cancel"};
    287     int ret = JOptionPane.showOptionDialog(null,
    288             tr("Click second corner for image cropping"),
    289             tr("Image cropping"),
    290             JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
     79    public boolean startGeoreferencing(WMSLayer wmsLayer) {
     80        this.wmsLayer = wmsLayer;
     81        countMouseClicked = 0;
     82        mode = cGetLambertCrosspieces;
     83        initialClickDelay = Config.getPref().getInt("cadastrewms.georef-click-delay", 200);
     84        mouseClickedTime = System.currentTimeMillis();
     85        Object[] options = {"OK", "Cancel"};
     86        int ret = JOptionPane.showOptionDialog(null,
     87                tr("Click first Lambert crosspiece for georeferencing\n(two points required)"),
     88                tr("Image georeferencing"),
     89                JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
     90                null, options, options[0]);
     91        if (ret == JOptionPane.OK_OPTION) {
     92            mouseClickedTime = System.currentTimeMillis();
     93        } else
     94            if (canceledOrRestartCurrAction("georeferencing"))
     95                return startGeoreferencing(wmsLayer);
     96        return true;
     97    }
     98
     99    public boolean isRunning() {
     100        return (countMouseClicked != 0 || mode != 0);
     101    }
     102
     103    @Override
     104    public void mouseClicked(MouseEvent e) {
     105        if (System.currentTimeMillis() - mouseClickedTime < initialClickDelay) {
     106            Logging.info("mouse click bounce detected");
     107            return; // mouse click anti-bounce
     108        } else
     109            mouseClickedTime = System.currentTimeMillis();
     110        if (e.getButton() != MouseEvent.BUTTON1)
     111            return;
     112        if (ignoreMouseClick) return; // In case we are currently just allowing zooming to read lambert coordinates
     113        EastNorth ea = ProjectionRegistry.getProjection().latlon2eastNorth(MainApplication.getMap().mapView.getLatLon(e.getX(), e.getY()));
     114        Logging.info("click:"+countMouseClicked+" ,"+ea+", mode:"+mode);
     115        if (clickOnTheMap) {
     116            clickOnTheMap = false;
     117            handleNewCoordinates(ea.east(), ea.north());
     118        } else {
     119            // ignore clicks outside the image
     120            if (ea.east() < wmsLayer.getImage(0).min.east() || ea.east() > wmsLayer.getImage(0).max.east()
     121                    || ea.north() < wmsLayer.getImage(0).min.north() || ea.north() > wmsLayer.getImage(0).max.north()) {
     122                Logging.info("ignore click outside the image");
     123                return;
     124            }
     125            countMouseClicked++;
     126            if (mode == cGetCorners) {
     127                if (countMouseClicked == 1) {
     128                    ea1 = ea;
     129                    continueCropping();
     130                }
     131                if (countMouseClicked == 2) {
     132                    wmsLayer.cropImage(ea1, ea);
     133                    wmsLayer.invalidate();
     134                    startGeoreferencing(wmsLayer);
     135                }
     136            } else if (mode == cGetLambertCrosspieces) {
     137                if (countMouseClicked == 1) {
     138                    ea1 = ea;
     139                    inputLambertPosition(); // This will automatically asks for second point and continue the georeferencing
     140                }
     141                if (countMouseClicked == 2) {
     142                    ea2 = ea;
     143                    inputLambertPosition(); // This will automatically ends the georeferencing
     144                }
     145            }
     146        }
     147    }
     148
     149    /**
     150    *
     151    * @return false if all operations are canceled
     152    */
     153    private boolean canceledOrRestartCurrAction(String action) {
     154        Object[] options = {"Cancel", "Retry"};
     155        int selectedValue = JOptionPane.showOptionDialog(null,
     156            tr("Do you want to cancel completely\n"+
     157                "or just retry "+action+" ?"), "",
     158            JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
    291159            null, options, options[0]);
    292     if (ret != JOptionPane.OK_OPTION) {
    293         if (canceledOrRestartCurrAction("image cropping"))
    294             return startCropping(wmsLayer);
    295     }
    296     return true;
     160        countMouseClicked = 0;
     161        if (selectedValue == 0) { // "Cancel"
     162            // remove layer
     163            MainApplication.getLayerManager().removeLayer(wmsLayer);
     164            wmsLayer = null;
     165            MainApplication.getMap().mapView.removeMouseListener(this);
     166            return false;
     167        }
     168        return true;
     169    }
     170
     171    /**
     172    * Use point org1 as anchor for scale, then move org1 to dst1, then rotate org2 on dst2
     173    * around org1/dst1 anchor
     174    * @param org1 first point at original coordinate system (the grabbed image)
     175    * @param org2 second point
     176    * @param dst1 first point at final destination coordinate system (the real east/north coordinate system)
     177    * @param dst2 second point
     178    */
     179    private void affineTransform(EastNorth org1, EastNorth org2, EastNorth dst1, EastNorth dst2) {
     180        // handle an NPE case I'm not able to reproduce
     181        if (org1 == null || org2 == null || dst1 == null || dst2 == null) {
     182            JOptionPane.showMessageDialog(MainApplication.getMainFrame(),
     183                    tr("Ooops. I failed to catch all coordinates\n"+
     184                        "correctly. Retry please."));
     185            Logging.warn("failed to transform: one coordinate missing:"
     186                        +"org1="+org1+", org2="+org2+", dst1="+dst1+", dst2="+dst2);
     187            return;
     188        }
     189        double angle = dst1.heading(dst2) - org1.heading(org2);
     190        double proportion = dst1.distance(dst2)/org1.distance(org2);
     191        // move
     192        double dx = dst1.getX() - org1.getX();
     193        double dy = dst1.getY() - org1.getY();
     194        wmsLayer.getImage(0).shear(dx, dy);
     195        // rotate : dst1 is anchor for rotation and scale
     196        wmsLayer.getImage(0).rotate(dst1, angle);
     197        // scale image from anchor dst1
     198        wmsLayer.getImage(0).scale(dst1, proportion);
     199    }
     200
     201    /**
     202    * Ends the georeferencing by computing the affine transformation
     203    */
     204    private void endGeoreferencing() {
     205        MainApplication.getMap().mapView.removeMouseListener(this);
     206        affineTransform(ea1, ea2, georefpoint1, georefpoint2);
     207        wmsLayer.grabThread.saveNewCache();
     208        wmsLayer.invalidate();
     209        actionCompleted();
     210        clickOnTheMap = false;
     211        ignoreMouseClick = false;
     212    }
     213
     214    private void inputLambertPosition() {
     215        JLabel labelEnterPosition = new JLabel(
     216                tr("Enter cadastre east,north position"));
     217        JLabel labelWarning = new JLabel(
     218                tr("(Warning: verify north with arrow !!)"));
     219        JPanel p = new JPanel(new GridBagLayout());
     220        JLabel labelEast = new JLabel(tr("East"));
     221        JLabel labelNorth = new JLabel(tr("North"));
     222        final JTextField inputEast = new JTextField();
     223        final JTextField inputNorth = new JTextField();
     224        p.add(labelEnterPosition, GBC.eol());
     225        p.add(labelWarning, GBC.eol());
     226        p.add(labelEast, GBC.std().insets(0, 0, 10, 0));
     227        p.add(inputEast, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 5, 0, 5));
     228        p.add(labelNorth, GBC.std().insets(0, 0, 10, 0));
     229        p.add(inputNorth, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 5, 0, 5));
     230        final Object[] options = {tr("OK"),
     231                tr("Cancel"),
     232                tr("I use the mouse")};
     233        final JOptionPane pane = new JOptionPane(p,
     234                JOptionPane.INFORMATION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION,
     235                null, options, options[0]);
     236        String number;
     237        if (countMouseClicked == 1)
     238            number = "first";
     239        else
     240            number = "second";
     241        JDialog dialog = pane.createDialog(MainApplication.getMainFrame(), tr(
     242                "Set {0} Lambert coordinates", number));
     243        dialog.setModal(false);
     244        // To avoid mouseClicked from being called during coordinates reading
     245        ignoreMouseClick = true;
     246        dialog.setAlwaysOnTop(true);
     247        dialog.setVisible(true);
     248        pane.addPropertyChangeListener(new PropertyChangeListener() {
     249            @Override
     250            public void propertyChange(PropertyChangeEvent evt) {
     251                if (JOptionPane.VALUE_PROPERTY.equals(evt.getPropertyName())) {
     252                    ignoreMouseClick = false;
     253                    // Cancel
     254                    if (pane.getValue().equals(options[1])) {
     255                        if (canceledOrRestartCurrAction("georeferencing"))
     256                            startGeoreferencing(wmsLayer);
     257                    }
     258                    // Click on the map
     259                    if (pane.getValue().equals(options[2])) {
     260                        clickOnTheMap = true;
     261                    } else {
     262                        // OK (coordinates manually entered)
     263                        clickOnTheMap = false;
     264                        if (inputEast.getText().length() != 0
     265                                && inputNorth.getText().length() != 0) {
     266                            double e, n;
     267                            try {
     268                                e = Double.parseDouble(inputEast.getText());
     269                                n = Double.parseDouble(inputNorth.getText());
     270                            } catch (NumberFormatException ex) {
     271                                return;
     272                            }
     273                            handleNewCoordinates(e, n);
     274                        }
     275                    }
     276                }
     277            }
     278        });
     279    }
     280
     281    /**
     282    * Ask if cropping should be continued
     283    * @return false if all operations are canceled
     284    */
     285    private boolean continueCropping() {
     286        Object[] options = {"OK", "Cancel"};
     287        int ret = JOptionPane.showOptionDialog(null,
     288                tr("Click second corner for image cropping"),
     289                tr("Image cropping"),
     290                JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
     291                null, options, options[0]);
     292        if (ret != JOptionPane.OK_OPTION) {
     293            if (canceledOrRestartCurrAction("image cropping"))
     294                return startCropping(wmsLayer);
     295        }
     296        return true;
     297    }
     298
     299    public void transformGeoreferencedImg() {
     300        georefpoint1 = new EastNorth(wmsLayer.X0, wmsLayer.Y0);
     301        georefpoint2 = new EastNorth(wmsLayer.X0+wmsLayer.fX*wmsLayer.communeBBox.max.getX(),
     302                wmsLayer.Y0+wmsLayer.fY*wmsLayer.communeBBox.max.getX());
     303        ea1 = new EastNorth(wmsLayer.getImage(0).min.east(), wmsLayer.getImage(0).max.north());
     304        EastNorth ea2 = wmsLayer.getImage(0).max;
     305        affineTransform(ea1, ea2, georefpoint1, georefpoint2);
     306        wmsLayer.grabThread.saveNewCache();
     307        wmsLayer.invalidate();
     308    }
     309
     310    /**
     311     * Ask if georeferencing should be continued
     312     * @return false if all operations are canceled
     313     */
     314    private boolean continueGeoreferencing() {
     315        Object[] options = {"OK", "Cancel"};
     316        int ret = JOptionPane.showOptionDialog(null,
     317                tr("Click second Lambert crosspiece for georeferencing"),
     318                tr("Image georeferencing"),
     319                JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
     320                null, options, options[0]);
     321        if (ret != JOptionPane.OK_OPTION) {
     322            if (canceledOrRestartCurrAction("georeferencing"))
     323                return startGeoreferencing(wmsLayer);
     324        }
     325        return true;
     326    }
     327
     328    private void handleNewCoordinates(double e, double n) {
     329        if (countMouseClicked == 1) {
     330            georefpoint1 = new EastNorth(e, n);
     331            continueGeoreferencing();
     332        } else {
     333            georefpoint2 = new EastNorth(e, n);
     334            endGeoreferencing();
     335        }
     336    }
     337
     338    private void actionCompleted() {
     339        countMouseClicked = 0;
     340        mode = 0;
     341        mouseClickedTime = System.currentTimeMillis();
     342    }
     343
     344    public void actionInterrupted() {
     345        actionCompleted();
     346        if (wmsLayer != null) {
     347            MainApplication.getLayerManager().removeLayer(wmsLayer);
     348            wmsLayer = null;
     349        }
     350    }
     351
     352    @Override
     353    public void mouseEntered(MouseEvent e) {
     354    }
     355
     356    @Override
     357    public void mouseExited(MouseEvent e) {
     358    }
     359
     360    @Override
     361    public void mousePressed(MouseEvent e) {
     362    }
     363
     364    @Override
     365    public void mouseReleased(MouseEvent e) {
     366    }
    297367}
    298 
    299 public void transformGeoreferencedImg() {
    300     georefpoint1 = new EastNorth(wmsLayer.X0, wmsLayer.Y0);
    301     georefpoint2 = new EastNorth(wmsLayer.X0+wmsLayer.fX*wmsLayer.communeBBox.max.getX(),
    302             wmsLayer.Y0+wmsLayer.fY*wmsLayer.communeBBox.max.getX());
    303     ea1 = new EastNorth(wmsLayer.getImage(0).min.east(), wmsLayer.getImage(0).max.north());
    304     EastNorth ea2 = wmsLayer.getImage(0).max;
    305     affineTransform(ea1, ea2, georefpoint1, georefpoint2);
    306     wmsLayer.grabThread.saveNewCache();
    307     wmsLayer.invalidate();
    308 }
    309 
    310 
    311  /**
    312  *
    313  * @return false if all operations are canceled
    314  */
    315 private boolean continueGeoreferencing() {
    316     Object[] options = {"OK", "Cancel"};
    317     int ret = JOptionPane.showOptionDialog(null,
    318             tr("Click second Lambert crosspiece for georeferencing"),
    319             tr("Image georeferencing"),
    320             JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
    321             null, options, options[0]);
    322     if (ret != JOptionPane.OK_OPTION) {
    323         if (canceledOrRestartCurrAction("georeferencing"))
    324             return startGeoreferencing(wmsLayer);
    325     }
    326     return true;
    327 }
    328 
    329  private void handleNewCoordinates(double e, double n) {
    330      if (countMouseClicked == 1) {
    331          georefpoint1 = new EastNorth(e, n);
    332          continueGeoreferencing();
    333      } else {
    334          georefpoint2 = new EastNorth(e, n);
    335          endGeoreferencing();
    336      }
    337  }
    338 
    339  private void actionCompleted() {
    340      countMouseClicked = 0;
    341      mode = 0;
    342      mouseClickedTime = System.currentTimeMillis();
    343  }
    344 
    345  public void actionInterrupted() {
    346      actionCompleted();
    347      if (wmsLayer != null) {
    348          MainApplication.getLayerManager().removeLayer(wmsLayer);
    349          wmsLayer = null;
    350      }
    351  }
    352 
    353  @Override
    354  public void mouseEntered(MouseEvent e) {
    355  }
    356 
    357  @Override
    358  public void mouseExited(MouseEvent e) {
    359  }
    360 
    361  @Override
    362  public void mousePressed(MouseEvent e) {
    363  }
    364 
    365  @Override
    366  public void mouseReleased(MouseEvent e) {
    367  }
    368 }
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/RasterImageModifier.java

    • Property svn:eol-style set to native
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/SVGParser.java

    • Property svn:eol-style set to native
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/VectorImageModifier.java

    • Property svn:eol-style set to native
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/WMSException.java

    • Property svn:eol-style set to native
Note: See TracChangeset for help on using the changeset viewer.