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
See Code Examples for Java 8 AWTEvent Methods: