本文整理汇总了Java中java.awt.event.MouseEvent.translatePoint方法的典型用法代码示例。如果您正苦于以下问题:Java MouseEvent.translatePoint方法的具体用法?Java MouseEvent.translatePoint怎么用?Java MouseEvent.translatePoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.event.MouseEvent
的用法示例。
在下文中一共展示了MouseEvent.translatePoint方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mouseReleased
import java.awt.event.MouseEvent; //导入方法依赖的package包/类
/**
* 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;
}
示例2: convertEvent
import java.awt.event.MouseEvent; //导入方法依赖的package包/类
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()
);
}
示例3: snapToGrid
import java.awt.event.MouseEvent; //导入方法依赖的package包/类
public static void snapToGrid(MouseEvent e) {
int old_x = e.getX();
int old_y = e.getY();
int new_x = snapXToGrid(old_x);
int new_y = snapYToGrid(old_y);
e.translatePoint(new_x - old_x, new_y - old_y);
}
示例4: zoomEvent
import java.awt.event.MouseEvent; //导入方法依赖的package包/类
private void zoomEvent(MouseEvent e, double zoom) {
int oldx = e.getX();
int oldy = e.getY();
int newx = (int) Math.round(e.getX() / zoom);
int newy = (int) Math.round(e.getY() / zoom);
e.translatePoint(newx - oldx, newy - oldy);
}
示例5: repairEvent
import java.awt.event.MouseEvent; //导入方法依赖的package包/类
private void repairEvent(MouseEvent e, double zoom) {
if (zoom != 1.0) {
int oldx = e.getX();
int oldy = e.getY();
int newx = (int) Math.round(e.getX() / zoom);
int newy = (int) Math.round(e.getY() / zoom);
e.translatePoint(newx - oldx, newy - oldy);
}
}
示例6: isCellEditable
import java.awt.event.MouseEvent; //导入方法依赖的package包/类
/**
* 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;
}
示例7: mouseDragged
import java.awt.event.MouseEvent; //导入方法依赖的package包/类
/** A method implemented from the MouseMotionListener interface to handle the splitter dragging */
public void mouseDragged(MouseEvent e) {
if (continuousLayout == true) {
Dimension d = getSize();
Point splitterPos = splitter.getLocation();
e.translatePoint(splitterPos.x, splitterPos.y);
if (splitType == VERTICAL) {
dragPos = e.getY();
if (dragPos > d.height) {
dragPos = d.height;
}
} else {
dragPos = e.getX();
if (dragPos > d.width) {
dragPos = d.width;
}
}
if (dragPos < 0) {
dragPos = 0;
}
if (continuousLayout) {
if (dragPos == -1) {
return;
}
int newDragPos = dragPos;
if (!absolute) {
if (splitType == VERTICAL) {
newDragPos = (100 * dragPos) / d.height;
} else {
newDragPos = (100 * dragPos) / d.width;
}
}
setSplitPosition(newDragPos);
}
}
}