Better detect when the client can be actually started

This commit is contained in:
Laurent Clouet
2015-04-03 19:39:52 +01:00
parent 56fb084afa
commit ebe6914624

View File

@@ -2,6 +2,8 @@ package com.sheepit.client.standalone.swing.activity;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.LinkedList; import java.util.LinkedList;
@@ -72,6 +74,7 @@ public class Settings implements Activity {
login.setBounds(start_label_right, n, end_label_right - start_label_right, size_height_label); login.setBounds(start_label_right, n, end_label_right - start_label_right, size_height_label);
login.setText(parent.getConfiguration().login()); login.setText(parent.getConfiguration().login());
login.setColumns(20); login.setColumns(20);
login.addKeyListener(new CheckCanStart());
parent.getContentPane().add(login); parent.getContentPane().add(login);
n += sep; n += sep;
@@ -84,6 +87,7 @@ public class Settings implements Activity {
password.setBounds(start_label_right, n, end_label_right - start_label_right, size_height_label); password.setBounds(start_label_right, n, end_label_right - start_label_right, size_height_label);
password.setText(parent.getConfiguration().password()); password.setText(parent.getConfiguration().password());
password.setColumns(10); password.setColumns(10);
password.addKeyListener(new CheckCanStart());
parent.getContentPane().add(password); parent.getContentPane().add(password);
n += sep; n += sep;
@@ -168,6 +172,7 @@ public class Settings implements Activity {
saveButton.addActionListener(new SaveAction()); saveButton.addActionListener(new SaveAction());
parent.getContentPane().add(saveButton); parent.getContentPane().add(saveButton);
checkDisplaySaveButton();
} }
public void checkDisplaySaveButton() { public void checkDisplaySaveButton() {
@@ -177,6 +182,9 @@ public class Settings implements Activity {
selected = true; selected = true;
} }
} }
if (login.getText().isEmpty() || password.getPassword().length == 0) {
selected = false;
}
saveButton.setEnabled(selected); saveButton.setEnabled(selected);
} }
@@ -215,6 +223,16 @@ public class Settings implements Activity {
} }
} }
class AutoSignInChangeAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
if (autoSignIn.isSelected()) {
saveFile.setSelected(true);
}
}
}
class SaveAction implements ActionListener { class SaveAction implements ActionListener {
@Override @Override
@@ -293,4 +311,21 @@ public class Settings implements Activity {
return gpu; return gpu;
} }
} }
public class CheckCanStart implements KeyListener {
@Override
public void keyPressed(KeyEvent arg0) {
}
@Override
public void keyReleased(KeyEvent arg0) {
}
@Override
public void keyTyped(KeyEvent arg0) {
checkDisplaySaveButton();
}
}
} }