Changeset 20214 in osm


Ignore:
Timestamp:
2010-02-28T17:49:37+01:00 (14 years ago)
Author:
pieren
Message:

Add non-modal dialog in action grab planImage + more history in main plugin file.

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

Legend:

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

    r19928 r20214  
    9191 * 1.7 12-Dec-2009 - Change URL's changes for cookie and downgrade imgs resolution due to WMS changes
    9292 * 1.8 xxx         - filter the mouse button 1 during georeferencing
    93  *                 - possibility to modify the auto-sourcing text just before upload
    9493 *                 - retry if getting a new cookie failed (10 times during 30 seconds)
    9594 *                 - cookie expiration automatically detected and renewed (after 30 minutes)
    9695 *                 - proper WMS layer cleanup at destruction (workaround for memory leak)
    9796 *                 - new cache format (v3) storing original image and cropped image bbox + angle
    98  *                 - cache management compatible with previous v2 format
    99  *                 - raster image rotation using shift+ctrl key instead of ctrl
     97 *                 - new cache format (v4) storing original image size for later rotation
     98 *                 - cache files read compatible with previous formats
     99 *                 - raster image rotation issues fixed, now using shift+ctrl key instead of ctrl
    100100 *                 - raster image adjustment using default system menu modifier (ctrl for windows) for Mac support
    101  *                 - from Clément Ménier, new option allowing an auto-selection of the first cadastre layer for grab 
     101 *                 - from Erik Amzallag:
     102 *                 -     possibility to modify the auto-sourcing text just before upload
     103 *                 - from Clément Ménier:
     104 *                 -     new option allowing an auto-selection of the first cadastre layer for grab
     105 *                 -     non-modal JDialog in MenuActionGrabPlanImage 
    102106 */
    103107public class CadastrePlugin extends Plugin {
     
    184188            cadastreJMenu.add(menuSettings);
    185189            cadastreJMenu.add(menuSource);
    186             cadastreJMenu.add(menuResetCookie);
     190            //cadastreJMenu.add(menuResetCookie); not required any more
    187191            //cadastreJMenu.add(menuLambertZone);
    188192            cadastreJMenu.add(menuLoadFromCache);
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionGrabPlanImage.java

    r19267 r20214  
    88import java.awt.event.MouseEvent;
    99import java.awt.event.MouseListener;
     10import java.beans.PropertyChangeEvent;
     11import java.beans.PropertyChangeListener;
    1012import java.util.ArrayList;
    1113
     14import javax.swing.JDialog;
    1215import javax.swing.JLabel;
    1316import javax.swing.JOptionPane;
     
    3740    private int cGetLambertCrosspieces = 2;
    3841    private EastNorth ea1;
     42    private EastNorth ea2;
    3943    private long mouseClickedTime = 0;
    4044    private EastNorth georefpoint1;
    4145    private EastNorth georefpoint2;
     46    private boolean ignoreMouseClick = false;
     47   
    4248    /**
    4349     * The time which needs to pass between two clicks during georeferencing, in milliseconds
     
    126132        if (e.getButton() != MouseEvent.BUTTON1)
    127133            return;
     134        if (ignoreMouseClick) return; // In case we are currently just allowing zooming to read lambert coordinates
    128135        countMouseClicked++;
    129136        EastNorth ea = Main.proj.latlon2eastNorth(Main.map.mapView.getLatLon(e.getX(), e.getY()));
     
    146153            if (countMouseClicked == 1) {
    147154                ea1 = ea;
    148                 if (inputLambertPosition())
    149                     continueGeoreferencing();
     155                inputLambertPosition(); // This will automatically asks for second point and continue the georeferencing
    150156            }
    151157            if (countMouseClicked == 2) {
    152                 if (inputLambertPosition()) {
    153                     Main.map.mapView.removeMouseListener(this);
    154                     affineTransform(ea1, ea, georefpoint1, georefpoint2);
    155                     wmsLayer.saveNewCache();
    156                     Main.map.mapView.repaint();
    157                     actionCompleted();
    158                 }
     158                ea2 = ea;
     159                inputLambertPosition(); // This will automatically ends the georeferencing
    159160            }
    160161        }
     
    237238            }
    238239            return true;
     240    }
     241   
     242    /**
     243     * Ends the georeferencing by computing the affine transformation
     244     */
     245    private void endGeoreferencing() {
     246        Main.map.mapView.removeMouseListener(this);
     247        affineTransform(ea1, ea2, georefpoint1, georefpoint2);
     248        wmsLayer.saveNewCache();
     249        Main.map.mapView.repaint();
     250        actionCompleted();
    239251    }
    240252
     
    261273    }
    262274
    263     private boolean inputLambertPosition() {
    264         JLabel labelEnterPosition = new JLabel(tr("Enter cadastre east,north position"));
    265         JLabel labelWarning = new JLabel(tr("(Warning: verify north with arrow !!)"));
     275    private void inputLambertPosition() {
     276        JLabel labelEnterPosition = new JLabel(
     277                tr("Enter cadastre east,north position"));
     278        JLabel labelWarning = new JLabel(
     279                tr("(Warning: verify north with arrow !!)"));
    266280        JPanel p = new JPanel(new GridBagLayout());
    267281        JLabel labelEast = new JLabel(tr("East"));
     
    275289        p.add(labelNorth, GBC.std().insets(0, 0, 10, 0));
    276290        p.add(inputNorth, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 5, 0, 5));
    277         JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null);
     291        final JOptionPane pane = new JOptionPane(p,
     292                JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION,
     293                null);
    278294        String number;
    279         if (countMouseClicked == 1) number = "first";
    280         else number = "second";
    281         pane.createDialog(Main.parent, tr("Set {0} Lambert coordinates",number)).setVisible(true);
    282         if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue())) {
    283             if (canceledOrRestartCurrAction("georeferencing"))
    284                 startGeoreferencing();
    285             return false;
    286         }
    287         if (inputEast.getText().length() != 0 && inputNorth.getText().length() != 0) {
    288             try {
    289                 double e = Double.parseDouble(inputEast.getText());
    290                 double n = Double.parseDouble(inputNorth.getText());
    291                 if (countMouseClicked == 1)
    292                     georefpoint1 = new EastNorth(e, n);
    293                 else
    294                     georefpoint2 = new EastNorth(e, n);
    295                 return true;
    296             } catch (NumberFormatException e) {
    297                 return false;
    298             }
    299         }
    300         return false;
     295        if (countMouseClicked == 1)
     296            number = "first";
     297        else
     298            number = "second";
     299        JDialog dialog = pane.createDialog(Main.parent, tr(
     300                "Set {0} Lambert coordinates", number));
     301        dialog.setModal(false);
     302        ignoreMouseClick = true; // To avoid mouseClicked from being called
     303                                 // during coordinates reading
     304        dialog.setAlwaysOnTop(true);
     305        dialog.setVisible(true);
     306        pane.addPropertyChangeListener(new PropertyChangeListener() {
     307            public void propertyChange(PropertyChangeEvent evt) {
     308                if (JOptionPane.VALUE_PROPERTY.equals(evt.getPropertyName())) {
     309                    ignoreMouseClick = false;
     310                    if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(
     311                            pane.getValue())) {
     312                        if (canceledOrRestartCurrAction("georeferencing"))
     313                            startGeoreferencing();
     314                    }
     315                    if (inputEast.getText().length() != 0
     316                            && inputNorth.getText().length() != 0) {
     317                        try {
     318                            double e = Double.parseDouble(inputEast.getText());
     319                            double n = Double.parseDouble(inputNorth.getText());
     320                            if (countMouseClicked == 1) {
     321                                georefpoint1 = new EastNorth(e, n);
     322                                continueGeoreferencing();
     323                            } else {
     324                                georefpoint2 = new EastNorth(e, n);
     325                                endGeoreferencing();
     326                            }
     327                        } catch (NumberFormatException e) {
     328                            return;
     329                        }
     330                    }
     331                }
     332            }
     333        });
    301334    }
    302335
Note: See TracChangeset for help on using the changeset viewer.