public static void main(final String[] args) { final int mask = InputEvent.META_DOWN_MASK | InputEvent.CTRL_MASK; Frame f = new Frame(); MouseEvent mwe = new MouseWheelEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true, 1, 1, 1); MouseEvent mdme = new MenuDragMouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true, null, null); MouseEvent me = new MouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true, MouseEvent.NOBUTTON); test(f, mwe); test(f, mdme); test(f, me); if (FAILED) { throw new RuntimeException("Wrong mouse event"); } }
private MouseEvent convertEvent(MouseEvent e) { MouseEvent me = null; //workaround for swing utilities removing mouse button when converting events. if (e instanceof MouseWheelEvent || e instanceof MenuDragMouseEvent) { SwingUtilities.convertMouseEvent(this, e, getDiagram()); } else { Point p = SwingUtilities.convertPoint(this, new Point(e.getX(), e.getY()), getDiagram()); me = new MouseEvent(getDiagram(), e.getID(), e.getWhen(), e.getModifiers() | e.getModifiersEx(), p.x, p.y, e.getXOnScreen(), e.getYOnScreen(), e.getClickCount(), e.isPopupTrigger(), e.getButton()); } return me; }
/** * This method fires MenuDragMouseEvents to registered listeners. * Different types of MenuDragMouseEvents are fired depending * on the observed mouse event. * * @param event Mouse */ public void processMenuDragMouseEvent(MenuDragMouseEvent event) { switch (event.getID()) { case MouseEvent.MOUSE_ENTERED: isDragging = false; fireMenuDragMouseEntered(event); break; case MouseEvent.MOUSE_EXITED: isDragging = false; fireMenuDragMouseExited(event); break; case MouseEvent.MOUSE_DRAGGED: isDragging = true; fireMenuDragMouseDragged(event); break; case MouseEvent.MOUSE_RELEASED: if (isDragging) fireMenuDragMouseReleased(event); break; } }
public void testFireMenuDragMouseEntered() { MenuDragMouseEvent event1 = new MenuDragMouseEvent(menuItem, 0, 0, 0, 0, 0, 0, false, new MenuElement[0], new MenuSelectionManager()); ConcreteMenuDragMouseListener listener1 = new ConcreteMenuDragMouseListener(); ConcreteMenuDragMouseListener listener2 = new ConcreteMenuDragMouseListener(); menuItem.addMenuDragMouseListener(listener1); menuItem.addMenuDragMouseListener(listener2); menuItem.fireMenuDragMouseEntered(event1); assertEquals("event fired properly ", "entered", listener1.event); assertEquals("event fired properly ", "entered", listener2.event); assertSame("one event fired ", listener1.event, listener2.event); menuItem.fireMenuDragMouseEntered(event1); assertEquals("event fired properly ", "entered", listener1.event); assertEquals("event fired properly ", "entered", listener2.event); assertSame("one event fired ", listener1.event, listener2.event); }
public void testFireMenuDragMouseExited() { MenuDragMouseEvent event1 = new MenuDragMouseEvent(menuItem, 0, 0, 0, 0, 0, 0, false, new MenuElement[0], new MenuSelectionManager()); ConcreteMenuDragMouseListener listener1 = new ConcreteMenuDragMouseListener(); ConcreteMenuDragMouseListener listener2 = new ConcreteMenuDragMouseListener(); menuItem.addMenuDragMouseListener(listener1); menuItem.addMenuDragMouseListener(listener2); menuItem.fireMenuDragMouseExited(event1); assertEquals("event fired properly ", "exited", listener1.event); assertEquals("event fired properly ", "exited", listener2.event); assertSame("one event fired ", listener1.event, listener2.event); menuItem.fireMenuDragMouseExited(event1); assertEquals("event fired properly ", "exited", listener1.event); assertEquals("event fired properly ", "exited", listener2.event); assertSame("one event fired ", listener1.event, listener2.event); }
private static MouseEvent convertEvent(final MouseEvent e, final Component target) { final Point point = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), target); if (e instanceof MouseWheelEvent) { final MouseWheelEvent mwe = (MouseWheelEvent)e; return new MouseWheelEvent(target, mwe.getID(), mwe.getWhen(), mwe.getModifiersEx(), point.x, point.y, mwe.getClickCount(), mwe.isPopupTrigger(), mwe.getScrollType(), mwe.getScrollAmount(), mwe.getWheelRotation()); } else if (e instanceof MenuDragMouseEvent) { final MenuDragMouseEvent de = (MenuDragMouseEvent)e; return new MenuDragMouseEvent(target, de.getID(), de.getWhen(), de.getModifiersEx(), point.x, point.y, e.getClickCount(), e.isPopupTrigger(), de.getPath(), de.getMenuSelectionManager()); } else { return new MouseEvent(target, e.getID(), e.getWhen(), e.getModifiersEx(), point.x, point.y, e.getClickCount(), e.isPopupTrigger(), e.getButton()); } }
/** * Maps {@code JMenuItem.processMenuDragMouseEvent(MenuDragMouseEvent)} * through queue */ public void processMenuDragMouseEvent(final MenuDragMouseEvent menuDragMouseEvent) { runMapping(new MapVoidAction("processMenuDragMouseEvent") { @Override public void map() { ((JMenuItem) getSource()).processMenuDragMouseEvent(menuDragMouseEvent); } }); }
/** * Process mouse events forwarded from MenuSelectionManager. * * @param ev event forwarded from MenuSelectionManager * @param path path to the menu element from which event was generated * @param manager MenuSelectionManager for the current menu hierarchy */ public void processMouseEvent(MouseEvent ev, MenuElement[] path, MenuSelectionManager manager) { MenuDragMouseEvent e = new MenuDragMouseEvent(ev.getComponent(), ev.getID(), ev.getWhen(), ev.getModifiers(), ev.getX(), ev.getY(), ev.getClickCount(), ev.isPopupTrigger(), path, manager); processMenuDragMouseEvent(e); }
/** * Fires MenuDragMouseEvent to all of the menuItem's MouseInputListeners. * * @param event The event signifying that mouse entered menuItem while it was dragged */ protected void fireMenuDragMouseEntered(MenuDragMouseEvent event) { EventListener[] ll = listenerList.getListeners(MenuDragMouseListener.class); for (int i = 0; i < ll.length; i++) ((MenuDragMouseListener) ll[i]).menuDragMouseEntered(event); }
/** * Fires MenuDragMouseEvent to all of the menuItem's MouseInputListeners. * * @param event The event signifying that mouse has exited menu item, while it was dragged */ protected void fireMenuDragMouseExited(MenuDragMouseEvent event) { EventListener[] ll = listenerList.getListeners(MenuDragMouseListener.class); for (int i = 0; i < ll.length; i++) ((MenuDragMouseListener) ll[i]).menuDragMouseExited(event); }
/** * Fires MenuDragMouseEvent to all of the menuItem's MouseInputListeners. * * @param event The event signifying that mouse is being dragged over the menuItem */ protected void fireMenuDragMouseDragged(MenuDragMouseEvent event) { EventListener[] ll = listenerList.getListeners(MenuDragMouseListener.class); for (int i = 0; i < ll.length; i++) ((MenuDragMouseListener) ll[i]).menuDragMouseDragged(event); }
/** * This method fires a MenuDragMouseEvent to all the MenuItem's MouseInputListeners. * * @param event The event signifying that mouse was released while it was dragged over the menuItem */ protected void fireMenuDragMouseReleased(MenuDragMouseEvent event) { EventListener[] ll = listenerList.getListeners(MenuDragMouseListener.class); for (int i = 0; i < ll.length; i++) ((MenuDragMouseListener) ll[i]).menuDragMouseReleased(event); }
/** * Tbis method is invoked when mouse was dragged and released inside the * menu item. * * @param e * The MenuDragMouseEvent */ public void menuDragMouseReleased(MenuDragMouseEvent e) { MenuSelectionManager manager = e.getMenuSelectionManager(); int x = e.getX(); int y = e.getY(); if (x >= 0 && x < menuItem.getWidth() && y >= 0 && y < menuItem.getHeight()) doClick(manager); else manager.clearSelectedPath(); }
public void menuDragMouseReleased(MenuDragMouseEvent e){ MenuSelectionManager manager=e.getMenuSelectionManager(); Point p=e.getPoint(); if(p.x>=0&&p.x<menuItem.getWidth()&& p.y>=0&&p.y<menuItem.getHeight()){ doClick(manager,e); } else{ manager.clearSelectedPath(); } }
public static MouseEvent convert(MouseEvent event, Component source, int id, long when, int modifiers, int x, int y) { if (event instanceof MouseWheelEvent) return convert((MouseWheelEvent)event, source, id, when, modifiers, x, y); if (event instanceof MenuDragMouseEvent) return convert((MenuDragMouseEvent)event, source, id, when, modifiers, x, y); return new MouseEvent(source, id, when, modifiers, x, y, event.getClickCount(), event.isPopupTrigger(), event.getButton()); }
public static MenuDragMouseEvent convert(MenuDragMouseEvent event, Component source, int id, long when, int modifiers, int x, int y) { return new MenuDragMouseEvent(source, id, when, modifiers, x, y, event.getClickCount(), event.isPopupTrigger(), event.getPath(), event.getMenuSelectionManager()); }