[cooja] plugins/VariableWatcher: Added Combo as name suffix for JComboBoxes
This commit is contained in:
parent
a9f31ee662
commit
6ae097cc09
|
@ -1,4 +1,5 @@
|
||||||
/*
|
/*
|
||||||
|
* Copyright (c) 2014, TU Braunschweig.
|
||||||
* Copyright (c) 2009, Swedish Institute of Computer Science.
|
* Copyright (c) 2009, Swedish Institute of Computer Science.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
|
@ -83,6 +84,7 @@ import org.contikios.cooja.mote.memory.VarMemory;
|
||||||
* User can also see which variables seems to be available on the selected node.
|
* User can also see which variables seems to be available on the selected node.
|
||||||
*
|
*
|
||||||
* @author Fredrik Osterlind
|
* @author Fredrik Osterlind
|
||||||
|
* @author Enrico Jorns
|
||||||
*/
|
*/
|
||||||
@ClassDescription("Variable Watcher")
|
@ClassDescription("Variable Watcher")
|
||||||
@PluginType(PluginType.MOTE_PLUGIN)
|
@PluginType(PluginType.MOTE_PLUGIN)
|
||||||
|
@ -102,8 +104,8 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
|
||||||
private JPanel lengthPane;
|
private JPanel lengthPane;
|
||||||
private JPanel valuePane;
|
private JPanel valuePane;
|
||||||
private JPanel charValuePane;
|
private JPanel charValuePane;
|
||||||
private JComboBox varName;
|
private JComboBox varNameCombo;
|
||||||
private JComboBox varType;
|
private JComboBox varTypeCombo;
|
||||||
private JFormattedTextField[] varValues;
|
private JFormattedTextField[] varValues;
|
||||||
private JTextField[] charValues;
|
private JTextField[] charValues;
|
||||||
private JFormattedTextField varLength;
|
private JFormattedTextField varLength;
|
||||||
|
@ -141,17 +143,17 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
|
||||||
label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT));
|
label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT));
|
||||||
smallPane.add(BorderLayout.WEST, label);
|
smallPane.add(BorderLayout.WEST, label);
|
||||||
|
|
||||||
varName = new JComboBox();
|
varNameCombo = new JComboBox();
|
||||||
varName.setEditable(true);
|
varNameCombo.setEditable(true);
|
||||||
varName.setSelectedItem("[enter or pick name]");
|
varNameCombo.setSelectedItem("[enter or pick name]");
|
||||||
|
|
||||||
List<String> allPotentialVarNames = new ArrayList<>(moteMemory.getVariableNames());
|
List<String> allPotentialVarNames = new ArrayList<>(moteMemory.getVariableNames());
|
||||||
Collections.sort(allPotentialVarNames);
|
Collections.sort(allPotentialVarNames);
|
||||||
for (String aVarName: allPotentialVarNames) {
|
for (String aVarName: allPotentialVarNames) {
|
||||||
varName.addItem(aVarName);
|
varNameCombo.addItem(aVarName);
|
||||||
}
|
}
|
||||||
|
|
||||||
varName.addKeyListener(new KeyListener() {
|
varNameCombo.addKeyListener(new KeyListener() {
|
||||||
@Override
|
@Override
|
||||||
public void keyPressed(KeyEvent e) {
|
public void keyPressed(KeyEvent e) {
|
||||||
writeButton.setEnabled(false);
|
writeButton.setEnabled(false);
|
||||||
|
@ -166,7 +168,7 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
smallPane.add(BorderLayout.EAST, varName);
|
smallPane.add(BorderLayout.EAST, varNameCombo);
|
||||||
mainPane.add(smallPane);
|
mainPane.add(smallPane);
|
||||||
|
|
||||||
// Variable type
|
// Variable type
|
||||||
|
@ -175,16 +177,16 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
|
||||||
label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT));
|
label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT));
|
||||||
smallPane.add(BorderLayout.WEST, label);
|
smallPane.add(BorderLayout.WEST, label);
|
||||||
|
|
||||||
varType = new JComboBox();
|
varTypeCombo = new JComboBox();
|
||||||
varType.addItem("Byte (1 byte)"); // BYTE_INDEX = 0
|
varTypeCombo.addItem("Byte (1 byte)"); // BYTE_INDEX = 0
|
||||||
varType.addItem("Integer (" + moteToView.getMemory().getLayout().intSize + " bytes)"); // INT_INDEX = 1
|
varTypeCombo.addItem("Integer (" + moteToView.getMemory().getLayout().intSize + " bytes)"); // INT_INDEX = 1
|
||||||
varType.addItem("Byte array (x bytes)"); // ARRAY_INDEX = 2
|
varTypeCombo.addItem("Byte array (x bytes)"); // ARRAY_INDEX = 2
|
||||||
varType.addItem("Char array (x bytes)"); // CHAR_ARRAY_INDEX = 3
|
varTypeCombo.addItem("Char array (x bytes)"); // CHAR_ARRAY_INDEX = 3
|
||||||
|
|
||||||
varType.addActionListener(new ActionListener() {
|
varTypeCombo.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
int selectedIndex = varType.getSelectedIndex();
|
int selectedIndex = varTypeCombo.getSelectedIndex();
|
||||||
if (selectedIndex == ARRAY_INDEX || selectedIndex == CHAR_ARRAY_INDEX) {
|
if (selectedIndex == ARRAY_INDEX || selectedIndex == CHAR_ARRAY_INDEX) {
|
||||||
lengthPane.setVisible(true);
|
lengthPane.setVisible(true);
|
||||||
setNumberOfValues(((Number) varLength.getValue()).intValue());
|
setNumberOfValues(((Number) varLength.getValue()).intValue());
|
||||||
|
@ -205,7 +207,7 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
smallPane.add(BorderLayout.EAST, varType);
|
smallPane.add(BorderLayout.EAST, varTypeCombo);
|
||||||
mainPane.add(smallPane);
|
mainPane.add(smallPane);
|
||||||
|
|
||||||
/* The recommended fix for the bug #4740914
|
/* The recommended fix for the bug #4740914
|
||||||
|
@ -238,7 +240,7 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
|
||||||
@Override
|
@Override
|
||||||
public void propertyChange(PropertyChangeEvent e) {
|
public void propertyChange(PropertyChangeEvent e) {
|
||||||
setNumberOfValues(((Number) varLength.getValue()).intValue());
|
setNumberOfValues(((Number) varLength.getValue()).intValue());
|
||||||
if(varType.getSelectedIndex() == CHAR_ARRAY_INDEX) {
|
if(varTypeCombo.getSelectedIndex() == CHAR_ARRAY_INDEX) {
|
||||||
setNumberOfCharValues(((Number) varLength.getValue()).intValue());
|
setNumberOfCharValues(((Number) varLength.getValue()).intValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -400,45 +402,45 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
|
||||||
button.addActionListener(new ActionListener() {
|
button.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (varType.getSelectedIndex() == BYTE_INDEX) {
|
if (varTypeCombo.getSelectedIndex() == BYTE_INDEX) {
|
||||||
try {
|
try {
|
||||||
byte val = moteMemory.getByteValueOf((String) varName.getSelectedItem());
|
byte val = moteMemory.getByteValueOf((String) varNameCombo.getSelectedItem());
|
||||||
varValues[0].setValue(new Integer(0xFF & val));
|
varValues[0].setValue(new Integer(0xFF & val));
|
||||||
varName.setBackground(Color.WHITE);
|
varNameCombo.setBackground(Color.WHITE);
|
||||||
writeButton.setEnabled(true);
|
writeButton.setEnabled(true);
|
||||||
} catch (UnknownVariableException ex) {
|
} catch (UnknownVariableException ex) {
|
||||||
varName.setBackground(Color.RED);
|
varNameCombo.setBackground(Color.RED);
|
||||||
writeButton.setEnabled(false);
|
writeButton.setEnabled(false);
|
||||||
}
|
}
|
||||||
} else if (varType.getSelectedIndex() == INT_INDEX) {
|
} else if (varTypeCombo.getSelectedIndex() == INT_INDEX) {
|
||||||
try {
|
try {
|
||||||
int val = moteMemory.getIntValueOf((String) varName.getSelectedItem());
|
int val = moteMemory.getIntValueOf((String) varNameCombo.getSelectedItem());
|
||||||
varValues[0].setValue(new Integer(val));
|
varValues[0].setValue(new Integer(val));
|
||||||
varName.setBackground(Color.WHITE);
|
varNameCombo.setBackground(Color.WHITE);
|
||||||
writeButton.setEnabled(true);
|
writeButton.setEnabled(true);
|
||||||
} catch (UnknownVariableException ex) {
|
} catch (UnknownVariableException ex) {
|
||||||
varName.setBackground(Color.RED);
|
varNameCombo.setBackground(Color.RED);
|
||||||
writeButton.setEnabled(false);
|
writeButton.setEnabled(false);
|
||||||
}
|
}
|
||||||
} else if (varType.getSelectedIndex() == ARRAY_INDEX ||
|
} else if (varTypeCombo.getSelectedIndex() == ARRAY_INDEX ||
|
||||||
varType.getSelectedIndex() == CHAR_ARRAY_INDEX) {
|
varTypeCombo.getSelectedIndex() == CHAR_ARRAY_INDEX) {
|
||||||
try {
|
try {
|
||||||
int length = ((Number) varLength.getValue()).intValue();
|
int length = ((Number) varLength.getValue()).intValue();
|
||||||
byte[] vals = moteMemory.getByteArray((String) varName.getSelectedItem(), length);
|
byte[] vals = moteMemory.getByteArray((String) varNameCombo.getSelectedItem(), length);
|
||||||
for (int i=0; i < length; i++) {
|
for (int i=0; i < length; i++) {
|
||||||
varValues[i].setValue(new Integer(0xFF & vals[i]));
|
varValues[i].setValue(new Integer(0xFF & vals[i]));
|
||||||
}
|
}
|
||||||
if(varType.getSelectedIndex() == CHAR_ARRAY_INDEX) {
|
if(varTypeCombo.getSelectedIndex() == CHAR_ARRAY_INDEX) {
|
||||||
for (int i=0; i < length; i++) {
|
for (int i=0; i < length; i++) {
|
||||||
char ch = (char)(0xFF & vals[i]);
|
char ch = (char)(0xFF & vals[i]);
|
||||||
charValues[i].setText(Character.toString(ch));
|
charValues[i].setText(Character.toString(ch));
|
||||||
varValues[i].addKeyListener(varValueKeyListener);
|
varValues[i].addKeyListener(varValueKeyListener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
varName.setBackground(Color.WHITE);
|
varNameCombo.setBackground(Color.WHITE);
|
||||||
writeButton.setEnabled(true);
|
writeButton.setEnabled(true);
|
||||||
} catch (UnknownVariableException ex) {
|
} catch (UnknownVariableException ex) {
|
||||||
varName.setBackground(Color.RED);
|
varNameCombo.setBackground(Color.RED);
|
||||||
writeButton.setEnabled(false);
|
writeButton.setEnabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -450,24 +452,24 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
|
||||||
button.addActionListener(new ActionListener() {
|
button.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (varType.getSelectedIndex() == BYTE_INDEX) {
|
if (varTypeCombo.getSelectedIndex() == BYTE_INDEX) {
|
||||||
try {
|
try {
|
||||||
byte val = (byte) ((Number) varValues[0].getValue()).intValue();
|
byte val = (byte) ((Number) varValues[0].getValue()).intValue();
|
||||||
moteMemory.setByteValueOf((String) varName.getSelectedItem(), val);
|
moteMemory.setByteValueOf((String) varNameCombo.getSelectedItem(), val);
|
||||||
varName.setBackground(Color.WHITE);
|
varNameCombo.setBackground(Color.WHITE);
|
||||||
} catch (UnknownVariableException ex) {
|
} catch (UnknownVariableException ex) {
|
||||||
varName.setBackground(Color.RED);
|
varNameCombo.setBackground(Color.RED);
|
||||||
}
|
}
|
||||||
} else if (varType.getSelectedIndex() == INT_INDEX) {
|
} else if (varTypeCombo.getSelectedIndex() == INT_INDEX) {
|
||||||
try {
|
try {
|
||||||
int val = ((Number) varValues[0].getValue()).intValue();
|
int val = ((Number) varValues[0].getValue()).intValue();
|
||||||
moteMemory.setIntValueOf((String) varName.getSelectedItem(), val);
|
moteMemory.setIntValueOf((String) varNameCombo.getSelectedItem(), val);
|
||||||
varName.setBackground(Color.WHITE);
|
varNameCombo.setBackground(Color.WHITE);
|
||||||
} catch (UnknownVariableException ex) {
|
} catch (UnknownVariableException ex) {
|
||||||
varName.setBackground(Color.RED);
|
varNameCombo.setBackground(Color.RED);
|
||||||
}
|
}
|
||||||
} else if (varType.getSelectedIndex() == ARRAY_INDEX ||
|
} else if (varTypeCombo.getSelectedIndex() == ARRAY_INDEX ||
|
||||||
varType.getSelectedIndex() == CHAR_ARRAY_INDEX) {
|
varTypeCombo.getSelectedIndex() == CHAR_ARRAY_INDEX) {
|
||||||
try {
|
try {
|
||||||
int length = ((Number) varLength.getValue()).intValue();
|
int length = ((Number) varLength.getValue()).intValue();
|
||||||
byte[] vals = new byte[length];
|
byte[] vals = new byte[length];
|
||||||
|
@ -475,11 +477,11 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
|
||||||
vals[i] = (byte) ((Number) varValues[i].getValue()).intValue();
|
vals[i] = (byte) ((Number) varValues[i].getValue()).intValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
moteMemory.setByteArray((String) varName.getSelectedItem(), vals);
|
moteMemory.setByteArray((String) varNameCombo.getSelectedItem(), vals);
|
||||||
varName.setBackground(Color.WHITE);
|
varNameCombo.setBackground(Color.WHITE);
|
||||||
writeButton.setEnabled(true);
|
writeButton.setEnabled(true);
|
||||||
} catch (UnknownVariableException ex) {
|
} catch (UnknownVariableException ex) {
|
||||||
varName.setBackground(Color.RED);
|
varNameCombo.setBackground(Color.RED);
|
||||||
writeButton.setEnabled(false);
|
writeButton.setEnabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -542,26 +544,26 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
|
||||||
|
|
||||||
// Selected variable name
|
// Selected variable name
|
||||||
element = new Element("varname");
|
element = new Element("varname");
|
||||||
element.setText((String) varName.getSelectedItem());
|
element.setText((String) varNameCombo.getSelectedItem());
|
||||||
config.add(element);
|
config.add(element);
|
||||||
|
|
||||||
// Selected variable type
|
// Selected variable type
|
||||||
if (varType.getSelectedIndex() == BYTE_INDEX) {
|
if (varTypeCombo.getSelectedIndex() == BYTE_INDEX) {
|
||||||
element = new Element("vartype");
|
element = new Element("vartype");
|
||||||
element.setText("byte");
|
element.setText("byte");
|
||||||
config.add(element);
|
config.add(element);
|
||||||
} else if (varType.getSelectedIndex() == INT_INDEX) {
|
} else if (varTypeCombo.getSelectedIndex() == INT_INDEX) {
|
||||||
element = new Element("vartype");
|
element = new Element("vartype");
|
||||||
element.setText("int");
|
element.setText("int");
|
||||||
config.add(element);
|
config.add(element);
|
||||||
} else if (varType.getSelectedIndex() == ARRAY_INDEX) {
|
} else if (varTypeCombo.getSelectedIndex() == ARRAY_INDEX) {
|
||||||
element = new Element("vartype");
|
element = new Element("vartype");
|
||||||
element.setText("array");
|
element.setText("array");
|
||||||
config.add(element);
|
config.add(element);
|
||||||
element = new Element("array_length");
|
element = new Element("array_length");
|
||||||
element.setText(varLength.getValue().toString());
|
element.setText(varLength.getValue().toString());
|
||||||
config.add(element);
|
config.add(element);
|
||||||
} else if (varType.getSelectedIndex() == CHAR_ARRAY_INDEX) {
|
} else if (varTypeCombo.getSelectedIndex() == CHAR_ARRAY_INDEX) {
|
||||||
element = new Element("vartype");
|
element = new Element("vartype");
|
||||||
element.setText("chararray");
|
element.setText("chararray");
|
||||||
config.add(element);
|
config.add(element);
|
||||||
|
@ -581,17 +583,17 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
|
||||||
|
|
||||||
for (Element element : configXML) {
|
for (Element element : configXML) {
|
||||||
if (element.getName().equals("varname")) {
|
if (element.getName().equals("varname")) {
|
||||||
varName.setSelectedItem(element.getText());
|
varNameCombo.setSelectedItem(element.getText());
|
||||||
} else if (element.getName().equals("vartype")) {
|
} else if (element.getName().equals("vartype")) {
|
||||||
if (element.getText().equals("byte")) {
|
if (element.getText().equals("byte")) {
|
||||||
varType.setSelectedIndex(BYTE_INDEX);
|
varTypeCombo.setSelectedIndex(BYTE_INDEX);
|
||||||
} else if (element.getText().equals("int")) {
|
} else if (element.getText().equals("int")) {
|
||||||
varType.setSelectedIndex(INT_INDEX);
|
varTypeCombo.setSelectedIndex(INT_INDEX);
|
||||||
} else if (element.getText().equals("array")) {
|
} else if (element.getText().equals("array")) {
|
||||||
varType.setSelectedIndex(ARRAY_INDEX);
|
varTypeCombo.setSelectedIndex(ARRAY_INDEX);
|
||||||
lengthPane.setVisible(true);
|
lengthPane.setVisible(true);
|
||||||
} else if (element.getText().equals("chararray")) {
|
} else if (element.getText().equals("chararray")) {
|
||||||
varType.setSelectedIndex(CHAR_ARRAY_INDEX);
|
varTypeCombo.setSelectedIndex(CHAR_ARRAY_INDEX);
|
||||||
lengthPane.setVisible(true);
|
lengthPane.setVisible(true);
|
||||||
}
|
}
|
||||||
} else if (element.getName().equals("array_length")) {
|
} else if (element.getName().equals("array_length")) {
|
||||||
|
|
Loading…
Reference in a new issue