- private ArrayList motes = new ArrayList();
- private ArrayList colors = new ArrayList();
-
- /* Initial mote colors cycle through this list. Add more colors if
- you want. */
- private Color[] cycle = {
- Color.RED, Color.WHITE, Color.GREEN, Color.MAGENTA,
- Color.YELLOW, Color.GRAY, Color.YELLOW
- };
- int cycleIndex;
-
- /* TableModel methods for achieving our table appearance */
- public String getColumnName(int col) {
- if (col == 0)
- return "Mote";
- else
- return "Color";
- }
- public int getColumnCount() { return 2; }
- public synchronized int getRowCount() { return motes.size(); }
- public synchronized Object getValueAt(int row, int col) {
- if (col == 0)
- return motes.get(row);
- else
- return colors.get(row);
- }
+ private ArrayList motes = new ArrayList();
+ private ArrayList colors = new ArrayList();
+
+ /* Initial mote colors cycle through this list. Add more colors if
+ you want. */
+ private Color[] cycle = {
+ Color.RED, Color.WHITE, Color.GREEN, Color.MAGENTA,
+ Color.YELLOW, Color.GRAY, Color.YELLOW
+ };
+ int cycleIndex;
+
+ /* TableModel methods for achieving our table appearance */
+ public String getColumnName(int col) {
+ if (col == 0) {
+ return "Mote";
+ }
+ else {
+ return "Color";
+ }
+ }
+ public int getColumnCount() { return 2; }
+ public synchronized int getRowCount() { return motes.size(); }
+ public synchronized Object getValueAt(int row, int col) {
+ if (col == 0) {
+ return motes.get(row);
+ }
+ else {
+ return colors.get(row);
+ }
+ }
- /* Return mote id of i'th mote */
- int get(int i) { return ((Integer)motes.get(i)).intValue(); }
-
- /* Return color of i'th mote */
- Color getColor(int i) { return (Color)colors.get(i); }
-
- /* Return number of motes */
- int size() { return motes.size(); }
-
- /* Add a new mote */
- synchronized void newNode(int nodeId) {
- /* Shock, horror. No binary search. */
- int i, len = motes.size();
-
- for (i = 0; ; i++)
- if (i == len || nodeId < get(i)) {
- motes.add(i, new Integer(nodeId));
- // Cycle through a set of initial colors
- colors.add(i, cycle[cycleIndex++ % cycle.length]);
- break;
- }
- fireTableRowsInserted(i, i);
- }
-
- /* Remove all motes */
- void clear() {
- motes = new ArrayList();
- colors = new ArrayList();
- fireTableDataChanged();
- }
+ /* Return mote id of i'th mote */
+ int get(int i) { return ((Integer)motes.get(i)).intValue(); }
+
+ /* Return color of i'th mote */
+ Color getColor(int i) { return (Color)colors.get(i); }
+
+ /* Return number of motes */
+ int size() { return motes.size(); }
+
+ /* Add a new mote */
+ synchronized void newNode(int nodeId) {
+ /* Shock, horror. No binary search. */
+ int i, len = motes.size();
+
+ for (i = 0; ; i++)
+ if (i == len || nodeId < get(i)) {
+ motes.add(i, new Integer(nodeId));
+ // Cycle through a set of initial colors
+ colors.add(i, cycle[cycleIndex++ % cycle.length]);
+ break;
+ }
+ fireTableRowsInserted(i, i);
+ }
+
+ /* Remove all motes */
+ void clear() {
+ motes = new ArrayList();
+ colors = new ArrayList();
+ fireTableDataChanged();
+ }
- JPanel main = new JPanel(new BorderLayout());
-
- main.setMinimumSize(new Dimension(500, 250));
- main.setPreferredSize(new Dimension(800, 400));
-
- // Three panels: mote list, graph, controls
- moteListModel = new MoteTableModel();
- JTable moteList = new JTable(moteListModel);
- moteList.setDefaultRenderer(Color.class, new MoteColor());
- moteList.setDefaultEditor(Color.class, new ColorCellEditor("Pick Mote Color"));
- moteList.setPreferredScrollableViewportSize(new Dimension(100, 400));
- JScrollPane motePanel = new JScrollPane();
- motePanel.getViewport().add(moteList, null);
- main.add(motePanel, BorderLayout.WEST);
-
- graph = new Graph(this);
- main.add(graph, BorderLayout.CENTER);
-
- // Controls. Organised using box layouts.
-
- // Sample period.
- JLabel sampleLabel = makeLabel("Sample period (ms):", JLabel.RIGHT);
- sampleText = makeTextField(6, new ActionListener() {
- public void actionPerformed(ActionEvent e) { setSamplePeriod(); }
- } );
- updateSamplePeriod();
-
- // Clear data.
- JButton clearButton = makeButton("Clear data", new ActionListener() {
- public void actionPerformed(ActionEvent e) { clearData(); }
- } );
-
- // Adjust X-axis zoom.
- Box xControl = new Box(BoxLayout.Y_AXIS);
- xLabel = makeLabel("", JLabel.CENTER);
- final JSlider xSlider = new JSlider(JSlider.HORIZONTAL, 0, 8, graph.scale);
- Hashtable xTable = new Hashtable();
- for (int i = 0; i <= 8; i += 2)
- xTable.put(new Integer(i),
- makeSmallLabel("" + (Graph.MIN_WIDTH << i),
- JLabel.CENTER));
- xSlider.setLabelTable(xTable);
- xSlider.setPaintLabels(true);
- graph.updateXLabel();
- graph.setScale(graph.scale);
- xSlider.addChangeListener(new ChangeListener() {
- public void stateChanged(ChangeEvent e) {
- //if (!xSlider.getValueIsAdjusting())
- graph.setScale((int)xSlider.getValue());
- }
- });
- xControl.add(xLabel);
- xControl.add(xSlider);
-
- // Adjust Y-axis range.
- JLabel yLabel = makeLabel("Y:", JLabel.RIGHT);
- yText = makeTextField(12, new ActionListener() {
- public void actionPerformed(ActionEvent e) { setYAxis(); }
- } );
- yText.setText(graph.gy0 + " - " + graph.gy1);
-
- Box controls = new Box(BoxLayout.X_AXIS);
- controls.add(clearButton);
- controls.add(Box.createHorizontalGlue());
- controls.add(Box.createRigidArea(new Dimension(20, 0)));
- controls.add(sampleLabel);
- controls.add(sampleText);
- controls.add(Box.createHorizontalGlue());
- controls.add(Box.createRigidArea(new Dimension(20, 0)));
- controls.add(xControl);
- controls.add(yLabel);
- controls.add(yText);
- main.add(controls, BorderLayout.SOUTH);
-
- // The frame part
- frame = new JFrame("Oscilloscope");
- frame.setSize(main.getPreferredSize());
- frame.getContentPane().add(main);
- frame.setVisible(true);
- frame.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) { System.exit(0); }
- });
+ JPanel main = new JPanel(new BorderLayout());
+
+ main.setMinimumSize(new Dimension(500, 250));
+ main.setPreferredSize(new Dimension(800, 400));
+
+ // Three panels: mote list, graph, controls
+ moteListModel = new MoteTableModel();
+ JTable moteList = new JTable(moteListModel);
+ moteList.setDefaultRenderer(Color.class, new MoteColor());
+ moteList.setDefaultEditor(Color.class, new ColorCellEditor("Pick Mote Color"));
+ moteList.setPreferredScrollableViewportSize(new Dimension(100, 400));
+ JScrollPane motePanel = new JScrollPane();
+ motePanel.getViewport().add(moteList, null);
+ main.add(motePanel, BorderLayout.WEST);
+
+ graph = new Graph(this);
+ main.add(graph, BorderLayout.CENTER);
+
+ // Controls. Organised using box layouts.
+
+ // Sample period.
+ JLabel sampleLabel = makeLabel("Sample period (ms):", JLabel.RIGHT);
+ sampleText = makeTextField(6, new ActionListener() {
+ public void actionPerformed(ActionEvent e) { setSamplePeriod(); }
+ } );
+ updateSamplePeriod();
+
+ // Clear data.
+ JButton clearButton = makeButton("Clear data", new ActionListener() {
+ public void actionPerformed(ActionEvent e) { clearData(); }
+ } );
+
+ // Adjust X-axis zoom.
+ Box xControl = new Box(BoxLayout.Y_AXIS);
+ xLabel = makeLabel("", JLabel.CENTER);
+ final JSlider xSlider = new JSlider(JSlider.HORIZONTAL, 0, 8, graph.scale);
+ Hashtable xTable = new Hashtable();
+ for (int i = 0; i <= 8; i += 2)
+ xTable.put(new Integer(i),
+ makeSmallLabel("" + (Graph.MIN_WIDTH << i),
+ JLabel.CENTER));
+ xSlider.setLabelTable(xTable);
+ xSlider.setPaintLabels(true);
+ graph.updateXLabel();
+ graph.setScale(graph.scale);
+ xSlider.addChangeListener(new ChangeListener() {
+ public void stateChanged(ChangeEvent e) {
+ //if (!xSlider.getValueIsAdjusting())
+ graph.setScale((int)xSlider.getValue());
+ }
+ });
+ xControl.add(xLabel);
+ xControl.add(xSlider);
+
+ // Adjust Y-axis range.
+ JLabel yLabel = makeLabel("Y:", JLabel.RIGHT);
+ yText = makeTextField(12, new ActionListener() {
+ public void actionPerformed(ActionEvent e) { setYAxis(); }
+ } );
+ yText.setText(graph.gy0 + " - " + graph.gy1);
+
+ Box controls = new Box(BoxLayout.X_AXIS);
+ controls.add(clearButton);
+ controls.add(Box.createHorizontalGlue());
+ controls.add(Box.createRigidArea(new Dimension(20, 0)));
+ controls.add(sampleLabel);
+ controls.add(sampleText);
+ controls.add(Box.createHorizontalGlue());
+ controls.add(Box.createRigidArea(new Dimension(20, 0)));
+ controls.add(xControl);
+ controls.add(yLabel);
+ controls.add(yText);
+ main.add(controls, BorderLayout.SOUTH);
+
+ // The frame part
+ frame = new JFrame("Oscilloscope");
+ frame.setSize(main.getPreferredSize());
+ frame.getContentPane().add(main);
+ frame.setVisible(true);
+ frame.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) { System.exit(0); }
+ });