java.awt.event.MouseWheelEvent#isShiftDown()源码实例Demo

下面列出了java.awt.event.MouseWheelEvent#isShiftDown() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: darklaf   文件: DarkScrollableTabSupport.java
@Override
public void mouseWheelMoved(final MouseWheelEvent e) {
    if (!ui.tabPane.isEnabled() || ui.tabPane.getTabCount() == 0) return;
    int tabPosition = ui.tabPane.getTabPlacement();
    int scrollAmount = -1 * e.getUnitsToScroll() * e.getScrollAmount();
    int scrolled;
    if (tabPosition == SwingConstants.LEFT || tabPosition == SwingConstants.RIGHT) {
        if (e.isShiftDown() || !moreTabsButton.isVisible()) return;
        timer.stop();
        scrolled = scroll(scrollAmount, false);
    } else {
        if (!e.isShiftDown() || !moreTabsButton.isVisible()) return;
        timer.stop();
        scrolled = scroll(scrollAmount, true);
    }
    if (scrolled != 0) {
        showMoreTabsButton();
        updateRollover();
        viewport.repaint();
    }
    timer.start();
}
 
源代码2 项目: netbeans   文件: SmoothScrollPaneUI.java
private void mouseWheelMoved(MouseWheelEvent e) {
    /* The code in this method is taken directly from Pavel Fatin's original IntelliJ patch.
    Some formatting changes have been applied. */
    /* The shift modifier will be enabled for horizontal touchbar scroll events, even when the
    actual shift key is not pressed, on both Windows and MacOS (though not on Java 8 on
    Windows). */
    JScrollBar scrollbar = e.isShiftDown()
            ? scrollpane.getHorizontalScrollBar() : scrollpane.getVerticalScrollBar();
    int orientation = scrollbar.getOrientation();
    JViewport viewport = scrollpane.getViewport();
    if (viewport == null || !(viewport.getView() instanceof Scrollable)) {
        return;
    }
    Scrollable view = (Scrollable) viewport.getView();
    double rotation = e.getPreciseWheelRotation();
    /* Use (0, 0) view position to obtain constant unit increment (which might otherwise be
    variable on smaller-than-unit scrolling). */
    Rectangle r = new Rectangle(new Point(0, 0), viewport.getViewSize());
    int unitIncrement = view.getScrollableUnitIncrement(r, orientation, 1);
    double delta = rotation * e.getScrollAmount() * unitIncrement;
    boolean limitDelta = Math.abs(rotation) < 1.0d + EPSILON;
    int blockIncrement = view.getScrollableBlockIncrement(r, orientation, 1);
    double adjustedDelta = limitDelta
            ? Math.max(-(double) blockIncrement, Math.min(delta, (double) blockIncrement))
            : delta;
    int value = scrollbar.getValue();
    int newValue = Math.max(scrollbar.getMinimum(),
            Math.min((int) Math.round(value + adjustedDelta), scrollbar.getMaximum()));
    if (newValue != value) {
        scrollbar.setValue(newValue);
    }
}
 
源代码3 项目: gcs   文件: DirectScrollPanel.java
@Override
public void mouseWheelMoved(MouseWheelEvent event) {
    if (event.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
        int        amt = event.getUnitsToScroll();
        JScrollBar bar = event.isShiftDown() ? mHSB : mVSB;
        bar.setValue(bar.getValue() + amt * bar.getUnitIncrement());
    }
}
 
源代码4 项目: snap-desktop   文件: ProductSceneView.java
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
    if (e.isAltDown() || e.isAltGraphDown() || e.isControlDown() || e.isShiftDown()) {
        return;
    }
    Viewport viewport = layerCanvas.getViewport();
    int wheelRotation = e.getWheelRotation();
    if (invertZooming) {
        wheelRotation *= -1;
    }
    double oldZoomFactor = viewport.getZoomFactor();
    double newZoomFactor = oldZoomFactor * Math.pow(1.1, wheelRotation);
    viewport.setZoomFactor(newZoomFactor);
}
 
源代码5 项目: consulo   文件: IdeMouseEventDispatcher.java
private static boolean isHorizontalScrolling(Component c, MouseEvent e) {
  if (c != null && e instanceof MouseWheelEvent && (!SystemInfo.isMac || isDiagramViewComponent(c.getParent()))) {
    final MouseWheelEvent mwe = (MouseWheelEvent)e;
    return mwe.isShiftDown() && mwe.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL && isScrollEvent(mwe) && findHorizontalScrollBar(c) != null;
  }
  return false;
}
 
源代码6 项目: FlatLaf   文件: FlatScrollPaneUI.java
private void mouseWheelMovedSmooth( MouseWheelEvent e ) {
		// return if there is no viewport
		JViewport viewport = scrollpane.getViewport();
		if( viewport == null )
			return;

		// find scrollbar to scroll
		JScrollBar scrollbar = scrollpane.getVerticalScrollBar();
		if( scrollbar == null || !scrollbar.isVisible() || e.isShiftDown() ) {
			scrollbar = scrollpane.getHorizontalScrollBar();
			if( scrollbar == null || !scrollbar.isVisible() )
				return;
		}

		// consume event
		e.consume();

		// get precise wheel rotation
		double rotation = e.getPreciseWheelRotation();

		// get unit and block increment
		int unitIncrement;
		int blockIncrement;
		int orientation = scrollbar.getOrientation();
		Component view = viewport.getView();
		if( view instanceof Scrollable ) {
			Scrollable scrollable = (Scrollable) view;

			// Use (0, 0) view position to obtain constant unit increment of first item
			// (which might otherwise be variable on smaller-than-unit scrolling).
			Rectangle visibleRect = new Rectangle( viewport.getViewSize() );
			unitIncrement = scrollable.getScrollableUnitIncrement( visibleRect, orientation, 1 );
			blockIncrement = scrollable.getScrollableBlockIncrement( visibleRect, orientation, 1 );

			if( unitIncrement > 0 ) {
				// For the case that the first item (e.g. in a list) is larger
				// than the other items, get the unit increment of the second item
				// and use the smaller one.
				if( orientation == SwingConstants.VERTICAL ) {
					visibleRect.y += unitIncrement;
					visibleRect.height -= unitIncrement;
				} else {
					visibleRect.x += unitIncrement;
					visibleRect.width -= unitIncrement;
				}
				int unitIncrement2 = scrollable.getScrollableUnitIncrement( visibleRect, orientation, 1 );
				if( unitIncrement2 > 0 )
					unitIncrement = Math.min( unitIncrement, unitIncrement2 );
			}
		} else {
			int direction = rotation < 0 ? -1 : 1;
			unitIncrement = scrollbar.getUnitIncrement( direction );
			blockIncrement = scrollbar.getBlockIncrement( direction );
		}

		// limit scroll amount (number of units to scroll) for small viewports
		// (e.g. vertical scrolling in file chooser)
		int scrollAmount = e.getScrollAmount();
		int viewportWH = (orientation == SwingConstants.VERTICAL)
			? viewport.getHeight()
			: viewport.getWidth();
		if( unitIncrement * scrollAmount > viewportWH )
			scrollAmount = Math.max( viewportWH / unitIncrement, 1 );

		// compute relative delta
		double delta = rotation * scrollAmount * unitIncrement;
		boolean adjustDelta = Math.abs( rotation ) < (1.0 + EPSILON);
		double adjustedDelta = adjustDelta
			? Math.max( -blockIncrement, Math.min( delta, blockIncrement ) )
			: delta;

		// compute new value
		int value = scrollbar.getValue();
		double minDelta = scrollbar.getMinimum() - value;
		double maxDelta = scrollbar.getMaximum() - scrollbar.getModel().getExtent() - value;
		double boundedDelta = Math.max( minDelta, Math.min( adjustedDelta, maxDelta ) );
		int newValue = value + (int) Math.round( boundedDelta );

		// set new value
		if( newValue != value )
			scrollbar.setValue( newValue );

/*debug
		System.out.println( String.format( "%4d  %9f / %4d %4d / %12f %5s %12f / %4d %4d %4d / %12f %12f %12f / %4d",
			e.getWheelRotation(),
			e.getPreciseWheelRotation(),
			unitIncrement,
			blockIncrement,
			delta,
			adjustDelta,
			adjustedDelta,
			value,
			scrollbar.getMinimum(),
			scrollbar.getMaximum(),
			minDelta,
			maxDelta,
			boundedDelta,
			newValue ) );
*/
	}
 
源代码7 项目: consulo   文件: EditorUtil.java
public static boolean isChangeFontSize(@Nonnull MouseWheelEvent e) {
  if (e.getWheelRotation() == 0) return false;
  return SystemInfo.isMac ? !e.isControlDown() && e.isMetaDown() && !e.isAltDown() && !e.isShiftDown() : e.isControlDown() && !e.isMetaDown() && !e.isAltDown() && !e.isShiftDown();
}