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

Last change on this file since 10189 was 10183, checked in by Don-vip, 8 years ago

sonar - squid:AssignmentInSubExpressionCheck - Assignments should not be made from within sub-expressions

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