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 |
|
---|
13 | import org.openstreetmap.josm.gui.widgets.JosmComboBox;
|
---|
14 |
|
---|
15 | public class AuthorizationProcedureComboBox extends JosmComboBox {
|
---|
16 |
|
---|
17 | public AuthorizationProcedureComboBox() {
|
---|
18 | super(AuthorizationProcedure.values());
|
---|
19 | setRenderer(new AuthorisationProcedureCellRenderer());
|
---|
20 | setSelectedItem(AuthorizationProcedure.FULLY_AUTOMATIC);
|
---|
21 | }
|
---|
22 |
|
---|
23 | static private class AuthorisationProcedureCellRenderer extends JLabel implements ListCellRenderer {
|
---|
24 | public AuthorisationProcedureCellRenderer() {
|
---|
25 | setOpaque(true);
|
---|
26 | }
|
---|
27 |
|
---|
28 | protected void renderColors(boolean isSelected) {
|
---|
29 | if (isSelected) {
|
---|
30 | setForeground(UIManager.getColor("List.selectionForeground"));
|
---|
31 | setBackground(UIManager.getColor("List.selectionBackground"));
|
---|
32 | } else {
|
---|
33 | setForeground(UIManager.getColor("List.foreground"));
|
---|
34 | setBackground(UIManager.getColor("List.background"));
|
---|
35 | }
|
---|
36 | }
|
---|
37 |
|
---|
38 | protected void renderText(AuthorizationProcedure value) {
|
---|
39 | switch(value) {
|
---|
40 | case FULLY_AUTOMATIC:
|
---|
41 | setText(tr("Fully automatic"));
|
---|
42 | break;
|
---|
43 | case SEMI_AUTOMATIC:
|
---|
44 | setText(tr("Semi-automatic"));
|
---|
45 | break;
|
---|
46 | case MANUALLY:
|
---|
47 | setText(tr("Manual"));
|
---|
48 | break;
|
---|
49 | }
|
---|
50 | }
|
---|
51 |
|
---|
52 | protected void renderToolTipText(AuthorizationProcedure value) {
|
---|
53 | switch(value) {
|
---|
54 | case FULLY_AUTOMATIC:
|
---|
55 | setToolTipText(tr(
|
---|
56 | "<html>Run a fully automatic procedure to get an access token from the OSM website.<br>"
|
---|
57 | + "JOSM accesses the OSM website on behalf of the JOSM user and fully<br>"
|
---|
58 | + "automatically authorizes the user and retrieves an Access Token.</html>"
|
---|
59 | ));
|
---|
60 | break;
|
---|
61 | case SEMI_AUTOMATIC:
|
---|
62 | setToolTipText(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 | break;
|
---|
69 | case MANUALLY:
|
---|
70 | setToolTipText(tr(
|
---|
71 | "<html>Enter an Access Token manually if it was generated and retrieved outside<br>"
|
---|
72 | + "of JOSM.</html>"
|
---|
73 | ));
|
---|
74 | break;
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | public Component getListCellRendererComponent(JList list, Object value, int idx, boolean isSelected, boolean hasFocus) {
|
---|
79 | AuthorizationProcedure procedure = (AuthorizationProcedure)value;
|
---|
80 | renderColors(isSelected);
|
---|
81 | renderText(procedure);
|
---|
82 | renderToolTipText(procedure);
|
---|
83 | return this;
|
---|
84 | }
|
---|
85 | }
|
---|
86 | }
|
---|