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

The following examples show how to use java.awt.event.MouseWheelEvent#getModifiers() . 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: VisualGraphScreenPositioningPlugin.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
	int eventModifiers = e.getModifiers();
	boolean controlKeyDown = (eventModifiers & DockingUtils.CONTROL_KEY_MODIFIER_MASK) != 0;
	if (!controlKeyDown) {
		return;
	}

	int wheelRotation = -e.getWheelRotation();
	int offset = wheelRotation * 10;

	Point newPoint = new Point(0, offset);

	if (e.isAltDown()) {
		// control-alt is a horizontal pan
		newPoint.setLocation(offset, 0);
	}

	VisualGraphViewUpdater<V, E> updater = getViewUpdater(e);
	updater.moveViewerLocationWithoutAnimation(newPoint);
}
 
Example 2
Source File: JavaOverviewSummary.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
HorizontalScroller(JComponent view) {
    super(view, VERTICAL_SCROLLBAR_NEVER, HORIZONTAL_SCROLLBAR_AS_NEEDED);

    setBorder(BorderFactory.createEmptyBorder());
    setViewportBorder(BorderFactory.createEmptyBorder());

    getViewport().setOpaque(false);
    setOpaque(false);
    
    super.addMouseWheelListener(new MouseWheelListener() {
        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (e.getModifiers() == MouseWheelEvent.SHIFT_MASK) {
                scroll(getHorizontalScrollBar(), e);
            } else {
                getParent().dispatchEvent(e);
            }
        }
        
    });
}
 
Example 3
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 4
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 5
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 6
Source File: VisualGraphScrollWheelPanningPlugin.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private boolean isScrollModifiers(MouseWheelEvent e) {
	GraphViewer<V, E> viewer = getGraphViewer(e);
	VisualGraphOptions options = viewer.getOptions();
	boolean scrollWheelPans = options.getScrollWheelPans();
	int scrollWheelModifierToggle = DockingUtils.CONTROL_KEY_MODIFIER_MASK;
	int eventModifiers = e.getModifiers();
	if (scrollWheelPans) {
		// scrolling will pan if *not* modified (modified in this case means to zoom)
		return !((scrollWheelModifierToggle & eventModifiers) == scrollWheelModifierToggle);
	}

	// scrolling *will* pan only when modified (unmodified in this case means to zoom)
	return ((scrollWheelModifierToggle & eventModifiers) == scrollWheelModifierToggle);
}
 
Example 7
Source File: PrintPreviewComponent.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
public PrintPreviewComponent(RamusPrintable printable, int columnCount,
                             GUIFramework framework) {
    this.printable = printable;
    this.columnCount = columnCount;
    this.framework = framework;
    MouseWheelListener l = new MouseWheelListener() {

        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
                if (e.getModifiers() == KeyEvent.CTRL_MASK) {
                    double r = e.getWheelRotation();
                    double zoom = getZoom() - 0.2 * r;
                    setCurrentZoom(zoom);
                } else {
                    Rectangle rect = getVisibleRect();
                    scrollRectToVisible(new Rectangle(rect.x, rect.y
                            + e.getWheelRotation() * 150, rect.width,
                            rect.height));
                }
            }
        }
    };
    this.addMouseWheelListener(l);
    layout = Options.getInteger("PREVIW_LAYOUT", PREV_LAYOUT_GRID);
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            setCurrentZoom(Options.getDouble("PREV_ZOOM", 1d));
        }
    });
    setCurrentZoom(Options.getDouble("PREV_ZOOM", 1d));
}
 
Example 8
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 9
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 10
Source File: GuiUtil.java    From CQL with GNU Affero General Public License v3.0 4 votes vote down vote up
private MouseWheelEvent cloneEvent(MouseWheelEvent e) {
	return new MouseWheelEvent(getParentScrollPane(), e.getID(), e.getWhen(), e.getModifiers(), 1, 1,
			e.getClickCount(), false, e.getScrollType(), e.getScrollAmount(), e.getWheelRotation());
}
 
Example 11
Source File: CustomScrollPane.java    From PacketProxy with Apache License 2.0 4 votes vote down vote up
private MouseWheelEvent cloneEvent(MouseWheelEvent e) {
	return new MouseWheelEvent(getParentScrollPane(), e.getID(), e
			.getWhen(), e.getModifiers(), 1, 1, e
			.getClickCount(), false, e.getScrollType(), e
			.getScrollAmount(), e.getWheelRotation());
}
 
Example 12
Source File: MouseWheelController.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
private MouseWheelEvent createScrollAmountEvent(MouseWheelEvent e) {
	//  Reset the scroll amount
	return new MouseWheelEvent(e.getComponent(), e.getID(), e.getWhen(), e.getModifiers(),
			e.getX(), e.getY(), e.getXOnScreen(), e.getYOnScreen(),
			e.getClickCount(), e.isPopupTrigger(), e.getScrollType(), scrollAmount, e.getWheelRotation());
}
 
Example 13
Source File: JBScrollPane.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * Indicates whether the specified event is not consumed and does not have unexpected modifiers.
 *
 * @param event a mouse wheel event to check for validity
 * @return {@code true} if the specified event is valid, {@code false} otherwise
 */
public static boolean isScrollEvent(@Nonnull MouseWheelEvent event) {
  if (event.isConsumed()) return false; // event should not be consumed already
  if (event.getWheelRotation() == 0) return false; // any rotation expected (forward or backward)
  return 0 == (SCROLL_MODIFIERS & event.getModifiers());
}