Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Any way to draw on Browser object?
Any way to draw on Browser object? [message #533461] Fri, 14 May 2010 04:03 Go to next message
Misha Koshelev is currently offline Misha KoshelevFriend
Messages: 31
Registered: May 2010
Member
SWT.Paint seems not to be called/supported (works fine on Shell).

Thank you
Misha
Re: Any way to draw on Browser object? [message #533542 is a reply to message #533461] Fri, 14 May 2010 14:01 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi Misha,

There isn't currently support for this. I could not find an existing bug
report for it, so if you want you can log one at
https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Platform &component=SWT .

The closest that you can currently get is to open a Shell on top with a
region set according to the content to be painted. Depending on how much
you want to paint on top, this may or may not be a reasonable thing to do.
A basic example of this follows:

public class Main0 {
static Region region;
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setBounds(10, 10, 400, 400);
shell.setLayout(new FillLayout());
final Browser browser = new Browser(shell, SWT.NONE);
browser.setUrl("eclipse.org");
shell.open();
display.timerExec(3333, new Runnable() {
public void run() {
Rectangle bounds = display.map(shell, null,
browser.getBounds());
Shell shell2 = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP);
shell2.setBounds(bounds);
final int width = bounds.width;
region = new Region();
Rectangle pixel = new Rectangle(0, 0, 1, 1);
for (int i = 0; i < width; i++) {
pixel.x = pixel.y = i;
region.add(pixel);
}
shell2.setRegion(region);
shell2.addListener(SWT.Paint, new Listener() {
public void handleEvent(Event event) {
event.gc.drawLine(0, 0, width, width);
}
});
shell2.open();
}
});
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
region.dispose();
shell.dispose();
display.dispose();
}
}

HTH,
Grant


"Misha Koshelev" <misha680@gmail.com> wrote in message
news:hsii2v$ooh$1@build.eclipse.org...
> SWT.Paint seems not to be called/supported (works fine on Shell).
>
> Thank you
> Misha
Re: Any way to draw on Browser object? [message #533562 is a reply to message #533542] Fri, 14 May 2010 14:55 Go to previous messageGo to next message
Misha Koshelev is currently offline Misha KoshelevFriend
Messages: 31
Registered: May 2010
Member
Wow. Thank you for the code.

I will file a bug report and try.

Thank you again. I look forward to contributing more to the Eclipse project. Stayed tuned for my next version of the automation framework on which I am working hard.
www.mkosh.com

Misha
Re: Any way to draw on Browser object? [message #533642 is a reply to message #533562] Fri, 14 May 2010 21:10 Go to previous messageGo to next message
Misha Koshelev is currently offline Misha KoshelevFriend
Messages: 31
Registered: May 2010
Member
Thank you. My code looks something like:

					Object[] coords=(Object[])result;
					Rectangle rectangle=new Rectangle(((Double)coords[0]).intValue(),((Double)coords[1]).intValue(),((Double)coords[2]).intValue(),((Double)coords[3]).intValue());
					rectangle.intersect(gui.getBrowser().getClientArea());
					rectangle=display.map(gui.getBrowser(),null,rectangle);
					if (rectangleShell!=null) {
					    rectangleShell.dispose();
					}
					rectangleShell=new Shell(display,SWT.NO_TRIM|SWT.ON_TOP);
					rectangleShell.setBounds(rectangle);
					rectangleShell.setBackground(display.getSystemColor(SWT.COLOR_RED));
					final Region region=new Region();
					Rectangle point=new Rectangle(0,0,1,1);
					for (int x=0;x<rectangle.width;x++) {
					    point.x=x;
					    point.y=0;
					    region.add(point);
					    point.y=rectangle.height-1;
					    region.add(point);
					}
					for (int y=0;y<rectangle.height;y++) {
					    point.x=0;
					    point.y=y;
					    region.add(point);
					    point.x=rectangle.width-1;
					    region.add(point);
					}
					rectangleShell.setRegion(region);
					rectangleShell.addListener(SWT.Dispose,new Listener() {
						public void handleEvent(Event event) {
						    region.dispose();
						}
					    });
					rectangleShell.open();
Re: Any way to draw on Browser object? [message #534629 is a reply to message #533642] Wed, 19 May 2010 16:45 Go to previous messageGo to next message
Misha Koshelev is currently offline Misha KoshelevFriend
Messages: 31
Registered: May 2010
Member
I have gotten this to work but my mind still wonders if there is a better way.

The problem: we have a rectangle that is on top of _all_ windows, even those that are separate from the browser.

My idea: perhaps a Canvas object can be created with a custom Region.

Is this possible?

Thank you
Misha
Re: Any way to draw on Browser object? [message #537353 is a reply to message #534629] Wed, 02 June 2010 07:24 Go to previous messageGo to next message
Shawn Spiars is currently offline Shawn SpiarsFriend
Messages: 22
Registered: July 2009
Junior Member
Misha Koshelev wrote:
> I have gotten this to work but my mind still wonders if there is a
> better way.
>
> The problem: we have a rectangle that is on top of _all_ windows, even
> those that are separate from the browser.
>
> My idea: perhaps a Canvas object can be created with a custom Region.
>
> Is this possible?
>
> Thank you
> Misha

It would be interesting to see if you could make the embedded SWT
browser the background for an Eclipse GEF canvas and then draw on top of
the canvas.
Re: Any way to draw on Browser object? [message #537423 is a reply to message #537353] Wed, 02 June 2010 12:16 Go to previous message
Misha Koshelev is currently offline Misha KoshelevFriend
Messages: 31
Registered: May 2010
Member
Thank you for the interesting suggestion.

Misha
Previous Topic:SWT Browser Example - RCP Application
Next Topic:Preventing the user from leaving the tab in a CTabFolder
Goto Forum:
  


Current Time: Thu Apr 25 09:08:33 GMT 2024

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

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

Back to the top