moved radio interface visualizer code to shared abstract radio

This commit is contained in:
Fredrik Osterlind 2011-02-22 20:23:43 +01:00
parent 498df44bc7
commit 990edbe32d
3 changed files with 0 additions and 236 deletions

View File

@ -385,84 +385,6 @@ public class SkyByteRadio extends Radio implements CustomDataRadio {
rssiLastCounter = 8;
}
public JPanel getInterfaceVisualizer() {
// Location
JPanel wrapperPanel = new JPanel(new BorderLayout());
JPanel panel = new JPanel(new GridLayout(5, 2));
final JLabel statusLabel = new JLabel("");
final JLabel lastEventLabel = new JLabel("");
final JLabel channelLabel = new JLabel("");
final JLabel powerLabel = new JLabel("");
final JLabel ssLabel = new JLabel("");
final JButton updateButton = new JButton("Update");
panel.add(new JLabel("STATE:"));
panel.add(statusLabel);
panel.add(new JLabel("LAST EVENT:"));
panel.add(lastEventLabel);
panel.add(new JLabel("CHANNEL:"));
panel.add(channelLabel);
panel.add(new JLabel("OUTPUT POWER:"));
panel.add(powerLabel);
panel.add(new JLabel("SIGNAL STRENGTH:"));
JPanel smallPanel = new JPanel(new GridLayout(1, 2));
smallPanel.add(ssLabel);
smallPanel.add(updateButton);
panel.add(smallPanel);
updateButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
channelLabel.setText(getChannel() + " (freq=" + getFrequency() + " MHz)");
powerLabel.setText(getCurrentOutputPower() + " dBm (indicator=" + getCurrentOutputPowerIndicator() + "/" + getOutputPowerIndicatorMax() + ")");
ssLabel.setText(getCurrentSignalStrength() + " dBm");
}
});
Observer observer;
this.addObserver(observer = new Observer() {
public void update(Observable obs, Object obj) {
if (isTransmitting()) {
statusLabel.setText("transmitting");
} else if (isReceiving()) {
statusLabel.setText("receiving");
} else if (isReceiverOn()) {
statusLabel.setText("listening for traffic");
} else {
statusLabel.setText("HW off");
}
lastEventLabel.setText(lastEvent + " @ time=" + lastEventTime);
channelLabel.setText(getChannel() + " (freq=" + getFrequency() + " MHz)");
powerLabel.setText(getCurrentOutputPower() + " dBm (indicator=" + getCurrentOutputPowerIndicator() + "/" + getOutputPowerIndicatorMax() + ")");
ssLabel.setText(getCurrentSignalStrength() + " dBm");
}
});
observer.update(null, null);
wrapperPanel.add(BorderLayout.NORTH, panel);
// Saving observer reference for releaseInterfaceVisualizer
wrapperPanel.putClientProperty("intf_obs", observer);
return wrapperPanel;
}
public void releaseInterfaceVisualizer(JPanel panel) {
Observer observer = (Observer) panel.getClientProperty("intf_obs");
if (observer == null) {
logger.fatal("Error when releasing panel, observer is null");
return;
}
this.deleteObserver(observer);
}
public Mote getMote() {
return mote;
}

View File

@ -355,86 +355,6 @@ public class TR1001Radio extends Radio implements USARTListener, CustomDataRadio
}
};
public JPanel getInterfaceVisualizer() {
// Location
JPanel wrapperPanel = new JPanel(new BorderLayout());
JPanel panel = new JPanel(new GridLayout(5, 2));
final JLabel statusLabel = new JLabel("");
final JLabel lastEventLabel = new JLabel("");
final JLabel channelLabel = new JLabel("ALL CHANNELS (-1)");
final JLabel powerLabel = new JLabel("");
final JLabel ssLabel = new JLabel("");
final JButton updateButton = new JButton("Update");
panel.add(new JLabel("STATE:"));
panel.add(statusLabel);
panel.add(new JLabel("LAST EVENT:"));
panel.add(lastEventLabel);
panel.add(new JLabel("CHANNEL:"));
panel.add(channelLabel);
panel.add(new JLabel("OUTPUT POWER:"));
panel.add(powerLabel);
panel.add(new JLabel("SIGNAL STRENGTH:"));
JPanel smallPanel = new JPanel(new GridLayout(1, 2));
smallPanel.add(ssLabel);
smallPanel.add(updateButton);
panel.add(smallPanel);
updateButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
powerLabel.setText(getCurrentOutputPower() + " dBm (indicator="
+ getCurrentOutputPowerIndicator() + "/"
+ getOutputPowerIndicatorMax() + ")");
ssLabel.setText(getCurrentSignalStrength() + " dBm");
}
});
Observer observer;
this.addObserver(observer = new Observer() {
public void update(Observable obs, Object obj) {
if (isTransmitting()) {
statusLabel.setText("transmitting");
} else if (isReceiving()) {
statusLabel.setText("receiving");
} else if (radioOn) {
statusLabel.setText("listening for traffic");
} else {
statusLabel.setText("HW off");
}
lastEventLabel.setText(lastEvent + " @ time=" + lastEventTime);
powerLabel.setText(getCurrentOutputPower() + " dBm (indicator="
+ getCurrentOutputPowerIndicator() + "/"
+ getOutputPowerIndicatorMax() + ")");
ssLabel.setText(getCurrentSignalStrength() + " dBm");
}
});
observer.update(null, null);
// Saving observer reference for releaseInterfaceVisualizer
panel.putClientProperty("intf_obs", observer);
wrapperPanel.add(BorderLayout.NORTH, panel);
return wrapperPanel;
}
public void releaseInterfaceVisualizer(JPanel panel) {
Observer observer = (Observer) panel.getClientProperty("intf_obs");
if (observer == null) {
logger.fatal("Error when releasing panel, observer is null");
return;
}
this.deleteObserver(observer);
}
public Collection<Element> getConfigXML() {
return null;
}

View File

@ -345,84 +345,6 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface, PolledA
}
}
public JPanel getInterfaceVisualizer() {
// Location
JPanel wrapperPanel = new JPanel(new BorderLayout());
JPanel panel = new JPanel(new GridLayout(5, 2));
final JLabel statusLabel = new JLabel("");
final JLabel lastEventLabel = new JLabel("");
final JLabel channelLabel = new JLabel("");
final JLabel powerLabel = new JLabel("");
final JLabel ssLabel = new JLabel("");
final JButton updateButton = new JButton("Update");
panel.add(new JLabel("STATE:"));
panel.add(statusLabel);
panel.add(new JLabel("LAST EVENT:"));
panel.add(lastEventLabel);
panel.add(new JLabel("CHANNEL:"));
panel.add(channelLabel);
panel.add(new JLabel("OUTPUT POWER:"));
panel.add(powerLabel);
panel.add(new JLabel("SIGNAL STRENGTH:"));
JPanel smallPanel = new JPanel(new GridLayout(1, 2));
smallPanel.add(ssLabel);
smallPanel.add(updateButton);
panel.add(smallPanel);
updateButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
channelLabel.setText("" + getChannel());
powerLabel.setText(getCurrentOutputPower() + " dBm (indicator=" + getCurrentOutputPowerIndicator() + "/" + getOutputPowerIndicatorMax() + ")");
ssLabel.setText(getCurrentSignalStrength() + " dBm");
}
});
Observer observer;
this.addObserver(observer = new Observer() {
public void update(Observable obs, Object obj) {
if (isTransmitting()) {
statusLabel.setText("transmitting");
} else if (isReceiving()) {
statusLabel.setText("receiving");
} else if (radioOn) {
statusLabel.setText("listening for traffic");
} else {
statusLabel.setText("HW off");
}
lastEventLabel.setText(lastEvent + " @ time=" + lastEventTime);
channelLabel.setText("" + getChannel());
powerLabel.setText(getCurrentOutputPower() + " dBm (indicator=" + getCurrentOutputPowerIndicator() + "/" + getOutputPowerIndicatorMax() + ")");
ssLabel.setText(getCurrentSignalStrength() + " dBm");
}
});
observer.update(null, null);
wrapperPanel.add(BorderLayout.NORTH, panel);
// Saving observer reference for releaseInterfaceVisualizer
wrapperPanel.putClientProperty("intf_obs", observer);
return wrapperPanel;
}
public void releaseInterfaceVisualizer(JPanel panel) {
Observer observer = (Observer) panel.getClientProperty("intf_obs");
if (observer == null) {
logger.fatal("Error when releasing panel, observer is null");
return;
}
this.deleteObserver(observer);
}
public Collection<Element> getConfigXML() {
return null;
}