Java Code Examples for java.awt.event.MouseEvent.BUTTON1_MASK

The following are Jave code examples for showing how to use BUTTON1_MASK of the java.awt.event.MouseEvent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: powertext   File: RTextArea.java   View Source Code Vote up 5 votes
@Override
public void mouseDragged(MouseEvent e) {
	// WORKAROUND:  Since JTextComponent only updates the caret
	// location on mouse clicked and released, we'll do it on dragged
	// events when the left mouse button is clicked.
	if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
		Caret caret = getCaret();
		dot = caret.getDot();
		mark = caret.getMark();
		fireCaretUpdate(this);
	}
}
 
Example 2
Project: powertext   File: RTextArea.java   View Source Code Vote up 5 votes
@Override
public void mousePressed(MouseEvent e) {
	if (e.isPopupTrigger()) { // OS X popup triggers are on pressed
		showPopup(e);
	}
	else if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
		Caret caret = getCaret();
		dot = caret.getDot();
		mark = caret.getMark();
		fireCaretUpdate(this);
	}
}
 
Example 3
Project: freecol   File: CanvasMouseMotionListener.java   View Source Code Vote up 5 votes
/**
 * {@inheritDoc}
 */
@Override
public void mouseDragged(MouseEvent e) {
    if ((e.getModifiers() & MouseEvent.BUTTON1_MASK)
        != MouseEvent.BUTTON1_MASK) return; // Do not use getButton!
    performDragScrollIfActive(e);

    if (canvas.isGotoStarted()) {
        getGUI().updateGotoPath(canvas.convertToMapTile(e.getX(), e.getY()));
    } else if (canvas.isDrag(e.getX(), e.getY())) {
        canvas.startGoto();
    }            
}
 
Example 4
Project: FreeCol   File: CanvasMouseMotionListener.java   View Source Code Vote up 5 votes
/**
 * Invoked when the mouse has been dragged.
 *
 * @param e The MouseEvent that holds all the information.
 */
@Override
public void mouseDragged(MouseEvent e) {

    performDragScrollIfActive(e);

    Tile tile = canvas.convertToMapTile(e.getX(), e.getY());
    if (tile != null
        && ((e.getModifiers() & MouseEvent.BUTTON1_MASK)
            == MouseEvent.BUTTON1_MASK)) {
        // only perform the goto for the left mouse button
        if (canvas.isGotoStarted()) {
            Unit active = canvas.getActiveUnit();
            if (active == null) {
                canvas.stopGoto();
            } else if (lastTile != tile) {
                lastTile = tile;
                PathNode dragPath = active.findPath(tile);
                canvas.setGotoPath(dragPath);
            }
        } else {
            // Only start a goto if the drag is 16 pixels or more
            Point dragPoint = canvas.getDragPoint();
            int deltaX = Math.abs(e.getX() - dragPoint.x);
            int deltaY = Math.abs(e.getY() - dragPoint.y);
            if (deltaX >= DRAG_THRESHOLD || deltaY >= DRAG_THRESHOLD) {
                canvas.startGoto();
            }
        }
    }
}
 
Example 5
Project: incubator-netbeans   File: NonEditabilityTest.java   View Source Code Vote up 4 votes
public void testClickInvokesCustomEditor() throws Exception {
    if( !ExtTestCase.canSafelyRunFocusTests() )
        return;
    
    Node n = new ANode();
    setCurrentNode (n, sheet);

    sleep();

    requestFocus (sheet.table);
    sleep();

    Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
    if (owner == sheet.table) { //sanity check to avoid random failures on some window managers

        System.out.println ("About to click cell");

        Rectangle r = sheet.table.getCellRect(1, 1, false);
        final MouseEvent me = new MouseEvent (sheet.table, MouseEvent.MOUSE_PRESSED,
            System.currentTimeMillis(), MouseEvent.BUTTON1_MASK, r.x + 3,
            r.y + 3, 2, false);

        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                sheet.table.dispatchEvent(me);
            }
        });

        sleep();
        sleep();

        System.out.println ("Now checking focus");

        owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
        assertTrue ("Focus owner should be custom editor, not " + owner, owner instanceof JTextArea);

        JComponent jc = (JComponent) owner;
        assertTrue ("Custom editor should have been invoked, but focus owner's top level ancestor is not a dialog", jc.getTopLevelAncestor() instanceof Dialog);

        Dialog d = (Dialog) jc.getTopLevelAncestor();

        d.setVisible(false);
    }

    requestFocus (sheet.table);
    sleep();

    owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
    if (owner == sheet.table) { //sanity check to avoid random failures on some window managers
        pressKey(sheet.table, KeyEvent.VK_SPACE);
        sleep();

        owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
        assertTrue ("After pressing a key, focus owner should still be the table, not " + owner, sheet.table == owner);
    }

}
 
Example 6
Project: 2D-Elliptic-Mesh-Generator   File: PlotCanvas.java   View Source Code Vote up 4 votes
public void mouseClicked(MouseEvent e) {
    //System.out.println("PlotCanvas.mouseClicked");

    /*
     * System.out.println("PlotCanvas.mouseClicked"); System.out.println("
     * mouseClick = [" + mouseClick[0] + " " + mouseClick[1] + "]");
     * System.out.println(" mouseCurent = [" + mouseCurent[0] + " " +
     * mouseCurent[1] + "]");
     */
    mouseCurent[0] = e.getX();
    mouseCurent[1] = e.getY();
    e.consume();
    mouseClick[0] = mouseCurent[0];
    mouseClick[1] = mouseCurent[1];

    if (allowEdit) {
        if (e.getModifiers() == MouseEvent.BUTTON1_MASK && e.getClickCount() > 1) {
            for (int i = 0; i < grid.getAxis().length; i++) {
                if (grid.getAxis(i).isSelected(mouseClick, draw) != null) {
                    grid.getAxis(i).edit(this);
                    return;
                }
            }

            for (int i = 0; i < plots.size(); i++) {
                if (getPlot(i).isSelected(mouseClick, draw) != null) {
                    getPlot(i).edit(this);
                    return;
                }
            }
        }
    }

    if (!dragging && allowNote) {
        for (int i = 0; i < plots.size(); i++) {
            double[] _coordNoted = getPlot(i).isSelected(mouseClick, draw);
            if (e.getModifiers() == MouseEvent.BUTTON1_MASK) {
                if (_coordNoted != null) {
                    getPlot(i).noted = !getPlot(i).noted;
                } else {
                    getPlot(i).noted = false;
                }
            } else if (e.getModifiers() == MouseEvent.BUTTON3_MASK) {
                if (_coordNoted != null) {
                    if (getPlot(i).coordNoted != null) {
                        boolean alreadyNoted = true;
                        for (int j = 0; j < _coordNoted.length; j++) {
                            alreadyNoted = alreadyNoted && _coordNoted[j] == getPlot(i).coordNoted[j];
                        }
                        if (alreadyNoted) {
                            getPlot(i).coordNoted = null;
                        } else {
                            getPlot(i).coordNoted = _coordNoted;
                        }
                    } else {
                        getPlot(i).coordNoted = _coordNoted;
                    }
                }
            }
        }
        repaint();
    } else {
        dragging = false;
    }
}
 
Example 7
Project: ramus   File: CloseableTabbedPane.java   View Source Code Vote up 4 votes
/**
 * Processes all caught <code>MouseEvent</code>s.
 *
 * @param e the <code>MouseEvent</code>
 */
private void processMouseEvents(MouseEvent e) {
    int tabNumber = getUI().tabForCoordinate(this, e.getX(), e.getY());
    if (tabNumber < 0)
        return;
    CloseTabIcon icon = (CloseTabIcon) getIconAt(tabNumber);
    if (icon != null) {
        Rectangle rect = icon.getBounds();
        Point pos = headerViewport == null ? new Point() : headerViewport
                .getViewPosition();
        Rectangle drawRect = new Rectangle(rect.x - pos.x, rect.y - pos.y,
                rect.width, rect.height);

        if (e.getID() == MouseEvent.MOUSE_PRESSED) {
            icon.mousepressed = e.getModifiers() == MouseEvent.BUTTON1_MASK;
            repaint(drawRect);
        } else if (e.getID() == MouseEvent.MOUSE_MOVED
                || e.getID() == MouseEvent.MOUSE_DRAGGED
                || e.getID() == MouseEvent.MOUSE_CLICKED) {
            pos.x += e.getX();
            pos.y += e.getY();
            if (rect.contains(pos)) {
                if (e.getID() == MouseEvent.MOUSE_CLICKED) {
                    int selIndex = getSelectedIndex();
                    if (fireCloseTab(selIndex)) {
                        if (selIndex > 0) {
                            // to prevent uncatchable null-pointers
                            Rectangle rec = getUI().getTabBounds(this,
                                    selIndex - 1);

                            MouseEvent event = new MouseEvent((Component) e
                                    .getSource(), e.getID() + 1, System
                                    .currentTimeMillis(), e.getModifiers(),
                                    rec.x, rec.y, e.getClickCount(), e
                                    .isPopupTrigger(), e
                                    .getButton());
                            dispatchEvent(event);
                        }
                        // the tab is being closed
                        // removeTabAt(tabNumber);
                        remove(selIndex);
                    } else {
                        icon.mouseover = false;
                        icon.mousepressed = false;
                        repaint(drawRect);
                    }
                } else {
                    icon.mouseover = true;
                    icon.mousepressed = e.getModifiers() == MouseEvent.BUTTON1_MASK;
                }
            } else {
                icon.mouseover = false;
            }
            repaint(drawRect);
        }
    }
}
 
Example 8
Project: WordnetLoom   File: CloseableTabbedPane.java   View Source Code Vote up 4 votes
/**
 * Processes all caught <code>MouseEvent</code>s.
 *
 * @param e the <code>MouseEvent</code>
 */
private void processMouseEvents(MouseEvent e) {

    int tabNumber = getUI().tabForCoordinate(this, e.getX(), e.getY());

    if (tabNumber < 0) {
        return;
    }

    CloseTabIcon icon = (CloseTabIcon) getIconAt(tabNumber);

    if (icon != null) {
        // TODO: draw states of button '+'
        if (icon instanceof AddTabIcon && (e.getID() == MouseEvent.MOUSE_CLICKED)) {
            tabButtonPressed();
            return;
        }

        /* allow all tabs closing feature */
        if (getTabCount() <= (allowAllTabsClosing ? (addTabLabel != null ? 1 : 0)
                : addTabLabel != null ? 2 : 1)) {
            return;
        }

        Rectangle rect = icon.getBounds();
        Point pos = headerViewport == null ? new Point() : headerViewport
                .getViewPosition();
        Rectangle drawRect = new Rectangle(rect.x - pos.x, rect.y - pos.y,
                rect.width, rect.height);

        if (e.getID() == MouseEvent.MOUSE_PRESSED) {
            icon.mousepressed = e.getModifiers() == MouseEvent.BUTTON1_MASK;
            repaint(drawRect);
        } else if (e.getID() == MouseEvent.MOUSE_MOVED
                || e.getID() == MouseEvent.MOUSE_DRAGGED
                || e.getID() == MouseEvent.MOUSE_CLICKED) {
            pos.x += e.getX();
            pos.y += e.getY();
            if (rect.contains(pos)) {
                if (e.getID() == MouseEvent.MOUSE_CLICKED) {
                    int selIndex = getSelectedIndex();
                    if (fireCloseTab(selIndex)) {
                        if (selIndex > 0) {
                            // to prevent uncatchable null-pointers
                            Rectangle rec = getUI().getTabBounds(this,
                                    selIndex - 1);

                            MouseEvent event = new MouseEvent((Component) e
                                    .getSource(), e.getID() + 1, System
                                    .currentTimeMillis(), e.getModifiers(),
                                    rec.x, rec.y, e.getClickCount(), e
                                    .isPopupTrigger(), e
                                    .getButton());
                            dispatchEvent(event);
                        }
                        // the tab is being closed
                        // removeTabAt(tabNumber);
                        //remove(selIndex);
                        removeTabAt(selIndex);
                    } else {
                        icon.mouseover = false;
                        icon.mousepressed = false;
                        repaint(drawRect);
                    }
                } else {
                    icon.mouseover = true;
                    icon.mousepressed = e.getModifiers() == MouseEvent.BUTTON1_MASK;
                }
            } else {
                icon.mouseover = false;
            }
            repaint(drawRect);
        }
    }
}