Permalink
Browse files

Added user preferences - remembers AP name and will auto-start on lau…

…nch if previously was started when quit.
  • Loading branch information...
adeward committed Oct 16, 2011
1 parent 7840a6d commit f46be26807613305309307965d1fb2b03a5b86fc
Showing with 22 additions and 2 deletions.
  1. +22 −2 src/Window.java
View
@@ -5,6 +5,7 @@
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
+import java.util.prefs.Preferences;
/**
* Main class
@@ -18,7 +19,8 @@
private JButton bouton;
private JTextField nameField;
private LaunchThread t;
-
+ private Preferences prefs;
+
/**
* @param args
*/
@@ -27,6 +29,9 @@ public static void main(String[] args) {
}
public Window(){
+
+ prefs = Preferences.userRoot().node(this.getClass().getName());
+
JFrame window = new JFrame();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// window.setSize(380, 100);
@@ -35,7 +40,9 @@ public Window(){
java.awt.Container contenu = window.getContentPane();
contenu.setLayout(new FlowLayout());
- nameField = new JTextField(15);
+ String apname = prefs.get("apname", ""); // Get the default AP name
+
+ nameField = new JTextField(apname,15);
bouton = new JButton("Start Airport Express");
bouton.addActionListener(this);
contenu.add(new JLabel("AP Name: "));
@@ -44,6 +51,15 @@ public Window(){
window.pack();
window.setVisible(true);
+
+ // If was previously Started, start it now
+ if (prefs.getBoolean("launched", false)) {
+ // TODO: Refactor so no duplication of code below
+ on = true;
+ t = new LaunchThread(nameField.getText());
+ t.start();
+ bouton.setText("Stop Airport Express");
+ }
}
@Override
@@ -54,10 +70,14 @@ public void actionPerformed(ActionEvent arg0) {
t = new LaunchThread(nameField.getText());
t.start();
bouton.setText("Stop Airport Express");
+
+ prefs.put("apname", nameField.getText());
+ prefs.putBoolean("launched", true); // Used on next launch
} else {
on = false;
t.stopThread();
bouton.setText("Start Airport Express");
+ prefs.putBoolean("launched", false); // Used on next launch
}
}

0 comments on commit f46be26

Please sign in to comment.