Ignore:
Timestamp:
2009-08-19T22:54:02+02:00 (15 years ago)
Author:
pieren
Message:

better handling of dialogs cancellations

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

Legend:

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

    r17089 r17181  
    7272        } catch (IOException e) {
    7373            /*JOptionPane.showMessageDialog(Main.parent,
    74                     tr("Town/city {0} not found or not available in WMS.\n" +
    75                             "Please check its availibility on www.cadastre.gouv.fr", wmsLayer.getLocation()));*/
     74                    tr("Town/city {0} not found or not available\n" +
     75                            "or action canceled", wmsLayer.getLocation()));*/
    7676            JOptionPane pane = new JOptionPane(
    77                     tr("Town/city {0} not found or not available in WMS.\n" +
    78                             "Please check its availibility on www.cadastre.gouv.fr", wmsLayer.getLocation()),
     77                    tr("Town/city {0} not found or not available\n" +
     78                            "or action canceled", wmsLayer.getLocation()),
    7979                            JOptionPane.INFORMATION_MESSAGE);
    8080            // this below is a temporary workaround to fix the "always on top" issue
     
    260260                // list of values parsed in listOfFeuilles (list all non-georeferenced images)
    261261                lines = getFeuillesList();
    262                 parseFeuillesList(lines);
    263                 if (listOfFeuilles.size() > 0) {
    264                     int res = selectFeuilleDialog();
    265                     if (res != -1) {
    266                         wmsLayer.setCodeCommune(listOfFeuilles.elementAt(res).name);
    267                         checkLayerDuplicates(wmsLayer);
    268                         interfaceRef = buildRasterFeuilleInterfaceRef(wmsLayer.getCodeCommune());
    269                         wmsLayer.setCodeCommune(listOfFeuilles.elementAt(res).ref);
    270                         lines = buildRasterFeuilleInterfaceRef(listOfFeuilles.elementAt(res).ref);
    271                         System.out.println("interface ref.:"+lines);
    272                         return lines;
    273                     }
     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                        }
    274276                }
    275277                return null;
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePreferenceSetting.java

    r17089 r17181  
    66import java.awt.event.ActionListener;
    77import javax.swing.*;
     8
    89import org.openstreetmap.josm.Main;
    910import org.openstreetmap.josm.gui.preferences.PreferenceDialog;
     
    3435    private JCheckBox drawBoundaries = new JCheckBox(tr("Draw boundaries of downloaded data."));
    3536
     37    private JCheckBox disableImageCropping = new JCheckBox(tr("Disable image cropping during georeferencing."));
     38   
    3639    private JRadioButton grabMultiplier1 = new JRadioButton("", true);
    3740
     
    106109        cadastrewms.add(drawBoundaries, GBC.eop().insets(0, 0, 0, 5));
    107110
     111        // separator
     112        cadastrewms.add(new JSeparator(SwingConstants.HORIZONTAL), GBC.eol().fill(GBC.HORIZONTAL));
     113       
    108114        // the vectorized images multiplier
    109115        JLabel jLabelScale = new JLabel(tr("Vector images grab multiplier:"));
     
    154160        cadastrewms.add(grabMultiplier4Size, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 0, 5));
    155161
     162        // separator
     163        cadastrewms.add(new JSeparator(SwingConstants.HORIZONTAL), GBC.eol().fill(GBC.HORIZONTAL));
     164
    156165        // for raster images (not vectorized), image grab divider (from 1 to 10)
    157166        String savedRasterDivider = Main.pref.get("cadastrewms.rasterDivider", DEFAULT_RASTER_DIVIDER);
     
    161170        cadastrewms.add(jLabelRasterDivider, GBC.std().insets(0, 5, 10, 0));
    162171        cadastrewms.add(rasterDivider, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 200, 5));
     172        // option to disable image cropping during raster image georeferencing
     173        disableImageCropping.setSelected(Main.pref.getBoolean("cadastrewms.noImageCropping", false));
     174        disableImageCropping.setToolTipText(tr("Disable image cropping during georeferencing."));
     175        cadastrewms.add(disableImageCropping, GBC.eop().insets(0, 0, 0, 5));
     176
     177        // separator
     178        cadastrewms.add(new JSeparator(SwingConstants.HORIZONTAL), GBC.eol().fill(GBC.HORIZONTAL));
    163179
    164180        // option to enable automatic caching
     
    213229        } catch (NumberFormatException e) { // ignore the last input
    214230        }
     231        Main.pref.put("cadastrewms.noImageCropping", disableImageCropping.isSelected());
    215232        Main.pref.put("cadastrewms.enableCaching", enableCache.isSelected());
    216233
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadWMSPlanImage.java

    r17089 r17181  
    9191        protected void cancel() {
    9292            grabber.getWmsInterface().cancel();
     93            dontGeoreference = true;
    9394        }
    9495
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionGrab.java

    r17089 r17181  
    3737                        tr("To enable the cadastre WMS plugin, change\n"
    3838                         + "the current projection to one of the cadastre\n"
    39                          + "projection and retry"));
     39                         + "projections and retry"));
    4040            }
    4141        }
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionGrabPlanImage.java

    r17089 r17181  
    8181                        tr("To enable the cadastre WMS plugin, change\n"
    8282                         + "the current projection to one of the cadastre\n"
    83                          + "projection and retry"));
     83                         + "projections and retry"));
    8484            }
    8585        }
     
    9191        if (wmsLayer.images.size() == 1 && !loadedFromCache) {
    9292            Main.map.mapView.addMouseListener(this);
    93             mousePrevious.setLocation(0, 0);
    94             mode = cGetCorners;
    95             JOptionPane.showMessageDialog(Main.parent,tr("Click first corner for image cropping\n"+
    96                     "(two points required)"));
    97         } else // action cancelled or image loaded from cache (and already georeferenced)
     93            if (Main.pref.getBoolean("cadastrewms.noImageCropping", false) == false)
     94                startCropping();
     95            else
     96                startGeoreferencing();
     97        } else // action cancelled or image loaded from cache (and already georeferenced)
    9898            Main.map.repaint();
    9999    }
     
    114114            if (countMouseClicked == 1) {
    115115                ea1 = ea;
    116                 JOptionPane.showMessageDialog(Main.parent,tr("Click second corner for image cropping"));
     116                continueCropping();
    117117            }
    118118            if (countMouseClicked == 2) {
    119119                wmsLayer.cropImage(ea1, ea);
    120120                Main.map.mapView.repaint();
    121                 countMouseClicked = 0;
    122                 mode = cGetLambertCrosspieces;
    123                 JOptionPane.showMessageDialog(Main.parent,tr("Click first Lambert crosspiece for georeferencing\n"+
    124                     "(two points required)"));
     121                startGeoreferencing();
    125122            }
    126123        } else if (mode == cGetLambertCrosspieces) {
    127124            if (countMouseClicked == 1) {
    128125                ea1 = ea;
    129                 georefpoint1 = inputLambertPosition();
    130                 if (georefpoint1 == null)
    131                     return;
    132                 JOptionPane.showMessageDialog(Main.parent,tr("Click second Lambert crosspiece for georeferencing\n"));
     126                if (inputLambertPosition())
     127                    continueGeoreferencing();
    133128            }
    134129            if (countMouseClicked == 2) {
    135                 Main.map.mapView.removeMouseListener(this);
    136                 georefpoint2 = inputLambertPosition();
    137                 if (georefpoint2 == null)
    138                     return;
    139                 affineTransform(ea1, ea, georefpoint1, georefpoint2);
    140                 wmsLayer.saveNewCache();
    141                 Main.map.mapView.repaint();
    142                 actionCompleted();
     130                if (inputLambertPosition()) {
     131                    Main.map.mapView.removeMouseListener(this);
     132                    affineTransform(ea1, ea, georefpoint1, georefpoint2);
     133                    wmsLayer.saveNewCache();
     134                    Main.map.mapView.repaint();
     135                    actionCompleted();
     136                }
    143137            }
    144138        }
    145139    }
    146140   
    147     private EastNorth inputLambertPosition() {
     141    /**
     142     *
     143     * @return false if all operations are canceled
     144     */
     145    private boolean startCropping() {
     146            mode = cGetCorners;
     147            countMouseClicked = 0;
     148                Object[] options = { "OK", "Cancel" };
     149                int ret = JOptionPane.showOptionDialog( null,
     150                                tr("Click first corner for image cropping\n(two points required)"),
     151                                tr("Image cropping"),
     152                        JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
     153                        null, options, options[0]);
     154            if (ret == JOptionPane.OK_OPTION) {
     155                mousePrevious.setLocation(0, 0);
     156            } else
     157                if (canceledOrRestartCurrAction("image cropping"))
     158                        return startCropping();
     159            return true;
     160    }
     161   
     162    /**
     163     *
     164     * @return false if all operations are canceled
     165     */
     166    private boolean continueCropping() {
     167                Object[] options = { "OK", "Cancel" };
     168                int ret = JOptionPane.showOptionDialog( null,
     169                                tr("Click second corner for image cropping"),
     170                                tr("Image cropping"),
     171                        JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
     172                        null, options, options[0]);
     173            if (ret != JOptionPane.OK_OPTION) {
     174                if (canceledOrRestartCurrAction("image cropping"))
     175                        return startCropping();
     176            }
     177            return true;
     178    }
     179   
     180    /**
     181     *
     182     * @return false if all operations are canceled
     183     */
     184    private boolean startGeoreferencing() {
     185            countMouseClicked = 0;
     186            mode = cGetLambertCrosspieces;
     187                Object[] options = { "OK", "Cancel" };
     188                int ret = JOptionPane.showOptionDialog( null,
     189                                tr("Click first Lambert crosspiece for georeferencing\n(two points required)"),
     190                                tr("Image georeferencing"),
     191                        JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
     192                        null, options, options[0]);
     193            if (ret == JOptionPane.OK_OPTION) {
     194                mousePrevious.setLocation(0, 0);
     195            } else
     196                if (canceledOrRestartCurrAction("georeferencing"))
     197                        return startGeoreferencing();
     198            return true;
     199    }
     200
     201    /**
     202     *
     203     * @return false if all operations are canceled
     204     */
     205    private boolean continueGeoreferencing() {
     206                Object[] options = { "OK", "Cancel" };
     207                int ret = JOptionPane.showOptionDialog( null,
     208                                tr("Click second Lambert crosspiece for georeferencing"),
     209                                tr("Image georeferencing"),
     210                        JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
     211                        null, options, options[0]);
     212            if (ret != JOptionPane.OK_OPTION) {
     213                if (canceledOrRestartCurrAction("georeferencing"))
     214                        return startGeoreferencing();
     215            }
     216            return true;
     217    }
     218   
     219    /**
     220     *
     221     * @return false if all operations are canceled
     222     */
     223    private boolean canceledOrRestartCurrAction(String action) {
     224        Object[] options = { "Cancel", "Retry" };
     225        int selectedValue = JOptionPane.showOptionDialog( null,
     226                        tr("Do you want to cancel completely\n"+
     227                                        "or just retry "+action+" ?"), "",
     228                        JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
     229                        null, options, options[0]);
     230        if (selectedValue == 0) { // "Cancel"
     231                // remove layer
     232                Main.map.mapView.removeLayer(wmsLayer);
     233            wmsLayer = null;
     234            Main.map.mapView.removeMouseListener(this);
     235                return false;
     236        } else
     237            countMouseClicked = 0;
     238        return true;
     239    }
     240   
     241    private boolean inputLambertPosition() {
    148242        JLabel labelEnterPosition = new JLabel(tr("Enter cadastre east,north position"));
    149243        JLabel labelWarning = new JLabel(tr("(Warning: verify north with arrow !!)"));
     
    160254        p.add(inputNorth, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 5, 0, 5));
    161255        JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null);
    162         pane.createDialog(Main.parent, tr("Set Lambert coordinate")).setVisible(true);
    163         if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue()))
    164             return null;
    165         if (inputEast.getText().length() == 0 || inputNorth.getText().length() == 0)
    166             return null;
    167         try {
    168             double e = Double.parseDouble(inputEast.getText());
    169             double n = Double.parseDouble(inputNorth.getText());
    170             return new EastNorth(e, n);
    171         } catch (NumberFormatException e) {
    172             return null;
    173         }       
     256        String number;
     257        if (countMouseClicked == 1) number = "first";
     258        else number = "second";
     259        pane.createDialog(Main.parent, tr("Set "+number+" Lambert coordinate")).setVisible(true);
     260        if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue())) {
     261            if (canceledOrRestartCurrAction("georeferencing"))
     262                startGeoreferencing();
     263            return false;
     264        }
     265        if (inputEast.getText().length() != 0 && inputNorth.getText().length() != 0) {
     266            try {
     267                double e = Double.parseDouble(inputEast.getText());
     268                double n = Double.parseDouble(inputNorth.getText());
     269                if (countMouseClicked == 1)
     270                    georefpoint1 = new EastNorth(e, n);
     271                else
     272                    georefpoint2 = new EastNorth(e, n);
     273                return true;
     274            } catch (NumberFormatException e) {
     275                return false;
     276            }
     277        }
     278        return false;
    174279    }
    175280   
Note: See TracChangeset for help on using the changeset viewer.