Java Code Examples for java.awt.event.MouseEvent#MOUSE_MOVED

The following examples show how to use java.awt.event.MouseEvent#MOUSE_MOVED . These examples are extracted from open source projects. 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
private void doProcess(MouseEvent e) {
    // We only handle events if there is something selected
    if (selectedModelItem != null) {
        switch (e.getID()) {
            case MouseEvent.MOUSE_MOVED:
                mouseMoved(e);
                break;
            case MouseEvent.MOUSE_CLICKED:
                mouseClicked(e);
                break;
            case MouseEvent.MOUSE_WHEEL:
                mouseWheel((MouseWheelEvent) e);
                break;
            case MouseEvent.MOUSE_DRAGGED:
                mouseDragged(e);
                break;
            case MouseEvent.MOUSE_RELEASED:
                mouseReleased(e);
                break;
        }
    }
}
 
Example 2
Source Project: pumpernickel   File: ClickSensitivityControl.java    License: MIT License 6 votes vote down vote up
@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 3
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);
    }
}
 
Example 4
Source Project: Bytecoder   File: AWTEvent.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Consumes this event, if this event can be consumed. Only low-level,
 * system events can be consumed
 */
protected void consume() {
    switch(id) {
      case KeyEvent.KEY_PRESSED:
      case KeyEvent.KEY_RELEASED:
      case MouseEvent.MOUSE_PRESSED:
      case MouseEvent.MOUSE_RELEASED:
      case MouseEvent.MOUSE_MOVED:
      case MouseEvent.MOUSE_DRAGGED:
      case MouseEvent.MOUSE_ENTERED:
      case MouseEvent.MOUSE_EXITED:
      case MouseEvent.MOUSE_WHEEL:
      case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
      case InputMethodEvent.CARET_POSITION_CHANGED:
          consumed = true;
          break;
      default:
          // event type cannot be consumed
    }
}
 
Example 5
Source Project: netbeans   File: TooltipHack.java    License: Apache License 2.0 6 votes vote down vote up
/** Hack to invoke tooltip on given JComponent, with given dismiss delay.
 * Triggers <br>
 * <code>comp.getToolTipText(MouseEvent)</code> and 
 * <code>comp.getToolTipLocation(MouseEvent)</code> with fake mousemoved 
 * MouseEvent, set to given coordinates.
 */
public static void invokeTip (JComponent comp, int x, int y, int dismissDelay) {
    final ToolTipManager ttm = ToolTipManager.sharedInstance();
    final int prevInit = ttm.getInitialDelay();
    prevDismiss = ttm.getDismissDelay();
    ttm.setInitialDelay(0);
    ttm.setDismissDelay(dismissDelay);
    
    MouseEvent fakeEvt = new MouseEvent(
            comp, MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), 
            0, x, y, 0, false);
    ttm.mouseMoved(fakeEvt);
    
    ttm.setInitialDelay(prevInit);
    Timer timer = new Timer(20, instance());
    timer.setRepeats(false);
    timer.start();
}
 
Example 6
private static String eventToString(MouseEvent e) {
    StringBuilder result = new StringBuilder();

    switch (e.getID()) {
        case MouseEvent.MOUSE_PRESSED:
            result.append("MOUSE_PRESSED");
            break;
        case MouseEvent.MOUSE_RELEASED:
            result.append("MOUSE_RELEASED");
            break;
        case MouseEvent.MOUSE_CLICKED:
            result.append("MOUSE_CLICKED");
            break;
        case MouseEvent.MOUSE_ENTERED:
            result.append("MOUSE_ENTERED");
            break;
        case MouseEvent.MOUSE_EXITED:
            result.append("MOUSE_EXITED");
            break;
        case MouseEvent.MOUSE_MOVED:
            result.append("MOUSE_MOVED");
            break;
        case MouseEvent.MOUSE_DRAGGED:
            result.append("MOUSE_DRAGGED");
            break;
        case MouseEvent.MOUSE_WHEEL:
            result.append("MOUSE_WHEEL");
            break;
        default:
            result.append("unknown type");
    }

    result.append(", modifiers = " + MouseEvent.getMouseModifiersText(e.getModifiers()));
    result.append(", modifiersEx = " + MouseEvent.getMouseModifiersText(e.getModifiersEx()));
    result.append(", button = " + e.getButton());

    return result.toString();
}
 
Example 7
@Override
public void handleJavaMouseEvent( MouseEvent mouseEvent ) {
    super.handleJavaMouseEvent(mouseEvent);
    if (xtext != null)  {
        mouseEvent.setSource(xtext);
        int id = mouseEvent.getID();
        if (id == MouseEvent.MOUSE_DRAGGED || id == MouseEvent.MOUSE_MOVED)
            xtext.processMouseMotionEventImpl(mouseEvent);
        else
            xtext.processMouseEventImpl(mouseEvent);
    }
}
 
Example 8
/**
 * Handles mouse events.
 */
void handleMouseEvent(int eventType, int modifierFlags, int buttonNumber,
                      int clickCount, int x, int y, int absoluteX,
                      int absoluteY) {
    final SunToolkit tk = (SunToolkit)Toolkit.getDefaultToolkit();
    if ((buttonNumber > 2 && !tk.areExtraMouseButtonsEnabled())
            || buttonNumber > tk.getNumberOfButtons() - 1) {
        return;
    }

    int jeventType = isNpapiCallback ? NSEvent.npToJavaEventType(eventType) :
                                       NSEvent.nsToJavaEventType(eventType);

    int jbuttonNumber = MouseEvent.NOBUTTON;
    int jclickCount = 0;

    if (jeventType != MouseEvent.MOUSE_MOVED &&
        jeventType != MouseEvent.MOUSE_ENTERED &&
        jeventType != MouseEvent.MOUSE_EXITED)
    {
        jbuttonNumber = NSEvent.nsToJavaButton(buttonNumber);
        jclickCount = clickCount;
    }

    int jmodifiers = NSEvent.nsToJavaMouseModifiers(buttonNumber,
                                                    modifierFlags);
    boolean jpopupTrigger = NSEvent.isPopupTrigger(jmodifiers);

    eventNotifier.notifyMouseEvent(jeventType, System.currentTimeMillis(), jbuttonNumber,
            x, y, absoluteX, absoluteY, jmodifiers, jclickCount,
            jpopupTrigger, null);
}
 
Example 9
/**
 * Handles mouse events.
 */
void handleMouseEvent(int eventType, int modifierFlags, int buttonNumber,
                      int clickCount, int x, int y, int absoluteX,
                      int absoluteY) {
    final SunToolkit tk = (SunToolkit)Toolkit.getDefaultToolkit();
    if ((buttonNumber > 2 && !tk.areExtraMouseButtonsEnabled())
            || buttonNumber > tk.getNumberOfButtons() - 1) {
        return;
    }

    int jeventType = isNpapiCallback ? NSEvent.npToJavaEventType(eventType) :
                                       NSEvent.nsToJavaEventType(eventType);

    int jbuttonNumber = MouseEvent.NOBUTTON;
    int jclickCount = 0;

    if (jeventType != MouseEvent.MOUSE_MOVED &&
        jeventType != MouseEvent.MOUSE_ENTERED &&
        jeventType != MouseEvent.MOUSE_EXITED)
    {
        jbuttonNumber = NSEvent.nsToJavaButton(buttonNumber);
        jclickCount = clickCount;
    }

    int jmodifiers = NSEvent.nsToJavaMouseModifiers(buttonNumber,
                                                    modifierFlags);
    boolean jpopupTrigger = NSEvent.isPopupTrigger(jmodifiers);

    eventNotifier.notifyMouseEvent(jeventType, System.currentTimeMillis(), jbuttonNumber,
            x, y, absoluteX, absoluteY, jmodifiers, jclickCount,
            jpopupTrigger, null);
}
 
Example 10
/**
 * Handles mouse events.
 */
void handleMouseEvent(int eventType, int modifierFlags, int buttonNumber,
                      int clickCount, int x, int y, int absoluteX,
                      int absoluteY) {
    final SunToolkit tk = (SunToolkit)Toolkit.getDefaultToolkit();
    if ((buttonNumber > 2 && !tk.areExtraMouseButtonsEnabled())
            || buttonNumber > tk.getNumberOfButtons() - 1) {
        return;
    }

    int jeventType = isNpapiCallback ? NSEvent.npToJavaEventType(eventType) :
                                       NSEvent.nsToJavaEventType(eventType);

    int jbuttonNumber = MouseEvent.NOBUTTON;
    int jclickCount = 0;

    if (jeventType != MouseEvent.MOUSE_MOVED &&
        jeventType != MouseEvent.MOUSE_ENTERED &&
        jeventType != MouseEvent.MOUSE_EXITED)
    {
        jbuttonNumber = NSEvent.nsToJavaButton(buttonNumber);
        jclickCount = clickCount;
    }

    int jmodifiers = NSEvent.nsToJavaMouseModifiers(buttonNumber,
                                                    modifierFlags);
    boolean jpopupTrigger = NSEvent.isPopupTrigger(jmodifiers);

    eventNotifier.notifyMouseEvent(jeventType, System.currentTimeMillis(), jbuttonNumber,
            x, y, absoluteX, absoluteY, jmodifiers, jclickCount,
            jpopupTrigger, null);
}
 
Example 11
@Override
public void handleJavaMouseEvent( MouseEvent mouseEvent ) {
    super.handleJavaMouseEvent(mouseEvent);
    if (xtext != null)  {
        mouseEvent.setSource(xtext);
        int id = mouseEvent.getID();
        if (id == MouseEvent.MOUSE_DRAGGED || id == MouseEvent.MOUSE_MOVED)
            xtext.processMouseMotionEventImpl(mouseEvent);
        else
            xtext.processMouseEventImpl(mouseEvent);
    }
}
 
Example 12
private static String eventToString(MouseEvent e) {
    StringBuilder result = new StringBuilder();

    switch (e.getID()) {
        case MouseEvent.MOUSE_PRESSED:
            result.append("MOUSE_PRESSED");
            break;
        case MouseEvent.MOUSE_RELEASED:
            result.append("MOUSE_RELEASED");
            break;
        case MouseEvent.MOUSE_CLICKED:
            result.append("MOUSE_CLICKED");
            break;
        case MouseEvent.MOUSE_ENTERED:
            result.append("MOUSE_ENTERED");
            break;
        case MouseEvent.MOUSE_EXITED:
            result.append("MOUSE_EXITED");
            break;
        case MouseEvent.MOUSE_MOVED:
            result.append("MOUSE_MOVED");
            break;
        case MouseEvent.MOUSE_DRAGGED:
            result.append("MOUSE_DRAGGED");
            break;
        case MouseEvent.MOUSE_WHEEL:
            result.append("MOUSE_WHEEL");
            break;
        default:
            result.append("unknown type");
    }

    result.append(", modifiers = " + MouseEvent.getMouseModifiersText(e.getModifiers()));
    result.append(", modifiersEx = " + MouseEvent.getMouseModifiersText(e.getModifiersEx()));
    result.append(", button = " + e.getButton());

    return result.toString();
}
 
Example 13
private static String eventToString(MouseEvent e) {
    StringBuilder result = new StringBuilder();

    switch (e.getID()) {
        case MouseEvent.MOUSE_PRESSED:
            result.append("MOUSE_PRESSED");
            break;
        case MouseEvent.MOUSE_RELEASED:
            result.append("MOUSE_RELEASED");
            break;
        case MouseEvent.MOUSE_CLICKED:
            result.append("MOUSE_CLICKED");
            break;
        case MouseEvent.MOUSE_ENTERED:
            result.append("MOUSE_ENTERED");
            break;
        case MouseEvent.MOUSE_EXITED:
            result.append("MOUSE_EXITED");
            break;
        case MouseEvent.MOUSE_MOVED:
            result.append("MOUSE_MOVED");
            break;
        case MouseEvent.MOUSE_DRAGGED:
            result.append("MOUSE_DRAGGED");
            break;
        case MouseEvent.MOUSE_WHEEL:
            result.append("MOUSE_WHEEL");
            break;
        default:
            result.append("unknown type");
    }

    result.append(", modifiers = " + MouseEvent.getMouseModifiersText(e.getModifiers()));
    result.append(", modifiersEx = " + MouseEvent.getMouseModifiersText(e.getModifiersEx()));
    result.append(", button = " + e.getButton());

    return result.toString();
}
 
Example 14
Source Project: darklaf   File: ToolTipContext.java    License: MIT License 4 votes vote down vote up
private MouseEvent processEvent(final MouseEvent mouseEvent, final Point mp) {
    if (mouseEvent != null) return mouseEvent;
    return new MouseEvent(target, MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), 0, mp.x, mp.y,
                          0, false, 0);
}
 
Example 15
@Override
public void processMouse(MouseEvent e) {
  ActiveBox bx1, bx2;
  Point p = e.getPoint();

  if (playing)
    switch (e.getID()) {
    case MouseEvent.MOUSE_PRESSED:
      ps.stopMedia(1);
      if (bc.active) {
        if (dragCells)
          bx1 = bc.getBox();
        else
          bx1 = bg.findActiveBox(bc.origin);
        bc.end();
        bx2 = bg.findActiveBox(p);
        if (bx1 != null && bx2 != null) {
          String src = bx1.getDescription() + "(" + bx1.idOrder + ")";
          String dest = "(" + bx2.idLoc + ")";
          boolean ok = (bx1.idOrder == bx2.idLoc);
          bx1.exchangeLocation(bx2);
          int cellsAtPlace = bg.countCellsAtEquivalentPlace(true);
          ps.reportNewAction(getActivity(), ACTION_PLACE, src, dest, ok, cellsAtPlace);
          if (ok && cellsAtPlace == bg.getNumCells())
            finishActivity(true);
          else
            playEvent(ok ? EventSounds.ACTION_OK : EventSounds.ACTION_ERROR);
        }
        repaint();
      } else {
        if ((bx1 = bg.findActiveBox(p)) != null) {
          if (dragCells)
            bc.begin(p, bx1);
          else
            bc.begin(p);
          if (!bx1.playMedia(ps))
            playEvent(EventSounds.CLICK);
        }
      }
      break;

    case MouseEvent.MOUSE_MOVED:
    case MouseEvent.MOUSE_DRAGGED:
      bc.moveTo(p);
      break;
    }
}
 
Example 16
Source Project: consulo   File: Breadcrumbs.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void handle(MouseEvent event) {
  if (!event.isConsumed()) {
    Crumb crumb = null;
    BiConsumer<Crumb, InputEvent> consumer = null;
    switch (event.getID()) {
      case MouseEvent.MOUSE_MOVED:
      case MouseEvent.MOUSE_ENTERED:
        crumb = getCrumbAt(event.getX(), event.getY());
      case MouseEvent.MOUSE_EXITED:
        if (!isHovered(crumb)) consumer = hover;
        break;
      case MouseEvent.MOUSE_CLICKED:
        if (!isLeftMouseButton(event)) break;
        crumb = getCrumbAt(event.getX(), event.getY());
        if (crumb != null) consumer = select;
        break;
      case MouseEvent.MOUSE_PRESSED:
      case MouseEvent.MOUSE_RELEASED:
        if (!event.isPopupTrigger()) break;
        crumb = getCrumbAt(event.getX(), event.getY());
        if (crumb == null) break; // crumb is not found
        Collection<? extends Action> actions = crumb.getContextActions();
        if (actions.isEmpty()) break; // nothing to show
        JPopupMenu popup = new JPopupMenu();
        for (Action action : actions) {
          if (action != null) {
            popup.add(action);
          }
          else {
            popup.addSeparator();
          }
        }
        Component invoker = event.getComponent();
        popup.show(invoker, event.getX(), invoker.getHeight());
        event.consume();
        break;
    }
    if (consumer != null) {
      consumer.accept(crumb, event);
      event.consume();
      revalidate();
      repaint();
    }
  }
}
 
Example 17
Source Project: jclic   File: DoublePuzzle.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public void processMouse(MouseEvent e) {
  ActiveBox bx1, bx2;
  Point p = e.getPoint();

  if (playing)
    switch (e.getID()) {
    case MouseEvent.MOUSE_PRESSED:
      ps.stopMedia(1);
      if (bc.active) {
        if (dragCells)
          bx1 = bc.getBox();
        else
          bx1 = bgA.findActiveBox(bc.origin);
        bc.end();
        bx2 = bgB.findActiveBox(p);
        if (bx1 != null && bx2 != null && bx2.isInactive()) {
          boolean ok = false;
          String src = bx1.getDescription() + " (" + bx1.idOrder + ")";
          String dest = "(" + bx2.idOrder + ")";
          if (bx1.getContent().isEquivalent(abc[0].getActiveBoxContent(bx2.idOrder), true)) {
            ok = true;
            bx1.exchangeContent(bx2);
            bx1.setVisible(false);
            if (useOrder)
              currentItem = bgA.getNextItem(currentItem);
          }
          int cellsAtPlace = bgA.countInactiveCells();
          ps.reportNewAction(DoublePuzzle.this, ACTION_PLACE, src, dest, ok, cellsAtPlace);
          if (ok && cellsAtPlace == bgA.getNumCells())
            finishActivity(true);
          else
            playEvent(ok ? EventSounds.ACTION_OK : EventSounds.ACTION_ERROR);
        }
        repaint();
      } else {
        if ((bx1 = bgA.findActiveBox(p)) != null && !bx1.isInactive()
            && (!useOrder || bx1.idOrder == currentItem)) {
          if (dragCells)
            bc.begin(p, bx1);
          else
            bc.begin(p);
          if (!bx1.playMedia(ps))
            playEvent(EventSounds.CLICK);
        }
      }
      break;

    case MouseEvent.MOUSE_MOVED:
    case MouseEvent.MOUSE_DRAGGED:
      bc.moveTo(p);
      break;
    }
}
 
Example 18
/**
 * Processes all caught <code>MouseEvent</code>s.
 *
 * @param e the <code>MouseEvent</code>
 */
private void processMouseEvents(MouseEvent e) {
    int tabNumber = getUI().tabForCoordinate(this, e.getX(), e.getY());
    if (tabNumber < 0)
        return;
    CloseTabIcon icon = (CloseTabIcon) getIconAt(tabNumber);
    if (icon != null) {
        Rectangle rect = icon.getBounds();
        Point pos = headerViewport == null ? new Point() : headerViewport
                .getViewPosition();
        Rectangle drawRect = new Rectangle(rect.x - pos.x, rect.y - pos.y,
                rect.width, rect.height);

        if (e.getID() == MouseEvent.MOUSE_PRESSED) {
            icon.mousepressed = e.getModifiers() == MouseEvent.BUTTON1_MASK;
            repaint(drawRect);
        } else if (e.getID() == MouseEvent.MOUSE_MOVED
                || e.getID() == MouseEvent.MOUSE_DRAGGED
                || e.getID() == MouseEvent.MOUSE_CLICKED) {
            pos.x += e.getX();
            pos.y += e.getY();
            if (rect.contains(pos)) {
                if (e.getID() == MouseEvent.MOUSE_CLICKED) {
                    int selIndex = getSelectedIndex();
                    if (fireCloseTab(selIndex)) {
                        if (selIndex > 0) {
                            // to prevent uncatchable null-pointers
                            Rectangle rec = getUI().getTabBounds(this,
                                    selIndex - 1);

                            MouseEvent event = new MouseEvent((Component) e
                                    .getSource(), e.getID() + 1, System
                                    .currentTimeMillis(), e.getModifiers(),
                                    rec.x, rec.y, e.getClickCount(), e
                                    .isPopupTrigger(), e
                                    .getButton());
                            dispatchEvent(event);
                        }
                        // the tab is being closed
                        // removeTabAt(tabNumber);
                        remove(selIndex);
                    } else {
                        icon.mouseover = false;
                        icon.mousepressed = false;
                        repaint(drawRect);
                    }
                } else {
                    icon.mouseover = true;
                    icon.mousepressed = e.getModifiers() == MouseEvent.BUTTON1_MASK;
                }
            } else {
                icon.mouseover = false;
            }
            repaint(drawRect);
        }
    }
}
 
Example 19
public void mouseClicked(MouseEvent e) {
        	if(world.started()) return;//Если идет обсчет не суетимся, выводить ничего не надо.
        	
        	Point p	= e.getPoint();
        	int x	= (int) p.getX();
        	int y	= (int) p.getY();
        	int botX=(x-2)/BOTW;
        	int botY=(y-2)/BOTH;	
        	Bot bot	= world.getBot(botX,botY);
        	if(bot!=null)
        	{
        		{
        			Graphics g	= buffer.getGraphics();
	        		g.setColor(Color.MAGENTA);
	        		g.fillRect(botX * BOTW, botY * BOTH, BOTW, BOTH);
//                    g.setColor(Color.BLACK);
  //                  g.drawRect(botX * 4, botY * 4, 4, 4);
	                paintPanel.repaint();
	        	}
        		StringBuilder buf	= new StringBuilder();
        		buf.append("<html>");
        		buf.append("<p>Многоклеточный: ");
        		switch(bot.isMulti())
        		{
        			case 0:// - нет,
        				buf.append("нет</p>");
        				break;
        			case 1:// - есть MPREV,
        				buf.append("есть MPREV</p>");
        				break;
        			case 2:// - есть MNEXT,
        				buf.append("есть MNEXT</p>");
        				break;
        			case 3:// есть MPREV и MNEXT
        				buf.append("есть MPREV и MNEXT</p>");
        				break;
        		}
        		buf.append("<p>c_blue="+bot.c_blue);
        		buf.append("<p>c_green="+bot.c_green);
        		buf.append("<p>c_red="+bot.c_red);
        		buf.append("<p>direction="+bot.direction);
        		buf.append("<p>health="+bot.health);
        		buf.append("<p>mineral="+bot.mineral);
        		
        		
        	    //buf.append("");
       	    
        	    IBotGeneController cont;
                for (int i = 0; i < Bot.MIND_SIZE; i++)
                {//15
                    int command = bot.mind[i];  // текущая команда
                    
                    // Получаем обработчика команды
                    cont	= Bot.geneController[command];
                    if(cont!=null)// если обработчик такой команды назначен
                    {
                    	buf.append("<p>");
                    	buf.append(String.valueOf(i));
                    	buf.append("&nbsp;");
                    	buf.append(cont.getDescription(bot, i));
                    	buf.append("</p>");
                    }
                }
        	    
        	    buf.append("</html>");
	        	JComponent component = (JComponent)e.getSource();
	        	//System.out.println(bot);
	        	paintPanel.setToolTipText(buf.toString());
	            MouseEvent phantom = new MouseEvent(
	                    component,
	                    MouseEvent.MOUSE_MOVED,
	                    System.currentTimeMillis()-2000,
	                    0,
	                    x,
	                    y,
	                    0,
	                    false);
	
	            ToolTipManager.sharedInstance().mouseMoved(phantom);
        	}
        
        }
 
Example 20
Source Project: consulo   File: IdeTooltipManager.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void eventDispatched(AWTEvent event) {
  if (!myIsEnabled.asBoolean()) return;

  MouseEvent me = (MouseEvent)event;
  myProcessingComponent = me.getComponent();
  try {
    if (me.getID() == MouseEvent.MOUSE_ENTERED) {
      boolean canShow = true;
      if (componentContextHasChanged(myProcessingComponent)) {
        canShow = hideCurrent(me, null, null);
      }
      if (canShow) {
        maybeShowFor(myProcessingComponent, me);
      }
    }
    else if (me.getID() == MouseEvent.MOUSE_EXITED) {
      //We hide tooltip (but not hint!) when it's shown over myComponent and mouse exits this component
      if (myProcessingComponent == myCurrentComponent && myCurrentTooltip != null && !myCurrentTooltip.isHint() && myCurrentTipUi != null) {
        myCurrentTipUi.setAnimationEnabled(false);
        hideCurrent(null, null, null, null, false);
      }
      else if (myProcessingComponent == myCurrentComponent || myProcessingComponent == myQueuedComponent) {
        hideCurrent(me, null, null);
      }
    }
    else if (me.getID() == MouseEvent.MOUSE_MOVED) {
      if (myProcessingComponent == myCurrentComponent || myProcessingComponent == myQueuedComponent) {
        if (myCurrentTipUi != null && myCurrentTipUi.wasFadedIn()) {
          maybeShowFor(myProcessingComponent, me);
        }
        else {
          if (!myCurrentTipIsCentered) {
            myX = me.getX();
            myY = me.getY();
            if (myProcessingComponent instanceof JComponent && !isTooltipDefined((JComponent)myProcessingComponent, me) && (myQueuedTooltip == null || !myQueuedTooltip.isHint())) {
              hideCurrent(me, null, null);//There is no tooltip or hint here, let's proceed it as MOUSE_EXITED
            }
            else {
              maybeShowFor(myProcessingComponent, me);
            }
          }
        }
      }
      else if (myCurrentComponent == null && myQueuedComponent == null) {
        maybeShowFor(myProcessingComponent, me);
      }
    }
    else if (me.getID() == MouseEvent.MOUSE_PRESSED) {
      boolean clickOnTooltip = myCurrentTipUi != null && myCurrentTipUi == JBPopupFactory.getInstance().getParentBalloonFor(myProcessingComponent);
      if (myProcessingComponent == myCurrentComponent || (clickOnTooltip && !myCurrentTipUi.isClickProcessor())) {
        hideCurrent(me, null, null, null, !clickOnTooltip);
      }
    }
    else if (me.getID() == MouseEvent.MOUSE_DRAGGED) {
      hideCurrent(me, null, null);
    }
  }
  finally {
    myProcessingComponent = null;
  }
}