📄 taskconfiguration.java
字号:
/*
* "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-2003 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.
*/
package net.tinyos.task.taskviz;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.awt.geom.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import java.io.File;
import java.io.IOException;
import edu.umd.cs.jazz.*;
import edu.umd.cs.jazz.component.*;
import edu.umd.cs.jazz.event.*;
import edu.umd.cs.jazz.util.*;
import net.tinyos.task.taskapi.*;
/**
*/
public class TASKConfiguration {
public String TAB1TIP = "Use to create queries for the network";
public String LABEL1 = "Data to collect (click or shift-click) ";
public String LABEL2 = "Sample Period (ms) ";
public String LABEL3 = "Enter name to store results as: ";
public String BUTTON1 = "Remove Entry";
public String BUTTON2 = "Clear List";
public String BUTTON3 = "Start Sensor Query";
public String BUTTON4 = "Start Health Query";
public String BUTTON5 = "Stop Sensor Query";
public String BUTTON6 = "Stop Health Query";
public JList list1;
public DefaultListModel clauseListModel;
public JList list2;
public JTextField textfield1;
public JTextField textfield2;
public JTextField textfield3;
public JButton button1;
public JButton button2;
public JButton button3;
public JButton button4;
public JButton button5;
public JButton button6;
public JButton sensorQueryEditButton;
public JButton sensorQuerySubmitButton;
private JFrame parentFrame;
private TASKClient client;
private JPanel parentPanel;
private JRadioButtonMenuItem[] sensorItems = new JRadioButtonMenuItem[20];
Vector atts = new Vector();
Vector aggs = new Vector();
Vector v = new Vector();
public int samplePeriod;
TASKQuery healthConstQuery, sensorQuery, currentQuery, oldQuery;
JTextArea sensorQueryArea;
JTextArea healthQueryArea;
JTextArea currentQueryArea;
DefaultBoundedRangeModel ttlModel;
FollowerRangeModel spModel;
ConversionPanel spPanel;
String configName;
public TASKConfiguration(JFrame parentFrame, TASKClient client, JPanel parentPanel) {
this.parentFrame = parentFrame;
this.client = client;
this.parentPanel = parentPanel;
Vector selectEntries = new Vector();
TASKAttributeInfo tai = client.getAttribute("nodeid");
if (tai != null) {
selectEntries.add(new TASKAttrExpr(tai));
}
else {
System.out.println("attribute nodeid not defined");
}
tai = client.getAttribute("parent");
if (tai != null) {
selectEntries.add(new TASKAttrExpr(tai));
}
else {
System.out.println("attribute parent not defined");
}
tai = client.getAttribute("depth");
if (tai != null) {
selectEntries.add(new TASKAttrExpr(tai));
}
else {
System.out.println("attribute depth not defined");
}
tai = client.getAttribute("qual");
if (tai != null) {
selectEntries.add(new TASKAttrExpr(tai));
}
else {
System.out.println("attribute qual not defined");
}
tai = client.getAttribute("freeram");
if (tai != null) {
selectEntries.add(new TASKAttrExpr(tai));
}
else {
System.out.println("attribute freeram not defined");
}
healthConstQuery = new TASKQuery(selectEntries, new Vector(), 2048, null);
}
/**
* Prepares the frame for the configuration.
*/
public void preparePanel(String cName) {
parentPanel.removeAll();
configName = cName;
// utility classes
Border b = BorderFactory.createBevelBorder(BevelBorder.LOWERED);
///////////////
// tab1
// set up the first tab
BoxLayout bl = new BoxLayout(parentPanel, BoxLayout.Y_AXIS);
parentPanel.setLayout(bl);
///////////////
// panel 1
JPanel panel1 = new JPanel();
panel1.setBorder(b);
panel1.setLayout(new BorderLayout());
JPanel row = new JPanel();
row.setLayout(new BorderLayout());
row.add(new Label(LABEL1), BorderLayout.WEST);
atts = client.getAttributes();
v = new Vector();
for (int i=0; i<atts.size(); i++) {
TASKAttributeInfo info = (TASKAttributeInfo)atts.elementAt(i);
v.addElement(info.name+": "+info.description);
}
aggs = client.getAggregates();
list1 = new JList(v) {
public String getToolTipText(MouseEvent me) {
int index = locationToIndex(me.getPoint());
if (index > -1) {
return ((TASKAttributeInfo)atts.elementAt(index)).description;
}
else {
return null;
}
}
};
list1.setToolTipText("");
list1.setVisibleRowCount(5);
list1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane scrollPane = new JScrollPane(list1);
row.add(scrollPane, BorderLayout.CENTER);
panel1.add(row, BorderLayout.NORTH);
row = new JPanel();
bl = new BoxLayout(row, BoxLayout.X_AXIS);
row.setLayout(bl);
row.add(new Label(LABEL2));
textfield1 = new JTextField("1");
// row.add(textfield1);
ttlModel = new DefaultBoundedRangeModel();
spModel = new FollowerRangeModel(ttlModel,this);
ttlModel.setMinimum(1);
ttlModel.setMaximum(720); //lifetime in days
spModel.setMinimum(1);
spModel.setMaximum(6400); // sample period in ms
ConversionPanel ttlPanel = new ConversionPanel("Time to Live (days)", ttlModel, 15);
spPanel = new ConversionPanel("Sample Period (ms)", spModel, 1084);
JPanel col = new JPanel();
bl = new BoxLayout(col, BoxLayout.Y_AXIS);
col.setLayout(bl);
col.add(row);
row = new JPanel();
bl = new BoxLayout(row, BoxLayout.X_AXIS);
row.setLayout(bl);
row.add(ttlPanel);
row.add(spPanel);
col.add(row);
panel1.add(col, BorderLayout.SOUTH);
//////////////
///////////////
// panel 2
JPanel panel2 = new JPanel();
panel2.setBorder(BorderFactory.createTitledBorder(b,"Editing Sensor Query"));
JPanel column2 = new JPanel();
bl = new BoxLayout(column2, BoxLayout.Y_AXIS);
column2.setLayout(bl);
clauseListModel = new DefaultListModel();
list2 = new JList(clauseListModel);
scrollPane = new JScrollPane(list2);
currentQueryArea = new JTextArea(3,40);
currentQueryArea.setEditable(false);
currentQueryArea.setText("English version of edited query here");
column2.add(scrollPane);
column2.add(currentQueryArea);
JPanel column = new JPanel();
bl = new BoxLayout(column, BoxLayout.Y_AXIS);
column.setLayout(bl);
button1 = new JButton(BUTTON1);
button1.setActionCommand(BUTTON1);
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
int index = list2.getSelectedIndex();
if (index >= 0) {
clauseListModel.remove(index);
int size = clauseListModel.getSize();
if (size == 0){
button1.setEnabled(false);
button2.setEnabled(false);
}
else {
if (index == clauseListModel.getSize()) {
index --;
}
else {
list2.setSelectedIndex(index);
}
}
currentQuery = createQuery(clauseListModel);
currentQueryArea.setText(currentQuery.toSQL());
}
}
});
button2 = new JButton(BUTTON2);
button2.setActionCommand(BUTTON2);
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
clauseListModel.clear();
button1.setEnabled(false);
button2.setEnabled(false);
currentQueryArea.setText("");
}
});
sensorQuerySubmitButton = new JButton("Submit Query");
sensorQuerySubmitButton.setActionCommand("Submit Query");
sensorQuerySubmitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
try {
samplePeriod = spPanel.getValue();
} catch (NumberFormatException nfe) {
JOptionPane.showMessageDialog(parentFrame, "Sample period must be of type integer", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (clauseListModel.size() > 0) {
currentQuery.setSamplePeriod(samplePeriod);
sensorQuery = currentQuery;
currentQueryArea.setText(sensorQuery.toSQL());
sensorQueryArea.setText(sensorQuery.toSQL());
sensorQueryEditButton.setEnabled(true);
button3.setEnabled(true);
button3.setText("Start Sensor Query");
}
}
});
column.add(button1);
column.add(button2);
column.add(sensorQuerySubmitButton);
panel2.add(column2, BorderLayout.CENTER);
panel2.add(column, BorderLayout.EAST);
///////////////
JPanel panel6 = new JPanel();
panel6.setBorder(BorderFactory.createTitledBorder(b,"Current Sensor Query"));
sensorQueryArea = new JTextArea(3,30);
sensorQueryArea.setEditable(false);
sensorQueryEditButton = new JButton("Edit");
sensorQueryEditButton.setEnabled(false);
panel6.add(sensorQueryArea);
panel6.add(sensorQueryEditButton);
sensorQueryEditButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
clauseListModel.clear();
Vector selects = sensorQuery.getSelectEntries();
for (int i=0; i<selects.size(); i++) {
Clause c = new Clause((TASKExpr)selects.elementAt(i));
clauseListModel.addElement(c);
}
Vector predicates = sensorQuery.getPredicates();
for (int i=0; i<predicates.size(); i++) {
Clause c = new Clause((TASKOperExpr)predicates.elementAt(i));
clauseListModel.addElement(c);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -