Example usage for java.awt.event MouseEvent getID

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

Introduction

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

Prototype

public int getID() 

Source Link

Document

Returns the event type.

Usage

From source file:ExText.java

/**
 * Responds to a button1 event (press, release, or drag). On a press, the
 * method adds a wakeup criterion to the behavior's set, callling for the
 * behavior to be awoken on each frame. On a button prelease, this criterion
 * is removed from the set./*  w w w .  ja  va2  s.  c o m*/
 * 
 * @param mouseEvent
 *            the 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 and change
        // the wakeup criterion to include elapsed time wakeups
        // so we can animate.
        previousX = x;
        previousY = y;
        initialX = x;
        initialY = y;

        // Swap criterion... parent class will not reschedule us
        mouseCriterion = mouseAndAnimationCriterion;

        // 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: restore original wakeup
        // criterion which only includes mouse activity, not
        // elapsed time
        mouseCriterion = savedMouseCriterion;

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

    previousX = x;
    previousY = y;
}

From source file:ExText.java

/**
 * Respond to a button2 event (press, release, or drag).
 * //from www .j  av  a 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  a va2s .  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

/**
 * 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.
 * /*  w ww  .ja v  a  2 s .  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:ExText.java

/**
 * Respond to a button1 event (press, release, or drag).
 * //from ww w.j  a  va2s  .com
 * @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

/**
 * 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 w  ww.  j  ava2 s.c  o  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.nuclos.client.ui.collect.searcheditor.SearchEditorController.java

/**
 * event: a mouse event occured on a node in the <code>view</code>
 * @param selPath the path of the node where the mouse event occured.
 * @param ev//w ww  .ja  va2s  .  c  o m
 */
private void mouseEventOnNode(TreePath selPath, MouseEvent ev) {
    final SearchConditionTreeNode node = (SearchConditionTreeNode) selPath.getLastPathComponent();
    final JTree tree = (JTree) ev.getComponent();

    // select the node:
    tree.setSelectionPath(selPath);

    if (ev.isPopupTrigger()) {
        // show popup menu:
        final JPopupMenu popupMenu = this.getPopupMenu(node, tree);
        if (popupMenu != null) {
            popupMenu.show(ev.getComponent(), ev.getX(), ev.getY());
        }
    } else if (ev.getID() == MouseEvent.MOUSE_CLICKED) {
        if (ev.getButton() == MouseEvent.BUTTON1) {
            if (ev.getClickCount() == 2) {
                if (this.clctfproviderfactory == null) {
                    throw new IllegalStateException(
                            "No CollectableFieldsProviderFactory was defined for the search editor.");
                }
                // perform the node's default action:
                final Action actDefault = node.getDefaultTreeNodeAction(tree, this.clcteRoot,
                        this.clctfproviderfactory, this.additionalFields);
                if (actDefault != null) {
                    actDefault.actionPerformed(null);
                }
            }
        }
    }
}

From source file:org.pmedv.blackboard.commands.CreateBoardCommand.java

private void handleMouseEvent(MouseEvent e, BoardEditor editor) {
    if (e.getID() == MouseEvent.MOUSE_PRESSED) {
        log.info(e);//from w  w w  .  j  a v  a  2  s.c om
        TabWindow tw = DockingUtil.getTabWindowFor(editor.getView());
        advisor.setCurrentEditorArea(tw);
        EditorUtils.setToolbarButtonState(editor);
        ctx.getBean(ApplicationWindow.class).getRasterCombo().setSelectedItem(new Integer(editor.getRaster()));
        editor.updateStatusBar();
        editor.getView().requestFocus();
        editor.notifyListeners(EventType.EDITOR_CHANGED);
    }
}

From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java

private void selectionQuery(DBBrowserNode selectedNode, MouseEvent e, boolean pressed) {
    OpenQueryAction openAction = new OpenQueryAction();
    openAction.setQueryName(selectedNode.getDBObject().getName());
    openAction.setQueryPath(selectedNode.getDBObject().getAbsolutePath());

    if (e.getClickCount() == 2) {
        if (pressed) {
            openAction.actionPerformed(new ActionEvent(e.getSource(), e.getID(), ""));
        }/*w w w  . jav  a  2s  . c  o  m*/
    } else {
        JPopupMenu popupMenu = new JPopupMenu();
        JMenuItem menuItem = new JMenuItem(openAction);
        popupMenu.add(menuItem);

        NewReportFromQueryAction newReportQAction = new NewReportFromQueryAction();
        newReportQAction.setQueryName(selectedNode.getDBObject().getName());
        newReportQAction.setQueryPath(selectedNode.getDBObject().getAbsolutePath());
        JMenuItem menuItem3 = new JMenuItem(newReportQAction);
        popupMenu.add(menuItem3);

        NewChartFromQueryAction newChartQAction = new NewChartFromQueryAction();
        newChartQAction.setQueryName(selectedNode.getDBObject().getName());
        newChartQAction.setQueryPath(selectedNode.getDBObject().getAbsolutePath());
        JMenuItem menuItem6 = new JMenuItem(newChartQAction);
        popupMenu.add(menuItem6);

        DeleteQueryAction deleteAction = new DeleteQueryAction(instance, selectedNode);
        JMenuItem menuItem2 = new JMenuItem(deleteAction);//
        popupMenu.add(menuItem2);

        RenameQueryAction renameAction = new RenameQueryAction(instance, selectedNode);
        JMenuItem menuItem4 = new JMenuItem(renameAction);
        popupMenu.add(menuItem4);

        ExportQueryAction exportAction = new ExportQueryAction(instance, selectedNode);
        JMenuItem menuItem5 = new JMenuItem(exportAction);
        popupMenu.add(menuItem5);

        JMenuItem menuItem7 = new JMenuItem(new ValidateSqlsAction(selectedNode.getDBObject()));
        popupMenu.add(menuItem7);

        popupMenu.show((Component) e.getSource(), e.getX(), e.getY());
    }
}

From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java

private void selectionReport(DBBrowserNode selectedNode, MouseEvent e, boolean pressed) {
    OpenReportAction openAction = new OpenReportAction();
    openAction.setReportName(selectedNode.getDBObject().getName());
    openAction.setReportPath(selectedNode.getDBObject().getAbsolutePath());

    if (e.getClickCount() == 2) {
        if (pressed) {
            openAction.actionPerformed(new ActionEvent(e.getSource(), e.getID(), ""));
        }//from  w ww  . jav a2 s  .c  o m
    } else {
        JPopupMenu popupMenu = new JPopupMenu();
        JMenuItem menuItem = new JMenuItem(openAction);
        popupMenu.add(menuItem);

        DeleteReportAction deleteAction = new DeleteReportAction(instance, selectedNode);
        JMenuItem menuItem2 = new JMenuItem(deleteAction);
        popupMenu.add(menuItem2);

        RenameReportAction renameAction = new RenameReportAction(instance, selectedNode);
        JMenuItem menuItem3 = new JMenuItem(renameAction);
        popupMenu.add(menuItem3);

        ExportReportAction exportAction = new ExportReportAction(instance, selectedNode);
        JMenuItem menuItem4 = new JMenuItem(exportAction);
        popupMenu.add(menuItem4);

        Report report = FormLoader.getInstance().load(selectedNode.getDBObject().getAbsolutePath(), false);
        JMenu runMenu = new JMenu(I18NSupport.getString("export"));
        Globals.setTreeReportAbsolutePath(selectedNode.getDBObject().getAbsolutePath());
        runMenu.add(new JMenuItem(new ExportToHtmlAction(report)));
        runMenu.add(new JMenuItem(new ExportToExcelAction(report)));
        runMenu.add(new JMenuItem(new ExportToPdfAction(report)));
        runMenu.add(new JMenuItem(new ExportToDocxAction(report)));
        runMenu.add(new JMenuItem(new ExportToRtfAction(report)));
        runMenu.add(new JMenuItem(new ExportToCsvAction(report)));
        runMenu.add(new JMenuItem(new ExportToTsvAction(report)));
        runMenu.add(new JMenuItem(new ExportToXmlAction(report)));
        runMenu.add(new JMenuItem(new ExportToTxtAction(report)));
        popupMenu.add(runMenu);

        PublishReportAction publishAction = new PublishReportAction(
                selectedNode.getDBObject().getAbsolutePath());
        JMenuItem menuItem5 = new JMenuItem(publishAction);
        popupMenu.add(menuItem5);

        JMenuItem menuItem6 = new JMenuItem(new ValidateSqlsAction(selectedNode.getDBObject()));
        popupMenu.add(menuItem6);

        JMenuItem menuItem7 = new JMenuItem(new AddToFavoritesAction(selectedNode.getDBObject()));
        popupMenu.add(menuItem7);

        popupMenu.show((Component) e.getSource(), e.getX(), e.getY());
    }
}