Changeset 4246 in josm
- Timestamp:
- 2011-07-14T21:38:33+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java
r3719 r4246 53 53 * So for getValue(), setDefaultButton(int) and setCancelButton(int) the 54 54 * first button has index 1. 55 * 56 * Simple example: 57 * <code> 58 * ExtendedDialog ed = new ExtendedDialog( 59 * Main.parent, tr("Dialog Title"), 60 * new String[] {tr("Ok"), tr("Cancel")}); 61 * ed.setButtonIcons(new String[] {"ok", "cancel"}); // optional 62 * ed.setIcon(JOptionPane.WARNING_MESSAGE); // optional 63 * ed.setContent(tr("Really proceed? Interesting things may happen...")); 64 * ed.showDialog(); 65 * if (ed.getValue() == 1) { // user clicked first button "Ok" 66 * // proceed... 67 * } 68 * </code> 55 69 */ 56 70 public class ExtendedDialog extends JDialog { … … 282 296 JPanel buttonsPanel = new JPanel(new GridBagLayout()); 283 297 284 for (int i=0; i < bTexts.length; i++) {298 for (int i=0; i < bTexts.length; i++) { 285 299 final int final_i = i; 286 300 Action action = new AbstractAction(bTexts[i]) { 287 public void actionPerformed(ActionEvent evt) {301 @Override public void actionPerformed(ActionEvent evt) { 288 302 buttonAction(final_i, evt); 289 303 } … … 415 429 private void setupEscListener() { 416 430 Action actionListener = new AbstractAction() { 417 public void actionPerformed(ActionEvent actionEvent) {431 @Override public void actionPerformed(ActionEvent actionEvent) { 418 432 // 0 means that the dialog has been closed otherwise. 419 433 // We need to set it to zero again, in case the dialog has been re-used … … 535 549 if (toggleable && defaultButton != null) { 536 550 SwingUtilities.invokeLater(new Runnable() { 537 public void run() {551 @Override public void run() { 538 552 defaultButton.requestFocusInWindow(); 539 553 } … … 611 625 } 612 626 613 public void actionPerformed(ActionEvent e) {627 @Override public void actionPerformed(ActionEvent e) { 614 628 HelpBrowser.setUrlForHelpTopic(helpTopic); 615 629 } -
trunk/src/org/openstreetmap/josm/gui/JosmUserIdentityManager.java
r3083 r4246 25 25 * 26 26 * The current user is fully identified if JOSM knows both the user name and the unique 27 * id of the users OSM account. The lat er is retrieved from the OSM server with a27 * id of the users OSM account. The latter is retrieved from the OSM server with a 28 28 * <tt>GET /api/0.6/user/details</tt> request, submitted with the user name and password 29 29 * of the current user. -
trunk/src/org/openstreetmap/josm/gui/preferences/server/OsmApiUrlInputPanel.java
r3934 r4246 38 38 static public final String API_URL_PROP = OsmApiUrlInputPanel.class.getName() + ".apiUrl"; 39 39 40 static p rivatefinal String defaulturl = "http://api.openstreetmap.org/api";40 static public final String defaulturl = "http://api.openstreetmap.org/api"; 41 41 private JLabel lblValid; 42 42 private JLabel lblApiUrl; -
trunk/src/org/openstreetmap/josm/gui/preferences/server/ProxyPreferencesPanel.java
r4245 r4246 292 292 String policy = Main.pref.get(PROXY_POLICY, null); 293 293 ProxyPolicy pp = ProxyPolicy.fromName(policy); 294 pp = pp == null? ProxyPolicy.NO_PROXY: pp; 294 if (pp == null) { 295 pp = ProxyPolicy.NO_PROXY; 296 } 295 297 rbProxyPolicy.get(pp).setSelected(true); 296 298 String value = Main.pref.get("proxy.host", null); … … 353 355 354 356 class ProxyPolicyChangeListener implements ItemListener { 357 @Override 355 358 public void itemStateChanged(ItemEvent arg0) { 356 359 updateEnabledState(); -
trunk/src/org/openstreetmap/josm/io/auth/CredentialsManager.java
r4245 r4246 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.io.auth; 3 4 import java.net.Authenticator.RequestorType; 5 import java.net.PasswordAuthentication; 6 7 import org.openstreetmap.josm.data.oauth.OAuthToken; 3 8 4 9 /** … … 8 13 * 9 14 */ 10 public class CredentialsManager { 11 private static CredentialsAgent instance; 15 public class CredentialsManager implements CredentialsAgent { 16 17 private static CredentialsManager instance; 12 18 13 19 /** … … 16 22 * @return the single credential agent used in JOSM 17 23 */ 18 static public Credentials AgentgetInstance() {24 static public CredentialsManager getInstance() { 19 25 if (instance == null) { 20 instance = new JosmPreferencesCredentialAgent(); 26 CredentialsAgent delegate; 27 if (agentFactory == null) { 28 delegate = new JosmPreferencesCredentialAgent(); 29 } else { 30 delegate = agentFactory.getCredentialsAgent(); 31 } 32 instance = new CredentialsManager(delegate); 21 33 } 22 34 return instance; 23 35 } 36 37 private static CredentialsAgentFactory agentFactory; 38 39 public interface CredentialsAgentFactory { 40 CredentialsAgent getCredentialsAgent(); 41 } 42 43 /** 44 * Plugins can register a CredentialsAgentFactory, thereby overriding 45 * JOSM's default credentials agent. 46 */ 47 public static void registerCredentialsAgentFactory(CredentialsAgentFactory agentFactory) { 48 CredentialsManager.agentFactory = agentFactory; 49 CredentialsManager.instance = null; 50 } 51 52 /***** 53 * non-static fields and methods 54 */ 55 56 private CredentialsAgent delegate; 57 58 public CredentialsManager(CredentialsAgent delegate) { 59 this.delegate = delegate; 60 } 61 62 @Override 63 public PasswordAuthentication lookup(RequestorType requestorType) throws CredentialsAgentException { 64 return delegate.lookup(requestorType); 65 } 66 67 @Override 68 public void store(RequestorType requestorType, PasswordAuthentication credentials) throws CredentialsAgentException { 69 delegate.store(requestorType, credentials); 70 } 71 72 @Override 73 public CredentialsAgentResponse getCredentials(RequestorType requestorType, boolean noSuccessWithLastResponse) throws CredentialsAgentException { 74 return delegate.getCredentials(requestorType, noSuccessWithLastResponse); 75 } 76 77 @Override 78 public OAuthToken lookupOAuthAccessToken() throws CredentialsAgentException { 79 return delegate.lookupOAuthAccessToken(); 80 } 81 82 @Override 83 public void storeOAuthAccessToken(OAuthToken accessToken) throws CredentialsAgentException { 84 delegate.storeOAuthAccessToken(accessToken); 85 } 24 86 } -
trunk/src/org/openstreetmap/josm/io/auth/JosmPreferencesCredentialAgent.java
r4245 r4246 4 4 import java.net.PasswordAuthentication; 5 5 import java.net.Authenticator.RequestorType; 6 import java.util.HashMap;7 import java.util.Map;8 6 9 7 import org.openstreetmap.josm.Main; 10 8 import org.openstreetmap.josm.data.oauth.OAuthToken; 11 import org.openstreetmap.josm.gui.io.CredentialDialog;12 9 import org.openstreetmap.josm.gui.preferences.server.ProxyPreferencesPanel; 13 10 … … 17 14 * 18 15 */ 19 public class JosmPreferencesCredentialAgent implementsCredentialsAgent {16 public class JosmPreferencesCredentialAgent extends AbstractCredentialsAgent { 20 17 21 Map<RequestorType, PasswordAuthentication> memoryCredentialsCache = new HashMap<RequestorType, PasswordAuthentication>();22 18 /** 23 19 * @see CredentialsAgent#lookup(RequestorType) … … 74 70 75 71 /** 76 * @see CredentialsAgent#getCredentials(RequestorType, boolean)77 */78 @Override79 public CredentialsAgentResponse getCredentials(RequestorType requestorType, boolean noSuccessWithLastResponse) throws CredentialsAgentException{80 if (requestorType == null)81 return null;82 PasswordAuthentication credentials = lookup(requestorType);83 String username = (credentials == null || credentials.getUserName() == null) ? "" : credentials.getUserName();84 String password = (credentials == null || credentials.getPassword() == null) ? "" : String.valueOf(credentials.getPassword());85 86 CredentialsAgentResponse response = new CredentialsAgentResponse();87 88 /*89 * Last request was successful and there was no credentials stored90 * in file (or only the username is stored).91 * -> Try to recall credentials that have been entered92 * manually in this session.93 */94 if (!noSuccessWithLastResponse && memoryCredentialsCache.containsKey(requestorType) &&95 (credentials == null || credentials.getPassword() == null || credentials.getPassword().length == 0)) {96 PasswordAuthentication pa = memoryCredentialsCache.get(requestorType);97 response.setUsername(pa.getUserName());98 response.setPassword(pa.getPassword());99 response.setCanceled(false);100 /*101 * Prompt the user for credentials. This happens the first time each102 * josm start if the user does not save the credentials to preference103 * file (username=="") and each time after authentication failed104 * (noSuccessWithLastResponse == true).105 */106 } else if (noSuccessWithLastResponse || username.equals("") || password.equals("")) {107 CredentialDialog dialog = null;108 switch(requestorType) {109 case SERVER: dialog = CredentialDialog.getOsmApiCredentialDialog(username, password); break;110 case PROXY: dialog = CredentialDialog.getHttpProxyCredentialDialog(username, password); break;111 }112 dialog.setVisible(true);113 response.setCanceled(dialog.isCanceled());114 if (dialog.isCanceled())115 return response;116 response.setUsername(dialog.getUsername());117 response.setPassword(dialog.getPassword());118 if (dialog.isSaveCredentials()) {119 store(requestorType, new PasswordAuthentication(120 response.getUsername(),121 response.getPassword()122 ));123 /*124 * User decides not to save credentials to file. Keep it125 * in memory so we don't have to ask over and over again.126 */127 } else {128 PasswordAuthentication pa = new PasswordAuthentication(dialog.getUsername(), dialog.getPassword());129 memoryCredentialsCache.put(requestorType, pa);130 }131 /*132 * We got it from file.133 */134 } else {135 response.setUsername(username);136 response.setPassword(password.toCharArray());137 response.setCanceled(false);138 }139 return response;140 }141 142 /**143 72 * Lookup the current OAuth Access Token to access the OSM server. Replies null, if no 144 73 * Access Token is currently managed by this CredentialManager.
Note:
See TracChangeset
for help on using the changeset viewer.