Example usage for java.awt Event ALT_MASK

List of usage examples for java.awt Event ALT_MASK

Introduction

In this page you can find the example usage for java.awt Event ALT_MASK.

Prototype

int ALT_MASK

To view the source code for java.awt Event ALT_MASK.

Click Source Link

Document

This flag indicates that the Alt key was down when the event occurred.

Usage

From source file:Main.java

/**
 * gives default modifier of the current OS.
 * //from   w w w  . ja v  a2 s . com
 * @return meta (command) for OSX, control for Windows/Linux etc 
 */
public static int getSystemDefaultModifier() {
    if (!(UIManager.getLookAndFeel().getID().equals(METAL_LAF_ID))) {
        int mask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
        if (mask == Event.META_MASK) {
            return KeyEvent.VK_META;
        } else if (mask == Event.ALT_MASK) {
            return KeyEvent.VK_ALT;
        }
    }
    return KeyEvent.VK_CONTROL;
}

From source file:MenuShortcuts.java

MenuShortcuts(String s) {
    super("JMenuShortcuts: " + s);
    mb = new JMenuBar();
    setJMenuBar(mb); // Frame implements JMenuContainer

    Container cp = getContentPane();
    JMenuItem mi;//from   ww  w .  j  ava  2s. co m
    // The File JMenu...
    fm = new JMenu("File");
    fm.setMnemonic('F');
    fm.add(mi = new JMenuItem("Open", 'O'));
    mi.addActionListener(this);
    fm.add(mi = new JMenuItem("Close", 'W'));
    mi.addActionListener(this);
    fm.addSeparator();

    fm.add(mi = new JMenuItem("Print", 'P'));
    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, Event.ALT_MASK));

    mi.addActionListener(this);
    fm.addSeparator();
    fm.add(mi = new JMenuItem("Exit", 'Q'));
    exitItem = mi; // save for action handler
    mi.addActionListener(this);
    mb.add(fm);

    // The Options JMenu...
    om = new JMenu("Options");
    om.add(new JMenuItem("Alpha"));
    om.add(new JMenuItem("Gamma"));
    om.add(new JMenuItem("Delta"));
    mb.add(om);

    // The Help JMenu...
    hm = new JMenu("Help");
    hm.add(mi = new JMenuItem("About"));
    mi.addActionListener(this);
    hm.add(mi = new JMenuItem("Topics"));
    mi.addActionListener(this);
    mb.add(hm);
    // mb.setHelpMenu(hm); // needed for portability (Motif, etc.).

    // the main window
    cp.add(new Label("Menu Demo Window", 200, 150));
    pack();
}

From source file:EventTester.java

private String mods(int flags) {
    String s = "[ ";
    if (flags == 0)
        return "";
    if ((flags & Event.SHIFT_MASK) != 0)
        s += "Shift ";
    if ((flags & Event.CTRL_MASK) != 0)
        s += "Control ";
    if ((flags & Event.META_MASK) != 0)
        s += "Meta ";
    if ((flags & Event.ALT_MASK) != 0)
        s += "Alt ";
    s += "] ";// w w  w .ja  v a2  s . c o  m
    return s;
}

From source file:com.prodigy4440.view.MainJFrame.java

public final void initComponents() {

    List<Image> icons = new LinkedList<>();
    icons.add(new ImageIcon(getClass().getResource("/com/prodigy4440/ited16x16.png")).getImage());
    icons.add(new ImageIcon(getClass().getResource("/com/prodigy4440/ited32x32.png")).getImage());
    icons.add(new ImageIcon(getClass().getResource("/com/prodigy4440/ited48x48.png")).getImage());
    icons.add(new ImageIcon(getClass().getResource("/com/prodigy4440/ited72x72.png")).getImage());

    this.setIconImages(icons);

    ActionHandler actionHandler = new ActionHandler(this);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setSize(620, 520);
    this.setLocationRelativeTo(null);
    this.setTitle("Untitled Document- IgboTextEditor");
    southJPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    SoftBevelBorder sbb = new SoftBevelBorder(SoftBevelBorder.LOWERED);
    southJPanel.setBorder(sbb);//from   www  . j  av  a  2  s .  c  om
    menuBar = new JMenuBar();

    fileJMenu = new JMenu("File");
    fileJMenu.setMnemonic('F');
    editJMenu = new JMenu("Edit");
    editJMenu.setMnemonic('E');
    formatJMenu = new JMenu("Format");
    formatJMenu.setMnemonic('A');
    viewJMenu = new JMenu("View");
    viewJMenu.setMnemonic('V');
    helpJMenu = new JMenu("Help");
    helpJMenu.setMnemonic('H');

    newDocumentJMenuItem = new JMenuItem("New");
    newDocumentJMenuItem.addActionListener(actionHandler);
    newDocumentJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK));
    openJMenuItem = new JMenuItem("Open");
    openJMenuItem.addActionListener(actionHandler);
    openJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK));
    saveJMenuItem = new JMenuItem("Save");
    saveJMenuItem.addActionListener(actionHandler);
    saveJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK));
    printJMenuItem = new JMenuItem("Print");
    printJMenuItem.addActionListener(actionHandler);
    printJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, Event.CTRL_MASK));
    exitJMenuItem = new JMenuItem("Exit");
    exitJMenuItem.addActionListener(actionHandler);

    undoJMenuItem = new JMenuItem("Undo");
    undoJMenuItem.addActionListener(actionHandler);
    undoJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, Event.CTRL_MASK));
    redoJMenuItem = new JMenuItem("Redo");
    redoJMenuItem.addActionListener(actionHandler);
    redoJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, Event.CTRL_MASK));
    copyJMenuItem = new JMenuItem("Copy");
    copyJMenuItem.addActionListener(actionHandler);
    copyJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.CTRL_MASK));
    cutJMenuItem = new JMenuItem("Cut");
    cutJMenuItem.addActionListener(actionHandler);
    cutJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.CTRL_MASK));
    pasteJMenuItem = new JMenuItem("Paste");
    pasteJMenuItem.addActionListener(actionHandler);
    pasteJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, Event.CTRL_MASK));
    deleteJMenuItem = new JMenuItem("Delete");
    deleteJMenuItem.addActionListener(actionHandler);
    deleteJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, Event.CTRL_MASK));
    selectAllJMenuItem = new JMenuItem("Select All");
    selectAllJMenuItem.addActionListener(actionHandler);
    selectAllJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, Event.CTRL_MASK));
    findJMenuItem = new JMenuItem("Find");
    findJMenuItem.addActionListener(actionHandler);
    findJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, Event.CTRL_MASK));
    replaceJMenuItem = new JMenuItem("Replace");
    replaceJMenuItem.addActionListener(actionHandler);
    replaceJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, Event.CTRL_MASK));

    wordWrapJCheckBoxMenuItem = new JCheckBoxMenuItem("Word Wrap");
    wordWrapJCheckBoxMenuItem.addActionListener(actionHandler);
    wordWrapJCheckBoxMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, Event.CTRL_MASK));
    fontJMenuItem = new JMenuItem("Font");
    fontJMenuItem.addActionListener(actionHandler);
    colorJMenuItem = new JMenuItem("Color");
    colorJMenuItem.addActionListener(actionHandler);

    statusBarJCheckBoxMenuItem = new JCheckBoxMenuItem("Status Bar");
    statusBarJCheckBoxMenuItem.addActionListener(actionHandler);
    statusBarJCheckBoxMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.ALT_MASK));

    helpJMenuItem = new JMenuItem("Help");
    helpJMenuItem.addActionListener(actionHandler);
    helpJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, Event.CTRL_MASK));
    aboutJMenuItem = new JMenuItem("About");
    aboutJMenuItem.addActionListener(actionHandler);

    statusJLabel = new JLabel("Status:");

    //Main text area setup
    textArea = new JTextArea();
    undoManager = new UndoManager();
    wordSearcher = new WordSearcher(textArea);
    textArea.setBorder(BorderFactory.createMatteBorder(4, 4, 4, 4, Color.WHITE));
    document = textArea.getDocument();
    document.addUndoableEditListener(new UndoableEditListener() {
        @Override
        public void undoableEditHappened(UndoableEditEvent e) {
            undoManager.addEdit(e.getEdit());
        }
    });

    font = new Font("Tahoma", Font.PLAIN, 16);
    textArea.setFont(font);
    color = Color.BLUE;
    textArea.setForeground(color);

    undoManager = new UndoManager();

    fileJMenu.add(newDocumentJMenuItem);
    fileJMenu.addSeparator();
    fileJMenu.add(openJMenuItem);
    fileJMenu.add(saveJMenuItem);
    fileJMenu.addSeparator();
    fileJMenu.add(printJMenuItem);
    fileJMenu.addSeparator();
    fileJMenu.add(exitJMenuItem);

    editJMenu.add(undoJMenuItem);
    editJMenu.add(redoJMenuItem);
    editJMenu.addSeparator();
    editJMenu.add(copyJMenuItem);
    editJMenu.add(cutJMenuItem);
    editJMenu.add(pasteJMenuItem);
    editJMenu.addSeparator();
    editJMenu.add(deleteJMenuItem);
    editJMenu.add(selectAllJMenuItem);
    editJMenu.addSeparator();
    editJMenu.add(findJMenuItem);
    editJMenu.add(replaceJMenuItem);

    formatJMenu.add(wordWrapJCheckBoxMenuItem);
    formatJMenu.add(fontJMenuItem);
    formatJMenu.add(colorJMenuItem);

    viewJMenu.add(statusBarJCheckBoxMenuItem);

    helpJMenu.add(helpJMenuItem);
    helpJMenu.add(aboutJMenuItem);

    menuBar.add(fileJMenu);
    menuBar.add(editJMenu);
    menuBar.add(formatJMenu);
    menuBar.add(viewJMenu);
    menuBar.add(helpJMenu);

    southJPanel.setVisible(false);
    southJPanel.add(statusJLabel);
    //JScrollPane setup
    JScrollPane scrollPane = new JScrollPane(textArea);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    //setting uo the Jframe
    this.setJMenuBar(menuBar);
    this.add(scrollPane, BorderLayout.CENTER);
    this.add(southJPanel, BorderLayout.SOUTH);
    textArea.addMouseListener(new MouseInputListener() {

        @Override
        public void mouseClicked(MouseEvent e) {
            Highlighter h = textArea.getHighlighter();
            h.removeAllHighlights();
        }

        @Override
        public void mousePressed(MouseEvent e) {
            Highlighter h = textArea.getHighlighter();
            h.removeAllHighlights();
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }

        @Override
        public void mouseDragged(MouseEvent e) {
        }

        @Override
        public void mouseMoved(MouseEvent e) {
        }
    });

    textArea.addKeyListener(new IgboKeyListener(textArea));

}

From source file:com.qawaa.gui.EventWebScanGUI.java

/**
 * //from   w ww. j a v  a2 s . c  o  m
 */
private void initGUI() {
    try {
        setSize(900, 600);
        {
            jMenuBar1 = new JMenuBar();
            setJMenuBar(jMenuBar1);
            {
                optionMenus = new JMenu();
                jMenuBar1.add(optionMenus);
                optionMenus.setText(CONTEXT.getMessage("gobal.menu.option", null, Locale.CHINA));
                {
                    exitMenuItem = new JMenuItem();
                    optionMenus.add(exitMenuItem);
                    exitMenuItem.setText(CONTEXT.getMessage("gobal.menu.option.quit", null, Locale.CHINA));
                    exitMenuItem.setMnemonic(KeyEvent.VK_Q);
                    exitMenuItem.setAccelerator(
                            javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_Q, Event.ALT_MASK, false));
                    exitMenuItem.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            windowsClosed();
                        }
                    });
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:de.codesourcery.jasm16.ide.ui.views.SourceEditorView.java

@Override
protected final void setupKeyBindingsHook(final JTextPane editor) {
    // 'Rename' action 
    addKeyBinding(editor, KeyStroke.getKeyStroke(KeyEvent.VK_R, Event.ALT_MASK | Event.SHIFT_MASK),
            new AbstractAction() {
                @Override//from   ww w .ja v  a2s  .c o  m
                public void actionPerformed(ActionEvent e) {
                    maybeRenameLabel(editor.getCaretPosition());
                }
            });
}

From source file:com.opendoorlogistics.studio.AppFrame.java

@SuppressWarnings("serial")
private List<MyAction> initFileActions() {
    ArrayList<MyAction> ret = new ArrayList<>();
    ret.add(new MyAction("New", "Create new file", null, "document-new-6.png", false,
            KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK)) {

        @Override//from w w  w . j  a  v  a  2  s.  c  o  m
        public void actionPerformed(ActionEvent e) {
            createNewDatastore();
        }
    });

    ret.add(new MyAction("Open", "Open file", null, "document-open-3.png", false,
            KeyStroke.getKeyStroke(KeyEvent.VK_O, java.awt.Event.CTRL_MASK)) {

        @Override
        public void actionPerformed(ActionEvent e) {
            openDatastoreWithUserPrompt();
        }
    });

    ret.add(null);

    ret.add(new MyAction("Close", "Close file", null, "document-close-4.png", true,
            KeyStroke.getKeyStroke(KeyEvent.VK_W, java.awt.Event.CTRL_MASK)) {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (!canCloseDatastore()) {
                return;
            }
            closeDatastore();
        }
    });

    ret.add(null);

    ret.add(new MyAction("Save", "Save file", null, "document-save-2.png", true,
            KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK)) {

        @Override
        public void actionPerformed(ActionEvent e) {
            saveDatastoreWithoutUserPrompt(loaded.getLastFile());
        }

        @Override
        public void updateEnabled() {

            setEnabled(loaded != null && loaded.getLastFile() != null);
        }

    });
    ret.add(new MyAction("Save as", "Save file as", null, "document-save-as-2.png", true,
            KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK | Event.ALT_MASK)) {

        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = SupportedFileType.EXCEL.createFileChooser();
            if (loaded.getLastFile() != null) {
                chooser.setSelectedFile(loaded.getLastFile());
            } else {
                File file = PreferencesManager.getSingleton().getFile(PrefKey.LAST_IO_DIR);
                IOUtils.setFile(file, chooser);
            }
            if (chooser.showSaveDialog(AppFrame.this) == JFileChooser.APPROVE_OPTION) {
                saveDatastoreWithoutUserPrompt(chooser.getSelectedFile());
            }

        }
    });

    return ret;
}

From source file:org.eclipse.jubula.rc.swing.driver.RobotAwtImpl.java

/**
 * {@inheritDoc}//from  www  .ja v  a 2s  . c o m
 */
public String getSystemModifierSpec() {
    String keyStrokeSpec = CompSystemConstants.MODIFIER_CONTROL;
    if (!(UIManager.getLookAndFeel().getID().equals(METAL_LAF_ID))) {
        if (Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() == Event.META_MASK) {
            keyStrokeSpec = CompSystemConstants.MODIFIER_META;
        } else if (Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() == Event.ALT_MASK) {
            keyStrokeSpec = CompSystemConstants.MODIFIER_ALT;
        }
    }
    return keyStrokeSpec;
}

From source file:org.zaproxy.zap.extension.ascan.ExtensionActiveScan.java

private ZapMenuItem getMenuItemCustomScan() {
    if (menuItemCustomScan == null) {
        menuItemCustomScan = new ZapMenuItem("menu.tools.ascanadv", KeyStroke.getKeyStroke(KeyEvent.VK_A,
                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() | Event.ALT_MASK, false));

        menuItemCustomScan.addActionListener(new java.awt.event.ActionListener() {
            @Override/*from w w  w.j  a v  a2 s . c o  m*/
            public void actionPerformed(java.awt.event.ActionEvent e) {
                showCustomScanDialog(null);
            }
        });

    }

    return menuItemCustomScan;
}

From source file:org.zaproxy.zap.extension.customFire.ExtensionCustomFire.java

private ZapMenuItem getMenuItemCustomScan() {
    if (menuItemCustomScan == null) {
        menuItemCustomScan = new ZapMenuItem("menu.tools.ascanadv", KeyStroke.getKeyStroke(KeyEvent.VK_A,
                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() | Event.ALT_MASK, false));

        menuItemCustomScan.addActionListener(new java.awt.event.ActionListener() {
            @Override//w w  w . j  a  va  2  s .  c  om
            public void actionPerformed(java.awt.event.ActionEvent e) {
                showCustomFireDialog(null);
            }
        });

    }

    return menuItemCustomScan;
}