类java.awt.event.MouseWheelEvent源码实例Demo

下面列出了怎么用java.awt.event.MouseWheelEvent的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: openstock   文件: MouseWheelHandler.java
/**
 * Handles a mouse wheel event from the underlying chart panel.
 *
 * @param e  the event.
 */
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
    JFreeChart chart = this.chartPanel.getChart();
    if (chart == null) {
        return;
    }
    Plot plot = chart.getPlot();
    if (plot instanceof Zoomable) {
        Zoomable zoomable = (Zoomable) plot;
        handleZoomable(zoomable, e);
    }
    else if (plot instanceof PiePlot) {
        PiePlot pp = (PiePlot) plot;
        pp.handleMouseWheelRotation(e.getWheelRotation());
    }
}
 
源代码2 项目: CQL   文件: GuiUtil.java
public void mouseWheelMoved(MouseWheelEvent e) {
	JScrollPane parent = getParentScrollPane();
	if (parent != null) {
		/*
		 * Only dispatch if we have reached top/bottom on previous scroll
		 */
		if (e.getWheelRotation() < 0) {
			if (bar.getValue() == 0 && previousValue == 0) {
				parent.dispatchEvent(cloneEvent(e));
			}
		} else {
			if (bar.getValue() == getMax() && previousValue == getMax()) {
				parent.dispatchEvent(cloneEvent(e));
			}
		}
		previousValue = bar.getValue();
	}
	/*
	 * If parent scrollpane doesn't exist, remove this as a listener. We have to
	 * defer this till now (vs doing it in constructor) because in the constructor
	 * this item has no parent yet.
	 */
	else {
		PDControlScrollPane.this.removeMouseWheelListener(this);
	}
}
 
源代码3 项目: openAGV   文件: ViewDragScrollListener.java
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
  if (e.isControlDown()) {
    int zoomLevel = zoomComboBox.getSelectedIndex();
    int notches = e.getWheelRotation();
    if (zoomLevel != -1) {
      if (notches < 0) {
        if (zoomLevel > 0) {
          zoomLevel--;
          zoomComboBox.setSelectedIndex(zoomLevel);
        }
      }
      else {
        if (zoomLevel < zoomComboBox.getItemCount() - 1) {
          zoomLevel++;
          zoomComboBox.setSelectedIndex(zoomLevel);
        }
      }
    }
  }
}
 
源代码4 项目: AMIDST   文件: MapViewer.java
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
	int notches = e.getWheelRotation();
	Point mouse = e.getPoint(); // Don't use getMousePosition() because when computer is swapping/grinding, mouse may have moved out of window before execution reaches here.
	for (Widget widget : widgets) {
		if ((widget.isVisible()) &&
			(mouse.x > widget.getX()) &&
			(mouse.y > widget.getY()) &&
			(mouse.x < widget.getX() + widget.getWidth()) &&
			(mouse.y < widget.getY() + widget.getHeight())) {
			if (widget.onMouseWheelMoved(mouse.x - widget.getX(), mouse.y - widget.getY(), notches))
				return;
		}
	}
	adjustZoom(getMousePosition(), notches);
}
 
源代码5 项目: zap-extensions   文件: JScrollPopupMenu.java
public JScrollPopupMenu(String label) {
    super(label);
    setLayout(new ScrollPopupMenuLayout());

    super.add(getScrollBar());
    addMouseWheelListener(new MouseWheelListener() {
        @Override public void mouseWheelMoved(MouseWheelEvent event) {
            JScrollBar scrollBar = getScrollBar();
            int amount = (event.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL)
                         ? event.getUnitsToScroll() * scrollBar.getUnitIncrement()
                         : (event.getWheelRotation() < 0 ? -1 : 1) * scrollBar.getBlockIncrement();

            scrollBar.setValue(scrollBar.getValue() + amount);
            event.consume();
        }
    });
}
 
源代码6 项目: Course_Generator   文件: CgSpinner.java
public CgSpinner(int start, int min, int max, int step) {
	super();
	this.min = min;
	this.max = max;
	this.step = step;

	model = new SpinnerNumberModel(start, // initial value
			min, // min
			max, // max
			step); // step
	setModel(model);

	addMouseWheelListener(new MouseWheelListener() {
		public void mouseWheelMoved(MouseWheelEvent mwe) {
			MouseWheelAction(mwe.getWheelRotation());
		}
	});

	// Center
	JSpinner.DefaultEditor spinnerEditor = (JSpinner.DefaultEditor) this.getEditor();
	spinnerEditor.getTextField().setHorizontalAlignment(JTextField.CENTER);
}
 
源代码7 项目: openjdk-jdk9   文件: ScrollPaneWheelScroller.java
public static void handleWheelScrolling(ScrollPane sp, MouseWheelEvent e) {
    if (log.isLoggable(PlatformLogger.Level.FINER)) {
        log.finer("x = " + e.getX() + ", y = " + e.getY() + ", src is " + e.getSource());
    }
    int increment = 0;

    if (sp != null && e.getScrollAmount() != 0) {
        Adjustable adj = getAdjustableToScroll(sp);
        if (adj != null) {
            increment = getIncrementFromAdjustable(adj, e);
            if (log.isLoggable(PlatformLogger.Level.FINER)) {
                log.finer("increment from adjustable(" + adj.getClass() + ") : " + increment);
            }
            scrollAdjustable(adj, increment);
        }
    }
}
 
源代码8 项目: Spade   文件: PaintCanvas.java
@Override
public void mouseWheelMoved(MouseWheelEvent e)
{
	int sign = e.getWheelRotation();
	
	if(sign < 0)
	{
		this.cam_zoom_increase();
		return;
	}
	
	if(sign > 0)
	{
		this.cam_zoom_decrease();
		return;
	}
}
 
源代码9 项目: scelight   文件: MapCanvas.java
/**
 * Creates a new {@link MapCanvas}.
 * 
 * @param repProc replay processor
 * @param zoomComboBox combo box which tells how to zoom the map image
 */
public MapCanvas( final RepProcessor repProc, final XComboBox< Zoom > zoomComboBox ) {
	this.repProc = repProc;
	this.zoomComboBox = zoomComboBox;
	
	ricon = MapImageCache.getMapImage( repProc );
	
	GuiUtils.makeComponentDragScrollable( this );
	
	// Zoom in and out with CTRL+wheel scroll:
	addMouseWheelListener( new MouseWheelListener() {
		@Override
		public void mouseWheelMoved( final MouseWheelEvent event ) {
			if ( event.isControlDown() ) {
				final int newZoomIdx = zoomComboBox.getSelectedIndex() - event.getWheelRotation();
				zoomComboBox.setSelectedIndex( Math.max( 0, Math.min( zoomComboBox.getItemCount() - 1, newZoomIdx ) ) );
				// An event will be fired which will cause reconfigureZoom() to be called...
			}
		}
	} );
}
 
源代码10 项目: jdk8u-jdk   文件: bug7170657.java
public static void main(final String[] args) {
    final int mask = InputEvent.META_DOWN_MASK | InputEvent.CTRL_MASK;

    Frame f = new Frame();

    MouseEvent mwe = new MouseWheelEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true,
                                         1, 1, 1);
    MouseEvent mdme = new MenuDragMouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1,
                                             true, null, null);
    MouseEvent me = new MouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true,
                                   MouseEvent.NOBUTTON);

    test(f, mwe);
    test(f, mdme);
    test(f, me);

    if (FAILED) {
        throw new RuntimeException("Wrong mouse event");
    }
}
 
源代码11 项目: dragonwell8_jdk   文件: bug7170657.java
public static void main(final String[] args) {
    final int mask = InputEvent.META_DOWN_MASK | InputEvent.CTRL_MASK;

    Frame f = new Frame();

    MouseEvent mwe = new MouseWheelEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true,
                                         1, 1, 1);
    MouseEvent mdme = new MenuDragMouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1,
                                             true, null, null);
    MouseEvent me = new MouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true,
                                   MouseEvent.NOBUTTON);

    test(f, mwe);
    test(f, mdme);
    test(f, me);

    if (FAILED) {
        throw new RuntimeException("Wrong mouse event");
    }
}
 
源代码12 项目: Cafebabe   文件: CFGraph.java
public CFGComponent(mxGraph g) {
	super(g);
	this.getViewport().setBackground(Color.WHITE);
	this.setEnabled(false);
	this.setBorder(new EmptyBorder(0, 0, 0, 0));
	this.setZoomFactor(1.1);
	this.getGraphControl().addMouseWheelListener(new MouseWheelListener() {
		@Override
		public void mouseWheelMoved(MouseWheelEvent e) {
			if (e.isControlDown()) {
				if (e.getWheelRotation() < 0) {
					zoomIn();
				} else {
					zoomOut();
				}
				repaint();
				revalidate();
			} else if (scp != null) {
				// do we need this on linux too?
				scp.getVerticalScrollBar().setValue(scp.getVerticalScrollBar().getValue()
						+ e.getUnitsToScroll() * scp.getVerticalScrollBar().getUnitIncrement());
			}
		}
	});
}
 
源代码13 项目: ECG-Viewer   文件: MouseWheelHandler.java
/**
 * Handles a mouse wheel event from the underlying chart panel.
 *
 * @param e  the event.
 */
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
    JFreeChart chart = this.chartPanel.getChart();
    if (chart == null) {
        return;
    }
    Plot plot = chart.getPlot();
    if (plot instanceof Zoomable) {
        Zoomable zoomable = (Zoomable) plot;
        handleZoomable(zoomable, e);
    }
    else if (plot instanceof PiePlot) {
        PiePlot pp = (PiePlot) plot;
        pp.handleMouseWheelRotation(e.getWheelRotation());
    }
}
 
源代码14 项目: TencentKona-8   文件: bug7170657.java
public static void main(final String[] args) {
    final int mask = InputEvent.META_DOWN_MASK | InputEvent.CTRL_MASK;

    Frame f = new Frame();

    MouseEvent mwe = new MouseWheelEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true,
                                         1, 1, 1);
    MouseEvent mdme = new MenuDragMouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1,
                                             true, null, null);
    MouseEvent me = new MouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true,
                                   MouseEvent.NOBUTTON);

    test(f, mwe);
    test(f, mdme);
    test(f, me);

    if (FAILED) {
        throw new RuntimeException("Wrong mouse event");
    }
}
 
源代码15 项目: jdk8u60   文件: ScrollPaneWheelScroller.java
public static void handleWheelScrolling(ScrollPane sp, MouseWheelEvent e) {
    if (log.isLoggable(PlatformLogger.Level.FINER)) {
        log.finer("x = " + e.getX() + ", y = " + e.getY() + ", src is " + e.getSource());
    }
    int increment = 0;

    if (sp != null && e.getScrollAmount() != 0) {
        Adjustable adj = getAdjustableToScroll(sp);
        if (adj != null) {
            increment = getIncrementFromAdjustable(adj, e);
            if (log.isLoggable(PlatformLogger.Level.FINER)) {
                log.finer("increment from adjustable(" + adj.getClass() + ") : " + increment);
            }
            scrollAdjustable(adj, increment);
        }
    }
}
 
源代码16 项目: jdk8u60   文件: ScrollPaneWheelScroller.java
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;
}
 
源代码17 项目: mzmine2   文件: ChartGestureMouseAdapter.java
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
  if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.MOUSE_WHEEL))
    return;

  if (e.getComponent() instanceof ChartPanel) {
    ChartPanel chartPanel = (ChartPanel) e.getComponent();
    ChartEntity entity = findChartEntity(chartPanel, e);
    ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity);
    Button button = Button.getButton(e.getButton());

    // handle event
    handleEvent(new ChartGestureEvent(chartPanel, e, entity,
        new ChartGesture(gestureEntity, Event.MOUSE_WHEEL, button)));
  }
}
 
源代码18 项目: Ngram-Graphs   文件: NavigableImagePanel.java
public void mouseWheelMoved(MouseWheelEvent e) {
	Point p = e.getPoint();
	boolean zoomIn = (e.getWheelRotation() < 0);
	if (isInNavigationImage(p)) {
		if (zoomIn) {
			navZoomFactor = 1.0 + zoomIncrement;
		} else {
			navZoomFactor = 1.0 - zoomIncrement;
		}
		zoomNavigationImage();
	} else if (isInImage(p)) {
		if (zoomIn) {
			zoomFactor = 1.0 + zoomIncrement;
		} else {
			zoomFactor = 1.0 - zoomIncrement;
		}
		zoomImage();
	}
}
 
源代码19 项目: radiance   文件: JCarosel.java
/**
 * When event received will spin the carousel to select the next object.
 * Because the wheel can be spun quicker than the carousel animates it keeps
 * track of the target (so the user may have selected something three
 * components away, althought the animation has not yet finished moving past
 * the first comopnent)
 * 
 * @param mouseWheelEvent
 *            The event object
 */
public void mouseWheelMoved(MouseWheelEvent mouseWheelEvent) {

	if (mouseWheelEvent.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
		int amount = mouseWheelEvent.getWheelRotation();
		if (lastWheeledTo == null) {
			lastWheeledTo = getFrontmost();
		}
		int lastPosition = layout.getComponentIndex(lastWheeledTo);
		int frontMostPosition = layout.getComponentIndex(getComponent(0));
		// Don't over spin
		if (Math.abs(lastPosition - frontMostPosition) > layout
				.getComponentCount() / 4) {
			return;
		}
		if (amount > 0) {
			lastWheeledTo = layout.getPreviousComponent(lastWheeledTo);
		} else {
			lastWheeledTo = layout.getNextComponent(lastWheeledTo);
		}
		bringToFront(lastWheeledTo);
	}
}
 
源代码20 项目: filthy-rich-clients   文件: EquationDisplay.java
public void mouseWheelMoved(MouseWheelEvent e) {
    double distanceX = maxX - minX;
    double distanceY = maxY - minY;
    
    double cursorX = minX + distanceX / 2.0;
    double cursorY = minY + distanceY / 2.0;
    
    int rotation = e.getWheelRotation();
    if (rotation < 0) {
        distanceX /= COEFF_ZOOM;
        distanceY /= COEFF_ZOOM;
    } else {
        distanceX *= COEFF_ZOOM;
        distanceY *= COEFF_ZOOM;
    }
    
    minX = cursorX - distanceX / 2.0;
    maxX = cursorX + distanceX / 2.0;
    minY = cursorY - distanceY / 2.0;
    maxY = cursorY + distanceY / 2.0;

    repaint();
}
 
源代码21 项目: jdk8u-jdk   文件: CPlatformResponder.java
private void dispatchScrollEvent(final int x, final int y,
                                 final int modifiers, final double delta) {
    final long when = System.currentTimeMillis();
    final int scrollType = MouseWheelEvent.WHEEL_UNIT_SCROLL;
    final int scrollAmount = 1;
    int wheelRotation = (int) delta;
    int signum = (int) Math.signum(delta);
    if (signum * delta < 1) {
        wheelRotation = signum;
    }
    // invert the wheelRotation for the peer
    eventNotifier.notifyMouseWheelEvent(when, x, y, modifiers, scrollType,
            scrollAmount, -wheelRotation, -delta, null);
}
 
源代码22 项目: 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());
    }
}
 
源代码23 项目: stendhal   文件: GroundContainer.java
@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);
		}
	}
}
 
源代码24 项目: jdk8u-jdk   文件: LWScrollPanePeer.java
@Override
public void handleEvent(AWTEvent e) {
    if (e instanceof MouseWheelEvent) {
        MouseWheelEvent wheelEvent = (MouseWheelEvent) e;
        //java.awt.ScrollPane consumes the event
        // in case isWheelScrollingEnabled() is true,
        // forcibly send the consumed event to the delegate
        if (getTarget().isWheelScrollingEnabled() && wheelEvent.isConsumed()) {
            sendEventToDelegate(wheelEvent);
        }
    } else {
        super.handleEvent(e);
    }
}
 
源代码25 项目: constellation   文件: HistogramDisplay.java
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
    final JViewport scrollpane = (JViewport) getParent();
    final Point pos = scrollpane.getViewPosition();
    final int y;
    final int SCROLL_HEIGHT = 50;
    if (e.getWheelRotation() < 0) {
        y = pos.y - (e.getScrollAmount() * SCROLL_HEIGHT);
    } else {
        y = pos.y + (e.getScrollAmount() * SCROLL_HEIGHT);
    }

    scrollpane.setViewPosition(new Point(0, Math.max(0, y)));
}
 
源代码26 项目: openstock   文件: MouseWheelHandler.java
/**
 * Handle the case where a plot implements the {@link Zoomable} interface.
 *
 * @param zoomable  the zoomable plot.
 * @param e  the mouse wheel event.
 */
private void handleZoomable(Zoomable zoomable, MouseWheelEvent e) {
    // don't zoom unless the mouse pointer is in the plot's data area
    ChartRenderingInfo info = this.chartPanel.getChartRenderingInfo();
    PlotRenderingInfo pinfo = info.getPlotInfo();
    Point2D p = this.chartPanel.translateScreenToJava2D(e.getPoint());
    if (!pinfo.getDataArea().contains(p)) {
        return;
    }

    Plot plot = (Plot) zoomable;
    // do not notify while zooming each axis
    boolean notifyState = plot.isNotify();
    plot.setNotify(false);
    int clicks = e.getWheelRotation();
    double zf = 1.0 + this.zoomFactor;
    if (clicks < 0) {
        zf = 1.0 / zf;
    }
    if (chartPanel.isDomainZoomable()) {
        zoomable.zoomDomainAxes(zf, pinfo, p, true);
    }
    if (chartPanel.isRangeZoomable()) {
        zoomable.zoomRangeAxes(zf, pinfo, p, true);
    }
    plot.setNotify(notifyState);  // this generates the change event too
}
 
源代码27 项目: openjdk-8   文件: WComponentPeer.java
@SuppressWarnings("fallthrough")
public void handleEvent(AWTEvent e) {
    int id = e.getID();

    if ((e instanceof InputEvent) && !((InputEvent)e).isConsumed() &&
        ((Component)target).isEnabled())
    {
        if (e instanceof MouseEvent && !(e instanceof MouseWheelEvent)) {
            handleJavaMouseEvent((MouseEvent) e);
        } else if (e instanceof KeyEvent) {
            if (handleJavaKeyEvent((KeyEvent)e)) {
                return;
            }
        }
    }

    switch(id) {
        case PaintEvent.PAINT:
            // Got native painting
            paintPending = false;
            // Fallthrough to next statement
        case PaintEvent.UPDATE:
            // Skip all painting while layouting and all UPDATEs
            // while waiting for native paint
            if (!isLayouting && ! paintPending) {
                paintArea.paint(target,shouldClearRectBeforePaint());
            }
            return;
        case FocusEvent.FOCUS_LOST:
        case FocusEvent.FOCUS_GAINED:
            handleJavaFocusEvent((FocusEvent)e);
        default:
        break;
    }

    // Call the native code
    nativeHandleEvent(e);
}
 
源代码28 项目: pumpernickel   文件: JEyeDropper.java
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
	if (e.getWheelRotation() < 0) {
		getZoomInAction().actionPerformed(
				new ActionEvent(ContentButton.this, 0,
						ACTION_MAP_KEY_ZOOM_IN));
	} else if (e.getWheelRotation() > 0) {
		getZoomOutAction().actionPerformed(
				new ActionEvent(ContentButton.this, 0,
						ACTION_MAP_KEY_ZOOM_OUT));
	}
}
 
源代码29 项目: buffer_bci   文件: MouseWheelHandler.java
/**
 * Handle the case where a plot implements the {@link Zoomable} interface.
 *
 * @param zoomable  the zoomable plot.
 * @param e  the mouse wheel event.
 */
private void handleZoomable(Zoomable zoomable, MouseWheelEvent e) {
    // don't zoom unless the mouse pointer is in the plot's data area
    ChartRenderingInfo info = this.chartPanel.getChartRenderingInfo();
    PlotRenderingInfo pinfo = info.getPlotInfo();
    Point2D p = this.chartPanel.translateScreenToJava2D(e.getPoint());
    if (!pinfo.getDataArea().contains(p)) {
        return;
    }

    Plot plot = (Plot) zoomable;
    // do not notify while zooming each axis
    boolean notifyState = plot.isNotify();
    plot.setNotify(false);
    int clicks = e.getWheelRotation();
    double zf = 1.0 + this.zoomFactor;
    if (clicks < 0) {
        zf = 1.0 / zf;
    }
    if (chartPanel.isDomainZoomable()) {
        zoomable.zoomDomainAxes(zf, pinfo, p, true);
    }
    if (chartPanel.isRangeZoomable()) {
        zoomable.zoomRangeAxes(zf, pinfo, p, true);
    }
    plot.setNotify(notifyState);  // this generates the change event too
}
 
源代码30 项目: zxpoly   文件: MainFrame.java
private void mainEditorPanelMouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
  if (this.selectAreaMode) {
    this.selectAreaMode = false;
    this.mainEditor.resetSelectArea();
  } else if (evt.getModifiersEx() == MouseWheelEvent.CTRL_DOWN_MASK) {
    if (evt.getWheelRotation() < 0) {
      this.mainEditor.zoomIn();
    } else {
      this.mainEditor.zoomOut();
    }
  }
  updateBottomBar();
}
 
 类所在包