00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 import javax.swing.*;
00036 import java.awt.*;
00037 import java.awt.event.*;
00038
00039
00040 public class ControlPanel extends JPanel implements ActionListener
00041 {
00042 public JTextArea results_txt;
00043
00044 private SenseGui gui;
00045 private JTextField spec_txt;
00046 private JButton submit_btn;
00047 private JLabel time_label;
00048 private String last_time;
00049
00050
00051 public ControlPanel(SenseGui g, int width, int height) {
00052 super();
00053 gui = g;
00054 last_time = "";
00055
00056 setLayout(new BorderLayout(0,0));
00057 setBorder(BorderFactory.createTitledBorder("Control"));
00058 setPreferredSize(new Dimension(width, height));
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 JPanel spec_input = new JPanel();
00073 spec_input.setLayout(new FlowLayout(FlowLayout.LEADING));
00074 int spacing = ((FlowLayout)spec_input.getLayout()).getHgap() + 2;
00075
00076 spec_txt = new JTextField();
00077 submit_btn = new JButton("Submit task");
00078 submit_btn.addActionListener(this);
00079 int remaining = width-(spacing * 3)-submit_btn.getPreferredSize().width;
00080
00081 JScrollPane spec_scroll = new JScrollPane(spec_txt,
00082 ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
00083 ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
00084 int ht = spec_scroll.getPreferredSize().height;
00085 spec_scroll.setPreferredSize(new Dimension(remaining, ht));
00086 spec_input.add(spec_scroll);
00087 spec_input.add(submit_btn);
00088
00089 JLabel spec_label = new JLabel("SENSIX task specification:");
00090 JPanel spec_entry = new JPanel();
00091 spec_entry.setLayout(new BorderLayout(0,0));
00092 spec_entry.add("North", spec_label);
00093 spec_entry.add("Center", spec_input);
00094
00095 results_txt = new JTextArea(10, gui.width/14);
00096 JScrollPane results_scroll = new JScrollPane(results_txt);
00097 results_txt.setEditable(false);
00098 JLabel results_label = new JLabel("Task results:");
00099 JPanel results_out = new JPanel();
00100 results_out.setLayout(new BorderLayout(0,0));
00101 results_out.add("North", results_label);
00102 results_out.add("Center", results_scroll);
00103
00104 add("North", spec_entry);
00105 add("Center", results_out);
00106
00107 setSize(getPreferredSize());
00108 setVisible(true);
00109 }
00110
00111
00112 public void actionPerformed(ActionEvent ae) {
00113 if (ae.getSource() == submit_btn) {
00114 gui.app.out.println(spec_txt.getText());
00115 }
00116 }
00117
00118
00119 public void displayTime(long s) {
00120 long minutes = s / 60000;
00121 long seconds = (s % 60000) / 1000;
00122 String min = "00";
00123 String sec = "00";
00124
00125 if (minutes < 10)
00126 min = "0" + minutes;
00127 else
00128 min = "" + minutes;
00129
00130 if (seconds < 10)
00131 sec = "0" + seconds;
00132 else
00133 sec = "" + seconds;
00134
00135 time_label.setText(min + ":" + sec);
00136 if ((s % 1000) == 0)
00137 gui.refreshTopology();
00138 }
00139
00140 public void displayTime(String s) {
00141 time_label.setText(s);
00142 if (!last_time.equals(s))
00143 gui.refreshTopology();
00144 last_time = s;
00145 }
00146 }