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

The following examples show how to use java.awt.event.MouseEvent#getWhen() . 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 JsDroidCmd with Mozilla Public License 2.0 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).
 */
@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 2
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 3
Source File: CategoryList.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void mouseClicked(MouseEvent e) {
    if( !list.isEnabled() )
        return;
    
    if( e.getClickCount() > 1 ) {
        selIndex = getValidIndex( e.getPoint() );
        if( selIndex >= 0 ) {
            list.setSelectedIndex( selIndex );
            Item item = (Item)list.getModel().getElementAt( selIndex );
            ActionEvent ae = new ActionEvent( e.getSource(), e.getID(), "doubleclick", e.getWhen(), e.getModifiers() );
            item.invokePreferredAction( ae );
            e.consume();
        }
    }
}
 
Example 4
Source File: TranslateMouseListener.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
private MouseEvent translateEvent(MouseEvent e)
{
	Dimension stretchedDimensions = client.getStretchedDimensions();
	Dimension realDimensions = client.getRealDimensions();

	int newX = (int) (e.getX() / (stretchedDimensions.width / realDimensions.getWidth()));
	int newY = (int) (e.getY() / (stretchedDimensions.height / realDimensions.getHeight()));

	MouseEvent mouseEvent = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiersEx(),
		newX, newY, e.getClickCount(), e.isPopupTrigger(), e.getButton());
	if (e.isConsumed())
	{
		mouseEvent.consume();
	}
	return mouseEvent;
}
 
Example 5
Source File: EditableLabel.java    From jace with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void mousePressed(MouseEvent e) {
    if (isEditing) {
        return;
    }
    activateEdit();
    // This next bit will generate a second mouse event and pass it on to the edit component so that 
    // the edit cursor appears under the mouse pointer, not a the start of the component.
    final MouseEvent e2 = new MouseEvent(editComponent, e.getID(), e.getWhen(), e.getModifiers(), e.getX(), e.getY(), e.getClickCount(), e.isPopupTrigger(), e.getButton());
    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            editComponent.dispatchEvent(e2);
        }
    });
}
 
Example 6
Source File: JTreeTable.java    From opensim-gui with Apache License 2.0 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).
 */
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 7
Source File: TranslateMouseListener.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private MouseEvent translateEvent(MouseEvent e)
{
	Dimension stretchedDimensions = client.getStretchedDimensions();
	Dimension realDimensions = client.getRealDimensions();

	int newX = (int) (e.getX() / (stretchedDimensions.width / realDimensions.getWidth()));
	int newY = (int) (e.getY() / (stretchedDimensions.height / realDimensions.getHeight()));

	MouseEvent mouseEvent = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiersEx(),
		newX, newY, e.getClickCount(), e.isPopupTrigger(), e.getButton());
	if (e.isConsumed())
	{
		mouseEvent.consume();
	}
	return mouseEvent;
}
 
Example 8
Source File: JTreeTable.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected MouseEvent convertEvent(MouseEvent e){
  int column = 0;
  int row = rowAtPoint(e.getPoint());

  //move the event from table to tree coordinates
  Rectangle tableCellRect = getCellRect(row, column, false);
  Rectangle treeCellRect = tree.getRowBounds(row);
  int dx = 0;
  if(tableCellRect != null) dx = -tableCellRect.x;
  int dy = 0;
  if(tableCellRect !=null && treeCellRect != null)
    dy = treeCellRect.y -tableCellRect.y;
  e.translatePoint(dx, dy);


  return new MouseEvent(
    tree, e.getID(), e.getWhen(), e.getModifiers(),
    e.getX(), e.getY(), e.getClickCount(), e.isPopupTrigger()
  );
}
 
Example 9
Source File: InfoWindow.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void mouseClicked(MouseEvent e) {
    // hide the balloon by any click
    hide();
    if (e.getButton() == MouseEvent.BUTTON1) {
        ActionEvent aev = new ActionEvent(target, ActionEvent.ACTION_PERFORMED,
                                          liveArguments.getActionCommand(),
                                          e.getWhen(), e.getModifiers());
        XToolkit.postEvent(XToolkit.targetToAppContext(aev.getSource()), aev);
    }
}
 
Example 10
Source File: VisualGraphView.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public MouseEvent translateMouseEventFromVertexToViewSpace(V v, MouseEvent e) {
	Point viewerPoint = translatePointFromVertexToViewSpace(v, e.getPoint());
	VisualizationViewer<V, E> newSource = getPrimaryGraphViewer();
	return new MouseEvent(newSource, e.getID(), e.getWhen(), e.getModifiers(),
		(int) viewerPoint.getX(), (int) viewerPoint.getY(), e.getClickCount(),
		e.isPopupTrigger(), e.getButton());
}
 
Example 11
Source File: TreeTable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean editCellAt(int row, int column, EventObject e) {
  boolean editResult = super.editCellAt(row, column, e);
  if (e instanceof MouseEvent && isTreeColumn(column)){
    MouseEvent me = (MouseEvent)e;
    int y = me.getY();

    if (getRowHeight() != myTree.getRowHeight()) {
      // fix y if row heights are not equal
      // [todo]: review setRowHeight to synchronize heights correctly!
      final Rectangle tableCellRect = getCellRect(row, column, true);
      y = Math.min(y - tableCellRect.y, myTree.getRowHeight() - 1) + row * myTree.getRowHeight();
    }

    MouseEvent newEvent = new MouseEvent(myTree, me.getID(),
                                         me.getWhen(), me.getModifiers(),
                                         me.getX() - getCellRect(0, column, true).x,
                                         y, me.getClickCount(),
                                         me.isPopupTrigger()
    );
    myTree.dispatchEvent(newEvent);

    // Some LAFs, for example, Aqua under MAC OS X
    // expand tree node by MOUSE_RELEASED event. Unfortunately,
    // it's not possible to find easy way to wedge in table's
    // event sequense. Therefore we send "synthetic" release event.
    if (newEvent.getID()==MouseEvent.MOUSE_PRESSED) {
      MouseEvent newME2 = new MouseEvent(
              myTree,
              MouseEvent.MOUSE_RELEASED,
              me.getWhen(), me.getModifiers(),
              me.getX() - getCellRect(0, column, true).x,
              y - getCellRect(0, column, true).y, me.getClickCount(),
              me.isPopupTrigger()
      );
      myTree.dispatchEvent(newME2);
    }
  }
  return editResult;
}
 
Example 12
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override protected void processMouseMotionEvent(MouseEvent e) {
  if (pointOutsidePrefSize(e.getPoint())) {
    MouseEvent ev = new MouseEvent(
        e.getComponent(), MouseEvent.MOUSE_EXITED, e.getWhen(),
        e.getModifiersEx(), e.getX(), e.getY(), e.getXOnScreen(), e.getYOnScreen(),
        e.getClickCount(), e.isPopupTrigger(), MouseEvent.NOBUTTON);
    super.processMouseEvent(ev);
  } else {
    super.processMouseMotionEvent(e);
  }
}
 
Example 13
Source File: BasicTabDisplayerUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void mousePressed(MouseEvent e) {
    int idx = updateMouseLocation(e);
    tabState.setPressed(idx);

    //One a double click, preserve the tab that was initially clicked, in case
    //a re-layout happened.  We'll pass that to the action.
    long time = e.getWhen();
    if (time - pressTime > 200) {
        lastPressedTab = idx;
    }
    pressTime = time;
    lastPressedTab = idx;
    if (idx != -1) {
        TabCellRenderer tcr = getTabCellRenderer(idx);
        getTabRect(idx, scratch);
        int state = tabState.getState(idx);

        //First find the command for the location with the default button -
        //TabState may trigger a repaint
        String command = tcr.getCommandAtPoint (e.getPoint(), state, scratch);
        if (TabDisplayer.COMMAND_CLOSE == command) {
            tabState.setCloseButtonContainsMouse(idx);
            tabState.setMousePressedInCloseButton(idx);

            //We're closing, don't try to maximize this tab if it turns out to be
            //a double click
            pressTime = -1;
            lastPressedTab = -1;
        }

        potentialCommand (idx, e, state, tcr, scratch);
    } else {
        tabState.setMousePressedInCloseButton(-1); //just in case
        if( e.isPopupTrigger() ) {
            displayer.repaint();
            performCommand (TabDisplayer.COMMAND_POPUP_REQUEST, -1, e);
        }
    }
}
 
Example 14
Source File: Dock.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void mousePressed(MouseEvent event) {
    DockLayoutNode over = over(event.getX(), event.getY());
    if (over instanceof DockLayout) {
        mDividerDragLayout = (DockLayout) over;
        mDividerDragStartedAt = event.getWhen();
        mDividerDragStartX = event.getX();
        mDividerDragStartY = event.getY();
        mDividerDragInitialEventPosition = mDividerDragLayout.isHorizontal() ? event.getX() : event.getY();
        mDividerDragInitialDividerPosition = mDividerDragLayout.getDividerPosition();
        mDividerDragIsValid = false;
        MouseCapture.start(this, mDividerDragLayout.isHorizontal() ? Cursors.HORIZONTAL_RESIZE : Cursors.VERTICAL_RESIZE);
    }
}
 
Example 15
Source File: VcsLogGraphTable.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private MouseEvent convertMouseEvent(@Nonnull MouseEvent e) {
  // create a new event, almost exactly the same, but in the header
  return new MouseEvent(e.getComponent(), e.getID(), e.getWhen(), e.getModifiers(), e.getX(), 0, e.getXOnScreen(), header.getY(),
                        e.getClickCount(), e.isPopupTrigger(), e.getButton());
}
 
Example 16
Source File: StrokeMouseSmoothingDemo.java    From pumpernickel with MIT License 4 votes vote down vote up
Input(MouseEvent e) {
	x = e.getX();
	y = e.getY();
	when = e.getWhen();
}
 
Example 17
Source File: JavaWindowsView.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
private void handleClick(MouseEvent e) {
    HeapViewerNodeAction.Actions nodeActions = HeapViewerNodeAction.Actions.forNode(windowNode, actionProviders, context, actions);
    ActionEvent ae = new ActionEvent(e.getSource(), e.getID(), "left button", e.getWhen(), e.getModifiers()); // NOI18N
    nodeActions.performDefaultAction(ae);
}
 
Example 18
Source File: TreeTable.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * This is overridden to forward the event to the tree and start editor timer.
 */
@Override
public boolean isCellEditable(EventObject e) {
    if (lastRow != -1) {
        TreePath tp = tree.getPathForRow(lastRow);
        org.openide.nodes.Node n = tp != null ? Visualizer.findNode(tp.getLastPathComponent()) : null;

        if ((n == null) || !n.canRename()) {
            //return false;
            canEdit = false;
        }
    }

    if (canEdit && (e != null) && (e.getSource() instanceof Timer)) {
        return true;
    }

    if (canEdit && shouldStartEditingTimer(e)) {
        startEditingTimer();
    } else if (shouldStopEditingTimer(e)) {
        timer.stop();
    }

    if (e instanceof MouseEvent) {
        MouseEvent me = (MouseEvent) e;
        int column = getTreeColumnIndex();

        if (SwingUtilities.isLeftMouseButton(me) && (me.getClickCount() == 2)) {
            TreePath path = tree.getPathForRow(TreeTable.this.rowAtPoint(me.getPoint()));
            Rectangle r = tree.getPathBounds(path);

            if ((me.getX() < (r.x - positionX)) || (me.getX() > (r.x - positionX + r.width))) {
                me.translatePoint(r.x - me.getX(), 0);
            }
        }

        MouseEvent newME = new MouseEvent(
                TreeTable.this.tree, me.getID(), me.getWhen(), me.getModifiers()+me.getModifiersEx(),
                me.getX() - getCellRect(0, column, true).x + positionX, me.getY(), me.getClickCount(),
                me.isPopupTrigger()
            );
        TreeTable.this.tree.dispatchEvent(newME);
    }

    return false;
}
 
Example 19
Source File: JavaWindowsView.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
private void handleMiddleClick(MouseEvent e) {
    HeapViewerNodeAction.Actions nodeActions = HeapViewerNodeAction.Actions.forNode(windowNode, actionProviders, context, actions);
    ActionEvent ae = new ActionEvent(e.getSource(), e.getID(), "middle button", e.getWhen(), e.getModifiers()); // NOI18N
    nodeActions.performMiddleButtonAction(ae);
}
 
Example 20
Source File: UIUtilities.java    From gcs with Mozilla Public License 2.0 3 votes vote down vote up
/**
 * Clones a {@link MouseEvent}.
 *
 * @param event       The event to clone.
 * @param source      Pass in a new source.
 * @param where       Pass in a new location.
 * @param refreshTime Pass in {@code true} to generate a new time stamp.
 * @return The new {@link MouseEvent}.
 */
public static final MouseEvent cloneMouseEvent(MouseEvent event, Component source, Point where, boolean refreshTime) {
    if (event instanceof MouseWheelEvent) {
        MouseWheelEvent old = (MouseWheelEvent) event;
        return new MouseWheelEvent(source, old.getID(), refreshTime ? System.currentTimeMillis() : event.getWhen(), old.getModifiersEx(), where.x, where.y, old.getClickCount(), old.isPopupTrigger(), old.getScrollType(), old.getScrollAmount(), old.getWheelRotation());
    }
    return new MouseEvent(source, event.getID(), refreshTime ? System.currentTimeMillis() : event.getWhen(), event.getModifiersEx(), where.x, where.y, event.getClickCount(), event.isPopupTrigger());
}