1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.oauth;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.GridBagConstraints;
|
---|
7 | import java.awt.GridBagLayout;
|
---|
8 | import java.awt.Insets;
|
---|
9 |
|
---|
10 | import javax.swing.JCheckBox;
|
---|
11 | import javax.swing.JLabel;
|
---|
12 | import javax.swing.JPanel;
|
---|
13 |
|
---|
14 | import org.openstreetmap.josm.data.oauth.OAuthToken;
|
---|
15 | import org.openstreetmap.josm.gui.preferences.server.OAuthAccessTokenHolder;
|
---|
16 | import org.openstreetmap.josm.gui.widgets.JosmTextField;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Displays the key and the secret of an OAuth Access Token.
|
---|
20 | *
|
---|
21 | */
|
---|
22 | public class AccessTokenInfoPanel extends JPanel {
|
---|
23 |
|
---|
24 | private JosmTextField tfAccessTokenKey;
|
---|
25 | private JosmTextField tfAccessTokenSecret;
|
---|
26 | private JCheckBox cbSaveAccessTokenInPreferences;
|
---|
27 |
|
---|
28 | protected final 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 JosmTextField(), 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 JosmTextField(), 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 | }
|
---|