Java Code Examples for java.awt.event.MouseEvent#isPopupTrigger()

The following examples show how to use java.awt.event.MouseEvent#isPopupTrigger() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JTreeTable.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Overridden to return false, and if the event is a mouse event
 * it is forwarded to the tree.<p>
 * The behavior for this is debatable, and should really be offered
 * as a property. By returning false, all keyboard actions are
 * implemented in terms of the table. By returning true, the
 * tree would get a chance to do something with the keyboard
 * events. For the most part this is ok. But for certain keys,
 * such as left/right, the tree will expand/collapse where as
 * the table focus should really move to a different column. Page
 * up/down should also be implemented in terms of the table.
 * By returning false this also has the added benefit that clicking
 * outside of the bounds of the tree node, but still in the tree
 * column will select the row, whereas if this returned true
 * that wouldn't be the case.
 * <p>By returning false we are also enforcing the policy that
 * the tree will never be editable (at least by a key sequence).
 * @param e
 * @return true if cell editable
 */
@Override
public boolean isCellEditable(EventObject e)
{
	if (e instanceof MouseEvent)
	{
		for (int counter = getColumnCount() - 1; counter >= 0; counter--)
		{
			if (getColumnClass(counter) == TreeTableNode.class)
			{
				MouseEvent me = (MouseEvent) e;
				int column = JTreeTable.this.columnAtPoint(me.getPoint());
				Rectangle cell = JTreeTable.this.getCellRect(0, column, true);
				MouseEvent newME = new MouseEvent(tree, me.getID(), me.getWhen(), me.getModifiers(), me.getX(),
					me.getY(), me.getClickCount(), me.isPopupTrigger());
				//we translate the event into the tree's coordinate system
				newME.translatePoint(-cell.x, 0);
				tree.dispatchEvent(newME);

				break;
			}
		}
	}

	return false;
}
 
Example 2
Source File: PopupMenuHandler.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void maybeShowPopupMenu(MouseEvent event) {
    if (event.isPopupTrigger()) {
        if (event.getComponent().isVisible()) {
            showPopupMenu(event);
        }
    }
}
 
Example 3
Source File: JTreeTable.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Overridden to return false, and if the event is a mouse event it is
 * forwarded to the tree.
 * <p/>
 * <
 * p/>
 * The behavior for this is debatable, and should really be offered as
 * a property. By returning false, all keyboard actions are
 * implemented in terms of the table. By returning true, the tree
 * would get a chance to do something with the keyboard events. For
 * the most part this is ok. But for certain keys, such as left/right,
 * the tree will expand/collapse where as the table focus should
 * really move to a different column. Page up/down should also be
 * implemented in terms of the table. By returning false this also has
 * the added benefit that clicking outside of the bounds of the tree
 * node, but still in the tree column will select the row, whereas if
 * this returned true that wouldn't be the case. </p>
 * <p/>
 * <
 * p/>
 * By returning false we are also enforcing the policy that the tree
 * will never be editable (at least by a key sequence). </p>
 */
@Override
public boolean isCellEditable (EventObject e)
{
    if (e instanceof MouseEvent) {
        for (int counter = getColumnCount() - 1; counter >= 0;
                counter--) {
            if (getColumnClass(counter) == TreeTableModel.class) {
                MouseEvent me = (MouseEvent) e;
                MouseEvent newME = new MouseEvent(
                        tree,
                        me.getID(),
                        me.getWhen(),
                        me.getModifiers(),
                        me.getX() - getCellRect(0, counter, true).x,
                        me.getY(),
                        me.getClickCount(),
                        me.isPopupTrigger());
                tree.dispatchEvent(newME);

                break;
            }
        }
    }

    return false;
}
 
Example 4
Source File: ProfilerTabbedPane.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
protected void processMouseEvent(MouseEvent e) {
    int index = indexAtLocation(e.getX(), e.getY());
    
    if (index != -1) {
        if (e.isPopupTrigger()) {
            // Show popup menu for the clicked tab
            final MouseEvent _e = e;
            final int _index = index;
            final Component _component = getComponentAt(index);
            
            SwingUtilities.invokeLater(new Runnable() {
                public void run() { showPopupMenu(_index, _component, _e); };
            });
            
            e.consume();
            return;
        } else if (e.getID() == MouseEvent.MOUSE_CLICKED && SwingUtilities.isMiddleMouseButton(e)) {
            // Close tab using middle button click
            if (isClosableAt(index)) closeTab(getComponentAt(index));
            
            e.consume();
            return;
        } else if (e.getID() == MouseEvent.MOUSE_PRESSED && !SwingUtilities.isLeftMouseButton(e)) {
            // Do not switch tabs using middle or right mouse button
            e.consume();
            return;
        }
    }
    
    super.processMouseEvent(e);
}
 
Example 5
Source File: JCriteriumTree.java    From binnavi with Apache License 2.0 5 votes vote down vote up
@Override
public void mousePressed(final MouseEvent event) {
  m_currentCriteriumPath = getPathForLocation(event.getX(), event.getY());

  if (event.isPopupTrigger()) {
    showPopupMenu(event);
  }
}
 
Example 6
Source File: BaseChartPanel.java    From nmonvisualizer with Apache License 2.0 5 votes vote down vote up
@Override
public void mouseReleased(MouseEvent event) {
    if (event.isPopupTrigger()) {
        clickLocation = new Point(event.getX(), event.getY());
    }

    super.mouseReleased(event);
}
 
Example 7
Source File: mxGraphHandler.java    From blog-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 
 */
public void mousePressed(MouseEvent e)
{
	if (graphComponent.isEnabled() && isEnabled() && !e.isConsumed()
			&& !graphComponent.isForceMarqueeEvent(e))
	{
		cell = graphComponent.getCellAt(e.getX(), e.getY(), false);
		initialCell = cell;

		if (cell != null)
		{
			if (isSelectEnabled()
					&& !graphComponent.getGraph().isCellSelected(cell))
			{
				graphComponent.selectCellForEvent(cell, e);
				cell = null;
			}

			// Starts move if the cell under the mouse is movable and/or any
			// cells of the selection are movable
			if (isMoveEnabled() && !e.isPopupTrigger())
			{
				start(e);
				e.consume();
			}
		}
		else if (e.isPopupTrigger())
		{
			graphComponent.getGraph().clearSelection();
		}
	}
}
 
Example 8
Source File: AdjudicationTablePanelMouseListener.java    From mae-annotation with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void mouseReleased(MouseEvent e) {

    if (e.isPopupTrigger()) {
        createAndShowContextMenu(e);
    } else if (e.getClickCount() == 2) {
        // TODO: 2016-02-07 14:53:35EST copy to gold, if the row is not GS
    }
}
 
Example 9
Source File: EditorPatternLabel.java    From SikuliX1 with MIT License 5 votes vote down vote up
private void checkPopup(MouseEvent me) {
  if (me.isPopupTrigger()) {
    wasPopup = true;
    popMenu = pane.getPopMenuImage();
    if (popMenu != null) {
      if (imgpop != null && imgpop.isShowing()) {
        showPopup(false);
      }
      popMenu.show(this, me.getX(), me.getY());
    }
    return;
  }
}
 
Example 10
Source File: ManagementModel.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void mouseReleased(MouseEvent e) {
    if (!e.isPopupTrigger()) return;
    showPopup(e);
}
 
Example 11
Source File: HistoryFileView.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void mousePressed(MouseEvent e) {
    pressedPopup = e.isPopupTrigger();
}
 
Example 12
Source File: PopupHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void mousePressed(MouseEvent e) {
  if (e.isPopupTrigger()) {
    invokePopup(e.getComponent(), e.getX(), e.getY());
    e.consume();
  }
}
 
Example 13
Source File: ProjectTreeMouseHandler.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void mouseReleased(MouseEvent e) {
  if (e.isPopupTrigger())
    handlePopupTriggerEvent(e);
}
 
Example 14
Source File: AquaPopupMenuUI.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public boolean isPopupTrigger(final MouseEvent e) {
    // Use the awt popup trigger code since this only runs on our OS!
    return e.isPopupTrigger();
}
 
Example 15
Source File: InstancesListControllerUI.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void mouseReleased(MouseEvent e) {
    int row = instancesListTable.rowAtPoint(e.getPoint());
    updateSelection(row);
    if (row != -1 && e.isPopupTrigger())
        showTablePopup(e.getComponent(), e.getX(), e.getY());
}
 
Example 16
Source File: LinkAndBrushChartPanel.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void mouseReleased(MouseEvent e) {

	// if we've been panning, we need to reset now that the mouse is
	// released...
	Rectangle2D zoomRectangle = (Rectangle2D) getChartFieldValueByName("zoomRectangle");
	Point2D zoomPoint = (Point2D) getChartFieldValueByName("zoomPoint");
	if (getChartFieldValueByName("panLast") != null) {
		setChartFieldValue(getChartFieldByName("panLast"), null);
		setCursor(Cursor.getDefaultCursor());
	} else if (zoomRectangle != null) {
		boolean hZoom = false;
		boolean vZoom = false;
		if ((PlotOrientation) getChartFieldValueByName("orientation") == PlotOrientation.HORIZONTAL) {
			hZoom = (Boolean) getChartFieldValueByName("rangeZoomable");
			vZoom = (Boolean) getChartFieldValueByName("domainZoomable");
		} else {
			hZoom = (Boolean) getChartFieldValueByName("domainZoomable");
			vZoom = (Boolean) getChartFieldValueByName("rangeZoomable");
		}

		boolean zoomTrigger1 = hZoom
				&& Math.abs(e.getX() - zoomPoint.getX()) >= (Integer) getChartFieldValueByName("zoomTriggerDistance");
		boolean zoomTrigger2 = vZoom
				&& Math.abs(e.getY() - zoomPoint.getY()) >= (Integer) getChartFieldValueByName("zoomTriggerDistance");
		if (zoomTrigger1 || zoomTrigger2) {
			if (hZoom && e.getX() < zoomPoint.getX() || vZoom && e.getY() < zoomPoint.getY()) {
				restoreAutoBounds();
			} else {
				double x, y, w, h;
				Rectangle2D screenDataArea = getScreenDataArea((int) zoomPoint.getX(), (int) zoomPoint.getY());
				double maxX = screenDataArea.getMaxX();
				double maxY = screenDataArea.getMaxY();
				// for mouseReleased event, (horizontalZoom || verticalZoom)
				// will be true, so we can just test for either being false;
				// otherwise both are true
				if (!vZoom) {
					x = zoomPoint.getX();
					y = screenDataArea.getMinY();
					w = Math.min(zoomRectangle.getWidth(), maxX - zoomPoint.getX());
					h = screenDataArea.getHeight();
				} else if (!hZoom) {
					x = screenDataArea.getMinX();
					y = zoomPoint.getY();
					w = screenDataArea.getWidth();
					h = Math.min(zoomRectangle.getHeight(), maxY - zoomPoint.getY());
				} else {
					x = zoomPoint.getX();
					y = zoomPoint.getY();
					w = Math.min(zoomRectangle.getWidth(), maxX - zoomPoint.getX());
					h = Math.min(zoomRectangle.getHeight(), maxY - zoomPoint.getY());
				}
				Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h);
				zoom(zoomArea);
			}
			setChartFieldValue(getChartFieldByName("zoomPoint"), null);
			setChartFieldValue(getChartFieldByName("zoomRectangle"), null);
		} else {
			// erase the zoom rectangle
			Graphics2D g2 = (Graphics2D) getGraphics();
			if ((Boolean) getChartFieldValueByName("useBuffer")) {
				repaint();
			} else {
				drawZoomRectangle(g2, true);
			}
			g2.dispose();
			setChartFieldValue(getChartFieldByName("zoomPoint"), null);
			setChartFieldValue(getChartFieldByName("zoomRectangle"), null);
		}

	}

	else if (e.isPopupTrigger()) {
		if (getChartFieldValueByName("popup") != null) {
			displayPopupMenu(e.getX(), e.getY());
		}
	}

}
 
Example 17
Source File: ClassesListControllerUI.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void mousePressed(final MouseEvent e) {
    final int row = classesListTable.rowAtPoint(e.getPoint());
    updateSelection(row);
    if (e.isPopupTrigger()) showPopupMenu(row, e.getX(), e.getY());
}
 
Example 18
Source File: ChartPanel.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Handles a 'mouse released' event.  On Windows, we need to check if this
 * is a popup trigger, but only if we haven't already been tracking a zoom
 * rectangle.
 *
 * @param e  information about the event.
 */
@Override
public void mouseReleased(MouseEvent e) {

    // if we've been panning, we need to reset now that the mouse is 
    // released...
    if (this.panLast != null) {
        this.panLast = null;
        setCursor(Cursor.getDefaultCursor());
    }

    else if (this.zoomRectangle != null) {
        boolean hZoom, vZoom;
        if (this.orientation == PlotOrientation.HORIZONTAL) {
            hZoom = this.rangeZoomable;
            vZoom = this.domainZoomable;
        }
        else {
            hZoom = this.domainZoomable;
            vZoom = this.rangeZoomable;
        }

        boolean zoomTrigger1 = hZoom && Math.abs(e.getX()
            - this.zoomPoint.getX()) >= this.zoomTriggerDistance;
        boolean zoomTrigger2 = vZoom && Math.abs(e.getY()
            - this.zoomPoint.getY()) >= this.zoomTriggerDistance;
        if (zoomTrigger1 || zoomTrigger2) {
            if ((hZoom && (e.getX() < this.zoomPoint.getX()))
                || (vZoom && (e.getY() < this.zoomPoint.getY()))) {
                restoreAutoBounds();
            }
            else {
                double x, y, w, h;
                Rectangle2D screenDataArea = getScreenDataArea(
                        (int) this.zoomPoint.getX(),
                        (int) this.zoomPoint.getY());
                double maxX = screenDataArea.getMaxX();
                double maxY = screenDataArea.getMaxY();
                // for mouseReleased event, (horizontalZoom || verticalZoom)
                // will be true, so we can just test for either being false;
                // otherwise both are true
                if (!vZoom) {
                    x = this.zoomPoint.getX();
                    y = screenDataArea.getMinY();
                    w = Math.min(this.zoomRectangle.getWidth(),
                            maxX - this.zoomPoint.getX());
                    h = screenDataArea.getHeight();
                }
                else if (!hZoom) {
                    x = screenDataArea.getMinX();
                    y = this.zoomPoint.getY();
                    w = screenDataArea.getWidth();
                    h = Math.min(this.zoomRectangle.getHeight(),
                            maxY - this.zoomPoint.getY());
                }
                else {
                    x = this.zoomPoint.getX();
                    y = this.zoomPoint.getY();
                    w = Math.min(this.zoomRectangle.getWidth(),
                            maxX - this.zoomPoint.getX());
                    h = Math.min(this.zoomRectangle.getHeight(),
                            maxY - this.zoomPoint.getY());
                }
                Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h);
                zoom(zoomArea);
            }
            this.zoomPoint = null;
            this.zoomRectangle = null;
        }
        else {
            // erase the zoom rectangle
            Graphics2D g2 = (Graphics2D) getGraphics();
            if (this.useBuffer) {
                repaint();
            }
            else {
                drawZoomRectangle(g2, true);
            }
            g2.dispose();
            this.zoomPoint = null;
            this.zoomRectangle = null;
        }

    }

    else if (e.isPopupTrigger()) {
        if (this.popup != null) {
            displayPopupMenu(e.getX(), e.getY());
        }
    }

}
 
Example 19
Source File: ServicePanel.java    From megan-ce with GNU General Public License v3.0 4 votes vote down vote up
public void mousePressed(MouseEvent e) {
    if (e.isPopupTrigger()) {
        showPopupMenu(e);
    }
}
 
Example 20
Source File: TextPanelMouseListener.java    From mae-annotation with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void mouseReleased(MouseEvent e) {
    if (e.isPopupTrigger()) {
        createAndShowContextMenu(e);
    }
}