001 // License: GPL. For details, see LICENSE file. 002 package org.openstreetmap.josm.gui.oauth; 003 004 import static org.openstreetmap.josm.tools.I18n.tr; 005 006 import java.awt.Component; 007 008 import javax.swing.JLabel; 009 import javax.swing.JList; 010 import javax.swing.ListCellRenderer; 011 import javax.swing.UIManager; 012 013 import org.openstreetmap.josm.gui.widgets.JosmComboBox; 014 015 public class AuthorizationProcedureComboBox extends JosmComboBox { 016 017 public AuthorizationProcedureComboBox() { 018 super(AuthorizationProcedure.values()); 019 setRenderer(new AuthorisationProcedureCellRenderer()); 020 setSelectedItem(AuthorizationProcedure.FULLY_AUTOMATIC); 021 } 022 023 static private class AuthorisationProcedureCellRenderer extends JLabel implements ListCellRenderer { 024 public AuthorisationProcedureCellRenderer() { 025 setOpaque(true); 026 } 027 028 protected void renderColors(boolean isSelected) { 029 if (isSelected) { 030 setForeground(UIManager.getColor("List.selectionForeground")); 031 setBackground(UIManager.getColor("List.selectionBackground")); 032 } else { 033 setForeground(UIManager.getColor("List.foreground")); 034 setBackground(UIManager.getColor("List.background")); 035 } 036 } 037 038 protected void renderText(AuthorizationProcedure value) { 039 switch(value) { 040 case FULLY_AUTOMATIC: 041 setText(tr("Fully automatic")); 042 break; 043 case SEMI_AUTOMATIC: 044 setText(tr("Semi-automatic")); 045 break; 046 case MANUALLY: 047 setText(tr("Manual")); 048 break; 049 } 050 } 051 052 protected void renderToolTipText(AuthorizationProcedure value) { 053 switch(value) { 054 case FULLY_AUTOMATIC: 055 setToolTipText(tr( 056 "<html>Run a fully automatic procedure to get an access token from the OSM website.<br>" 057 + "JOSM accesses the OSM website on behalf of the JOSM user and fully<br>" 058 + "automatically authorizes the user and retrieves an Access Token.</html>" 059 )); 060 break; 061 case SEMI_AUTOMATIC: 062 setToolTipText(tr( 063 "<html>Run a semi-automatic procedure to get an access token from the OSM website.<br>" 064 + "JOSM submits the standards OAuth requests to get a Request Token and an<br>" 065 + "Access Token. It dispatches the user to the OSM website in an external browser<br>" 066 + "to authenticate itself and to accept the request token submitted by JOSM.</html>" 067 )); 068 break; 069 case MANUALLY: 070 setToolTipText(tr( 071 "<html>Enter an Access Token manually if it was generated and retrieved outside<br>" 072 + "of JOSM.</html>" 073 )); 074 break; 075 } 076 } 077 078 public Component getListCellRendererComponent(JList list, Object value, int idx, boolean isSelected, boolean hasFocus) { 079 AuthorizationProcedure procedure = (AuthorizationProcedure)value; 080 renderColors(isSelected); 081 renderText(procedure); 082 renderToolTipText(procedure); 083 return this; 084 } 085 } 086 }