Java 8 AWTEvent - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 AWTEvent class.

This code example shows how to use the following methods:getID, getModifiers, getWhen, getButton, getClickCount
        } 
 
        public void mouseDragged(MouseEvent e) {
            isDragging = true;
            JComponent c = ColorWell.this;
            Point pt = e.getPoint();
            JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(c);
            pt = SwingUtilities.convertPoint(c, pt, frame.getContentPane());
            MouseEvent newEvent = new MouseEvent(colorPicker, e.getID(), e.getWhen(), e.getModifiers(), (int) pt.getX(), (int) pt.getY(), e.getClickCount(), e.isPopupTrigger(), e.getButton());
            colorPicker.dispatchEvent(newEvent);
        } 
 
        public void mouseMoved(MouseEvent e) {
        } 
 
        public void mousePressed(MouseEvent e) {
            isDragging = false;
            JComponent c = ColorWell.this;
            JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(c);
            if (frame == null) return;
8
CodeRank
This code example shows how to use the following methods:getID, getComponent, getWhen, getButton, getClickCount
        this.cellHeight = cellHeight;
        this.listener = listener;
    } 
 
    private MouseEvent translateToGrid(MouseEvent e) {
        int x = e.getX() / cellWidth;
        int y = e.getY() / cellHeight;
        return new MouseEvent(e.getComponent(), e.getID(), e.getWhen(), e.getModifiersEx(), x, y, e.getClickCount(), e.isPopupTrigger(), e.getButton());
    } 
 
    @Override 
    public void mouseClicked(MouseEvent e) {
        listener.mouseClicked(translateToGrid(e));
    } 
 
    @Override 
    public void mousePressed(MouseEvent e) {
        listener.mousePressed(translateToGrid(e));
    } 
 
7
CodeRank
This code example shows how to use the following methods:getID, getWhen, isControlDown, getButton
	public void mouseExited(MouseEvent e) {
	} 
 
	private void handleButton(MouseEvent e) {
		byte state;
		switch (e.getID()) {
			case MouseEvent.MOUSE_PRESSED:
				state = 1;
				break; 
			case MouseEvent.MOUSE_RELEASED:
				state = 0;
				break; 
			default: 
				throw new IllegalArgumentException("Not a valid event ID: " + e.getID());
		} 
		byte button;
		switch (e.getButton()) {
			case MouseEvent.NOBUTTON:
				// Nothing to do, so return 
				return; 

7
CodeRank
This code example shows how to use the following methods:getID, getActionCommand, getModifiers, getWhen
This code example shows how to use the following methods:getID, getComponent, getX, getY, getSource
  protected void dispatchEvent(AWTEvent e) {
    // TODO: implement enter/exit events 
    // TODO: change source to drag source, not mouse under 
    if (nativeDnd.isNativeDragAndDrop(e)) {
      MouseEvent mouseEvent = (MouseEvent) e;
      Component target = getDeepestComponentAt(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
      if (target != mouseEvent.getSource()) {
        mouseEvent = convertMouseEvent(mouseEvent.getComponent(), mouseEvent, target);
      } 
      relayDndEvent(mouseEvent);
    } 
    super.dispatchEvent(e);
  } 
 
  private void relayDndEvent(@Nonnull MouseEvent event) {
    int eventId = event.getID();
    if (eventId == MOUSE_MOVED || eventId == MOUSE_DRAGGED) {
      if ((mask & MOUSE_MOTION_EVENT_MASK) != 0) {
        eventListener.eventDispatched(event);
      } 

7
CodeRank
This code example shows how to use the following methods:getID, isConsumed, isShiftDown, getPoint
    return new MouseInputListener() {
      public void mouseClicked(MouseEvent e) {}
      public void mouseEntered(MouseEvent e) {}
      public void mouseExited(MouseEvent e) {}
      public void mousePressed(MouseEvent e) {
        if (e.isConsumed()) {
          selectedOnPress = false;
          return; 
        } 
        selectedOnPress = true;
        adjustFocusAndSelection(e);
      } 
 
      void adjustFocusAndSelection(MouseEvent e) {
        if (!SwingUtilities.isLeftMouseButton(e)) {
          return; 
        } 
 
        if (!list.isEnabled()) {
          return; 

6
CodeRank
This code example shows how to use the following methods:getID, getModifiers, getWhen, getClickCount, getPoint
    } 
 
    @Override 
    public String getToolTipText(MouseEvent event) {
        if (_actualTreeRenderer instanceof JComponent) {
            Point p = event.getPoint();
            p.translate(-_checkBox.getWidth(), 0);
            MouseEvent newEvent = new MouseEvent(((JComponent) _actualTreeRenderer), event.getID(),
                    event.getWhen(),
                    event.getModifiers(),
                    p.x, p.y, event.getClickCount(),
                    event.isPopupTrigger());
 
            String tip = ((JComponent) _actualTreeRenderer).getToolTipText(
                    newEvent);
 
            if (tip != null) {
                return tip;
            } 
        } 

6
CodeRank
This code example shows how to use the following methods:getID, getModifiers, getWhen, getKeyChar, getKeyCode
	public boolean dispatchKeyEvent(final KeyEvent ke) {
		if(ke.equals(dispatchedEvent)){
			return false; 
		} 
		if(textComponent != null){
			KeyEvent newEvent = new KeyEvent(textComponent, ke.getID(), ke.getWhen(), ke.getModifiers(), ke.getKeyCode(), ke.getKeyChar(), ke.getKeyLocation());
			events.add(newEvent);
		} 
        else { 
	        events.add(ke);
        } 
		 
		// Prevent Freeplane freeze 
		if(ke.getKeyCode() == KeyEvent.VK_ESCAPE 
				&& ke.getID() == KeyEvent.KEY_RELEASED){
			EventQueue.invokeLater(new Runnable() {
				public void run() { 
					KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(EventBuffer.this);
				} 
			}); 
6
CodeRank
This code example shows how to use the following methods:getID, getWhen, getButton, getClickCount, getModifiersEx
		} 
 
		double dx = (vWidth - scale * fWidth) / 2;
		double dy = (vHeight - scale * fHeight) / 2;
 
		int x = (int) ((e.getX() - dx) / scale + 0.5);
		int y = (int) (fHeight - (e.getY() - dy) / scale + 0.5);
 
		return new MouseEvent(SafeComponent.getSafeEventComponent(), e.getID(), e.getWhen(), e.getModifiersEx(), x, y,
				e.getClickCount(), e.isPopupTrigger(), e.getButton());
	} 
 
	private MouseWheelEvent mirroredMouseWheelEvent(final MouseWheelEvent e) {
 
		double scale;
		BattleProperties battleProps = battleManager.getBattleProperties();
 
		int vWidth = battleView.getWidth();
		int vHeight = battleView.getHeight();
		int fWidth = battleProps.getBattlefieldWidth();
6
CodeRank
This code example shows how to use the following methods:getID, getModifiers, getWhen, getButton, getClickCount
        } 
 
        public void mouseDragged(MouseEvent e) {
            isDragging = true;
            JComponent c = ColorWell.this;
            Point pt = e.getPoint();
            JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(c);
            pt = SwingUtilities.convertPoint(c, pt, frame.getContentPane());
            MouseEvent newEvent = new MouseEvent(colorPicker, e.getID(), e.getWhen(), e.getModifiers(), (int) pt.getX(), (int) pt.getY(), e.getClickCount(), e.isPopupTrigger(), e.getButton());
            colorPicker.dispatchEvent(newEvent);
        } 
 
        public void mouseMoved(MouseEvent e) {
        } 
 
        public void mousePressed(MouseEvent e) {
            isDragging = false;
            JComponent c = ColorWell.this;
            JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(c);
            if (frame == null) return;
8
CodeRank
This code example shows how to use the following methods:getID, getComponent, getPoint
  private int buttonUsed(@Nonnull MouseEvent event) {
    return event.getModifiers() & BUTTON_MASK;
  } 
 
  private void updateOnMouseEntered(@Nonnull MouseEvent event, @Nullable Point eventScreenLocation) {
    if (event.getID() != MOUSE_ENTERED) {
      return; 
    } 
    componentStack.push(new WeakReference<Component>(event.getComponent()));
    Point eventPoint = event.getPoint();
    locationStack.push(eventPoint);
    screenLocationStack.push(eventScreenLocation != null ? eventScreenLocation : eventPoint);
  } 
 
  private void updateOnMouseExited(@Nonnull MouseEvent event) {
    if (event.getID() != MOUSE_EXITED || componentStack.empty()) {
      return; 
    } 
    componentStack.pop();
    locationStack.pop();
6
CodeRank
This code example shows how to use the following methods:getID, getComponent, getWhen, isConsumed, getButton
            SwingUtilities.invokeLater(new SafeScroller(nloc));
        } 
    } 
 
    protected MouseEvent convertMouseEventToScale(MouseEvent e) {
        if (!e.isConsumed() && panel instanceof ScalableXHTMLPanel) {
            Point newP = ((ScalableXHTMLPanel) panel).convertFromScaled(e.getX(), e.getY());
            MouseEvent newE = new MouseEvent(
                    e.getComponent(),
                    e.getID(),
                    e.getWhen(),
                    e.getModifiersEx(),
                    (int) newP.getX(), 
                    (int) newP.getY(), 
                    e.getClickCount(),
                    e.isPopupTrigger(),
                    e.getButton()
            ); 
            return newE;
        } 

7
CodeRank
This code example shows how to use the following methods:getID, getModifiers, getWhen, getButton, getClickCount
   */ 
  public void mouseReleased(MouseEvent e) {
    checkTabCount(); 
    // forward the event to the pressed smart icon 
    if (pressedIcon != null){
      Point p = e.getPoint();
       
      final Rectangle r = tabbedPane.getBoundsAt(pressedTab);
      Point iPoint = convertPointToIcon(r, p, pressedIcon);
       
      final MouseEvent eSmart = new MouseEvent(
            (Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiers(),
            iPoint.x, iPoint.y, e.getClickCount(), e.isPopupTrigger(), e.getButton());
      try { 
        if (pressedIcon.onMouseReleased(eSmart)){
          tabbedPane.repaint(r.x, r.y, r.width, r.height); // no choice but trigger a repaint        
        } 
      } catch (Exception ignore){ // bug database : 5075526 this is to remove the stack trace        
      } 
      pressedIcon = null;
6
CodeRank
This code example shows how to use the following methods:getID, getWhen, getButton, getClickCount, getModifiersEx
This code example shows how to use the following methods:getID, consume, isAltDown, isConsumed, isShiftDown
	public boolean dispatchKeyEvent(KeyEvent event) {
 
		// ignore key events coming from text components (i.e. text fields and 
		// text areas) 
		// or key events coming from popups (source class = JRootPane) 
		if (event.isConsumed() || event.getSource() instanceof JTextComponent
				|| event.getSource() instanceof JRootPane) {
			return false; 
		} 
 
		boolean consumed = false;
		switch (event.getID()) {
		case KeyEvent.KEY_PRESSED:
			consumed = handleKeyPressed(event);
			break; 
 
		case KeyEvent.KEY_TYPED:
			consumed = handleKeyTyped(event);
			break; 
		} 

6
CodeRank
This code example shows how to use the following methods:getID
     */ 
    protected void processMouseEvent(MouseEvent e)
    { 
        super.processMouseEvent(e);
 
        switch (e.getID())
        { 
            case MouseEvent.MOUSE_ENTERED:
                overrideFirstMode = true;
                repaint();
                break; 
 
            case MouseEvent.MOUSE_EXITED:
                overrideFirstMode = false;
                repaint();
                break; 
 
            default: 
                break; 
        } 
6
CodeRank
This code example shows how to use the following methods:setSource
import javax.swing.*; 
import java.awt.event.MouseEvent;
 
public class bug6690791 { 
    public static void main(String[] args) throws Exception {
        MouseEvent me = new MouseEvent(new JLabel(), MouseEvent.MOUSE_CLICKED,
                System.currentTimeMillis(), MouseEvent.ALT_MASK,
                10, 10, 100, 100, 1, false, MouseEvent.BUTTON1);
        me.setSource(new Object());
        MenuSelectionManager.defaultManager().processMouseEvent(me);
    } 
} 
6
CodeRank
This code example shows how to use the following methods:getID, getComponent, getX, getY
  void clear() { 
    source(null); 
  } 
 
  void update(@Nonnull MouseEvent event) {
    int mouseEventId = event.getID();
    if (mouseEventId == MOUSE_RELEASED || mouseEventId == MOUSE_MOVED) {
      clear(); 
      return; 
    } 
    if (mouseEventId == MOUSE_PRESSED) {
      source(event.getComponent());
      x = event.getX();
      y = event.getY();
    } 
  } 
 
  @Nullable Component source() {
    return source;
  } 
6
CodeRank
This code example shows how to use the following methods:getID, getModifiers, getWhen, getClickCount, getX
    public boolean handleEventFromParentComponent(MouseEvent mouseEvent) {
        // filter out events that come from client explicitly calling this method, but we have already handled in awt event listener 
        if(mouseEvent == lastMouseEvent) {
            return false; 
        } 
        Object      source = mouseEvent.getSource();
        if(source != parentComponent) {
            return false; 
        } 
        int         id = mouseEvent.getID();
        int         x = mouseEvent.getX();
        int         y = mouseEvent.getY();
        long        when = mouseEvent.getWhen();
        int         modifiers = mouseEvent.getModifiers();
        int         clickCount = mouseEvent.getClickCount();
        boolean     isPopupTrigger = mouseEvent.isPopupTrigger();
        if(id == MouseEvent.MOUSE_EXITED) {
            Point point = SwingUtilities.convertPoint(parentComponent, x, y, tipComponentWindow);
            if(tipComponentWindow.contains(point)) { 
                MouseEvent newEvent = new MouseEvent(parentComponent, MouseEvent.MOUSE_MOVED, when, modifiers,
                        x, y, clickCount, isPopupTrigger);
6
CodeRank
This code example shows how to use the following methods:getID, getModifiers, getWhen, getButton, getClickCount
        insets.top = Math.max(insets.top, size.height);
        return insets;
    } 
 
    private void dispatchEvent(MouseEvent me) {
        if (rect != null && rect.contains(me.getX(), me.getY())) {
            Point pt = me.getPoint();
            pt.translate(-offset, 0);
            comp.setBounds(rect);
            comp.dispatchEvent(new MouseEvent(comp, me.getID(), me.getWhen(), me.getModifiers(), pt.x, pt.y, me
                    .getClickCount(), me.isPopupTrigger(), me.getButton()));
            if (!comp.isValid()) {
                container.repaint();
            } 
        } 
    } 
 
    public void mouseClicked(MouseEvent me) {
        dispatchEvent(me);
    } 
6
CodeRank
This code example shows how to use the following methods:getID, getModifiers, getWhen, getClickCount, getPoint
    } 
 
    @Override 
    public String getToolTipText(MouseEvent event) {
        if (_actualListRenderer instanceof JComponent) {
            Point p = event.getPoint();
            p.translate(-_checkBox.getWidth(), 0);
            MouseEvent newEvent = new MouseEvent(((JComponent) _actualListRenderer), event.getID(),
                    event.getWhen(),
                    event.getModifiers(),
                    p.x, p.y, event.getClickCount(),
                    event.isPopupTrigger());
 
            String tip = ((JComponent) _actualListRenderer).getToolTipText(
                    newEvent);
 
            if (tip != null) {
                return tip;
            } 
        } 

6
CodeRank
This code example shows how to use the following methods:getID, consume, getModifiers, getKeyChar, getKeyCode
	 * {@link KeyEventWorkaround#processKeyEvent(java.awt.event.KeyEvent)}. 
	 *  
	 * @since jEdit 4.2pre3 
	 */ 
	public static Key translateKeyEvent(final KeyEvent evt) {
		final int modifiers = evt.getModifiers();
		Key returnValue = null;
		switch (evt.getID()) {
			case KeyEvent.KEY_PRESSED:
				final int keyCode = evt.getKeyCode();
				if ((keyCode >= KeyEvent.VK_0 && keyCode <= KeyEvent.VK_9)
				        || (keyCode >= KeyEvent.VK_A && keyCode <= KeyEvent.VK_Z)) {
					returnValue = new Key(KeyEventTranslator.modifiersToString(modifiers), '\0', Character
					    .toUpperCase((char) keyCode));
				} 
				else { 
					if (keyCode > 0 && keyCode <= KeyEvent.VK_SPACE
							|| keyCode == KeyEvent.VK_DELETE) {
						evt.consume();
						returnValue = new Key(KeyEventTranslator.modifiersToString(modifiers), keyCode,

6
CodeRank
This code example shows how to use the following methods:getID, consume, getKeyCode
    @Override 
    public void eventDispatched(AWTEvent arg0) {
        if (!(arg0 instanceof KeyEvent))
                return; 
        KeyEvent ev = (KeyEvent) arg0;
        if (ev.getKeyCode() == KeyEvent.VK_ESCAPE && ev.getID() == KeyEvent.KEY_PRESSED) {
            ev.consume();
            cancelDrawing(); 
        } 
    } 
 
    public void cancelDrawing() { 
        if (Main.map == null || Main.map.mapView == null) 
            return; 
        Main.map.statusLine.setHeading(-1); 
        Main.map.statusLine.setAngle(-1); 
        Main.map.mapView.repaint(); 
        updateStatusLine(); 
        parentPlugin.abortInput(); 
    } 
5
CodeRank
This code example shows how to use the following methods:toString, getActionCommand
public class Debug implements ActionListener {
    public Debug () { 
        super(); 
    } 
    public void actionPerformed (ActionEvent ev) {
        System.out.println ("Action command: "+ev.getActionCommand ());
        System.out.println (ev.toString ());
        System.out.println ("");
    } 
} 
5
CodeRank
This code example shows how to use the following methods:getID, getSource
     * @param event an event 
     */ 
    @Override 
    public void eventDispatched(AWTEvent event) {
        if (fixture == null) {
            Object source = event.getSource();
            if (windowClass.isAssignableFrom(source.getClass())
                    && event.getID() == WindowEvent.WINDOW_ACTIVATED) {
 
                if (source instanceof Frame) {
                    fixture = new FrameFixture((Frame) source);
                } else if (source instanceof Dialog) {
                    fixture = new DialogFixture((Dialog) source);
                } 
 
                latch.countDown();
            } 
        } 
    } 
 
6
CodeRank
This code example shows how to use the following methods:getID, getModifiers, getWhen, getClickCount, isPopupTrigger
This code example shows how to use the following methods:getID, getButton, getClickCount
     */ 
    protected void processMouseEvent(MouseEvent e)
    { 
        super.processMouseEvent(e);
 
        switch (e.getID())
        { 
            case MouseEvent.MOUSE_CLICKED:
                if (e.getClickCount() == 1 && e.getButton() == MouseEvent.BUTTON1)
                { 
                    doAction(); 
                } 
                break; 
 
            case MouseEvent.MOUSE_ENTERED:
                if (highlightLink)
                { 
                    super.setForeground(HIGHLIGHT_COLOR); 
                    GlobalController.SINGLETON.setHoveredHyperLink(link);
                } 
5
CodeRank
This code example shows how to use the following methods:getID, getComponent, getModifiers, getWhen, getButton
 
        GlimpseBounds bounds = stack.getBounds( );
 
        if ( bounds == null ) return null;
 
        if ( e.getComponent( ) == null ) return null;
 
        int parentHeight = e.getComponent( ).getBounds( ).height;
 
        Component source = e.getComponent( );
        int id = e.getID( );
        long when = e.getWhen( );
        int modifiers = e.getModifiers( );
        int local_x = e.getX( ) - bounds.getX( );
        int local_y = e.getY( ) - ( parentHeight - ( bounds.getY( ) + bounds.getHeight( ) ) );
        int clickCount = e.getClickCount( );
        boolean popupTrigger = e.isPopupTrigger( );
        int button = e.getButton( );
 
        MouseEvent localEvent = new GlimpseSwingMouseEvent( stack, source, id, when, modifiers, local_x, local_y, clickCount, popupTrigger, button );

5
CodeRank
This code example shows how to use the following methods:getID, getPoint
        g.setColor(oldColor);
    } 
 
    // Called from ImageDatumControl.isControllerEvent(). 
    boolean isStarsEvent(MouseEvent event) {
        if ((event.getID() == MouseEvent.MOUSE_PRESSED) ||
            (event.getID() == MouseEvent.MOUSE_DRAGGED) ||
            (event.getID() == MouseEvent.MOUSE_RELEASED))
        { 
            Point p = event.getPoint();
            if ((rect != null) && (rect.contains(p))) {
                return true; 
            } 
        } 
        return false; 
    } 
 
    void handleEvent(MouseEvent event) {
        if (event.getID() == MouseEvent.MOUSE_PRESSED) {
            stars = pointToStar(event.getPoint());
5
CodeRank
This code example shows how to use the following methods:getID, getWindow
  boolean isDuplicateDispose(AWTEvent event) {
    if (!(event instanceof WindowEvent)) {
      return false; 
    } 
    WindowEvent windowEvent = (WindowEvent) event;
    int eventId = windowEvent.getID();
    if (eventId == WINDOW_CLOSING) {
      return false; 
    } 
    if (eventId == WINDOW_CLOSED) {
      Window w = windowEvent.getWindow();
      if (disposedWindows.containsKey(w)) {
        return true; 
      } 
      disposedWindows.put(w, true);
      // execute(addComponentListenerTask(w, new DisposalMonitor(disposedWindows))); 
      w.addComponentListener(new DisposalMonitor(disposedWindows));
      return false; 
    } 
    disposedWindows.remove(windowEvent.getWindow());

5
CodeRank
See Code Examples for Java 8 AWTEvent Methods: