added setVisualized method (experimental)

This commit is contained in:
fros4943 2007-05-28 09:01:49 +00:00
parent 6271beabc3
commit 953c60c35a

View file

@ -24,7 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* $Id: GUI.java,v 1.52 2007/05/28 08:06:41 fros4943 Exp $ * $Id: GUI.java,v 1.53 2007/05/28 09:01:49 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -194,12 +194,15 @@ public class GUI {
* Creates a new COOJA Simulator GUI. * Creates a new COOJA Simulator GUI.
* *
* @param desktop Desktop pane * @param desktop Desktop pane
* @param createSimDialog If true, a create simulation dialog will be displayed at startup
*/ */
public GUI(JDesktopPane desktop, boolean createSimDialog) { public GUI(JDesktopPane desktop) {
myGUI = this; myGUI = this;
mySimulation = null; mySimulation = null;
myDesktopPane = desktop; myDesktopPane = desktop;
if (menuPlugins == null)
menuPlugins = new JMenu("Plugins");
if (menuMotePluginClasses == null)
menuMotePluginClasses = new Vector<Class<? extends Plugin>>();
// Load default and overwrite with user settings (if any) // Load default and overwrite with user settings (if any)
loadExternalToolsDefaultSettings(); loadExternalToolsDefaultSettings();
@ -208,12 +211,6 @@ public class GUI {
setExternalToolsSetting("PATH_CONTIKI", specifiedContikiPath); setExternalToolsSetting("PATH_CONTIKI", specifiedContikiPath);
} }
// Add menu bar
if (frame != null) {
frame.setJMenuBar(createMenuBar());
}
// Register default project directories // Register default project directories
String defaultProjectDirs = getExternalToolsSetting( String defaultProjectDirs = getExternalToolsSetting(
"DEFAULT_PROJECTDIRS", null); "DEFAULT_PROJECTDIRS", null);
@ -239,14 +236,6 @@ public class GUI {
startPlugin(visPluginClass, this, null, null); startPlugin(visPluginClass, this, null, null);
} }
} }
if (createSimDialog && frame != null) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
myGUI.doCreateSimulation(true);
}
});
}
} }
/** /**
@ -255,6 +244,22 @@ public class GUI {
public boolean isVisualized() { public boolean isVisualized() {
return frame != null; return frame != null;
} }
/**
* EXPERIMENTAL!
* Tries to create/remove simulator visualizer.
*
* @param visualized Visualized
*/
public void setVisualized(boolean visualized) {
if (!isVisualized() && visualized) {
configureFrame(myGUI, false);
} else {
frame.setVisible(false);
frame.dispose();
frame = null;
}
}
private Vector<File> getFileHistory() { private Vector<File> getFileHistory() {
Vector<File> history = new Vector<File>(); Vector<File> history = new Vector<File>();
@ -516,7 +521,10 @@ public class GUI {
menu.add(menuItem); menu.add(menuItem);
// Plugins menu // Plugins menu
menuPlugins = new JMenu("Plugins"); if (menuPlugins == null)
menuPlugins = new JMenu("Plugins");
else
menuPlugins.setText("Plugins");
menuPlugins.setMnemonic(KeyEvent.VK_P); menuPlugins.setMnemonic(KeyEvent.VK_P);
menuBar.add(menuPlugins); menuBar.add(menuPlugins);
@ -543,11 +551,12 @@ public class GUI {
menu.add(menuItem); menu.add(menuItem);
// Mote plugins popup menu (not available via menu bar) // Mote plugins popup menu (not available via menu bar)
menuMotePluginClasses = new Vector<Class<? extends Plugin>>(); if (menuMotePluginClasses == null)
menuMotePluginClasses = new Vector<Class<? extends Plugin>>();
return menuBar; return menuBar;
} }
private static void createAndShowGUI() { private static void configureFrame(final GUI gui, boolean createSimDialog) {
// Make sure we have nice window decorations. // Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true); JFrame.setDefaultLookAndFeelDecorated(true);
@ -560,13 +569,10 @@ public class GUI {
if (maxSize != null) if (maxSize != null)
frame.setMaximizedBounds(maxSize); frame.setMaximizedBounds(maxSize);
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
logger.debug(frame.getPreferredSize());
// Create and set up the content pane. // Add menu bar
JDesktopPane desktop = new JDesktopPane(); frame.setJMenuBar(gui.createMenuBar());
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
GUI gui = new GUI(desktop, true);
JComponent newContentPane = gui.getDesktopPane(); JComponent newContentPane = gui.getDesktopPane();
newContentPane.setOpaque(true); newContentPane.setOpaque(true);
frame.setContentPane(newContentPane); frame.setContentPane(newContentPane);
@ -598,6 +604,14 @@ public class GUI {
// Display the window. // Display the window.
frame.setVisible(true); frame.setVisible(true);
if (createSimDialog) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
gui.doCreateSimulation(true);
}
});
}
} }
/** /**
@ -654,8 +668,7 @@ public class GUI {
// Create and set up the content pane. // Create and set up the content pane.
JDesktopPane desktop = new JDesktopPane(); JDesktopPane desktop = new JDesktopPane();
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
GUI gui = new GUI(desktop, false); // loads external settings and creates initial GUI gui = new GUI(desktop); // loads external settings and creates initial project config
// project config
// Add menu bar // Add menu bar
frame.setSize(700, 700); frame.setSize(700, 700);
@ -1645,6 +1658,8 @@ public class GUI {
public void unregisterPlugins() { public void unregisterPlugins() {
if (menuPlugins != null) { if (menuPlugins != null) {
menuPlugins.removeAll(); menuPlugins.removeAll();
}
if (menuMotePluginClasses != null) {
menuMotePluginClasses.clear(); menuMotePluginClasses.clear();
} }
pluginClasses.clear(); pluginClasses.clear();
@ -2701,7 +2716,7 @@ public class GUI {
// No GUI start-up // No GUI start-up
javax.swing.SwingUtilities.invokeLater(new Runnable() { javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() { public void run() {
new GUI(null, false); new GUI(null);
} }
}); });
@ -2710,7 +2725,10 @@ public class GUI {
// Regular start-up // Regular start-up
javax.swing.SwingUtilities.invokeLater(new Runnable() { javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() { public void run() {
createAndShowGUI(); JDesktopPane desktop = new JDesktopPane();
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
GUI gui = new GUI(desktop);
configureFrame(gui, false);
} }
}); });