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.DefaultComboBoxModel;
|
---|
9 | import javax.swing.JComboBox;
|
---|
10 | import javax.swing.JLabel;
|
---|
11 | import javax.swing.JList;
|
---|
12 | import javax.swing.ListCellRenderer;
|
---|
13 | import javax.swing.UIManager;
|
---|
14 |
|
---|
15 | public class AuthorizationProcedureComboBox extends JComboBox {
|
---|
16 |
|
---|
17 | public AuthorizationProcedureComboBox() {
|
---|
18 | setModel(new AuthorisationProcedureComboBoxModel());
|
---|
19 | setRenderer(new AuthorisationProcedureCellRenderer());
|
---|
20 | setSelectedItem(AuthorizationProcedure.FULLY_AUTOMATIC);
|
---|
21 | }
|
---|
22 |
|
---|
23 | static private class AuthorisationProcedureComboBoxModel extends DefaultComboBoxModel {
|
---|
24 | @Override
|
---|
25 | public Object getElementAt(int index) {
|
---|
26 | switch(index) {
|
---|
27 | case 0: return AuthorizationProcedure.FULLY_AUTOMATIC;
|
---|
28 | case 1: return AuthorizationProcedure.SEMI_AUTOMATIC;
|
---|
29 | case 2: return AuthorizationProcedure.MANUALLY;
|
---|
30 | }
|
---|
31 | return null;
|
---|
32 | }
|
---|
33 |
|
---|
34 | @Override
|
---|
35 | public int getSize() {
|
---|
36 | return 3;
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | static private class AuthorisationProcedureCellRenderer extends JLabel implements ListCellRenderer {
|
---|
41 | public AuthorisationProcedureCellRenderer() {
|
---|
42 | setOpaque(true);
|
---|
43 | }
|
---|
44 |
|
---|
45 | protected void renderColors(boolean isSelected) {
|
---|
46 | if (isSelected) {
|
---|
47 | setForeground(UIManager.getColor("List.selectionForeground"));
|
---|
48 | setBackground(UIManager.getColor("List.selectionBackground"));
|
---|
49 | } else {
|
---|
50 | setForeground(UIManager.getColor("List.foreground"));
|
---|
51 | setBackground(UIManager.getColor("List.background"));
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | protected void renderText(AuthorizationProcedure value) {
|
---|
56 | switch(value) {
|
---|
57 | case FULLY_AUTOMATIC:
|
---|
58 | setText(tr("Fully automatic"));
|
---|
59 | break;
|
---|
60 | case SEMI_AUTOMATIC:
|
---|
61 | setText(tr("Semi-automatic"));
|
---|
62 | break;
|
---|
63 | case MANUALLY:
|
---|
64 | setText(tr("Manual"));
|
---|
65 | break;
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | protected void renderToolTipText(AuthorizationProcedure value) {
|
---|
70 | switch(value) {
|
---|
71 | case FULLY_AUTOMATIC:
|
---|
72 | setToolTipText(tr(
|
---|
73 | "<html>Run a fully automatic procedure to get an access token from the OSM website.<br>"
|
---|
74 | + "JOSM accesses the OSM website on behalf of the JOSM user and fully<br>"
|
---|
75 | + "automatically authorizes the user and retrieves an Access Token.</html>"
|
---|
76 | ));
|
---|
77 | break;
|
---|
78 | case SEMI_AUTOMATIC:
|
---|
79 | setToolTipText(tr(
|
---|
80 | "<html>Run a semi-automatic procedure to get an access token from the OSM website.<br>"
|
---|
81 | + "JOSM submits the standards OAuth requests to get a Request Token and an<br>"
|
---|
82 | + "Access Token. It dispatches the user to the OSM website in an external browser<br>"
|
---|
83 | + "to authenticate itself and to accept the request token submitted by JOSM.</html>"
|
---|
84 | ));
|
---|
85 | break;
|
---|
86 | case MANUALLY:
|
---|
87 | setToolTipText(tr(
|
---|
88 | "<html>Enter an Access Token manually if it was generated and retrieved outside<br>"
|
---|
89 | + "of JOSM.</html>"
|
---|
90 | ));
|
---|
91 | break;
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | public Component getListCellRendererComponent(JList list, Object value, int idx, boolean isSelected, boolean hasFocus) {
|
---|
96 | AuthorizationProcedure procedure = (AuthorizationProcedure)value;
|
---|
97 | renderColors(isSelected);
|
---|
98 | renderText(procedure);
|
---|
99 | renderToolTipText(procedure);
|
---|
100 | return this;
|
---|
101 | }
|
---|
102 | }
|
---|
103 | }
|
---|