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

Last change on this file since 8836 was 8836, checked in by Don-vip, 9 years ago

fix Checkstyle issues

  • Property svn:eol-style set to native
File size: 3.5 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
15public class AuthorizationProcedureComboBox extends JosmComboBox<AuthorizationProcedure> {
16
17 /**
18 * Constructs a new {@code AuthorizationProcedureComboBox}.
19 */
20 public AuthorizationProcedureComboBox() {
21 super(AuthorizationProcedure.values());
22 setRenderer(new AuthorisationProcedureCellRenderer());
23 setSelectedItem(AuthorizationProcedure.FULLY_AUTOMATIC);
24 }
25
26 private static class AuthorisationProcedureCellRenderer extends JLabel implements ListCellRenderer<AuthorizationProcedure> {
27 AuthorisationProcedureCellRenderer() {
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
41 protected void renderText(AuthorizationProcedure value) {
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
55 protected void renderToolTipText(AuthorizationProcedure value) {
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>"
61 + "automatically authorizes the user and retrieves an Access Token.</html>"
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
81 @Override
82 public Component getListCellRendererComponent(JList<? extends AuthorizationProcedure> list, AuthorizationProcedure procedure,
83 int idx, boolean isSelected, boolean hasFocus) {
84 renderColors(isSelected);
85 renderText(procedure);
86 renderToolTipText(procedure);
87 return this;
88 }
89 }
90}
Note: See TracBrowser for help on using the repository browser.