Java Code Examples for java.awt.AWTEvent#getSource()
The following examples show how to use
java.awt.AWTEvent#getSource() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwingGui.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Processes the next GUI event. */ public void dispatchNextGuiEvent() throws InterruptedException { EventQueue queue = awtEventQueue; if (queue == null) { queue = Toolkit.getDefaultToolkit().getSystemEventQueue(); awtEventQueue = queue; } AWTEvent event = queue.getNextEvent(); if (event instanceof ActiveEvent) { ((ActiveEvent)event).dispatch(); } else { Object source = event.getSource(); if (source instanceof Component) { Component comp = (Component)source; comp.dispatchEvent(event); } else if (source instanceof MenuComponent) { ((MenuComponent)source).dispatchEvent(event); } } }
Example 2
Source File: XDMFrame.java From xdm with GNU General Public License v2.0 | 6 votes |
private synchronized void startModal(Component comp) { try { if (SwingUtilities.isEventDispatchThread()) { EventQueue theQueue = Toolkit.getDefaultToolkit().getSystemEventQueue(); while (comp.isVisible()) { AWTEvent event = theQueue.getNextEvent(); Object source = event.getSource(); if (event instanceof ActiveEvent) { ((ActiveEvent) event).dispatch(); } else if (source instanceof Component) { ((Component) source).dispatchEvent(event); } else if (source instanceof MenuComponent) { ((MenuComponent) source).dispatchEvent(event); } else { System.err.println("Unable to dispatch: " + event); } } } else { while (comp.isVisible()) { wait(); } } } catch (InterruptedException ignored) { } }
Example 3
Source File: SwingGui.java From JsDroidCmd with Mozilla Public License 2.0 | 6 votes |
/** * Processes the next GUI event. */ public void dispatchNextGuiEvent() throws InterruptedException { EventQueue queue = awtEventQueue; if (queue == null) { queue = Toolkit.getDefaultToolkit().getSystemEventQueue(); awtEventQueue = queue; } AWTEvent event = queue.getNextEvent(); if (event instanceof ActiveEvent) { ((ActiveEvent)event).dispatch(); } else { Object source = event.getSource(); if (source instanceof Component) { Component comp = (Component)source; comp.dispatchEvent(event); } else if (source instanceof MenuComponent) { ((MenuComponent)source).dispatchEvent(event); } } }
Example 4
Source File: SelectTrackAction.java From tuxguitar with GNU Lesser General Public License v2.1 | 6 votes |
protected void processAction(TGActionContext context) { final AWTEvent awtEvent = context.getAttribute(AWTEvent.class.getName()); final Caret caret = TuxGuitar.instance().getTablatureEditor().getTablature().getCaret(); final JButton button = (JButton) awtEvent.getSource(); final JPopupMenu menu = new JPopupMenu(); Iterator<?> it = TuxGuitar.instance().getTablatureEditor().getTablature().getSong().getTracks(); while( it.hasNext() ){ final TGTrack track = (TGTrack) it.next(); JMenuItem item = new JRadioButtonMenuItem( track.getName() , (track.getNumber() == caret.getTrack().getNumber()) ); item.setFont( TGConfig.FONT_WIDGETS ); item.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { caret.update( track.getNumber() ); TuxGuitar.instance().updateCache( true ); } }); menu.add( item ); } menu.show(button, 0, button.getHeight() ); }
Example 5
Source File: ButtonPopupSwitcher.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void eventDispatched(AWTEvent event) { if (event.getSource() == this) { return; } if (event instanceof KeyEvent) { if (event.getID() == KeyEvent.KEY_PRESSED) { if( !changeSelection( (KeyEvent)event ) ) { Toolkit.getDefaultToolkit().removeAWTEventListener(this); hideCurrentPopup(); } else { ((KeyEvent)event).consume(); } } } }
Example 6
Source File: TooltipWindow.java From netbeans with Apache License 2.0 | 5 votes |
private void onClick(AWTEvent event) { Component component = (Component) event.getSource(); if (outsideOfTooltipWindow(component)) { // hide the tooltip if event occurs outside of the tooltip shutdown(); } }
Example 7
Source File: ContainerFocusAutoTransferTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public boolean dispatchEvent(AWTEvent e) { if (e.getID() == FocusEvent.FOCUS_GAINED) { System.out.println(e); Component src = (Component)e.getSource(); if (src == frame.b1 || src == frame.b2) { throw new TestFailedException("wrong focus transfer on removal!"); } } return super.dispatchEvent(e); }
Example 8
Source File: ContainerFocusAutoTransferTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public boolean dispatchEvent(AWTEvent e) { if (e.getID() == FocusEvent.FOCUS_GAINED) { System.out.println(e); Component src = (Component)e.getSource(); if (src == frame.b1 || src == frame.b2) { throw new TestFailedException("wrong focus transfer on removal!"); } } return super.dispatchEvent(e); }
Example 9
Source File: TooltipWindow.java From netbeans with Apache License 2.0 | 5 votes |
private void onClick(AWTEvent event) { Component component = (Component) event.getSource(); if (outsideOfTooltipWindow(component)) { // hide the tooltip if event occurs outside of the tooltip shutdown(); } }
Example 10
Source File: ContainerFocusAutoTransferTest.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public boolean dispatchEvent(AWTEvent e) { if (e.getID() == FocusEvent.FOCUS_GAINED) { System.out.println(e); Component src = (Component)e.getSource(); if (src == frame.b1 || src == frame.b2) { throw new TestFailedException("wrong focus transfer on removal!"); } } return super.dispatchEvent(e); }
Example 11
Source File: DrawTableValuesPlugin.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean dialogItemChanged(GenericDialog gd, AWTEvent evt) { if (gd.wasCanceled() || gd.wasOKed()) { return true; } @SuppressWarnings({ "unchecked" }) Vector<Choice> choices = gd.getChoices(); if (choices == null) { IJ.log("empty choices array..."); return false; } // Change of the data table if (evt.getSource() == choices.get(0)) { String tableName = ((Choice) evt.getSource()).getSelectedItem(); Frame tableFrame = WindowManager.getFrame(tableName); this.table = ((TextWindow) tableFrame).getTextPanel().getResultsTable(); // Choose current headings String[] headings = this.table.getHeadings(); replaceStrings(choices.get(1), headings, chooseDefaultHeading(headings, xPosHeaderName)); replaceStrings(choices.get(2), headings, chooseDefaultHeading(headings, yPosHeaderName)); replaceStrings(choices.get(3), headings, chooseDefaultHeading(headings, valueHeaderName)); } return true; }
Example 12
Source File: TooltipWindow.java From netbeans with Apache License 2.0 | 5 votes |
private void onClick(AWTEvent event) { Component component = (Component) event.getSource(); if (outsideOfTooltipWindow(component)) { // hide the tooltip if event occurs outside of the tooltip shutdown(); } }
Example 13
Source File: ContainerFocusAutoTransferTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public boolean dispatchEvent(AWTEvent e) { if (e.getID() == FocusEvent.FOCUS_GAINED) { System.out.println(e); Component src = (Component)e.getSource(); if (src == frame.b1 || src == frame.b2) { throw new TestFailedException("wrong focus transfer on removal!"); } } return super.dispatchEvent(e); }
Example 14
Source File: ContainerFocusAutoTransferTest.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public boolean dispatchEvent(AWTEvent e) { if (e.getID() == FocusEvent.FOCUS_GAINED) { System.out.println(e); Component src = (Component)e.getSource(); if (src == frame.b1 || src == frame.b2) { throw new TestFailedException("wrong focus transfer on removal!"); } } return super.dispatchEvent(e); }
Example 15
Source File: ExtTestCase.java From netbeans with Apache License 2.0 | 5 votes |
private static void dispatchEvent(EventQueue queue, AWTEvent evt) throws Exception { if (queue == null) { queue = Toolkit.getDefaultToolkit().getSystemEventQueue(); } Method m = EventQueue.class.getDeclaredMethod("dispatchEvent", new Class[] {AWTEvent.class}); m.setAccessible(true); if (evt.getSource() instanceof JTextField) { foo = System.currentTimeMillis(); } m.invoke(queue, new Object[] {evt}); }
Example 16
Source File: ContainerFocusAutoTransferTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public boolean dispatchEvent(AWTEvent e) { if (e.getID() == FocusEvent.FOCUS_GAINED) { System.out.println(e); Component src = (Component)e.getSource(); if (src == frame.b1 || src == frame.b2) { throw new TestFailedException("wrong focus transfer on removal!"); } } return super.dispatchEvent(e); }
Example 17
Source File: ContainerFocusAutoTransferTest.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public boolean dispatchEvent(AWTEvent e) { if (e.getID() == FocusEvent.FOCUS_GAINED) { System.out.println(e); Component src = (Component)e.getSource(); if (src == frame.b1 || src == frame.b2) { throw new TestFailedException("wrong focus transfer on removal!"); } } return super.dispatchEvent(e); }
Example 18
Source File: BreadCrumbComponent.java From netbeans with Apache License 2.0 | 4 votes |
private void expand(int startX, final Node what) { if (what.getChildren().getNodesCount() == 0) return ; final ExplorerManager expandManager = new ExplorerManager(); class Expanded extends JPanel implements ExplorerManager.Provider { public Expanded(LayoutManager layout) { super(layout); } @Override public ExplorerManager getExplorerManager() { return expandManager; } } final JPanel expanded = new Expanded(new BorderLayout()); expanded.setBorder(new LineBorder(Color.BLACK, 1)); final ListView listView = new ListView() { { int nodesCount = what.getChildren().getNodesCount(); if (nodesCount >= MAX_ROWS_IN_POP_UP) { list.setVisibleRowCount(MAX_ROWS_IN_POP_UP); } else { list.setVisibleRowCount(nodesCount); NodeRenderer nr = new NodeRenderer(); int i = 0; int width = getPreferredSize().width; for (Node n : what.getChildren().getNodes()) { if (nr.getListCellRendererComponent(list, n, i, false, false).getPreferredSize().width > width) { Dimension pref = getPreferredSize(); pref.height += getHorizontalScrollBar().getPreferredSize().height; setPreferredSize(pref); break; } } } } }; listView.setPopupAllowed(false); expanded.add(listView, BorderLayout.CENTER); expandManager.setRootContext(what); Point place = new Point(startX, 0); SwingUtilities.convertPointToScreen(place, this); expanded.validate(); final Popup popup = PopupFactory.getSharedInstance().getPopup(this, expanded, place.x, place.y - expanded.getPreferredSize().height); final AWTEventListener multicastListener = new AWTEventListener() { @Override public void eventDispatched(AWTEvent event) { if (event instanceof MouseEvent && ((MouseEvent) event).getClickCount() > 0) { Object source = event.getSource(); while (source instanceof Component) { if (source == expanded) return ; //accept source = ((Component) source).getParent(); } popup.hide(); Toolkit.getDefaultToolkit().removeAWTEventListener(this); } } }; Toolkit.getDefaultToolkit().addAWTEventListener(multicastListener, AWTEvent.MOUSE_EVENT_MASK); expandManager.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) { Node[] selected = expandManager.getSelectedNodes(); if (selected.length == 1) { open(selected[0]); popup.hide(); Toolkit.getDefaultToolkit().removeAWTEventListener(multicastListener); } } } }); popup.show(); }
Example 19
Source File: Editor.java From jclic with GNU General Public License v2.0 | 4 votes |
protected static Component findParentForDlg(AWTEvent ev) { if (ev != null && ev.getSource() instanceof Component) return (Component) ev.getSource(); else return null; }
Example 20
Source File: SnippetCreator.java From Scripts with GNU General Public License v3.0 | 4 votes |
@Override public boolean dialogItemChanged(final GenericDialog gd, final AWTEvent e) { final Object source = (e == null) ? null : e.getSource(); final Vector<?> choices = gd.getChoices(); final Vector<?> fields = gd.getStringFields(); final Button[] buttons = gd.getButtons(); final Choice fChoice = (Choice) choices.elementAt(0); final TextField fField = (TextField) fields.elementAt(0); final Button okButton = buttons[0]; sFilename = gd.getNextString(); sType = gd.getNextChoiceIndex(); infoMsg = (MultiLineLabel) gd.getMessage(); // Populate text area if (source == fChoice) { String header = ""; switch (sType) { case BSH: header = bshHeader(); break; case CLJ: header = cljHeader(); break; case GRV: header = grvHeader(); break; case IJM: header = ijmHeader(); break; case JS: header = jsHeader(); break; case PY: header = pyHeader(); break; case RB: header = rbHeader(); break; } if (header != "") appendToTextArea(header); // Ensure adequate filename extension if (!sFilename.endsWith(S_EXTS[sType])) { final int index = sFilename.lastIndexOf("."); if (index > -1) sFilename = sFilename.substring(0, index); sFilename += S_EXTS[sType]; fField.setText(sFilename); } } // Adjust labels and fields final File f = new File(Utils.getMyRoutinesDir() + sFilename); final boolean invalidName = invalidFilename(sFilename); okButton.setLabel(f.exists() ? "Replace and Open" : " Create and Open "); fField.setForeground((f.exists()||invalidName) ? Color.RED : Color.BLACK); // Adjust messages final StringBuilder sb = new StringBuilder(); if (invalidName) { sb.append("\nInvalid Filename"); } else if (f.exists()) { sb.append("File already exists in BAR/My_Routines!"); } else if (sFilename.indexOf("_") == -1) { sb.append("\nFile does not contain an underscore"); sb.append("\nand will not be listed in the BAR Menu."); } else { sb.append("\nFile will be listed in the BAR Menu."); } infoMsg.setText(sb.toString()); infoMsg.setForeground(Color.DARK_GRAY); return !invalidName; }