package swing;
import java.awt.BorderLayout;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.SoftBevelBorder;
import core.RPC;
import core.XML_Parser;
public class MainWindow extends JFrame implements ActionListener {
private MenuBar menuBar = new MenuBar(this);
private JPanel statusBar = new JPanel();
private JLabel statusLabel = new JLabel();
private RPC rpc = new RPC("localhost", 31416);
public XML_Parser parser;
private Tabs tabs = new Tabs();
public MainWindow(String title) throws HeadlessException {
super(title);
System.out.println("Programm started");
setLayout(new BorderLayout());
setJMenuBar(menuBar);
System.out.println("Creating status-bar");
createStatusBar();
System.out.println("creating window content");
createWindow();
System.out.println("Connecting to coreclient");
rpc.createConnection();
}
private void createWindow() {
add(tabs, BorderLayout.CENTER);
}
private void createStatusBar() {
add(statusBar, BorderLayout.SOUTH);
statusBar.setBorder(new SoftBevelBorder(SoftBevelBorder.LOWERED));
statusBar.add(statusLabel);
}
public static void main(String[] args) {
MainWindow win = new MainWindow("Test");
win.setBounds(10, 10, 400, 400);
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
win.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
Object src = e.getSource();
if (src == menuBar.quit) {
quit();
}
if (src == menuBar.attachToProject) {
}
if (src == menuBar.accountManager) {
}
if (src == menuBar.runAlways) {
statusLabel.setText("Setting run mode...");
parser = new XML_Parser(rpc.set_run_mode(RPC.RUN_MODE_ALWAYS).toString());
if(parser.runMode()) {
statusLabel.setText(statusLabel.getText()+" done");
} else {
statusLabel.setText(statusLabel.getText()+" ERROR!!!");
}
}
if (src == menuBar.runBasedOnPreferences) {
statusLabel.setText("Setting run mode...");
parser = new XML_Parser(rpc.set_run_mode(RPC.RUN_MODE_AUTO).toString());
if(parser.runMode()) {
statusLabel.setText(statusLabel.getText()+" done");
} else {
statusLabel.setText(statusLabel.getText()+" ERROR!!!");
}
}
if (src == menuBar.suspend) {
statusLabel.setText("Setting run mode...");
parser = new XML_Parser(rpc.set_run_mode(RPC.RUN_MODE_NEVER).toString());
if(parser.runMode()) {
statusLabel.setText(statusLabel.getText()+" done");
} else {
statusLabel.setText(statusLabel.getText()+" ERROR!!!");
}
}
if (src == menuBar.networkActivityAlwaysAvailable) {
statusLabel.setText("Setting network mode...");
parser = new XML_Parser(rpc.set_network_mode(RPC.NETWORK_MODE_ALWAYS).toString());
if(parser.networkMode()) {
statusLabel.setText(statusLabel.getText()+" done");
} else {
statusLabel.setText(statusLabel.getText()+" ERROR!!!");
}
}
if (src == menuBar.networkActivityBasedOnPreferences) {
statusLabel.setText("Setting network mode...");
parser = new XML_Parser(rpc.set_network_mode(RPC.NETWORK_MODE_AUTO).toString());
if(parser.networkMode()) {
statusLabel.setText(statusLabel.getText()+" done");
} else {
statusLabel.setText(statusLabel.getText()+" ERROR!!!");
}
}
if (src == menuBar.networkActivitySuspended) {
statusLabel.setText("Setting network mode...");
parser = new XML_Parser(rpc.set_network_mode(RPC.NETWORK_MODE_NEVER).toString());
if(parser.networkMode()) {
statusLabel.setText(statusLabel.getText()+" done");
} else {
statusLabel.setText(statusLabel.getText()+" ERROR!!!");
}
}
if (src == menuBar.options) {
}
if (src == menuBar.selectComputer) {
}
if (src == menuBar.runCPUBenchmarks) {
statusLabel.setText("running Benchmarks...");
parser = new XML_Parser(rpc.run_benchmarks().toString());
if(parser.benchmark()) {
statusLabel.setText(statusLabel.getText()+" done");
} else {
statusLabel.setText(statusLabel.getText()+" ERROR!!!");
}
}
if (src == menuBar.retryCommunication) {
}
if (src == menuBar.jBoincManager) {
}
if (src == menuBar.jBoincWebsite) {
}
if (src == menuBar.boincWebsite) {
}
if (src == menuBar.about) {
JOptionPane.showMessageDialog(this, core.Strings.ABOUT);
}
}
private void quit() {
rpc.removeConnection();
dispose();
core.Main.quit();
}
}