Home » Archived » Albireo » Advice on getting started?
|
Re: Advice on getting started? [message #3704 is a reply to message #3635] |
Mon, 15 October 2007 17:07 |
Gordon Hirsch 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 |
Chris Kwon Lewis 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 |
Gordon Hirsch 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 #573141 is a reply to message #3635] |
Mon, 15 October 2007 17:07 |
Gordon Hirsch 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 |
Chris Kwon Lewis 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 |
Gordon Hirsch 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 ();
}
}
|
|
| | |
Goto Forum:
Current Time: Fri Sep 20 07:05:19 GMT 2024
Powered by FUDForum. Page generated in 0.04459 seconds
|