Example usage for java.awt.event ActionEvent CTRL_MASK

List of usage examples for java.awt.event ActionEvent CTRL_MASK

Introduction

In this page you can find the example usage for java.awt.event ActionEvent CTRL_MASK.

Prototype

int CTRL_MASK

To view the source code for java.awt.event ActionEvent CTRL_MASK.

Click Source Link

Document

The control modifier.

Usage

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();
    ActionListener listener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Command: " + e.getActionCommand());
            int modifiers = e.getModifiers();
            System.out.println("\tALT : " + checkMod(modifiers, ActionEvent.ALT_MASK));
            System.out.println("\tCTRL : " + checkMod(modifiers, ActionEvent.CTRL_MASK));
            System.out.println("\tMETA : " + checkMod(modifiers, ActionEvent.META_MASK));
            System.out.println("\tSHIFT: " + checkMod(modifiers, ActionEvent.SHIFT_MASK));
            Object source = e.getSource();
            if (source instanceof JComboBox) {
                JComboBox jb = (JComboBox) source;
                System.out.println("Combo: " + jb.getSelectedItem());
            }/*from www .  j a  v a2s. c  o  m*/
        }

        private boolean checkMod(int modifiers, int mask) {
            return ((modifiers & mask) == mask);
        }
    };

    String flavors[] = { "Item 1", "Item 2", "Item 3" };
    JComboBox jc = new JComboBox(flavors);
    jc.setMaximumRowCount(4);
    jc.setEditable(true);
    jc.addActionListener(listener);
    contentPane.add(jc, BorderLayout.NORTH);

    JButton b = new JButton("Button!");
    b.addActionListener(listener);
    contentPane.add(b, BorderLayout.CENTER);

    JPanel panel = new JPanel();
    JLabel label = new JLabel("Label 1: ");
    JTextField text = new JTextField("Type your text", 15);
    text.addActionListener(listener);
    label.setDisplayedMnemonic(KeyEvent.VK_1);
    label.setLabelFor(text);
    panel.add(label);
    panel.add(text);
    contentPane.add(panel, BorderLayout.SOUTH);

    frame.pack();
    frame.setVisible(true);
}

From source file:ActionTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();
    ActionListener listener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Command: " + e.getActionCommand());
            System.out.println("Modifiers: ");
            int modifiers = e.getModifiers();
            System.out.println("\tALT : " + checkMod(modifiers, ActionEvent.ALT_MASK));
            System.out.println("\tCTRL : " + checkMod(modifiers, ActionEvent.CTRL_MASK));
            System.out.println("\tMETA : " + checkMod(modifiers, ActionEvent.META_MASK));
            System.out.println("\tSHIFT: " + checkMod(modifiers, ActionEvent.SHIFT_MASK));
            Object source = e.getSource();
            if (source instanceof JComboBox) {
                JComboBox jb = (JComboBox) source;
                System.out.println("Combo: " + jb.getSelectedItem());
            }/*from  w ww . j  a v a2  s. c  o m*/
        }

        private boolean checkMod(int modifiers, int mask) {
            return ((modifiers & mask) == mask);
        }
    };

    String flavors[] = { "Item 1", "Item 2", "Item 3" };
    JComboBox jc = new JComboBox(flavors);
    jc.setMaximumRowCount(4);
    jc.setEditable(true);
    jc.addActionListener(listener);
    contentPane.add(jc, BorderLayout.NORTH);

    JButton b = new JButton("Button!");
    b.addActionListener(listener);
    contentPane.add(b, BorderLayout.CENTER);

    JPanel panel = new JPanel();
    JLabel label = new JLabel("Label 1: ");
    JTextField text = new JTextField("Type your text", 15);
    text.addActionListener(listener);
    label.setDisplayedMnemonic(KeyEvent.VK_1);
    label.setLabelFor(text);
    panel.add(label);
    panel.add(text);
    contentPane.add(panel, BorderLayout.SOUTH);

    frame.pack();
    frame.show();
}

From source file:EventObject.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    JButton ok = new JButton("Ok");

    ok.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            Calendar cal = Calendar.getInstance();
            cal.setTimeInMillis(event.getWhen());
            Locale locale = Locale.getDefault();
            String s = DateFormat.getTimeInstance(DateFormat.SHORT, locale).format(new Date());

            if (event.getID() == ActionEvent.ACTION_PERFORMED)
                System.out.println(" Event Id: ACTION_PERFORMED");

            System.out.println(" Time: " + s);

            String source = event.getSource().getClass().getName();
            System.out.println(" Source: " + source);

            int mod = event.getModifiers();
            if ((mod & ActionEvent.ALT_MASK) > 0)
                System.out.println("Alt ");

            if ((mod & ActionEvent.SHIFT_MASK) > 0)
                System.out.println("Shift ");

            if ((mod & ActionEvent.META_MASK) > 0)
                System.out.println("Meta ");

            if ((mod & ActionEvent.CTRL_MASK) > 0)
                System.out.println("Ctrl ");

        }/*  w  ww  .  j av a2  s.co  m*/
    });

    f.add(ok);

    f.setSize(420, 250);
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:Submenu.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    JMenuBar menubar = new JMenuBar();
    ImageIcon iconNew = new ImageIcon("new.png");
    ImageIcon iconOpen = new ImageIcon("open.png");
    ImageIcon iconSave = new ImageIcon("save.png");
    ImageIcon iconClose = new ImageIcon("exit.png");

    JMenu file = new JMenu("File");
    JMenu imp = new JMenu("Import");

    JMenuItem fileNew = new JMenuItem("New", iconNew);
    JMenuItem fileOpen = new JMenuItem("Open", iconOpen);
    JMenuItem fileSave = new JMenuItem("Save", iconSave);
    JMenuItem fileClose = new JMenuItem("Close", iconClose);

    file.setMnemonic(KeyEvent.VK_F);
    imp.setMnemonic(KeyEvent.VK_M);

    JMenuItem newsf = new JMenuItem("Import newsfeed list...");
    JMenuItem bookm = new JMenuItem("Import bookmarks...");
    JMenuItem mail = new JMenuItem("Import mail...");

    imp.add(newsf);/*from w  ww  .  j  a  v a  2 s  . c om*/
    imp.add(bookm);
    imp.add(mail);

    fileNew.setMnemonic(KeyEvent.VK_N);
    fileNew.setMnemonic(KeyEvent.VK_O);
    fileSave.setMnemonic(KeyEvent.VK_S);

    fileClose.setMnemonic(KeyEvent.VK_C);
    fileClose.setToolTipText("Exit application");
    fileClose.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, ActionEvent.CTRL_MASK));

    fileClose.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });

    file.add(fileNew);
    file.add(fileOpen);
    file.add(fileSave);
    file.addSeparator();
    file.add(imp);
    file.addSeparator();
    file.add(fileClose);

    menubar.add(file);

    f.setJMenuBar(menubar);

    f.setSize(360, 250);
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:MyActionListener.java

public void actionPerformed(ActionEvent e) {
    System.out.println("Command: " + e.getActionCommand());
    int modifiers = e.getModifiers();
    System.out.println("\tALT : " + checkMod(modifiers, ActionEvent.ALT_MASK));
    System.out.println("\tCTRL : " + checkMod(modifiers, ActionEvent.CTRL_MASK));
    System.out.println("\tMETA : " + checkMod(modifiers, ActionEvent.META_MASK));
    System.out.println("\tSHIFT: " + checkMod(modifiers, ActionEvent.SHIFT_MASK));
    Object source = e.getSource();
    if (source instanceof JButton) {
        JButton jb = (JButton) source;
        System.out.println("JButton: " + jb.getText());
    }/*  w  w  w.  j a  va 2 s  .com*/
}

From source file:Main.java

public void actionPerformed(ActionEvent e) {

    Locale locale = Locale.getDefault();
    Date date = new Date(e.getWhen());
    String s = DateFormat.getTimeInstance(DateFormat.SHORT, locale).format(date);

    if (!model.isEmpty()) {
        model.clear();//from  w  ww  .j  av a  2 s.c  om
    }

    if (e.getID() == ActionEvent.ACTION_PERFORMED) {
        model.addElement(" Event Id: ACTION_PERFORMED");

    }

    model.addElement("Time: " + s);

    String source = e.getSource().getClass().getName();

    int mod = e.getModifiers();

    StringBuffer buffer = new StringBuffer("Modifiers: ");

    if ((mod & ActionEvent.ALT_MASK) > 0) {
        buffer.append("Alt ");

    }

    if ((mod & ActionEvent.SHIFT_MASK) > 0) {
        buffer.append("Shift ");

    }

    if ((mod & ActionEvent.META_MASK) > 0) {
        buffer.append("Meta ");

    }

    if ((mod & ActionEvent.CTRL_MASK) > 0) {
        buffer.append("Ctrl ");

    }
    model.addElement(buffer);

}

From source file:PopupDemo.java

String getMods(int mods) {
    String modstr = "";
    if ((mods & ActionEvent.SHIFT_MASK) == ActionEvent.SHIFT_MASK)
        modstr += (" SHIFT");
    if ((mods & ActionEvent.ALT_MASK) == ActionEvent.ALT_MASK)
        modstr += (" ALT");
    if ((mods & ActionEvent.CTRL_MASK) == ActionEvent.CTRL_MASK)
        modstr += (" CTRL");
    if ((mods & ActionEvent.META_MASK) == ActionEvent.META_MASK)
        modstr += (" META");
    return modstr;
}

From source file:de.tor.tribes.ui.views.DSWorkbenchChurchFrame.java

/**
 * Creates new form DSWorkbenchChurchFrame
 */// w w  w.ja v  a  2 s.c  o m
DSWorkbenchChurchFrame() {
    initComponents();
    centerPanel = new GenericTestPanel();
    jChurchPanel.add(centerPanel, BorderLayout.CENTER);
    centerPanel.setChildComponent(jXPanel1);
    buildMenu();

    KeyStroke delete = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false);
    KeyStroke bbCopy = KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK, false);

    ActionListener listener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if ("Delete".equals(e.getActionCommand())) {
                deleteSelection();
            } else if ("BBCopy".equals(e.getActionCommand())) {
                bbCopySelection();
            }
        }
    };
    capabilityInfoPanel1.addActionListener(listener);
    jChurchTable.registerKeyboardAction(listener, "Delete", delete,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jChurchTable.registerKeyboardAction(listener, "BBCopy", bbCopy,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    jChurchFrameAlwaysOnTop.setSelected(GlobalOptions.getProperties().getBoolean("church.frame.alwaysOnTop"));
    setAlwaysOnTop(jChurchFrameAlwaysOnTop.isSelected());

    jChurchTable.setModel(new ChurchTableModel());
    // <editor-fold defaultstate="collapsed" desc=" Init HelpSystem ">
    if (!Constants.DEBUG) {
        GlobalOptions.getHelpBroker().enableHelpKey(getRootPane(), "pages.church_view",
                GlobalOptions.getHelpBroker().getHelpSet());
    }
    // </editor-fold>
    jChurchTable.getSelectionModel().addListSelectionListener(DSWorkbenchChurchFrame.this);
    pack();
}

From source file:de.tor.tribes.ui.views.DSWorkbenchWatchtowerFrame.java

/**
 * Creates new form DSWorkbenchWatchtowerFrame
 *//*from  w  w  w .  j  av  a 2 s  .c  o m*/
DSWorkbenchWatchtowerFrame() {
    initComponents();
    centerPanel = new GenericTestPanel();
    jWatchtowerPanel.add(centerPanel, BorderLayout.CENTER);
    centerPanel.setChildComponent(jXPanel1);
    buildMenu();

    KeyStroke delete = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false);
    KeyStroke bbCopy = KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK, false);

    ActionListener listener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if ("Delete".equals(e.getActionCommand())) {
                deleteSelection();
            } else if ("BBCopy".equals(e.getActionCommand())) {
                bbCopySelection();
            }
        }
    };
    capabilityInfoPanel1.addActionListener(listener);
    jWatchtowerTable.registerKeyboardAction(listener, "Delete", delete,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jWatchtowerTable.registerKeyboardAction(listener, "BBCopy", bbCopy,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    jWatchtowerFrameAlwaysOnTop
            .setSelected(GlobalOptions.getProperties().getBoolean("watchtower.frame.alwaysOnTop"));
    setAlwaysOnTop(jWatchtowerFrameAlwaysOnTop.isSelected());

    jWatchtowerTable.setModel(new WatchtowerTableModel());
    // <editor-fold defaultstate="collapsed" desc=" Init HelpSystem ">
    if (!Constants.DEBUG) {
        //TODO create help page
        GlobalOptions.getHelpBroker().enableHelpKey(getRootPane(), "pages.church_view",
                GlobalOptions.getHelpBroker().getHelpSet());
    }
    // </editor-fold>
    jWatchtowerTable.getSelectionModel().addListSelectionListener(DSWorkbenchWatchtowerFrame.this);
    pack();
}

From source file:net.sf.clichart.main.ChartFrame.java

private void createMenu() {
    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);/*from www . j ava 2  s .  co m*/

    JMenu fileMenu = new JMenu("File");
    menuBar.add(fileMenu);

    JMenuItem saveItem = new JMenuItem("Save as...", KeyEvent.VK_S);
    saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
    saveItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            saveChart();
        }
    });
    fileMenu.add(saveItem);

    JMenuItem exitItem = new JMenuItem("Exit", KeyEvent.VK_Q);
    exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    fileMenu.addSeparator();
    fileMenu.add(exitItem);

}