Example usage for javax.swing.event MenuKeyListener MenuKeyListener

List of usage examples for javax.swing.event MenuKeyListener MenuKeyListener

Introduction

In this page you can find the example usage for javax.swing.event MenuKeyListener MenuKeyListener.

Prototype

MenuKeyListener

Source Link

Usage

From source file:ContructMenuMenuKeyListener.java

License:asdf

public static void main(final String args[]) {
    JFrame frame = new JFrame("MenuSample Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuBar menuBar = new JMenuBar();

    // File Menu, F - Mnemonic
    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);
    menuBar.add(fileMenu);//w w  w.  ja v  a  2s.  c o  m

    // File->New, N - Mnemonic
    JMenuItem newMenuItem = new JMenuItem("asdf");
    fileMenu.add(newMenuItem);

    newMenuItem.addMenuKeyListener(new MenuKeyListener() {

        public void menuKeyTyped(MenuKeyEvent e) {
            System.out.println("KeyTyped");
        }

        public void menuKeyPressed(MenuKeyEvent e) {
            System.out.println("KeyPressed");
        }

        public void menuKeyReleased(MenuKeyEvent e) {
            System.out.println("KeyReleased");
        }
    });

    frame.setJMenuBar(menuBar);
    frame.setSize(350, 250);
    frame.setVisible(true);
}

From source file:org.openmicroscopy.shoola.agents.fsimporter.view.ImporterControl.java

/** Attaches listener to the window listener. */
private void attachListeners() {
    if (UIUtilities.isMacOS() && model.isMaster()) {
        try {/*from   www . j  a  v  a2 s  .  c  o m*/
            MacOSMenuHandler handler = new MacOSMenuHandler(view);
            handler.initialize();
            view.addPropertyChangeListener(this);
        } catch (Throwable e) {
        }
    }
    view.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    view.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            model.close();
        }
    });
    JMenu menu = ImporterFactory.getWindowMenu();
    menu.addMenuListener(new MenuListener() {

        public void menuSelected(MenuEvent e) {
            Object source = e.getSource();
            if (source instanceof JMenu)
                createWindowsMenuItems((JMenu) source);
        }

        /** 
         * Required by I/F but not actually needed in our case, 
         * no-operation implementation.
         * @see MenuListener#menuCanceled(MenuEvent)
         */
        public void menuCanceled(MenuEvent e) {
        }

        /** 
         * Required by I/F but not actually needed in our case, 
         * no-operation implementation.
         * @see MenuListener#menuDeselected(MenuEvent)
         */
        public void menuDeselected(MenuEvent e) {
        }

    });

    //Listen to keyboard selection
    menu.addMenuKeyListener(new MenuKeyListener() {

        public void menuKeyReleased(MenuKeyEvent e) {
            Object source = e.getSource();
            if (source instanceof JMenu)
                createWindowsMenuItems((JMenu) source);
        }

        /** 
         * Required by I/F but not actually needed in our case, 
         * no-operation implementation.
         * @see MenuKeyListener#menuKeyPressed(MenuKeyEvent)
         */
        public void menuKeyPressed(MenuKeyEvent e) {
        }

        /** 
         * Required by I/F but not actually needed in our case, 
         * no-operation implementation.
         * @see MenuKeyListener#menuKeyTyped(MenuKeyEvent)
         */
        public void menuKeyTyped(MenuKeyEvent e) {
        }

    });
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewerControl.java

/** 
 * Attaches a window listener to the view to discard the model when 
 * the user closes the window. /*from   ww w.j  a v  a 2  s .  c om*/
 */
private void attachListeners() {
    if (UIUtilities.isMacOS()) {
        try {
            MacOSMenuHandler handler = new MacOSMenuHandler(view);
            handler.initialize();
            view.addPropertyChangeListener(this);
        } catch (Throwable e) {
        }
    }
    Map browsers = model.getBrowsers();
    Iterator i = browsers.values().iterator();
    Browser browser;
    while (i.hasNext()) {
        browser = (Browser) i.next();
        browser.addPropertyChangeListener(this);
        browser.addChangeListener(this);
    }
    view.addWindowFocusListener(this);
    model.addPropertyChangeListener(this);
    view.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    view.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            model.closeWindow();
        }
    });

    //
    JMenu menu = TreeViewerFactory.getWindowMenu();
    menu.addMenuListener(new MenuListener() {

        public void menuSelected(MenuEvent e) {
            Object source = e.getSource();
            if (source instanceof JMenu)
                createWindowsMenuItems((JMenu) source);
        }

        /** 
         * Required by I/F but not actually needed in our case, 
         * no-operation implementation.
         * @see MenuListener#menuCanceled(MenuEvent)
         */
        public void menuCanceled(MenuEvent e) {
        }

        /** 
         * Required by I/F but not actually needed in our case, 
         * no-operation implementation.
         * @see MenuListener#menuDeselected(MenuEvent)
         */
        public void menuDeselected(MenuEvent e) {
        }

    });

    //Listen to keyboard selection
    menu.addMenuKeyListener(new MenuKeyListener() {

        public void menuKeyReleased(MenuKeyEvent e) {
            Object source = e.getSource();
            if (source instanceof JMenu)
                createWindowsMenuItems((JMenu) source);
        }

        /** 
         * Required by I/F but not actually needed in our case, 
         * no-operation implementation.
         * @see MenuKeyListener#menuKeyPressed(MenuKeyEvent)
         */
        public void menuKeyPressed(MenuKeyEvent e) {
        }

        /** 
         * Required by I/F but not actually needed in our case, 
         * no-operation implementation.
         * @see MenuKeyListener#menuKeyTyped(MenuKeyEvent)
         */
        public void menuKeyTyped(MenuKeyEvent e) {
        }

    });
}