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:net.sf.firemox.clickable.target.card.VirtualCard.java

public void mousePressed(MouseEvent e) {
    if (card.getParent() instanceof MZone) {
        card.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
        ((MZone) card.getParent()).startDragAndDrop(card, e.getPoint());
    }/*from  w w w  .j a  v a  2  s.c  o m*/
}

From source file:org.gumtree.vis.hist2d.Hist2DPanel.java

protected int findCursorOnSelectedItem(int x, int y) {
    if (getSelectedMask() != null && !getSelectedMask().getRectangleFrame().isEmpty()) {
        Rectangle2D screenArea = getScreenDataArea();
        Rectangle2D maskArea = ChartMaskingUtilities
                .translateChartRectangle(getSelectedMask(), getScreenDataArea(), getChart())
                .getRectangleFrame();/*w  w w .  j  ava2 s . co  m*/
        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 maxY = maskArea.getMaxY();
        double width = maskArea.getWidth();
        double height = maskArea.getHeight();
        if (!intersect.isEmpty() && screenArea.contains(point)) {
            //              if (y > minY && y < maxY) {
            //                 if (minX > screenArea.getMinX() + 1 
            //                       && minX < screenArea.getMaxX() - 1) {
            //                       if (x > minX - 4 && x < minX + (width < 8 ? width / 2 : 4)) {
            //                          return Cursor.W_RESIZE_CURSOR;
            //                       } 
            //                 }
            //                 if (maxX > screenArea.getMinX() + 1 
            //                       && maxX < screenArea.getMaxX() - 1) {
            //                       if (x > maxX - (width < 8 ? width / 2 : 4) && x < maxX + 4) {
            //                          return Cursor.E_RESIZE_CURSOR;
            //                       } 
            //                 }
            //              }
            if (height > 8 && width > 8) {
                Rectangle2D center = new Rectangle2D.Double(minX + 4, minY + 4, width - 8, height - 8);
                if (screenArea.createIntersection(center).contains(point)) {
                    return Cursor.MOVE_CURSOR;
                }
            }
            if (height > 8) {
                Rectangle2D west = new Rectangle2D.Double(minX - 4, minY + 4, width < 8 ? width / 2 + 4 : 8,
                        height - 8);
                if (screenArea.createIntersection(west).contains(point)) {
                    return Cursor.W_RESIZE_CURSOR;
                }
                Rectangle2D east = new Rectangle2D.Double(maxX - (width < 8 ? width / 2 : 4), minY + 4,
                        width < 8 ? width / 2 + 4 : 8, height - 8);
                if (screenArea.createIntersection(east).contains(point)) {
                    return Cursor.E_RESIZE_CURSOR;
                }
            }
            if (width > 8) {
                Rectangle2D north = new Rectangle2D.Double(minX + 4, minY - 4, width - 8,
                        height < 8 ? height / 2 + 4 : 8);
                if (screenArea.createIntersection(north).contains(point)) {
                    return Cursor.N_RESIZE_CURSOR;
                }
                Rectangle2D south = new Rectangle2D.Double(minX + 4, maxY - (height < 8 ? height / 2 : 4),
                        width - 8, height < 8 ? height / 2 + 4 : 8);
                if (screenArea.createIntersection(south).contains(point)) {
                    return Cursor.S_RESIZE_CURSOR;
                }
            }
            Rectangle2D northwest = new Rectangle2D.Double(minX - 4, minY - 4, width < 8 ? width / 2 + 4 : 8,
                    height < 8 ? height / 2 + 4 : 8);
            if (screenArea.createIntersection(northwest).contains(point)) {
                return Cursor.NW_RESIZE_CURSOR;
            }
            Rectangle2D northeast = new Rectangle2D.Double(maxX - (width < 8 ? width / 2 : 4), minY - 4,
                    width < 8 ? width / 2 + 4 : 8, height < 8 ? height / 2 + 4 : 8);
            if (screenArea.createIntersection(northeast).contains(point)) {
                return Cursor.NE_RESIZE_CURSOR;
            }
            Rectangle2D southwest = new Rectangle2D.Double(minX - 4, maxY - (height < 8 ? height / 2 : 4),
                    width < 8 ? width / 2 + 4 : 8, height < 8 ? height / 2 + 4 : 8);
            if (screenArea.createIntersection(southwest).contains(point)) {
                return Cursor.SW_RESIZE_CURSOR;
            }
            Rectangle2D southeast = new Rectangle2D.Double(maxX - (width < 8 ? width / 2 : 4),
                    maxY - (height < 8 ? height / 2 : 4), width < 8 ? width / 2 + 4 : 8,
                    height < 8 ? height / 2 + 4 : 8);
            if (screenArea.createIntersection(southeast).contains(point)) {
                return Cursor.SE_RESIZE_CURSOR;
            }
        }
        //           System.out.println("intersect X:[" + intersect.getMinX() + ", " + 
        //                 (intersect.getMinX() + intersect.getWidth()) + 
        //                 "], Y:[" + intersect.getMinY() + ", " + 
        //                 (intersect.getMinY() + intersect.getHeight()) +
        //                 "], x=" + point.getX() + ", y=" + point.getY() + 
        //                 " " + intersect.contains(point));
    }
    return Cursor.DEFAULT_CURSOR;
}

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

@Override
public void mousePressed(MouseEvent e) {
    int mods = e.getModifiers();
    //        if (isMaskingEnabled() && (mods & maskingKeyMask) != 0) {
    if (isInternalLegendEnabled && isInternalLegendSelected) {
        int cursorType = findCursorOnSelectedItem(e.getX(), e.getY());
        if (cursorType == Cursor.DEFAULT_CURSOR) {
            Rectangle2D screenDataArea = getScreenDataArea(e.getX(), e.getY());
            if (screenDataArea != null) {
                legendPoint = e.getPoint();
            } else {
                legendPoint = null;//www. j a  v  a  2s .c  om
            }
        } else {
            if (cursorType == Cursor.MOVE_CURSOR) {
                legendPoint = e.getPoint();
            }
        }
    }
    if (isMaskingEnabled()) {
        // Prepare masking service.
        int cursorType = findCursorOnSelectedItem(e.getX(), e.getY());
        if (cursorType == Cursor.DEFAULT_CURSOR && (mods & maskingKeyMask) != 0) {
            Rectangle2D screenDataArea = getScreenDataArea(e.getX(), e.getY());
            if (screenDataArea != null) {
                this.maskPoint = getPointInRectangle(e.getX(), e.getY(), screenDataArea).getX();
            } else {
                this.maskPoint = Double.NaN;
            }
        } else {
            if (cursorType == Cursor.MOVE_CURSOR) {
                //                 this.maskMovePoint = translateScreenToChart(
                //                       translateScreenToJava2D(e.getPoint())).getX();
                Insets insets = getInsets();
                this.maskMovePoint = ChartMaskingUtilities.translateScreenX(
                        (e.getX() - insets.left) / getScaleX(), getScreenDataArea(), getChart());
            }
            setMaskDragIndicator(cursorType);
        }
    }
    if (getMaskDragIndicator() == Cursor.DEFAULT_CURSOR) {
        super.mousePressed(e);
    }
}

From source file:ExText.java

/**
 * Respond to a button2 event (press, release, or drag).
 * //  w  ww  . j  a va  2  s .  co  m
 * @param mouseEvent
 *            A 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;

        // 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 Y from the previous
    // position. Use the delta to compute translation
    // distances with the mapping:
    //
    //   positive Y mouse delta --> positive Y-axis translation
    //
    // where positive X mouse movement is to the right, and
    // positive Y mouse movement is **down** the screen.
    //
    int deltaY = y - previousY;

    if (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 zTranslationDistance = deltaY * ZTranslationFactor;

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

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

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

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

    previousX = x;
    previousY = y;
}

From source file:ExText.java

/**
 * Respond to a button3 event (press, release, or drag).
 * //from w  w w.  j ava  2  s . co  m
 * @param mouseEvent
 *            A 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, currentTransform);

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

    previousX = x;
    previousY = y;
}

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

private void changeInternalLegend(MouseEvent e) {
    // TODO Auto-generated method stub
    Point2D screenPoint = translateScreenToJava2D(e.getPoint());
    //TODO: resize the mask
    Rectangle2D screenArea = getScreenDataArea();
    if (screenArea.contains(screenPoint)) {
        //             Point2D chartPoint = translateScreenToChart(screenPoint);

        //         changeSelectedMask(ChartMaskingUtilities.translateScreenX(
        //               screenPoint.getX(), getScreenDataArea(), getChart()));
        int cursorType = findCursorOnSelectedItem(e.getX(), e.getY());
        switch (cursorType) {
        case Cursor.MOVE_CURSOR:
            moveLegend(e.getPoint());//w w w . j  a  v a  2s  . c o m
            break;
        case Cursor.W_RESIZE_CURSOR:
            changeLegendX(e.getPoint());
            break;
        case Cursor.E_RESIZE_CURSOR:
            changeLegendWidth(e.getPoint());
            break;
        default:
            break;
        }
        repaint();
    }
}

From source file:cn.pholance.datamanager.common.components.JRViewer.java

void pnlLinksMousePressed(MouseEvent evt) {//GEN-FIRST:event_pnlLinksMousePressed
    // Add your handling code here:
    pnlLinks.setCursor(new Cursor(Cursor.MOVE_CURSOR));

    downX = evt.getX();/*w  w  w .ja va2  s. co m*/
    downY = evt.getY();
}

From source file:org.gumtree.vis.hist2d.Hist2DPanel.java

@Override
public void mousePressed(MouseEvent e) {
    //        int mods = e.getModifiers();
    //        if (isMaskingEnabled() && (mods & maskingKeyMask) != 0) {
    if (isMaskingEnabled()) {
        // Prepare masking service.
        int cursorType = findCursorOnSelectedItem(e.getX(), e.getY());
        if (cursorType == Cursor.DEFAULT_CURSOR) {
            Rectangle2D screenDataArea = getScreenDataArea(e.getX(), e.getY());
            if (screenDataArea != null) {
                this.maskPoint = getPointInRectangle(e.getX(), e.getY(), screenDataArea);
            } else {
                this.maskPoint = null;
            }/*from  ww  w.jav a 2s  .  co m*/
        } else {
            if (cursorType == Cursor.MOVE_CURSOR) {
                Point2D point = translateScreenToChart(translateScreenToJava2D(e.getPoint()));
                if (point != null) {
                    this.maskMovePoint = point;
                }
            }
            setMaskDragIndicator(cursorType);
        }
    }
    if (getMaskDragIndicator() == Cursor.DEFAULT_CURSOR) {
        if (e.getX() < getScreenDataArea().getMaxX()) {
            super.mousePressed(e);
        }
    }
}

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

@Override
public void mouseMoved(MouseEvent e) {
    //        if (isMaskingEnabled() && (e.getModifiers() & maskingKeyMask) != 0) {
    if (selectedTextWrapper == null && isMaskingEnabled()) {
        int cursorType = findCursorOnSelectedItem(e.getX(), e.getY());
        setCursor(Cursor.getPredefinedCursor(cursorType));
    } else {/*w ww.j  a  v  a 2  s.co m*/
        Cursor newCursor = defaultCursor;
        if (selectedTextWrapper != null) {
            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())) {
                newCursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR);
            }
        }
        if (newCursor != getCursor()) {
            setCursor(newCursor);
        }
    }
    Line2D oldSelection = selectedMarker;
    findSelectedMarker(e.getPoint());
    if (selectedMarker != oldSelection) {
        repaint();
    }
}

From source file:corelyzer.ui.CorelyzerGLCanvas.java

/**
 * Handles mouse dragging events: panning, sliding sections, sliding tracks,
 * and trackpad based zooming.//from   ww  w . ja va 2 s  .  c  om
 */
public void mouseDragged(final MouseEvent e) {

    Point currentPos = e.getPoint();
    int dX = currentPos.x - prePos.x;
    int dY = currentPos.y - prePos.y;

    float sx, sy;
    float w, h;

    canvasLock.lock();

    w = SceneGraph.getCanvasWidth(canvasId);
    h = SceneGraph.getCanvasHeight(canvasId);

    sx = w / canvas.getWidth();
    sy = h / canvas.getHeight();

    this.convertMousePointToSceneSpace(currentPos, scenePos);

    // play a bit measuring test
    if (canvasMode == CorelyzerApp.APP_MEASURE_MODE) {
        SceneGraph.positionMouse(scenePos[0], scenePos[1]);

        // some work for panning
        // automatically pan mode
        canvas.setCursor(new Cursor(Cursor.MOVE_CURSOR));
        SceneGraph.panScene(-dX * sx, -dY * sy);

        canvasLock.unlock();
        prePos = currentPos;
        CorelyzerApp.getApp().updateGLWindows();
        return;
    } else if (canvasMode == CorelyzerApp.APP_CLAST_MODE || canvasMode == CorelyzerApp.APP_CUT_MODE) {
        SceneGraph.positionMouse(scenePos[0], scenePos[1]);

        // Don't have a selected section, just pan
        if (selectedTrackSection == -1) {
            canvas.setCursor(new Cursor(Cursor.MOVE_CURSOR));
            SceneGraph.panScene(-dX * sx, -dY * sy);
        }

        canvasLock.unlock();
        prePos = currentPos;

        CorelyzerApp.getApp().updateGLWindows();
        return;
    }

    // check focused marker manipulation
    if (MANIPULATE_MODE == 1) {
        float dx, dy;
        dx = scenePos[0] - prescenePos[0];
        dy = scenePos[1] - prescenePos[1];
        prescenePos[0] = scenePos[0];
        prescenePos[1] = scenePos[1];
        SceneGraph.manipulateMarker(canvasId, dx, dy);
        SceneGraph.positionMouse(scenePos[0], scenePos[1]);
        canvasLock.unlock();
        prePos = currentPos;
        CorelyzerApp.getApp().updateGLWindows();
        return;
    } else {
        if (e.isAltDown()) // slide track section
        {
            // TODO consider separate move of section image and graph
            // moveSectionImage & moveSectionGraph
            if (selectedTrack >= 0 && selectedTrackSection >= 0) {
                if (canvas.getCursor().getType() != Cursor.HAND_CURSOR) {
                    canvas.setCursor(new Cursor(Cursor.HAND_CURSOR));
                }

                // depth orientation
                float tX = SceneGraph.getDepthOrientation() ? dX * sx : dY * sy;

                // allow vertical movements?
                float tY = 0;
                // float tY = SceneGraph.getDepthOrientation() ?
                // (dY * sy) : (-dX * sx);

                if (selectedGraph >= 0) {
                    // moving graph instead of whole section
                    SceneGraph.moveSectionGraph(selectedTrack, selectedTrackSection, tX, tY);
                } else {
                    Object[] sections = CorelyzerApp.getApp().getSectionList().getSelectedValues();
                    int[] secids = new int[sections.length];
                    for (int i = 0; i < sections.length; i++) {
                        CoreSection cs = (CoreSection) sections[i];
                        secids[i] = (cs != null ? cs.getId() : -1);
                    }
                    SceneGraph.moveSections(selectedTrack, secids, tX, tY);
                }

                // broadcast event to plugins
                String msg = "";
                msg = msg + selectedTrack + "\t" + selectedTrackSection;
                msg = msg + "\t" + dX * sx / SceneGraph.getCanvasDPIX(canvasId) + "\t0";

                CorelyzerApp.getApp().getPluginManager()
                        .broadcastEventToPlugins(CorelyzerPluginEvent.SECTION_MOVED, msg);
            }
        } else if (e.isShiftDown()) { // slide track
            if (selectedTrack >= 0) {
                if (canvas.getCursor().getType() != Cursor.HAND_CURSOR) {
                    canvas.setCursor(new Cursor(Cursor.HAND_CURSOR));
                }

                // fine tune allows depth movements
                if (isFineTune() && finetuneDialog != null) {
                    // depth orientation
                    if (SceneGraph.getDepthOrientation()) { // landscape
                        SceneGraph.moveTrack(selectedTrack, dX * sx, dY * sy);
                    } else { // Portrait
                        SceneGraph.moveTrack(selectedTrack, dY * sy, -dX * sx);
                    }

                    float currentTrackPosX = SceneGraph.getTrackXPos(selectedTrack);
                    float canvasDPIX = SceneGraph.getCanvasDPIX(0);

                    JTextField fineTuneCoreADepthStatus = finetuneDialog.getCoreAAdjustedDepthTextField();
                    JTextField fineTuneCoreBDepthStatus = finetuneDialog.getCoreBAdjustedDepthTextField();
                    int coreANativeID = finetuneDialog.getCoreANativeID();
                    int coreBNativeID = finetuneDialog.getCoreBNativeID();
                    float coreAOrigDepth = finetuneDialog.getCoreAOrigDepth();
                    float coreBOrigDepth = finetuneDialog.getCoreBOrigDepth();

                    if (fineTuneCoreADepthStatus != null && coreANativeID == selectedTrack) {
                        float depth = coreAOrigDepth + 2.54f * currentTrackPosX / (100 * canvasDPIX);
                        fineTuneCoreADepthStatus.setText(String.valueOf(depth));
                    }

                    if (fineTuneCoreBDepthStatus != null && coreBNativeID == selectedTrack) {
                        float depth = coreBOrigDepth + 2.54f * currentTrackPosX / (100 * canvasDPIX);
                        fineTuneCoreBDepthStatus.setText(String.valueOf(depth));
                    }
                } else { // normal
                    // depth orientation
                    if (SceneGraph.getDepthOrientation()) {
                        SceneGraph.moveTrack(selectedTrack, 0.0f, dY * sy);
                    } else {
                        SceneGraph.moveTrack(selectedTrack, 0.0f, -dX * sx);
                    }
                }

                // broadcast message to plugins
                String msg = "";
                msg = msg + selectedTrack;
                msg = msg + "\t0\t" + dY * sx / SceneGraph.getCanvasDPIY(canvasId);
                CorelyzerApp.getApp().getPluginManager()
                        .broadcastEventToPlugins(CorelyzerPluginEvent.TRACK_MOVED, msg);
            }
        } else if (e.isControlDown()) // zooming
        {
            sy = (float) dY / (float) canvas.getHeight();
            SceneGraph.scaleScene(1.0f + sy);
        } else if (PAN_MODE == 1) {
            // automatically pan mode
            canvas.setCursor(new Cursor(Cursor.MOVE_CURSOR));
            SceneGraph.panScene(-dX * sx, -dY * sy);
        }
    } // end of else (manipulation mode)

    SceneGraph.positionMouse(scenePos[0], scenePos[1]);
    canvasLock.unlock();
    prePos = currentPos;
    CorelyzerApp.getApp().updateGLWindows();

}