]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
start to gui
authoridgay <idgay>
Wed, 4 Apr 2007 21:01:11 +0000 (21:01 +0000)
committeridgay <idgay>
Wed, 4 Apr 2007 21:01:11 +0000 (21:01 +0000)
apps/AntiTheft/java/AntiTheftGui.java [new file with mode: 0644]
apps/AntiTheft/java/BagPanel.java [new file with mode: 0644]
apps/AntiTheft/java/Makefile [new file with mode: 0644]
apps/AntiTheft/java/run [new file with mode: 0755]

diff --git a/apps/AntiTheft/java/AntiTheftGui.java b/apps/AntiTheft/java/AntiTheftGui.java
new file mode 100644 (file)
index 0000000..1fd12a5
--- /dev/null
@@ -0,0 +1,134 @@
+// $Id$
+
+/*                                                                     tab:4
+ * "Copyright (c) 2000-2003 The Regents of the University  of California.  
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ * 
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ * Copyright (c) 2002-2007 Intel Corporation
+ * All rights reserved.
+ *
+ * This file is distributed under the terms in the attached INTEL-LICENSE     
+ * file. If you do not find these files, copies can be found by writing to
+ * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, 
+ * 94704.  Attention:  Intel License Inquiry.
+ */
+
+
+/**
+ * Description:
+ * The GUI for the AntiTheft application.
+ *
+ * @author Bret Hull
+ * @author David Gay
+ */
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+import net.tinyos.packet.*;
+
+public class AntiTheftGui {
+    JTextArea mssgArea;
+    JTextField fieldInterval;
+    JCheckBox detDarkCb, detAccelCb, repLedCb, repSirenCb, repServerCb,
+       repNeighboursCb;
+
+    public AntiTheftGui() {
+       try {
+           guiInit();
+       }
+       catch(Exception e) {
+           e.printStackTrace();
+           System.exit(2);
+       }
+    }
+
+    private void guiInit() throws Exception {
+       JPanel mainPanel = new JPanel(new BorderLayout());
+       mainPanel.setMinimumSize(new Dimension(500, 250));
+       mainPanel.setPreferredSize(new Dimension(500, 300));
+
+       JScrollPane mssgPanel = new JScrollPane();
+       mssgPanel.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
+       mssgPanel.setAutoscrolls(true);
+       mssgArea = new JTextArea();
+       mssgArea.setFont(new java.awt.Font("Monospaced", Font.PLAIN, 20));
+       mainPanel.add(mssgPanel, BorderLayout.CENTER);
+       mssgPanel.getViewport().add(mssgArea, null);
+       
+       BagPanel buttonPanel = new BagPanel();
+       GridBagConstraints c = buttonPanel.c;
+
+       c.fill = GridBagConstraints.HORIZONTAL;
+       c.gridwidth = GridBagConstraints.REMAINDER;
+
+       buttonPanel.makeLabel("Detection", JLabel.CENTER);
+       c.gridwidth = GridBagConstraints.RELATIVE;
+       detDarkCb = buttonPanel.makeCheckBox("Dark", true);
+       c.gridwidth = GridBagConstraints.REMAINDER;
+       detAccelCb = buttonPanel.makeCheckBox("Movement", false);
+       buttonPanel.addSeparator(SwingConstants.HORIZONTAL);
+
+
+       buttonPanel.makeLabel("Theft Reports", JLabel.CENTER);
+       c.gridwidth = GridBagConstraints.RELATIVE;
+       repLedCb = buttonPanel.makeCheckBox("LED", true);
+       c.gridwidth = GridBagConstraints.REMAINDER;
+       repSirenCb = buttonPanel.makeCheckBox("Siren", false);
+       c.gridwidth = GridBagConstraints.RELATIVE;
+       repServerCb = buttonPanel.makeCheckBox("Server", false);
+       c.gridwidth = GridBagConstraints.REMAINDER;
+       repNeighboursCb = buttonPanel.makeCheckBox("Neighbours", false);
+       buttonPanel.addSeparator(SwingConstants.HORIZONTAL);
+
+       buttonPanel.makeLabel("Interval", JLabel.CENTER);
+       fieldInterval = buttonPanel.makeTextField(10, null);
+       fieldInterval.setText(Integer.toString(Constants.DEFAULT_CHECK_INTERVAL));
+
+       // Send settings button
+       ActionListener settingsAction = new ActionListener() {
+               public void actionPerformed(ActionEvent e) {
+                   updateSettings();
+               }
+           };
+       buttonPanel.makeButton("Update", settingsAction);
+
+       mainPanel.add(buttonPanel, BorderLayout.EAST);
+
+       // The frame part
+       JFrame frame = new JFrame("AntiTheft");
+       frame.setSize(mainPanel.getPreferredSize());
+       frame.getContentPane().add(mainPanel);
+       frame.setVisible(true);
+       frame.addWindowListener(new WindowAdapter() {
+               public void windowClosing(WindowEvent e) { System.exit(0); }
+           });
+    }
+
+    public synchronized void theft(String mssg) {
+       mssgArea.append(mssg + "\n");
+       mssgArea.setCaretPosition(mssgArea.getDocument().getLength());
+    }
+
+    public void updateSettings() { }
+
+    public static void main(String[] args) {
+       AntiTheftGui me = new AntiTheftGui();
+    }
+}
diff --git a/apps/AntiTheft/java/BagPanel.java b/apps/AntiTheft/java/BagPanel.java
new file mode 100644 (file)
index 0000000..20e340a
--- /dev/null
@@ -0,0 +1,80 @@
+// $Id$
+
+/*                                                                     tab:4
+ * Copyright (c) 2007 Intel Corporation
+ * All rights reserved.
+ *
+ * This file is distributed under the terms in the attached INTEL-LICENSE     
+ * file. If you do not find these files, copies can be found by writing to
+ * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, 
+ * 94704.  Attention:  Intel License Inquiry.
+ */
+
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+
+/**
+ * A GridBagLayout based panel with convenience methods for 
+ * making various swing items. These methods also ensure a
+ * consistent appearance.
+ *
+ * @author David Gay
+ */
+public class BagPanel extends JPanel {
+    Font boldFont = new Font("Dialog", Font.BOLD, 12);
+    Font normalFont = new Font("Dialog", Font.PLAIN, 12);
+
+    GridBagLayout bag;
+    GridBagConstraints c;
+
+    public BagPanel() {
+       bag = new GridBagLayout();
+       setLayout(bag);
+       c = new GridBagConstraints();
+    }
+
+    public JButton makeButton(String label, ActionListener action) {
+       JButton button = new JButton();
+        button.setText(label);
+        button.setFont(boldFont);
+       button.addActionListener(action);
+       bag.setConstraints(button, c);
+       add(button);
+       return button;
+    }
+
+    public JCheckBox makeCheckBox(String label, boolean selected) {
+       JCheckBox box = new JCheckBox(label, selected);
+       box.setFont(normalFont);
+       bag.setConstraints(box, c);
+       add(box);
+       return box;
+    }
+
+    public JLabel makeLabel(String txt, int alignment) {
+       JLabel label = new JLabel(txt, alignment);
+       label.setFont(boldFont);
+       bag.setConstraints(label, c);
+       add(label);
+       return label;
+    }
+
+    public JTextField makeTextField(int columns, ActionListener action) {
+       JTextField tf = new JTextField(columns);
+       tf.setFont(normalFont);
+       tf.setMaximumSize(tf.getPreferredSize());
+       tf.addActionListener(action);
+       bag.setConstraints(tf, c);
+       add(tf);
+       return tf;
+    }
+
+    public void addSeparator(int axis) {
+       JSeparator sep = new JSeparator(axis);
+       bag.setConstraints(sep, c);
+       add(sep);
+    }
+
+}
diff --git a/apps/AntiTheft/java/Makefile b/apps/AntiTheft/java/Makefile
new file mode 100644 (file)
index 0000000..00cb3dd
--- /dev/null
@@ -0,0 +1,26 @@
+GEN=SettingsMsg.java AlertMsg.java Constants.java
+
+ANTITHEFT_H=../Nodes/antitheft.h
+
+all: antitheft.jar
+
+antitheft.jar: AntiTheftGui.class
+       jar cf $@ *.class
+
+SettingsMsg.java: $(ANTITHEFT_H)
+       mig -target=null -java-classname=SettingsMsg java $(ANTITHEFT_H) settings -o $@
+
+AlertMsg.java: $(ANTITHEFT_H)
+       mig -target=null -java-classname=AlertMsg java $(ANTITHEFT_H) alert -o $@
+
+Constants.java: $(ANTITHEFT_H)
+       ncg -target=null -java-classname=Constants java $(ANTITHEFT_H) antitheft.h -o $@
+
+AntiTheftGui.class: $(wildcard *.java) $(GEN)
+       javac *.java
+
+clean:
+       rm -f *.class $(GEN)
+
+veryclean: clean
+       rm antitheft.jar
diff --git a/apps/AntiTheft/java/run b/apps/AntiTheft/java/run
new file mode 100755 (executable)
index 0000000..a60c253
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+if cygpath -w / >/dev/null 2>/dev/null; then
+  CLASSPATH="antitheft.jar;$CLASSPATH"
+else
+  CLASSPATH="antitheft.jar:$CLASSPATH"
+fi
+java AntiTheftGui