Changeset 18650 in josm for trunk/src/org/openstreetmap/josm/gui/oauth/AdvancedOAuthPropertiesPanel.java
- Timestamp:
- 2023-02-08T18:31:58+01:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/oauth/AdvancedOAuthPropertiesPanel.java
r15586 r18650 16 16 import javax.swing.JOptionPane; 17 17 18 import org.openstreetmap.josm.data.oauth.IOAuthParameters; 19 import org.openstreetmap.josm.data.oauth.OAuth20Parameters; 18 20 import org.openstreetmap.josm.data.oauth.OAuthParameters; 21 import org.openstreetmap.josm.data.oauth.OAuthVersion; 19 22 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 20 23 import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec; … … 52 55 private final JosmTextField tfOsmLoginURL = new JosmTextField(); 53 56 private final JosmTextField tfOsmLogoutURL = new JosmTextField(); 57 private final OAuthVersion oauthVersion; 54 58 private transient UseDefaultItemListener ilUseDefault; 55 59 private String apiUrl; … … 57 61 /** 58 62 * Constructs a new {@code AdvancedOAuthPropertiesPanel}. 59 */ 60 public AdvancedOAuthPropertiesPanel() { 63 * @param oauthVersion The OAuth version to make the panel for 64 */ 65 public AdvancedOAuthPropertiesPanel(OAuthVersion oauthVersion) { 66 this.oauthVersion = oauthVersion; 61 67 build(); 62 68 } … … 71 77 gc.weightx = 1.0; 72 78 gc.insets = new Insets(0, 0, 3, 3); 73 gc.gridwidth = 2;79 gc.gridwidth = 3; 74 80 add(cbUseDefaults, gc); 75 81 … … 78 84 gc.weightx = 0.0; 79 85 gc.gridwidth = 1; 80 add(new JLabel(tr("Consumer Key:")), gc); 86 if (this.oauthVersion == OAuthVersion.OAuth10a) { 87 add(new JLabel(tr("Consumer Key:")), gc); 88 } else { 89 add(new JLabel(tr("Client ID:")), gc); 90 } 81 91 82 92 gc.gridx = 1; … … 86 96 87 97 // -- consumer secret 88 gc.gridy = 2;98 gc.gridy++; 89 99 gc.gridx = 0; 90 100 gc.weightx = 0.0; 91 add(new JLabel(tr("Consumer Secret:")), gc); 101 if (this.oauthVersion == OAuthVersion.OAuth10a) { 102 add(new JLabel(tr("Consumer Secret:")), gc); 103 } else { 104 add(new JLabel(tr("Client Secret:")), gc); 105 } 92 106 93 107 gc.gridx = 1; … … 97 111 98 112 // -- request token URL 99 gc.gridy = 3;113 gc.gridy++; 100 114 gc.gridx = 0; 101 115 gc.weightx = 0.0; 102 add(new JLabel(tr("Request Token URL:")), gc); 116 if (this.oauthVersion == OAuthVersion.OAuth10a) { 117 add(new JLabel(tr("Request Token URL:")), gc); 118 } else { 119 add(new JLabel(tr("Redirect URL:")), gc); 120 } 103 121 104 122 gc.gridx = 1; … … 108 126 109 127 // -- access token URL 110 gc.gridy = 4;128 gc.gridy++; 111 129 gc.gridx = 0; 112 130 gc.weightx = 0.0; … … 119 137 120 138 // -- authorise URL 121 gc.gridy = 5;139 gc.gridy++; 122 140 gc.gridx = 0; 123 141 gc.weightx = 0.0; … … 129 147 SelectAllOnFocusGainedDecorator.decorate(tfAuthoriseURL); 130 148 131 // -- OSM login URL 132 gc.gridy = 6; 133 gc.gridx = 0; 134 gc.weightx = 0.0; 135 add(new JLabel(tr("OSM login URL:")), gc); 136 137 gc.gridx = 1; 138 gc.weightx = 1.0; 139 add(tfOsmLoginURL, gc); 140 SelectAllOnFocusGainedDecorator.decorate(tfOsmLoginURL); 141 142 // -- OSM logout URL 143 gc.gridy = 7; 144 gc.gridx = 0; 145 gc.weightx = 0.0; 146 add(new JLabel(tr("OSM logout URL:")), gc); 147 148 gc.gridx = 1; 149 gc.weightx = 1.0; 150 add(tfOsmLogoutURL, gc); 151 SelectAllOnFocusGainedDecorator.decorate(tfOsmLogoutURL); 149 if (this.oauthVersion == OAuthVersion.OAuth10a) { 150 // -- OSM login URL 151 gc.gridy++; 152 gc.gridx = 0; 153 gc.weightx = 0.0; 154 add(new JLabel(tr("OSM login URL:")), gc); 155 156 gc.gridx = 1; 157 gc.weightx = 1.0; 158 add(tfOsmLoginURL, gc); 159 SelectAllOnFocusGainedDecorator.decorate(tfOsmLoginURL); 160 161 // -- OSM logout URL 162 gc.gridy++; 163 gc.gridx = 0; 164 gc.weightx = 0.0; 165 add(new JLabel(tr("OSM logout URL:")), gc); 166 167 gc.gridx = 1; 168 gc.weightx = 1.0; 169 add(tfOsmLogoutURL, gc); 170 SelectAllOnFocusGainedDecorator.decorate(tfOsmLogoutURL); 171 } 152 172 153 173 ilUseDefault = new UseDefaultItemListener(); … … 192 212 protected void resetToDefaultSettings() { 193 213 cbUseDefaults.setSelected(true); 194 OAuthParameters params = OAuthParameters.createDefault(apiUrl); 195 tfConsumerKey.setText(params.getConsumerKey()); 196 tfConsumerSecret.setText(params.getConsumerSecret()); 197 tfRequestTokenURL.setText(params.getRequestTokenUrl()); 198 tfAccessTokenURL.setText(params.getAccessTokenUrl()); 199 tfAuthoriseURL.setText(params.getAuthoriseUrl()); 200 tfOsmLoginURL.setText(params.getOsmLoginUrl()); 201 tfOsmLogoutURL.setText(params.getOsmLogoutUrl()); 214 IOAuthParameters iParams = OAuthParameters.createDefault(apiUrl, this.oauthVersion); 215 switch (this.oauthVersion) { 216 case OAuth10a: 217 OAuthParameters params = (OAuthParameters) iParams; 218 tfConsumerKey.setText(params.getConsumerKey()); 219 tfConsumerSecret.setText(params.getConsumerSecret()); 220 tfRequestTokenURL.setText(params.getRequestTokenUrl()); 221 tfAccessTokenURL.setText(params.getAccessTokenUrl()); 222 tfAuthoriseURL.setText(params.getAuthoriseUrl()); 223 tfOsmLoginURL.setText(params.getOsmLoginUrl()); 224 tfOsmLogoutURL.setText(params.getOsmLogoutUrl()); 225 break; 226 case OAuth20: 227 case OAuth21: 228 OAuth20Parameters params20 = (OAuth20Parameters) iParams; 229 tfConsumerKey.setText(params20.getClientId()); 230 tfConsumerSecret.setText(params20.getClientSecret()); 231 tfAccessTokenURL.setText(params20.getAccessTokenUrl()); 232 tfAuthoriseURL.setText(params20.getAuthorizationUrl()); 233 tfRequestTokenURL.setText(params20.getRedirectUri()); 234 } 202 235 203 236 setChildComponentsEnabled(false); … … 217 250 * @return the OAuth parameters 218 251 */ 219 public OAuthParameters getAdvancedParameters() { 252 public IOAuthParameters getAdvancedParameters() { 220 253 if (cbUseDefaults.isSelected()) 221 return OAuthParameters.createDefault(apiUrl); 222 return new OAuthParameters( 223 tfConsumerKey.getText(), 224 tfConsumerSecret.getText(), 225 tfRequestTokenURL.getText(), 226 tfAccessTokenURL.getText(), 227 tfAuthoriseURL.getText(), 228 tfOsmLoginURL.getText(), 229 tfOsmLogoutURL.getText()); 254 return OAuthParameters.createDefault(apiUrl, this.oauthVersion); 255 if (this.oauthVersion == OAuthVersion.OAuth10a) { 256 return new OAuthParameters( 257 tfConsumerKey.getText(), 258 tfConsumerSecret.getText(), 259 tfRequestTokenURL.getText(), 260 tfAccessTokenURL.getText(), 261 tfAuthoriseURL.getText(), 262 tfOsmLoginURL.getText(), 263 tfOsmLogoutURL.getText()); 264 } 265 return new OAuth20Parameters( 266 tfConsumerKey.getText(), 267 tfConsumerSecret.getText(), 268 tfAuthoriseURL.getText(), 269 tfAccessTokenURL.getText(), 270 tfRequestTokenURL.getText() 271 ); 230 272 } 231 273 … … 236 278 * @throws IllegalArgumentException if parameters is null. 237 279 */ 238 public void setAdvancedParameters(OAuthParameters parameters) { 280 public void setAdvancedParameters(IOAuthParameters parameters) { 239 281 CheckParameterUtil.ensureParameterNotNull(parameters, "parameters"); 240 if (parameters.equals(OAuthParameters.createDefault(apiUrl))) { 282 if (parameters.equals(OAuthParameters.createDefault(apiUrl, parameters.getOAuthVersion()))) { 241 283 cbUseDefaults.setSelected(true); 242 284 setChildComponentsEnabled(false); … … 244 286 cbUseDefaults.setSelected(false); 245 287 setChildComponentsEnabled(true); 246 tfConsumerKey.setText(parameters.getConsumerKey() == null ? "" : parameters.getConsumerKey()); 247 tfConsumerSecret.setText(parameters.getConsumerSecret() == null ? "" : parameters.getConsumerSecret()); 248 tfRequestTokenURL.setText(parameters.getRequestTokenUrl() == null ? "" : parameters.getRequestTokenUrl()); 249 tfAccessTokenURL.setText(parameters.getAccessTokenUrl() == null ? "" : parameters.getAccessTokenUrl()); 250 tfAuthoriseURL.setText(parameters.getAuthoriseUrl() == null ? "" : parameters.getAuthoriseUrl()); 251 tfOsmLoginURL.setText(parameters.getOsmLoginUrl() == null ? "" : parameters.getOsmLoginUrl()); 252 tfOsmLogoutURL.setText(parameters.getOsmLogoutUrl() == null ? "" : parameters.getOsmLogoutUrl()); 288 if (parameters instanceof OAuthParameters) { 289 OAuthParameters parameters10 = (OAuthParameters) parameters; 290 tfConsumerKey.setText(parameters10.getConsumerKey() == null ? "" : parameters10.getConsumerKey()); 291 tfConsumerSecret.setText(parameters10.getConsumerSecret() == null ? "" : parameters10.getConsumerSecret()); 292 tfRequestTokenURL.setText(parameters10.getRequestTokenUrl() == null ? "" : parameters10.getRequestTokenUrl()); 293 tfAccessTokenURL.setText(parameters10.getAccessTokenUrl() == null ? "" : parameters10.getAccessTokenUrl()); 294 tfAuthoriseURL.setText(parameters10.getAuthoriseUrl() == null ? "" : parameters10.getAuthoriseUrl()); 295 tfOsmLoginURL.setText(parameters10.getOsmLoginUrl() == null ? "" : parameters10.getOsmLoginUrl()); 296 tfOsmLogoutURL.setText(parameters10.getOsmLogoutUrl() == null ? "" : parameters10.getOsmLogoutUrl()); 297 } else if (parameters instanceof OAuth20Parameters) { 298 OAuth20Parameters parameters20 = (OAuth20Parameters) parameters; 299 tfConsumerKey.setText(parameters20.getClientId()); 300 tfConsumerSecret.setText(parameters20.getClientSecret()); 301 tfAccessTokenURL.setText(parameters20.getAccessTokenUrl()); 302 tfAuthoriseURL.setText(parameters20.getAuthorizationUrl()); 303 tfRequestTokenURL.setText(parameters20.getRedirectUri()); 304 } 253 305 } 254 306 }
Note:
See TracChangeset
for help on using the changeset viewer.
