Example usage for java.awt.event MouseEvent MOUSE_RELEASED

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

Introduction

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

Prototype

int MOUSE_RELEASED

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

Click Source Link

Document

The "mouse released" event.

Usage

From source file:Main.java

/**
 * Display mouse events that don't involve mouse motion. The mousemods()
 * method prints modifiers, and is defined below. The other methods return
 * additional information about the mouse event. showLine() displays a line
 * of text in the window. It is defined at the end of this class, along with
 * the paintComponent() method.//from w  w  w  .j a  v  a2  s.com
 */
public void processMouseEvent(MouseEvent e) {
    String type = null;
    switch (e.getID()) {
    case MouseEvent.MOUSE_DRAGGED:
        type = "MOUSE_DRAGGED";
        break;
    case MouseEvent.MOUSE_RELEASED:
        type = "MOUSE_RELEASED";
        break;
    case MouseEvent.MOUSE_CLICKED:
        type = "MOUSE_CLICKED";
        break;
    case MouseEvent.MOUSE_ENTERED:
        type = "MOUSE_ENTERED";
        break;
    case MouseEvent.MOUSE_EXITED:
        type = "MOUSE_EXITED";
        break;
    }
    showLine(mousemods(e) + type + ": [" + e.getX() + "," + e.getY() + "] " + "num clicks = "
            + e.getClickCount() + (e.isPopupTrigger() ? "; is popup trigger" : ""));

    // When the mouse enters the component, request keyboard focus so
    // we can receive and respond to keyboard events
    if (e.getID() == MouseEvent.MOUSE_ENTERED)
        requestFocus();
}

From source file:EventTestPane.java

/**
 * Display mouse events that don't involve mouse motion. The mousemods()
 * method prints modifiers, and is defined below. The other methods return
 * additional information about the mouse event. showLine() displays a line
 * of text in the window. It is defined at the end of this class, along with
 * the paintComponent() method.//from www  .  j  a v  a2 s  . com
 */
public void processMouseEvent(MouseEvent e) {
    String type = null;
    switch (e.getID()) {
    case MouseEvent.MOUSE_PRESSED:
        type = "MOUSE_PRESSED";
        break;
    case MouseEvent.MOUSE_RELEASED:
        type = "MOUSE_RELEASED";
        break;
    case MouseEvent.MOUSE_CLICKED:
        type = "MOUSE_CLICKED";
        break;
    case MouseEvent.MOUSE_ENTERED:
        type = "MOUSE_ENTERED";
        break;
    case MouseEvent.MOUSE_EXITED:
        type = "MOUSE_EXITED";
        break;
    }
    showLine(mousemods(e) + type + ": [" + e.getX() + "," + e.getY() + "] " + "num clicks = "
            + e.getClickCount() + (e.isPopupTrigger() ? "; is popup trigger" : ""));

    // When the mouse enters the component, request keyboard focus so
    // we can receive and respond to keyboard events
    if (e.getID() == MouseEvent.MOUSE_ENTERED)
        requestFocus();
}

From source file:JToggleButtonMenuItem.java

public void processMouseEvent(MouseEvent mouseEvent, MenuElement path[], MenuSelectionManager manager) {
    // For when mouse dragged over menu and button released
    if (mouseEvent.getID() == MouseEvent.MOUSE_RELEASED) {
        manager.clearSelectedPath();//from   w w  w.j  ava  2  s.c  o  m
        System.out.println("Selected: JToggleButtonMenuItem, by MouseEvent");
        doClick(0); // inherited from AbstractButton
    }
}

From source file:com.hp.alm.ali.idea.content.taskboard.TaskBoardPanel.java

public TaskBoardPanel(final Project project) {
    super(new BorderLayout());

    this.project = project;

    status = new EntityStatusPanel(project);
    queue = new QueryQueue(project, status, false);

    entityService = project.getComponent(EntityService.class);
    entityService.addEntityListener(this);
    sprintService = project.getComponent(SprintService.class);
    sprintService.addListener(this);

    loadTasks();//from  w w w.  j  a v  a 2s  .co m

    header = new Header();
    columnHeader = new ColumnHeader();

    content = new Content();
    add(content, BorderLayout.NORTH);

    header.assignedTo.reload();

    // force mouse-over task as visible (otherwise events are captured by the overlay and repaint quirks)
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        @Override
        public void eventDispatched(AWTEvent event) {
            if (isShowing() && event.getID() == MouseEvent.MOUSE_MOVED) {
                MouseEvent m = (MouseEvent) event;
                TaskPanel currentPanel = locateContainer(m, TaskPanel.class);
                if (currentPanel != null) {
                    if (forcedTaskPanel == currentPanel) {
                        return;
                    } else if (forcedTaskPanel != null) {
                        forcedTaskPanel.removeForcedMatch(this);
                    }
                    forcedTaskPanel = currentPanel;
                    forcedTaskPanel.addForcedMatch(this);
                } else if (forcedTaskPanel != null) {
                    forcedTaskPanel.removeForcedMatch(this);
                    forcedTaskPanel = null;
                }
            }
        }
    }, AWTEvent.MOUSE_MOTION_EVENT_MASK);

    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        @Override
        public void eventDispatched(AWTEvent event) {
            if (isShowing()) {
                MouseEvent m = (MouseEvent) event;
                switch (event.getID()) {
                case MouseEvent.MOUSE_PRESSED:
                case MouseEvent.MOUSE_RELEASED:
                    // implement backlog item popup
                    if (m.isPopupTrigger()) {
                        final BacklogItemPanel itemPanel = locateContainer(m, BacklogItemPanel.class);
                        if (itemPanel != null) {
                            ActionPopupMenu popupMenu = ActionUtil.createEntityActionPopup("taskboard");
                            Point p = SwingUtilities.convertPoint(m.getComponent(), m.getPoint(), itemPanel);
                            popupMenu.getComponent().show(itemPanel, p.x, p.y);
                        }
                    }
                    break;

                case MouseEvent.MOUSE_CLICKED:
                    // implement backlog item double click
                    if (m.getClickCount() > 1) {
                        BacklogItemPanel itemPanel = locateContainer(m, BacklogItemPanel.class);
                        if (itemPanel != null) {
                            Entity backlogItem = itemPanel.getItem();
                            Entity workItem = new Entity(backlogItem.getPropertyValue("entity-type"),
                                    Integer.valueOf(backlogItem.getPropertyValue("entity-id")));
                            AliContentFactory.loadDetail(project, workItem, true, true);
                        }
                    }
                }
            }

        }
    }, AWTEvent.MOUSE_EVENT_MASK);
}

From source file:TransferableScribblePane.java

/**
 * This method is called on mouse button events. It begins a new line or tries
 * to select an existing line.//from   w w w  .j a  va 2s.co  m
 */
public void processMouseEvent(MouseEvent e) {
    if (e.getButton() == MouseEvent.BUTTON1) { // Left mouse button
        if (e.getID() == MouseEvent.MOUSE_PRESSED) { // Pressed down
            if (e.isShiftDown()) { // with Shift key
                // If the shift key is down, try to select a line
                int x = e.getX();
                int y = e.getY();

                // Loop through the lines checking to see if we hit one
                PolyLine selection = null;
                int numlines = lines.size();
                for (int i = 0; i < numlines; i++) {
                    PolyLine line = (PolyLine) lines.get(i);
                    if (line.intersects(x - 2, y - 2, 4, 4)) {
                        selection = line;
                        e.consume();
                        break;
                    }
                }
                // If we found an intersecting line, save it and repaint
                if (selection != selectedLine) { // If selection changed
                    selectedLine = selection; // remember which is selected
                    repaint(); // will make selection dashed
                }
            } else if (!e.isControlDown()) { // no shift key or ctrl key
                // Start a new line on mouse down without shift or ctrl
                currentLine = new PolyLine(e.getX(), e.getY());
                lines.add(currentLine);
                e.consume();
            }
        } else if (e.getID() == MouseEvent.MOUSE_RELEASED) {// Left Button Up
            // End the line on mouse up
            if (currentLine != null) {
                currentLine = null;
                e.consume();
            }
        }
    }

    // The superclass method dispatches to registered event listeners
    super.processMouseEvent(e);
}

From source file:ToggleSample.java

public void processMouseEvent(MouseEvent mouseEvent, MenuElement path[], MenuSelectionManager manager) {
    // For when mouse dragged over menu and button released
    if (mouseEvent.getID() == MouseEvent.MOUSE_RELEASED) {
        manager.clearSelectedPath();//www  .  j ava 2 s  .c  o m
        doClick(0); // inherited from AbstractButton
    }
}

From source file:brainflow.app.toplevel.BrainFlow.java

private void initializeToolBar() {

    CommandGroup mainToolbarGroup = new CommandGroup("main-toolbar");

    mainToolbarGroup.bind(getApplicationFrame());

    ToggleGroup interpToggleGroup = new ToggleGroup("toggle-interp-group");
    interpToggleGroup.bind(getApplicationFrame());

    bindCommand(new OpenImageCommand(), true);
    bindCommand(new SnapshotCommand(), true);
    bindCommand(new NewCanvasCommand(), true);

    bindCommand(new CreateAxialViewCommand(), true);
    bindCommand(new CreateSagittalViewCommand(), true);

    bindCommand(new CreateCoronalViewCommand(), true);
    bindCommand(new CreateMontageViewCommand(), true);
    bindCommand(new CreateVerticalOrthogonalCommand(), true);

    bindCommand(new CreateHorizontalOrthogonalCommand(), true);
    bindCommand(new CreateTriangularOrthogonalCommand(), true);

    CommandGroup orthoGroup = new CommandGroup("ortho-view-group");
    orthoGroup.bind(getApplicationFrame());

    final NextSliceCommand nextSliceCommand = new NextSliceCommand();
    bindCommand(nextSliceCommand, false);

    final PreviousSliceCommand previousSliceCommand = new PreviousSliceCommand();
    bindCommand(previousSliceCommand, false);

    bindCommand(new PageBackSliceCommand(), true);
    bindCommand(new PageForwardSliceCommand(), true);

    bindCommand(new IncreaseContrastCommand(), true);
    bindCommand(new DecreaseContrastCommand(), true);

    bindCommand(new NearestInterpolationToggleCommand(), true);
    bindCommand(new LinearInterpolationToggleCommand(), true);
    bindCommand(new CubicInterpolationToggleCommand(), true);
    bindCommand(new ToggleAxisLabelCommand(), true);
    bindCommand(new ToggleCrossCommand(), true);

    //JToolBar mainToolbar = mainToolbarGroup.createToolBar();
    final CommandBar mainToolbar = new CommandBar();
    // for nimbus look and feel
    mainToolbar.setPaintBackground(false);
    // for nimbus look and feel

    mainToolbar.setBorder(new EmptyBorder(0, 0, 0, 0));
    final ButtonFactory buttonFactory = createToolBarButtonFactory();

    mainToolbarGroup.visitMembers(new GroupVisitor() {
        @Override/*  w  ww  .j ava2s .c o m*/
        public void visit(ActionCommand actionCommand) {
            JideButton jb = new JideButton(actionCommand.getActionAdapter());
            jb.setButtonStyle(JideButton.TOOLBAR_STYLE);
            jb.setText("");
            mainToolbar.add(jb);
        }

        @Override
        public void visit(CommandGroup commandGroup) {
            JComponent jc = commandGroup.createButton(buttonFactory);
            mainToolbar.add(jc);
        }
    });

    mainToolbar.setKey("toolbar");
    brainFrame.getDockableBarManager().addDockableBar(mainToolbar);

    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        public void eventDispatched(AWTEvent event) {

            if (event.getID() == KeyEvent.KEY_PRESSED) {

                KeyEvent ke = (KeyEvent) event;
                Component comp = ke.getComponent();
                if (ke.getKeyCode() == KeyEvent.VK_LEFT) {
                    ImageView view = BrainFlow.get().getSelectedView();

                    if (/*view.hasFocus() || */ parentIsImageView(comp)) {
                        previousSliceCommand.execute();
                    }
                } else if (ke.getKeyCode() == KeyEvent.VK_RIGHT) {
                    ImageView view = BrainFlow.get().getSelectedView();

                    if ( /*view.hasFocus() */ parentIsImageView(comp)) {
                        nextSliceCommand.execute();
                    } else {
                        System.out.println("no focus");
                    }
                }

            }

        }
    }, AWTEvent.KEY_EVENT_MASK);

    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        public void eventDispatched(AWTEvent event) {
            if (event.getID() == MouseEvent.MOUSE_RELEASED) {
                MouseEvent me = (MouseEvent) event;
                if (me.isPopupTrigger()) {
                    showActionMenu(me);
                }
            }

        }
    }, AWTEvent.MOUSE_EVENT_MASK);

}

From source file:MouseNavigateTest.java

/**
 * @return true if this is the event that stops drag tracking behviour the
 *         default uses MOUSE_RELEASED.// ww w  . j  av  a  2s .  co m
 */
//*****************************************************************************
protected boolean isStopBehaviorEvent(java.awt.event.MouseEvent evt) {
    int nId = evt.getID();
    return (m_bDragging != false && nId == MouseEvent.MOUSE_RELEASED || nId == MouseEvent.MOUSE_EXITED);
}

From source file:MouseNavigateTest.java

/**
 * Registers which AWT events are of interest to the behaviour
 *//*from  ww w. j  a va  2  s .  c  o m*/
//*****************************************************************************
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).
 * /*from  ww w.  j  a  va 2 s.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;
}