Changeset 17600 in josm for trunk/src/org


Ignore:
Timestamp:
2021-03-20T14:00:14+01:00 (4 years ago)
Author:
simon04
Message:

see #20244 - OAuthAuthorizationWizard: Separate buttons for authorization procedures

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  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.oauth;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
    35
    46/**
     
    2729     * have been generated in a former session and filed away in a secure place.
    2830     */
    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    }
    3076}
  • trunk/src/org/openstreetmap/josm/gui/oauth/OAuthAuthorizationWizard.java

    r17599 r17600  
    1313import java.awt.event.ComponentAdapter;
    1414import java.awt.event.ComponentEvent;
    15 import java.awt.event.ItemEvent;
    16 import java.awt.event.ItemListener;
    1715import java.awt.event.WindowAdapter;
    1816import java.awt.event.WindowEvent;
     
    2119import java.lang.reflect.InvocationTargetException;
    2220import java.net.URL;
     21import java.util.Objects;
    2322import java.util.concurrent.Executor;
    2423import java.util.concurrent.FutureTask;
     
    2827import javax.swing.JButton;
    2928import javax.swing.JDialog;
    30 import javax.swing.JLabel;
    3129import javax.swing.JPanel;
    3230import javax.swing.JScrollPane;
     
    4442import org.openstreetmap.josm.gui.util.WindowGeometry;
    4543import org.openstreetmap.josm.gui.widgets.HtmlPanel;
     44import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
    4645import org.openstreetmap.josm.spi.preferences.Config;
    47 import org.openstreetmap.josm.tools.CheckParameterUtil;
    4846import org.openstreetmap.josm.tools.GBC;
    4947import org.openstreetmap.josm.tools.ImageProvider;
     
    5957public class OAuthAuthorizationWizard extends JDialog {
    6058    private boolean canceled;
     59    private final AuthorizationProcedure procedure;
    6160    private final String apiUrl;
    6261
    63     private final AuthorizationProcedureComboBox cbAuthorisationProcedure = new AuthorizationProcedureComboBox();
    6462    private FullyAutomaticAuthorizationUI pnlFullyAutomaticAuthorisationUI;
    6563    private SemiAutomaticAuthorizationUI pnlSemiAutomaticAuthorisationUI;
     
    123121
    124122        // the authorisation procedure
    125         JLabel lbl = new JLabel(tr("Please select an authorization procedure: "));
     123        JMultilineLabel lbl = new JMultilineLabel(AuthorizationProcedure.FULLY_AUTOMATIC.getDescription());
    126124        lbl.setFont(lbl.getFont().deriveFont(Font.PLAIN));
    127125        pnl.add(lbl, GBC.std());
    128 
    129         pnl.add(cbAuthorisationProcedure, GBC.eol().fill(GBC.HORIZONTAL));
    130         cbAuthorisationProcedure.addItemListener(new AuthorisationProcedureChangeListener());
    131         lbl.setLabelFor(cbAuthorisationProcedure);
    132126
    133127        if (!Config.getUrls().getDefaultOsmApiUrl().equals(apiUrl)) {
     
    155149     */
    156150    protected void refreshAuthorisationProcedurePanel() {
    157         AuthorizationProcedure procedure = (AuthorizationProcedure) cbAuthorisationProcedure.getSelectedItem();
    158151        switch(procedure) {
    159152        case FULLY_AUTOMATIC:
     
    217210     *
    218211     * @param parent the component relative to which the dialog is displayed
     212     * @param procedure the authorization procedure to use
    219213     * @param apiUrl the API URL. Must not be null.
    220214     * @param executor the executor used for running the HTTP requests for the authorization
    221215     * @throws IllegalArgumentException if apiUrl is null
    222216     */
    223     public OAuthAuthorizationWizard(Component parent, String apiUrl, Executor executor) {
     217    public OAuthAuthorizationWizard(Component parent, AuthorizationProcedure procedure, String apiUrl, Executor executor) {
    224218        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");
    227221        this.executor = executor;
    228222        build();
     
    239233
    240234    protected AbstractAuthorizationUI getCurrentAuthorisationUI() {
    241         switch((AuthorizationProcedure) cbAuthorisationProcedure.getSelectedItem()) {
     235        switch(procedure) {
    242236        case FULLY_AUTOMATIC: return pnlFullyAutomaticAuthorisationUI;
    243237        case MANUALLY: return pnlManualAuthorisationUI;
     
    320314            // executed via main worker. The OAuth connections would block otherwise.
    321315            final OAuthAuthorizationWizard wizard = new OAuthAuthorizationWizard(
    322                     MainApplication.getMainFrame(), serverUrl.toExternalForm(), Utils.newDirectExecutor());
     316                    MainApplication.getMainFrame(),
     317                    AuthorizationProcedure.FULLY_AUTOMATIC,
     318                    serverUrl.toExternalForm(), Utils.newDirectExecutor());
    323319            wizard.showDialog();
    324320            return wizard;
     
    332328    }
    333329
    334     class AuthorisationProcedureChangeListener implements ItemListener {
    335         @Override
    336         public void itemStateChanged(ItemEvent arg0) {
    337             refreshAuthorisationProcedurePanel();
    338         }
    339     }
    340 
    341330    class CancelAction extends AbstractAction {
    342331
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/OAuthAuthenticationPreferencesPanel.java

    r17333 r17600  
    2323import javax.swing.JPanel;
    2424
     25import org.openstreetmap.josm.actions.ExpertToggleAction;
    2526import org.openstreetmap.josm.data.oauth.OAuthAccessTokenHolder;
    2627import org.openstreetmap.josm.data.oauth.OAuthParameters;
     
    2829import org.openstreetmap.josm.gui.MainApplication;
    2930import org.openstreetmap.josm.gui.oauth.AdvancedOAuthPropertiesPanel;
     31import org.openstreetmap.josm.gui.oauth.AuthorizationProcedure;
    3032import org.openstreetmap.josm.gui.oauth.OAuthAuthorizationWizard;
    3133import org.openstreetmap.josm.gui.oauth.TestAccessTokenTask;
     
    174176
    175177            // 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;
    180178            JMultilineLabel lbl = new JMultilineLabel(
    181179                    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));
    183181            lbl.setFont(lbl.getFont().deriveFont(Font.PLAIN));
    184182
    185183            // 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);
    190189
    191190            // 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));
    197192        }
    198193    }
     
    260255            // -- action buttons
    261256            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)));
    263258            btns.add(new JButton(new TestAuthorisationAction()));
    264259            gc.gridy = 4;
     
    296291     */
    297292    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            }
    302302        }
    303303
     
    306306            OAuthAuthorizationWizard wizard = new OAuthAuthorizationWizard(
    307307                    OAuthAuthenticationPreferencesPanel.this,
     308                    procedure,
    308309                    apiUrl,
    309310                    MainApplication.worker);
     
    326327         * Constructs a new {@code RenewAuthorisationAction}.
    327328         */
    328         RenewAuthorisationAction() {
     329        RenewAuthorisationAction(AuthorizationProcedure procedure) {
     330            super(procedure);
    329331            putValue(NAME, tr("New Access Token"));
    330332            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.