Posted on 2006-12-29 12:26
Hexise 閱讀(1136)
評論(0) 編輯 收藏 所屬分類:
Eclipse Plugin
轉(zhuǎn)換成相對坐標,要運用translateToRelative(Point point)方法.
例如,在Eclipse Editor視圖中加入Figure,需要計算出相對于HostFigure的坐標,才能正確將figure放在鼠標點擊的位置.可以如下這樣做:
在getCreateCommand(CreateRequest request)方法中,加入如下語句:
Point location = request.getLocation().getCopy();
getHostFigure().translateToRelative(location);
如此獲得的location就是相對于HostFigure的坐標.
能夠獲得當前光標絕對坐標的方法是:
Display.getDefault().getCursorLocation()