source: josm/trunk/src/org/openstreetmap/josm/gui/oauth/AccessTokenInfoPanel.java@ 3530

Last change on this file since 3530 was 3530, checked in by stoecker, 14 years ago

fix array preferences

  • Property svn:eol-style set to native
File size: 3.2 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.GridBagConstraints;
7import java.awt.GridBagLayout;
8import java.awt.Insets;
9
10import javax.swing.JCheckBox;
11import javax.swing.JLabel;
12import javax.swing.JPanel;
13import javax.swing.JTextField;
14
15import org.openstreetmap.josm.data.oauth.OAuthToken;
16import org.openstreetmap.josm.gui.preferences.server.OAuthAccessTokenHolder;
17
18/**
19 * Displays the key and the secret of an OAuth Access Token.
20 *
21 */
22public class AccessTokenInfoPanel extends JPanel {
23
24 private JTextField tfAccessTokenKey;
25 private JTextField tfAccessTokenSecret;
26 private JCheckBox cbSaveAccessTokenInPreferences;
27
28 protected void build() {
29 setLayout(new GridBagLayout());
30 GridBagConstraints gc = new GridBagConstraints();
31
32 // the access token key
33 gc.anchor = GridBagConstraints.NORTHWEST;
34 gc.fill = GridBagConstraints.HORIZONTAL;
35 gc.weightx = 0.0;
36 gc.insets = new Insets(0,0,3,3);
37 add(new JLabel(tr("Access Token Key:")), gc);
38
39 gc.gridx = 1;
40 gc.weightx = 1.0;
41 add(tfAccessTokenKey = new JTextField(), gc);
42 tfAccessTokenKey.setEditable(false);
43
44 // the access token secret
45 gc.gridx = 0;
46 gc.gridy = 1;
47 gc.weightx = 0.0;
48 gc.insets = new Insets(0,0,3,3);
49 add(new JLabel(tr("Access Token Secret:")), gc);
50
51 gc.gridx = 1;
52 gc.weightx = 1.0;
53 add(tfAccessTokenSecret = new JTextField(), gc);
54 tfAccessTokenSecret.setEditable(false);
55
56 // the checkbox
57 gc.gridx = 0;
58 gc.gridy = 2;
59 gc.gridwidth = 2;
60 add(cbSaveAccessTokenInPreferences = new JCheckBox(tr("Save Access Token in preferences")), gc);
61 cbSaveAccessTokenInPreferences.setToolTipText(tr(
62 "<html>Select to save the Access Token in the JOSM preferences.<br>"
63 + "Unselect to use the Access Token in this JOSM session only.</html>"
64 ));
65 cbSaveAccessTokenInPreferences.setSelected(OAuthAccessTokenHolder.getInstance().isSaveToPreferences());
66
67 // filler - grab the remaining space
68 gc.gridx = 0;
69 gc.gridy = 3;
70 gc.weightx = 1.0;
71 gc.weighty = 1.0;
72 gc.fill = GridBagConstraints.BOTH;
73 gc.gridwidth = 2;
74 add(new JPanel(), gc);
75 }
76
77 public AccessTokenInfoPanel() {
78 build();
79 }
80
81 /**
82 * Displays the key and secret in <code>token</code>.
83 *
84 * @param token the access token. If null, the content in the info panel is cleared
85 */
86 public void setAccessToken(OAuthToken token) {
87 if (token == null) {
88 tfAccessTokenKey.setText("");
89 tfAccessTokenSecret.setText("");
90 return;
91 }
92 tfAccessTokenKey.setText(token.getKey());
93 tfAccessTokenSecret.setText(token.getSecret());
94 }
95
96 public void setSaveToPreferences(boolean saveToPreferences) {
97 cbSaveAccessTokenInPreferences.setSelected(saveToPreferences);
98 }
99
100 public boolean isSaveToPreferences() {
101 return cbSaveAccessTokenInPreferences.isSelected();
102 }
103}
Note: See TracBrowser for help on using the repository browser.