Java Code Examples for java.awt.event.MouseMotionListener

The following are top voted examples for showing how to use java.awt.event.MouseMotionListener. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: cn1   File: Component.java   Source Code and License 7 votes vote down vote up
@SuppressWarnings("unchecked")
public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
    if (ComponentListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getComponentListeners();
    } else if (FocusListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getFocusListeners();
    } else if (HierarchyBoundsListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getHierarchyBoundsListeners();
    } else if (HierarchyListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getHierarchyListeners();
    } else if (InputMethodListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getInputMethodListeners();
    } else if (KeyListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getKeyListeners();
    } else if (MouseWheelListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getMouseWheelListeners();
    } else if (MouseMotionListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getMouseMotionListeners();
    } else if (MouseListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getMouseListeners();
    } else if (PropertyChangeListener.class.isAssignableFrom(listenerType)) {
        return (T[]) getPropertyChangeListeners();
    }
    return (T[]) Array.newInstance(listenerType, 0);
}
 
Example 2
Project: Parabot-317-API-Minified-PkHonor   File: ScriptEngine.java   Source Code and License 6 votes vote down vote up
public void init() {
    if (script == null) {
        throw new RuntimeException("Script is null");
    }
    if (script instanceof MouseListener) {
        addMouseListener((MouseListener) script);
    }
    if (script instanceof MouseMotionListener) {
        addMouseMotionListener((MouseMotionListener) script);
    }
    if (script instanceof MessageListener) {
        addMessageListener((MessageListener) script);
    }
    if (script instanceof Paintable) {
        Context.getInstance().addPaintable((Paintable) script);
    }
    if (script instanceof GameActionListener) {
        addActionListener((GameActionListener) script);
    }
}
 
Example 3
Project: Parabot-317-API-Minified-Dreamscape   File: ScriptEngine.java   Source Code and License 6 votes vote down vote up
public void init() {
    if (script == null) {
        throw new RuntimeException("Script is null");
    }
    if (script instanceof MouseListener) {
        addMouseListener((MouseListener) script);
    }
    if (script instanceof MouseMotionListener) {
        addMouseMotionListener((MouseMotionListener) script);
    }
    if (script instanceof MessageListener) {
        addMessageListener((MessageListener) script);
    }
    if (script instanceof Paintable) {
        Context.getInstance().addPaintable((Paintable) script);
    }
    if (script instanceof GameActionListener) {
        addActionListener((GameActionListener) script);
    }
}
 
Example 4
Project: powertext   File: RTextAreaBase.java   Source Code and License 6 votes vote down vote up
/**
 * Adds listeners that listen for changes to the current line, so we can
 * update our "current line highlight."  This is needed only because of an
 * apparent difference between the JRE 1.4.2 and 1.5.0 (needed on 1.4.2,
 * not needed on 1.5.0).
 */
private void addCurrentLineHighlightListeners() {
	boolean add = true;
	MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners();
	for (int i=0; i<mouseMotionListeners.length; i++) {
		if (mouseMotionListeners[i]==mouseListener) {
			add = false;
			break;
		}
	}
	if (add) {
		//System.err.println("Adding mouse motion listener!");
		addMouseMotionListener(mouseListener);
	}
	MouseListener[] mouseListeners = getMouseListeners();
	for (int i=0; i<mouseListeners.length; i++) {
		if (mouseListeners[i]==mouseListener) {
			add = false;
			break;
		}
	}
	if (add) {
		//System.err.println("Adding mouse listener!");
		addMouseListener(mouseListener);
	}
}
 
Example 5
Project: freecol   File: Canvas.java   Source Code and License 6 votes vote down vote up
/**
 * Checks if this {@code Canvas} contains any in game components.
 *
 * @return {@code true} if there is any in game components.
 */
public boolean containsInGameComponents() {
    KeyListener[] keyListeners = getKeyListeners();
    if (keyListeners.length > 0) {
        return true;
    }

    MouseListener[] mouseListeners = getMouseListeners();
    if (mouseListeners.length > 0) {
        return true;
    }

    MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners();
    if (mouseMotionListeners.length > 0) {
        return true;
    }

    return false;
}
 
Example 6
Project: freecol   File: Canvas.java   Source Code and License 6 votes vote down vote up
/**
 * Removes components that is only used when in game.
 */
public void removeInGameComponents() {
    // remove listeners, they will be added when launching the new game...
    KeyListener[] keyListeners = getKeyListeners();
    for (KeyListener keyListener : keyListeners) {
        removeKeyListener(keyListener);
    }

    MouseListener[] mouseListeners = getMouseListeners();
    for (MouseListener mouseListener : mouseListeners) {
        removeMouseListener(mouseListener);
    }

    MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners();
    for (MouseMotionListener mouseMotionListener : mouseMotionListeners) {
        removeMouseMotionListener(mouseMotionListener);
    }

    for (Component c : getComponents()) {
        removeFromCanvas(c);
    }
}
 
Example 7
Project: freecol   File: InGameMenuBar.java   Source Code and License 6 votes vote down vote up
/**
 * Creates a new {@code FreeColMenuBar}. This menu bar will include
 * all of the submenus and items.
 *
 * @param freeColClient The main controller.
 * @param listener An optional mouse motion listener.
 */
public InGameMenuBar(FreeColClient freeColClient, MouseMotionListener listener) {
    // FIXME: FreeColClient should not have to be passed in to
    // this class.  This is only a menu bar, it doesn't need a
    // reference to the main controller.  The only reason it has
    // one now is because DebugMenu needs it.  And DebugMenu needs
    // it because it is using inner classes for ActionListeners
    // and those inner classes use the reference.  If those inner
    // classes were in seperate classes, when they were created,
    // they could use the FreeColClient reference of the
    // ActionManger.  So DebugMenu needs to be refactored to remove
    // inner classes so that this MenuBar can lose its unnecessary
    // reference to the main controller.  See FreeColMenuTest.
    //
    // Okay, I lied.. the update() and paintComponent() methods in
    // this MenuBar use freeColClient, too. But so what.  Move
    // those to another class too. :)
    super(freeColClient);

    // Add a mouse listener so that autoscrolling can happen in
    // this menubar
    this.addMouseMotionListener(listener);
    
    reset();
}
 
Example 8
Project: VTerminal   File: Panel.java   Source Code and License 6 votes vote down vote up
/**
 * Adds an event listener to the Panel.
 *
 * @param eventListener
 *        The event listener.
 *
 * @throws IllegalArgumentException
 *        If the event listener isn't supported by this function.
 */
public void addListener(final EventListener eventListener) {
    if (eventListener instanceof KeyListener) {
        this.addKeyListener((KeyListener) eventListener);
        return;
    }

    if (eventListener instanceof MouseListener) {
        this.addMouseListener((MouseListener) eventListener);
        return;
    }

    if (eventListener instanceof MouseMotionListener) {
        this.addMouseMotionListener((MouseMotionListener) eventListener);
        return;
    }

    throw new IllegalArgumentException("The " + eventListener.getClass().getSimpleName() + " is not supported.");
}
 
Example 9
Project: VTerminal   File: Panel.java   Source Code and License 6 votes vote down vote up
/**
 * Removes an event listener from the Panel.
 *
 * @param eventListener
 *        The event listener.
 *
 * @throws IllegalArgumentException
 *        If the event listener isn't supported by this function.
 */
public void removeListener(final EventListener eventListener) {
    if (eventListener instanceof KeyListener) {
        this.removeKeyListener((KeyListener) eventListener);
        return;
    }

    if (eventListener instanceof MouseListener) {
        this.removeMouseListener((MouseListener) eventListener);
        return;
    }

    if (eventListener instanceof MouseMotionListener) {
        this.removeMouseMotionListener((MouseMotionListener) eventListener);
        return;
    }

    throw new IllegalArgumentException("The " + eventListener.getClass().getSimpleName() + " is not supported.");
}
 
Example 10
Project: Parabot-317-API-Minified-OS-Scape   File: ScriptEngine.java   Source Code and License 6 votes vote down vote up
public void init() {
        if (script == null) {
            throw new RuntimeException("Script is null");
        }
        if (script instanceof MouseListener) {
            addMouseListener((MouseListener) script);
        }
        if (script instanceof MouseMotionListener) {
            addMouseMotionListener((MouseMotionListener) script);
        }
//        if (script instanceof MessageListener) {
//            addMessageListener((MessageListener) script);
//        }
        if (script instanceof Paintable) {
            Context.getInstance().addPaintable((Paintable) script);
        }
//        if (script instanceof GameActionListener) {
//            addActionListener((GameActionListener) script);
//        }
    }
 
Example 11
Project: Cognizant-Intelligent-Test-Scripter   File: SelectionManager.java   Source Code and License 6 votes vote down vote up
public void removeListener() {
    for (MouseListener ml : com.getMouseListeners()) {
        com.removeMouseListener(ml);
    }
    for (MouseMotionListener mml : com.getMouseMotionListeners()) {
        com.removeMouseMotionListener(mml);
    }
    for (KeyListener kl : com.getKeyListeners()) {
        com.removeKeyListener(kl);
    }
    reset();
    com.repaint();
}
 
Example 12
Project: FreeCol   File: Canvas.java   Source Code and License 6 votes vote down vote up
/**
 * Checks if this {@code Canvas} contains any in game components.
 *
 * @return {@code true} if there is any in game components.
 */
public boolean containsInGameComponents() {
    KeyListener[] keyListeners = getKeyListeners();
    if (keyListeners.length > 0) {
        return true;
    }

    MouseListener[] mouseListeners = getMouseListeners();
    if (mouseListeners.length > 0) {
        return true;
    }

    MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners();
    if (mouseMotionListeners.length > 0) {
        return true;
    }

    return false;
}
 
Example 13
Project: FreeCol   File: Canvas.java   Source Code and License 6 votes vote down vote up
/**
 * Removes components that is only used when in game.
 */
public void removeInGameComponents() {
    // remove listeners, they will be added when launching the new game...
    KeyListener[] keyListeners = getKeyListeners();
    for (KeyListener keyListener : keyListeners) {
        removeKeyListener(keyListener);
    }

    MouseListener[] mouseListeners = getMouseListeners();
    for (MouseListener mouseListener : mouseListeners) {
        removeMouseListener(mouseListener);
    }

    MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners();
    for (MouseMotionListener mouseMotionListener : mouseMotionListeners) {
        removeMouseMotionListener(mouseMotionListener);
    }

    for (Component c : getComponents()) {
        removeFromCanvas(c);
    }
}
 
Example 14
Project: FreeCol   File: InGameMenuBar.java   Source Code and License 6 votes vote down vote up
/**
 * Creates a new {@code FreeColMenuBar}. This menu bar will include
 * all of the submenus and items.
 *
 * @param freeColClient The main controller.
 * @param listener An optional mouse motion listener.
 */
public InGameMenuBar(FreeColClient freeColClient, MouseMotionListener listener) {
    // FIXME: FreeColClient should not have to be passed in to
    // this class.  This is only a menu bar, it doesn't need a
    // reference to the main controller.  The only reason it has
    // one now is because DebugMenu needs it.  And DebugMenu needs
    // it because it is using inner classes for ActionListeners
    // and those inner classes use the reference.  If those inner
    // classes were in seperate classes, when they were created,
    // they could use the FreeColClient reference of the
    // ActionManger.  So DebugMenu needs to be refactored to remove
    // inner classes so that this MenuBar can lose its unnecessary
    // reference to the main controller.  See FreeColMenuTest.
    //
    // Okay, I lied.. the update() and paintComponent() methods in
    // this MenuBar use freeColClient, too. But so what.  Move
    // those to another class too. :)
    super(freeColClient);

    // Add a mouse listener so that autoscrolling can happen in
    // this menubar
    this.addMouseMotionListener(listener);
    
    reset();
}
 
Example 15
Project: PhET   File: ApparatusPanel.java   Source Code and License 6 votes vote down vote up
/**
 * Sets up mouse and key listeners
 */
protected void setMouseAndKeyListeners( MouseInputListener mouseHandler, KeyListener keyAdapter ) {
    // Clear the old handlers
    MouseListener[] mouseListeners = this.getMouseListeners();
    for ( int i = 0; i < mouseListeners.length; i++ ) {
        MouseListener mouseListener = mouseListeners[i];
        this.removeMouseListener( mouseListener );
    }
    MouseMotionListener[] mouseMostionListeners = this.getMouseMotionListeners();
    for ( int i = 0; i < mouseMostionListeners.length; i++ ) {
        MouseMotionListener mouseMostionListener = mouseMostionListeners[i];
        this.removeMouseMotionListener( mouseMostionListener );
    }
    KeyListener[] keyListeners = this.getKeyListeners();
    for ( int i = 0; i < keyListeners.length; i++ ) {
        KeyListener keyListener = keyListeners[i];
        this.removeKeyListener( keyListener );
    }

    // Add the new handlers
    this.addMouseListener( mouseHandler );
    this.addMouseMotionListener( getGraphic().getMouseHandler() );
    this.addKeyListener( keyAdapter );
}
 
Example 16
Project: FCMFrame   File: CCSystem.java   Source Code and License 6 votes vote down vote up
/**
 * Set whether the coordinate system is movable with the mouse, i.e.
 * the scope of the system changes as the the mouse is clicked, held
 * and dragged over the system.
 * 
 * @param movable
 *        If true, move is possible.
 */
public void setMovable(boolean movable) {
    if (this.movable && movable) return;
    if (!this.movable && !movable) return;
    
    if (movable) {
        addMouseListener(mouseListener);
        addMouseMotionListener((MouseMotionListener) mouseListener);
    }
    else {
        removeMouseListener(mouseListener);
        removeMouseMotionListener((MouseMotionListener) mouseListener);
    }
    
    movable = !movable;
}
 
Example 17
Project: ftc   File: RTextAreaBase.java   Source Code and License 6 votes vote down vote up
/**
 * Adds listeners that listen for changes to the current line, so we can
 * update our "current line highlight."  This is needed only because of an
 * apparent difference between the JRE 1.4.2 and 1.5.0 (needed on 1.4.2,
 * not needed on 1.5.0).
 */
private void addCurrentLineHighlightListeners() {
	boolean add = true;
	MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners();
	for (int i=0; i<mouseMotionListeners.length; i++) {
		if (mouseMotionListeners[i]==mouseListener) {
			add = false;
			break;
		}
	}
	if (add==true) {
		//System.err.println("Adding mouse motion listener!");
		addMouseMotionListener(mouseListener);
	}
	MouseListener[] mouseListeners = getMouseListeners();
	for (int i=0; i<mouseListeners.length; i++) {
		if (mouseListeners[i]==mouseListener) {
			add = false;
			break;
		}
	}
	if (add==true) {
		//System.err.println("Adding mouse listener!");
		addMouseListener(mouseListener);
	}
}
 
Example 18
Project: Tank   File: RTextAreaBase.java   Source Code and License 6 votes vote down vote up
/**
 * Adds listeners that listen for changes to the current line, so we can update our "current line highlight." This
 * is needed only because of an apparent difference between the JRE 1.4.2 and 1.5.0 (needed on 1.4.2, not needed on
 * 1.5.0).
 */
protected void addCurrentLineHighlightListeners() {
    boolean add = true;
    MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners();
    for (int i = 0; i < mouseMotionListeners.length; i++) {
        if (mouseMotionListeners[i] == mouseListener) {
            add = false;
            break;
        }
    }
    if (add == true) {
        // System.err.println("Adding mouse motion listener!");
        addMouseMotionListener(mouseListener);
    }
    MouseListener[] mouseListeners = getMouseListeners();
    for (int i = 0; i < mouseListeners.length; i++) {
        if (mouseListeners[i] == mouseListener) {
            add = false;
            break;
        }
    }
    if (add == true) {
        // System.err.println("Adding mouse listener!");
        addMouseListener(mouseListener);
    }
}
 
Example 19
Project: Tank   File: RTextAreaBase.java   Source Code and License 6 votes vote down vote up
/**
 * Adds listeners that listen for changes to the current line, so we can update our "current line highlight." This
 * is needed only because of an apparent difference between the JRE 1.4.2 and 1.5.0 (needed on 1.4.2, not needed on
 * 1.5.0).
 */
protected void addCurrentLineHighlightListeners() {
    boolean add = true;
    MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners();
    for (int i = 0; i < mouseMotionListeners.length; i++) {
        if (mouseMotionListeners[i] == mouseListener) {
            add = false;
            break;
        }
    }
    if (add == true) {
        // System.err.println("Adding mouse motion listener!");
        addMouseMotionListener(mouseListener);
    }
    MouseListener[] mouseListeners = getMouseListeners();
    for (int i = 0; i < mouseListeners.length; i++) {
        if (mouseListeners[i] == mouseListener) {
            add = false;
            break;
        }
    }
    if (add == true) {
        // System.err.println("Adding mouse listener!");
        addMouseListener(mouseListener);
    }
}
 
Example 20
Project: ESPlorer   File: RTextAreaBase.java   Source Code and License 6 votes vote down vote up
/**
 * Adds listeners that listen for changes to the current line, so we can
 * update our "current line highlight."  This is needed only because of an
 * apparent difference between the JRE 1.4.2 and 1.5.0 (needed on 1.4.2,
 * not needed on 1.5.0).
 */
private void addCurrentLineHighlightListeners() {
	boolean add = true;
	MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners();
	for (int i=0; i<mouseMotionListeners.length; i++) {
		if (mouseMotionListeners[i]==mouseListener) {
			add = false;
			break;
		}
	}
	if (add==true) {
		//System.err.println("Adding mouse motion listener!");
		addMouseMotionListener(mouseListener);
	}
	MouseListener[] mouseListeners = getMouseListeners();
	for (int i=0; i<mouseListeners.length; i++) {
		if (mouseListeners[i]==mouseListener) {
			add = false;
			break;
		}
	}
	if (add==true) {
		//System.err.println("Adding mouse listener!");
		addMouseListener(mouseListener);
	}
}
 
Example 21
Project: openwonderland   File: HUDFrameHeader2D.java   Source Code and License 6 votes vote down vote up
public void notifyMouseMotionListeners(final MouseEvent e) {
    SwingWorker worker = new SwingWorker<String, Object>() {

        @Override
        public String doInBackground() {
            if (mouseMotionListeners != null) {
                e.setSource(this);
                ListIterator<MouseMotionListener> iter = mouseMotionListeners.listIterator();
                while (iter.hasNext()) {
                    MouseMotionListener listener = iter.next();

                    switch (e.getID()) {
                        case MouseEvent.MOUSE_MOVED:
                            listener.mouseMoved(e);
                            break;
                        case MouseEvent.MOUSE_DRAGGED:
                            listener.mouseDragged(e);
                            break;
                        default:
                            break;
                    }
                }
                iter = null;
            }
            return null;
        }
    };
    worker.execute();
    try {
        worker.get();
    } catch (Exception ie) {
    }
}
 
Example 22
Project: openwonderland   File: HUDView2D.java   Source Code and License 6 votes vote down vote up
public void notifyMouseMotionListeners(MouseEvent e) {
    if (mouseMotionListeners != null) {
        e.setSource(this);
        ListIterator<MouseMotionListener> iter = mouseMotionListeners.listIterator();
        while (iter.hasNext()) {
            MouseMotionListener listener = iter.next();

            switch (e.getID()) {
                case MouseEvent.MOUSE_MOVED:
                    listener.mouseMoved(e);
                    break;
                case MouseEvent.MOUSE_DRAGGED:
                    listener.mouseDragged(e);
                    break;
                default:
                    break;
            }
        }
        iter = null;
    }
}
 
Example 23
Project: openwonderland   File: Window2D.java   Source Code and License 6 votes vote down vote up
/**
 * Deliver the given mouse motion event to the window.
 *
 * @param event The mouse motion event to deliver.
 */
private void deliverMouseMotionEvent(MouseEvent event) {
    if (mouseMotionListeners == null) {
        return;
    }

    for (MouseMotionListener listener : mouseMotionListeners) {
        switch (event.getID()) {
            case MouseEvent.MOUSE_MOVED:
                listener.mouseMoved(event);
                break;
            case MouseEvent.MOUSE_DRAGGED:
                listener.mouseDragged(event);
                break;
        }
    }
}
 
Example 24
Project: openwonderland   File: Window2D.java   Source Code and License 6 votes vote down vote up
/**
 * Remove a listener for mouse motion events.
 *
 * @param listener The mouse motion listener to remove.
 */
public void removeMouseMotionListener(MouseMotionListener listener) {
    if (app == null) {
        return;
    }
    synchronized (app.getAppCleanupLock()) {
        synchronized (this) {
            if (mouseMotionListeners == null) {
                return;
            }
            mouseMotionListeners.remove(listener);
            if (mouseMotionListeners.size() == 0) {
                mouseMotionListeners = null;
            }
        }
    }
}
 
Example 25
Project: openwonderland   File: HeaderPanel.java   Source Code and License 6 votes vote down vote up
@Override
public void addMouseMotionListener(final MouseMotionListener listener) {
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            HeaderPanel.super.addMouseMotionListener(listener);
            if (appLabel != null) {
                appLabel.addMouseMotionListener(listener);
            }
            if (controllerLabel != null) {
                controllerLabel.addMouseMotionListener(listener);
            }
            if (closeButton != null) {
                closeButton.addMouseMotionListener(listener);
            }
            if (hudButton != null) {
                hudButton.addMouseMotionListener(listener);
            }
        }
    });
}
 
Example 26
Project: openwonderland   File: HeaderPanel.java   Source Code and License 6 votes vote down vote up
@Override
public void removeMouseMotionListener(final MouseMotionListener listener) {
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            HeaderPanel.super.removeMouseMotionListener(listener);
            if (appLabel != null) {
                appLabel.removeMouseMotionListener(listener);
            }
            if (controllerLabel != null) {
                controllerLabel.removeMouseMotionListener(listener);
            }
            if (closeButton != null) {
                closeButton.removeMouseMotionListener(listener);
            }
            if (hudButton != null) {
                hudButton.removeMouseMotionListener(listener);
            }
        }
    });
}
 
Example 27
Project: power-matchmaker   File: MungePen.java   Source Code and License 6 votes vote down vote up
/**
 * Removes all listeners associated with the given Component. This is useful when removing to to make sure
 * it does not stick around.
 */
public static void removeAllListeners(Component com) {
	for (FocusListener fl : com.getFocusListeners()) {
		com.removeFocusListener(fl);
	}
	
	for (MouseListener ml : com.getMouseListeners()) {
		com.removeMouseListener(ml);
	}
	
	for (MouseMotionListener mml : com.getMouseMotionListeners()) {
		com.removeMouseMotionListener(mml);
	}
	
	for (KeyListener kl : com.getKeyListeners()) {
		com.removeKeyListener(kl);
	}
	
	for (ComponentListener cl : com.getComponentListeners()) {
		com.removeComponentListener(cl);
	}
}
 
Example 28
Project: kkMulticopterFlashTool   File: SelectionManager.java   Source Code and License 6 votes vote down vote up
public void mouseClicked(MouseEvent event)
  {
if ((activeObject != null) && activeObject.contains(event.getX(), event.getY()))
{
	eventRelay.relay("mouseClicked", event);
}
else
{
   	if (event.getClickCount() == 2)
   	{
   		if (selectedObject != null)
   		{
   			activeObject = selectedObject;
   			Component component = activeObject.getComponent();
   			if (component != null)
   			{
   				eventRelay.reset();
    			eventRelay.addTarget(component, MouseListener.class, MouseEvent.class, mouseNames);
    			eventRelay.addTarget(component, MouseMotionListener.class, MouseEvent.class, mouseMotionNames);
    		    selectableContainer.select(selectedObject, false);
   			}
   		}
   	}
}
  }
 
Example 29
Project: kkMulticopterFlashTool   File: MouseInterceptPanel.java   Source Code and License 6 votes vote down vote up
public void setMouseMotionIntercept(MouseMotionListener listener)
{
	if (mouseMotionIntercept instanceof MouseMotionListener)
		removeMouseMotionListener(mouseMotionIntercept);
	mouseMotionIntercept = listener;
	if (mouseMotionIntercept instanceof MouseMotionListener)
	{
		removeMouseMotionListener(this);
		addMouseMotionListener(mouseMotionIntercept);
		mouseMotionPassThrough = false;
	}
	else
	{
		addMouseMotionListener(this);
		mouseMotionPassThrough = true;
	}
}
 
Example 30
Project: cn1   File: MouseDispatcher.java   Source Code and License 6 votes vote down vote up
private void dispatchMotionEvent(PointerInfo info, NativeEvent event) {
    propagateEvent(info, AWTEvent.MOUSE_MOTION_EVENT_MASK,
                   MouseMotionListener.class, false);
    final Point pos = info.position;
    if ((lastUnderMotion != info.src) ||
        !lastLocalPos.equals(pos)) {

        lastUnderMotion = info.src;
        lastLocalPos = pos;

        if (info.src.isIndirectlyEnabled()) {
            toolkit.getSystemEventQueueImpl().postEvent(
                        new MouseEvent(info.src, event.getEventId(),
                        event.getTime(),
                        event.getInputModifiers(),
                        pos.x, pos.y, 0, false));
        }
    }
}
 
Example 31
Project: ESPlorer   File: RTextAreaBase.java   Source Code and License 6 votes vote down vote up
/**
 * Adds listeners that listen for changes to the current line, so we can
 * update our "current line highlight."  This is needed only because of an
 * apparent difference between the JRE 1.4.2 and 1.5.0 (needed on 1.4.2,
 * not needed on 1.5.0).
 */
private void addCurrentLineHighlightListeners() {
	boolean add = true;
	MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners();
	for (int i=0; i<mouseMotionListeners.length; i++) {
		if (mouseMotionListeners[i]==mouseListener) {
			add = false;
			break;
		}
	}
	if (add==true) {
		//System.err.println("Adding mouse motion listener!");
		addMouseMotionListener(mouseListener);
	}
	MouseListener[] mouseListeners = getMouseListeners();
	for (int i=0; i<mouseListeners.length; i++) {
		if (mouseListeners[i]==mouseListener) {
			add = false;
			break;
		}
	}
	if (add==true) {
		//System.err.println("Adding mouse listener!");
		addMouseListener(mouseListener);
	}
}
 
Example 32
Project: Muloks   File: Updater.java   Source Code and License 6 votes vote down vote up
/**
 * Creates all listeners requested from the current state and adds them to
 * the Listenerlist
 */
private void createListeners() {
	eventListeners.addAll(StateManager.getInstance().getState().getListeners());
	for (EventListener e : eventListeners) {
		if (e instanceof KeyListener) {
			canvas.addKeyListener((KeyListener) e);
		} else if (e instanceof MouseMotionListener) {
			canvas.addMouseMotionListener((MouseMotionListener) e);
		} else if (e instanceof MouseListener) {
			canvas.addMouseListener((MouseListener) e);
		} else if (e instanceof CommandListener) {
			CommandListener cl = (CommandListener) e;
			cl.setUpdater(this);
			StateManager.getInstance().getState().setCommandListener(cl);
		} else {
			System.err.println("Warning: Unimplemented listener listed in Updater");
		}
	}
}
 
Example 33
Project: Muloks   File: Updater.java   Source Code and License 6 votes vote down vote up
/**
 * Destroys all listeners of the current state (use before creating a new state)
 */
private void destroyListeners() {
	for (EventListener e : eventListeners) {
		if (e instanceof KeyListener) {
			canvas.removeKeyListener((KeyListener) e);
		} else if (e instanceof MouseMotionListener) {
			canvas.removeMouseMotionListener((MouseMotionListener) e);
		} else if (e instanceof MouseListener) {
			canvas.removeMouseListener((MouseListener) e);
		} else if (e instanceof CommandListener); //No need to do anything here yet
		else {
			System.err.println("Warning: Unimplemented listener removed from Updater");
		}
	}
	eventListeners.clear();
}
 
Example 34
Project: Parabot-317-API-Minified   File: ScriptEngine.java   Source Code and License 6 votes vote down vote up
public void init() {
    if (script == null) {
        throw new RuntimeException("Script is null");
    }
    if (script instanceof MouseListener) {
        addMouseListener((MouseListener) script);
    }
    if (script instanceof MouseMotionListener) {
        addMouseMotionListener((MouseMotionListener) script);
    }
    if (script instanceof MessageListener) {
        addMessageListener((MessageListener) script);
    }
    if (script instanceof Paintable) {
        Context.getInstance().addPaintable((Paintable) script);
    }
    if (script instanceof GameActionListener) {
        addActionListener((GameActionListener) script);
    }
}
 
Example 35
Project: BfROpenLab   File: VisualizationViewer.java   Source Code and License 6 votes vote down vote up
/**
 * a setter for the GraphMouse. This will remove any
 * previous GraphMouse (including the one that
 * is added in the initMouseClicker method.
 * @param graphMouse new value
 */
public void setGraphMouse(GraphMouse graphMouse) {
    this.graphMouse = graphMouse;
    MouseListener[] ml = getMouseListeners();
    for(int i=0; i<ml.length; i++) {
        if(ml[i] instanceof GraphMouse) {
            removeMouseListener(ml[i]);
        }
    }
    MouseMotionListener[] mml = getMouseMotionListeners();
    for(int i=0; i<mml.length; i++) {
        if(mml[i] instanceof GraphMouse) {
            removeMouseMotionListener(mml[i]);
        }
    }
    MouseWheelListener[] mwl = getMouseWheelListeners();
    for(int i=0; i<mwl.length; i++) {
        if(mwl[i] instanceof GraphMouse) {
            removeMouseWheelListener(mwl[i]);
        }
    }
    addMouseListener(graphMouse);
    addMouseMotionListener(graphMouse);
    addMouseWheelListener(graphMouse);
}
 
Example 36
Project: litiengine   File: Mouse.java   Source Code and License 5 votes vote down vote up
@Override
public void registerMouseMotionListener(final MouseMotionListener listener) {
  if (this.mouseMotionListeners.contains(listener)) {
    return;
  }

  this.mouseMotionListeners.add(listener);
}
 
Example 37
Project: litiengine   File: Mouse.java   Source Code and License 5 votes vote down vote up
@Override
public void unregisterMouseMotionListener(final MouseMotionListener listener) {
  if (!this.mouseMotionListeners.contains(listener)) {
    return;
  }

  this.mouseMotionListeners.remove(listener);
}
 
Example 38
Project: VASSAL-src   File: PrivateMap.java   Source Code and License 5 votes vote down vote up
public synchronized void addMouseMotionListener(MouseMotionListener l) {
  if (listenersActive) {
    super.addMouseMotionListener(l);
  }
  else {
    mouseMotionListeners.add(l);
  }
}
 
Example 39
Project: MapAnalyst   File: JMapController.java   Source Code and License 5 votes vote down vote up
public JMapController(JMapViewer map) {
    this.map = map;
    if (this instanceof MouseListener)
        map.addMouseListener((MouseListener) this);
    if (this instanceof MouseWheelListener)
        map.addMouseWheelListener((MouseWheelListener) this);
    if (this instanceof MouseMotionListener)
        map.addMouseMotionListener((MouseMotionListener) this);
}
 
Example 40
Project: ramus   File: Handler.java   Source Code and License 5 votes vote down vote up
/**
 * Strips off the UI's mouse listeners attached to the associated toolbar
 * and replaces them with this handler's listeners.
 */
private void installListeners() {
    if (!ourVersionIsCompatible)
        return;

    ourToolBar.removePropertyChangeListener("UI", ourUIListener);

    // Uninstall the current ui, collect the remaining listeners
    // on the toolbar, and reinstall the ui...
    final ComponentUI ui = ourToolBar.getUI();
    ui.uninstallUI(ourToolBar);
    final java.util.List mList = Arrays.asList(ourToolBar
            .getListeners(MouseListener.class));

    final java.util.List mmList = Arrays.asList(ourToolBar
            .getListeners(MouseMotionListener.class));
    ui.installUI(ourToolBar);

    // ...then remove the listeners that were added by the ui...
    final MouseListener[] ml = ourToolBar
            .getListeners(MouseListener.class);
    final MouseMotionListener[] mml = ourToolBar
            .getListeners(MouseMotionListener.class);

    for (int i = 0; i < ml.length; i++) {
        if (!mList.contains(ml[i]))
            ourToolBar.removeMouseListener(ml[i]);
    }

    for (int i = 0; i < mml.length; i++) {
        if (!mmList.contains(mml[i]))
            ourToolBar.removeMouseMotionListener(mml[i]);
    }

    // ...and add our listeners to the toolbar.
    ourToolBar.addMouseListener(ourDragListener);
    ourToolBar.addMouseMotionListener(ourDragListener);
    ourToolBar.addPropertyChangeListener("UI", ourUIListener);
}
 
Example 41
Project: freecol   File: MapEditorMenuBar.java   Source Code and License 5 votes vote down vote up
/**
 * Creates a new {@code MapEditorMenuBar}. This menu bar will include
 * all of the submenus and items.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param listener An optional mouse motion listener.
 */
public MapEditorMenuBar(final FreeColClient freeColClient, MouseMotionListener listener) {
    super(freeColClient);

    // Add a mouse listener so that autoscrolling can happen in this menubar
    this.addMouseMotionListener(listener);
    reset();
}
 
Example 42
Project: openjdk-jdk10   File: ComponentOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code Component.addMouseMotionListener(MouseMotionListener)}
 * through queue
 */
public void addMouseMotionListener(final MouseMotionListener mouseMotionListener) {
    runMapping(new MapVoidAction("addMouseMotionListener") {
        @Override
        public void map() {
            getSource().addMouseMotionListener(mouseMotionListener);
        }
    });
}
 
Example 43
Project: openjdk-jdk10   File: ComponentOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps
 * {@code Component.removeMouseMotionListener(MouseMotionListener)}
 * through queue
 */
public void removeMouseMotionListener(final MouseMotionListener mouseMotionListener) {
    runMapping(new MapVoidAction("removeMouseMotionListener") {
        @Override
        public void map() {
            getSource().removeMouseMotionListener(mouseMotionListener);
        }
    });
}
 
Example 44
Project: FreeCol   File: MapEditorMenuBar.java   Source Code and License 5 votes vote down vote up
/**
 * Creates a new {@code MapEditorMenuBar}. This menu bar will include
 * all of the submenus and items.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param listener An optional mouse motion listener.
 */
public MapEditorMenuBar(final FreeColClient freeColClient, MouseMotionListener listener) {
    super(freeColClient);

    // Add a mouse listener so that autoscrolling can happen in this menubar
    this.addMouseMotionListener(listener);
    reset();
}
 
Example 45
Project: openjdk9   File: ComponentOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code Component.addMouseMotionListener(MouseMotionListener)}
 * through queue
 */
public void addMouseMotionListener(final MouseMotionListener mouseMotionListener) {
    runMapping(new MapVoidAction("addMouseMotionListener") {
        @Override
        public void map() {
            getSource().addMouseMotionListener(mouseMotionListener);
        }
    });
}
 
Example 46
Project: openjdk9   File: ComponentOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps
 * {@code Component.removeMouseMotionListener(MouseMotionListener)}
 * through queue
 */
public void removeMouseMotionListener(final MouseMotionListener mouseMotionListener) {
    runMapping(new MapVoidAction("removeMouseMotionListener") {
        @Override
        public void map() {
            getSource().removeMouseMotionListener(mouseMotionListener);
        }
    });
}
 
Example 47
Project: PhET   File: PhetJComponent.java   Source Code and License 5 votes vote down vote up
/**
 * This is the nonrecursive form, let's keep it around just in case.
 */
private boolean applyEvent( JComponent component, MouseEvent e, MouseMethod mouseMethod ) {
    MouseListener[] ml = component.getMouseListeners();

    //need an intelligent conversion of mouse point.
    Point pt = toLocalFrame( e.getPoint() );

    MouseEvent newEvent = new MouseEvent( component, e.getID(), System.currentTimeMillis(), e.getModifiers(), pt.x, pt.y, e.getClickCount(), e.isPopupTrigger(), e.getButton() );
    //pass to all listeners, some will be no-ops.//could be rewritten for understandability.
    boolean changed = false;
    if ( mouseMethod instanceof PhetJComponent.MouseListenerMethod ) {
        MouseListenerMethod mle = (MouseListenerMethod) mouseMethod;
        for ( int i = 0; i < ml.length; i++ ) {
            MouseListener mouseListener = ml[i];
            mle.invoke( mouseListener, newEvent );
            changed = true;
        }
    }
    else if ( mouseMethod instanceof MouseMotionListenerMethod ) {
        MouseMotionListenerMethod mmlm = (MouseMotionListenerMethod) mouseMethod;

        MouseMotionListener[] mml = component.getMouseMotionListeners();
        for ( int i = 0; i < mml.length; i++ ) {
            MouseMotionListener mouseMotionListener = mml[i];
            mmlm.invoke( mouseMotionListener, newEvent );
            changed = true;
        }
    }
    else {
        throw new RuntimeException( "Illegal mouse handler class: " + mouseMethod );
    }
    if ( changed ) {
        redraw();
    }
    return changed;
}
 
Example 48
Project: PhET   File: PSwingMouseMotionEvent.java   Source Code and License 5 votes vote down vote up
/**
 * Calls appropriate method on the listener based on this events ID.
 * 
 * @param listener the target for dispatch.
 */
public void dispatchTo(final Object listener) {
    final MouseMotionListener mouseMotionListener = (MouseMotionListener) listener;
    switch (getID()) {
        case MouseEvent.MOUSE_DRAGGED:
            mouseMotionListener.mouseDragged(this);
            break;
        case MouseEvent.MOUSE_MOVED:
            mouseMotionListener.mouseMoved(this);
            break;
        default:
            throw new RuntimeException("PMouseMotionEvent with bad ID");
    }
}
 
Example 49
Project: pumpernickel   File: DecoratedTreeUI.java   Source Code and License 5 votes vote down vote up
@Override
public void mouseDragged(MouseEvent e) {
	mouseX = e.getX();
	mouseY = e.getY();
	repaintDecorations(false);
	if(mouseListener instanceof MouseMotionListener)
		((MouseMotionListener)mouseListener).mouseDragged(e);
}
 
Example 50
Project: pumpernickel   File: DecoratedTreeUI.java   Source Code and License 5 votes vote down vote up
@Override
public void mouseMoved(MouseEvent e) {
	mouseX = e.getX();
	mouseY = e.getY();
	repaintDecorations(false);
	if(mouseListener instanceof MouseMotionListener)
		((MouseMotionListener)mouseListener).mouseMoved(e);
}
 
Example 51
Project: sldeditor   File: CharMap4Grid.java   Source Code and License 5 votes vote down vote up
/**
 * Instantiates a new char map4 grid.
 * 
 * @param charMap4
 */
public CharMap4Grid(CharMap4 charMap4) {
    super(); // initialize our superclass first (JPanel)

    this.charMap4 = charMap4;
    // Set class instance variables to undefined values that we will recognise
    // if we are called before the layout and first "paint" is complete. */

    cellCount = charCount = glyphCount = 0; // no chars or glyphs to display
    clickIndex = NO_MOUSE; // cell index of clicked character
    clickStartX = clickStartY = NO_MOUSE; // no starting coordinates for click
    cornerIndex = 0; // cell index of top-left corner
    fontData = null; // information about current display font
    horizStep = 100; // horizontal offset from one cell to next
    hoverIndex = NO_MOUSE; // cell index of mouse over character
    lineAscent = 100; // number of pixels above baseline
    lineHeight = 100; // height of each display line in pixels
    maxWidth = 100; // maximum pixel width of all characters
    panelColumns = 10; // number of complete text columns displayed
    panelCount = -1; // saved value of <cellCount> used previously
    panelFont = null; // saved font for drawing text on this panel
    panelHeight = panelWidth = -1; // saved panel height and width in pixels
    panelRows = 10; // number of complete lines (rows) displayed
    vertiStep = 100; // vertical offset from one cell to next

    /* Install our mouse and scroll listeners. */

    this.addMouseListener((MouseListener) this);
    this.addMouseMotionListener((MouseMotionListener) this);
    this.addMouseWheelListener((MouseWheelListener) this);
    // this.setFocusable(false); // we don't handle keyboard input, owner does

}
 
Example 52
Project: j2se_for_android   File: JComponent.java   Source Code and License 5 votes vote down vote up
protected void processMouseMotionEvent(final MouseEvent e) {
	final MouseMotionListener[] listeners = getMouseMotionListeners();
	if(listeners != null){
		for (int i = 0; i < listeners.length; i++) {
			if(e.getButton() == MouseEvent.NOBUTTON){
				listeners[i].mouseMoved(e);
			}else{
				listeners[i].mouseDragged(e);
			}
		}
	}
}
 
Example 53
Project: javify   File: Component.java   Source Code and License 5 votes vote down vote up
/**
 * Deserializes this component. This regenerates all serializable listeners
 * which were registered originally.
 *
 * @param s the stream to read from
 * @throws ClassNotFoundException if deserialization fails
 * @throws IOException if the stream fails
 */
private void readObject(ObjectInputStream s)
  throws ClassNotFoundException, IOException
{
  s.defaultReadObject();
  String key = (String) s.readObject();
  while (key != null)
    {
      Object listener = s.readObject();
      if ("componentL".equals(key))
        addComponentListener((ComponentListener) listener);
      else if ("focusL".equals(key))
        addFocusListener((FocusListener) listener);
      else if ("keyL".equals(key))
        addKeyListener((KeyListener) listener);
      else if ("mouseL".equals(key))
        addMouseListener((MouseListener) listener);
      else if ("mouseMotionL".equals(key))
        addMouseMotionListener((MouseMotionListener) listener);
      else if ("inputMethodL".equals(key))
        addInputMethodListener((InputMethodListener) listener);
      else if ("hierarchyL".equals(key))
        addHierarchyListener((HierarchyListener) listener);
      else if ("hierarchyBoundsL".equals(key))
        addHierarchyBoundsListener((HierarchyBoundsListener) listener);
      else if ("mouseWheelL".equals(key))
        addMouseWheelListener((MouseWheelListener) listener);
      key = (String) s.readObject();
    }
}
 
Example 54
Project: javify   File: StandaloneAppletWindow.java   Source Code and License 5 votes vote down vote up
/**
 * This method is called when the mouse is moved over a component
 * while a button has been pressed.
 *
 * @param event the <code>MouseEvent</code> indicating the motion
 */
public void mouseDragged(MouseEvent event)
{
  if (applet != null)
    {
      MouseMotionListener[] l = applet.getMouseMotionListeners();
      for (int i = 0; i < l.length; i++)
        l[i].mouseDragged(event);
    }
}
 
Example 55
Project: javify   File: StandaloneAppletWindow.java   Source Code and License 5 votes vote down vote up
/**
 * This method is called when the mouse is moved over a component
 * while no button is pressed.
 *
 * @param event the <code>MouseEvent</code> indicating the motion
 */
public void mouseMoved(MouseEvent event)
{
  if (applet != null)
    {
      MouseMotionListener[] l = applet.getMouseMotionListeners();
      for (int i = 0; i < l.length; i++)
        l[i].mouseMoved(event);
    }
}
 
Example 56
Project: javify   File: PluginAppletWindow.java   Source Code and License 5 votes vote down vote up
/**
 * This method is called when the mouse is moved over a component
 * while a button has been pressed.
 *
 * @param event the <code>MouseEvent</code> indicating the motion
 */
public void mouseDragged(MouseEvent event)
{
  if (applet != null)
    {
      MouseMotionListener[] l = applet.getMouseMotionListeners();
      for (int i = 0; i < l.length; i++)
        l[i].mouseDragged(event);
    }
}
 
Example 57
Project: javify   File: PluginAppletWindow.java   Source Code and License 5 votes vote down vote up
/**
 * This method is called when the mouse is moved over a component
 * while no button is pressed.
 *
 * @param event the <code>MouseEvent</code> indicating the motion
 */
public void mouseMoved(MouseEvent event)
{
  if (applet != null)
    {
      MouseMotionListener[] l = applet.getMouseMotionListeners();
      for (int i = 0; i < l.length; i++)
        l[i].mouseMoved(event);
    }
}
 
Example 58
Project: intellij-ce-playground   File: IdeGlassPaneImpl.java   Source Code and License 5 votes vote down vote up
private static void fireMouseMotion(MouseMotionListener listener, final MouseEvent event) {
  switch (event.getID()) {
    case MouseEvent.MOUSE_DRAGGED:
      listener.mouseDragged(event);
    case MouseEvent.MOUSE_MOVED:
      listener.mouseMoved(event);
  }
}
 
Example 59
Project: intellij-ce-playground   File: ListenerUtil.java   Source Code and License 5 votes vote down vote up
public static void addMouseMotionListener(Component c, MouseMotionListener l) {
  c.addMouseMotionListener(l);
  if (c instanceof Container) {
    final Container container = (Container)c;
    Component[] children = container.getComponents();
    for (Component child : children) {
      addMouseMotionListener(child, l);
    }
  }
}
 
Example 60
Project: intellij-ce-playground   File: ListenerUtil.java   Source Code and License 5 votes vote down vote up
public static void removeMouseMotionListener(final Component component, final MouseMotionListener motionListener) {
  component.removeMouseMotionListener(motionListener);
  if (component instanceof Container) {
    Container container = (Container)component;
    for (int i = 0; i < container.getComponentCount(); i++) {
      removeMouseMotionListener(container.getComponent(i), motionListener);
    }
  }
}