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

The following examples show how to use java.awt.event.MouseEvent#getPoint() . 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: ImportPreviewTable.java    From chipster with MIT License 6 votes vote down vote up
public void mouseDragged(MouseEvent e) {
	if(e.getSource() == this && screen.getCurrentStep() == ImportScreen.Step.FIRST){
		if(tableFrame.isInHeaderMarkingMode()){
			markHeaderAtPoint(e.getPoint());
		} else if(tableFrame.isInFooterMarkingMode()){
			markFooterAtPoint(e.getPoint());
		} else if(tableFrame.isInTitleMarkingMode()){
			markTitleAtPoint(e.getPoint(), false);
		}
	} else {
		markColumnsBetweenPoints(lastDragPoint, e.getPoint());
		if(this.columnAtPoint(e.getPoint()) == -1){
			// User dragged mouse out of the table. Do not set new last point
			return;
		} else {
			lastDragPoint = e.getPoint();
		}
	}
	updateHighlight(e);
}
 
Example 2
Source File: WMouseDragGestureRecognizer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Invoked when a mouse button is pressed on a component.
 */

@Override
public void mouseDragged(MouseEvent e) {
    if (!events.isEmpty()) { // gesture pending
        int dop = mapDragOperationFromModifiers(e);

        if (dop == DnDConstants.ACTION_NONE) {
            return;
        }

        MouseEvent trigger = (MouseEvent)events.get(0);


        Point      origin  = trigger.getPoint();
        Point      current = e.getPoint();

        int        dx      = Math.abs(origin.x - current.x);
        int        dy      = Math.abs(origin.y - current.y);

        if (dx > motionThreshold || dy > motionThreshold) {
            fireDragGestureRecognized(dop, ((MouseEvent)getTriggerEvent()).getPoint());
        } else
            appendEvent(e);
    }
}
 
Example 3
Source File: EditableTableHeaderUI.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void mousePressed(MouseEvent e) {
	if (!SwingUtilities.isLeftMouseButton(e)) {
		return;
	}
	super.mousePressed(e);

	if (header.getResizingColumn() == null) {
		Point p = e.getPoint();
		TableColumnModel columnModel = header.getColumnModel();
		int index = columnModel.getColumnIndexAtX(p.x);
		if (index != -1) {
			if (header.editCellAt(index, e)) {
				setDispatchComponent(e);
				repostEvent(e);
			}
		}
	}
}
 
Example 4
Source File: XMouseDragGestureRecognizer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Invoked when a mouse button is pressed on a component.
 */

public void mouseDragged(MouseEvent e) {
    if (!events.isEmpty()) { // gesture pending
        int dop = mapDragOperationFromModifiers(e);


        if (dop == DnDConstants.ACTION_NONE) {
            return;
        }

        MouseEvent trigger = (MouseEvent)events.get(0);

        Point      origin  = trigger.getPoint();
        Point      current = e.getPoint();

        int        dx      = Math.abs(origin.x - current.x);
        int        dy      = Math.abs(origin.y - current.y);

        if (dx > motionThreshold || dy > motionThreshold) {
            fireDragGestureRecognized(dop, ((MouseEvent)getTriggerEvent()).getPoint());
        } else
            appendEvent(e);
    }
}
 
Example 5
Source File: RangeSlider.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public void mouseMoved(MouseEvent e) {
    isOverBar = false;
    if (model == null) {
        return;
    }


    Point p = e.getPoint();
    if (isOverFirstPosition(p) || isOverSecondPosition(p)) {
        setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
    } else if (isOverSelection(p)) {
        isOverBar = true;
        setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    } else {
        this.setCursor(Cursor.getDefaultCursor());
    }
    repaint();
}
 
Example 6
Source File: MouseHandler.java    From rscplus with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void mouseDragged(MouseEvent e) {
  if (listener_mouse_motion == null) return;

  if (Replay.isRecording) {
    Replay.dumpMouseInput(
        Replay.MOUSE_DRAGGED,
        e.getX(),
        e.getY(),
        0,
        e.getModifiers(),
        e.getClickCount(),
        0,
        0,
        e.isPopupTrigger(),
        e.getButton());
  }

  if (Settings.CAMERA_ROTATABLE.get(Settings.currentProfile) && m_rotating) {
    m_rotateX += (float) (e.getX() - m_rotatePosition.x) / 2.0f;
    int xDist = (int) m_rotateX;

    Camera.addRotation(xDist);
    m_rotateX -= xDist;

    m_rotatePosition = e.getPoint();
  }

  if (!e.isConsumed()) {
    x = e.getX();
    y = e.getY();
    listener_mouse_motion.mouseDragged(e);
  }
}
 
Example 7
Source File: NavigableImagePanel.java    From PyramidShader with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void mouseClicked(MouseEvent e) {
    if (image == null) {
        return;
    }
    Point p = e.getPoint();
    if (SwingUtilities.isRightMouseButton(e)) {
        if (isInNavigationImage(p)) {
            navZoomFactor = 1.0 - zoomIncrement;
            zoomNavigationImage();
        } else /*if (isInImage(p))*/ {
            zoomImage(1 / ZOOM_INC);
        }
    } else {
        if (isInNavigationImage(p)) {
            navZoomFactor = 1.0 + zoomIncrement;
            zoomNavigationImage();
        } else if (e.getClickCount() == 2)/*if (isInImage(p))*/ {
            zoomImage(ZOOM_INC);
        }
    }
}
 
Example 8
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
private Point getToolTipLocation(MouseEvent e) {
  Point p = e.getPoint();
  Component c = e.getComponent();
  SwingUtilities.convertPointToScreen(p, c);
  p.translate(0, -tip.getPreferredSize().height);
  return p;
}
 
Example 9
Source File: InnerPanelSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void mouseMoved(MouseEvent e) {
    Point p = e.getPoint();
    int col = listClasses.columnAtPoint(p);
    int row = listClasses.rowAtPoint(p);
    
    if (col < 0 || row < 0) {
        hidePopup();
        return;
    }
    if (col == currentCol && row == currentRow) {
        // the tooltip is (probably) shown, do not create again
        return;
    }
    Rectangle cellRect = listClasses.getCellRect(row, col, false);
    Point pt = cellRect.getLocation();
    SwingUtilities.convertPointToScreen(pt, listClasses);
    
    RenderedImage ri = new RenderedImage();
    if (!updateTooltipImage(ri, row, col)) {
        return;
    }
    ri.addMouseListener(this);
    
    Popup popup = PopupFactory.getSharedInstance().getPopup(listClasses, ri, pt.x, pt.y);
    popupContents = ri;
    currentPopup = popup;
    currentCol = col;
    currentRow = row;
    popup.show();
    System.err.println("Hello");
}
 
Example 10
Source File: KMeansDemo.java    From COMP6237 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void mouseDragged(MouseEvent e) {
	if (!isRunning) {
		final Point pt = e.getPoint();
		final Point2dImpl pti = new Point2dImpl(pt.x, pt.y);
		image.drawPoint(pti, RGBColour.MAGENTA, 10);
		points.add(pti);
		updateImage();
	}
}
 
Example 11
Source File: WorldPanel.java    From WorldGrower with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Point getToolTipLocation(MouseEvent event) {
	final int mouseCutoff = 20;
	Point currentMouseLocation = event.getPoint();
	int x = (currentMouseLocation.x / mouseCutoff) * mouseCutoff;
	int y = (currentMouseLocation.y / mouseCutoff) * mouseCutoff;
	return new Point(x, y);
}
 
Example 12
Source File: MouseCapture.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private void redispatchMouseEvent(MouseEvent event) {
    Point     glassPanePoint = event.getPoint();
    Point     containerPoint = SwingUtilities.convertPoint(mGlassPane, glassPanePoint, mCaptureComponent);
    Component component      = SwingUtilities.getDeepestComponentAt(mCaptureComponent, containerPoint.x, containerPoint.y);
    if (component != null) {
        Point componentPoint = SwingUtilities.convertPoint(mGlassPane, glassPanePoint, component);
        component.dispatchEvent(new MouseEvent(component, event.getID(), event.getWhen(), event.getModifiersEx(), componentPoint.x, componentPoint.y, event.getClickCount(), event.isPopupTrigger()));
    }
}
 
Example 13
Source File: ViewerMouseListener.java    From amidst with GNU General Public License v3.0 5 votes vote down vote up
@CalledOnlyBy(AmidstThread.EDT)
@Override
public void mouseReleased(MouseEvent e) {
	Point mousePosition = e.getPoint();
	if (isPopup(e)) {
		showPopupMenu(mousePosition, e.getComponent(), e.getX(), e.getY());
	} else if (!widgetManager.mouseReleased()) {
		doMouseReleased();
	}
}
 
Example 14
Source File: BasicGridUI.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
public void mousePressed(MouseEvent event) {
            startPoint = event.getPoint();

//			System.out.println("MouseInputHandler.mousePressed()");
            if (!event.isShiftDown()) {
                selectionRegion = null;
            }
            if (event.isConsumed()) {
                selectedOnPress = false;
                return;
            }
            selectedOnPress = true;
            adjustFocusAndSelection(event);
        }
 
Example 15
Source File: DarkFilePane.java    From darklaf with MIT License 4 votes vote down vote up
@Override
public void mouseClicked(MouseEvent evt) {
    JComponent source = (JComponent) evt.getSource();

    int index;
    if (source instanceof JList) {
        index = list.locationToIndex(evt.getPoint());
    } else if (source instanceof JTable) {
        JTable table = (JTable) source;
        Point p = evt.getPoint();
        index = table.rowAtPoint(p);

        boolean pointOutsidePrefSize = SwingUtilities2.pointOutsidePrefSize(table, index,
                                                                            table.columnAtPoint(p), p);

        if (pointOutsidePrefSize && !fullRowSelection) {
            return;
        }

        // Translate point from table to list
        if (index >= 0 && list != null && listSelectionModel.isSelectedIndex(index)) {

            // Make a new event with the list as source, placing the
            // click in the corresponding list cell.
            Rectangle r = list.getCellBounds(index, index);
            MouseEvent newEvent = new MouseEvent(list, evt.getID(),
                                                 evt.getWhen(), evt.getModifiersEx(),
                                                 r.x + 1, r.y + r.height / 2,
                                                 evt.getXOnScreen(),
                                                 evt.getYOnScreen(),
                                                 evt.getClickCount(), evt.isPopupTrigger(),
                                                 evt.getButton());
            SwingUtilities.convertMouseEvent(list, newEvent, list);
            evt = newEvent;
        }
    } else {
        return;
    }

    if (index >= 0 && SwingUtilities.isLeftMouseButton(evt)) {
        JFileChooser fc = getFileChooser();

        // For single click, we handle editing file name
        if (evt.getClickCount() == 1 && source instanceof JList) {
            if ((!fc.isMultiSelectionEnabled() || fc.getSelectedFiles().length <= 1)
                && listSelectionModel.isSelectedIndex(index)
                && getEditIndex() == index && editFile == null
                && DarkUIUtil.isOverText(evt, index, list)) {
                editFileName(index);
            } else {
                setEditIndex(index);
            }
        } else if (evt.getClickCount() == 2) {
            // on double click (open or drill down one directory) be
            // sure to clear the edit index
            resetEditIndex();
        }
    }

    // Forward event to Basic
    if (getDoubleClickListener() != null) {
        list.putClientProperty("List.isFileList", false);
        getDoubleClickListener().mouseClicked(evt);
        list.putClientProperty("List.isFileList", true);
    }
}
 
Example 16
Source File: MainFrame.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
public void mousePressed(MouseEvent e) {
	if(e.getButton() == MouseEvent.BUTTON1) {
		corner = e.getPoint();
	}
}
 
Example 17
Source File: SheetTable.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**  Returns true if a mouse event occured over the custom editor button.
 *   This is used to supply button specific tooltips and launch the custom
 *   editor without needing to instantiate a real button */
private boolean onCustomEditorButton(MouseEvent e) {
    //see if we're in the approximate bounds of the custom editor button
    Point pt = e.getPoint();
    int row = rowAtPoint(pt);
    int col = columnAtPoint(pt);
    FeatureDescriptor fd = getSheetModel().getPropertySetModel().getFeatureDescriptor(row);
    if( null == fd ) {
        //prevent NPE when the activated Node has been destroyed and a new one hasn't been set yet
        return false;
    }

    //see if the event happened over the custom editor button
    boolean success;

    if (PropUtils.noCustomButtons) {
        //#41412 - impossible to invoke custom editor on props w/ no inline
        //edit mode if the no custom buttons switch is set
        success = false;
    } else {
        success = e.getX() > (getWidth() - PropUtils.getCustomButtonWidth());
    }

    //if it's a mouse button event, then we're not showing a tooltip, we're
    //deciding if we should display a custom editor.  For read-only props that
    //support one, we should return true, since clicking the non-editable cell
    //is not terribly useful.
    if (
        (e.getID() == MouseEvent.MOUSE_PRESSED) || (e.getID() == MouseEvent.MOUSE_RELEASED) ||
            (e.getID() == MouseEvent.MOUSE_CLICKED)
    ) {
        //We will show the custom editor for any click on the text value
        //of a property that looks editable but sets canEditAsText to false -
        //the click means the user is trying to edit something, so to just
        //swallow the gesture is confusing
        success |= Boolean.FALSE.equals(fd.getValue("canEditAsText"));

        if (!success && fd instanceof Property) {
            PropertyEditor pe = PropUtils.getPropertyEditor((Property) fd);

            if ((pe != null) && pe.supportsCustomEditor()) {
                //Undocumented but used in Studio - in NB 3.5 and earlier, returning null from getAsText()
                //was a way to make a property non-editable
                success |= (pe.isPaintable() && (pe.getAsText() == null) && (pe.getTags() == null));
            }
        }
    }

    try {
        if (success) { //NOI18N

            if (fd instanceof Property && (col == 1)) {
                boolean supp = PropUtils.getPropertyEditor((Property) fd).supportsCustomEditor();

                return (supp);
            }
        }
    } catch (IllegalStateException ise) {
        //See bugtraq 4941073 - if a property accessed via Reflection throws
        //an unexpected exception (try customize bean on a vanilla GenericServlet
        //to produce this) when the getter is accessed, then we are already
        //displaying "Error fetching property value" in the value area of
        //the propertysheet.  No point in distracting the user with a 
        //stack trace - it's not our bug.
        Logger.getLogger(SheetTable.class.getName()).log(Level.WARNING, null, ise);
    }

    return false;
}
 
Example 18
Source File: Mostrador.java    From brModelo with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void mouseMoved(MouseEvent e) {
    super.mouseMoved(e);
    Point p = e.getPoint();
    ChecaCursor(p);
}
 
Example 19
Source File: CompMover.java    From Math-Game with Apache License 2.0 4 votes vote down vote up
/**
 * If a card is selected, it can be dragged
 */
@Override
public void mousePressed(MouseEvent e) {

	selectedComponent = (Component) (e.getSource());
	// System.out.println(selectedComponent.getParent());
	// Point tempPoint = selectedComponent.getLocation();
	offset = e.getPoint();
	draggingCard = true;

	try {
		if (selectedComponent.getParent().equals(mathGame.getWorkspacePanel())) {

			mathGame.getWorkspacePanel().remove(selectedComponent);
			mathGame.getWorkspacePanel().revalidate();
			mathGame.getMasterPane().add(selectedComponent, new Integer(1));
			mathGame.getMasterPane().revalidate();
			mathGame.getMasterPane().repaint();

			// offset = selectedComponent.getLocationOnScreen();
			// selectedComponent.setBounds(MouseInfo.getPointerInfo().getLocation().x,
			// MouseInfo.getPointerInfo().getLocation().y,
			// cardHomes[1].getSize().width, cardHomes[1].getSize().height);
			// selectedComponent.setLocation(MouseInfo.getPointerInfo().getLocation());
			
			/*
			System.out.println(MouseInfo.getPointerInfo().getLocation());
			System.out.println(selectedComponent.getLocation());
			System.out.println(selectedComponent.getLocationOnScreen());
			System.out.println(tempPoint);
			*/
			selectedComponent.setLocation(-200, -200);

			// selectedComponent.setSize(cardHomes[1].getSize().width,
			// cardHomes[1].getSize().height);

		} else if (selectedComponent.getParent().equals(mathGame.getHoldPanel())) {
			int tempX = selectedComponent.getX();
			int tempY = selectedComponent.getLocationOnScreen().y;
			mathGame.getHoldPanel().remove(selectedComponent);
			mathGame.getHoldPanel().revalidate();
			mathGame.getMasterPane().add(selectedComponent, new Integer(1));
			mathGame.getMasterPane().revalidate();
			mathGame.getMasterPane().repaint();

			selectedComponent.setLocation(tempX, tempY);
		}
		/*
		else { System.out.println("normal workpanel:"+workPanel);
		System.out.println("parent:"+selectedComponent.getParent()); }
		*/

	} catch (Exception ex) {
		System.out.println("error removing from panel");
		ex.printStackTrace();
	}

}
 
Example 20
Source File: EditableTableHeaderUI.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
private void setDispatchComponent(MouseEvent e) {
	Component editorComponent = header.getEditorComponent();
	Point p = e.getPoint();
	Point p2 = SwingUtilities.convertPoint(header, p, editorComponent);
	dispatchComponent = SwingUtilities.getDeepestComponentAt(editorComponent, p2.x, p2.y);
}