automatically updating when new mote types are added/removed
This commit is contained in:
parent
36f70eff7c
commit
bae02d252a
|
@ -26,21 +26,21 @@
|
||||||
* 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: MoteTypeInformation.java,v 1.3 2008/02/07 13:14:42 fros4943 Exp $
|
* $Id: MoteTypeInformation.java,v 1.4 2008/02/11 14:37:17 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.plugins;
|
package se.sics.cooja.plugins;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.util.Observable;
|
||||||
|
import java.util.Observer;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import se.sics.cooja.*;
|
import se.sics.cooja.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows a summary of all created mote types.
|
* Shows a summary of all mote types.
|
||||||
*
|
*
|
||||||
* @author Fredrik Osterlind
|
* @author Fredrik Osterlind
|
||||||
*/
|
*/
|
||||||
|
@ -53,8 +53,7 @@ public class MoteTypeInformation extends VisPlugin {
|
||||||
|
|
||||||
private Simulation mySimulation;
|
private Simulation mySimulation;
|
||||||
|
|
||||||
private final static int LABEL_WIDTH = 170;
|
private Observer simObserver;
|
||||||
private final static int LABEL_HEIGHT = 15;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new mote type information window.
|
* Create a new mote type information window.
|
||||||
|
@ -62,25 +61,46 @@ public class MoteTypeInformation extends VisPlugin {
|
||||||
* @param simulation Simulation
|
* @param simulation Simulation
|
||||||
*/
|
*/
|
||||||
public MoteTypeInformation(Simulation simulation, GUI gui) {
|
public MoteTypeInformation(Simulation simulation, GUI gui) {
|
||||||
super("Mote Type Information *frozen*", gui);
|
super("Mote Type Information", gui);
|
||||||
|
|
||||||
mySimulation = simulation;
|
mySimulation = simulation;
|
||||||
|
|
||||||
|
this.getContentPane().add(BorderLayout.CENTER,
|
||||||
|
new JScrollPane(createPanel(),
|
||||||
|
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
|
||||||
|
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
|
||||||
|
pack();
|
||||||
|
setPreferredSize(new Dimension(350,500));
|
||||||
|
setSize(new Dimension(350,500));
|
||||||
|
|
||||||
|
mySimulation.addObserver(simObserver = new Observer() {
|
||||||
|
public void update(Observable obs, Object obj) {
|
||||||
|
MoteTypeInformation.this.getContentPane().removeAll();
|
||||||
|
MoteTypeInformation.this.getContentPane().add(BorderLayout.CENTER,
|
||||||
|
new JScrollPane(createPanel(),
|
||||||
|
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
|
||||||
|
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
|
||||||
|
setPreferredSize(MoteTypeInformation.this.getSize());
|
||||||
|
pack();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
setSelected(true);
|
||||||
|
} catch (java.beans.PropertyVetoException e) {
|
||||||
|
// Could not select
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private JPanel createPanel() {
|
||||||
JLabel label;
|
JLabel label;
|
||||||
JPanel mainPane = new JPanel();
|
|
||||||
mainPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
|
||||||
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
|
|
||||||
JPanel smallPane;
|
JPanel smallPane;
|
||||||
|
|
||||||
|
JPanel panel = new JPanel();
|
||||||
|
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||||
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
// Visualize mote types
|
// Visualize mote types
|
||||||
smallPane = new JPanel(new BorderLayout());
|
|
||||||
label = new JLabel("-- MOTE TYPES AT TIME " + simulation.getSimulationTime() + " --");
|
|
||||||
label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT));
|
|
||||||
smallPane.add(BorderLayout.NORTH, label);
|
|
||||||
|
|
||||||
mainPane.add(smallPane);
|
|
||||||
mainPane.add(Box.createRigidArea(new Dimension(0,10)));
|
|
||||||
|
|
||||||
for (MoteType moteType: mySimulation.getMoteTypes()) {
|
for (MoteType moteType: mySimulation.getMoteTypes()) {
|
||||||
smallPane = new JPanel();
|
smallPane = new JPanel();
|
||||||
smallPane.setLayout(new BorderLayout());
|
smallPane.setLayout(new BorderLayout());
|
||||||
|
@ -99,27 +119,16 @@ public class MoteTypeInformation extends VisPlugin {
|
||||||
smallPane.add(BorderLayout.CENTER, Box.createVerticalStrut(25));
|
smallPane.add(BorderLayout.CENTER, Box.createVerticalStrut(25));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
panel.add(smallPane);
|
||||||
mainPane.add(smallPane);
|
panel.add(Box.createRigidArea(new Dimension(0,20)));
|
||||||
mainPane.add(Box.createRigidArea(new Dimension(0,25)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getContentPane().add(BorderLayout.NORTH, new JScrollPane(mainPane,
|
return panel;
|
||||||
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
|
|
||||||
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
|
|
||||||
pack();
|
|
||||||
setPreferredSize(new Dimension(350,500));
|
|
||||||
setSize(new Dimension(350,500));
|
|
||||||
|
|
||||||
try {
|
|
||||||
setSelected(true);
|
|
||||||
} catch (java.beans.PropertyVetoException e) {
|
|
||||||
// Could not select
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void closePlugin() {
|
public void closePlugin() {
|
||||||
|
mySimulation.deleteObserver(simObserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue