Ignore:
Timestamp:
2006-04-27T01:29:55+02:00 (18 years ago)
Author:
imi
Message:
  • added GeoImage feature (showing images on a tracklog)
  • added zoom slider
  • added Escape cancels selection rectangle
  • added "Save password" option to Auth-dialog
  • fixed that redo/undo buttons were not enabled
  • fixed hotkeys beeing inaccessible when no data is loaded
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/io/OsmConnection.java

    r98 r99  
    88
    99import javax.swing.BoundedRangeModel;
     10import javax.swing.JCheckBox;
    1011import javax.swing.JLabel;
    1112import javax.swing.JOptionPane;
     
    2930        protected JLabel currentAction;
    3031        protected BoundedRangeModel progress;
    31        
     32
    3233        private static OsmAuth authentication;
    3334        /**
     
    3839                Authenticator.setDefault(authentication = new OsmAuth());
    3940        }
    40        
     41
    4142        /**
    42      * The authentication class handling the login requests.
    43      */
    44     private static class OsmAuth extends Authenticator {
    45         /**
    46          * Set to true, when the autenticator tried the password once.
    47          */
    48         boolean passwordtried = false;
    49         /**
    50          * Whether the user cancelled the password dialog
    51          */
    52         boolean authCancelled = false;
    53    
    54         @Override protected PasswordAuthentication getPasswordAuthentication() {
    55                 String username = Main.pref.get("osm-server.username");
    56                 String password = Main.pref.get("osm-server.password");
    57                 if (passwordtried || username.equals("") || password.equals("")) {
    58                         JPanel p = new JPanel(new GridBagLayout());
    59                         p.add(new JLabel("Username"), GBC.std().insets(0,0,10,0));
    60                         JTextField usernameField = new JTextField(username, 20);
    61                         p.add(usernameField, GBC.eol());
    62                         p.add(new JLabel("Password"), GBC.std().insets(0,0,10,0));
    63                         JPasswordField passwordField = new JPasswordField(password, 20);
    64                         p.add(passwordField, GBC.eol());
    65                         JLabel warning = new JLabel("Warning: The password is transferred unencrypted.");
    66                         warning.setFont(warning.getFont().deriveFont(Font.ITALIC));
    67                         p.add(warning, GBC.eol());
    68                         int choice = JOptionPane.showConfirmDialog(Main.parent, p, "Enter Password", JOptionPane.OK_CANCEL_OPTION);
    69                         if (choice == JOptionPane.CANCEL_OPTION) {
    70                                 authCancelled = true;
    71                                 return null;
    72                         }
    73                         username = usernameField.getText();
    74                         password = String.valueOf(passwordField.getPassword());
    75                         if (username.equals(""))
    76                                 return null;
    77                 }
    78                 passwordtried = true;
    79                 return new PasswordAuthentication(username, password.toCharArray());
    80         }
    81     }
     43         * The authentication class handling the login requests.
     44         */
     45        private static class OsmAuth extends Authenticator {
     46                /**
     47                 * Set to true, when the autenticator tried the password once.
     48                 */
     49                boolean passwordtried = false;
     50                /**
     51                 * Whether the user cancelled the password dialog
     52                 */
     53                boolean authCancelled = false;
     54
     55                @Override protected PasswordAuthentication getPasswordAuthentication() {
     56                        String username = Main.pref.get("osm-server.username");
     57                        String password = Main.pref.get("osm-server.password");
     58                        if (passwordtried || username.equals("") || password.equals("")) {
     59                                JPanel p = new JPanel(new GridBagLayout());
     60                                if (!username.equals("") && !password.equals(""))
     61                                        p.add(new JLabel("Incorrect password or username."), GBC.eop());
     62                                p.add(new JLabel("Username"), GBC.std().insets(0,0,10,0));
     63                                JTextField usernameField = new JTextField(username, 20);
     64                                p.add(usernameField, GBC.eol());
     65                                p.add(new JLabel("Password"), GBC.std().insets(0,0,10,0));
     66                                JPasswordField passwordField = new JPasswordField(password, 20);
     67                                p.add(passwordField, GBC.eol());
     68                                JLabel warning = new JLabel("Warning: The password is transferred unencrypted.");
     69                                warning.setFont(warning.getFont().deriveFont(Font.ITALIC));
     70                                p.add(warning, GBC.eop());
     71
     72                                JCheckBox savePassword = new JCheckBox("Save user and password (unencrypted)", !username.equals("") && !password.equals(""));
     73                                p.add(savePassword, GBC.eop());
     74
     75                                int choice = JOptionPane.showConfirmDialog(Main.parent, p, "Enter Password", JOptionPane.OK_CANCEL_OPTION);
     76                                if (choice == JOptionPane.CANCEL_OPTION) {
     77                                        authCancelled = true;
     78                                        return null;
     79                                }
     80                                username = usernameField.getText();
     81                                password = String.valueOf(passwordField.getPassword());
     82                                if (savePassword.isSelected()) {
     83                                        Main.pref.put("osm-server.username", username);
     84                                        Main.pref.put("osm-server.password", password);
     85                                }
     86                                if (username.equals(""))
     87                                        return null;
     88                        }
     89                        passwordtried = true;
     90                        return new PasswordAuthentication(username, password.toCharArray());
     91                }
     92        }
    8293
    8394        /**
     
    8899                authentication.passwordtried = false;
    89100        }
    90        
     101
    91102        /**
    92103         * @return Whether the connection was cancelled.
     
    99110                this.currentAction = currentAction;
    100111                this.progress = progress;
    101     }
     112        }
    102113
    103114        public void cancel() {
    104115                currentAction.setText("Aborting...");
    105         cancel = true;
    106         if (activeConnection != null) {
    107                 activeConnection.setConnectTimeout(1);
    108                 activeConnection.setReadTimeout(1);
    109                 activeConnection.disconnect();
    110         }
    111     }
     116                cancel = true;
     117                if (activeConnection != null) {
     118                        activeConnection.setConnectTimeout(1);
     119                        activeConnection.setReadTimeout(1);
     120                        activeConnection.disconnect();
     121                }
     122        }
    112123}
Note: See TracChangeset for help on using the changeset viewer.