List of usage examples for java.awt.event ActionEvent getModifiers
public int getModifiers()
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()); }/* w w w. j a v a2 s.co 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 ww w . j a va 2s .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 "); }//from ww w . jav a 2 s . c o m }); f.add(ok); f.setSize(420, 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()); }// ww w . ja va 2 s . c o m }
From source file:PopupDemo.java
String getMods(ActionEvent e) { return getMods(e.getModifiers()); }
From source file:Main.java
public void actionPerformed(ActionEvent e) { if (e.getActionCommand() != null) { String command = e.getActionCommand(); if (command != null) { command = command.toUpperCase(); }/*from w ww .jav a2 s .c om*/ e = new ActionEvent(e.getSource(), e.getID(), command, e.getModifiers()); } if (defAction != null) { defAction.actionPerformed(e); } }
From source file:javazoom.jlgui.player.amp.StandalonePlayer.java
/** * Install keyboard shortcuts.//from w w w. j a v a 2 s .c om */ public void setKeyBoardShortcut() { KeyStroke jKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_J, 0, false); KeyStroke ctrlPKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_P, KeyEvent.CTRL_MASK, false); KeyStroke altSKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.ALT_MASK, false); KeyStroke vKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_V, 0, false); String searchID = "TAGSEARCH"; String preferenceID = "PREFERENCES"; String skinbrowserID = "SKINBROWSER"; String stopplayerID = "STOPPLAYER"; Action searchAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { if (mp != null) mp.processJumpToFile(e.getModifiers()); } }; Action preferencesAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { if (mp != null) mp.processPreferences(e.getModifiers()); } }; Action skinbrowserAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { if (mp != null) mp.processSkinBrowser(e.getModifiers()); } }; Action stopplayerAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { if (mp != null) mp.processStop(MouseEvent.BUTTON1_MASK); } }; setKeyboardAction(searchID, jKeyStroke, searchAction); setKeyboardAction(preferenceID, ctrlPKeyStroke, preferencesAction); setKeyboardAction(skinbrowserID, altSKeyStroke, skinbrowserAction); setKeyboardAction(stopplayerID, vKeyStroke, stopplayerAction); }
From source file:com.diversityarrays.kdxplore.vistool.VisualisationToolActionListener.java
@Override public void actionPerformed(ActionEvent e) { boolean developerRunMode = RunMode.getRunMode().isDeveloper(); if (onlyForDeveloper) { if (!developerRunMode) { doDisabledForTesting(parentComponent, title, tool.getToolName()); return; }//from w w w . j av a 2 s . c o m } boolean allowSubPlots = developerRunMode || (0 != (ActionEvent.SHIFT_MASK & e.getModifiers())); int[] dataSets = tool.getDataRequirements(); if (dataSets == null || dataSets.length <= 0) { VisToolUtil.allowSubplotTraits = allowSubPlots; try { Either<String, List<JFrame>> either = tool.getVisualisationDialogs(curationContext, null); if (either.isRight()) { VisToolUtil.staggerOpenedFrames(either.right()); } else { curationContext.errorMessage(tool, either.left()); } } finally { } } else { boolean xAndYaxes = tool.supportsXandYaxes(); askForManyTraitInstancesWithData(parentComponent, tool.getToolName(), xAndYaxes, dataSets, allowSubPlots, onInstancesChosen); } }
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();/*ww w.ja va 2 s . c o m*/ } 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:com.mirth.connect.client.ui.components.rsta.FindReplaceDialog.java
private void initComponents() { setLayout(new MigLayout("insets 11, novisualpadding, hidemode 3, fill, gap 6")); setBackground(UIConstants.COMBO_BOX_BACKGROUND); getContentPane().setBackground(getBackground()); findPanel = new JPanel(new MigLayout("insets 0, novisualpadding, hidemode 3, fill, gap 6")); findPanel.setBackground(getBackground()); ActionListener findActionListener = new ActionListener() { @Override// ww w.j a v a2 s . co m public void actionPerformed(ActionEvent evt) { find(); } }; findLabel = new JLabel("Find text:"); findComboBox = new JComboBox<String>(); findComboBox.setEditable(true); findComboBox.setBackground(UIConstants.BACKGROUND_COLOR); findComboBox.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() { @Override public void keyReleased(final KeyEvent evt) { if (evt.getKeyCode() == KeyEvent.VK_ENTER && evt.getModifiers() == 0) { find(); } } }); ActionListener replaceActionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { replace(); } }; replaceLabel = new JLabel("Replace with:"); replaceComboBox = new JComboBox<String>(); replaceComboBox.setEditable(true); replaceComboBox.setBackground(UIConstants.BACKGROUND_COLOR); directionPanel = new JPanel(new MigLayout("insets 8, novisualpadding, hidemode 3, fill, gap 6")); directionPanel.setBackground(getBackground()); directionPanel.setBorder(BorderFactory.createTitledBorder( BorderFactory.createLineBorder(new Color(150, 150, 150)), "Direction", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Tahoma", 1, 11))); ButtonGroup directionButtonGroup = new ButtonGroup(); directionForwardRadio = new JRadioButton("Forward"); directionForwardRadio.setBackground(directionPanel.getBackground()); directionButtonGroup.add(directionForwardRadio); directionBackwardRadio = new JRadioButton("Backward"); directionBackwardRadio.setBackground(directionPanel.getBackground()); directionButtonGroup.add(directionBackwardRadio); optionsPanel = new JPanel(new MigLayout("insets 8, novisualpadding, hidemode 3, fill, gap 6")); optionsPanel.setBackground(getBackground()); optionsPanel.setBorder(BorderFactory.createTitledBorder( BorderFactory.createLineBorder(new Color(150, 150, 150)), "Options", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Tahoma", 1, 11))); wrapSearchCheckBox = new JCheckBox("Wrap Search"); matchCaseCheckBox = new JCheckBox("Match Case"); regularExpressionCheckBox = new JCheckBox("Regular Expression"); wholeWordCheckBox = new JCheckBox("Whole Word"); findButton = new JButton("Find"); findButton.addActionListener(findActionListener); replaceButton = new JButton("Replace"); replaceButton.addActionListener(replaceActionListener); replaceAllButton = new JButton("Replace All"); replaceAllButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { replaceAll(); } }); warningLabel = new JLabel(); closeButton = new JButton("Close"); closeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { dispose(); } }); }