source: josm/trunk/src/org/openstreetmap/josm/gui/oauth/AuthorizationProcedureComboBox.java@ 12825

Last change on this file since 12825 was 12646, checked in by bastiK, 7 years ago

see #14794 - javadoc

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