List of usage examples for java.awt Component dispatchEvent
public final void dispatchEvent(AWTEvent e)
From source file:Main.java
/** * Simulate a key press/release event on the component. * /*from www. ja v a2s . c om*/ * @param key * KeyEvent.VK_... */ public static void simulateKeyPressed(Component component, int key) { component.dispatchEvent(new KeyEvent(component, KeyEvent.KEY_PRESSED, 0, 1, key, KeyEvent.CHAR_UNDEFINED)); component.dispatchEvent(new KeyEvent(component, KeyEvent.KEY_RELEASED, 0, 2, key, KeyEvent.CHAR_UNDEFINED)); }
From source file:Main.java
public static void retargetKeyEvent(KeyEvent e, Component target) { if ((target == null) || (target == e.getSource())) { return;//from w w w .j ava2 s. co m } target.dispatchEvent(e); }
From source file:Main.java
private static void dispatchEventsUntilNow() { if (java.awt.EventQueue.isDispatchThread() && !isDispatching) { isDispatching = true;//from w w w . j a v a2 s . co m try { int handled = 0; java.awt.EventQueue eventQ = java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue(); class StopEvent extends AWTEvent { StopEvent() { super(new Object(), 0); } } eventQ.postEvent(new StopEvent()); while (true) { try { AWTEvent event = eventQ.getNextEvent(); if (event instanceof StopEvent) { break; } if (event instanceof ActiveEvent) { ((ActiveEvent) event).dispatch(); } else { Object source = event.getSource(); if (source instanceof Component) { Component comp = (Component) source; comp.dispatchEvent(event); } } handled++; } catch (InterruptedException e) { //hmm } } // Debug.trace("####dispatchEventsUntilNow handeld "+(handled)+" events"); } finally { isDispatching = false; } } }
From source file:Main.java
/** * Setta il focus su form modali/*from ww w .j a va 2s . co m*/ * * @param target componente che ricevera' il focus */ public static void postponeFocus(final Component target) { SwingUtilities.invokeLater(new Runnable() { public void run() { target.dispatchEvent(new FocusEvent(target, FocusEvent.FOCUS_GAINED)); } }); }
From source file:Main.java
public static void swingDispatch(MouseEvent e, Point point, final Component component) { synchronized (component.getTreeLock()) { if (component instanceof Container) { Container container = (Container) component; for (int i = container.getComponentCount(); i-- != 0;) { Component child = container.getComponent(i); Rectangle r = child.getBounds(); if (r.contains(point)) { swingDispatch(e, new Point(point.x - r.x, point.y - r.y), child); return; }/* w ww . ja va 2 s. c o m*/ } } } final MouseEvent adapted = convertMouseEvent(e, component, point); SwingUtilities.invokeLater(new Runnable() { public void run() { component.dispatchEvent(adapted); } }); }
From source file:components.GlassPaneDemo.java
private void redispatchMouseEvent(MouseEvent e, boolean repaint) { Point glassPanePoint = e.getPoint(); Container container = contentPane; Point containerPoint = SwingUtilities.convertPoint(glassPane, glassPanePoint, contentPane); if (containerPoint.y < 0) { //we're not in the content pane if (containerPoint.y + menuBar.getHeight() >= 0) { //The mouse event is over the menu bar. //Could handle specially. } else {/*ww w.j a v a2s . c o m*/ //The mouse event is over non-system window //decorations, such as the ones provided by //the Java look and feel. //Could handle specially. } } else { //The mouse event is probably over the content pane. //Find out exactly which component it's over. Component component = SwingUtilities.getDeepestComponentAt(container, containerPoint.x, containerPoint.y); if ((component != null) && (component.equals(liveButton))) { //Forward events over the check box. Point componentPoint = SwingUtilities.convertPoint(glassPane, glassPanePoint, component); component.dispatchEvent(new MouseEvent(component, e.getID(), e.getWhen(), e.getModifiers(), componentPoint.x, componentPoint.y, e.getClickCount(), e.isPopupTrigger())); } } //Update the glass pane if requested. if (repaint) { glassPane.setPoint(glassPanePoint); glassPane.repaint(); } }
From source file:GlassPaneDemo.java
private void redispatchMouseEvent(MouseEvent e, boolean repaint) { Point glassPanePoint = e.getPoint(); Container container = contentPane; Point containerPoint = SwingUtilities.convertPoint(glassPane, glassPanePoint, contentPane); if (containerPoint.y < 0) { // we're not in the content pane if (containerPoint.y + menuBar.getHeight() >= 0) { // The mouse event is over the menu bar. // Could handle specially. } else {/* w w w.ja v a 2s . co m*/ // The mouse event is over non-system window // decorations, such as the ones provided by // the Java look and feel. // Could handle specially. } } else { // The mouse event is probably over the content pane. // Find out exactly which component it's over. Component component = SwingUtilities.getDeepestComponentAt(container, containerPoint.x, containerPoint.y); if ((component != null) && (component.equals(liveButton))) { // Forward events over the check box. Point componentPoint = SwingUtilities.convertPoint(glassPane, glassPanePoint, component); component.dispatchEvent(new MouseEvent(component, e.getID(), e.getWhen(), e.getModifiers(), componentPoint.x, componentPoint.y, e.getClickCount(), e.isPopupTrigger())); } } // Update the glass pane if requested. if (repaint) { glassPane.setPoint(glassPanePoint); glassPane.repaint(); } }
From source file:it.unibas.spicygui.vista.listener.MyMouseEventListener.java
private void dispacciaEventoDrag(Component com, MouseEvent e, Point point, boolean draggedEvent) { Point componentPoint = SwingUtilities.convertPoint(component, e.getPoint(), com); if (com != null) { if (com instanceof JTree) { TreePath treePath = ((JTree) com).getPathForLocation(componentPoint.x, componentPoint.y); if (treePath == null || draggedEvent) { component.updateUI();//from w ww.j a v a 2 s . c o m return; } } if ((!(com instanceof JScrollBar) && (tmp12 instanceof JScrollBar))) { jLayeredPane.moveToFront(component); component.updateUI(); return; } com.dispatchEvent(new MouseEvent(component, e.getID(), e.getWhen(), e.getModifiers(), componentPoint.x, componentPoint.y, e.getClickCount(), e.isPopupTrigger())); jLayeredPane.moveToFront(component); component.updateUI(); } jLayeredPane.moveToFront(component); component.updateUI(); }
From source file:it.unibas.spicygui.vista.listener.MyMouseEventListener.java
private void dispacciaEvento(Component com, MouseEvent e, Point point, boolean draggedEvent) { if (com == null) { com = SwingUtilities.getDeepestComponentAt(pannelloPrincipale, point.x, point.y); }// w ww . j a v a 2s. c o m Point componentPoint = SwingUtilities.convertPoint(component, e.getPoint(), com); if (com != null) { if (com instanceof JTree) { TreePath treePath = ((JTree) com).getPathForLocation(componentPoint.x, componentPoint.y); if (treePath == null || draggedEvent) { jLayeredPane.moveToFront(component); component.updateUI(); if (e.getButton() == MouseEvent.BUTTON3) { return; } } } com.dispatchEvent(new MouseEvent(com, e.getID(), e.getWhen(), e.getModifiers(), componentPoint.x, componentPoint.y, e.getClickCount(), e.isPopupTrigger())); jLayeredPane.moveToFront(component); component.updateUI(); } jLayeredPane.moveToFront(component); component.updateUI(); }
From source file:SwingGlassExample.java
private void redispatchMouseEvent(MouseEvent e) { boolean inButton = false; boolean inMenuBar = false; Point glassPanePoint = e.getPoint(); Component component = null; Container container = contentPane; Point containerPoint = SwingUtilities.convertPoint(this, glassPanePoint, contentPane); int eventID = e.getID(); if (containerPoint.y < 0) { inMenuBar = true;//from ww w . j a v a 2 s. co m container = menuBar; containerPoint = SwingUtilities.convertPoint(this, glassPanePoint, menuBar); testForDrag(eventID); } //XXX: If the event is from a component in a popped-up menu, //XXX: then the container should probably be the menu's //XXX: JPopupMenu, and containerPoint should be adjusted //XXX: accordingly. component = SwingUtilities.getDeepestComponentAt(container, containerPoint.x, containerPoint.y); if (component == null) { return; } else { inButton = true; testForDrag(eventID); } if (inMenuBar || inButton || inDrag) { Point componentPoint = SwingUtilities.convertPoint(this, glassPanePoint, component); component.dispatchEvent(new MouseEvent(component, eventID, e.getWhen(), e.getModifiers(), componentPoint.x, componentPoint.y, e.getClickCount(), e.isPopupTrigger())); } }