private static JMenuItem getMenuItem_ShowTabs() { final JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem("Panel Tabs"); menuItem.setAccelerator(MenuUtil.getAcceleratorKey(KeyEvent.VK_T)); menuItem.setState(!prefs.getPrefBoolean(FPref.UI_HIDE_GAME_TABS)); menuItem.addActionListener(getShowTabsAction(menuItem)); return menuItem; }
public static JCheckBoxMenuItem createMenuItem2(Action a, char m, int key, HotKey hotKey) { JCheckBoxMenuItem res = new JCheckBoxMenuItem(a); res.setMnemonic(m); int mask = getMask(hotKey); if (key != 0) res.setAccelerator(KeyStroke.getKeyStroke(key, mask)); return res; }
private JMenuBar createMenuBar() { JMenu menu = new JMenu("Menu"); disablingItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.ALT_MASK)); menu.add(disablingItem); menu.addSeparator(); blurItem.setSelected(true); blurItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, InputEvent.ALT_MASK)); menu.add(blurItem); embossItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, InputEvent.ALT_MASK)); menu.add(embossItem); busyPainterItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3, InputEvent.ALT_MASK)); menu.add(busyPainterItem); ButtonGroup group = new ButtonGroup(); group.add(blurItem); group.add(embossItem); group.add(busyPainterItem); ItemListener menuListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (blurItem.isSelected()) { // layer.setUI(blurUI); } else if (embossItem.isSelected()) { // layer.setUI(embossUI); } else if (busyPainterItem.isSelected()) { layer.setUI(busyPainterUI); } } }; blurItem.addItemListener(menuListener); embossItem.addItemListener(menuListener); busyPainterItem.addItemListener(menuListener); // embossUI.getUnlockButton().addActionListener(new ActionListener() { // public void actionPerformed(ActionEvent e) { // disablingItem.doClick(); // } // }); JMenuBar bar = new JMenuBar(); bar.add(menu); bar.add(new LafMenu()); return bar; }
/** * Intilizes all the menu buttons to their respective menu structure, associates action listeners * and sets mnemonics for all menu buttons. */ private void buildMenu() { mnuNew.setAccelerator(KeyStroke.getKeyStroke("ctrl N")); mnuOpen.setAccelerator(KeyStroke.getKeyStroke("ctrl O")); mnuSave.setAccelerator(KeyStroke.getKeyStroke("ctrl S")); mnuGenRep.setAccelerator(KeyStroke.getKeyStroke("ctrl G")); mnuClearConsole.setAccelerator(KeyStroke.getKeyStroke("F3")); mnuRefreshNodeInformation.setAccelerator(KeyStroke.getKeyStroke("F4")); mnuMsgLinkLayer.setAccelerator(KeyStroke.getKeyStroke("F9")); mnuMsgNetwork.setAccelerator(KeyStroke.getKeyStroke("F10")); mnuMsgTransport.setAccelerator(KeyStroke.getKeyStroke("F11")); mnuMsgApplication.setAccelerator(KeyStroke.getKeyStroke("F12")); mnuHelpPane.setAccelerator(KeyStroke.getKeyStroke("F1")); mnuExit.setAccelerator(KeyStroke.getKeyStroke("ctrl + Q")); mnuLayers.setAccelerator(KeyStroke.getKeyStroke("F7")); mnuPackets.setAccelerator(KeyStroke.getKeyStroke("F8")); // Add items to file menu mnuFile.add(mnuNew); mnuFile.add(mnuOpen); mnuFile.add(mnuSave); mnuFile.add(mnuSaveAs); mnuFile.addSeparator(); mnuFile.add(mnuImport); mnuFile.add(mnuGenRep); mnuFile.addSeparator(); mnuFile.add(mnuExit); // Add items to simulation menu mnuSimulation.add(mnuAdd); mnuEnvironment.add(mnuClearConsole); mnuEnvironment.add(mnuRefreshNodeInformation); mnuEnvironment.add(mnuFilters); mnuEnvironment.add(mnuFilters2); mnuFilters2.add(mnuLayers); mnuFilters2.add(mnuPackets); mnuFilters.add(mnuMsgLinkLayer); // mnuFilters.add(mnuMsgARP); mnuFilters.add(mnuMsgNetwork); mnuFilters.add(mnuMsgTransport); mnuFilters.add(mnuMsgApplication); // Add items to help mnuHelp.add(mnuHelpPane); mnuHelp.add(mnuAbout); // Set up Mnemonics for menu bar. mnuFile.setMnemonic('F'); mnuNew.setMnemonic('N'); mnuOpen.setMnemonic('O'); mnuSave.setMnemonic('S'); mnuSaveAs.setMnemonic('a'); mnuExit.setMnemonic('x'); mnuSimulation.setMnemonic('S'); mnuAdd.setMnemonic('A'); mnuGenRep.setMnemonic('G'); mnuEnvironment.setMnemonic('E'); mnuClearConsole.setMnemonic('C'); mnuRefreshNodeInformation.setMnemonic('N'); mnuHelp.setMnemonic('H'); mnuAbout.setMnemonic('A'); // Add action listener to generate html report menuitem mnuGenRep.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { controller.Export(); } }); mnuMsgLinkLayer.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { controller.setFilter(0, !controller.getFilter(0)); } }); mnuLayers.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { controller.setFilter2(1, !controller.getFilter2(1)); } }); mnuPackets.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { controller.setFilter2(0, !controller.getFilter2(0)); } }); mnuMsgARP.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { controller.setFilter(1, !controller.getFilter(1)); } }); mnuMsgNetwork.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { controller.setFilter(2, !controller.getFilter(2)); } }); mnuMsgTransport.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { controller.setFilter(3, !controller.getFilter(3)); } }); mnuMsgApplication.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { controller.setFilter(4, !controller.getFilter(4)); } }); // Add action listener to exit mnuExit.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // int result = JOptionPane // .showConfirmDialog(null, // "Are you sure you wish to quit?", // "Really Quit?", JOptionPane.YES_NO_OPTION, // JOptionPane.QUESTION_MESSAGE); // // if (result == JOptionPane.YES_OPTION) { // // Quit the program if Yes is selected. controller.quit(); // } } }); // Add action listener to Save menu item mnuSave.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // JOptionPane.showMessageDialog(null,"Sorry this is not yet // implemented.","Save Dialog Message", // JOptionPane.INFORMATION_MESSAGE); controller.Save(); } }); // Add action listener to Save As menu item mnuSaveAs.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // JOptionPane.showMessageDialog(null,"Sorry this is not yet // implemented.","SaveAs Dialog Message", // JOptionPane.INFORMATION_MESSAGE); controller.SaveAs(null); } }); // Add action listener to Save menu item mnuOpen.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // JOptionPane.showMessageDialog(null,"Sorry this is not yet // implemented.","Open Dialog Message", // JOptionPane.INFORMATION_MESSAGE); controller.Open(); } }); // Add action listener to Save menu item mnuImport.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { controller.Import(); } }); // Add action listener to New menu item mnuNew.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { controller.clearSaveAs(); controller.refreshMainScreen(); } }); mnuAbout.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // Display message box with info about the project. String strAboutProject; strAboutProject = "javaNetSim " + Version.CORE_VERSION + "\n\n"; for (int i = 0; i < Version.TEAM_MEMBERS.length; i++) { strAboutProject = strAboutProject + Version.TEAM_MEMBERS[i] + "\n"; } JOptionPane.showMessageDialog( null, strAboutProject, "About javaNetSim", JOptionPane.INFORMATION_MESSAGE); } }); mnuClearConsole.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { controller.clearConsole(); } }); mnuRefreshNodeInformation.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { controller.refreshNodeInformationTab(); } }); mnuHelpPane.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { controller.showHelpPane(); } }); // Add menu's to menubar this.add(mnuFile); this.add(mnuSimulation); this.add(mnuEnvironment); this.add(mnuHelp); }
public SpeedyGraderInterface() { super("SpeedyGrader"); this.setSize(1000, 500); BufferedImage icon = null; try { icon = ImageIO.read(new File("img" + File.separator + "speedygrader-icon.png")); } catch (IOException e) { try { icon = ImageIO.read(SpeedyGraderInterface.class.getResourceAsStream("/speedygrader-icon.png")); } catch (IOException e2) { e2.printStackTrace(); } } this.setIconImage(icon); textFont = new Font("Consolas", 0, 16); menuBar = new JMenuBar(); JMenu fileMenu = new JMenu(" File "); fileMenu.setMnemonic(KeyEvent.VK_F); openItem = new JMenuItem("Select Folder"); openItem.setToolTipText("The folder that contains the source files."); openItem.addActionListener(this); openItem.setFont(textFont); openItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)); inputItem = new JMenuItem("Set Input"); inputItem.addActionListener(this); inputItem.setFont(textFont); inputItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, ActionEvent.CTRL_MASK)); saveItem = new JMenuItem("Save All and Run"); saveItem.addActionListener(this); saveItem.setFont(textFont); saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)); fileMenu.add(openItem); fileMenu.add(inputItem); fileMenu.add(saveItem); JMenu optionsMenu = new JMenu(" Options "); optionsMenu.setMnemonic(KeyEvent.VK_O); refreshItem = new JMenuItem("Refresh Folder"); refreshItem.setFont(textFont); refreshItem.addActionListener(this); refreshItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK)); optionsMenu.add(refreshItem); timeoutPrograms = new JCheckBoxMenuItem("Timeout Programs"); timeoutPrograms.setSelected(true); timeoutPrograms.setFont(textFont); timeoutPrograms.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.CTRL_MASK)); optionsMenu.add(timeoutPrograms); editorSplitToggle = new JCheckBoxMenuItem("Split editor/console vertically"); editorSplitToggle.setSelected(true); editorSplitToggle.setFont(textFont); editorSplitToggle.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK | ActionEvent.ALT_MASK)); editorSplitToggle.addActionListener(this); optionsMenu.add(editorSplitToggle); JMenu helpMenu = new JMenu(" Help "); helpMenu.setMnemonic(KeyEvent.VK_H); aboutItem = new JMenuItem("About"); aboutItem.setFont(textFont); aboutItem.addActionListener(this); aboutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK)); helpMenu.add(aboutItem); githubItem = new JMenuItem("Open Github"); githubItem.setFont(textFont); githubItem.addActionListener(this); githubItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, ActionEvent.CTRL_MASK)); helpMenu.add(githubItem); upgradeItem = new JMenuItem("Check for Update"); upgradeItem.setFont(textFont); upgradeItem.addActionListener(this); upgradeItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, ActionEvent.CTRL_MASK)); helpMenu.add(upgradeItem); installItem = new JMenuItem("Install Instructions"); installItem.setFont(textFont); installItem.addActionListener(this); installItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_I, ActionEvent.CTRL_MASK | ActionEvent.ALT_MASK)); helpMenu.add(installItem); menuBar.add(fileMenu); menuBar.add(optionsMenu); menuBar.add(helpMenu); this.setJMenuBar(menuBar); filesList = new JList<SourceFile>(); filesList.setSelectionMode(JList.VERTICAL); filesList.setLayoutOrientation(JList.VERTICAL); filesList.setVisibleRowCount(-1); filesList.addListSelectionListener(this); filesList.setFont(textFont); filesListModel = new DefaultListModel<SourceFile>(); filesList.setModel(filesListModel); tabbedPane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT); editorPanels = new ArrayList<EditorPanel>(); consoleTextArea = new JTextArea(); consoleTextArea.setEditable(false); consoleTextArea.setFont(textFont); splitEditorPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); splitEditorPane.add(tabbedPane); splitEditorPane.add(new JScrollPane(consoleTextArea)); splitEditorPane.setDividerLocation(.8); splitMainPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); splitMainPane.add(new JScrollPane(filesList)); splitMainPane.add(splitEditorPane); splitMainPane.setDividerLocation(.2); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setLocationRelativeTo(null); this.add(splitMainPane); this.setVisible(true); }