[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,14 +450,18 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
writeButton.setEnabled(true);
|
try {
|
||||||
bufferedBytes = moteMemory.getByteArray(
|
writeButton.setEnabled(true);
|
||||||
(long) varAddressField.getValue(),
|
bufferedBytes = moteMemory.getByteArray(
|
||||||
Integer.decode(varSizeField.getText()));
|
(long) varAddressField.getValue(),
|
||||||
refreshValues();
|
Integer.decode(varSizeField.getText()));
|
||||||
|
refreshValues();
|
||||||
|
} catch (MemoryInterface.MoteMemoryException ex) {
|
||||||
|
JOptionPane.showMessageDialog(varNameCombo, ex.getMessage(), "MoteMemoryException", JOptionPane.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
readPane.add(BorderLayout.WEST, readButton);
|
readPane.add(BorderLayout.WEST, readButton);
|
||||||
|
|
||||||
/* MemoryMonitor required for monitor button */
|
/* MemoryMonitor required for monitor button */
|
||||||
|
@ -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 */
|
||||||
bufferedBytes = moteMemory.getByteArray(
|
try {
|
||||||
(long) varAddressField.getValue(),
|
bufferedBytes = moteMemory.getByteArray(
|
||||||
Integer.decode(varSizeField.getText()));
|
(long) varAddressField.getValue(),
|
||||||
refreshValues();
|
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() {
|
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,30 +764,32 @@ 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 */
|
||||||
varValues = new JFormattedTextField[elements];
|
if (elements == 0) {
|
||||||
for (int i = 0; i < elements; i++) {
|
|
||||||
varValues[i] = new JFormattedTextField(defac);
|
|
||||||
varValues[i].setColumns(6);
|
|
||||||
varValues[i].setToolTipText(String.format("0x%04x", address + i * typeSize));
|
|
||||||
linePane.add(varValues[i]);
|
|
||||||
/* After 8 Elements, break line */
|
|
||||||
if ((i + 1) % 8 == 0) {
|
|
||||||
valuePane.add(linePane);
|
|
||||||
linePane = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
valuePane.add(linePane);
|
|
||||||
|
|
||||||
readButton.setEnabled(true);
|
|
||||||
monitorButton.setEnabled(true);
|
|
||||||
writeButton.setEnabled(true);
|
|
||||||
} else {
|
|
||||||
readButton.setEnabled(false);
|
readButton.setEnabled(false);
|
||||||
monitorButton.setEnabled(false);
|
monitorButton.setEnabled(false);
|
||||||
writeButton.setEnabled(false);
|
writeButton.setEnabled(false);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
varValues = new JFormattedTextField[elements];
|
||||||
|
for (int i = 0; i < elements; i++) {
|
||||||
|
varValues[i] = new JFormattedTextField(defac);
|
||||||
|
varValues[i].setColumns(6);
|
||||||
|
varValues[i].setToolTipText(String.format("0x%04x", address + i * typeSize));
|
||||||
|
linePane.add(varValues[i]);
|
||||||
|
/* After 8 Elements, break line */
|
||||||
|
if ((i + 1) % 8 == 0) {
|
||||||
|
valuePane.add(linePane);
|
||||||
|
linePane = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
valuePane.add(linePane);
|
||||||
|
|
||||||
|
readButton.setEnabled(true);
|
||||||
|
monitorButton.setEnabled(true);
|
||||||
|
writeButton.setEnabled(true);
|
||||||
|
|
||||||
refreshValues();
|
refreshValues();
|
||||||
|
|
||||||
pack();
|
pack();
|
||||||
|
|
Loading…
Reference in a new issue