chiark / gitweb /
Control panel selects live servers by default
[jarrg-owen.git] / src / com / tedpearson / ypp / market / ControlPanel.java
1 package com.tedpearson.ypp.market;
2
3 import javax.swing.*;
4 import java.awt.*;
5 import java.awt.event.*;
6 import java.util.prefs.*;
7
8 /**
9 *       ControlPanel is a simple management utility that sets
10 *       a preference for whether the PCTB client is to launch or not.
11 */
12 public class ControlPanel extends JFrame {
13         public static void main(String[] args) {
14                 new ControlPanel();
15         }
16         
17         public ControlPanel() {
18                 super("PCTB Control Panel");
19                 final Preferences prefs = Preferences.userNodeForPackage(getClass());
20                 final JCheckBox cb = new JCheckBox("Launch PCTB Uploader when YPP starts?", prefs.getBoolean("launchAtStartup", true));
21                 final JCheckBox toPCTB = new JCheckBox("Upload to PCTB?", prefs.getBoolean("uploadToPCTB", true));
22                 final JCheckBox toYarrg = new JCheckBox("Upload to Yarrg?", prefs.getBoolean("uploadToYarrg", true));
23
24                 final JRadioButton live = new JRadioButton("Use live servers");
25                 final JRadioButton testing = new JRadioButton("Use testing servers");
26                 
27                 live.setSelected(prefs.getBoolean("useLiveServers", true));
28                 testing.setSelected(!prefs.getBoolean("useLiveServers", true));
29
30                 ButtonGroup liveortest = new ButtonGroup();
31                 liveortest.add(live);
32                 liveortest.add(testing);
33
34                 setLayout(new GridLayout(6,1));
35                 add(cb);
36                 add(toPCTB);
37                 add(toYarrg);
38                 add(live);
39                 add(testing);
40
41                 JButton but = new JButton("Save");
42                 add(but);
43                 but.addActionListener(new ActionListener() {
44                         public void actionPerformed(ActionEvent e) {
45                                 prefs.putBoolean("launchAtStartup", cb.isSelected());
46                                 prefs.putBoolean("uploadToPCTB", toPCTB.isSelected());
47                                 prefs.putBoolean("uploadToYarrg", toYarrg.isSelected());
48                                 prefs.putBoolean("useLiveServers", live.isSelected());
49                                 System.exit(0);
50                         }
51                 });
52                 pack();
53                 setLocationRelativeTo(null);
54                 setVisible(true);
55                 setSize(getWidth() + 10, getHeight() + 10);
56                 setDefaultCloseOperation(EXIT_ON_CLOSE);
57                 getRootPane().setDefaultButton(but);
58         }
59 }