下面列出了java.awt.event.MouseWheelEvent#getUnitsToScroll() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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();
}
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);
}
}
}
/**
* Listener for mouse scrolls.
*
* @param e the <code>MouseWheelEvent</code>
*
* @see java.awt.event.MouseWheelListener#mouseWheelMoved(java.awt.event.MouseWheelEvent)
*/
public void mouseWheelMoved(MouseWheelEvent e){
if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL && e.getUnitsToScroll() != 0){
int scrollValue = e.getUnitsToScroll();
double newzoom = renderer_.getMapZoom();
if(scrollValue > 0){
for(int i= 0; i < scrollValue; i+=3){
newzoom -= newzoom/ZOOM_VALUE;
}
} else {
for(int i= 0; i > scrollValue; i-=3){
newzoom += newzoom/ZOOM_VALUE;
}
}
renderer_.setMapZoom(newzoom);
VanetSimStart.getMainControlPanel().getSimulatePanel().setZoomValue((int)Math.round(Math.log(renderer_.getMapZoom()*1000)*50));
ReRenderManager.getInstance().doReRender();
}
}
public static int getIncrementFromAdjustable(Adjustable adj,
MouseWheelEvent e) {
if (log.isLoggable(PlatformLogger.Level.FINE)) {
if (adj == null) {
log.fine("Assertion (adj != null) failed");
}
}
int increment = 0;
if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
increment = e.getUnitsToScroll() * adj.getUnitIncrement();
}
else if (e.getScrollType() == MouseWheelEvent.WHEEL_BLOCK_SCROLL) {
increment = adj.getBlockIncrement() * e.getWheelRotation();
}
return increment;
}
public static int getIncrementFromAdjustable(Adjustable adj,
MouseWheelEvent e) {
if (log.isLoggable(PlatformLogger.Level.FINE)) {
if (adj == null) {
log.fine("Assertion (adj != null) failed");
}
}
int increment = 0;
if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
increment = e.getUnitsToScroll() * adj.getUnitIncrement();
}
else if (e.getScrollType() == MouseWheelEvent.WHEEL_BLOCK_SCROLL) {
increment = adj.getBlockIncrement() * e.getWheelRotation();
}
return increment;
}
public static int getIncrementFromAdjustable(Adjustable adj,
MouseWheelEvent e) {
if (log.isLoggable(PlatformLogger.Level.FINE)) {
if (adj == null) {
log.fine("Assertion (adj != null) failed");
}
}
int increment = 0;
if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
increment = e.getUnitsToScroll() * adj.getUnitIncrement();
}
else if (e.getScrollType() == MouseWheelEvent.WHEEL_BLOCK_SCROLL) {
increment = adj.getBlockIncrement() * e.getWheelRotation();
}
return increment;
}
public static int getIncrementFromAdjustable(Adjustable adj,
MouseWheelEvent e) {
if (log.isLoggable(PlatformLogger.Level.FINE)) {
if (adj == null) {
log.fine("Assertion (adj != null) failed");
}
}
int increment = 0;
if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
increment = e.getUnitsToScroll() * adj.getUnitIncrement();
}
else if (e.getScrollType() == MouseWheelEvent.WHEEL_BLOCK_SCROLL) {
increment = adj.getBlockIncrement() * e.getWheelRotation();
}
return increment;
}
static boolean doWheelScroll(XVerticalScrollbar vsb,
XHorizontalScrollbar hsb,
MouseWheelEvent e) {
XScrollbar scroll = null;
int wheelRotation;
// Determine which, if any, sb to scroll
if (vsb != null) {
scroll = vsb;
}
else if (hsb != null) {
scroll = hsb;
}
else { // Neither scrollbar is showing
return false;
}
wheelRotation = e.getWheelRotation();
// Check if scroll is necessary
if ((wheelRotation < 0 && scroll.getValue() > scroll.getMinimum()) ||
(wheelRotation > 0 && scroll.getValue() < scroll.getMaximum()) ||
wheelRotation != 0) {
int type = e.getScrollType();
int incr;
if (type == MouseWheelEvent.WHEEL_BLOCK_SCROLL) {
incr = wheelRotation * scroll.getBlockIncrement();
}
else { // type is WHEEL_UNIT_SCROLL
incr = e.getUnitsToScroll() * scroll.getUnitIncrement();
}
scroll.setValue(scroll.getValue() + incr);
return true;
}
return false;
}
@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());
}
}
static boolean doWheelScroll(XVerticalScrollbar vsb,
XHorizontalScrollbar hsb,
MouseWheelEvent e) {
XScrollbar scroll = null;
int wheelRotation;
// Determine which, if any, sb to scroll
if (vsb != null) {
scroll = vsb;
}
else if (hsb != null) {
scroll = hsb;
}
else { // Neither scrollbar is showing
return false;
}
wheelRotation = e.getWheelRotation();
// Check if scroll is necessary
if ((wheelRotation < 0 && scroll.getValue() > scroll.getMinimum()) ||
(wheelRotation > 0 && scroll.getValue() < scroll.getMaximum()) ||
wheelRotation != 0) {
int type = e.getScrollType();
int incr;
if (type == MouseWheelEvent.WHEEL_BLOCK_SCROLL) {
incr = wheelRotation * scroll.getBlockIncrement();
}
else { // type is WHEEL_UNIT_SCROLL
incr = e.getUnitsToScroll() * scroll.getUnitIncrement();
}
scroll.setValue(scroll.getValue() + incr);
return true;
}
return false;
}
static boolean doWheelScroll(XVerticalScrollbar vsb,
XHorizontalScrollbar hsb,
MouseWheelEvent e) {
XScrollbar scroll = null;
int wheelRotation;
// Determine which, if any, sb to scroll
if (vsb != null) {
scroll = vsb;
}
else if (hsb != null) {
scroll = hsb;
}
else { // Neither scrollbar is showing
return false;
}
wheelRotation = e.getWheelRotation();
// Check if scroll is necessary
if ((wheelRotation < 0 && scroll.getValue() > scroll.getMinimum()) ||
(wheelRotation > 0 && scroll.getValue() < scroll.getMaximum()) ||
wheelRotation != 0) {
int type = e.getScrollType();
int incr;
if (type == MouseWheelEvent.WHEEL_BLOCK_SCROLL) {
incr = wheelRotation * scroll.getBlockIncrement();
}
else { // type is WHEEL_UNIT_SCROLL
incr = e.getUnitsToScroll() * scroll.getUnitIncrement();
}
scroll.setValue(scroll.getValue() + incr);
return true;
}
return false;
}
private void handleInMoveMode(final MouseWheelEvent event) {
final boolean scrollDirection = event.getUnitsToScroll() > 0;
if (event.isAltDown()) {
moveVertical(scrollDirection);
} else {
moveHorizontal(scrollDirection);
}
}
private static void scroll(JScrollBar scroller, MouseWheelEvent event) {
if (event.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
int direction = event.getUnitsToScroll() < 0 ? -1 : 1;
int increment = scroller.getUnitIncrement(direction);
int amount = event.getScrollAmount();
int oldValue = scroller.getValue();
int newValue = oldValue + increment * amount * direction;
if (oldValue != newValue) scroller.setValue(newValue);
event.consume();
}
}
private static void scroll(final JScrollBar scroller, final MouseWheelEvent event) {
if (event.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
int unitsToScroll = event.getUnitsToScroll();
int direction = unitsToScroll < 0 ? -1 : 1;
if (unitsToScroll != 0) {
int increment = scroller.getUnitIncrement(direction);
int oldValue = scroller.getValue();
int newValue = oldValue + increment * unitsToScroll;
newValue = Math.max(Math.min(newValue, scroller.getMaximum() -
scroller.getVisibleAmount()), scroller.getMinimum());
if (oldValue != newValue) scroller.setValue(newValue);
}
event.consume();
}
}
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
if (User.isNull()) {
return;
}
/*
* Turning with mouse wheel. Ignore all but the first to avoid flooding
* the server with turn commands.
*/
logger.debug(e.getClickCount() + " click count and " + e.getScrollType() + " scroll type and wheel rotation " + e.getWheelRotation());
if (e.getClickCount() <= 1) {
final User user = User.get();
Direction currentDirection = user.getDirection();
Direction newDirection = null;
if (e.getUnitsToScroll() > 0) {
// Turn right
newDirection = currentDirection.nextDirection();
} else {
// Turn left
newDirection =
currentDirection.nextDirection().oppositeDirection();
}
if (newDirection != null && newDirection != currentDirection) {
final RPAction turnAction = new RPAction();
turnAction.put(TYPE, FACE);
turnAction.put(DIR, newDirection.get());
client.send(turnAction);
}
}
}
static boolean doWheelScroll(XVerticalScrollbar vsb,
XHorizontalScrollbar hsb,
MouseWheelEvent e) {
XScrollbar scroll = null;
int wheelRotation;
// Determine which, if any, sb to scroll
if (vsb != null) {
scroll = vsb;
}
else if (hsb != null) {
scroll = hsb;
}
else { // Neither scrollbar is showing
return false;
}
wheelRotation = e.getWheelRotation();
// Check if scroll is necessary
if ((wheelRotation < 0 && scroll.getValue() > scroll.getMinimum()) ||
(wheelRotation > 0 && scroll.getValue() < scroll.getMaximum()) ||
wheelRotation != 0) {
int type = e.getScrollType();
int incr;
if (type == MouseWheelEvent.WHEEL_BLOCK_SCROLL) {
incr = wheelRotation * scroll.getBlockIncrement();
}
else { // type is WHEEL_UNIT_SCROLL
incr = e.getUnitsToScroll() * scroll.getUnitIncrement();
}
scroll.setValue(scroll.getValue() + incr);
return true;
}
return false;
}
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
int units = e.getUnitsToScroll();
double zoomx = distX / 100.0 * units;
double zoomy = distY / 100.0 * units;
zoom(zoomx, zoomy);
repaint();
}
/**
* Receives notification of a mouse wheel movement and responds by moving
* the viewpoint in or out (zooming).
*
* @param mwe the mouse wheel event.
*/
@Override
public void mouseWheelMoved(MouseWheelEvent mwe) {
float units = mwe.getUnitsToScroll();
double maxViewingDistance = this.maxViewingDistanceMultiplier
* this.minViewingDistance;
double valRho = Math.max(this.minViewingDistance,
Math.min(maxViewingDistance,
this.drawable.getViewPoint().getRho() + units));
this.drawable.getViewPoint().setRho(valRho);
repaint();
}
static boolean doWheelScroll(XVerticalScrollbar vsb,
XHorizontalScrollbar hsb,
MouseWheelEvent e) {
XScrollbar scroll = null;
int wheelRotation;
// Determine which, if any, sb to scroll
if (vsb != null) {
scroll = vsb;
}
else if (hsb != null) {
scroll = hsb;
}
else { // Neither scrollbar is showing
return false;
}
wheelRotation = e.getWheelRotation();
// Check if scroll is necessary
if ((wheelRotation < 0 && scroll.getValue() > scroll.getMinimum()) ||
(wheelRotation > 0 && scroll.getValue() < scroll.getMaximum()) ||
wheelRotation != 0) {
int type = e.getScrollType();
int incr;
if (type == MouseWheelEvent.WHEEL_BLOCK_SCROLL) {
incr = wheelRotation * scroll.getBlockIncrement();
}
else { // type is WHEEL_UNIT_SCROLL
incr = e.getUnitsToScroll() * scroll.getUnitIncrement();
}
scroll.setValue(scroll.getValue() + incr);
return true;
}
return false;
}
private static void scroll(JScrollBar scrollBar, MouseWheelEvent e) {
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);
}
}
}