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:Main.java

public Point getClick() {
    EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
    while (true) {
        try {/*  ww w  .ja va2s.co  m*/
            AWTEvent evt = eq.getNextEvent();
            if (evt.getID() == MouseEvent.MOUSE_PRESSED) {
                MouseEvent mevt = (MouseEvent) evt;
                Point p = mevt.getPoint();
                Point top = getRootPane().getLocation();
                p.x -= top.x;
                p.y -= top.y;
                return p;
            }
        } catch (InterruptedException e) {
        }
    }
}

From source file:Main.java

public Point getClick() {
    EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
    System.out.println(eq.isDispatchThread());
    while (true) {
        try {// w  w  w.j  av a  2s  .  co  m
            AWTEvent evt = eq.getNextEvent();
            if (evt.getID() == MouseEvent.MOUSE_PRESSED) {
                MouseEvent mevt = (MouseEvent) evt;
                Point p = mevt.getPoint();
                Point top = getRootPane().getLocation();
                p.x -= top.x;
                p.y -= top.y;
                return p;
            }
        } catch (InterruptedException e) {
        }
    }
}

From source file:Main.java

public Point getClick() {
    EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();

    while (true) {
        try {//from w  w w.j a v  a 2  s.  c om
            AWTEvent pEvent = eq.peekEvent();

            AWTEvent evt = eq.getNextEvent();
            if (evt.getID() == MouseEvent.MOUSE_PRESSED) {
                MouseEvent mevt = (MouseEvent) evt;
                Point p = mevt.getPoint();
                Point top = getRootPane().getLocation();
                p.x -= top.x;
                p.y -= top.y;
                return p;
            }
        } catch (InterruptedException e) {
        }
    }
}

From source file:ItemEventComponent.java

public void processEvent(AWTEvent e) {
    if (e.getID() == MouseEvent.MOUSE_PRESSED) {
        if (itemListener != null) {
            selected = !selected;/* ww w .  ja  va  2  s  .c  o m*/
            i++;
            itemListener.itemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED,
                    getSelectedObjects(), (selected ? ItemEvent.SELECTED : ItemEvent.DESELECTED)));
        }
    }
}

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 ww w. j  av a2 s .  c o  m
 */
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:com.haulmont.cuba.desktop.sys.DesktopToolTipManager.java

protected DesktopToolTipManager() {
    closeTimer = new Timer(CLOSE_TIME, null);
    closeTimer.setRepeats(false);//from   www  . j av  a  2  s  .  c o m
    closeTimer.addActionListener(e -> {
        if (window != null) {
            window.hide();
            window = null;
            tooltipShowing = false;
            toolTipWindow.removeMouseListener(DesktopToolTipManager.this);
            component.removeMouseListener(DesktopToolTipManager.this);
        }
    });

    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        protected MouseEvent event;

        @Override
        public void eventDispatched(AWTEvent e) {
            if (!tooltipShowing) {
                return;
            }
            event = (MouseEvent) e;
            if (event.getID() == MouseEvent.MOUSE_PRESSED) {
                if (event.getComponent() != null && event.getComponent().isShowing()) {
                    if (!isPointInComponent(event.getLocationOnScreen(), toolTipWindow))
                        hideTooltip();
                } else
                    hideTooltip();
            }
        }
    }, AWTEvent.MOUSE_EVENT_MASK);
}

From source file:edu.umn.ecology.populus.plot.BasicPlotCanvas.java

/** The popup menu on the output screen accesses this function to dynamically modify
  the graph. When "optimized," the case values should be turned into constants somewhere
  for easier modification.*//*from  w w w. j  ava2 s.co  m*/

public void displayChartOptionScreen(int whatOption) {
    if (PopPreferencesStorage.isUseJFreeClass()) {
        //TODO

    } else {
        JCAxis h = chart.getChartArea().getHorizActionAxis();
        JCAxis v = chart.getChartArea().getVertActionAxis();
        switch (whatOption) {
        case MenuOptions.kCoarserGrid:
            coarserGrid();
            break;

        case MenuOptions.kFinerGrid:
            finerGrid();
            break;

        case MenuOptions.kClearGrid:
            h.setGridVisible(false);
            v.setGridVisible(false);
            break;

        case MenuOptions.kOptionScreen:
            /*this is kind of a "hacked" way of bringing up the customizer screen because unfortunately, the
               JClass people didn't provide an easier way to do this. but this works, so whatever.*/
            chart.mousePressed(new MouseEvent(this, MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(),
                    InputEvent.SHIFT_MASK, 0, 0, 1, false));
            break;

        case MenuOptions.kReset:
            h.setGridVisible(false);
            v.setGridVisible(false);
            chart.reset();
            break;
        }
    }
}

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  v a 2  s. c om
 */
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: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  ww  w .  j  a  v  a  2s  .c o  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:AppletMenuBarDemo.java

/** Called when a mouse event happens over the menubar */
protected void processMouseEvent(MouseEvent e) {
    int type = e.getID(); // What type of event?
    int item = findItemAt(e.getX()); // Over which menu label?

    if (type == MouseEvent.MOUSE_PRESSED) {
        // If it was a mouse down event, then pop up the menu
        if (item == -1)
            return;
        Dimension size = getSize();
        PopupMenu pm = (PopupMenu) menus.elementAt(item);
        if (pm != null)
            pm.show(this, startPositions[item] - 3, size.height);

    } else if (type == MouseEvent.MOUSE_EXITED) {
        // If the mouse left the menubar, then unhighlight
        if (highlightedItem != -1) {
            highlightedItem = -1;/*from ww w. jav  a  2s . co  m*/
            if (highlightColor != null)
                repaint();
        }
    } else if ((type == MouseEvent.MOUSE_MOVED) || (type == MouseEvent.MOUSE_ENTERED)) {
        // If the mouse moved, change the highlighted item, if necessary
        if (item != highlightedItem) {
            highlightedItem = item;
            if (highlightColor != null)
                repaint();
        }
    }
}