Java Code Examples for java.awt.Component#addMouseMotionListener()

The following examples show how to use java.awt.Component#addMouseMotionListener() . 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
Source File: MouseCapture.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Starts redirecting all mouse events to the specified component or one of its children.
 *
 * @param component The target.
 * @param cursor    The cursor to use while the mouse is captured.
 */
public static void start(Component component, Cursor cursor) {
    JRootPane rootPane = SwingUtilities.getRootPane(component);
    if (rootPane != null) {
        Component    glassPane = rootPane.getGlassPane();
        MouseCapture capture   = new MouseCapture(glassPane, component);
        glassPane.addMouseListener(capture);
        glassPane.addMouseMotionListener(capture);
        glassPane.addHierarchyListener(capture);
        if (cursor != null) {
            glassPane.setCursor(cursor);
        }
        MAP.put(component, capture);
        glassPane.setVisible(true);
    }
}
 
Example 2
Source File: MagnificationPanel.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * Add MouseListeners to a component and its children. If children have a
 * MouseListener for mouse-moved events, then this component won't otherwise
 * receive mouse-moved events (and therefore it won't repaint correctly).
 * <p>
 * A common instance of this problem is simply the presence of tooltips
 * (which require a MouseListener).
 */
private void addMouseListeners(Component c) {
	c.addMouseMotionListener(mouseListener);
	c.addMouseListener(mouseListener);
	if (c instanceof Container) {
		Container c2 = (Container) c;
		c2.addContainerListener(containerListener);
		for (Component child : c2.getComponents()) {
			addMouseListeners(child);
		}
	}
}
 
Example 3
Source File: DescendantMouseListener.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * Add all our internal listeners from a component and its descendants.
 */
private void addListeners(DefaultMutableTreeNode componentNode) {
	Component c = (Component) componentNode.getUserObject();
	c.addHierarchyListener(hierarchyListener);
	c.addMouseListener(mouseListener);
	c.addMouseMotionListener(mouseListener);
	for (int a = 0; a < componentNode.getChildCount(); a++) {
		addListeners((DefaultMutableTreeNode) componentNode.getChildAt(a));
	}
	if (c instanceof Container)
		((Container) c).addContainerListener(containerListener);
}
 
Example 4
Source File: AWTMouseInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void bind(Component component) {
    super.bind(component);
    component.addMouseListener(this);
    component.addMouseMotionListener(this);
    component.addMouseWheelListener(this);
}
 
Example 5
Source File: GOSwingEventConverter.java    From settlers-remake with MIT License 5 votes vote down vote up
/**
 * Creates a new event converter, that converts swing events to go events.
 * 
 * @param component
 *            The component.
 * @param provider
 *            THe provider to which to send the events.
 */
public GOSwingEventConverter(Component component, GOEventHandlerProvider provider) {
	super(provider);

	component.setFocusTraversalKeysEnabled(false);

	component.addKeyListener(this);
	component.addMouseListener(this);
	component.addMouseMotionListener(this);
	component.addMouseWheelListener(this);
	component.addHierarchyListener(this);

	addReplaceRule(new EventReplacementRule(ReplacableEvent.DRAW, Replacement.COMMAND_SELECT, MOUSE_TIME_TRSHOLD, MOUSE_MOVE_TRESHOLD));
	addReplaceRule(new EventReplacementRule(ReplacableEvent.PAN, Replacement.COMMAND_ACTION, MOUSE_TIME_TRSHOLD, MOUSE_MOVE_TRESHOLD));
}
 
Example 6
Source File: LazyMouse.java    From amodeus with GNU General Public License v2.0 4 votes vote down vote up
public void addListenersTo(Component myComponent) {
    myComponent.addMouseListener(this);
    myComponent.addMouseMotionListener(this);
}
 
Example 7
Source File: DragReorderHandler.java    From Pixelitor with GNU General Public License v3.0 4 votes vote down vote up
public void attachToComponent(Component c) {
    c.addMouseListener(this);
    c.addMouseMotionListener(this);
}
 
Example 8
Source File: GlobalMouseAdapter.java    From jclic with GNU General Public License v2.0 4 votes vote down vote up
public void attachTo(Component cmp, boolean catchMotion) {
  cmp.addMouseListener(this);
  if (catchMotion)
    cmp.addMouseMotionListener(this);
}
 
Example 9
Source File: WindowMover.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 2 votes vote down vote up
private void addListeners(Component com) {

        com.addMouseListener(ma);
        com.addMouseMotionListener(mma);

    }