Ignore:
Timestamp:
2009-08-23T21:23:13+02:00 (15 years ago)
Author:
pieren
Message:

improve georeferencing action cancellation; fixed bug of raster image loaded from cache not working on Java1.6; improve mouse click bounce detection during georeferencing process

Location:
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CacheControl.java

    r17089 r17215  
    1111
    1212import static org.openstreetmap.josm.tools.I18n.tr;
     13
     14import java.awt.image.BufferedImage;
    1315import java.io.*;
    1416import java.util.ArrayList;
     
    127129            return false;
    128130        }
     131        if (wmsLayer.isRaster()) {
     132            // serialized raster bufferedImage hangs-up on Java6. Recreate them here
     133            wmsLayer.images.get(0).image = RasterImageModifier.fixRasterImage(wmsLayer.images.get(0).image);
     134        }
    129135        return true;
    130136    }
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreInterface.java

    r17181 r17215  
    246246            rd.close();
    247247            urlConn.disconnect();
    248             if (lines.indexOf(cImageFormat) != -1) {
    249                 int i = lines.indexOf(cImageFormat);
    250                 int j = lines.indexOf(".", i);
    251                 wmsLayer.setRaster(lines.substring(i+cImageFormat.length(), j).equals("image"));
    252             }
    253             if (!wmsLayer.isRaster() && lines.indexOf(cInterfaceVector) != -1) {  // "afficherCarteCommune.do"
    254                 // shall be something like: interfaceRef = "afficherCarteCommune.do?c=X2269";
    255                 lines = lines.substring(lines.indexOf(cInterfaceVector),lines.length());
    256                 lines = lines.substring(0, lines.indexOf("'"));
    257                 System.out.println("interface ref.:"+lines);
    258                 return lines;
    259             } else if (wmsLayer.isRaster() && lines.indexOf(cInterfaceRasterTA) != -1) { // "afficherCarteTa.do"
    260                 // list of values parsed in listOfFeuilles (list all non-georeferenced images)
    261                 lines = getFeuillesList();
    262                 if (!downloadCancelled) {
    263                         parseFeuillesList(lines);
    264                         if (listOfFeuilles.size() > 0) {
    265                             int res = selectFeuilleDialog();
    266                             if (res != -1) {
    267                                 wmsLayer.setCodeCommune(listOfFeuilles.elementAt(res).name);
    268                                 checkLayerDuplicates(wmsLayer);
    269                                 interfaceRef = buildRasterFeuilleInterfaceRef(wmsLayer.getCodeCommune());
    270                                 wmsLayer.setCodeCommune(listOfFeuilles.elementAt(res).ref);
    271                                 lines = buildRasterFeuilleInterfaceRef(listOfFeuilles.elementAt(res).ref);
    272                                 System.out.println("interface ref.:"+lines);
    273                                 return lines;
    274                             }
    275                         }
    276                 }
    277                 return null;
    278             } else if (lines.indexOf(cCommuneListStart) != -1 && lines.indexOf(cCommuneListEnd) != -1) {
    279                 // list of values parsed in listOfCommunes
    280                 int i = lines.indexOf(cCommuneListStart);
    281                 int j = lines.indexOf(cCommuneListEnd, i);
    282                 parseCommuneList(lines.substring(i, j));
     248            if (lines != null) {
     249                if (lines.indexOf(cImageFormat) != -1) {
     250                    int i = lines.indexOf(cImageFormat);
     251                    int j = lines.indexOf(".", i);
     252                    wmsLayer.setRaster(lines.substring(i+cImageFormat.length(), j).equals("image"));
     253                }
     254                if (!wmsLayer.isRaster() && lines.indexOf(cInterfaceVector) != -1) {  // "afficherCarteCommune.do"
     255                    // shall be something like: interfaceRef = "afficherCarteCommune.do?c=X2269";
     256                    lines = lines.substring(lines.indexOf(cInterfaceVector),lines.length());
     257                    lines = lines.substring(0, lines.indexOf("'"));
     258                    System.out.println("interface ref.:"+lines);
     259                    return lines;
     260                } else if (wmsLayer.isRaster() && lines.indexOf(cInterfaceRasterTA) != -1) { // "afficherCarteTa.do"
     261                    // list of values parsed in listOfFeuilles (list all non-georeferenced images)
     262                    lines = getFeuillesList();
     263                    if (!downloadCancelled) {
     264                        parseFeuillesList(lines);
     265                        if (listOfFeuilles.size() > 0) {
     266                            int res = selectFeuilleDialog();
     267                            if (res != -1) {
     268                                wmsLayer.setCodeCommune(listOfFeuilles.elementAt(res).name);
     269                                checkLayerDuplicates(wmsLayer);
     270                                interfaceRef = buildRasterFeuilleInterfaceRef(wmsLayer.getCodeCommune());
     271                                wmsLayer.setCodeCommune(listOfFeuilles.elementAt(res).ref);
     272                                lines = buildRasterFeuilleInterfaceRef(listOfFeuilles.elementAt(res).ref);
     273                                System.out.println("interface ref.:"+lines);
     274                                return lines;
     275                            }
     276                        }
     277                    }
     278                    return null;
     279                } else if (lines.indexOf(cCommuneListStart) != -1 && lines.indexOf(cCommuneListEnd) != -1) {
     280                    // list of values parsed in listOfCommunes
     281                    int i = lines.indexOf(cCommuneListStart);
     282                    int j = lines.indexOf(cCommuneListEnd, i);
     283                    parseCommuneList(lines.substring(i, j));
     284                }
    283285            }
    284286        } catch (MalformedURLException e) {
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePlugin.java

    r17089 r17215  
    2020import org.openstreetmap.josm.actions.UploadAction;
    2121import org.openstreetmap.josm.actions.UploadAction.UploadHook;
    22 import org.openstreetmap.josm.gui.IconToggleButton;
    2322import org.openstreetmap.josm.gui.MainMenu;
    2423import org.openstreetmap.josm.gui.MapFrame;
     
    7372 * 1.1 11-Jun-2009 - fixed a null exception error when trying to displace a vectorized layer
    7473 *                 - propose to use shortcut F11 for grabbing
     74 * 1.2 16-Aug-2009 - implementation of raster image grabbing, cropping and georeferencing (not the
     75 *                   overview rasters (Tableau d'assemblage) but directly small units (Feuille)
     76 * 1.3 23-Aug-2009 - improve georeferencing action cancellation
     77 *                 - fixed bug of raster image loaded from cache not working on Java1.6
     78 *                 - improve mouse click bounce detection during georeferencing process
    7579 */
    7680public class CadastrePlugin extends Plugin {
    77     static String VERSION = "1.0";
     81    static String VERSION = "1.3";
    7882
    7983    static JMenu cadastreJMenu;
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePreferenceSetting.java

    r17181 r17215  
    8181        reversGrey.setSelected(Main.pref.getBoolean("cadastrewms.invertGrey", false));
    8282        reversGrey.setToolTipText(tr("Invert the original black and white colors (and all intermediate greys). Useful for texts on dark backgrounds."));
    83         reversGrey.setEnabled(alterColors.isSelected());
    8483        cadastrewms.add(reversGrey, GBC.eop().insets(00, 0, 0, 0));
    8584
     
    102101        sliderTrans.setPaintTicks(true);
    103102        sliderTrans.setPaintLabels(false);
     103        sliderTrans.setEnabled(transparency.isSelected());
    104104        cadastrewms.add(sliderTrans, GBC.eol().fill(GBC.HORIZONTAL).insets(20, 0, 250, 0));
    105105
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/GeorefImage.java

    r17089 r17215  
    133133     */
    134134    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    135         max = (EastNorth) in.readObject();
    136         min = (EastNorth) in.readObject();
     135        max = new EastNorth((Double)in.readObject(), (Double)in.readObject());
     136        min = new EastNorth((Double)in.readObject(), (Double)in.readObject());
    137137        image = (BufferedImage) ImageIO.read(ImageIO.createImageInputStream(in));
    138138        updatePixelPer();
     
    143143     */
    144144    private void writeObject(ObjectOutputStream out) throws IOException {
    145         out.writeObject(max);
    146         out.writeObject(min);
     145        out.writeObject(max.getX());
     146        out.writeObject(max.getY());
     147        out.writeObject(min.getX());
     148        out.writeObject(min.getY());
    147149        ImageIO.write(image, "png", ImageIO.createImageOutputStream(out));
    148150    }
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionGrabPlanImage.java

    r17181 r17215  
    44
    55import java.awt.GridBagLayout;
    6 import java.awt.Point;
    76import java.awt.event.ActionEvent;
    87import java.awt.event.MouseEvent;
     
    3736    private int cGetLambertCrosspieces = 2;
    3837    private EastNorth ea1;
    39     private Point mousePrevious = new Point();
     38    private long mouseClickedTime = 0;
    4039    private EastNorth georefpoint1;
    4140    private EastNorth georefpoint2;
     41    /**
     42     * The time which needs to pass between two clicks during georeferencing, in milliseconds
     43     */
     44    private int initialClickDelay;
    4245
    4346    public MenuActionGrabPlanImage() {
     
    4851        countMouseClicked = 0;
    4952        mode = 0;
    50         mousePrevious.setLocation(0, 0);
     53        mouseClickedTime = System.currentTimeMillis();
    5154    }
    5255   
     
    7578                downloadWMSPlanImage = new DownloadWMSPlanImage();
    7679                downloadWMSPlanImage.download(wmsLayer);
     80                initialClickDelay = Main.pref.getInteger("cadastrewms.georef-click-delay",200);
    7781                // download sub-images of the cadastre scan and join them into one single
    7882                Main.worker.execute(this);
     
    9094        boolean loadedFromCache = downloadWMSPlanImage.waitFinished();
    9195        if (wmsLayer.images.size() == 1 && !loadedFromCache) {
     96            mouseClickedTime = System.currentTimeMillis();
    9297            Main.map.mapView.addMouseListener(this);
    9398            if (Main.pref.getBoolean("cadastrewms.noImageCropping", false) == false)
     
    95100            else
    96101                startGeoreferencing();
    97         } else // action cancelled or image loaded from cache (and already georeferenced)
     102        } else // action cancelled or image loaded from cache (and already georeferenced)
    98103            Main.map.repaint();
    99104    }
    100105
    101106    public void mouseClicked(MouseEvent e) {
    102         if (e.getX() == mousePrevious.getX() && e.getY() == mousePrevious.getY())
    103             return; // double click filtered
     107        if (System.currentTimeMillis() - mouseClickedTime < initialClickDelay) {
     108            System.out.println("mouse click bounce detected");
     109            return; // mouse click anti-bounce
     110        }
    104111        else
    105             mousePrevious.setLocation(e.getX(), e.getY());
     112            mouseClickedTime = System.currentTimeMillis();
    106113        countMouseClicked++;
    107114        EastNorth ea = Main.proj.latlon2eastNorth(Main.map.mapView.getLatLon(e.getX(), e.getY()));
    108         System.out.println("clic:"+countMouseClicked+" ,"+ea);
     115        System.out.println("clic:"+countMouseClicked+" ,"+ea+", mode:"+mode);
    109116        // ignore clicks outside the image
    110117        if (ea.east() < wmsLayer.images.get(0).min.east() || ea.east() > wmsLayer.images.get(0).max.east()
     
    153160                        null, options, options[0]);
    154161            if (ret == JOptionPane.OK_OPTION) {
    155                 mousePrevious.setLocation(0, 0);
     162                mouseClickedTime = System.currentTimeMillis();
    156163            } else
    157164                if (canceledOrRestartCurrAction("image cropping"))
     
    192199                        null, options, options[0]);
    193200            if (ret == JOptionPane.OK_OPTION) {
    194                 mousePrevious.setLocation(0, 0);
     201                mouseClickedTime = System.currentTimeMillis();
    195202            } else
    196203                if (canceledOrRestartCurrAction("georeferencing"))
     
    257264        if (countMouseClicked == 1) number = "first";
    258265        else number = "second";
    259         pane.createDialog(Main.parent, tr("Set "+number+" Lambert coordinate")).setVisible(true);
     266        pane.createDialog(Main.parent, tr("Set "+number+" Lambert coordinates")).setVisible(true);
    260267        if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue())) {
    261268            if (canceledOrRestartCurrAction("georeferencing"))
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/RasterImageModifier.java

    r17089 r17215  
    6060    private void makeTransparent() {
    6161        if (bufferedImage.getColorModel() instanceof ComponentColorModel) {
    62             // raster image (ComponentColorModel)
    6362            int width = bufferedImage.getWidth();
    6463            int height = bufferedImage.getHeight();
     
    8584        return;
    8685    }
     86   
     87    /**
     88     * Temporary fix for Java6 which doesn't de-serialize correctly cached image on disk.
     89     * Recreate a new raster image based on what is loaded/serialized from disk cache.
     90     * @param img
     91     * @return new image
     92     */
     93    public static BufferedImage fixRasterImage(BufferedImage img) {
     94        int width = img.getWidth();
     95        int height = img.getHeight();
     96        BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
     97        int rgbArray[] = new int[width * height];
     98        img.getRGB(0, 0, width, height, rgbArray, 0, width);
     99        bi.setRGB(0, 0, width, height, rgbArray, 0, width);
     100        return bi;
     101    }
    87102
    88103}
Note: See TracChangeset for help on using the changeset viewer.