Java Code Examples for java.awt.event.MouseEvent

The following are top voted examples for showing how to use java.awt.event.MouseEvent. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Reinickendorf_SER316   File: HTMLEditor.java   View source code 6 votes vote down vote up
private void maybeShowPopup(MouseEvent e) {
	if (e.isPopupTrigger()) {
		JPopupMenu popupMenu = new JPopupMenu();
		popupMenu.setFocusable(false);

		popupMenu.add(jMenuItemUndo);
		popupMenu.add(jMenuItemRedo);
		popupMenu.addSeparator();
		popupMenu.add(jMenuItemCut);
		popupMenu.add(jMenuItemCopy);
		popupMenu.add(jMenuItemPaste);
		popupMenu.addSeparator();
		if (jMenuItemInsCell.getAction().isEnabled()) {
			popupMenu.add(jMenuItemInsCell);
			jMenuItemInsCell.setEnabled(true);
			popupMenu.add(jMenuItemInsRow);
			jMenuItemInsRow.setEnabled(true);
			popupMenu.addSeparator();
		}
		popupMenu.add(jMenuItemProp);
		popupMenu.show(e.getComponent(), e.getX(), e.getY());

	}
}
 
Example 2
Project: SpotSpotter   File: CameraShot.java   View source code 6 votes vote down vote up
/**
 * Initialize the contents of the frame.
 */
private void initialize() {
	frame = new JFrame();
	frame.setBounds(100, 100, 800, 450);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.getContentPane().setLayout(null);

	final JButton btnNewButton = new JButton("\u62CD\u7167");
	btnNewButton.addMouseListener(new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent arg0) {
			flag = 1;// ��̬��������Ϊ1���Ӷ����°�ťʱ��ֹͣ����ͷ�ĵ���
		}
	});
	btnNewButton.setBounds(33, 13, 113, 27);
	frame.getContentPane().add(btnNewButton);

	label = new JLabel("");
	label.setBounds(0, 0, 800, 450);
	frame.getContentPane().add(label);
}
 
Example 3
Project: Equella   File: WorkflowTree.java   View source code 6 votes vote down vote up
@Override
public void mousePressed(final MouseEvent e)
{
	if( e.getButton() == MouseEvent.BUTTON3 )
	{
		setSelectionPath(getPathForLocation(e.getX(), e.getY()));
	}
	final WorkflowNode node = getSelectedNode();
	final boolean canedit = node != null && node.getParent() != model.getRoot();
	visible = (node == null && model.getRootNode() == null) || (node != null && node.canAddChildren());

	add.setVisible(visible);
	edit.setVisible(canedit);
	remove.setVisible(canedit);
	visible |= node != null;
}
 
Example 4
Project: VASSAL-src   File: Map.java   View source code 6 votes vote down vote up
/**
 * Mouse events are first translated into map coordinates.
 * Then the event is forwarded to the top MouseListener in the
 * stack, if any, otherwise forwarded to all LocalMouseListeners.
 *
 * @see #pushMouseListener
 * @see #popMouseListener
 * @see #addLocalMouseListener
 */
public void mouseReleased(MouseEvent e) {
  Point p = e.getPoint();
  p.translate(theMap.getX(), theMap.getY());
  if (theMap.getBounds().contains(p)) {
    if (!mouseListenerStack.isEmpty()) {
      p = mapCoordinates(e.getPoint());
      e.translatePoint(p.x - e.getX(), p.y - e.getY());
      mouseListenerStack.get(mouseListenerStack.size()-1).mouseReleased(e);
    }
    else if (multicaster != null) {
      p = mapCoordinates(e.getPoint());
      e.translatePoint(p.x - e.getX(), p.y - e.getY());
      multicaster.mouseReleased(e);
    }
    // Request Focus so that keyboard input will be recognized
    theMap.requestFocus();
  }
  // Clicking with mouse always repaints the map
  clearFirst = true;
  theMap.repaint();
  activeMap = this;
}
 
Example 5
Project: cuttlefish   File: PopupMousePlugin.java   View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected void handlePopup(MouseEvent e) {
       final VisualizationViewer<V,E> vv =
               (VisualizationViewer<V,E>)e.getSource();
       Point2D p = e.getPoint();
       
       GraphElementAccessor<V,E> pickSupport = vv.getPickSupport();
       if(pickSupport != null) {
           final V v = pickSupport.getVertex(vv.getGraphLayout(), p.getX(), p.getY());
           if(v != null) {
               updateVertexMenu(v, networkPanel, p);
               vertexPopup.show(vv, e.getX(), e.getY());
           } else {
               final E edge = pickSupport.getEdge(vv.getGraphLayout(), p.getX(), p.getY());
               if(edge != null) {
                   updateEdgeMenu(edge, networkPanel, p);
                   edgePopup.show(vv, e.getX(), e.getY());              
               }
           }
       }
   }
 
Example 6
Project: A-Pathfinding-Visualization   File: Frame.java   View source code 6 votes vote down vote up
@Override
// Track mouse on movement
public void mouseMoved(MouseEvent e) {
	int x = e.getX();
	int y = e.getY();
	int height = this.getHeight();
	
	// Detects if mouse is within button panel
	if(x >= 10 && x <= 332 && y >= (height-96) && y <= (height-6)) {
		btnHover = true;
	}
	else {
		btnHover = false;
	}
	repaint();
}
 
Example 7
Project: DicomViewer   File: PanelController.java   View source code 5 votes vote down vote up
@Override
public void mousePressed(MouseEvent e) {
    if (e.isShiftDown()) return;
            
    e.getComponent().requestFocus();
    if (e.getButton() == MouseEvent.BUTTON1) {
        dragAnim.stop();
        bDragging = true;
        dragMem = e.getPoint();
        dragWhen = e.getWhen();
    }
}
 
Example 8
Project: The-Mysterious-Mind-Of-Jack   File: Mouse.java   View source code 5 votes vote down vote up
public void mouseDragged(MouseEvent e) {
	mouseX = e.getX();
	mouseY = e.getY();
	if (SwingUtilities.isLeftMouseButton(e)) {
		mouseB = 1;
	}
	if (SwingUtilities.isRightMouseButton(e)) {
		mouseB = 3;
	}

	MouseDraggedEvent event = new MouseDraggedEvent(e.getX(), e.getY(), mouseB);
	try {
		eventListener.onEvent(event);
	} catch (Exception ex) {}
}
 
Example 9
Project: JavaGraph   File: RuleTree.java   View source code 5 votes vote down vote up
@Override
public void mousePressed(MouseEvent evt) {
    TreePath path = getPathForLocation(evt.getX(), evt.getY());
    if (path != null) {
        if (evt.getButton() == MouseEvent.BUTTON3 && !isRowSelected(getRowForPath(path))) {
            setSelectionPath(path);
        }
        DisplayKind toDisplay = null;
        Object lastComponent = path.getLastPathComponent();
        if (lastComponent instanceof RuleTreeNode) {
            toDisplay = DisplayKind.RULE;
        } else if (lastComponent instanceof RecipeTreeNode) {
            toDisplay = DisplayKind.CONTROL;
        } else if (lastComponent instanceof MatchTreeNode
            && getSimulatorModel().getDisplay() != DisplayKind.LTS) {
            toDisplay = DisplayKind.STATE;
        }
        if (evt.getClickCount() == 1 && toDisplay != null) {
            getSimulatorModel().setDisplay(toDisplay);
        } else if (evt.getClickCount() == 2 && toDisplay != null) {
            if (toDisplay.hasResource()) {
                getActions().getEditAction(toDisplay.getResource())
                    .execute();
            }
        }
    }
    maybeShowPopup(evt);
}
 
Example 10
Project: candlelight   File: Console.java   View source code 5 votes vote down vote up
protected void onContentMouseReleasedEvent(MouseEvent e)
{
	Point mousePoint = e.getPoint();
	mousePoint.x -= 0.5F;
	int index = this.textContent.viewToModel(mousePoint);

	if (index == -1) return;

	StyledDocument doc = this.getDocument();
	Element element = doc.getCharacterElement(index);

	LinkHandler handler = LinkHandler.getLinkHandler(element.getAttributes());

	if (handler != null)
	{
		int begin = element.getStartOffset();
		int end = element.getEndOffset();
		String string = null;
		try
		{
			string = doc.getText(begin, end - begin);
		}
		catch (BadLocationException ex)
		{
			ex.printStackTrace();
		}

		if (string == null) return;

		handler.execute(this, doc, string, begin, end, element);
	}
}
 
Example 11
Project: TrabalhoFinalEDA2   File: mxGraphComponent.java   View source code 5 votes vote down vote up
/**
 * installs a handler to set the focus to the container.
 */
protected void installFocusHandler()
{
	graphControl.addMouseListener(new MouseAdapter()
	{
		public void mousePressed(MouseEvent e)
		{
			if (!hasFocus())
			{
				requestFocus();
			}
		}
	});
}
 
Example 12
Project: zencash-swing-wallet-ui   File: AddressBookPanel.java   View source code 5 votes vote down vote up
@Override
public void mousePressed(MouseEvent e) {
    if (e.isConsumed() || (!e.isPopupTrigger()))
        return;

    int row = table.rowAtPoint(e.getPoint());
    int column = table.columnAtPoint(e.getPoint());
    table.changeSelection(row, column, false, false);
    AddressBookEntry entry = entries.get(row);
    
    JPopupMenu menu = new JPopupMenu();
    
    JMenuItem sendCash = new JMenuItem("Send ZEN to "+entry.name);
    sendCash.addActionListener(new SendCashActionListener());
    menu.add(sendCash);
    
    JMenuItem copyAddress = new JMenuItem("Copy address to clipboard");
    copyAddress.addActionListener(new CopyToClipboardActionListener());
    menu.add(copyAddress);
    
    JMenuItem deleteEntry = new JMenuItem("Delete "+entry.name+" from contacts");
    deleteEntry.addActionListener(new DeleteAddressActionListener());
    menu.add(deleteEntry);
    
    menu.show(e.getComponent(), e.getPoint().x, e.getPoint().y);
    e.consume();
}
 
Example 13
Project: jaer   File: HumanVsComputerThrottleController.java   View source code 5 votes vote down vote up
private Point getPixel(MouseEvent e) {
    if (canvas == null) {
        return null;
    }
    Point p = canvas.getPixelFromMouseEvent(e);
    if (canvas.wasMousePixelInsideChipBounds()) {
        return p;
    } else {
        return null;
    }
}
 
Example 14
Project: openjdk-jdk10   File: MouseEventDriver.java   View source code 5 votes vote down vote up
@Override
public void clickMouse(ComponentOperator oper, int x, int y, int clickCount, int mouseButton,
        int modifiers, Timeout mouseClick) {

    moveMouse(oper, x, y);
    dispatchEvent(oper.getSource(),
            MouseEvent.MOUSE_ENTERED,
            0, x, y, 0,
            Operator.getDefaultMouseButton());
    dispatchEvent(oper.getSource(),
            MouseEvent.MOUSE_PRESSED,
            modifiers, x, y, 1,
            mouseButton);

    for (int i = 1; i < clickCount; i++) {
        dispatchEvent(oper.getSource(),
                MouseEvent.MOUSE_RELEASED,
                modifiers, x, y, i,
                mouseButton);
        dispatchEvent(oper.getSource(),
                MouseEvent.MOUSE_CLICKED,
                modifiers, x, y, i,
                mouseButton);
        dispatchEvent(oper.getSource(),
                MouseEvent.MOUSE_PRESSED,
                modifiers, x, y, i + 1,
                mouseButton);
    }

    mouseClick.sleep();
    dispatchEvent(oper.getSource(),
            MouseEvent.MOUSE_RELEASED,
            modifiers, x, y, clickCount,
            mouseButton);
    dispatchEvent(oper.getSource(),
            MouseEvent.MOUSE_CLICKED,
            modifiers, x, y, clickCount,
            mouseButton);
    exitMouse(oper);
}
 
Example 15
Project: openjdk-jdk10   File: WMouseDragGestureRecognizer.java   View source code 5 votes vote down vote up
/**
 * Invoked when a mouse button has been pressed on a component.
 */

@Override
public void mousePressed(MouseEvent e) {
    events.clear();

    if (mapDragOperationFromModifiers(e) != DnDConstants.ACTION_NONE) {
        try {
            motionThreshold = DragSource.getDragThreshold();
        } catch (Exception exc) {
            motionThreshold = 5;
        }
        appendEvent(e);
    }
}
 
Example 16
Project: incubator-netbeans   File: JExtendedTree.java   View source code 5 votes vote down vote up
public void processMouseEvent(MouseEvent e) {
    if (e instanceof MouseWheelEvent) {
        Component target = JExtendedTree.this.getParent();
        if (target == null || !(target instanceof JViewport))
            target = JExtendedTree.this;
        MouseEvent mwe = SwingUtilities.convertMouseEvent(
                JExtendedTree.this, (MouseWheelEvent)e, target);
        target.dispatchEvent((MouseWheelEvent)mwe);
    } else {
        super.processMouseEvent((MouseEvent)e);
    }
}
 
Example 17
Project: openjdk-jdk10   File: MotifDnDDropTargetProtocol.java   View source code 5 votes vote down vote up
/**
 * Reset the state of the object.
 */
public void cleanup() {
    // Clear the reference to this protocol.
    XDropTargetEventProcessor.reset();

    if (targetXWindow != null) {
        notifyProtocolListener(targetXWindow, 0, 0,
                               DnDConstants.ACTION_NONE, sourceActions,
                               null, MouseEvent.MOUSE_EXITED);
    }

    if (sourceWindow != 0) {
        XToolkit.awtLock();
        try {
            XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
            XlibWrapper.XSelectInput(XToolkit.getDisplay(), sourceWindow,
                                     sourceWindowMask);
            XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
        } finally {
            XToolkit.awtUnlock();
        }
    }

    sourceWindow = 0;
    sourceWindowMask = 0;
    sourceProtocolVersion = 0;
    sourceActions = DnDConstants.ACTION_NONE;
    sourceFormats = null;
    sourceAtom = 0;
    userAction = DnDConstants.ACTION_NONE;
    sourceX = 0;
    sourceY = 0;
    targetXWindow = null;
    topLevelLeavePostponed = false;
}
 
Example 18
Project: incubator-netbeans   File: WatchAnnotationProvider.java   View source code 5 votes vote down vote up
@Override
public void mouseExited(MouseEvent e) {
    if (lastFocusOwner != null) {
        lastFocusOwner.removeKeyListener(this);
        lastFocusOwner = null;
    }
    unsetSelectCursor();
}
 
Example 19
Project: jaer   File: EventFilter2DMouseAdaptor.java   View source code 5 votes vote down vote up
/**
 * Returns the chip pixel position from the MouseEvent.
 * Note that any calls that modify the GL model matrix (or viewport, etc) will make the location meaningless.
 * Make sure that your graphics rendering code wraps transforms inside pushMatrix and popMatrix calls.
 *
 * @param e the mouse event
 * @return the pixel position in the chip object, origin 0,0 in lower left
 * corner.
 */
protected Point getMousePixel(MouseEvent e) {
    if (chipCanvas == null) {
        return null;
    }
    Point p = chipCanvas.getPixelFromMouseEvent(e);
    if (chipCanvas.wasMousePixelInsideChipBounds()) {
        return p;
    } else {
        return null;
    }
}
 
Example 20
Project: myqq   File: Login.java   View source code 5 votes vote down vote up
/**
 * 处理窗体的拖拽事件
 * @param e
 */
public void mouseDrag(MouseEvent e)
{
	Point point = e.getLocationOnScreen();
	int offsetX = point.x - lastPoint.x;
	int offsetY = point.y - lastPoint.y;
	Rectangle bounds = this.getBounds();
	bounds.x += offsetX;
	bounds.y += offsetY;
	this.setBounds(bounds);
	lastPoint = point;
}
 
Example 21
Project: featurea   File: Util.java   View source code 5 votes vote down vote up
public static InputSource retrieveInputSourceFromMouseEvent(MouseEvent mouseEvent) {
    if (mouseEvent instanceof MouseWheelEvent) {
        return InputSource.MOUSE_WHEEL;
    }
    if (SwingUtilities.isLeftMouseButton(mouseEvent)) {
        return InputSource.TOUCH;
    }
    if (SwingUtilities.isRightMouseButton(mouseEvent)) {
        return InputSource.MOUSE_RIGHT;
    }
    return InputSource.TOUCH; // IMPORTANT
}
 
Example 22
Project: OpenJSharp   File: NervousText.java   View source code 5 votes vote down vote up
@Override
public synchronized void mousePressed(MouseEvent e) {
    e.consume();
    threadSuspended = !threadSuspended;
    if (!threadSuspended) {
        notify();
    }
}
 
Example 23
Project: alevin-svn2   File: MultiAlgoScenarioWizard.java   View source code 5 votes vote down vote up
private void updateSelection(MouseEvent e) {
	int row = networkTable.rowAtPoint(e.getPoint());
	if (row < 0) {
		networkTable.clearSelection();
	} else {
		networkTable.setRowSelectionInterval(row, row);
	}
}
 
Example 24
Project: JavaGraph   File: PropertiesDisplay.java   View source code 5 votes vote down vote up
@Override
public void mouseClicked(MouseEvent e) {
    if (e.getClickCount() == 2) {
        getActions().getEditSystemPropertiesAction()
            .execute();
    }
}
 
Example 25
Project: QN-ACTR-Release   File: KMeanSingleClusterScatter.java   View source code 5 votes vote down vote up
public void mousePressed(MouseEvent e) {
	// Controllo che la pressione del mouse risulti all'interno dell'area del grafico
	if ((e.getX() - UpperLeftGraph.x) >= 0 && (e.getY() - UpperLeftGraph.y) >= 0
			&& (e.getX() - UpperLeftGraph.x) < KMeanSingleClusterScatter.this.WIDTH
			&& (e.getY() - UpperLeftGraph.y) < KMeanSingleClusterScatter.this.HEIGHT) {
		// Start visualizzazione zoom area
		if (e.getButton() == MouseEvent.BUTTON1) {
			xStart = e.getX();
			yStart = e.getY();
			zoomming = true;
		}
	}
}
 
Example 26
Project: Equella   File: FlatterCheckBoxUI.java   View source code 5 votes vote down vote up
@Override
public synchronized void mousePressed(MouseEvent e)
{
	JComponent c = (JComponent) e.getComponent();
	if( c.isEnabled() )
	{
		c.setForeground(mTextPressed);
		c.setBackground(mBackgroundPressed);
		c.repaint();
	}
}
 
Example 27
Project: openjdk-jdk10   File: MissingDragExitEventTest.java   View source code 5 votes vote down vote up
@Override
public void mouseExited(final MouseEvent e) {
    if (!inside) {
        FAILED = true;
        Thread.dumpStack();
    }
    inside = false;
    MOUSE_EXIT = true;
}
 
Example 28
Project: incubator-netbeans   File: MultiSplitPane.java   View source code 5 votes vote down vote up
@Override
public void mouseReleased(MouseEvent e) {
    if( null == draggingDivider )
        return;
    
    final Point p = new Point( e.getPoint() );
    draggingDivider.finishDraggingTo( p );
    draggingDivider = null;
    setCursor( Cursor.getDefaultCursor() );
    e.consume();
}
 
Example 29
Project: incubator-netbeans   File: ListView.java   View source code 5 votes vote down vote up
@Override
public void mouseClicked(MouseEvent e) {
    if (MouseUtils.isDoubleClick(e)) {
        int index = list.locationToIndex(e.getPoint());
        performObjectAt(index, e.getModifiers());
    }
}
 
Example 30
Project: rapidminer   File: Item.java   View source code 5 votes vote down vote up
public void componentMouseReleased(MouseEvent e) {
	if (this.parentPane.getFilePane().isAutoArrange()) {
		this.setLocation(this.initPosition);
	} else {
		return;
	}
}
 
Example 31
Project: jmt   File: UpdatePanel.java   View source code 5 votes vote down vote up
@Override
public String getToolTipText(MouseEvent e) {
	String tip = null;
	Point p = e.getPoint();
	int rowIndex = rowAtPoint(p);
	try {
		tip = data.get(rowIndex).getToolTip();
	} catch (Exception e1) {
		e1.printStackTrace();
	}
	return tip;
}
 
Example 32
Project: Cognizant-Intelligent-Test-Scripter   File: Listeners.java   View source code 5 votes vote down vote up
@Override
public void mouseEntered(MouseEvent e) {
    JButton now = (JButton) e.getSource();
    if (!now.isSelected()) {
        now.setBorder(focusBorder);
    }
}
 
Example 33
Project: incubator-netbeans   File: MultiSplitPane.java   View source code 5 votes vote down vote up
@Override
public void mousePressed(MouseEvent e) {
    if( !Switches.isTopComponentResizingEnabled() )
        return;
    doLayout();
    MultiSplitDivider divider = dividerAtPoint( e.getPoint() );
    if( null == divider )
        return;
    
    draggingDivider = divider;
    divider.startDragging( e.getPoint() );
    e.consume();
}
 
Example 34
Project: incubator-netbeans   File: ProfilerTableHover.java   View source code 5 votes vote down vote up
public void mouseMoved(MouseEvent e) {
    // Do not display popup when a modifier is pressed (can't read all keys)
    if (e.getModifiers() != 0) return;
            
    Point point = e.getPoint();
    // Skip AWT noise after closing popup
    if (point.equals(forwardPoint)) return;
    
    checkPopup(table.rowAtPoint(point), table.columnAtPoint(point), point);
}
 
Example 35
Project: incubator-netbeans   File: ButtonPopupSwitcher.java   View source code 5 votes vote down vote up
@Override
public void mouseMoved(MouseEvent e) {
    e.consume();
    changeSelection(e);
    pTable.onMouseEvent(e);
    isDragging = false;
}
 
Example 36
Project: incubator-netbeans   File: HintsPanelLogic.java   View source code 5 votes vote down vote up
@Override
public void mouseClicked(MouseEvent e) {
    Point p = e.getPoint();
    TreePath path = errorTree.getPathForLocation(e.getPoint().x, e.getPoint().y);
    if ( path != null ) {
        Rectangle r = errorTree.getPathBounds(path);
        if (r != null) {
            r.width = r.height;
            if ( r.contains(p)) {
                toggle( path );
            }
        }
    }
}
 
Example 37
Project: TopDownGame   File: ControlMouse.java   View source code 4 votes vote down vote up
@Override
public void mouseClicked(MouseEvent e)
{
	
}
 
Example 38
Project: openjdk-jdk10   File: DrawTest.java   View source code 4 votes vote down vote up
@Override
public void mouseClicked(MouseEvent e) {
}
 
Example 39
Project: Logisim   File: Canvas.java   View source code 4 votes vote down vote up
@Override
protected void processMouseMotionEvent(MouseEvent e) {
	repairMouseEvent(e);
	super.processMouseMotionEvent(e);
}
 
Example 40
Project: incubator-netbeans   File: SnippetPanel.java   View source code 4 votes vote down vote up
public void mouseEntered(MouseEvent e) {
    title.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    title.setRollOver(true);
}