Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Albireo » Advice on getting started?
Advice on getting started? [message #3635] Fri, 12 October 2007 20:18 Go to next message
Chris Kwon Lewis is currently offline Chris Kwon LewisFriend
Messages: 24
Registered: July 2009
Junior Member
I thought it would be best to ask a few questions before diving into my
project of combining swt and swing.

First, thanks for that snippet you posted Gordon. I noticed you used
"EmbeddedSwingComposite" like an object. Currently it is an abstract
class, do you recommend making it non abstract and just putting in the
code I want for createSwingComponent() to suit my own program?

here is a screen shot of how my program looks currently:
http://www.kingkwon.com/misc/gui.jpg

The part that is labeled "canvas" is where I will need to put the swing
part. The swing I will be using is a JComponent when it comes down to it
after all the extending.

Basically:
NetCanvas(My file) extends PCanvas(Piccolo)
PCanvas(Piccolo) extends JComponent (swing)

So as of now, I'm thinking:
1)Use a swt component to hold the JComponent (NetCanvas) in it
2)Bring your examples folder into my workspace to use as helper classes
for EmbeddedSwingComposite.
3)Making the EmbeddedSwingComposite non abstract and putting my code
into createSwingComponent()

Does that sound about right? Also I notice James submitted some
suggestions, do I need to fix anything major to the sample code as of
right now?

Also I'm still a little unclear on the things I need to schedule
individually for swing and swt. What type of general things need to be
scheduled by me?

Any help or insight would be greatly appreciated. Thanks
Re: Advice on getting started? [message #3704 is a reply to message #3635] Mon, 15 October 2007 17:07 Go to previous messageGo to next message
Gordon Hirsch is currently offline Gordon HirschFriend
Messages: 100
Registered: July 2009
Senior Member
Cklewis wrote:
> I thought it would be best to ask a few questions before diving into my
> project of combining swt and swing.
>
> First, thanks for that snippet you posted Gordon. I noticed you used
> "EmbeddedSwingComposite" like an object. Currently it is an abstract
> class, do you recommend making it non abstract and just putting in the
> code I want for createSwingComponent() to suit my own program?

Actually the snippet creates an anonymous subclass of
EmbeddedSwingComposite. The subclass implements only the
createSwingComponent() method. That's basically how it was intended to
be used.

....
>
> Basically:
> NetCanvas(My file) extends PCanvas(Piccolo)
> PCanvas(Piccolo) extends JComponent (swing)
>
> So as of now, I'm thinking:
> 1)Use a swt component to hold the JComponent (NetCanvas) in it
> 2)Bring your examples folder into my workspace to use as helper classes
> for EmbeddedSwingComposite.
> 3)Making the EmbeddedSwingComposite non abstract and putting my code
> into createSwingComponent()

1 and 2 sound fine for now. See advice above for creating a subclass of
EmbeddedSwingComposite (in your own folder) instead of 3. Implement the
createSwingComponent() method to create your NetCanvas.

>
> Does that sound about right? Also I notice James submitted some
> suggestions, do I need to fix anything major to the sample code as of
> right now?

I would focus on getting the original code working in your project
first. But you definitely should take a look at his suggestions,
especially if you are noticing problems.

We are working on getting the project approved and moving it forward. If
all goes well, there should be an updated CVS code repository available
in the future. Until then, it's a bit of pain, sorry. (And, there are no
guarantees that the programming interfaces will stay the same.)

>
> Also I'm still a little unclear on the things I need to schedule
> individually for swing and swt. What type of general things need to be
> scheduled by me?

It completely depends on what you are doing. Basically, you just need to
try to make your AWT/Swing API calls on the AWT event thread and SWT API
calls on the SWT event thread.
Re: Advice on getting started? [message #3734 is a reply to message #3704] Mon, 15 October 2007 20:41 Go to previous messageGo to next message
Chris Kwon Lewis is currently offline Chris Kwon LewisFriend
Messages: 24
Registered: July 2009
Junior Member
First, thanks for taking the time to help me out.
> Actually the snippet creates an anonymous subclass of
> EmbeddedSwingComposite. The subclass implements only the
> createSwingComponent() method. That's basically how it was intended to
> be used.

Oh ok. I wasn't aware you could do it like that with an abstract class.
I thought I had to "extend" my class to 'EmbeddedSwingComposite' since
it was abstract (or make it non abstract). I'm still a student, so sorry
for the newbiness :)

I went off of your snippet you posted (the one with the JTables) and
also your Eclipse article and i'm apparently doing something wrong still.


In the old code, we put the canvas onto a JFrame.

Am I missing a function call?
What do I do with the returned JComponent of createSwingComponent()?
Should I be returning the frame instead of the canvas?


So the code i used was:
..
..
..
SashForm sf = new SashForm(main_shell, SWT.VERTICAL);
sf.setLayoutData(new GridData(SWT.FILL,SWT.FILL, true,true));


Composite swing_composite = new Composite(sf, SWT.EMBEDDED |
SWT.NO_BACKGROUND); // put this composite as the top portion of the sashform

createPartControl(swing_composite);
setFocus();

..
..
..

then my function that I went off of your snippet example:

public void createPartControl(Composite parent) {
embeddedComposite = new EmbeddedSwingComposite(parent, SWT.NONE) {
protected JComponent createSwingComponent() {
/* Creating components */
JFrame frame = new JFrame();
canvas = new NetCanvas(frame);
canvas.setBackground( Color.BLACK );
canvas.setBounds( frame.getBounds() );
canvas.setDoubleBuffered( false );

return canvas;
}//end createSwingComponent
};
embeddedComposite.populate();
}//end

public void setFocus() {
embeddedComposite.setFocus();
}
Re: Advice on getting started? [message #4070 is a reply to message #3734] Tue, 16 October 2007 20:12 Go to previous messageGo to next message
Gordon Hirsch is currently offline Gordon HirschFriend
Messages: 100
Registered: July 2009
Senior Member
Cklewis wrote:
>
> I went off of your snippet you posted (the one with the JTables) and
> also your Eclipse article and i'm apparently doing something wrong still.

From the code you posted, it looks like you are trying to embed the
JTable in a SashForm. I took the standard SWT snippet for SashForm and
modified it to make one of its children a JTable, with the help of the
source code from my article. Here's the whole thing. I hope it helps.

/*********************************************************** ********************
* Copyright (c) 2000, 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation

************************************************************ *******************/
package org.eclipse.swt.snippets;

/*
* SashForm example snippet: create a sash form with three children
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
*/
import java.util.Vector;

import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

import swingintegration.example.EmbeddedSwingComposite;

public class Snippet109 {

public static void main (String [] args) {
final Display display = new Display ();
Shell shell = new Shell(display);
shell.setLayout (new FillLayout());

SashForm form = new SashForm(shell,SWT.HORIZONTAL);
form.setLayout(new FillLayout());

Composite child1 = new Composite(form,SWT.NONE);
child1.setLayout(new FillLayout());
new Label(child1,SWT.NONE).setText("Label in pane 1");

Composite child2 = new Composite(form,SWT.NONE);
child2.setLayout(new FillLayout());
new Button(child2,SWT.PUSH).setText("Button in pane2");

// Composite child3 = new Composite(form,SWT.NONE);
// child3.setLayout(new FillLayout());
// new Label(child3,SWT.PUSH).setText("Label in pane3");

EmbeddedSwingComposite child3 = new EmbeddedSwingComposite(form,
SWT.NONE) {
protected JComponent createSwingComponent() {
/* Creating components */
int nrows = 1000, ncolumns = 10;
Vector rows = new Vector();
for (int i = 0; i < nrows; i++) {
Vector row = new Vector();
for (int j = 0; j < ncolumns; j++) {
row.addElement("Item " + i + "-" + j);
}
rows.addElement(row);
}
Vector columns = new Vector();
for (int i = 0; i < ncolumns; i++) {
columns.addElement("Column " + i);
}
JTable table = new JTable(rows, columns);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.createDefaultColumnsFromModel();

JScrollPane scrollPane = new JScrollPane(table);

return scrollPane;
}
};
child3.populate();


form.setWeights(new int[] {30,40,30});
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}
Re: Advice on getting started? [message #4136 is a reply to message #4070] Wed, 17 October 2007 21:25 Go to previous messageGo to next message
Chris Kwon Lewis is currently offline Chris Kwon LewisFriend
Messages: 24
Registered: July 2009
Junior Member
Thanks, the snippet you posted was really helpful. The process was
different than what I expected. I thought the composite I was suppose to
make was SWT.EMBEDDED | SWT.NO_BACKGROUND.

My program seems to be working great and performance wise I haven't
noticed a difference (the program has to redraw the screen every .5
seconds or so). I have a few bugs right now and i'm hoping it's on my
end and not the swing integration.

Btw do I need to ever call setFocus()?

Thanks again, you've saved me a lot of hours of work. Hope other people
can use the snippet to help them get started as well.
Re: Advice on getting started? [message #4205 is a reply to message #4136] Wed, 17 October 2007 22:09 Go to previous message
Gordon Hirsch is currently offline Gordon HirschFriend
Messages: 100
Registered: July 2009
Senior Member
Cklewis wrote:
> Thanks, the snippet you posted was really helpful. The process was
> different than what I expected. I thought the composite I was suppose to
> make was SWT.EMBEDDED | SWT.NO_BACKGROUND.

Sorry if that was confusing. The EmbeddedSwingComposite actually wraps
and builds on the SWT.EMBEDDED composite, so you don't have to create
one yourself.

>
> My program seems to be working great and performance wise I haven't
> noticed a difference (the program has to redraw the screen every .5
> seconds or so). I have a few bugs right now and i'm hoping it's on my
> end and not the swing integration.
>
> Btw do I need to ever call setFocus()?

Nothing about the Swing integration requires a setFocus(). I can't say
about your particular application though...

The original code snippet I posted had a call to setFocus because it
implemented a view part for the Eclipse Rich Client Platform. That
wouldn't apply in your case.
Re: Advice on getting started? [message #573141 is a reply to message #3635] Mon, 15 October 2007 17:07 Go to previous message
Gordon Hirsch is currently offline Gordon HirschFriend
Messages: 100
Registered: July 2009
Senior Member
Cklewis wrote:
> I thought it would be best to ask a few questions before diving into my
> project of combining swt and swing.
>
> First, thanks for that snippet you posted Gordon. I noticed you used
> "EmbeddedSwingComposite" like an object. Currently it is an abstract
> class, do you recommend making it non abstract and just putting in the
> code I want for createSwingComponent() to suit my own program?

Actually the snippet creates an anonymous subclass of
EmbeddedSwingComposite. The subclass implements only the
createSwingComponent() method. That's basically how it was intended to
be used.

....
>
> Basically:
> NetCanvas(My file) extends PCanvas(Piccolo)
> PCanvas(Piccolo) extends JComponent (swing)
>
> So as of now, I'm thinking:
> 1)Use a swt component to hold the JComponent (NetCanvas) in it
> 2)Bring your examples folder into my workspace to use as helper classes
> for EmbeddedSwingComposite.
> 3)Making the EmbeddedSwingComposite non abstract and putting my code
> into createSwingComponent()

1 and 2 sound fine for now. See advice above for creating a subclass of
EmbeddedSwingComposite (in your own folder) instead of 3. Implement the
createSwingComponent() method to create your NetCanvas.

>
> Does that sound about right? Also I notice James submitted some
> suggestions, do I need to fix anything major to the sample code as of
> right now?

I would focus on getting the original code working in your project
first. But you definitely should take a look at his suggestions,
especially if you are noticing problems.

We are working on getting the project approved and moving it forward. If
all goes well, there should be an updated CVS code repository available
in the future. Until then, it's a bit of pain, sorry. (And, there are no
guarantees that the programming interfaces will stay the same.)

>
> Also I'm still a little unclear on the things I need to schedule
> individually for swing and swt. What type of general things need to be
> scheduled by me?

It completely depends on what you are doing. Basically, you just need to
try to make your AWT/Swing API calls on the AWT event thread and SWT API
calls on the SWT event thread.
Re: Advice on getting started? [message #573164 is a reply to message #3704] Mon, 15 October 2007 20:41 Go to previous message
Chris Kwon Lewis is currently offline Chris Kwon LewisFriend
Messages: 24
Registered: July 2009
Junior Member
First, thanks for taking the time to help me out.
> Actually the snippet creates an anonymous subclass of
> EmbeddedSwingComposite. The subclass implements only the
> createSwingComponent() method. That's basically how it was intended to
> be used.

Oh ok. I wasn't aware you could do it like that with an abstract class.
I thought I had to "extend" my class to 'EmbeddedSwingComposite' since
it was abstract (or make it non abstract). I'm still a student, so sorry
for the newbiness :)

I went off of your snippet you posted (the one with the JTables) and
also your Eclipse article and i'm apparently doing something wrong still.


In the old code, we put the canvas onto a JFrame.

Am I missing a function call?
What do I do with the returned JComponent of createSwingComponent()?
Should I be returning the frame instead of the canvas?


So the code i used was:
..
..
..
SashForm sf = new SashForm(main_shell, SWT.VERTICAL);
sf.setLayoutData(new GridData(SWT.FILL,SWT.FILL, true,true));


Composite swing_composite = new Composite(sf, SWT.EMBEDDED |
SWT.NO_BACKGROUND); // put this composite as the top portion of the sashform

createPartControl(swing_composite);
setFocus();

..
..
..

then my function that I went off of your snippet example:

public void createPartControl(Composite parent) {
embeddedComposite = new EmbeddedSwingComposite(parent, SWT.NONE) {
protected JComponent createSwingComponent() {
/* Creating components */
JFrame frame = new JFrame();
canvas = new NetCanvas(frame);
canvas.setBackground( Color.BLACK );
canvas.setBounds( frame.getBounds() );
canvas.setDoubleBuffered( false );

return canvas;
}//end createSwingComponent
};
embeddedComposite.populate();
}//end

public void setFocus() {
embeddedComposite.setFocus();
}
Re: Advice on getting started? [message #573186 is a reply to message #3734] Tue, 16 October 2007 20:12 Go to previous message
Gordon Hirsch is currently offline Gordon HirschFriend
Messages: 100
Registered: July 2009
Senior Member
Cklewis wrote:
>
> I went off of your snippet you posted (the one with the JTables) and
> also your Eclipse article and i'm apparently doing something wrong still.

From the code you posted, it looks like you are trying to embed the
JTable in a SashForm. I took the standard SWT snippet for SashForm and
modified it to make one of its children a JTable, with the help of the
source code from my article. Here's the whole thing. I hope it helps.

/*********************************************************** ********************
* Copyright (c) 2000, 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation

************************************************************ *******************/
package org.eclipse.swt.snippets;

/*
* SashForm example snippet: create a sash form with three children
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
*/
import java.util.Vector;

import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

import swingintegration.example.EmbeddedSwingComposite;

public class Snippet109 {

public static void main (String [] args) {
final Display display = new Display ();
Shell shell = new Shell(display);
shell.setLayout (new FillLayout());

SashForm form = new SashForm(shell,SWT.HORIZONTAL);
form.setLayout(new FillLayout());

Composite child1 = new Composite(form,SWT.NONE);
child1.setLayout(new FillLayout());
new Label(child1,SWT.NONE).setText("Label in pane 1");

Composite child2 = new Composite(form,SWT.NONE);
child2.setLayout(new FillLayout());
new Button(child2,SWT.PUSH).setText("Button in pane2");

// Composite child3 = new Composite(form,SWT.NONE);
// child3.setLayout(new FillLayout());
// new Label(child3,SWT.PUSH).setText("Label in pane3");

EmbeddedSwingComposite child3 = new EmbeddedSwingComposite(form,
SWT.NONE) {
protected JComponent createSwingComponent() {
/* Creating components */
int nrows = 1000, ncolumns = 10;
Vector rows = new Vector();
for (int i = 0; i < nrows; i++) {
Vector row = new Vector();
for (int j = 0; j < ncolumns; j++) {
row.addElement("Item " + i + "-" + j);
}
rows.addElement(row);
}
Vector columns = new Vector();
for (int i = 0; i < ncolumns; i++) {
columns.addElement("Column " + i);
}
JTable table = new JTable(rows, columns);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.createDefaultColumnsFromModel();

JScrollPane scrollPane = new JScrollPane(table);

return scrollPane;
}
};
child3.populate();


form.setWeights(new int[] {30,40,30});
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}
Re: Advice on getting started? [message #573208 is a reply to message #4070] Wed, 17 October 2007 21:25 Go to previous message
Chris Kwon Lewis is currently offline Chris Kwon LewisFriend
Messages: 24
Registered: July 2009
Junior Member
Thanks, the snippet you posted was really helpful. The process was
different than what I expected. I thought the composite I was suppose to
make was SWT.EMBEDDED | SWT.NO_BACKGROUND.

My program seems to be working great and performance wise I haven't
noticed a difference (the program has to redraw the screen every .5
seconds or so). I have a few bugs right now and i'm hoping it's on my
end and not the swing integration.

Btw do I need to ever call setFocus()?

Thanks again, you've saved me a lot of hours of work. Hope other people
can use the snippet to help them get started as well.
Re: Advice on getting started? [message #573228 is a reply to message #4136] Wed, 17 October 2007 22:09 Go to previous message
Gordon Hirsch is currently offline Gordon HirschFriend
Messages: 100
Registered: July 2009
Senior Member
Cklewis wrote:
> Thanks, the snippet you posted was really helpful. The process was
> different than what I expected. I thought the composite I was suppose to
> make was SWT.EMBEDDED | SWT.NO_BACKGROUND.

Sorry if that was confusing. The EmbeddedSwingComposite actually wraps
and builds on the SWT.EMBEDDED composite, so you don't have to create
one yourself.

>
> My program seems to be working great and performance wise I haven't
> noticed a difference (the program has to redraw the screen every .5
> seconds or so). I have a few bugs right now and i'm hoping it's on my
> end and not the swing integration.
>
> Btw do I need to ever call setFocus()?

Nothing about the Swing integration requires a setFocus(). I can't say
about your particular application though...

The original code snippet I posted had a call to setFocus because it
implemented a view part for the Eclipse Rich Client Platform. That
wouldn't apply in your case.
Previous Topic:For Starters...
Next Topic:Albireo Creation Review
Goto Forum:
  


Current Time: Wed Nov 14 15:04:55 GMT 2018

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

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

Back to the top