下面列出了org.eclipse.swt.widgets.Composite#getLocation ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public Point getRealPosition( Composite canvas, int x, int y ) {
Point p = new Point( 0, 0 );
Composite follow = canvas;
while ( follow != null ) {
org.eclipse.swt.graphics.Point loc = follow.getLocation();
Point xy = new Point( loc.x, loc.y );
p.x += xy.x;
p.y += xy.y;
follow = follow.getParent();
}
int offsetX = -16;
int offsetY = -64;
if ( Const.isOSX() ) {
offsetX = -2;
offsetY = -24;
}
p.x = x - p.x + offsetX;
p.y = y - p.y + offsetY;
return screen2real( p.x, p.y );
}
/**
* This is a helper method created to get the location on screen of a
* composite. It does not take into account multiple monitors.
*
* @param cmpTarget
* The composite whose location on screen is required
* @return The location of the composite on screen.
*/
public static Point getScreenLocation( Composite cmpTarget )
{
Point ptScreen = new Point( 0, 0 );
try
{
Composite cTmp = cmpTarget;
while ( !( cTmp instanceof Shell ) )
{
ptScreen.x += cTmp.getLocation( ).x;
ptScreen.y += cTmp.getLocation( ).y;
cTmp = cTmp.getParent( );
}
}
catch ( Exception e )
{
logger.log( e );
}
return cmpTarget.getShell( ).toDisplay( ptScreen );
}
/**
* This is a helper method created to get the location on screen of a
* composite. It does not take into account multiple monitors.
*
* @param cmpTarget
* The composite whose location on screen is required
* @return The location of the composite on screen.
*/
public static Point getScreenLocation( Composite cmpTarget )
{
Point ptScreen = new Point( 0, 0 );
try
{
Composite cTmp = cmpTarget;
while ( !( cTmp instanceof Shell ) )
{
ptScreen.x += cTmp.getLocation( ).x;
ptScreen.y += cTmp.getLocation( ).y;
cTmp = cTmp.getParent( );
}
}
catch ( Exception e )
{
WizardBase.displayException( e );
}
return cmpTarget.getShell( ).toDisplay( ptScreen );
}
public Point getRealPosition( Composite canvas, int x, int y ) {
Point p = new Point( 0, 0 );
Composite follow = canvas;
while ( follow != null ) {
org.eclipse.swt.graphics.Point loc = follow.getLocation();
Point xy = new Point( loc.x, loc.y );
p.x += xy.x;
p.y += xy.y;
follow = follow.getParent();
}
int offsetX = -16;
int offsetY = -64;
if ( Const.isOSX() ) {
offsetX = -2;
offsetY = -24;
}
p.x = x - p.x + offsetX;
p.y = y - p.y + offsetY;
return screen2real( p.x, p.y );
}
public Point getRealPosition( Composite canvas, int x, int y ) {
Point p = new Point( 0, 0 );
Composite follow = canvas;
while ( follow != null ) {
Point xy = new Point( follow.getLocation().x, follow.getLocation().y );
p.x += xy.x;
p.y += xy.y;
follow = follow.getParent();
}
p.x = x - p.x - 8;
p.y = y - p.y - 48;
return screen2real( p.x, p.y );
}
/**
* Gets the absolute location.
*
* @param control the control
* @param x the x
* @param y the y
* @return the absolute location
*/
private Point getAbsoluteLocation(Control control, int x, int y) {
Point point = new Point(x, y);
Composite composite = control.getParent();
while (composite != null) {
point.x += composite.getLocation().x;
point.y += composite.getLocation().y;
composite = composite.getParent();
}
return point;
}
public Point getRealPosition( Composite canvas, int x, int y ) {
Point p = new Point( 0, 0 );
Composite follow = canvas;
while ( follow != null ) {
Point xy = new Point( follow.getLocation().x, follow.getLocation().y );
p.x += xy.x;
p.y += xy.y;
follow = follow.getParent();
}
p.x = x - p.x - 8;
p.y = y - p.y - 48;
return screen2real( p.x, p.y );
}