[cooja] plugins/VariableWatcher: Catch exceptions, show error dialog for invalid addresses
And some gui option handling fixes
This commit is contained in:
parent
f70e1ef99f
commit
57719de18d
|
@ -56,6 +56,7 @@ import javax.swing.JCheckBox;
|
||||||
import javax.swing.JComboBox;
|
import javax.swing.JComboBox;
|
||||||
import javax.swing.JFormattedTextField;
|
import javax.swing.JFormattedTextField;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import javax.swing.JToggleButton;
|
import javax.swing.JToggleButton;
|
||||||
|
@ -334,17 +335,15 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
|
||||||
if (varAddrCheckBox.isSelected()) {
|
if (varAddrCheckBox.isSelected()) {
|
||||||
varNameCombo.setEnabled(false);
|
varNameCombo.setEnabled(false);
|
||||||
varNameCombo.setEditable(false);
|
varNameCombo.setEditable(false);
|
||||||
varAddressField.setEnabled(true);
|
|
||||||
varAddressField.setEditable(true);
|
varAddressField.setEditable(true);
|
||||||
varSizeField.setEnabled(true);
|
|
||||||
varSizeField.setEditable(true);
|
varSizeField.setEditable(true);
|
||||||
} else {
|
} else {
|
||||||
varNameCombo.setEnabled(true);
|
varNameCombo.setEnabled(true);
|
||||||
varNameCombo.setEditable(true);
|
varNameCombo.setEditable(true);
|
||||||
// switch back to var name control
|
|
||||||
updateBySelectedVarname();
|
|
||||||
varAddressField.setEditable(false);
|
varAddressField.setEditable(false);
|
||||||
varSizeField.setEditable(false);
|
varSizeField.setEditable(false);
|
||||||
|
// switch back to var name control
|
||||||
|
updateBySelectedVarname();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -451,11 +450,15 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
writeButton.setEnabled(true);
|
writeButton.setEnabled(true);
|
||||||
bufferedBytes = moteMemory.getByteArray(
|
bufferedBytes = moteMemory.getByteArray(
|
||||||
(long) varAddressField.getValue(),
|
(long) varAddressField.getValue(),
|
||||||
Integer.decode(varSizeField.getText()));
|
Integer.decode(varSizeField.getText()));
|
||||||
refreshValues();
|
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);
|
memMonitor);
|
||||||
varAddrCheckBox.setEnabled(true);
|
varAddrCheckBox.setEnabled(true);
|
||||||
readButton.setEnabled(true);
|
readButton.setEnabled(true);
|
||||||
varNameCombo.setEnabled(true);
|
|
||||||
writeButton.setEnabled(true);
|
writeButton.setEnabled(true);
|
||||||
|
if (!varAddrCheckBox.isSelected()) {
|
||||||
|
varNameCombo.setEnabled(true);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initial readout so we have a value to display */
|
/* initial readout so we have a value to display */
|
||||||
|
try {
|
||||||
bufferedBytes = moteMemory.getByteArray(
|
bufferedBytes = moteMemory.getByteArray(
|
||||||
(long) varAddressField.getValue(),
|
(long) varAddressField.getValue(),
|
||||||
Integer.decode(varSizeField.getText()));
|
Integer.decode(varSizeField.getText()));
|
||||||
refreshValues();
|
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() {
|
memMonitor = new MemoryInterface.SegmentMonitor() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
// public void memoryChanged(MoteMemory memory, MoteMemory.MemoryEventType type, int address) {
|
|
||||||
public void memoryChanged(MemoryInterface memory, EventType type, long address) {
|
public void memoryChanged(MemoryInterface memory, EventType type, long address) {
|
||||||
bufferedBytes = moteMemory.getByteArray(
|
bufferedBytes = moteMemory.getByteArray(
|
||||||
(long) varAddressField.getValue(),
|
(long) varAddressField.getValue(),
|
||||||
|
@ -756,7 +764,14 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
|
||||||
int typeSize = ((VarTypes) varTypeCombo.getSelectedItem()).getBytes();
|
int typeSize = ((VarTypes) varTypeCombo.getSelectedItem()).getBytes();
|
||||||
int elements = (int) Math.ceil((double) bytes / typeSize);
|
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];
|
varValues = new JFormattedTextField[elements];
|
||||||
for (int i = 0; i < elements; i++) {
|
for (int i = 0; i < elements; i++) {
|
||||||
varValues[i] = new JFormattedTextField(defac);
|
varValues[i] = new JFormattedTextField(defac);
|
||||||
|
@ -774,11 +789,6 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
|
||||||
readButton.setEnabled(true);
|
readButton.setEnabled(true);
|
||||||
monitorButton.setEnabled(true);
|
monitorButton.setEnabled(true);
|
||||||
writeButton.setEnabled(true);
|
writeButton.setEnabled(true);
|
||||||
} else {
|
|
||||||
readButton.setEnabled(false);
|
|
||||||
monitorButton.setEnabled(false);
|
|
||||||
writeButton.setEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
refreshValues();
|
refreshValues();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue