[2801] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.gui.oauth;
|
---|
| 3 |
|
---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 5 |
|
---|
| 6 | import java.awt.Component;
|
---|
| 7 |
|
---|
| 8 | import javax.swing.JLabel;
|
---|
| 9 | import javax.swing.JList;
|
---|
| 10 | import javax.swing.ListCellRenderer;
|
---|
| 11 | import javax.swing.UIManager;
|
---|
| 12 |
|
---|
[5429] | 13 | import org.openstreetmap.josm.gui.widgets.JosmComboBox;
|
---|
[2801] | 14 |
|
---|
[7015] | 15 | public class AuthorizationProcedureComboBox extends JosmComboBox<AuthorizationProcedure> {
|
---|
[5429] | 16 |
|
---|
[6883] | 17 | /**
|
---|
| 18 | * Constructs a new {@code AuthorizationProcedureComboBox}.
|
---|
| 19 | */
|
---|
[2861] | 20 | public AuthorizationProcedureComboBox() {
|
---|
[5450] | 21 | super(AuthorizationProcedure.values());
|
---|
[2801] | 22 | setRenderer(new AuthorisationProcedureCellRenderer());
|
---|
[2861] | 23 | setSelectedItem(AuthorizationProcedure.FULLY_AUTOMATIC);
|
---|
[2801] | 24 | }
|
---|
| 25 |
|
---|
[7001] | 26 | private static class AuthorisationProcedureCellRenderer extends JLabel implements ListCellRenderer<AuthorizationProcedure> {
|
---|
[8836] | 27 | AuthorisationProcedureCellRenderer() {
|
---|
[2801] | 28 | setOpaque(true);
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | protected void renderColors(boolean isSelected) {
|
---|
| 32 | if (isSelected) {
|
---|
| 33 | setForeground(UIManager.getColor("List.selectionForeground"));
|
---|
| 34 | setBackground(UIManager.getColor("List.selectionBackground"));
|
---|
| 35 | } else {
|
---|
| 36 | setForeground(UIManager.getColor("List.foreground"));
|
---|
| 37 | setBackground(UIManager.getColor("List.background"));
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
[2861] | 41 | protected void renderText(AuthorizationProcedure value) {
|
---|
[2801] | 42 | switch(value) {
|
---|
| 43 | case FULLY_AUTOMATIC:
|
---|
| 44 | setText(tr("Fully automatic"));
|
---|
| 45 | break;
|
---|
| 46 | case SEMI_AUTOMATIC:
|
---|
| 47 | setText(tr("Semi-automatic"));
|
---|
| 48 | break;
|
---|
| 49 | case MANUALLY:
|
---|
| 50 | setText(tr("Manual"));
|
---|
| 51 | break;
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 |
|
---|
[2861] | 55 | protected void renderToolTipText(AuthorizationProcedure value) {
|
---|
[2801] | 56 | switch(value) {
|
---|
| 57 | case FULLY_AUTOMATIC:
|
---|
| 58 | setToolTipText(tr(
|
---|
| 59 | "<html>Run a fully automatic procedure to get an access token from the OSM website.<br>"
|
---|
| 60 | + "JOSM accesses the OSM website on behalf of the JOSM user and fully<br>"
|
---|
[2877] | 61 | + "automatically authorizes the user and retrieves an Access Token.</html>"
|
---|
[2801] | 62 | ));
|
---|
| 63 | break;
|
---|
| 64 | case SEMI_AUTOMATIC:
|
---|
| 65 | setToolTipText(tr(
|
---|
| 66 | "<html>Run a semi-automatic procedure to get an access token from the OSM website.<br>"
|
---|
| 67 | + "JOSM submits the standards OAuth requests to get a Request Token and an<br>"
|
---|
| 68 | + "Access Token. It dispatches the user to the OSM website in an external browser<br>"
|
---|
| 69 | + "to authenticate itself and to accept the request token submitted by JOSM.</html>"
|
---|
| 70 | ));
|
---|
| 71 | break;
|
---|
| 72 | case MANUALLY:
|
---|
| 73 | setToolTipText(tr(
|
---|
| 74 | "<html>Enter an Access Token manually if it was generated and retrieved outside<br>"
|
---|
| 75 | + "of JOSM.</html>"
|
---|
| 76 | ));
|
---|
| 77 | break;
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 |
|
---|
[6084] | 81 | @Override
|
---|
[7509] | 82 | public Component getListCellRendererComponent(JList<? extends AuthorizationProcedure> list, AuthorizationProcedure procedure,
|
---|
[7001] | 83 | int idx, boolean isSelected, boolean hasFocus) {
|
---|
[2801] | 84 | renderColors(isSelected);
|
---|
| 85 | renderText(procedure);
|
---|
| 86 | renderToolTipText(procedure);
|
---|
| 87 | return this;
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 | }
|
---|