added simple way for user to reconfigure application radio's channel

This commit is contained in:
fros4943 2010-08-31 07:35:22 +00:00
parent c54fee4738
commit 925759e72c

View file

@ -26,11 +26,12 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: ApplicationRadio.java,v 1.13 2010/02/08 16:00:46 fros4943 Exp $ * $Id: ApplicationRadio.java,v 1.14 2010/08/31 07:35:22 fros4943 Exp $
*/ */
package se.sics.cooja.interfaces; package se.sics.cooja.interfaces;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.Collection; import java.util.Collection;
@ -38,8 +39,8 @@ import java.util.Observable;
import java.util.Observer; import java.util.Observer;
import javax.swing.Box; import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
@ -271,12 +272,15 @@ public class ApplicationRadio extends Radio {
*/ */
public void setChannel(int channel) { public void setChannel(int channel) {
radioChannel = channel; radioChannel = channel;
lastEvent = RadioEvent.UNKNOWN;
lastEventTime = simulation.getSimulationTime();
setChanged();
notifyObservers();
} }
public JPanel getInterfaceVisualizer() { public JPanel getInterfaceVisualizer() {
// Location JPanel panel = new JPanel(new BorderLayout());
JPanel panel = new JPanel(); Box box = Box.createVerticalBox();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
final JLabel statusLabel = new JLabel(""); final JLabel statusLabel = new JLabel("");
final JLabel lastEventLabel = new JLabel(""); final JLabel lastEventLabel = new JLabel("");
@ -284,13 +288,35 @@ public class ApplicationRadio extends Radio {
final JLabel ssLabel = new JLabel(""); final JLabel ssLabel = new JLabel("");
final JButton updateButton = new JButton("Update SS"); final JButton updateButton = new JButton("Update SS");
panel.add(statusLabel); JComboBox channelMenu = new JComboBox(new String[] {
panel.add(lastEventLabel); "ALL",
panel.add(ssLabel); "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
panel.add(updateButton); "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
panel.add(Box.createVerticalStrut(3)); "21", "22", "23", "24", "25", "26", "27", "28", "29", "30"
panel.add(channelLabel); });
panel.add(Box.createVerticalGlue()); channelMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox m = (JComboBox) e.getSource();
String s = (String) m.getSelectedItem();
if (s == null || s.equals("ALL")) {
setChannel(-1);
} else {
setChannel(Integer.parseInt(s));
}
}
});
if (getChannel() == -1) {
channelMenu.setSelectedIndex(0);
} else {
channelMenu.setSelectedIndex(getChannel());
}
box.add(statusLabel);
box.add(lastEventLabel);
box.add(ssLabel);
box.add(updateButton);
box.add(channelLabel);
box.add(channelMenu);
updateButton.addActionListener(new ActionListener() { updateButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -303,8 +329,7 @@ public class ApplicationRadio extends Radio {
public void update(Observable obs, Object obj) { public void update(Observable obs, Object obj) {
if (isTransmitting()) { if (isTransmitting()) {
statusLabel.setText("Transmitting"); statusLabel.setText("Transmitting");
} } else if (isReceiving()) {
if (isReceiving()) {
statusLabel.setText("Receiving"); statusLabel.setText("Receiving");
} else { } else {
statusLabel.setText("Listening"); statusLabel.setText("Listening");
@ -313,15 +338,19 @@ public class ApplicationRadio extends Radio {
lastEventLabel.setText("Last event (time=" + lastEventTime + "): " + lastEvent); lastEventLabel.setText("Last event (time=" + lastEventTime + "): " + lastEvent);
ssLabel.setText("Signal strength (not auto-updated): " ssLabel.setText("Signal strength (not auto-updated): "
+ getCurrentSignalStrength() + " dBm"); + getCurrentSignalStrength() + " dBm");
if (getChannel() == -1) {
channelLabel.setText("Current channel: ALL");
} else {
channelLabel.setText("Current channel: " + getChannel());
}
} }
}; };
this.addObserver(observer); this.addObserver(observer);
observer.update(null, null); observer.update(null, null);
// Saving observer reference for releaseInterfaceVisualizer panel.add(BorderLayout.NORTH, box);
panel.putClientProperty("intf_obs", observer); panel.putClientProperty("intf_obs", observer);
return panel; return panel;
} }