mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-22 10:30:13 +00:00
simplified skin menu implementation, removed unused skin button code
This commit is contained in:
parent
c276f90247
commit
9c05689be0
@ -37,7 +37,6 @@ import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.MouseInfo;
|
||||
import java.awt.Point;
|
||||
import java.awt.Polygon;
|
||||
import java.awt.RenderingHints;
|
||||
@ -68,7 +67,6 @@ import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
@ -80,6 +78,8 @@ import javax.swing.JSeparator;
|
||||
import javax.swing.MenuElement;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.Timer;
|
||||
import javax.swing.event.MenuEvent;
|
||||
import javax.swing.event.MenuListener;
|
||||
import javax.swing.plaf.basic.BasicInternalFrameUI;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
@ -87,16 +87,16 @@ import org.jdom.Element;
|
||||
|
||||
import se.sics.cooja.ClassDescription;
|
||||
import se.sics.cooja.GUI;
|
||||
import se.sics.cooja.GUI.MoteRelation;
|
||||
import se.sics.cooja.HasQuickHelp;
|
||||
import se.sics.cooja.Mote;
|
||||
import se.sics.cooja.MoteInterface;
|
||||
import se.sics.cooja.PluginType;
|
||||
import se.sics.cooja.RadioMedium;
|
||||
import se.sics.cooja.SimEventCentral.MoteCountListener;
|
||||
import se.sics.cooja.Simulation;
|
||||
import se.sics.cooja.SupportedArguments;
|
||||
import se.sics.cooja.VisPlugin;
|
||||
import se.sics.cooja.GUI.MoteRelation;
|
||||
import se.sics.cooja.SimEventCentral.MoteCountListener;
|
||||
import se.sics.cooja.interfaces.LED;
|
||||
import se.sics.cooja.interfaces.Position;
|
||||
import se.sics.cooja.interfaces.SerialPort;
|
||||
@ -160,7 +160,6 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
||||
private Cursor moveCursor = new Cursor(Cursor.MOVE_CURSOR);
|
||||
|
||||
/* Visualizers */
|
||||
private final JButton skinButton = new JButton("Select visualizer skins");
|
||||
private static ArrayList<Class<? extends VisualizerSkin>> visualizerSkins =
|
||||
new ArrayList<Class<? extends VisualizerSkin>>();
|
||||
static {
|
||||
@ -222,10 +221,20 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
||||
|
||||
/* Menus */
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
|
||||
|
||||
viewMenu = new JMenu("View");
|
||||
viewMenu.addMenuListener(new MenuListener() {
|
||||
public void menuSelected(MenuEvent e) {
|
||||
viewMenu.removeAll();
|
||||
populateSkinMenu(viewMenu);
|
||||
}
|
||||
public void menuDeselected(MenuEvent e) {
|
||||
}
|
||||
public void menuCanceled(MenuEvent e) {
|
||||
}
|
||||
});
|
||||
JMenu zoomMenu = new JMenu("Zoom");
|
||||
|
||||
|
||||
menuBar.add(viewMenu);
|
||||
menuBar.add(zoomMenu);
|
||||
|
||||
@ -280,20 +289,6 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
||||
canvas.setBackground(Color.WHITE);
|
||||
viewportTransform = new AffineTransform();
|
||||
|
||||
/* Skin selector */
|
||||
skinButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Point mouse = MouseInfo.getPointerInfo().getLocation();
|
||||
JPopupMenu skinPopupMenu = new JPopupMenu();
|
||||
|
||||
populateSkinMenu(skinPopupMenu);
|
||||
|
||||
skinPopupMenu.setLocation(mouse);
|
||||
skinPopupMenu.setInvoker(skinButton);
|
||||
skinPopupMenu.setVisible(true);
|
||||
}
|
||||
});
|
||||
/*this.add(BorderLayout.NORTH, skinButton);*/
|
||||
this.add(BorderLayout.CENTER, canvas);
|
||||
|
||||
/* Observe simulation and mote positions */
|
||||
@ -524,7 +519,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
||||
|
||||
/* XXX HACK: here we set the position and size of the window when it appears on a blank simulation screen. */
|
||||
this.setLocation(1, 1);
|
||||
this.setSize(400, 400);
|
||||
this.setSize(400, 400);
|
||||
}
|
||||
|
||||
private void generateAndActivateSkin(Class<? extends VisualizerSkin> skinClass) {
|
||||
@ -550,9 +545,6 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
||||
} catch (IllegalAccessException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
skinButton.setText("Select visualizer " +
|
||||
"(" + currentSkins.size() + "/" + visualizerSkins.size() + ")");
|
||||
repaint();
|
||||
}
|
||||
|
||||
@ -572,9 +564,6 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
||||
simulation.getGUI().tryLoadClass(this, VisualizerSkin.class, skin);
|
||||
generateAndActivateSkin(skinClass);
|
||||
}
|
||||
|
||||
populateSkinMenu(viewMenu);
|
||||
|
||||
}
|
||||
|
||||
public VisualizerSkin[] getCurrentSkins() {
|
||||
@ -700,11 +689,15 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
||||
menu.setVisible(true);
|
||||
}
|
||||
|
||||
private void populateSkinMenu(MenuElement skinMenu) {
|
||||
JCheckBoxMenuItem item;
|
||||
private void populateSkinMenu(MenuElement menu) {
|
||||
for (Class<? extends VisualizerSkin> skinClass: visualizerSkins) {
|
||||
/* Should skin be enabled in this simulation? */
|
||||
if (!isSkinCompatible(skinClass)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String description = GUI.getDescriptionOf(skinClass);
|
||||
item = new JCheckBoxMenuItem(description, false);
|
||||
JCheckBoxMenuItem item = new JCheckBoxMenuItem(description, false);
|
||||
item.putClientProperty("skinclass", skinClass);
|
||||
|
||||
/* Select skin if active */
|
||||
@ -749,23 +742,15 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
||||
skinToDeactivate.setInactive();
|
||||
repaint();
|
||||
currentSkins.remove(skinToDeactivate);
|
||||
skinButton.setText("Select visualizers " +
|
||||
"(" + currentSkins.size() + "/" + visualizerSkins.size() + ")");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/* Should skin be enabled in this simulation? */
|
||||
if (!isSkinCompatible(skinClass)) {
|
||||
continue;
|
||||
if (menu instanceof JMenu) {
|
||||
((JMenu)menu).add(item);
|
||||
}
|
||||
|
||||
if (skinMenu instanceof JMenu) {
|
||||
((JMenu)skinMenu).add(item);
|
||||
}
|
||||
if (skinMenu instanceof JPopupMenu) {
|
||||
((JPopupMenu)skinMenu).add(item);
|
||||
if (menu instanceof JPopupMenu) {
|
||||
((JPopupMenu)menu).add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -845,7 +830,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
||||
newZoom,
|
||||
newZoom
|
||||
);
|
||||
|
||||
|
||||
/*Position moved = transformPixelToPosition(zoomingPixel);
|
||||
viewportTransform.translate(
|
||||
moved.getXCoordinate() - zoomingPosition.getXCoordinate(),
|
||||
@ -919,7 +904,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
||||
}
|
||||
/* Restore cursor */
|
||||
canvas.setCursor(Cursor.getDefaultCursor());
|
||||
|
||||
|
||||
|
||||
/* Move mote */
|
||||
if (moveStartTime < 0 || System.currentTimeMillis() - moveStartTime > 300) {
|
||||
@ -1296,7 +1281,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
||||
}
|
||||
|
||||
public boolean setConfigXML(Collection<Element> configXML, boolean visAvailable) {
|
||||
loadedConfig = true;
|
||||
loadedConfig = true;
|
||||
|
||||
for (Element element : configXML) {
|
||||
if (element.getName().equals("skin")) {
|
||||
@ -1337,21 +1322,8 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
||||
} else if (element.getName().equals("hidden")) {
|
||||
BasicInternalFrameUI ui = (BasicInternalFrameUI) getUI();
|
||||
ui.getNorthPane().setPreferredSize(new Dimension(0,0));
|
||||
skinButton.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This is a hack: since the viewers are activated through an invokeLater
|
||||
* mechanism (see above), we'll have to invoke the
|
||||
* populateSkinMenu(viewMenu) later too. Lets just hope the invokation of
|
||||
* populateSkinMenu() is done later than the activation of the viewers...
|
||||
*/
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
populateSkinMenu(viewMenu);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1503,11 +1475,9 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
||||
ui.getNorthPane().getPreferredSize().height == 0) {
|
||||
/* Restore window decorations */
|
||||
ui.getNorthPane().setPreferredSize(null);
|
||||
visualizer.skinButton.setVisible(true);
|
||||
} else {
|
||||
/* Hide window decorations */
|
||||
ui.getNorthPane().setPreferredSize(new Dimension(0,0));
|
||||
visualizer.skinButton.setVisible(false);
|
||||
}
|
||||
visualizer.revalidate();
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
|
Loading…
Reference in New Issue
Block a user