Java Code Examples for java.awt.event.MouseEvent.translatePoint()

The following are Jave code examples for showing how to use translatePoint() of the java.awt.event.MouseEvent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: VASSAL-src   File: Map.java   View Source Code Vote up 6 votes
/**
 * 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 2
Project: gate-core   File: JTreeTable.java   View Source Code Vote up 6 votes
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 3
Project: Logisim   File: Canvas.java   View Source Code Vote up 5 votes
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);
}
 
Example 4
Project: Logisim   File: Canvas.java   View Source Code Vote up 5 votes
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);
}
 
Example 5
Project: Logisim   File: AppearanceCanvas.java   View Source Code Vote up 5 votes
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);
	}
}
 
Example 6
Project: incubator-netbeans   File: TreeTable.java   View Source Code Vote up 4 votes
/**
 * 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 7
Project: incubator-netbeans   File: SplittedPanel.java   View Source Code Vote up 4 votes
/** 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);
        }
    }
}