@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(); }
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)) { removePopup(); return; } Component comp = (Component)aWTEvent.getSource(); Container par1 = SwingUtilities.getAncestorNamed(POPUP_NAME, comp); //NOI18N Container par2 = SwingUtilities.getAncestorNamed(SUB_POPUP_NAME, comp); //NOI18N // Container barpar = SwingUtilities.getAncestorOfClass(PopupUtil.class, comp); // if (par == null && barpar == null) { if ( par1 == null && par2 == null ) { removePopup(); } } } }
/** * Dispatches {@code AWTEvent} to component passed in constructor. If * {@code (getDispatchingModel & JemmyProperties.QUEUE_MODEL_MASK) == 0} * dispatched event directly, otherwise uses * {@code javax.swing.SwingUtilities.invokeAndWait(Runnable)}<BR> * * @param event AWTEvent instance to be dispatched. * @throws ComponentIsNotVisibleException * @throws ComponentIsNotFocusedException */ public void dispatchEvent(final AWTEvent event) { // run in dispatch thread String eventToString = queueTool.invokeSmoothly( new QueueTool.QueueAction<String>("event.toString()") { @Override public String launch() { return event.toString(); } } ); output.printLine("Dispatch event " + eventToString); output.printGolden("Dispatch event " + event.getClass().toString()); Dispatcher<Void> disp = new Dispatcher<>(event); queueTool.invokeAndWait(disp); }
private AWTEvent waitEvent(long eventMask, long waitTime, TestOut waiterOutput) { EventWaiter waiter = new EventWaiter(eventMask); waiter.setTimeouts(timeouts.cloneThis()); waiter.setOutput(waiterOutput); waiter.getTimeouts(). setTimeout("Waiter.WaitingTime", waitTime); waiter.getTimeouts(). setTimeout("Waiter.TimeDelta", timeouts.getTimeout("EventTool.EventCheckingDelta")); try { return waiter.waitAction(null); } catch (InterruptedException e) { output.printStackTrace(e); return null; } }
public @Override void eventDispatched(java.awt.AWTEvent aWTEvent) { if (aWTEvent instanceof MouseEvent) { MouseEvent mv = (MouseEvent)aWTEvent; if (mv.getClickCount() > 0) { //#118828 if (! (aWTEvent.getSource() instanceof Component)) { return; } Component comp = (Component)aWTEvent.getSource(); Container par = SwingUtilities.getAncestorNamed("progresspopup", comp); //NOI18N Container barpar = SwingUtilities.getAncestorOfClass(StatusLineComponent.class, comp); if (par == null && barpar == null) { hidePopup(); } } } }
public void show(Point location) { Rectangle screenBounds = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gds = ge.getScreenDevices(); for (GraphicsDevice device : gds) { GraphicsConfiguration gc = device.getDefaultConfiguration(); screenBounds = gc.getBounds(); if (screenBounds.contains(location)) { break; } } // showing the popup tooltip cp = new TooltipContentPanel(master.getTextComponent()); Window w = SwingUtilities.windowForComponent(master.getTextComponent()); contentWindow = new JWindow(w); contentWindow.add(cp); contentWindow.pack(); Dimension dim = contentWindow.getSize(); if (location.y + dim.height + SCREEN_BORDER > screenBounds.y + screenBounds.height) { dim.height = (screenBounds.y + screenBounds.height) - (location.y + SCREEN_BORDER); } if (location.x + dim.width + SCREEN_BORDER > screenBounds.x + screenBounds.width) { dim.width = (screenBounds.x + screenBounds.width) - (location.x + SCREEN_BORDER); } contentWindow.setSize(dim); contentWindow.setLocation(location.x, location.y - 1); // slight visual adjustment contentWindow.setVisible(true); Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.KEY_EVENT_MASK); w.addWindowFocusListener(this); contentWindow.addWindowFocusListener(this); }
private void doSelect(JComponent owner) { invokingComponent = owner; invokingComponent.addMouseListener(this); invokingComponent.addMouseMotionListener(this); pTable.addMouseListener(this); pTable.addMouseMotionListener(this); pTable.getSelectionModel().addListSelectionListener( this ); displayer.getModel().addComplexListDataListener( this ); Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK); popup = new JPopupMenu(); popup.setBorderPainted( false ); popup.setBorder( BorderFactory.createEmptyBorder() ); popup.add( pTable ); popup.pack(); int locationX = x - (int) pTable.getPreferredSize().getWidth(); int locationY = y + 1; popup.setLocation( locationX, locationY ); popup.setInvoker( invokingComponent ); popup.addPopupMenuListener( this ); popup.setVisible( true ); shown = true; invocationTime = System.currentTimeMillis(); }
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(); } } } }
@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(); } } } }
@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"); }
public void eventDispatched(AWTEvent e) { if (popup == null) return; // Not a mouse event if (!(e instanceof MouseEvent)) return; MouseEvent me = (MouseEvent)e; // Event not relevant if (isIgnoreEvent(me)) return; // Mouse moved over popup if (me.getID() == MouseEvent.MOUSE_MOVED && overPopup(me)) return; if (!overPopup(me)) { // Mouse event outside of popup hidePopup(); } else if (isForwardEvent(me)) { // Mouse event on popup, to be forwarded to table Point popupPoint = popupLocation; hidePopup(); forwardEvent(me, popupPoint); } }
/** * Creates and shows the popup with given <code>items</code>. When user * selects an item <code>SwitcherTableItem.Activatable.activate()</code> is * called. So what exactly happens depends on the concrete * <code>SwitcherTableItem.Activatable</code> implementation. * Selection is made when user releases a <code>releaseKey</code> passed on * as a parameter. If user releases the <code>releaseKey</code> before a * specified time (<code>TIME_TO_SHOW</code>) expires the popup won't show * at all and switch to the last used document will be performed * immediately. * * A popup appears on <code>x</code>, <code>y</code> coordinates. */ public static void selectItem(SwitcherTableItem items[], int releaseKey, int triggerKey, boolean forward, boolean cancelOnFocusLost) { // reject multiple invocations if (invokerTimerRunning) { return; } KeyboardPopupSwitcher.items = items; KeyboardPopupSwitcher.releaseKey = releaseKey; KeyboardPopupSwitcher.triggerKey = triggerKey; KeyboardPopupSwitcher.cancelOnFocusLost = cancelOnFocusLost; invokerTimer = new Timer(TIME_TO_SHOW, new PopupInvoker(forward)); invokerTimer.setRepeats(false); invokerTimer.start(); invokerTimerRunning = true; awtListener = new AWTListener(); Toolkit.getDefaultToolkit().addAWTEventListener(awtListener, AWTEvent.KEY_EVENT_MASK); }
/** * Popup should be closed under some circumstances. Namely when mouse is * pressed or released outside of popup or when key is pressed during the * time popup is visible. */ public void eventDispatched(AWTEvent event) { if (event.getSource() == this) { return; } if (event instanceof MouseEvent) { if (event.getID() == MouseEvent.MOUSE_RELEASED) { long time = System.currentTimeMillis(); // check if button was just slowly clicked if (time - invocationTime > 500) { if (!onSwitcherTable((MouseEvent) event)) { // Don't take any chances hideCurrentPopup(); } } } else if (event.getID() == MouseEvent.MOUSE_PRESSED) { if (!onSwitcherTable((MouseEvent) event)) { // Don't take any chances if (event.getSource() != invokingComponent) { // If it's the invoker, don't do anything - it will // generate another call to invoke(), which will do the // hiding - if we do it here, it will get shown again // when the button processes the event hideCurrentPopup(); } } } } else if (event instanceof KeyEvent) { if (event.getID() == KeyEvent.KEY_PRESSED) { Toolkit.getDefaultToolkit().removeAWTEventListener(this); hideCurrentPopup(); } } }
public void run() { while( isModal() ) { handleIdleTime(); try { AWTEvent event = Toolkit.getDefaultToolkit().getSystemEventQueue().getNextEvent(); dispatchEvent( event ); } catch( Throwable e ) { handleUncaughtException( e ); } } }
@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(); } } }
@Override public void eventDispatched(AWTEvent event) { if (ignoreMouseEvents) { return; } Component root = SwingUtilities.getRoot((Component) event.getSource()); if (root instanceof IRecordingArtifact || root.getName().startsWith("###")) { return; } if (!(event instanceof MouseEvent)) { return; } MouseEvent mouseEvent = (MouseEvent) event; mouseEvent.consume(); if (event.getID() == MouseEvent.MOUSE_PRESSED) { disposeOverlay(); Component mouseComponent = SwingUtilities.getDeepestComponentAt(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY()); if (mouseComponent == null) { return; } mouseEvent = SwingUtilities.convertMouseEvent(mouseEvent.getComponent(), mouseEvent, mouseComponent); setComponent(mouseComponent, mouseEvent.getPoint(), true); return; } }
/** Called by the constructors to init the <code>JFrame</code> properly. */ protected void frameInit() { enableEvents(AWTEvent.KEY_EVENT_MASK | AWTEvent.WINDOW_EVENT_MASK); setLocale( JComponent.getDefaultLocale() ); setRootPane(createRootPane()); setBackground(UIManager.getColor("control")); setRootPaneCheckingEnabled(true); if (JFrame.isDefaultLookAndFeelDecorated()) { boolean supportsWindowDecorations = UIManager.getLookAndFeel().getSupportsWindowDecorations(); if (supportsWindowDecorations) { setUndecorated(true); getRootPane().setWindowDecorationStyle(JRootPane.FRAME); } } sun.awt.SunToolkit.checkAndSetPolicy(this); }
public AppFrame() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch (Exception e) { new ExceptionDialog(e); } }
public AppFrame_AboutBox(Frame parent) { super(parent); enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } setSize(400, 500); }
/** * Returns the default implementation of the dispatcher * * @return MouseInterceptor */ public static MouseInterceptor get() { if (instance == null) { instance = new MouseInterceptor(); Toolkit.getDefaultToolkit().addAWTEventListener(instance, AWTEvent.MOUSE_EVENT_MASK); Toolkit.getDefaultToolkit().addAWTEventListener(instance, AWTEvent.MOUSE_MOTION_EVENT_MASK); Toolkit.getDefaultToolkit().addAWTEventListener(instance, AWTEvent.MOUSE_WHEEL_EVENT_MASK); } return instance; }
/** * Creates a new mouse dispatcher */ private HierarchyMouseDispatcher() { listeners = new ArrayList<>(); Toolkit tk = Toolkit.getDefaultToolkit(); tk.addAWTEventListener((AWTEvent e) -> { if (e instanceof MouseEvent) { redirectMouseEvent((MouseEvent) e); } }, AWTEvent.MOUSE_MOTION_EVENT_MASK); }
/** * Creates an input method event from the arguments given * and posts it on the AWT event queue. For arguments, * see InputMethodEvent. Called by input method. * * @see java.awt.event.InputMethodEvent#InputMethodEvent */ private void postInputMethodEvent(int id, AttributedCharacterIterator text, int committedCharacterCount, TextHitInfo caret, TextHitInfo visiblePosition, long when) { Component source = getClientComponent(); if (source != null) { InputMethodEvent event = new InputMethodEvent(source, id, when, text, committedCharacterCount, caret, visiblePosition); SunToolkit.postEvent(SunToolkit.targetToAppContext(source), (AWTEvent)event); } }
public void eventDispatched(AWTEvent event) { if (event instanceof MouseEvent) { MouseEvent me = (MouseEvent) event; Component mecmp = me.getComponent(); if (!SwingUtilities.isDescendingFrom(mecmp, (Component) rootPaneContainer)) { return; } if ((me.getID() == MouseEvent.MOUSE_EXITED) && (mecmp == rootPaneContainer)) { highcmp = null; point = null; } else { MouseEvent converted = SwingUtilities.convertMouseEvent(mecmp, me, this); point = converted.getPoint(); Component parent = mecmp; Rectangle rect = new Rectangle(); rect.width = mecmp.getWidth(); rect.height = mecmp.getHeight(); Rectangle parentBounds = new Rectangle(); while ((parent != null) && (parent != this.getRootPane()) && (parent != rootPaneContainer)) { parent.getBounds(parentBounds); rect.x += parentBounds.x; rect.y += parentBounds.y; parent = parent.getParent(); } highcmp = rect; } repaint(); } }
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); } } }
static String startHierarchyListener() { if (hierarchyListener == null) { hierarchyListener = new RemoteAWTHierarchyListener(); try { Toolkit.getDefaultToolkit().addAWTEventListener(hierarchyListener, AWTEvent.HIERARCHY_EVENT_MASK); } catch (SecurityException se) { hierarchyListener = null; return "Toolkit.addAWTEventListener() threw "+se.toString(); } } return null; }
public Call(String function, String state, boolean withCellInfo, AWTEvent event, String cellInfo) { this.function = function; this.state = state; this.withCellInfo = withCellInfo; this.event = event; this.cellInfo = cellInfo; }
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}); }
/** * Performs common constructor initialization and setup. */ protected void setup(FileSystemView view) { installShowFilesListener(); installHierarchyListener(); if(view == null) { view = FileSystemView.getFileSystemView(); } setFileSystemView(view); updateUI(); if(isAcceptAllFileFilterUsed()) { setFileFilter(getAcceptAllFileFilter()); } enableEvents(AWTEvent.MOUSE_EVENT_MASK); }
/** * Initializes this text area. */ protected void init() { // Sets the UI. Note that setUI() is overridden in RTextArea to only // update the popup menu; this method must be called to set the real // UI. This is done because the look and feel of an RTextArea is // independent of the installed Java look and feels. setRTextAreaUI(createRTextAreaUI()); // So we get notified when the component is resized. enableEvents(AWTEvent.COMPONENT_EVENT_MASK|AWTEvent.KEY_EVENT_MASK); // Defaults for various properties. setHighlightCurrentLine(true); setCurrentLineHighlightColor(getDefaultCurrentLineHighlightColor()); setMarginLineEnabled(false); setMarginLineColor(getDefaultMarginLineColor()); setMarginLinePosition(getDefaultMarginLinePosition()); setBackgroundObject(Color.WHITE); setWrapStyleWord(true);// We only support wrapping at word boundaries. setTabSize(5); setForeground(Color.BLACK); setTabsEmulated(false); // Stuff needed by the caret listener below. previousCaretY = currentCaretY = getInsets().top; // Stuff to highlight the current line. mouseListener = createMouseListener(); // Also acts as a focus listener so we can update our shared actions // (cut, copy, etc. on the popup menu). addFocusListener(mouseListener); addCurrentLineHighlightListeners(); }
public Object run() { Toolkit tk = Toolkit.getDefaultToolkit(); if(invocator == null) { tk.addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK); } else { tk.removeAWTEventListener(invocator); } // Return value not used. return null; }
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); }
@Override protected void dispatchEvent(AWTEvent event) { eq = Thread.currentThread(); boolean scheduled = false; try { scheduled = tick("dispatchEvent"); // NOI18N super.dispatchEvent(event); } finally { if (scheduled) { done(); } } }
/** * 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; }
@Override public void eventDispatched(AWTEvent event) { KeyEvent keyevent = (KeyEvent)event; if ((keyevent.getID() == KeyEvent.KEY_PRESSED || keyevent.getID() == KeyEvent.KEY_RELEASED) && keyevent.getKeyCode() == KeyEvent.VK_ESCAPE) { hackESC = true; } }