Example usage for java.awt.event MouseEvent MOUSE_PRESSED

List of usage examples for java.awt.event MouseEvent MOUSE_PRESSED

Introduction

In this page you can find the example usage for java.awt.event MouseEvent MOUSE_PRESSED.

Prototype

int MOUSE_PRESSED

To view the source code for java.awt.event MouseEvent MOUSE_PRESSED.

Click Source Link

Document

The "mouse pressed" event.

Usage

From source file:SwingGlassExample.java

private void testForDrag(int eventID) {
    if (eventID == MouseEvent.MOUSE_PRESSED) {
        inDrag = true;
    }
}

From source file:OrientedTest.java

public void processStimulus(Enumeration criteria) {
    WakeupCriterion wakeup;/*from w  w w. j av a  2  s . co  m*/
    AWTEvent[] event;
    int id;
    int dx;

    while (criteria.hasMoreElements()) {
        wakeup = (WakeupCriterion) criteria.nextElement();
        if (wakeup instanceof WakeupOnAWTEvent) {
            event = ((WakeupOnAWTEvent) wakeup).getAWTEvent();
            for (int i = 0; i < event.length; i++) {
                processMouseEvent((MouseEvent) event[i]);

                if (((buttonPress) && ((flags & MANUAL_WAKEUP) == 0))
                        || ((wakeUp) && ((flags & MANUAL_WAKEUP) != 0))) {

                    id = event[i].getID();
                    if ((id == MouseEvent.MOUSE_DRAGGED) && !((MouseEvent) event[i]).isMetaDown()
                            && !((MouseEvent) event[i]).isAltDown()) {

                        x = ((MouseEvent) event[i]).getX();

                        dx = x - x_last;

                        if (!reset) {
                            y_angle = dx * y_factor;

                            transformY.rotY(y_angle);

                            transformGroup.getTransform(currXform);

                            //Vector3d translation = new Vector3d();
                            //Matrix3f rotation = new Matrix3f();
                            Matrix4d mat = new Matrix4d();

                            // Remember old matrix
                            currXform.get(mat);

                            // Translate to origin
                            currXform.setTranslation(new Vector3d(0.0, 0.0, 0.0));
                            if (invert) {
                                currXform.mul(currXform, transformX);
                                currXform.mul(currXform, transformY);
                            } else {
                                currXform.mul(transformX, currXform);
                                currXform.mul(transformY, currXform);
                            }

                            // Set old translation back
                            Vector3d translation = new Vector3d(mat.m03, mat.m13, mat.m23);
                            currXform.setTranslation(translation);

                            // Update xform
                            transformGroup.setTransform(currXform);
                        } else {
                            reset = false;
                        }

                        x_last = x;
                    } else if (id == MouseEvent.MOUSE_PRESSED) {
                        x_last = ((MouseEvent) event[i]).getX();
                    }
                }
            }
        }
    }

    wakeupOn(mouseCriterion);

}

From source file:IntersectTest.java

public void initialize() {
    wakeupOn(new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED));
}

From source file:IntersectTest.java

public void processStimulus(Enumeration criteria) {
    WakeupCriterion wakeup;/*  w  w  w  .  j  ava  2s. co  m*/
    AWTEvent[] event;
    int eventId;

    while (criteria.hasMoreElements()) {
        wakeup = (WakeupCriterion) criteria.nextElement();
        if (wakeup instanceof WakeupOnAWTEvent) {
            event = ((WakeupOnAWTEvent) wakeup).getAWTEvent();
            for (int i = 0; i < event.length; i++) {
                eventId = event[i].getID();
                if (eventId == MouseEvent.MOUSE_PRESSED) {
                    int x = ((MouseEvent) event[i]).getX();
                    int y = ((MouseEvent) event[i]).getY();
                    pickCanvas.setShapeLocation(x, y);

                    Point3d eyePos = pickCanvas.getStartPosition();
                    pickResult = pickCanvas.pickAllSorted();
                    // Use this to do picking benchmarks
                    /*
                     * long start = System.currentTimeMillis(); for (int
                     * l=0;l <3;l++) { if (l == 0) System.out.print
                     * ("BOUNDS: "); if (l == 1) System.out.print
                     * ("GEOMETRY: "); if (l == 2) System.out.print
                     * ("GEOMETRY_INTERSECT_INFO: ");
                     * 
                     * for (int k=0;k <1000;k++) { if (l == 0) {
                     * pickCanvas.setMode(PickTool.BOUNDS); pickResult =
                     * pickCanvas.pickAllSorted(); } if (l == 1) {
                     * pickCanvas.setMode(PickTool.GEOMETRY); pickResult =
                     * pickCanvas.pickAllSorted(); } if (l == 2) {
                     * pickCanvas.setMode(PickTool.GEOMETRY_INTERSECT_INFO);
                     * pickResult = pickCanvas.pickAllSorted(); } } long
                     * delta = System.currentTimeMillis() - start;
                     * System.out.println ("\t"+delta+" ms / 1000 picks"); }
                     */
                    if (pickResult != null) {

                        // Get closest intersection results
                        PickIntersection pi = pickResult[0].getClosestIntersection(eyePos);

                        GeometryArray curGeomArray = pi.getGeometryArray();

                        // Position sphere at intersection point
                        Vector3d v = new Vector3d();
                        Point3d intPt = pi.getPointCoordinatesVW();
                        v.set(intPt);
                        spht3.setTranslation(v);
                        sphTrans[0].setTransform(spht3);

                        // Position sphere at closest vertex
                        Point3d closestVert = pi.getClosestVertexCoordinatesVW();
                        v.set(closestVert);
                        spht3.setTranslation(v);
                        sphTrans[1].setTransform(spht3);

                        Point3d[] ptw = pi.getPrimitiveCoordinatesVW();
                        Point3d[] pt = pi.getPrimitiveCoordinates();
                        int[] coordidx = pi.getPrimitiveCoordinateIndices();
                        Point3d ptcoord = new Point3d();
                        for (int k = 0; k < pt.length; k++) {
                            v.set(ptw[k]);
                            spht3.setTranslation(v);
                            sphTrans[k + 2].setTransform(spht3);
                        }

                        // Get interpolated color (if available)
                        Color4f iColor4 = null;
                        Color3f iColor = null;
                        Vector3f iNormal = null;

                        if (curGeomArray != null) {
                            int vf = curGeomArray.getVertexFormat();

                            if (((vf & (GeometryArray.COLOR_3 | GeometryArray.COLOR_4)) != 0)
                                    && (null != (iColor4 = pi.getPointColor()))) {
                                iColor = new Color3f(iColor4.x, iColor4.y, iColor4.z);

                                // Change the point's color
                                redlook.setMaterial(new Material(iColor, new Color3f(0.0f, 0.0f, 0.0f), iColor,
                                        new Color3f(1.0f, 1.0f, 1.0f), 50.0f));
                            }
                            if (((vf & GeometryArray.NORMALS) != 0)
                                    && (null != (iNormal = pi.getPointNormal()))) {
                                System.out.println("Interpolated normal: " + iNormal);
                            }
                        }

                        System.out.println("=============");
                        System.out.println("Coordinates of intersection pt:" + intPt);
                        System.out.println("Coordinates of vertices: ");
                        for (int k = 0; k < pt.length; k++) {
                            System.out.println(k + ":" + ptw[k].x + " " + ptw[k].y + " " + ptw[k].z);
                        }
                        System.out.println("Closest vertex: " + closestVert);
                        if (iColor != null) {
                            System.out.println("Interpolated color: " + iColor);
                        }
                        if (iNormal != null) {
                            System.out.println("Interpolated normal: " + iNormal);
                        }
                    }
                }
            }
        }
    }
    wakeupOn(new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED));
}

From source file:edu.ku.brc.ui.tmanfe.SpreadSheet.java

@Override
public void processMouseEvent(MouseEvent ev) {
    int type = ev.getID();
    //int modifiers = ev.getModifiers();

    mouseDown = type == MouseEvent.MOUSE_PRESSED;

    // XXX For Java 5 Bug
    // I am not sure if we still need this
    if (mouseDown && UIHelper.getOSType() == UIHelper.OSTYPE.MacOSX) {
        int rowIndexStart = rowAtPoint(ev.getPoint());
        int colIndexStart = columnAtPoint(ev.getPoint());

        //System.out.println(isEditing()+"  "+rowIndexStart+" "+colIndexStart+" "+prevRowSelInx+" "+prevColSelInx+" ");
        if (isEditing() && (prevRowSelInx != rowIndexStart || prevColSelInx != colIndexStart)) {
            getCellEditor().stopCellEditing();
        }/*from  w  w  w . jav a 2 s .co  m*/
    }
    // Done - For Java 5 Bug

    if (ev.isPopupTrigger()) {
        // No matter what, stop editing if we are editing
        if (isEditing()) {
            getCellEditor().stopCellEditing();
        }

        // Now check to see if we right clicked on a different rowor column
        boolean isOnSelectedCell = false;
        int rowIndexStart = rowAtPoint(ev.getPoint());
        int colIndexStart = columnAtPoint(ev.getPoint());

        // Check to see if we are in the selection of mulitple rows and cols
        if (getSelectedRowCount() > 0) {
            int[] cols = getSelectedColumns();
            for (int r : getSelectedRows()) {
                if (r == rowIndexStart) {
                    for (int c : cols) {
                        if (c == colIndexStart) {
                            isOnSelectedCell = true;
                            break;
                        }
                    }
                }
            }
        }
        if (!isOnSelectedCell) {
            setRowSelectionInterval(rowIndexStart, rowIndexStart);
            setColumnSelectionInterval(colIndexStart, colIndexStart);
        }

        if (popupMenu != null) {
            popupMenu.setVisible(false);
        }

        popupMenu = createMenuForSelection(ev.getPoint());

        if (popupMenu.isVisible()) {
            popupMenu.setVisible(false);

        } else {
            //popupMenu.setTargetCells(_selection);
            Point p = getLocationOnScreen();
            popupMenu.setLocation(p.x + ev.getX() + 1, p.y + ev.getY() + 1);
            popupMenu.setVisible(true);
        }
    }
    super.processMouseEvent(ev);
}

From source file:MouseNavigateTest.java

/**
 * Registers which AWT events are of interest to the behaviour
 *//*from   w ww. j a va 2 s.  c  om*/
//*****************************************************************************
public void initialize() {
    WakeupCriterion[] mouseEvents = new WakeupCriterion[3];

    mouseEvents[0] = new WakeupOnAWTEvent(MouseEvent.MOUSE_DRAGGED);
    mouseEvents[1] = new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED);
    mouseEvents[2] = new WakeupOnAWTEvent(MouseEvent.MOUSE_RELEASED);

    m_MouseCriterion = new WakeupOr(mouseEvents);
    wakeupOn(m_MouseCriterion);
}

From source file:ExText.java

/**
 * Respond to a button1 event (press, release, or drag).
 * // www  .  ja  va  2s. c o  m
 * @param mouseEvent
 *            A MouseEvent to respond to.
 */
public void onButton1(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.HAND_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 --> positive Y-axis rotation
    //   positive Y mouse delta --> positive 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 = 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(transform1, currentTransform);
    currentTransform.mul(transform2, currentTransform);
    currentTransform.setTranslation(translate);

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

    previousX = x;
    previousY = y;
}

From source file:ExText.java

/**
 * Respond to a button2 event (press, release, or drag).
 * /*w w  w .  java2 s.c  o 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).
 * //ww w  . j a v  a  2s .  c  o 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:ExText.java

/**
 * Initializes the behavior./*from   ww w  .  j  a  v a  2  s  .  c o m*/
 */
public void initialize() {
    super.initialize();
    savedMouseCriterion = mouseCriterion; // from parent class
    mouseAndAnimationEvents = new WakeupCriterion[4];
    mouseAndAnimationEvents[0] = new WakeupOnAWTEvent(MouseEvent.MOUSE_DRAGGED);
    mouseAndAnimationEvents[1] = new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED);
    mouseAndAnimationEvents[2] = new WakeupOnAWTEvent(MouseEvent.MOUSE_RELEASED);
    mouseAndAnimationEvents[3] = new WakeupOnElapsedFrames(0);
    mouseAndAnimationCriterion = new WakeupOr(mouseAndAnimationEvents);
    // Don't use the above criterion until a button 1 down event
}