📄 gui.java
字号:
lastItem.addActionListener(guiEventHandler); menuConfOpenSimulation.add(lastItem); } menuOpenSimulation.removeAll(); browseItem = new JMenuItem("Browse..."); browseItem.setActionCommand("open sim"); browseItem.addActionListener(guiEventHandler); menuOpenSimulation.add(browseItem); menuOpenSimulation.add(new JSeparator()); for (File file: openFilesHistory) { JMenuItem lastItem = new JMenuItem(file.getName()); lastItem.setActionCommand("open last sim"); lastItem.putClientProperty("file", file); lastItem.setToolTipText(file.getAbsolutePath()); lastItem.addActionListener(guiEventHandler); menuOpenSimulation.add(lastItem); } } private JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu menu; JMenuItem menuItem; // File menu menu = new JMenu("File"); menu.addMenuListener(new MenuListener() { public void menuSelected(MenuEvent e) { updateOpenHistoryMenuItems(); } public void menuDeselected(MenuEvent e) { } public void menuCanceled(MenuEvent e) { } }); menu.setMnemonic(KeyEvent.VK_F); menuBar.add(menu); menuItem = new JMenuItem("New simulation"); menuItem.setMnemonic(KeyEvent.VK_N); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK)); menuItem.setActionCommand("new sim"); menuItem.addActionListener(guiEventHandler); menu.add(menuItem); menuItem = new JMenuItem("Reload simulation"); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { reloadCurrentSimulation(); } }); menu.add(menuItem); menuItem = new JMenuItem("Close simulation"); menuItem.setMnemonic(KeyEvent.VK_C); menuItem.setActionCommand("close sim"); menuItem.addActionListener(guiEventHandler); menu.add(menuItem); menuOpenSimulation = new JMenu("Open simulation"); menuOpenSimulation.setMnemonic(KeyEvent.VK_O); menu.add(menuOpenSimulation); menuConfOpenSimulation = new JMenu("Open & Reconfigure simulation"); menuConfOpenSimulation.setMnemonic(KeyEvent.VK_R); menu.add(menuConfOpenSimulation); menuItem = new JMenuItem("Save simulation"); menuItem.setMnemonic(KeyEvent.VK_S); menuItem.setActionCommand("save sim"); menuItem.addActionListener(guiEventHandler); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem("Close all plugins"); menuItem.setActionCommand("close plugins"); menuItem.addActionListener(guiEventHandler); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem("Exit"); menuItem.setMnemonic(KeyEvent.VK_X); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK)); menuItem.setActionCommand("quit"); menuItem.addActionListener(guiEventHandler); menu.add(menuItem); // Simulation menu menu = new JMenu("Simulation"); menu.setMnemonic(KeyEvent.VK_S); menuBar.add(menu); menuItem = new JMenuItem("Open Control"); menuItem.setMnemonic(KeyEvent.VK_C); menuItem.setActionCommand("start plugin"); menuItem.putClientProperty("class", SimControl.class); menuItem.addActionListener(guiEventHandler); menu.add(menuItem); menuItem = new JMenuItem("Information"); menuItem.setMnemonic(KeyEvent.VK_I); menuItem.setActionCommand("start plugin"); menuItem.putClientProperty("class", SimInformation.class); menuItem.addActionListener(guiEventHandler); menu.add(menuItem); // Mote type menu menu = new JMenu("Mote Types"); menu.setMnemonic(KeyEvent.VK_T); menuBar.add(menu); // Mote type classes sub menu menuMoteTypeClasses = new JMenu("Create mote type"); menuMoteTypeClasses.setMnemonic(KeyEvent.VK_C); menuMoteTypeClasses.addMenuListener(new MenuListener() { public void menuSelected(MenuEvent e) { // Clear menu menuMoteTypeClasses.removeAll(); // Recreate menu items JMenuItem menuItem; for (Class<? extends MoteType> moteTypeClass : moteTypeClasses) { String description = GUI.getDescriptionOf(moteTypeClass); menuItem = new JMenuItem(description); menuItem.setActionCommand("create mote type"); menuItem.putClientProperty("class", moteTypeClass); menuItem.addActionListener(guiEventHandler); menuMoteTypeClasses.add(menuItem); } } public void menuDeselected(MenuEvent e) { } public void menuCanceled(MenuEvent e) { } }); menu.add(menuMoteTypeClasses); menuItem = new JMenuItem("Information"); menuItem.setActionCommand("start plugin"); menuItem.putClientProperty("class", MoteTypeInformation.class); menuItem.addActionListener(guiEventHandler); menu.add(menuItem); // Mote menu menu = new JMenu("Motes"); menu.setMnemonic(KeyEvent.VK_M); menuBar.add(menu); // Mote types sub menu menuMoteTypes = new JMenu("Add motes of type"); menuMoteTypes.setMnemonic(KeyEvent.VK_A); menuMoteTypes.addMenuListener(new MenuListener() { public void menuSelected(MenuEvent e) { // Clear menu menuMoteTypes.removeAll(); if (mySimulation == null) { return; } // Recreate menu items JMenuItem menuItem; for (MoteType moteType : mySimulation.getMoteTypes()) { menuItem = new JMenuItem(moteType.getDescription()); menuItem.setActionCommand("add motes"); menuItem.setToolTipText(getDescriptionOf(moteType.getClass())); menuItem.putClientProperty("motetype", moteType); menuItem.addActionListener(guiEventHandler); menuMoteTypes.add(menuItem); } } public void menuDeselected(MenuEvent e) { } public void menuCanceled(MenuEvent e) { } }); menu.add(menuMoteTypes); menuItem = new JMenuItem("Remove all motes"); menuItem.setActionCommand("remove all motes"); menuItem.addActionListener(guiEventHandler); menu.add(menuItem); // Plugins menu if (menuPlugins == null) { menuPlugins = new JMenu("Plugins"); } else { menuPlugins.setText("Plugins"); } menuPlugins.setMnemonic(KeyEvent.VK_P); menuBar.add(menuPlugins); // Settings menu menu = new JMenu("Settings"); menuBar.add(menu); menuItem = new JMenuItem("External tools paths"); menuItem.setActionCommand("edit paths"); menuItem.addActionListener(guiEventHandler); menu.add(menuItem); menuItem = new JMenuItem("Manage project directories"); menuItem.setActionCommand("manage projects"); menuItem.addActionListener(guiEventHandler); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem("Java version: " + System.getProperty("java.version") + " (" + System.getProperty("java.vendor") + ")"); menuItem.setEnabled(false); menu.add(menuItem); // Mote plugins popup menu (not available via menu bar) if (menuMotePluginClasses == null) { menuMotePluginClasses = new Vector<Class<? extends Plugin>>(); } return menuBar; } private static void configureFrame(final GUI gui, boolean createSimDialog) { // Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); Rectangle maxSize = GraphicsEnvironment.getLocalGraphicsEnvironment() .getMaximumWindowBounds(); // Create and set up the window. frame = new JFrame("COOJA Simulator"); if (maxSize != null) { frame.setMaximizedBounds(maxSize); } frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // Add menu bar frame.setJMenuBar(gui.createMenuBar()); JComponent newContentPane = gui.getDesktopPane(); newContentPane.setOpaque(true); frame.setContentPane(newContentPane); frame.setSize(700, 700); frame.setLocationRelativeTo(null); frame.addWindowListener(gui.guiEventHandler); // Restore last frame size and position if (frame != null) { int framePosX = Integer.parseInt(getExternalToolsSetting("FRAME_POS_X", "-1")); int framePosY = Integer.parseInt(getExternalToolsSetting("FRAME_POS_Y", "-1")); int frameWidth = Integer.parseInt(getExternalToolsSetting("FRAME_WIDTH", "-1")); int frameHeight = Integer.parseInt(getExternalToolsSetting("FRAME_HEIGHT", "-1")); if (framePosX >= 0 && framePosY >= 0 && frameWidth > 0 && frameHeight > 0) { frame.setLocation(framePosX, framePosY); frame.setSize(frameWidth, frameHeight); // Assume window was maximized if loaded size matches maximum bounds if (maxSize != null && framePosX == 0 && framePosY == 0 && frameWidth == maxSize.width && frameHeight == maxSize.height) { frame.setExtendedState(JFrame.MAXIMIZED_BOTH); } } } // Display the window. frame.setVisible(true); if (createSimDialog) { SwingUtilities.invokeLater(new Runnable() { public void run() { gui.doCreateSimulation(true); } }); } } /** * @return Current desktop pane (simulator visualizer) */ public JDesktopPane getDesktopPane() { return myDesktopPane; } /** * Quick-starts a simulation using given parameters. TODO Experimental code * * @param moteTypeID * Mote type ID (if null "mtype1" will be used) * @param projectDirs * GUI project directories * @param sensors * Contiki sensors (if null sensors will be scanned for) * @param coreInterfaces * COOJA core interfaces (if null interfaces will be scanned for) * @param userProcesses * Contiki user processes (if null processes all in given main file * will be added) * @param addAutostartProcesses * Should autostart processes automatically be added? * @param numberOfNodes * Number of nodes to add * @param areaSideLength * Side of node positioning square * @param delayTime * Initial delay time * @param simulationStartinge * Simulation automatically started? * @param filename * Main Contiki process file * @param contikiPath * Contiki path * @return True if simulation was quickstarted correctly */ private static boolean quickStartSimulation(String moteTypeID, Vector<String> projectDirs, Vector<String> sensors, Vector<String> coreInterfaces, Vector<String> userProcesses, boolean addAutostartProcesses, int numberOfNodes, double areaSideLength, int delayTime, boolean simulationStarting, String filename, String contikiPath) { // Create GUI and GUI frame (not visible yet) JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); logger.info("> Creating GUI and main frame (invisible)"); frame = new JFrame("COOJA Simulator"); frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // Create and set up the content pane. JDesktopPane desktop = new JDesktopPane(); desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); GUI gui = new GUI(desktop); // loads external settings and creates initial project config // Add menu bar frame.setSize(700, 700); frame.addWindowListener(gui.guiEventHandler); JComponent newContentPane = gui.getDesktopPane(); newContentPane.setOpaque(true); frame.setContentPane(newContentPane); frame.setLocationRelativeTo(null); // Set manual Contiki path if specified if (contikiPath != null) { setExternalToolsSetting("PATH_CONTIKI", contikiPath); } // Parse project directories and create config if (projectDirs == null) { projectDirs = new Vector<String>(); projectDirs.add("."); } // TODO Should add user prop projects as well here... logger.info("> Reparsing project directories and creating config"); for (String projectDir : projectDirs) { logger.info(">> Adding: " + projectDir); // Check if config file exists File configFile = new File(projectDir + File.separatorChar + PROJECT_CONFIG_FILENAME); if (!configFile.exists()) { logger.debug(">>> Creating empty cooja.config file"); try { configFile.createNewFile(); } catch (IOException e) { logger.fatal(">> Error when creating cooja.config file, aborting"); return false; } } gui.currentProjectDirs.add(new File(projectDir)); } try { gui.reparseProjectConfig(); } catch (ParseProjectsException e) { logger.fatal(">> Error when parsing project directories: " + e.getMessage()); return false; } // Check file permissions and paths logger.info("> Checking paths and file permissions"); if (moteTypeID == null) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -