always show profile link

This commit is contained in:
rusefi 2020-07-21 20:29:07 -04:00
parent f9dc225da3
commit bcdd030566
1 changed files with 12 additions and 13 deletions

View File

@ -17,12 +17,11 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
public class AuthTokenPanel { public class AuthTokenPanel {
private static final String TOKEN_WARNING = "Please copy token from your forum profile"; private static final String TOKEN_WARNING = "Please copy token from your forum profile";
private static final String TOKEN_SUBSTRING = "token";
private static final String AUTH_TOKEN = "auth_token"; private static final String AUTH_TOKEN = "auth_token";
private static final String TOKEN_PROFILE_URL = "https://rusefi.com/forum/ucp.php?i=254"; private static final String TOKEN_PROFILE_URL = "https://rusefi.com/forum/ucp.php?i=254";
private JPanel content = new JPanel(new BorderLayout()); private final JPanel content = new JPanel(new BorderLayout());
private JTextField textField = new JTextField(); private final JTextField authTokenTestField = new JTextField();
public AuthTokenPanel() { public AuthTokenPanel() {
@ -30,12 +29,12 @@ public class AuthTokenPanel {
content.setBorder(BorderFactory.createTitledBorder("rusEFI Online Authentication Token")); content.setBorder(BorderFactory.createTitledBorder("rusEFI Online Authentication Token"));
textField.setPreferredSize(new Dimension(200, 24)); authTokenTestField.setPreferredSize(new Dimension(200, 24));
String authToken = getAuthToken(); String authToken = getAuthToken();
System.out.println("Got from settings: " + authToken); System.out.println("Got from settings: " + authToken);
textField.getDocument().addDocumentListener(new DocumentListener() { authTokenTestField.getDocument().addDocumentListener(new DocumentListener() {
@Override @Override
public void insertUpdate(DocumentEvent e) { public void insertUpdate(DocumentEvent e) {
onTextChange(); onTextChange();
@ -61,7 +60,7 @@ public class AuthTokenPanel {
try { try {
String data = (String) clipboard.getData(DataFlavor.stringFlavor); String data = (String) clipboard.getData(DataFlavor.stringFlavor);
if (AutoTokenUtil.isToken(data)) { if (AutoTokenUtil.isToken(data)) {
textField.setText(data); authTokenTestField.setText(data);
} }
} catch (IOException | UnsupportedFlavorException ex) { } catch (IOException | UnsupportedFlavorException ex) {
// ignoring this exception // ignoring this exception
@ -75,7 +74,7 @@ public class AuthTokenPanel {
setPasteButtonEnabledBasedOnClipboardContent(clipboard, paste); setPasteButtonEnabledBasedOnClipboardContent(clipboard, paste);
top.add(textField); top.add(authTokenTestField);
top.add(paste); top.add(paste);
/* /*
JButton save = new JButton("Save"); JButton save = new JButton("Save");
@ -90,9 +89,9 @@ public class AuthTokenPanel {
content.add(top); content.add(top);
if (authToken.trim().isEmpty()) { if (authToken.trim().isEmpty()) {
authToken = TOKEN_WARNING; authToken = TOKEN_WARNING;
content.add(new URLLabel("Get your token from your forum profile", TOKEN_PROFILE_URL), BorderLayout.SOUTH);
} }
textField.setText(authToken); content.add(new URLLabel("Manage authentication token at your forum profile", TOKEN_PROFILE_URL), BorderLayout.SOUTH);
authTokenTestField.setText(authToken);
} }
private void setPasteButtonEnabledBasedOnClipboardContent(Clipboard clipboard, JButton paste) { private void setPasteButtonEnabledBasedOnClipboardContent(Clipboard clipboard, JButton paste) {
@ -105,12 +104,12 @@ public class AuthTokenPanel {
} }
private void grabText() { private void grabText() {
setAuthToken(AuthTokenPanel.this.textField.getText()); setAuthToken(AuthTokenPanel.this.authTokenTestField.getText());
PersistentConfiguration.getConfig().save(); PersistentConfiguration.getConfig().save();
} }
private void onTextChange() { private void onTextChange() {
if (AutoTokenUtil.isToken(textField.getText())) { if (AutoTokenUtil.isToken(authTokenTestField.getText())) {
grabText(); grabText();
} }
} }
@ -129,11 +128,11 @@ public class AuthTokenPanel {
} }
public boolean hasToken() { public boolean hasToken() {
return AutoTokenUtil.isToken(textField.getText()); return AutoTokenUtil.isToken(authTokenTestField.getText());
} }
public String getToken() { public String getToken() {
return textField.getText(); return authTokenTestField.getText();
} }
public void showError(JComponent parent) { public void showError(JComponent parent) {