Changeset 17600 in josm for trunk/src/org
- Timestamp:
- 2021-03-20T14:00:14+01:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/oauth/AuthorizationProcedure.java
r12646 r17600 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.oauth; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 /** … … 27 29 * have been generated in a former session and filed away in a secure place. 28 30 */ 29 MANUALLY 31 MANUALLY; 32 33 /** 34 * Returns the translated name of this procedure 35 * @return the translated name of this procedure 36 */ 37 public String getText() { 38 switch(this) { 39 case FULLY_AUTOMATIC: 40 return tr("Fully automatic"); 41 case SEMI_AUTOMATIC: 42 return tr("Semi-automatic"); 43 case MANUALLY: 44 return tr("Manual"); 45 } 46 throw new IllegalStateException(); 47 } 48 49 /** 50 * Returns a translated description of this procedure 51 * @return a translated description of this procedure 52 */ 53 public String getDescription() { 54 switch(this) { 55 case FULLY_AUTOMATIC: 56 return tr( 57 "<html>Run a fully automatic procedure to get an access token from the OSM website.<br>" 58 + "JOSM accesses the OSM website on behalf of the JOSM user and fully<br>" 59 + "automatically authorizes the user and retrieves an Access Token.</html>" 60 ); 61 case SEMI_AUTOMATIC: 62 return tr( 63 "<html>Run a semi-automatic procedure to get an access token from the OSM website.<br>" 64 + "JOSM submits the standards OAuth requests to get a Request Token and an<br>" 65 + "Access Token. It dispatches the user to the OSM website in an external browser<br>" 66 + "to authenticate itself and to accept the request token submitted by JOSM.</html>" 67 ); 68 case MANUALLY: 69 return tr( 70 "<html>Enter an Access Token manually if it was generated and retrieved outside<br>" 71 + "of JOSM.</html>" 72 ); 73 } 74 throw new IllegalStateException(); 75 } 30 76 } -
trunk/src/org/openstreetmap/josm/gui/oauth/OAuthAuthorizationWizard.java
r17599 r17600 13 13 import java.awt.event.ComponentAdapter; 14 14 import java.awt.event.ComponentEvent; 15 import java.awt.event.ItemEvent;16 import java.awt.event.ItemListener;17 15 import java.awt.event.WindowAdapter; 18 16 import java.awt.event.WindowEvent; … … 21 19 import java.lang.reflect.InvocationTargetException; 22 20 import java.net.URL; 21 import java.util.Objects; 23 22 import java.util.concurrent.Executor; 24 23 import java.util.concurrent.FutureTask; … … 28 27 import javax.swing.JButton; 29 28 import javax.swing.JDialog; 30 import javax.swing.JLabel;31 29 import javax.swing.JPanel; 32 30 import javax.swing.JScrollPane; … … 44 42 import org.openstreetmap.josm.gui.util.WindowGeometry; 45 43 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 44 import org.openstreetmap.josm.gui.widgets.JMultilineLabel; 46 45 import org.openstreetmap.josm.spi.preferences.Config; 47 import org.openstreetmap.josm.tools.CheckParameterUtil;48 46 import org.openstreetmap.josm.tools.GBC; 49 47 import org.openstreetmap.josm.tools.ImageProvider; … … 59 57 public class OAuthAuthorizationWizard extends JDialog { 60 58 private boolean canceled; 59 private final AuthorizationProcedure procedure; 61 60 private final String apiUrl; 62 61 63 private final AuthorizationProcedureComboBox cbAuthorisationProcedure = new AuthorizationProcedureComboBox();64 62 private FullyAutomaticAuthorizationUI pnlFullyAutomaticAuthorisationUI; 65 63 private SemiAutomaticAuthorizationUI pnlSemiAutomaticAuthorisationUI; … … 123 121 124 122 // the authorisation procedure 125 J Label lbl = new JLabel(tr("Please select an authorization procedure: "));123 JMultilineLabel lbl = new JMultilineLabel(AuthorizationProcedure.FULLY_AUTOMATIC.getDescription()); 126 124 lbl.setFont(lbl.getFont().deriveFont(Font.PLAIN)); 127 125 pnl.add(lbl, GBC.std()); 128 129 pnl.add(cbAuthorisationProcedure, GBC.eol().fill(GBC.HORIZONTAL));130 cbAuthorisationProcedure.addItemListener(new AuthorisationProcedureChangeListener());131 lbl.setLabelFor(cbAuthorisationProcedure);132 126 133 127 if (!Config.getUrls().getDefaultOsmApiUrl().equals(apiUrl)) { … … 155 149 */ 156 150 protected void refreshAuthorisationProcedurePanel() { 157 AuthorizationProcedure procedure = (AuthorizationProcedure) cbAuthorisationProcedure.getSelectedItem();158 151 switch(procedure) { 159 152 case FULLY_AUTOMATIC: … … 217 210 * 218 211 * @param parent the component relative to which the dialog is displayed 212 * @param procedure the authorization procedure to use 219 213 * @param apiUrl the API URL. Must not be null. 220 214 * @param executor the executor used for running the HTTP requests for the authorization 221 215 * @throws IllegalArgumentException if apiUrl is null 222 216 */ 223 public OAuthAuthorizationWizard(Component parent, String apiUrl, Executor executor) {217 public OAuthAuthorizationWizard(Component parent, AuthorizationProcedure procedure, String apiUrl, Executor executor) { 224 218 super(GuiHelper.getFrameForComponent(parent), ModalityType.DOCUMENT_MODAL); 225 CheckParameterUtil.ensureParameterNotNull(apiUrl, "apiUrl");226 this.apiUrl = apiUrl;219 this.procedure = Objects.requireNonNull(procedure, "procedure"); 220 this.apiUrl = Objects.requireNonNull(apiUrl, "apiUrl"); 227 221 this.executor = executor; 228 222 build(); … … 239 233 240 234 protected AbstractAuthorizationUI getCurrentAuthorisationUI() { 241 switch( (AuthorizationProcedure) cbAuthorisationProcedure.getSelectedItem()) {235 switch(procedure) { 242 236 case FULLY_AUTOMATIC: return pnlFullyAutomaticAuthorisationUI; 243 237 case MANUALLY: return pnlManualAuthorisationUI; … … 320 314 // executed via main worker. The OAuth connections would block otherwise. 321 315 final OAuthAuthorizationWizard wizard = new OAuthAuthorizationWizard( 322 MainApplication.getMainFrame(), serverUrl.toExternalForm(), Utils.newDirectExecutor()); 316 MainApplication.getMainFrame(), 317 AuthorizationProcedure.FULLY_AUTOMATIC, 318 serverUrl.toExternalForm(), Utils.newDirectExecutor()); 323 319 wizard.showDialog(); 324 320 return wizard; … … 332 328 } 333 329 334 class AuthorisationProcedureChangeListener implements ItemListener {335 @Override336 public void itemStateChanged(ItemEvent arg0) {337 refreshAuthorisationProcedurePanel();338 }339 }340 341 330 class CancelAction extends AbstractAction { 342 331 -
trunk/src/org/openstreetmap/josm/gui/preferences/server/OAuthAuthenticationPreferencesPanel.java
r17333 r17600 23 23 import javax.swing.JPanel; 24 24 25 import org.openstreetmap.josm.actions.ExpertToggleAction; 25 26 import org.openstreetmap.josm.data.oauth.OAuthAccessTokenHolder; 26 27 import org.openstreetmap.josm.data.oauth.OAuthParameters; … … 28 29 import org.openstreetmap.josm.gui.MainApplication; 29 30 import org.openstreetmap.josm.gui.oauth.AdvancedOAuthPropertiesPanel; 31 import org.openstreetmap.josm.gui.oauth.AuthorizationProcedure; 30 32 import org.openstreetmap.josm.gui.oauth.OAuthAuthorizationWizard; 31 33 import org.openstreetmap.josm.gui.oauth.TestAccessTokenTask; … … 174 176 175 177 // A message explaining that the user isn't authorised yet 176 gc.anchor = GridBagConstraints.NORTHWEST;177 gc.insets = new Insets(0, 0, 3, 0);178 gc.fill = GridBagConstraints.HORIZONTAL;179 gc.weightx = 1.0;180 178 JMultilineLabel lbl = new JMultilineLabel( 181 179 tr("You do not have an Access Token yet to access the OSM server using OAuth. Please authorize first.")); 182 add(lbl, gc);180 add(lbl, GBC.eol().anchor(GBC.NORTHWEST).fill(GBC.HORIZONTAL)); 183 181 lbl.setFont(lbl.getFont().deriveFont(Font.PLAIN)); 184 182 185 183 // Action for authorising now 186 gc.gridy = 1; 187 gc.fill = GridBagConstraints.NONE; 188 gc.weightx = 0.0; 189 add(new JButton(new AuthoriseNowAction()), gc); 184 add(new JButton(new AuthoriseNowAction(AuthorizationProcedure.FULLY_AUTOMATIC)), GBC.eol()); 185 add(new JButton(new AuthoriseNowAction(AuthorizationProcedure.SEMI_AUTOMATIC)), GBC.eol()); 186 JButton authManually = new JButton(new AuthoriseNowAction(AuthorizationProcedure.MANUALLY)); 187 add(authManually, GBC.eol()); 188 ExpertToggleAction.addVisibilitySwitcher(authManually); 190 189 191 190 // filler - grab remaining space 192 gc.gridy = 2; 193 gc.fill = GridBagConstraints.BOTH; 194 gc.weightx = 1.0; 195 gc.weighty = 1.0; 196 add(new JPanel(), gc); 191 add(new JPanel(), GBC.std().fill(GBC.BOTH)); 197 192 } 198 193 } … … 260 255 // -- action buttons 261 256 JPanel btns = new JPanel(new FlowLayout(FlowLayout.LEFT)); 262 btns.add(new JButton(new RenewAuthorisationAction( )));257 btns.add(new JButton(new RenewAuthorisationAction(AuthorizationProcedure.FULLY_AUTOMATIC))); 263 258 btns.add(new JButton(new TestAuthorisationAction())); 264 259 gc.gridy = 4; … … 296 291 */ 297 292 private class AuthoriseNowAction extends AbstractAction { 298 AuthoriseNowAction() { 299 putValue(NAME, tr("Authorize now")); 300 putValue(SHORT_DESCRIPTION, tr("Click to step through the OAuth authorization process")); 301 new ImageProvider("oauth", "oauth-small").getResource().attachImageIcon(this); 293 private final AuthorizationProcedure procedure; 294 295 AuthoriseNowAction(AuthorizationProcedure procedure) { 296 this.procedure = procedure; 297 putValue(NAME, tr("{0} ({1})", tr("Authorize now"), procedure.getText())); 298 putValue(SHORT_DESCRIPTION, procedure.getDescription()); 299 if (procedure == AuthorizationProcedure.FULLY_AUTOMATIC) { 300 new ImageProvider("oauth", "oauth-small").getResource().attachImageIcon(this); 301 } 302 302 } 303 303 … … 306 306 OAuthAuthorizationWizard wizard = new OAuthAuthorizationWizard( 307 307 OAuthAuthenticationPreferencesPanel.this, 308 procedure, 308 309 apiUrl, 309 310 MainApplication.worker); … … 326 327 * Constructs a new {@code RenewAuthorisationAction}. 327 328 */ 328 RenewAuthorisationAction() { 329 RenewAuthorisationAction(AuthorizationProcedure procedure) { 330 super(procedure); 329 331 putValue(NAME, tr("New Access Token")); 330 332 putValue(SHORT_DESCRIPTION, tr("Click to step through the OAuth authorization process and generate a new Access Token"));
Note:
See TracChangeset
for help on using the changeset viewer.