當前位置: 首頁>>代碼示例>>Java>>正文


Java MouseEvent.translatePoint方法代碼示例

本文整理匯總了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;
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:32,代碼來源:Map.java

示例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()
  );
}
 
開發者ID:GateNLP,項目名稱:gate-core,代碼行數:21,代碼來源:JTreeTable.java

示例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);
}
 
開發者ID:LogisimIt,項目名稱:Logisim,代碼行數:8,代碼來源:Canvas.java

示例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);
}
 
開發者ID:LogisimIt,項目名稱:Logisim,代碼行數:8,代碼來源:Canvas.java

示例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);
	}
}
 
開發者ID:LogisimIt,項目名稱:Logisim,代碼行數:10,代碼來源:AppearanceCanvas.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:49,代碼來源:TreeTable.java

示例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);
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:45,代碼來源:SplittedPanel.java


注:本文中的java.awt.event.MouseEvent.translatePoint方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。