下面列出了java.awt.event.MouseEvent#getPoint() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
@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);
}
}
}
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();
}
/**
* 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);
}
}
@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);
}
}
}
}
/**
* 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);
}
}
@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);
}
}
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;
}
@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");
}
@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();
}
}
@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);
}
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()));
}
}
@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();
}
}
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);
}
/** 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;
}
@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);
}
}
public void mousePressed(MouseEvent e) {
if(e.getButton() == MouseEvent.BUTTON1) {
corner = e.getPoint();
}
}
@Override
public void mouseMoved(MouseEvent e) {
super.mouseMoved(e);
Point p = e.getPoint();
ChecaCursor(p);
}
/**
* 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();
}
}
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);
}