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

The following examples show how to use java.awt.event.MouseWheelEvent#getComponent() . 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: ChartGestureMouseAdapter.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
@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);
    GestureButton button = GestureButton.getButton(e.getButton());

    // handle event
    handleEvent(new ChartGestureEvent(chartPanel, e, entity,
        new ChartGesture(gestureEntity, Event.MOUSE_WHEEL, button)));
  }
}
 
Example 2
Source File: ChartGestureMouseAdapter.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
@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)));
  }
}
 
Example 3
Source File: ChartGestureMouseAdapter.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
@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)));
  }
}
 
Example 4
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override public void mouseWheelMoved(MouseWheelEvent e) {
  int dir = e.getWheelRotation();
  int z = zoomRange.getValue();
  zoomRange.setValue(z + EXTENT * (dir > 0 ? -1 : 1));
  if (z == zoomRange.getValue()) {
    return;
  }
  Component c = e.getComponent();
  Rectangle r = c.getBounds();
  Point2D p = new Point2D.Double(r.getCenterX(), r.getCenterY());
  Point2D p1 = transformPoint(p);
  double scale = dir > 0 ? 1 / ZOOM_MULTIPLICATION_FACTOR : ZOOM_MULTIPLICATION_FACTOR;
  coordAndZoomTransform.scale(scale, scale);
  Point2D p2 = transformPoint(p);
  coordAndZoomTransform.translate(p2.getX() - p1.getX(), p2.getY() - p1.getY());
  c.repaint();
}
 
Example 5
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override public void mouseWheelMoved(MouseWheelEvent e) {
  double dir = e.getPreciseWheelRotation();
  int z = zoomRange.getValue();
  zoomRange.setValue(z + EXTENT * (dir > 0 ? -1 : 1));
  if (z != zoomRange.getValue()) {
    Component c = e.getComponent();
    Container p = SwingUtilities.getAncestorOfClass(JViewport.class, c);
    if (p instanceof JViewport) {
      JViewport vport = (JViewport) p;
      Rectangle ovr = vport.getViewRect();
      double s = dir > 0 ? 1d / ZOOM_MULTIPLICATION_FACTOR : ZOOM_MULTIPLICATION_FACTOR;
      zoomTransform.scale(s, s);
      // double s = 1d + zoomRange.getValue() * .1;
      // zoomTransform.setToScale(s, s);
      Rectangle nvr = AffineTransform.getScaleInstance(s, s).createTransformedShape(ovr).getBounds();
      Point vp = nvr.getLocation();
      vp.translate((nvr.width - ovr.width) / 2, (nvr.height - ovr.height) / 2);
      vport.setViewPosition(vp);
      c.revalidate();
      c.repaint();
    }
  }
}
 
Example 6
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override protected void processMouseWheelEvent(MouseWheelEvent e, JLayer<? extends JScrollPane> l) {
  Component c = e.getComponent();
  int dir = e.getWheelRotation();
  JScrollPane main = l.getView();
  if (c instanceof JScrollPane && !c.equals(main)) {
    JScrollPane child = (JScrollPane) c;
    BoundedRangeModel m = child.getVerticalScrollBar().getModel();
    int extent = m.getExtent();
    int minimum = m.getMinimum();
    int maximum = m.getMaximum();
    int value = m.getValue();
    boolean b1 = dir > 0 && value + extent >= maximum;
    boolean b2 = dir < 0 && value <= minimum;
    if (b1 || b2) {
      main.dispatchEvent(SwingUtilities.convertMouseEvent(c, e, main));
    }
  }
}
 
Example 7
Source File: MouseEventUI.java    From darklaf with MIT License 5 votes vote down vote up
/**
 * Re-dispatches the event to the first component in the hierarchy that has a {@link MouseWheelListener}
 * registered.
 */
@Override
protected void processMouseWheelEvent(final MouseWheelEvent event,
                                      final JXLayer<? extends V> jxlayer) {
    /*
     * Only process an event if it is not already consumed. This may be the
     * case if this LayerUI is contained in a wrapped hierarchy.
     */
    if (!event.isConsumed()) {
        /*
         * Since we will create a new event, the argument event must be
         * consumed.
         */
        event.consume();
        /*
         * Find a target up in the hierarchy that has
         * MouseWheelEventListeners registered.
         */
        Component target = event.getComponent();
        Component newTarget = findWheelListenerComponent(target);
        if (newTarget == null) {
            newTarget = jxlayer.getParent();
        }
        /*
         * Convert the location relative to the new target
         */
        Point point = SwingUtilities.convertPoint(event.getComponent(),
                                                  event.getPoint(), newTarget);
        /*
         * Create a new event and dispatch it.
         */
        newTarget.dispatchEvent(createMouseWheelEvent(event, point,
                                                      newTarget));
    }
}
 
Example 8
Source File: VOWLWheelZoomControl.java    From ProtegeVOWL with MIT License 5 votes vote down vote up
/**
 * mouseWheelMoved is similar to mouseWheelMoved from WheelZoomControl,
 * except the zoom direction is changed. Here we use 1 - 0.1f * e.getWheelRotation()
 * while mouseWheelMoved from WheelZoomControl uses 1 + 0.1f * e.getWheelRotation()
 */
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
	Display display = (Display) e.getComponent();
	m_point.x = display.getWidth() / 2;
	m_point.y = display.getHeight() / 2;
	zoom(display, m_point, 1 - 0.1f * e.getWheelRotation(), false);
}
 
Example 9
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 10
Source File: MainPanel.java    From java-swing-tips with MIT License 4 votes vote down vote up
@Override public void mouseWheelMoved(MouseWheelEvent e) {
  JSlider s = (JSlider) e.getComponent();
  s.setValue(s.getValue() - e.getWheelRotation());
}