List of usage examples for java.awt.event ActionEvent getWhen
public long getWhen()
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 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:Main.java
public static void main(final String args[]) { final String labels[] = { "A", "B", "C", "D", "E" }; JFrame frame = new JFrame("Selecting JComboBox"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JComboBox comboBox = new JComboBox(labels); frame.add(comboBox, BorderLayout.SOUTH); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("Command: " + actionEvent.getActionCommand()); ItemSelectable is = (ItemSelectable) actionEvent.getSource(); System.out.println(", Selected: " + selectedString(is)); System.out.println(", Selected: " + new Date(actionEvent.getWhen())); }// w w w . j av a2 s . c o m }; comboBox.addActionListener(actionListener); frame.setSize(400, 200); frame.setVisible(true); }
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 ww w . 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:gsn.wrappers.SystemTime.java
public void actionPerformed(ActionEvent actionEvent) { StreamElement streamElement = new StreamElement(EMPTY_FIELD_LIST, EMPTY_FIELD_TYPES, EMPTY_DATA_PART, actionEvent.getWhen()); if (delayPostingElements) { streamElementBuffer.add(streamElement); synchronized (objectLock) { objectLock.notifyAll();/*from ww w. j a v a 2 s. c o m*/ } } else postStreamElement(streamElement); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopButton.java
public DesktopButton() { impl = createImplementation();//from w w w . j a v a 2 s. co m impl.addActionListener(new ValidationAwareActionListener() { @Override public void actionPerformedAfterValidation(ActionEvent e) { if (action != null) { if (shouldBeFocused && !impl.isFocusOwner() && impl.isFocusable()) { return; } if (useResponsePending && e.getWhen() <= responseEndTs) { return; } if (disableOnClick) { impl.setEnabled(false); } try { userActionsLog.trace("Button (id = {}, caption = {}) on frame {} was clicked", id, caption, frame == null ? " NULL " : frame.getId()); action.actionPerform(DesktopButton.this); } finally { responseEndTs = System.currentTimeMillis(); } } } }); DesktopComponentsHelper.adjustSize(impl); }
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./* w w w. j a va 2 s . c o 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.paxle.desktop.impl.event.MultipleChangesListener.java
public void actionPerformed(ActionEvent e) { setState(e.getSource(), e.getWhen()); }
From source file:org.rdv.datapanel.DigitalTabularDataPanel.java
private void addColumn() { if (columnGroupCount == MAX_COLUMN_GROUP_COUNT) { return;/*from w w w. j a v a 2s . com*/ } 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:org.wings.SAbstractButton.java
/** * Fire an ActionEvent at each registered listener. * * @param event supplied ActionEvent/*from ww w. jav 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); } } }