Java Code Examples for java.awt.event.MouseWheelEvent#getSource()

The following examples show how to use java.awt.event.MouseWheelEvent#getSource() . 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: InteractiveCanvasComponent.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void mouseWheelMoved(MouseWheelEvent e) {
    // Mouse wheel zooming takes precedence over scrolling
    if (isMouseZoomingEnabled() &&
        e.getSource() == InteractiveCanvasComponent.this) return;

    // Change the ScrollBar value
    if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
        int unitsToScroll = e.getUnitsToScroll();
        int direction = unitsToScroll < 0 ? -1 : 1;
        if (unitsToScroll != 0) {
            int increment = scrollBar.getUnitIncrement(direction);
            int oldValue = scrollBar.getValue();
            int newValue = oldValue + increment * unitsToScroll;
            newValue = Math.max(Math.min(newValue, scrollBar.getMaximum() -
                    scrollBar.getVisibleAmount()), scrollBar.getMinimum());
            if (oldValue != newValue) scrollBar.setValue(newValue);
        }
    }
}
 
Example 2
Source File: UIUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static void issue163946Hack(final JScrollPane scrollPane) {
    MouseWheelListener listener = new MouseWheelListener() {
        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (scrollPane.getVerticalScrollBar().isShowing()) {
                if (e.getSource() != scrollPane) {
                    e.setSource(scrollPane);
                    scrollPane.dispatchEvent(e);
                }
            } else {
                scrollPane.getParent().dispatchEvent(e);
            }
        }
    };
    scrollPane.addMouseWheelListener(listener);
    scrollPane.getViewport().getView().addMouseWheelListener(listener);
}
 
Example 3
Source File: InteractiveCanvasComponent.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public void mouseWheelMoved(MouseWheelEvent e) {
    // Mouse wheel zooming takes precedence over scrolling
    if (isMouseZoomingEnabled() &&
        e.getSource() == InteractiveCanvasComponent.this) return;

    // Change the ScrollBar value
    if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
        int unitsToScroll = e.getUnitsToScroll();
        int direction = unitsToScroll < 0 ? -1 : 1;
        if (unitsToScroll != 0) {
            int increment = scrollBar.getUnitIncrement(direction);
            int oldValue = scrollBar.getValue();
            int newValue = oldValue + increment * unitsToScroll;
            newValue = Math.max(Math.min(newValue, scrollBar.getMaximum() -
                    scrollBar.getVisibleAmount()), scrollBar.getMinimum());
            if (oldValue != newValue) scrollBar.setValue(newValue);
        }
    }
}
 
Example 4
Source File: Treeline.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void mouseWheelMoved(final MouseWheelEvent mwe) {
	final int modifiers = mwe.getModifiers();
	if (0 == ( (MouseWheelEvent.SHIFT_MASK | MouseWheelEvent.ALT_MASK) ^ modifiers)) {
		final Object source = mwe.getSource();
		if (! (source instanceof DisplayCanvas)) return;
		final DisplayCanvas dc = (DisplayCanvas)source;
		final Layer la = dc.getDisplay().getLayer();
		final int rotation = mwe.getWheelRotation();
		final float magnification = (float)dc.getMagnification();
		final Rectangle srcRect = dc.getSrcRect();
		final float x = ((mwe.getX() / magnification) + srcRect.x);
		final float y = ((mwe.getY() / magnification) + srcRect.y);

		final float inc = (rotation > 0 ? 1 : -1) * (1/magnification);
		if (null != adjustNodeRadius(inc, x, y, la, dc)) {
			Display.repaint(this);
			mwe.consume();
			return;
		}
	}
	super.mouseWheelMoved(mwe);
}
 
Example 5
Source File: Tree.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void mouseWheelMoved(final MouseWheelEvent mwe) {
	final int modifiers = mwe.getModifiers();
	if (0 == (MouseWheelEvent.SHIFT_MASK ^ modifiers)) {
		final Object source = mwe.getSource();
		if (! (source instanceof DisplayCanvas)) return;
		final DisplayCanvas dc = (DisplayCanvas)source;
		final Layer la = dc.getDisplay().getLayer();
		final int rotation = mwe.getWheelRotation();
		final double magnification = dc.getMagnification();
		final Rectangle srcRect = dc.getSrcRect();
		final float x = (float)((mwe.getX() / magnification) + srcRect.x);
		final float y = (float)((mwe.getY() / magnification) + srcRect.y);

		adjustEdgeConfidence(rotation > 0 ? 1 : -1, x, y, la, dc);
		Display.repaint(this);
		mwe.consume();
	}
}
 
Example 6
Source File: TranslateMouseWheelListener.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
private MouseWheelEvent translateEvent(MouseWheelEvent e)
{
	Dimension stretchedDimensions = client.getStretchedDimensions();
	Dimension realDimensions = client.getRealDimensions();

	int newX = (int) (e.getX() / (stretchedDimensions.width / realDimensions.getWidth()));
	int newY = (int) (e.getY() / (stretchedDimensions.height / realDimensions.getHeight()));

	return new MouseWheelEvent((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiers(), newX, newY,
		e.getClickCount(), e.isPopupTrigger(), e.getScrollType(), e.getScrollAmount(), e.getWheelRotation());
}
 
Example 7
Source File: UIUtilities.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Clones a {@link MouseEvent}.
 *
 * @param event The event to clone.
 * @return The new {@link MouseEvent}.
 */
public static final MouseEvent cloneMouseEvent(MouseEvent event) {
    if (event instanceof MouseWheelEvent) {
        MouseWheelEvent old = (MouseWheelEvent) event;
        return new MouseWheelEvent((Component) old.getSource(), old.getID(), System.currentTimeMillis(), old.getModifiersEx(), old.getX(), old.getY(), old.getClickCount(), old.isPopupTrigger(), old.getScrollType(), old.getScrollAmount(), old.getWheelRotation());
    }
    return new MouseEvent((Component) event.getSource(), event.getID(), System.currentTimeMillis(), event.getModifiersEx(), event.getX(), event.getY(), event.getClickCount(), event.isPopupTrigger());
}
 
Example 8
Source File: UIUtilities.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Clones a {@link MouseEvent}.
 *
 * @param event       The event to clone.
 * @param refreshTime Pass in {@code true} to generate a new time stamp.
 * @return The new {@link MouseEvent}.
 */
public static final MouseEvent cloneMouseEvent(MouseEvent event, boolean refreshTime) {
    if (event instanceof MouseWheelEvent) {
        MouseWheelEvent old = (MouseWheelEvent) event;
        return new MouseWheelEvent((Component) old.getSource(), old.getID(), refreshTime ? System.currentTimeMillis() : event.getWhen(), old.getModifiersEx(), old.getX(), old.getY(), old.getClickCount(), old.isPopupTrigger(), old.getScrollType(), old.getScrollAmount(), old.getWheelRotation());
    }
    return new MouseEvent((Component) event.getSource(), event.getID(), refreshTime ? System.currentTimeMillis() : event.getWhen(), event.getModifiersEx(), event.getX(), event.getY(), event.getClickCount(), event.isPopupTrigger());
}
 
Example 9
Source File: TranslateMouseWheelListener.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private MouseWheelEvent translateEvent(MouseWheelEvent e)
{
	Dimension stretchedDimensions = client.getStretchedDimensions();
	Dimension realDimensions = client.getRealDimensions();

	int newX = (int) (e.getX() / (stretchedDimensions.width / realDimensions.getWidth()));
	int newY = (int) (e.getY() / (stretchedDimensions.height / realDimensions.getHeight()));

	return new MouseWheelEvent((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiers(), newX, newY,
			e.getClickCount(), e.isPopupTrigger(), e.getScrollType(), e.getScrollAmount(), e.getWheelRotation());
}
 
Example 10
Source File: WebViewPanel.java    From wandora with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void processMouseWheelEvent(MouseWheelEvent e) {
    MouseWheelEvent ee = new MouseWheelEvent(
            (Component) e.getSource(), e.getID(), e.getWhen(),
            e.getModifiers(), e.getX(), e.getY(), e.getXOnScreen(),
            e.getYOnScreen(), e.getClickCount(),
            e.isPopupTrigger(), e.getScrollType(), e.getScrollAmount(),
            e.getWheelRotation(), e.getPreciseWheelRotation());
    super.processMouseWheelEvent(ee);
}
 
Example 11
Source File: OptionPanel.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void mouseWheelMoved(MouseWheelEvent mwe) {
	Component source = (Component) mwe.getSource();
	try {
		Setter s = setters.get(source);
		if (s instanceof NumericalSetter) {
			if (null != s) {
				// Update the value of the field and also of the JTextField
				((JTextField)source).setText(((NumericalSetter)s).setFrom(source, mwe.getWheelRotation()).toString());
			}
		}
	} catch (Throwable t) {
		Utils.logAll("Invalid value " + ((JTextField)source).getText());
	}
}
 
Example 12
Source File: ColorWellUI.java    From pumpernickel with MIT License 4 votes vote down vote up
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
	JColorWell well = (JColorWell) e.getSource();
	well.getUI().processMouseEvent(e);
}
 
Example 13
Source File: MTabbedPane.java    From javamelody with Apache License 2.0 4 votes vote down vote up
@Override
public void mouseWheelMoved(MouseWheelEvent event) {
	final MTabbedPane tabbedPane = (MTabbedPane) event.getSource();
	tabbedPane.mouseWheelMoved(event);
}