List of usage examples for javax.swing KeyStroke getKeyStroke
public static KeyStroke getKeyStroke(int keyCode, int modifiers)
From source file:kr.ac.kaist.swrc.jhannanum.demo.GUIDemo.java
/** * Sets the GUI up and launch the demo.// www. j a v a2s. com */ public void run() { /////////////////////////////////////////////////////////////////// // Basic setting for the mainFrame /////////////////////////////////////////////////////////////////// mainFrame = new JFrame(); Toolkit kit = mainFrame.getToolkit(); Dimension windowSize = kit.getScreenSize(); mainFrame.setBounds(windowSize.width / 20, windowSize.height / 20, windowSize.width * 18 / 20, windowSize.height * 18 / 20); mainFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); mainFrame.setTitle("HanNanum Korean Morphological Analyzer - A Plug-in Component based System (GUI Demo)"); Font font = new Font("MonoSpaced", Font.PLAIN, 12); UIManager.put("TextArea.font", font); /////////////////////////////////////////////////////////////////// // Layout setting for the mainFrame /////////////////////////////////////////////////////////////////// mainFrame.setLayout(new BorderLayout()); mainFrame.getContentPane().add(createPaneCenter(), BorderLayout.CENTER); mainFrame.getContentPane().add(createPaneNorth(), BorderLayout.NORTH); /////////////////////////////////////////////////////////////////// // Menu Setting /////////////////////////////////////////////////////////////////// menuBar = new JMenuBar(); menuFile = new JMenu("File"); menuItemFileOpen = new JMenuItem("Open", KeyEvent.VK_O); menuHelp = new JMenu("Help"); menuItemHelp = new JMenuItem("Help", KeyEvent.VK_H); menuItemFileOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.ALT_MASK)); menuItemHelp.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, ActionEvent.ALT_MASK)); menuBar.add(menuFile); menuBar.add(menuHelp); menuFile.add(menuItemFileOpen); menuHelp.add(menuItemHelp); mainFrame.setJMenuBar(menuBar); /////////////////////////////////////////////////////////////////// // Event Handler Setting /////////////////////////////////////////////////////////////////// menuItemFileOpen.addActionListener(new SharedActionHandler()); menuItemHelp.addActionListener(new SharedActionHandler()); buttonActivate.addActionListener(new SharedActionHandler()); buttonAnalysis.addActionListener(new SharedActionHandler()); buttonReset.addActionListener(new SharedActionHandler()); radioMultiThread.addActionListener(new SharedActionHandler()); radioSingleThread.addActionListener(new SharedActionHandler()); listPluginMajor2.addMouseListener(new PluginListMouseListener(listPluginMajor2, listModelMajor2)); listPluginMajor3.addMouseListener(new PluginListMouseListener(listPluginMajor3, listModelMajor3)); listPluginSupplement1 .addMouseListener(new PluginListMouseListener(listPluginSupplement1, listModelSupplement1)); listPluginSupplement2 .addMouseListener(new PluginListMouseListener(listPluginSupplement2, listModelSupplement2)); listPluginSupplement3 .addMouseListener(new PluginListMouseListener(listPluginSupplement3, listModelSupplement3)); listPluginMajor2.setTransferHandler(new PluginTransferHandler(PluginInfo.PHASE2, PluginInfo.MAJOR)); listPluginMajor3.setTransferHandler(new PluginTransferHandler(PluginInfo.PHASE3, PluginInfo.MAJOR)); listPluginSupplement1 .setTransferHandler(new PluginTransferHandler(PluginInfo.PHASE1, PluginInfo.SUPPLEMENT)); listPluginSupplement2 .setTransferHandler(new PluginTransferHandler(PluginInfo.PHASE2, PluginInfo.SUPPLEMENT)); listPluginSupplement3 .setTransferHandler(new PluginTransferHandler(PluginInfo.PHASE3, PluginInfo.SUPPLEMENT)); listPluginSupplement1.setDropMode(DropMode.ON_OR_INSERT); listPluginSupplement2.setDropMode(DropMode.ON_OR_INSERT); listPluginSupplement3.setDropMode(DropMode.ON_OR_INSERT); listPluginMajor2.setDropMode(DropMode.ON_OR_INSERT); listPluginMajor3.setDropMode(DropMode.ON_OR_INSERT); listPluginMajor2.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); listPluginMajor3.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); listPluginSupplement1.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); listPluginSupplement2.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); listPluginSupplement3.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); listPluginMajor2.setDragEnabled(true); listPluginMajor3.setDragEnabled(true); listPluginSupplement1.setDragEnabled(true); listPluginSupplement2.setDragEnabled(true); listPluginSupplement3.setDragEnabled(true); tree.setDragEnabled(true); tempPlugin = new PluginInfo("", 0, 0); workflow = new Workflow(); // Show the main frame on the screen mainFrame.setVisible(true); for (int i = 0; i < tree.getRowCount(); i++) { tree.expandRow(i); } splitPaneTop.setDividerLocation(0.3); splitPaneBottom.setDividerLocation(0.5); }
From source file:TextComponentDemo.java
protected void addBindings() { InputMap inputMap = textPane.getInputMap(); // Ctrl-b to go backward one character KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_B, Event.CTRL_MASK); inputMap.put(key, DefaultEditorKit.backwardAction); // Ctrl-f to go forward one character key = KeyStroke.getKeyStroke(KeyEvent.VK_F, Event.CTRL_MASK); inputMap.put(key, DefaultEditorKit.forwardAction); // Ctrl-p to go up one line key = KeyStroke.getKeyStroke(KeyEvent.VK_P, Event.CTRL_MASK); inputMap.put(key, DefaultEditorKit.upAction); // Ctrl-n to go down one line key = KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK); inputMap.put(key, DefaultEditorKit.downAction); }
From source file:au.org.ala.delta.editor.ui.CharacterTree.java
public CharacterTree() { setToggleClickCount(0);// w ww . j av a2 s.c o m _characterListBehaviour = new CharacterListBehaviour(); _stateListBehaviour = new StateListBehaviour(); ToolTipManager.sharedInstance().registerComponent(this); addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (_doubleProcessingMouseEvent) { return; } if (!isEditing()) { int selectedRow = getClosestRowForLocation(e.getX(), e.getY()); if ((selectedRow >= 0) && (e.getClickCount() == 2) && SwingUtilities.isLeftMouseButton(e)) { Action action = getActionMap().get(SELECTION_ACTION_KEY); if (action != null) { action.actionPerformed(new ActionEvent(this, -1, "")); } } } } }); addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { TreePath selection = e.getNewLeadSelectionPath(); if (selection != null) { Object lastComponent = selection.getLastPathComponent(); if (lastComponent instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) lastComponent; if (node.isLeaf()) { CharacterTree.super.setTransferHandler(_stateTransferHandler); } else { CharacterTree.super.setTransferHandler(_characterTransferHandler); } } } } }); ActionMap actionMap = Application.getInstance().getContext().getActionMap(this); javax.swing.Action find = actionMap.get("find"); if (find != null) { getActionMap().put("find", find); } javax.swing.Action findNext = actionMap.get("findNext"); if (findNext != null) { getActionMap().put("findNext", findNext); } getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.CTRL_MASK), SELECTION_ACTION_KEY); }
From source file:net.chaosserver.timelord.swingui.TimelordMenu.java
/** * Creates the view menu./* w w w . j a va 2s . c om*/ * * @return the new view menu */ protected JMenu createViewMenu() { JMenuItem menuItem; JMenu viewMenu = new JMenu("View"); viewMenu.setMnemonic(KeyEvent.VK_V); JMenu annoyanceModeMenu = new JMenu("Annoyance Mode"); annoyanceJordanCheckbox = new JCheckBoxMenuItem("Jordan Mode"); annoyanceJordanCheckbox.setToolTipText("For Cool People"); annoyanceJordanCheckbox.setActionCommand(ACTION_ANNOY_JORDAN); annoyanceJordanCheckbox.addActionListener(this); annoyanceModeMenu.add(annoyanceJordanCheckbox); annoyanceDougCheckbox = new JCheckBoxMenuItem("Doug Mode"); annoyanceDougCheckbox.setToolTipText("For Losers"); annoyanceJordanCheckbox.setActionCommand(ACTION_ANNOY_DOUG); annoyanceDougCheckbox.addActionListener(this); annoyanceModeMenu.add(annoyanceDougCheckbox); annoyanceNoneCheckbox = new JCheckBoxMenuItem("None"); annoyanceJordanCheckbox.setActionCommand(ACTION_ANNOY_NONE); annoyanceNoneCheckbox.addActionListener(this); annoyanceModeMenu.add(annoyanceNoneCheckbox); updateAnnoyanceButtons(); viewMenu.add(annoyanceModeMenu); menuItem = new JMenuItem("Refresh View", KeyEvent.VK_R); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_R, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); menuItem.setActionCommand(ACTION_REFRESH_VIEW); menuItem.addActionListener(this); viewMenu.add(menuItem); viewMenu.addSeparator(); menuItem = new JMenuItem("Change Start Time"); menuItem.setActionCommand(ACTION_CHANGE_START); menuItem.addActionListener(this); viewMenu.add(menuItem); menuItem = new JMenuItem("Change Annoy Time"); // currently disabled experimental functionality menuItem.setEnabled(false); menuItem.setActionCommand(ACTION_CHANGE_ANNOY); menuItem.addActionListener(this); viewMenu.add(menuItem); viewMenu.addSeparator(); menuItem = new JMenuItem("Select Previous Tab", KeyEvent.VK_BRACELEFT); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_BRACELEFT, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); menuItem.setActionCommand(ACTION_PREVIOUS_TAB); menuItem.addActionListener(this); viewMenu.add(menuItem); menuItem = new JMenuItem("Select Next Tab", KeyEvent.VK_BRACERIGHT); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_BRACERIGHT, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); menuItem.setActionCommand(ACTION_NEXT_TAB); menuItem.addActionListener(this); viewMenu.add(menuItem); return viewMenu; }
From source file:edu.brown.gui.CatalogViewer.java
/** * /* w w w.j a va 2 s . com*/ */ protected void viewerInit() { // ---------------------------------------------- // MENU // ---------------------------------------------- JMenu menu; JMenuItem menuItem; // // File Menu // menu = new JMenu("File"); menu.getPopupMenu().setLightWeightPopupEnabled(false); menu.setMnemonic(KeyEvent.VK_F); menu.getAccessibleContext().setAccessibleDescription("File Menu"); menuBar.add(menu); menuItem = new JMenuItem("Open Catalog From File"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Open Catalog From File"); menuItem.addActionListener(this.menuHandler); menuItem.putClientProperty(MenuHandler.MENU_ID, MenuOptions.CATALOG_OPEN_FILE); menu.add(menuItem); menuItem = new JMenuItem("Open Catalog From Jar"); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Open Catalog From Project Jar"); menuItem.addActionListener(this.menuHandler); menuItem.putClientProperty(MenuHandler.MENU_ID, MenuOptions.CATALOG_OPEN_JAR); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem("Quit", KeyEvent.VK_Q); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Quit Program"); menuItem.addActionListener(this.menuHandler); menuItem.putClientProperty(MenuHandler.MENU_ID, MenuOptions.QUIT); menu.add(menuItem); // ---------------------------------------------- // CATALOG TREE PANEL // ---------------------------------------------- this.catalogTree = new JTree(); this.catalogTree.setEditable(false); this.catalogTree.setCellRenderer(new CatalogViewer.CatalogTreeRenderer()); this.catalogTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); this.catalogTree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) CatalogViewer.this.catalogTree .getLastSelectedPathComponent(); if (node == null) return; Object user_obj = node.getUserObject(); String new_text = ""; // <html>"; boolean text_mode = true; if (user_obj instanceof WrapperNode) { CatalogType catalog_obj = ((WrapperNode) user_obj).getCatalogType(); new_text += CatalogViewer.this.getAttributesText(catalog_obj); } else if (user_obj instanceof AttributesNode) { AttributesNode wrapper = (AttributesNode) user_obj; new_text += wrapper.getAttributes(); } else if (user_obj instanceof PlanTreeCatalogNode) { final PlanTreeCatalogNode wrapper = (PlanTreeCatalogNode) user_obj; text_mode = false; CatalogViewer.this.mainPanel.remove(0); CatalogViewer.this.mainPanel.add(wrapper.getPanel(), BorderLayout.CENTER); CatalogViewer.this.mainPanel.validate(); CatalogViewer.this.mainPanel.repaint(); if (SwingUtilities.isEventDispatchThread() == false) { SwingUtilities.invokeLater(new Runnable() { public void run() { wrapper.centerOnRoot(); } }); } else { wrapper.centerOnRoot(); } } else { new_text += CatalogViewer.this.getSummaryText(); } // Text Mode if (text_mode) { if (CatalogViewer.this.text_mode == false) { CatalogViewer.this.mainPanel.remove(0); CatalogViewer.this.mainPanel.add(CatalogViewer.this.textInfoPanel); } CatalogViewer.this.textInfoTextArea.setText(new_text); // Scroll to top CatalogViewer.this.textInfoTextArea.grabFocus(); } CatalogViewer.this.text_mode = text_mode; } }); this.generateCatalogTree(this.catalog, this.catalog_file_path.getName()); // // Text Information Panel // this.textInfoPanel = new JPanel(); this.textInfoPanel.setLayout(new BorderLayout()); this.textInfoTextArea = new JTextArea(); this.textInfoTextArea.setEditable(false); this.textInfoTextArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); this.textInfoTextArea.setText(this.getSummaryText()); this.textInfoTextArea.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent e) { // TODO Auto-generated method stub } @Override public void focusGained(FocusEvent e) { CatalogViewer.this.scrollTextInfoToTop(); } }); this.textInfoScroller = new JScrollPane(this.textInfoTextArea); this.textInfoPanel.add(this.textInfoScroller, BorderLayout.CENTER); this.mainPanel = new JPanel(new BorderLayout()); this.mainPanel.add(textInfoPanel, BorderLayout.CENTER); // // Search Toolbar // JPanel searchPanel = new JPanel(); searchPanel.setLayout(new BorderLayout()); JPanel innerSearchPanel = new JPanel(); innerSearchPanel.setLayout(new BoxLayout(innerSearchPanel, BoxLayout.X_AXIS)); innerSearchPanel.add(new JLabel("Search: ")); this.searchField = new JTextField(30); innerSearchPanel.add(this.searchField); searchPanel.add(innerSearchPanel, BorderLayout.EAST); this.searchField.addKeyListener(new KeyListener() { private String last = null; @Override public void keyReleased(KeyEvent e) { String value = CatalogViewer.this.searchField.getText().toLowerCase().trim(); if (!value.isEmpty() && (this.last == null || !this.last.equals(value))) { CatalogViewer.this.search(value); } this.last = value; } @Override public void keyTyped(KeyEvent e) { // Do nothing... } @Override public void keyPressed(KeyEvent e) { // Do nothing... } }); // Putting it all together JScrollPane scrollPane = new JScrollPane(this.catalogTree); JPanel topPanel = new JPanel(); topPanel.setLayout(new BorderLayout()); topPanel.add(searchPanel, BorderLayout.NORTH); topPanel.add(scrollPane, BorderLayout.CENTER); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, topPanel, this.mainPanel); splitPane.setDividerLocation(400); this.add(splitPane, BorderLayout.CENTER); }
From source file:TextComponentDemo.java
protected void addBindings() { InputMap inputMap = textPane.getInputMap(); //Ctrl-b to go backward one character KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_B, Event.CTRL_MASK); inputMap.put(key, DefaultEditorKit.backwardAction); //Ctrl-f to go forward one character key = KeyStroke.getKeyStroke(KeyEvent.VK_F, Event.CTRL_MASK); inputMap.put(key, DefaultEditorKit.forwardAction); //Ctrl-p to go up one line key = KeyStroke.getKeyStroke(KeyEvent.VK_P, Event.CTRL_MASK); inputMap.put(key, DefaultEditorKit.upAction); //Ctrl-n to go down one line key = KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK); inputMap.put(key, DefaultEditorKit.downAction); }
From source file:com.digitalgeneralists.assurance.ui.MainWindow.java
private void initializeComponent() { if (!this.initialized) { logger.info("Initializing the main window."); if (AssuranceUtils.getPlatform() == Platform.MAC) { System.setProperty("apple.laf.useScreenMenuBar", "true"); com.apple.eawt.Application macApplication = com.apple.eawt.Application.getApplication(); MacApplicationAdapter macAdapter = new MacApplicationAdapter(this); macApplication.addApplicationListener(macAdapter); macApplication.setEnabledPreferencesMenu(true); }//from ww w. j a va 2s. c o m this.setTitle(Application.applicationShortName); this.setDefaultCloseOperation(EXIT_ON_CLOSE); GridBagLayout gridbag = new GridBagLayout(); this.setLayout(gridbag); this.topArea = new JTabbedPane(); this.scanLaunchPanel.setPreferredSize(new Dimension(600, 150)); this.scanHistoryPanel.setPreferredSize(new Dimension(600, 150)); this.topArea.addTab("Scan", this.scanLaunchPanel); this.topArea.addTab("History", this.scanHistoryPanel); this.resultsPanel.setPreferredSize(new Dimension(600, 400)); this.topArea.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { resultsPanel.resetPanel(); // NOTE: This isn't ideal. It feels brittle. if (topArea.getSelectedIndex() == viewHistoryMenuItemIndex) { viewHistoryMenuItem.setSelected(true); } else { viewScanMenuItem.setSelected(true); } } }); GridBagConstraints topPanelConstraints = new GridBagConstraints(); topPanelConstraints.anchor = GridBagConstraints.NORTH; topPanelConstraints.fill = GridBagConstraints.BOTH; topPanelConstraints.gridx = 0; topPanelConstraints.gridy = 0; topPanelConstraints.weightx = 1.0; topPanelConstraints.weighty = 0.33; topPanelConstraints.gridheight = 1; topPanelConstraints.gridwidth = 1; topPanelConstraints.insets = new Insets(0, 0, 0, 0); this.getContentPane().add(this.topArea, topPanelConstraints); GridBagConstraints resultsPanelConstraints = new GridBagConstraints(); resultsPanelConstraints.anchor = GridBagConstraints.SOUTH; resultsPanelConstraints.fill = GridBagConstraints.BOTH; resultsPanelConstraints.gridx = 0; resultsPanelConstraints.gridy = 1; resultsPanelConstraints.weightx = 1.0; resultsPanelConstraints.weighty = 0.67; resultsPanelConstraints.gridheight = 1; resultsPanelConstraints.gridwidth = 1; resultsPanelConstraints.insets = new Insets(0, 0, 0, 0); this.getContentPane().add(this.resultsPanel, resultsPanelConstraints); this.applicationDelegate.addEventObserver(ScanStartedEvent.class, this); this.applicationDelegate.addEventObserver(ScanCompletedEvent.class, this); this.applicationDelegate.addEventObserver(SetScanDefinitionMenuStateEvent.class, this); this.applicationDelegate.addEventObserver(SetScanResultsMenuStateEvent.class, this); this.applicationDelegate.addEventObserver(ApplicationConfigurationLoadedEvent.class, this); JMenu menu; JMenuItem menuItem; menuBar = new JMenuBar(); StringBuilder accessiblityLabel = new StringBuilder(128); if (AssuranceUtils.getPlatform() != Platform.MAC) { menu = new JMenu(Application.applicationShortName); menu.getAccessibleContext().setAccessibleDescription(accessiblityLabel.append("Actions for ") .append(Application.applicationShortName).append(" application").toString()); accessiblityLabel.setLength(0); menuBar.add(menu); menuItem = new JMenuItem(MainWindow.quitApplicationMenuLabel, KeyEvent.VK_Q); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext().setAccessibleDescription(accessiblityLabel.append("Close the ") .append(Application.applicationShortName).append(" application").toString()); accessiblityLabel.setLength(0); menuItem.addActionListener(this); menuItem.setActionCommand(AssuranceActions.quitApplicationAction); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(MainWindow.aboutApplicationMenuLabel); menuItem.getAccessibleContext().setAccessibleDescription( accessiblityLabel.append("Display information about this version of ") .append(Application.applicationShortName).append(".").toString()); accessiblityLabel.setLength(0); menuItem.addActionListener(this); menuItem.setActionCommand(AssuranceActions.aboutApplicationAction); menu.add(menuItem); } menu = new JMenu("Scan"); menu.setMnemonic(KeyEvent.VK_S); menu.getAccessibleContext().setAccessibleDescription("Actions for file scans"); menuBar.add(menu); menuItem = new JMenuItem(MainWindow.newScanDefinitonMenuLabel, KeyEvent.VK_N); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Create a new scan definition"); menuItem.addActionListener(this.scanLaunchPanel); menuItem.setActionCommand(AssuranceActions.newScanDefinitonAction); menu.add(menuItem); menuItem = new JMenuItem(MainWindow.deleteScanDefinitonMenuLabel, KeyEvent.VK_D); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Delete the selected scan definition"); menuItem.addActionListener(this.scanLaunchPanel); menuItem.setActionCommand(AssuranceActions.deleteScanDefinitonAction); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(MainWindow.scanMenuLabel, KeyEvent.VK_S); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext() .setAccessibleDescription("Launch a scan using the selected scan definition"); menuItem.addActionListener(this.scanLaunchPanel); menuItem.setActionCommand(AssuranceActions.scanAction); menu.add(menuItem); menuItem = new JMenuItem(MainWindow.scanAndMergeMenuLabel, KeyEvent.VK_M); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext().setAccessibleDescription( "Launch a scan using the selected scan definition and merge the results"); menuItem.addActionListener(this.scanLaunchPanel); menuItem.setActionCommand(AssuranceActions.scanAndMergeAction); menu.add(menuItem); menu = new JMenu("Results"); menu.setMnemonic(KeyEvent.VK_R); menu.getAccessibleContext().setAccessibleDescription("Actions for scan results"); menuBar.add(menu); menuItem = new JMenuItem(MainWindow.replaceSourceMenuLabel, KeyEvent.VK_O); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext() .setAccessibleDescription("Replace the source file with the target file"); menuItem.addActionListener(this.resultsPanel.getResultMenuListener()); menuItem.setActionCommand(AssuranceActions.replaceSourceAction); menu.add(menuItem); menuItem = new JMenuItem(MainWindow.replaceTargetMenuLabel, KeyEvent.VK_T); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext() .setAccessibleDescription("Replace the target file with the source file"); menuItem.addActionListener(this.resultsPanel.getResultMenuListener()); menuItem.setActionCommand(AssuranceActions.replaceTargetAction); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(MainWindow.sourceAttributesMenuLabel); menuItem.getAccessibleContext().setAccessibleDescription("View the source file attributes"); menuItem.addActionListener(this.resultsPanel.getResultMenuListener()); menuItem.setActionCommand(AssuranceActions.sourceAttributesAction); menu.add(menuItem); menuItem = new JMenuItem(MainWindow.targetAttributesMenuLabel); menuItem.getAccessibleContext().setAccessibleDescription("View the target file attributes"); menuItem.addActionListener(this.resultsPanel.getResultMenuListener()); menuItem.setActionCommand(AssuranceActions.targetAttributesAction); menu.add(menuItem); menu = new JMenu("View"); menu.setMnemonic(KeyEvent.VK_V); menu.getAccessibleContext().setAccessibleDescription( accessiblityLabel.append("Views within ").append(Application.applicationShortName).toString()); accessiblityLabel.setLength(0); menuBar.add(menu); ButtonGroup group = new ButtonGroup(); this.viewScanMenuItem = new JRadioButtonMenuItem(MainWindow.viewScanMenuLabel); this.viewScanMenuItem.addActionListener(this); this.viewScanMenuItem.setActionCommand(AssuranceActions.viewScanAction); this.viewScanMenuItem.setSelected(true); group.add(this.viewScanMenuItem); menu.add(this.viewScanMenuItem); this.viewHistoryMenuItem = new JRadioButtonMenuItem(MainWindow.viewHistoryMenuLabel); this.viewHistoryMenuItem.addActionListener(this); this.viewHistoryMenuItem.setActionCommand(AssuranceActions.viewHistoryAction); this.viewHistoryMenuItem.setSelected(true); group.add(this.viewHistoryMenuItem); menu.add(this.viewHistoryMenuItem); if (AssuranceUtils.getPlatform() != Platform.MAC) { menu = new JMenu("Tools"); menu.getAccessibleContext() .setAccessibleDescription(accessiblityLabel.append("Additional actions for ") .append(Application.applicationShortName).append(" application").toString()); accessiblityLabel.setLength(0); menuBar.add(menu); menuItem = new JMenuItem(MainWindow.settingsMenuLabel, KeyEvent.VK_COMMA); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_COMMA, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext() .setAccessibleDescription(accessiblityLabel.append("Change settings for the ") .append(Application.applicationShortName).append(" application").toString()); accessiblityLabel.setLength(0); menuItem.addActionListener(this); menuItem.setActionCommand(AssuranceActions.displaySettingsAction); menu.add(menuItem); } this.setJMenuBar(menuBar); this.initialized = true; } }
From source file:de.freese.base.swing.mac_os_x.MyApp.java
/** * *//* ww w.j a va 2 s . com*/ public void addMenus() { JMenu fileMenu = new JMenu("File"); JMenuBar mainMenuBar = new JMenuBar(); mainMenuBar.add(fileMenu = new JMenu("File")); fileMenu.add(this.openMI = new JMenuItem("Open...")); this.openMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, MENU_MASK)); this.openMI.addActionListener(this); // Quit/prefs menu items are provided on Mac OS X; only add your own on other platforms if (!IS_OS_MAC_OSX) { fileMenu.addSeparator(); fileMenu.add(this.optionsMI = new JMenuItem("Options")); this.optionsMI.addActionListener(this); fileMenu.addSeparator(); fileMenu.add(this.quitMI = new JMenuItem("Quit")); this.quitMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, MENU_MASK)); this.quitMI.addActionListener(this); } mainMenuBar.add(this.helpMenu = new JMenu("Help")); this.helpMenu.add(this.docsMI = new JMenuItem("Online Documentation")); this.helpMenu.addSeparator(); this.helpMenu.add(this.supportMI = new JMenuItem("Technical Support")); // About menu item is provided on Mac OS X; only add your own on other platforms if (!IS_OS_MAC_OSX) { this.helpMenu.addSeparator(); this.helpMenu.add(this.aboutMI = new JMenuItem("About OSXAdapter")); this.aboutMI.addActionListener(this); } setJMenuBar(mainMenuBar); }
From source file:org.pgptool.gui.ui.mainframe.MainFrameView.java
@SuppressWarnings("serial") private void initTableKeyListener() { InputMap inputMap = table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), DELETE); table.getActionMap().put(DELETE, new AbstractAction() { @Override/*from w ww . j a v a 2s . c om*/ public void actionPerformed(ActionEvent e) { if (pm == null) { return; } pm.actionDelete.actionPerformed(e); } }); InputMap inputMap2 = table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); inputMap2.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), CHOOSE); table.getActionMap().put(CHOOSE, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (pm == null) { return; } pm.actionOpen.actionPerformed(e); } }); }
From source file:com.intuit.tank.tools.debugger.ActionProducer.java
/** * // ww w . ja v a 2 s. co m * @return */ public Action getFindAction() { Action ret = actionMap.get(ACTION_FIND); if (ret == null) { ret = new AbstractAction(ACTION_FIND, getIcon("find.png", IconSize.SMALL)) { private static final long serialVersionUID = 1L; private FindReplaceDialog dialog; @Override public void actionPerformed(ActionEvent event) { try { if (dialog == null) { dialog = new FindReplaceDialog(debuggerFrame, DialogType.SEARCH); } dialog.setVisible(true); } catch (HeadlessException e) { showError("Error opening file: " + e); } } }; ret.putValue(Action.SHORT_DESCRIPTION, "Find in script."); ret.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke('F', menuActionMods)); ret.putValue(Action.MNEMONIC_KEY, new Integer('F')); ret.setEnabled(false); actionMap.put(ACTION_FIND, ret); } return ret; }