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

The following examples show how to use java.awt.event.MouseWheelEvent#getX() . 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: Editor.java    From brModelo with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Recebe o evento de MouseWheel do quadro de edição se não consumido.
 *
 * @param e
 */
public void ScrollMove(MouseWheelEvent e) {
    int x = parente.getHorizontalScrollBar().getValue();
    int y = parente.getVerticalScrollBar().getValue();
    int vpw = parente.getViewport().getWidth() - getMargem();
    int vph = parente.getViewport().getHeight() - getMargem();
    int p1 = e.getX() + getMargem() - x;
    int p2 = e.getY() + getMargem() - y;

    boolean ambos = (p2 > vph && p1 > vpw);

    p1 = vpw - (p1);
    p2 = vph - (p2);

    if (p1 < p2 || ambos) {
        parente.getVerticalScrollBar().setValue(y + 2 * e.getUnitsToScroll());
    }
    if (p2 < p1 || ambos) {
        parente.getHorizontalScrollBar().setValue(x + 2 * e.getUnitsToScroll());
    }
    e.consume();
}
 
Example 2
Source File: MouseHandler.java    From rscplus with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
  if (Replay.isRecording) {
    Replay.dumpMouseInput(
        Replay.MOUSE_WHEEL_MOVED,
        e.getX(),
        e.getY(),
        e.getWheelRotation(),
        e.getModifiers(),
        e.getClickCount(),
        e.getScrollType(),
        e.getScrollAmount(),
        e.isPopupTrigger(),
        0);
  }

  x = e.getX();
  y = e.getY();
  Camera.addZoom(e.getWheelRotation() * 16);
}
 
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: WidgetAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a mouse wheel event.
 * @param id the event id
 * @param event the Swing event
 */
public WidgetMouseWheelEvent(long id, MouseWheelEvent event) {
    this.id = id;
    this.event = event;
    x = event.getX ();
    y = event.getY ();
}
 
Example 7
Source File: UIUtilities.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Clones a {@link MouseEvent}.
 *
 * @param event The event to clone.
 * @return The new {@link MouseEvent}.
 */
public static final MouseEvent cloneMouseEvent(MouseEvent event) {
    if (event instanceof MouseWheelEvent) {
        MouseWheelEvent old = (MouseWheelEvent) event;
        return new MouseWheelEvent((Component) old.getSource(), old.getID(), System.currentTimeMillis(), old.getModifiersEx(), old.getX(), old.getY(), old.getClickCount(), old.isPopupTrigger(), old.getScrollType(), old.getScrollAmount(), old.getWheelRotation());
    }
    return new MouseEvent((Component) event.getSource(), event.getID(), System.currentTimeMillis(), event.getModifiersEx(), event.getX(), event.getY(), event.getClickCount(), event.isPopupTrigger());
}
 
Example 8
Source File: UIUtilities.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Clones a {@link MouseEvent}.
 *
 * @param event       The event to clone.
 * @param refreshTime Pass in {@code true} to generate a new time stamp.
 * @return The new {@link MouseEvent}.
 */
public static final MouseEvent cloneMouseEvent(MouseEvent event, boolean refreshTime) {
    if (event instanceof MouseWheelEvent) {
        MouseWheelEvent old = (MouseWheelEvent) event;
        return new MouseWheelEvent((Component) old.getSource(), old.getID(), refreshTime ? System.currentTimeMillis() : event.getWhen(), old.getModifiersEx(), old.getX(), old.getY(), old.getClickCount(), old.isPopupTrigger(), old.getScrollType(), old.getScrollAmount(), old.getWheelRotation());
    }
    return new MouseEvent((Component) event.getSource(), event.getID(), refreshTime ? System.currentTimeMillis() : event.getWhen(), event.getModifiersEx(), event.getX(), event.getY(), event.getClickCount(), event.isPopupTrigger());
}
 
Example 9
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 10
Source File: Display.java    From osm-lib with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
    int x = e.getX();
    int y = e.getY();
    // TODO metersPerPixel *= (1 + (0.1 * e.getWheelRotation()));
    double scale = 1 + (0.05 * e.getWheelRotation());
    wgsWindow.setRect(wgsWindow.getX(), wgsWindow.getY(),
            wgsWindow.getWidth() * scale, wgsWindow.getHeight() * scale);
    repaint();
}
 
Example 11
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 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: AgeByDelta234UPlotPanel.java    From ET_Redux with Apache License 2.0 4 votes vote down vote up
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
    if (mouseInHouse(e)) {

        zoomMaxX = e.getX();
        zoomMaxY = e.getY();

        // https://java.com/en/download/faq/release_changes.xml
        double notches = e.getPreciseWheelRotation();
        if (true) {//(notches == Math.rint(notches)) {
            if (notches < 0) {// zoom in
                if (zoomCount >= 0) {
                    minX += getRangeX_Display() / ZOOM_FACTOR;
                }
                maxX -= getRangeX_Display() / ZOOM_FACTOR;
                if (zoomCount >= 0) {
                    minY += getRangeY_Display() / ZOOM_FACTOR;
                }
                maxY -= getRangeY_Display() / ZOOM_FACTOR;

                zoomCount++;

            } else {// zoom out
                minX -= getRangeX_Display() / ZOOM_FACTOR;
                minX = Math.max(minX, 0.0);

                minY -= getRangeY_Display() / ZOOM_FACTOR;
                minY = Math.max(minY, 0.0);

                zoomCount--;
                // stop zoom out
                if (minX * minY > 0.0) {
                    maxX += getRangeX_Display() / ZOOM_FACTOR;
                    maxY += getRangeY_Display() / ZOOM_FACTOR;
                    zoomCount = 0;

                } else {
                    minX = 0.0;
                    minY = 0.0;

                    maxX += getRangeX_Display() / ZOOM_FACTOR;
                    maxY += getRangeY_Display() / ZOOM_FACTOR;
                }

            }
            if (minX <= 0.0) {
                minX = 0.0;
                displayOffsetX = 0.0;

            }
            if (minY <= 0.0) {
                minY = 0.0;
                displayOffsetY = 0.0;
            }

            zoomMinX = zoomMaxX;
            zoomMinY = zoomMaxY;

            ticsYaxis = TicGeneratorForAxes.generateTics(getMinY_Display(), getMaxY_Display(), 10);
            ticsXaxis = TicGeneratorForAxes.generateTics(getMinX_Display(), getMaxX_Display(), 10);

            repaint();
        }
    }
}
 
Example 14
Source File: EvolutionPlotPanel.java    From ET_Redux with Apache License 2.0 4 votes vote down vote up
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
    if (mouseInHouse(e)) {

        zoomMaxX = e.getX();
        zoomMaxY = e.getY();

        // https://java.com/en/download/faq/release_changes.xml
        double notches = e.getPreciseWheelRotation();
        if (true) {//(notches == Math.rint(notches)) {
            if (notches < 0) {// zoom in
                minX += getRangeX_Display() / ZOOM_FACTOR;
                maxX -= getRangeX_Display() / ZOOM_FACTOR;
                minY += getRangeY_Display() / ZOOM_FACTOR;
                maxY -= getRangeY_Display() / ZOOM_FACTOR;

                zoomCount++;

            } else {// zoom out
                minX -= getRangeX_Display() / ZOOM_FACTOR;
                minX = Math.max(minX, 0.0);

                minY -= getRangeY_Display() / ZOOM_FACTOR;
                minY = Math.max(minY, 0.0);

                zoomCount--;
                // stop zoom out
                if (minX * minY > 0.0) {
                    maxX += getRangeX_Display() / ZOOM_FACTOR;
                    maxY += getRangeY_Display() / ZOOM_FACTOR;

                } else {
                    minX = 0.0;
                    maxX = xAxisMax;
                    minY = 0.0;
                    maxY = yAxisMax;
                    zoomCount = 0;
                }
            }

            if (minX <= 0.0) {
                minX = 0.0;
                displayOffsetX = 0.0;
            }
            if (minY <= 0.0) {
                minY = 0.0;
                displayOffsetY = 0.0;
            }

            zoomMinX = zoomMaxX;
            zoomMinY = zoomMaxY;

            buildIsochronsAndInitDelta234UContours();
            generateCustomTics();
            repaint();
        }
    }
}