java.awt.AWTEvent Java Examples
The following examples show how to use
java.awt.AWTEvent.
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: SwingUtilities3.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@SuppressWarnings("unchecked") public EventQueueDelegateFromMap(Map<String, Map<String, Object>> objectMap) { Map<String, Object> methodMap = objectMap.get("afterDispatch"); afterDispatchEventArgument = (AWTEvent[]) methodMap.get("event"); afterDispatchHandleArgument = (Object[]) methodMap.get("handle"); afterDispatchCallable = (Callable<Void>) methodMap.get("method"); methodMap = objectMap.get("beforeDispatch"); beforeDispatchEventArgument = (AWTEvent[]) methodMap.get("event"); beforeDispatchCallable = (Callable<Object>) methodMap.get("method"); methodMap = objectMap.get("getNextEvent"); getNextEventEventQueueArgument = (EventQueue[]) methodMap.get("eventQueue"); getNextEventCallable = (Callable<AWTEvent>) methodMap.get("method"); }
Example #2
Source File: EditorScrollPane.java From nextreports-designer with Apache License 2.0 | 6 votes |
/** * Creates a scroll pane with preferred size (width, height). * * @param width The preferred width of <code>area</code>. * @param height The preferred height of <code>area</code>. * @param area The text area this scroll pane will contain. * @param lineNumbersEnabled Whether line numbers are initially enabled. * @param lineNumberColor The color to use for line numbers. */ public EditorScrollPane(int width, int height, JEditorPane area, boolean lineNumbersEnabled, Color lineNumberColor) { super(area); setPreferredSize(new Dimension(width, height)); // Create the text area and set it inside this scrollbar area. editorPane = area; // Create the line number list for this document. enableEvents(AWTEvent.MOUSE_EVENT_MASK); lineNumberBorder = new LineNumberBorder(this, editorPane, lineNumberColor); lineNumberBorder.setFont(getDefaultFont()); setLineNumbersEnabled(lineNumbersEnabled); // Set miscellaneous properties. setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); }
Example #3
Source File: PanningManager.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
@Override public void eventDispatched(AWTEvent e) { if (e instanceof MouseEvent) { MouseEvent me = (MouseEvent) e; if (!SwingUtilities.isDescendingFrom(me.getComponent(), target)) { return; } if (me.getID() == MouseEvent.MOUSE_RELEASED) { // stop when mouse released mouseOnScreenPoint = null; if (timer.isRunning()) { timer.stop(); } } else if (me.getID() == MouseEvent.MOUSE_DRAGGED && me.getComponent() == target) { mouseOnScreenPoint = me.getLocationOnScreen(); } else if (me.getID() == MouseEvent.MOUSE_PRESSED && me.getComponent() == target) { mouseOnScreenPoint = me.getLocationOnScreen(); timer.start(); } } }
Example #4
Source File: ClickSensitivityControl.java From pumpernickel with MIT License | 6 votes |
@Override public void eventDispatched(AWTEvent e) { MouseEvent m = (MouseEvent) e; if (m.getID() == MouseEvent.MOUSE_CLICKED) { mouseClicked(m); } else if (m.getID() == MouseEvent.MOUSE_DRAGGED) { mouseDragged(m); } else if (m.getID() == MouseEvent.MOUSE_ENTERED) { mouseEntered(m); } else if (m.getID() == MouseEvent.MOUSE_EXITED) { mouseExited(m); } else if (m.getID() == MouseEvent.MOUSE_MOVED) { mouseMoved(m); } else if (m.getID() == MouseEvent.MOUSE_PRESSED) { mousePressed(m); } else if (m.getID() == MouseEvent.MOUSE_RELEASED) { mouseReleased(m); } }
Example #5
Source File: MainFrame.java From javamelody with Apache License 2.0 | 6 votes |
private void initActivityMonitor() { lastActivity = System.currentTimeMillis(); final AWTEventListener awtEventListener = new AWTEventListener() { /** {@inheritDoc} */ @Override public void eventDispatched(AWTEvent event) { lastActivity = System.currentTimeMillis(); } }; Toolkit.getDefaultToolkit().addAWTEventListener(awtEventListener, AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_WHEEL_EVENT_MASK); final Timer activityMonitorTimer = new Timer("ActivityMonitorTimer", true); final TimerTask timerTask = new TimerTask() { /** {@inheritDoc} */ @Override public void run() { if (System.currentTimeMillis() - lastActivity > INACTIVITY_DELAY * 60L * 1000) { exit(1); } } }; // on vérifie l'activité utilisateur toutes les 60 secondes par rapport au délai maximum d'inactivité activityMonitorTimer.schedule(timerTask, 60L * 1000, 60L * 1000); }
Example #6
Source File: DitherTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
@Override protected void processEvent(AWTEvent evt) { int id = evt.getID(); if (id != KeyEvent.KEY_TYPED) { super.processEvent(evt); return; } KeyEvent kevt = (KeyEvent) evt; char c = kevt.getKeyChar(); // Digits, backspace, and delete are okay // Note that the minus sign is not allowed (neither is decimal) if (Character.isDigit(c) || (c == '\b') || (c == '\u007f')) { super.processEvent(evt); return; } Toolkit.getDefaultToolkit().beep(); kevt.consume(); }
Example #7
Source File: CompletionLayoutPopup.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void eventDispatched(AWTEvent aWTEvent) { if (aWTEvent instanceof MouseEvent) { MouseEvent mv = (MouseEvent) aWTEvent; if (mv.getID() == MouseEvent.MOUSE_CLICKED && mv.getClickCount() > 0) { //#118828 if (!(aWTEvent.getSource() instanceof Component)) { hide(); return; } Component comp = (Component) aWTEvent.getSource(); Container par1 = SwingUtilities.getAncestorNamed(POPUP_NAME, comp); //NOI18N if (par1 == null) { hide(); } } } }
Example #8
Source File: PopupUtil.java From netbeans with Apache License 2.0 | 6 votes |
public void eventDispatched(java.awt.AWTEvent aWTEvent) { if (aWTEvent instanceof MouseEvent) { MouseEvent mv = (MouseEvent)aWTEvent; if (mv.getID() == MouseEvent.MOUSE_CLICKED && mv.getClickCount() > 0) { //#118828 if (! (aWTEvent.getSource() instanceof Component)) { hidePopup(); return; } Component comp = (Component)aWTEvent.getSource(); Container par = SwingUtilities.getAncestorNamed(POPUP_NAME, comp); //NOI18N // Container barpar = SwingUtilities.getAncestorOfClass(PopupUtil.class, comp); // if (par == null && barpar == null) { if ( par == null ) { hidePopup(); } } } }
Example #9
Source File: ActionStatisticsCollector.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
protected void start() { if (RapidMiner.getExecutionMode().isHeadless()) { return; } long eventMask = AWTEvent.MOUSE_EVENT_MASK + AWTEvent.KEY_EVENT_MASK; Toolkit.getDefaultToolkit().addAWTEventListener(e -> { if (e.getID() == KeyEvent.KEY_RELEASED) { if (((KeyEvent) e).getComponent() != null) { lastUserActionTime = System.currentTimeMillis(); } } else if (e.getID() == MouseEvent.MOUSE_RELEASED) { final MouseEvent me = (MouseEvent) e; Component component = me.getComponent(); logAction(component); } }, eventMask); RapidMinerGUI.getMainFrame().getDockingDesktop().addDockableStateChangeListener(e -> log(TYPE_DOCKABLE, e.getNewState().getDockable().getDockKey().getKey(), e.getNewState().getLocation().toString()) ); }
Example #10
Source File: DragLayer.java From stendhal with GNU General Public License v2.0 | 6 votes |
@Override public void eventDispatched(AWTEvent e) { if (e instanceof MouseEvent) { MouseEvent event = (MouseEvent) e; MouseEvent converted = SwingUtilities.convertMouseEvent(event.getComponent(), event, this); point = converted.getPoint(); if (e.getID() == MouseEvent.MOUSE_DRAGGED) { underlyingComponent = null; requestDraw(); } else if ((event.getID() == MouseEvent.MOUSE_RELEASED) && (dragged != null)) { underlyingComponent = null; stopDrag(event); requestDraw(); point = null; } // We are interested only in DnD, so we can ignore any other events } }
Example #11
Source File: InputMethodContext.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
public void dispatchEvent(AWTEvent event) { // some host input method adapters may dispatch input method events // through the Java event queue. If the component that the event is // intended for isn't an active client, or if we're using below-the-spot // input, we need to dispatch this event // to the input window. Note that that component is not necessarily the // current client component, since we may have switched clients while // the event was in the queue. if (event instanceof InputMethodEvent) { if (((Component) event.getSource()).getInputMethodRequests() == null || (useBelowTheSpotInput() && !dispatchingCommittedText)) { getCompositionAreaHandler(true).processInputMethodEvent((InputMethodEvent) event); } } else { // make sure we don't dispatch our own key events back to the input method if (!dispatchingCommittedText) { super.dispatchEvent(event); } } }
Example #12
Source File: InputMethodContext.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public void dispatchEvent(AWTEvent event) { // some host input method adapters may dispatch input method events // through the Java event queue. If the component that the event is // intended for isn't an active client, or if we're using below-the-spot // input, we need to dispatch this event // to the input window. Note that that component is not necessarily the // current client component, since we may have switched clients while // the event was in the queue. if (event instanceof InputMethodEvent) { if (((Component) event.getSource()).getInputMethodRequests() == null || (useBelowTheSpotInput() && !dispatchingCommittedText)) { getCompositionAreaHandler(true).processInputMethodEvent((InputMethodEvent) event); } } else { // make sure we don't dispatch our own key events back to the input method if (!dispatchingCommittedText) { super.dispatchEvent(event); } } }
Example #13
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 #14
Source File: DitherTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Override protected void processEvent(AWTEvent evt) { int id = evt.getID(); if (id != KeyEvent.KEY_TYPED) { super.processEvent(evt); return; } KeyEvent kevt = (KeyEvent) evt; char c = kevt.getKeyChar(); // Digits, backspace, and delete are okay // Note that the minus sign is not allowed (neither is decimal) if (Character.isDigit(c) || (c == '\b') || (c == '\u007f')) { super.processEvent(evt); return; } Toolkit.getDefaultToolkit().beep(); kevt.consume(); }
Example #15
Source File: XComponentPeer.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
void handleJavaFocusEvent(AWTEvent e) { if (focusLog.isLoggable(PlatformLogger.Level.FINER)) { focusLog.finer(e.toString()); } if (e.getID() == FocusEvent.FOCUS_GAINED) { focusGained((FocusEvent)e); } else { focusLost((FocusEvent)e); } }
Example #16
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 #17
Source File: JFileChooser.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * 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 */ 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); } } }
Example #18
Source File: JListXTest.java From marathonv5 with Apache License 2.0 | 5 votes |
@BeforeMethod public void showDialog() throws Throwable { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { @Override public void eventDispatched(AWTEvent event) { } }, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK); frame = new JFrame("My Dialog"); frame.setName("dialog-1"); Object[] listData = new Object[30]; for (int i = 1; i <= listData.length; i++) { if (i == 25) { listData[i - 1] = "List Item - '" + i + "'"; } else { listData[i - 1] = "List Item - " + i; } } list = new JList(listData); list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); list.setName("list-1"); list.setDragEnabled(true); JPanel p = new JPanel(new BorderLayout()); p.add(new JScrollPane(list), BorderLayout.NORTH); textfield = new JTextField(80); textfield.setName("text-field"); textfield.setDropMode(DropMode.USE_SELECTION); p.add(textfield, BorderLayout.SOUTH); frame.getContentPane().add(p); frame.pack(); frame.setAlwaysOnTop(true); frame.setVisible(true); list.requestFocusInWindow(); } }); }
Example #19
Source File: KeyCharTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override public void eventDispatched(AWTEvent event) { eventsCount++; char delete = ((KeyEvent) event).getKeyChar(); if (delete != '\u007f') { throw new RuntimeException("Key char is not delete: '" + delete + "'"); } }
Example #20
Source File: JFileChooser.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
/** * 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 */ 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); } } }
Example #21
Source File: CompositionArea.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
CompositionArea() { // create composition window with localized title String windowTitle = Toolkit.getProperty("AWT.CompositionWindowTitle", "Input Window"); compositionWindow = (JFrame)InputMethodContext.createInputMethodWindow(windowTitle, null, true); setOpaque(true); setBorder(LineBorder.createGrayLineBorder()); setForeground(Color.black); setBackground(Color.white); // if we get the focus, we still want to let the client's // input context handle the event enableInputMethods(true); enableEvents(AWTEvent.KEY_EVENT_MASK); compositionWindow.getContentPane().add(this); compositionWindow.addWindowListener(new FrameWindowAdapter()); addInputMethodListener(this); compositionWindow.enableInputMethods(false); compositionWindow.pack(); Dimension windowSize = compositionWindow.getSize(); Dimension screenSize = (getToolkit()).getScreenSize(); compositionWindow.setLocation(screenSize.width - windowSize.width-20, screenSize.height - windowSize.height-100); compositionWindow.setVisible(false); }
Example #22
Source File: XComponentPeer.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
final static AWTEvent wrapInSequenced(AWTEvent event) { try { if (seClass == null) { seClass = Class.forName("java.awt.SequencedEvent"); } if (seCtor == null) { seCtor = (Constructor) AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws Exception { Constructor ctor = seClass.getConstructor(new Class[] { AWTEvent.class }); ctor.setAccessible(true); return ctor; } }); } return (AWTEvent) seCtor.newInstance(new Object[] { event }); } catch (ClassNotFoundException e) { throw new NoClassDefFoundError("java.awt.SequencedEvent."); } catch (PrivilegedActionException ex) { throw new NoClassDefFoundError("java.awt.SequencedEvent."); } catch (InstantiationException e) { assert false; } catch (IllegalAccessException e) { assert false; } catch (InvocationTargetException e) { assert false; } return null; }
Example #23
Source File: InteractiveMorphologicalReconstruction.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
/** * Called when a dialog widget has been modified: recomputes option values * from dialog content. */ public boolean dialogItemChanged(GenericDialog gd, AWTEvent evt) { // set up current parameters operation = Operation.fromLabel(gd.getNextChoice()); connectivity = Conn2D.fromLabel(gd.getNextChoice()); return true; }
Example #24
Source File: NbClipboard.java From netbeans with Apache License 2.0 | 5 votes |
NbClipboard( Clipboard systemClipboard ) { super("NBClipboard"); // NOI18N this.systemClipboard = systemClipboard; result = Lookup.getDefault().lookupResult(ExClipboard.Convertor.class); result.addLookupListener(this); systemClipboard.addFlavorListener(this); resultChanged(null); if (System.getProperty("netbeans.slow.system.clipboard.hack") != null) { slowSystemClipboard = Boolean.getBoolean("netbeans.slow.system.clipboard.hack"); // NOI18N } else if (Utilities.isMac()) { slowSystemClipboard = false; } else { slowSystemClipboard = true; } if (System.getProperty("sun.awt.datatransfer.timeout") == null) { // NOI18N System.setProperty("sun.awt.datatransfer.timeout", "1000"); // NOI18N } if (slowSystemClipboard) { Toolkit.getDefaultToolkit().addAWTEventListener( this, AWTEvent.WINDOW_EVENT_MASK); } }
Example #25
Source File: EventObserver.java From mochadoom with GNU General Public License v3.0 | 5 votes |
/** * Consumes InputEvents so they will not pass further */ protected void discardInputEvent(final AWTEvent ev) { try { ((InputEvent) ev).consume(); } catch (ClassCastException ex) { LOGGER.log(Level.SEVERE, null, ex); } }
Example #26
Source File: BasicPopupMenuUI.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
void grabWindow(MenuElement[] newPath) { // A grab needs to be added final Toolkit tk = Toolkit.getDefaultToolkit(); java.security.AccessController.doPrivileged( new java.security.PrivilegedAction<Object>() { public Object run() { tk.addAWTEventListener(MouseGrabber.this, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_WHEEL_EVENT_MASK | AWTEvent.WINDOW_EVENT_MASK | sun.awt.SunToolkit.GRAB_EVENT_MASK); return null; } } ); Component invoker = newPath[0].getComponent(); if (invoker instanceof JPopupMenu) { invoker = ((JPopupMenu)invoker).getInvoker(); } grabbedWindow = invoker instanceof Window? (Window)invoker : SwingUtilities.getWindowAncestor(invoker); if(grabbedWindow != null) { if(tk instanceof sun.awt.SunToolkit) { ((sun.awt.SunToolkit)tk).grab(grabbedWindow); } else { grabbedWindow.addComponentListener(this); grabbedWindow.addWindowListener(this); } } }
Example #27
Source File: SunDragSourceContextPeer.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Filters out all mouse events that were on the java event queue when * startDrag was called. */ public static boolean checkEvent(AWTEvent event) { if (discardingMouseEvents && event instanceof MouseEvent) { MouseEvent mouseEvent = (MouseEvent)event; if (!(mouseEvent instanceof SunDropTargetEvent)) { return false; } } return true; }
Example #28
Source File: MorphologicalFilterPlugin.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
public boolean dialogItemChanged(GenericDialog gd, AWTEvent evt) { boolean wasPreview = this.previewing; parseDialogParameters(gd); // if preview checkbox was unchecked, replace the preview image by the original image if (wasPreview && !this.previewing) { resetPreview(); } return true; }
Example #29
Source File: ContainerFocusAutoTransferTest.java From hottub 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 #30
Source File: JavaHelp.java From netbeans with Apache License 2.0 | 5 votes |
/** Make a JavaHelp implementation of the Help.Impl interface. *Or, use {@link #getDefaultJavaHelp}. */ public JavaHelp() { Installer.log.fine("JavaHelp created"); if (!isModalExcludedSupported()) { Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.WINDOW_EVENT_MASK); } }