List of usage examples for java.awt.event ActionEvent ActionEvent
public ActionEvent(Object source, int id, String command, long when, int modifiers)
From source file:Main.java
/** * Programmatically perform action on textfield.This does the same * thing as if the user had pressed enter key in textfield. * * @param textField textField on which action to be preformed *//*from www .j av a 2 s.c o m*/ public static void doAction(JTextField textField) { String command = null; if (textField.getAction() != null) command = (String) textField.getAction().getValue(Action.ACTION_COMMAND_KEY); ActionEvent event = null; for (ActionListener listener : textField.getActionListeners()) { if (event == null) event = new ActionEvent(textField, ActionEvent.ACTION_PERFORMED, command, System.currentTimeMillis(), 0); listener.actionPerformed(event); } }
From source file:Main.java
public KeyTextComponent() { setBackground(Color.CYAN);//from w w w. j a v a2 s . c o m KeyListener internalKeyListener = new KeyAdapter() { public void keyPressed(KeyEvent keyEvent) { if (actionListenerList != null) { int keyCode = keyEvent.getKeyCode(); String keyText = KeyEvent.getKeyText(keyCode); ActionEvent actionEvent = new ActionEvent(this, ActionEvent.ACTION_FIRST, keyText, System.currentTimeMillis() - 10, ActionEvent.ALT_MASK); fireActionPerformed(actionEvent); } } }; MouseListener internalMouseListener = new MouseAdapter() { public void mousePressed(MouseEvent mouseEvent) { requestFocusInWindow(); } }; addKeyListener(internalKeyListener); addMouseListener(internalMouseListener); }
From source file:org.bitbucket.mlopatkin.android.logviewer.widgets.UiHelper.java
public static void addDoubleClickAction(JComponent component, final Action action) { component.addMouseListener(new MouseAdapter() { @Override/*from w w w .ja va2 s . c o m*/ public void mouseClicked(MouseEvent e) { if (e.getClickCount() == DOUBLE_CLICK_COUNT && e.getButton() == MouseEvent.BUTTON1) { action.actionPerformed(new ActionEvent(e.getSource(), ActionEvent.ACTION_PERFORMED, (String) action.getValue(Action.ACTION_COMMAND_KEY), e.getWhen(), e.getModifiers())); } } }); }
From source file:Main.java
/** * Fires a {@link ActionListener}. This is useful for firing * {@link ApplicationAction}s to show blocking dialog. * * @param source the source of the event. * @param listener the listener to fire. * @param command a string that may specify a command (possibly one * of several) associated with the event. * @param modifiers the modifier keys held down during this action. * @see ActionEvent#ActionEvent(Object, int, String, long, int) *//*from ww w . ja v a2s . c o m*/ public static void fireAction(final Object source, final ActionListener listener, final String command, final int modifiers) { fireAction(listener, new ActionEvent(source, ActionEvent.ACTION_PERFORMED, command, System.currentTimeMillis(), modifiers)); }
From source file:org.bitbucket.mlopatkin.android.logviewer.widgets.UiHelper.java
/** * Creates a wrapper around an existing action of the component to be used * in menus.//from w ww . j a va 2 s.co m * * @param c * base component * @param actionKey * key in the component's ActionMap * @param caption * caption of the action wrapper * @param acceleratorKey * accelerator key of the action wrapper * @return action that translates its * {@link Action#actionPerformed(ActionEvent)} to the underlaying * existing action. */ public static Action createActionWrapper(final JComponent c, final String actionKey, String caption, final String acceleratorKey) { final Action baseAction = c.getActionMap().get(actionKey); Action result = new AbstractAction(caption) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(acceleratorKey)); } @Override public void actionPerformed(ActionEvent e) { ActionEvent newEvent = new ActionEvent(c, e.getID(), actionKey, e.getWhen(), e.getModifiers()); baseAction.actionPerformed(newEvent); } @Override public void setEnabled(boolean newValue) { super.setEnabled(newValue); baseAction.setEnabled(newValue); } }; return result; }
From source file:org.wings.SAbstractButton.java
/** * Fire an ActionEvent at each registered listener. * * @param event supplied ActionEvent/*from ww w . j a v a2 s.c om*/ */ protected void fireActionPerformed(ActionEvent event) { // Guaranteed to return a non-null array Object[] listeners = getListenerList(); ActionEvent e = null; // Process the listeners last to first, notifying // those that are interested in this event for (int i = listeners.length - 2; i >= 0; i -= 2) { if (listeners[i] == ActionListener.class) { if (e == null) { String actionCommand = event.getActionCommand(); if (actionCommand == null) { actionCommand = getActionCommand(); } e = new ActionEvent(SAbstractButton.this, ActionEvent.ACTION_PERFORMED, actionCommand, event.getWhen(), event.getModifiers()); } ((ActionListener) listeners[i + 1]).actionPerformed(e); } } }
From source file:org.adempiere.apps.graph.PerformanceIndicator.java
/** * Notifies all listeners that have registered interest for * notification on this event type. The event instance * is lazily created using the <code>event</code> * parameter.//from w w w. ja va 2 s .c om * * @param event the <code>ActionEvent</code> object * @see EventListenerList */ protected void fireActionPerformed(MouseEvent event) { // Guaranteed to return a non-null array ActionListener[] listeners = getActionListeners(); ActionEvent e = null; // Process the listeners first to last for (int i = 0; i < listeners.length; i++) { // Lazily create the event: if (e == null) e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "pi", event.getWhen(), event.getModifiers()); listeners[i].actionPerformed(e); } }
From source file:org.rdv.datapanel.DigitalTabularDataPanel.java
private void addColumn() { if (columnGroupCount == MAX_COLUMN_GROUP_COUNT) { return;/*w w w .j a v a 2s.c o m*/ } if (columnGroupCount != 0) { panelBox.add(Box.createHorizontalStrut(7)); } final int tableIndex = columnGroupCount; final DataTableModel tableModel = new DataTableModel(); final JTable table = new JTable(tableModel); table.setDragEnabled(true); table.setName(DigitalTabularDataPanel.class.getName() + " JTable #" + Integer.toString(columnGroupCount)); if (showThresholdCheckBoxGroup.isSelected()) { tableModel.setThresholdVisible(true); } if (showMinMaxCheckBoxGroup.isSelected()) { tableModel.setMaxMinVisible(true); table.getColumn("Min").setCellRenderer(doubleCellRenderer); table.getColumn("Max").setCellRenderer(doubleCellRenderer); } table.getColumn("Value").setCellRenderer(dataCellRenderer); tables.add(table); tableModels.add(tableModel); JScrollPane tableScrollPane = new JScrollPane(table); panelBox.add(tableScrollPane); // popup menu for panel JPopupMenu popupMenu = new JPopupMenu(); final JMenuItem copyMenuItem = new JMenuItem("Copy"); copyMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { TransferHandler.getCopyAction().actionPerformed( new ActionEvent(table, ae.getID(), ae.getActionCommand(), ae.getWhen(), ae.getModifiers())); } }); popupMenu.add(copyMenuItem); popupMenu.addSeparator(); JMenuItem printMenuItem = new JMenuItem("Print..."); printMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { table.print(JTable.PrintMode.FIT_WIDTH); } catch (PrinterException pe) { } } }); popupMenu.add(printMenuItem); popupMenu.addSeparator(); final JCheckBoxMenuItem showMaxMinMenuItem = new JCheckBoxMenuItem("Show min/max columns", false); showMaxMinMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setMaxMinVisible(showMaxMinMenuItem.isSelected()); } }); showMinMaxCheckBoxGroup.addCheckBox(showMaxMinMenuItem); popupMenu.add(showMaxMinMenuItem); final JCheckBoxMenuItem showThresholdMenuItem = new JCheckBoxMenuItem("Show threshold columns", false); showThresholdMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setThresholdVisible(showThresholdMenuItem.isSelected()); } }); showThresholdCheckBoxGroup.addCheckBox(showThresholdMenuItem); popupMenu.add(showThresholdMenuItem); popupMenu.addSeparator(); JMenuItem blankRowMenuItem = new JMenuItem("Insert blank row"); blankRowMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tableModel.addBlankRow(); } }); popupMenu.add(blankRowMenuItem); final JMenuItem removeSelectedRowsMenuItem = new JMenuItem("Remove selected rows"); removeSelectedRowsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { removeSelectedRows(tableIndex); } }); popupMenu.add(removeSelectedRowsMenuItem); popupMenu.addSeparator(); JMenu numberOfColumnsMenu = new JMenu("Number of columns"); numberOfColumnsMenu.addMenuListener(new MenuListener() { public void menuSelected(MenuEvent me) { JMenu menu = (JMenu) me.getSource(); for (int j = 0; j < MAX_COLUMN_GROUP_COUNT; j++) { JMenuItem menuItem = menu.getItem(j); boolean selected = (j == (columnGroupCount - 1)); menuItem.setSelected(selected); } } public void menuDeselected(MenuEvent me) { } public void menuCanceled(MenuEvent me) { } }); for (int i = 0; i < MAX_COLUMN_GROUP_COUNT; i++) { final int number = i + 1; JRadioButtonMenuItem item = new JRadioButtonMenuItem(Integer.toString(number)); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setNumberOfColumns(number); } }); numberOfColumnsMenu.add(item); } popupMenu.add(numberOfColumnsMenu); popupMenu.addPopupMenuListener(new PopupMenuListener() { public void popupMenuWillBecomeVisible(PopupMenuEvent arg0) { boolean anyRowsSelected = table.getSelectedRowCount() > 0; copyMenuItem.setEnabled(anyRowsSelected); removeSelectedRowsMenuItem.setEnabled(anyRowsSelected); } public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) { } public void popupMenuCanceled(PopupMenuEvent arg0) { } }); // set component popup and mouselistener to trigger it table.setComponentPopupMenu(popupMenu); tableScrollPane.setComponentPopupMenu(popupMenu); panelBox.revalidate(); columnGroupCount++; properties.setProperty("numberOfColumns", Integer.toString(columnGroupCount)); }
From source file:com.googlecode.vfsjfilechooser2.VFSJFileChooser.java
/** * Notifies all listeners that have registered interest for * notification on this event type. The event instance * is lazily created using the <code>command</code> parameter. * * @see EventListenerList/*w w w.j a va 2 s . c om*/ */ protected void fireActionPerformed(String command) { // Guaranteed to return a non-null array Object[] listeners = listenerList.getListenerList(); long mostRecentEventTime = EventQueue.getMostRecentEventTime(); int modifiers = 0; AWTEvent currentEvent = EventQueue.getCurrentEvent(); if (currentEvent instanceof InputEvent) { modifiers = ((InputEvent) currentEvent).getModifiers(); } else if (currentEvent instanceof ActionEvent) { modifiers = ((ActionEvent) currentEvent).getModifiers(); } ActionEvent e = null; // Process the listeners last to first, notifying // those that are interested in this event for (int i = listeners.length - 2; i >= 0; i -= 2) { if (listeners[i] == ActionListener.class) { // Lazily create the event: if (e == null) { e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, command, mostRecentEventTime, modifiers); } ((ActionListener) listeners[i + 1]).actionPerformed(e); } } }
From source file:us.daveread.basicquery.BasicQuery.java
/** * Copy the selected data cells to the clipboard *//*from ww w .j a v a2 s .c om*/ private void copySelectionToClipboard() { Action objlCopy; try { objlCopy = TransferHandler.getCopyAction(); objlCopy.actionPerformed(new ActionEvent(table, ActionEvent.ACTION_PERFORMED, (String) objlCopy.getValue(Action.NAME), EventQueue.getMostRecentEventTime(), 0)); } catch (Throwable any) { LOGGER.error("Failed to copy data to clipboard", any); JOptionPane.showMessageDialog(this, Resources.getString("errClipboardCopyDataText", any.getClass().getName(), any.getMessage() != null ? any.getMessage() : ""), Resources.getString("errClipboardCopyDataTitle"), JOptionPane.ERROR_MESSAGE); } }