chiark / gitweb /
Initial commit of Yarrg code
[jarrg-owen.git] / src / com / tedpearson / ypp / market / ControlPanel.java
diff --git a/src/com/tedpearson/ypp/market/ControlPanel.java b/src/com/tedpearson/ypp/market/ControlPanel.java
new file mode 100644 (file)
index 0000000..a00e734
--- /dev/null
@@ -0,0 +1,59 @@
+package com.tedpearson.ypp.market;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.util.prefs.*;
+
+/**
+*      ControlPanel is a simple management utility that sets
+*      a preference for whether the PCTB client is to launch or not.
+*/
+public class ControlPanel extends JFrame {
+       public static void main(String[] args) {
+               new ControlPanel();
+       }
+       
+       public ControlPanel() {
+               super("PCTB Control Panel");
+               final Preferences prefs = Preferences.userNodeForPackage(getClass());
+               final JCheckBox cb = new JCheckBox("Launch PCTB Uploader when YPP starts?", prefs.getBoolean("launchAtStartup", true));
+               final JCheckBox toPCTB = new JCheckBox("Upload to PCTB?", prefs.getBoolean("uploadToPCTB", true));
+               final JCheckBox toYarrg = new JCheckBox("Upload to Yarrg?", prefs.getBoolean("uploadToYarrg", true));
+
+               final JRadioButton live = new JRadioButton("Use live servers");
+               final JRadioButton testing = new JRadioButton("Use testing servers");
+               
+               live.setSelected(prefs.getBoolean("useLiveServers", false));
+               testing.setSelected(!prefs.getBoolean("useLiveServers", false));
+
+               ButtonGroup liveortest = new ButtonGroup();
+               liveortest.add(live);
+               liveortest.add(testing);
+
+               setLayout(new GridLayout(6,1));
+               add(cb);
+               add(toPCTB);
+               add(toYarrg);
+               add(live);
+               add(testing);
+
+               JButton but = new JButton("Save");
+               add(but);
+               but.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               prefs.putBoolean("launchAtStartup", cb.isSelected());
+                               prefs.putBoolean("uploadToPCTB", toPCTB.isSelected());
+                               prefs.putBoolean("uploadToYarrg", toYarrg.isSelected());
+                               prefs.putBoolean("useLiveServers", live.isSelected());
+                               System.exit(0);
+                       }
+               });
+               pack();
+               setLocationRelativeTo(null);
+               setVisible(true);
+               setSize(getWidth() + 10, getHeight() + 10);
+               setDefaultCloseOperation(EXIT_ON_CLOSE);
+               getRootPane().setDefaultButton(but);
+       }
+}