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

Last change on this file since 5965 was 5450, checked in by Don-vip, 12 years ago

fix #7917 - Control the number of items displayed at once in all comboboxes (replaced configurable method with a dynamic method based on screen height and look and feel)

  • Property svn:eol-style set to native
File size: 3.3 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 {
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}
Note: See TracBrowser for help on using the repository browser.