Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How does the map function works ?
How does the map function works ? [message #446992] Tue, 07 December 2004 14:04
hortiz Mising name is currently offline hortiz Mising nameFriend
Messages: 96
Registered: July 2009
Member
Hi,

I do not understand how the map function works : I've got two composites
in the same parent one (code provided below).

When I map the first one (black color) with the blue one, everything is ok
(its y coordinate is increased by 14 (distance between it and the blue
one).

But when I map the second one (white color), its coordinate is increased
by 123 ??? It should also be increased by 14 isn't it ?

Provided code shows the problem.

Thanks,
Helene


import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class MapComposites {

private static Display display;
private static Shell shell;

private static Composite firstComposite;
private static Composite secondComposite;
private static Composite thirdComposite;
private static Composite inside1;
private static Composite inside2;

public static void createComposites() {

firstComposite = new Composite(shell, SWT.BORDER);
GridData gridData = new GridData();
gridData.widthHint = 800;
gridData.heightHint = 400;
firstComposite.setLayoutData(gridData);
firstComposite.setLayout(new GridLayout());
firstComposite.setBackground(new Color(display, new RGB(0, 0,
255)));

secondComposite = new Composite(firstComposite, SWT.BORDER);
gridData = new GridData();
gridData.widthHint = 600;
gridData.heightHint = 300;
secondComposite.setLayoutData(gridData);
secondComposite.setLayout(new GridLayout());
secondComposite.setBackground(new Color(display, new RGB(0, 255,
0)));

thirdComposite = new Composite(secondComposite, SWT.BORDER);
gridData = new GridData();
gridData.verticalAlignment = GridData.FILL_BOTH;
gridData.widthHint = 300;
gridData.heightHint = 250;
thirdComposite.setLayoutData(gridData);
thirdComposite.setLayout(new GridLayout());

inside1 = new Composite(thirdComposite, SWT.BORDER);
gridData = new GridData();
gridData.widthHint = 150;
gridData.heightHint = 100;
inside1.setLayoutData(gridData);
inside1.setBackground(new Color(display, new RGB(0,0,0)));

inside2 = new Composite(thirdComposite, SWT.BORDER);
gridData = new GridData();
gridData.widthHint = 150;
gridData.heightHint = 100;
inside2.setLayoutData(gridData);
inside2.setBackground(new Color(display, new RGB(255,255,255)));

thirdComposite.setBackground(new Color(display, new RGB(105, 0,
0)));
}

public static void main(String[] args) {

display = new Display ();
shell = new Shell (display);

GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 1;
shell.setLayout(gridLayout);
shell.setBackground(new Color(display, new RGB(255, 0, 0)));

createComposites();

shell.pack();
shell.open();

System.out.println("Third composite bounds " +
thirdComposite.getBounds());

int x = thirdComposite.getBounds().x;
int y = thirdComposite.getBounds().y;

Point point = display.map(thirdComposite, secondComposite, x, y);

System.out.println("Point = " + point);

System.out.println("INSIDE1 BOUNDS " + inside1.getBounds());

System.out.println("INSIDE 1 MAPPED " + display.map(inside1,
secondComposite, inside1.getBounds()));

System.out.println("INSIDE2 BOUNDS " + inside2.getBounds());

System.out.println("INSIDE 2 MAPPED " + display.map(inside2,
secondComposite, inside2.getBounds()));

while (!shell.isDisposed ()) {
if (!display.readAndDispatch ())
display.sleep ();
}
display.dispose ();
}
}
Previous Topic:SWT Browser.setText() not working on linux
Next Topic:could not use transparent *.png's in swt
Goto Forum:
  


Current Time: Tue Oct 20 01:04:25 GMT 2020

Powered by FUDForum. Page generated in 0.01849 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top