Example usage for java.awt Cursor MOVE_CURSOR

List of usage examples for java.awt Cursor MOVE_CURSOR

Introduction

In this page you can find the example usage for java.awt Cursor MOVE_CURSOR.

Prototype

int MOVE_CURSOR

To view the source code for java.awt Cursor MOVE_CURSOR.

Click Source Link

Document

The move cursor type.

Usage

From source file:org.gumtree.vis.awt.JChartPanel.java

@Override
public void mousePressed(MouseEvent e) {
    if (selectedTextWrapper != null && getCursor() == Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)) {
        Point2D screenXY = ChartMaskingUtilities.translateChartPoint(
                new Point2D.Double(selectedTextWrapper.getMinX(), selectedTextWrapper.getMinY()),
                getScreenDataArea(), getChart());
        Rectangle2D screenRect = new Rectangle2D.Double(screenXY.getX(), screenXY.getY() - 15,
                selectedTextWrapper.getWidth(), selectedTextWrapper.getHeight());
        if (screenRect.contains(e.getX(), e.getY())) {

            double screenX = ChartMaskingUtilities.translateScreenX(e.getX() / getScaleX(), getScreenDataArea(),
                    getChart());//from  www . j  a v  a2s  .  c  o  m
            double screenY = ChartMaskingUtilities.translateScreenY(e.getY(), getScreenDataArea(), getChart(),
                    0);
            //         Point2D point = translateScreenToChart(translateScreenToJava2D(e.getPoint()));
            Point2D point = new Point2D.Double(screenX, screenY);
            if (point != null) {
                this.textMovePoint = point;
            }
        } else {
            this.textMovePoint = null;
        }
    } else {
        super.mousePressed(e);
    }
}

From source file:org.gumtree.vis.plot1d.Plot1DPanel.java

protected int findCursorOnSelectedItem(int x, int y) {
    if (isInternalLegendEnabled && isInternalLegendSelected) {
        Rectangle2D screenArea = getScreenDataArea();
        Rectangle2D legendArea = new Rectangle2D.Double(screenArea.getMaxX() - internalLegendSetup.getMinX(),
                screenArea.getMinY() + internalLegendSetup.getMinY(), internalLegendSetup.getWidth(),
                internalLegendSetup.getHeight());
        Rectangle2D intersect = screenArea.createIntersection(legendArea);
        Point2D point = new Point2D.Double(x, y);
        double minX = legendArea.getMinX();
        double maxX = legendArea.getMaxX();
        double minY = legendArea.getMinY();
        double width = legendArea.getWidth();
        double height = legendArea.getHeight();
        if (!intersect.isEmpty() && screenArea.contains(point)) {
            if (width > 8) {
                Rectangle2D center = new Rectangle2D.Double(minX + 4, minY, width - 8, height);
                if (screenArea.createIntersection(center).contains(point)) {
                    return Cursor.MOVE_CURSOR;
                }// w  w w . j  a va 2s . com
            }
            Rectangle2D west = new Rectangle2D.Double(minX - 4, minY, width < 8 ? width / 2 + 4 : 8, height);
            if (screenArea.createIntersection(west).contains(point)) {
                return Cursor.W_RESIZE_CURSOR;
            }
            Rectangle2D east = new Rectangle2D.Double(maxX - (width < 8 ? width / 2 : 4), minY,
                    width < 8 ? width / 2 + 4 : 8, height);
            if (screenArea.createIntersection(east).contains(point)) {
                return Cursor.E_RESIZE_CURSOR;
            }
        }
    } else if (getSelectedMask() != null && !getSelectedMask().isEmpty()) {
        Rectangle2D screenArea = getScreenDataArea();
        Rectangle2D maskArea = ChartMaskingUtilities.getDomainMaskFrame(getSelectedMask(), getScreenDataArea(),
                getChart());
        Rectangle2D intersect = screenArea.createIntersection(maskArea);
        Point2D point = new Point2D.Double(x, y);
        double minX = maskArea.getMinX();
        double maxX = maskArea.getMaxX();
        double minY = maskArea.getMinY();
        double width = maskArea.getWidth();
        double height = maskArea.getHeight();
        if (!intersect.isEmpty() && screenArea.contains(point)) {
            if (width > 8) {
                Rectangle2D center = new Rectangle2D.Double(minX + 4, minY, width - 8, height);
                if (screenArea.createIntersection(center).contains(point)) {
                    return Cursor.MOVE_CURSOR;
                }
            }
            Rectangle2D west = new Rectangle2D.Double(minX - 4, minY, width < 8 ? width / 2 + 4 : 8, height);
            if (screenArea.createIntersection(west).contains(point)) {
                return Cursor.W_RESIZE_CURSOR;
            }
            Rectangle2D east = new Rectangle2D.Double(maxX - (width < 8 ? width / 2 : 4), minY,
                    width < 8 ? width / 2 + 4 : 8, height);
            if (screenArea.createIntersection(east).contains(point)) {
                return Cursor.E_RESIZE_CURSOR;
            }
        }
    }
    return Cursor.DEFAULT_CURSOR;
}

From source file:org.gumtree.vis.plot1d.Plot1DPanel.java

private void changeSelectedMask(double point) {
    switch (getMaskDragIndicator()) {
    case Cursor.MOVE_CURSOR:
        moveMask(point);//w w w.ja va2 s.  c o  m
        break;
    case Cursor.W_RESIZE_CURSOR:
        if (((XYPlot) getChart().getPlot()).getDomainAxis().isInverted()) {
            changeMaskXMax(point);
        } else {
            changeMaskXMin(point);
        }
        break;
    case Cursor.E_RESIZE_CURSOR:
        if (((XYPlot) getChart().getPlot()).getDomainAxis().isInverted()) {
            changeMaskXMin(point);
        } else {
            changeMaskXMax(point);
        }
        break;
    default:
        break;
    }
}

From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java

/**
 * Handles a 'mouse pressed' event.//from  w  ww  . ja  v  a 2 s  .c o  m
 * <P>
 * This event is the popup trigger on Unix/Linux. For Windows, the popup trigger is the 'mouse
 * released' event.
 * 
 * @param e
 *            The mouse event.
 */

@Override
public void mousePressed(MouseEvent e) {
    if (this.chart == null) {
        return;
    }
    Plot plot = this.chart.getPlot();
    int mods = e.getModifiers();
    if ((mods & this.panMask) == this.panMask) {
        // can we pan this plot?
        if (plot instanceof Pannable) {
            Rectangle2D screenDataArea = getScreenDataArea(e.getX(), e.getY());
            if (screenDataArea != null && screenDataArea.contains(e.getPoint())) {
                this.panW = screenDataArea.getWidth();
                this.panH = screenDataArea.getHeight();
                this.panLast = e.getPoint();
                setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
            }
        }
    } else if (this.selectionRectangle == null) {
        Rectangle2D screenDataArea = getScreenDataArea(e.getX(), e.getY());
        if (screenDataArea != null) {
            this.zoomPoint = getPointInRectangle(e.getX(), e.getY(), screenDataArea);
        } else {
            this.zoomPoint = null;
        }
        if (e.isPopupTrigger()) {
            if (this.popup != null) {
                displayPopupMenu(e.getX(), e.getY());
            }
        }
    }
}

From source file:ExText.java

/**
 * Responds to a button2 event (press, release, or drag). On a press, the
 * method records the initial cursor location. On a drag, the difference
 * between the current and previous cursor location provides a delta that
 * controls the amount by which to rotate in X and Y.
 * /*from  ww  w  .  ja  v  a  2 s .  co  m*/
 * @param mouseEvent
 *            the MouseEvent to respond to
 */
public void onButton2(MouseEvent mev) {
    if (subjectTransformGroup == null)
        return;

    int x = mev.getX();
    int y = mev.getY();

    if (mev.getID() == MouseEvent.MOUSE_PRESSED) {
        // Mouse button pressed: record position
        previousX = x;
        previousY = y;
        initialX = x;
        initialY = y;

        // Change to a "rotate" cursor
        if (parentComponent != null) {
            savedCursor = parentComponent.getCursor();
            parentComponent.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
        }
        return;
    }
    if (mev.getID() == MouseEvent.MOUSE_RELEASED) {
        // Mouse button released: do nothing

        // Switch the cursor back
        if (parentComponent != null)
            parentComponent.setCursor(savedCursor);
        return;
    }

    //
    // Mouse moved while button down: create a rotation
    //
    // Compute the delta in X and Y from the previous
    // position. Use the delta to compute rotation
    // angles with the mapping:
    //
    //   positive X mouse delta --> negative Y-axis rotation
    //   positive Y mouse delta --> negative X-axis rotation
    //
    // where positive X mouse movement is to the right, and
    // positive Y mouse movement is **down** the screen.
    //
    int deltaX = x - previousX;
    int deltaY = 0;

    if (Math.abs(y - initialY) > DELTAY_DEADZONE) {
        // Cursor has moved far enough vertically to consider
        // it intentional, so get it's delta.
        deltaY = y - previousY;
    }

    if (deltaX > UNUSUAL_XDELTA || deltaX < -UNUSUAL_XDELTA || deltaY > UNUSUAL_YDELTA
            || deltaY < -UNUSUAL_YDELTA) {
        // Deltas are too huge to be believable. Probably a glitch.
        // Don't record the new XY location, or do anything.
        return;
    }

    double xRotationAngle = -deltaY * XRotationFactor;
    double yRotationAngle = -deltaX * YRotationFactor;

    //
    // Build transforms
    //
    transform1.rotX(xRotationAngle);
    transform2.rotY(yRotationAngle);

    // Get and save the current transform matrix
    subjectTransformGroup.getTransform(currentTransform);
    currentTransform.get(matrix);
    translate.set(matrix.m03, matrix.m13, matrix.m23);

    // Translate to the origin, rotate, then translate back
    currentTransform.setTranslation(origin);
    currentTransform.mul(transform2, currentTransform);
    currentTransform.mul(transform1);
    currentTransform.setTranslation(translate);

    // Update the transform group
    subjectTransformGroup.setTransform(currentTransform);

    previousX = x;
    previousY = y;
}

From source file:org.gumtree.vis.awt.JChartPanel.java

private void selectText(double xNew, double yNew) {
    for (Entry<Rectangle2D, String> item : textContentMap.entrySet()) {
        Rectangle2D rect = item.getKey();
        Point2D screenPoint = ChartMaskingUtilities.translateChartPoint(
                new Point2D.Double(rect.getMinX(), rect.getMinY()), getScreenDataArea(), getChart());
        Rectangle2D screenRect = new Rectangle2D.Double(screenPoint.getX(), screenPoint.getY() - 15,
                rect.getWidth(), rect.getHeight());
        if (screenRect.contains(xNew, yNew)) {
            if (selectedTextWrapper == rect) {
                selectedTextWrapper = null;
            } else {
                selectedTextWrapper = rect;
                setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                return;
            }/*from w  w w. j  av a 2s  .  co  m*/
        }
    }
    if (selectedTextWrapper != null) {
        selectedTextWrapper = null;
    }
}

From source file:ExText.java

/**
 * Responds to a button3 event (press, release, or drag). On a drag, the
 * difference between the current and previous cursor location provides a
 * delta that controls the amount by which to translate in X and Y.
 * /*from ww w  .j a v a 2s .c  o m*/
 * @param mouseEvent
 *            the MouseEvent to respond to
 */
public void onButton3(MouseEvent mev) {
    if (subjectTransformGroup == null)
        return;

    int x = mev.getX();
    int y = mev.getY();

    if (mev.getID() == MouseEvent.MOUSE_PRESSED) {
        // Mouse button pressed: record position
        previousX = x;
        previousY = y;

        // Change to a "move" cursor
        if (parentComponent != null) {
            savedCursor = parentComponent.getCursor();
            parentComponent.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
        }
        return;
    }
    if (mev.getID() == MouseEvent.MOUSE_RELEASED) {
        // Mouse button released: do nothing

        // Switch the cursor back
        if (parentComponent != null)
            parentComponent.setCursor(savedCursor);
        return;
    }

    //
    // Mouse moved while button down: create a translation
    //
    // Compute the delta in X and Y from the previous
    // position. Use the delta to compute translation
    // distances with the mapping:
    //
    //   positive X mouse delta --> positive X-axis translation
    //   positive Y mouse delta --> negative Y-axis translation
    //
    // where positive X mouse movement is to the right, and
    // positive Y mouse movement is **down** the screen.
    //
    int deltaX = x - previousX;
    int deltaY = y - previousY;

    if (deltaX > UNUSUAL_XDELTA || deltaX < -UNUSUAL_XDELTA || deltaY > UNUSUAL_YDELTA
            || deltaY < -UNUSUAL_YDELTA) {
        // Deltas are too huge to be believable. Probably a glitch.
        // Don't record the new XY location, or do anything.
        return;
    }

    double xTranslationDistance = deltaX * XTranslationFactor;
    double yTranslationDistance = -deltaY * YTranslationFactor;

    //
    // Build transforms
    //
    translate.set(xTranslationDistance, yTranslationDistance, 0.0);
    transform1.set(translate);

    // Get and save the current transform
    subjectTransformGroup.getTransform(currentTransform);

    // Translate as needed
    currentTransform.mul(transform1);

    // Update the transform group
    subjectTransformGroup.setTransform(currentTransform);

    previousX = x;
    previousY = y;
}

From source file:org.pentaho.reporting.designer.core.editor.report.AbstractRenderComponent.java

protected void updateCursorForIndicator() {
    if (currentIndicator == null) {
        setCursor(Cursor.getDefaultCursor());
        return;/*from   w  w w. j  a  v a  2  s  .  co  m*/
    }
    switch (currentIndicator) {
    case NOT_IN_RANGE:
        setCursor(Cursor.getDefaultCursor());
        break;
    case MOVE:
        setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
        break;
    case BOTTOM_CENTER:
        setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
        break;
    case BOTTOM_LEFT:
        setCursor(Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR));
        break;
    case BOTTOM_RIGHT:
        setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
        break;
    case MIDDLE_LEFT:
        setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
        break;
    case MIDDLE_RIGHT:
        setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
        break;
    case TOP_LEFT:
        setCursor(Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR));
        break;
    case TOP_CENTER:
        setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));
        break;
    case TOP_RIGHT:
        setCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
        break;
    }
}