[cooja] plugins/VariableWatcher: Catch exceptions, show error dialog for invalid addresses

And some gui option handling fixes
This commit is contained in:
Enrico Joerns 2014-08-28 16:05:32 +02:00
parent f70e1ef99f
commit 57719de18d

View File

@ -56,6 +56,7 @@ import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JToggleButton;
@ -334,17 +335,15 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
if (varAddrCheckBox.isSelected()) {
varNameCombo.setEnabled(false);
varNameCombo.setEditable(false);
varAddressField.setEnabled(true);
varAddressField.setEditable(true);
varSizeField.setEnabled(true);
varSizeField.setEditable(true);
} else {
varNameCombo.setEnabled(true);
varNameCombo.setEditable(true);
// switch back to var name control
updateBySelectedVarname();
varAddressField.setEditable(false);
varSizeField.setEditable(false);
// switch back to var name control
updateBySelectedVarname();
}
}
});
@ -451,11 +450,15 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
return;
}
try {
writeButton.setEnabled(true);
bufferedBytes = moteMemory.getByteArray(
(long) varAddressField.getValue(),
Integer.decode(varSizeField.getText()));
refreshValues();
} catch (MemoryInterface.MoteMemoryException ex) {
JOptionPane.showMessageDialog(varNameCombo, ex.getMessage(), "MoteMemoryException", JOptionPane.ERROR_MESSAGE);
}
}
});
@ -479,23 +482,28 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
memMonitor);
varAddrCheckBox.setEnabled(true);
readButton.setEnabled(true);
varNameCombo.setEnabled(true);
writeButton.setEnabled(true);
if (!varAddrCheckBox.isSelected()) {
varNameCombo.setEnabled(true);
}
return;
}
/* initial readout so we have a value to display */
try {
bufferedBytes = moteMemory.getByteArray(
(long) varAddressField.getValue(),
Integer.decode(varSizeField.getText()));
refreshValues();
} catch (MemoryInterface.MoteMemoryException ex) {
JOptionPane.showMessageDialog(varNameCombo, ex.getMessage(), "MoteMemoryException", JOptionPane.ERROR_MESSAGE);
monitorButton.setSelected(false);
return;
}
// monitorAddr = moteMemory.getVariableAddress(varname);
// monitorSize = moteMemory.getVariableSize(varname);
memMonitor = new MemoryInterface.SegmentMonitor() {
@Override
// public void memoryChanged(MoteMemory memory, MoteMemory.MemoryEventType type, int address) {
public void memoryChanged(MemoryInterface memory, EventType type, long address) {
bufferedBytes = moteMemory.getByteArray(
(long) varAddressField.getValue(),
@ -756,7 +764,14 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
int typeSize = ((VarTypes) varTypeCombo.getSelectedItem()).getBytes();
int elements = (int) Math.ceil((double) bytes / typeSize);
if (elements > 0) {
/* If no/unknown size: disable buttons and abort */
if (elements == 0) {
readButton.setEnabled(false);
monitorButton.setEnabled(false);
writeButton.setEnabled(false);
return;
}
varValues = new JFormattedTextField[elements];
for (int i = 0; i < elements; i++) {
varValues[i] = new JFormattedTextField(defac);
@ -774,11 +789,6 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
readButton.setEnabled(true);
monitorButton.setEnabled(true);
writeButton.setEnabled(true);
} else {
readButton.setEnabled(false);
monitorButton.setEnabled(false);
writeButton.setEnabled(false);
}
refreshValues();