Re: j2s-development] Nested Shells
Brought to you by:
zhourenjian
|
From: Zhou R. <jo...@sj...> - 2006-10-16 14:34:24
|
Hi Sal,
Sorry for misunderstanding about "nested Shells" concept.
For "MDI" type interfaces by SWT, you may add Control listeners to
parent Shell so parent Shell and children Shells can perform as MDI.
Here is a SWT snippet (You can also check it out from
sources/tests/net.sf.j2s.test.swt/src/net/sf/j2s/test/swt/widgets/TestNestedShells.java)
Display display = new Display ();
final Shell shell = new Shell (display);
shell.setText ("hi");
shell.setSize(210, 120);
shell.open ();
final Shell shell2 = new Shell(shell);
shell2.setSize(110, 60);
shell2.open();
shell.addControlListener(new ControlListener() {
int lastX, lastY;
public void controlResized(ControlEvent e) {
}
public void controlMoved(ControlEvent e) {
Point pt = shell.getLocation();
Point pt2 = shell2.getLocation();
shell2.setLocation(pt2.x + pt.x - lastX, pt2.y + pt.y -
lastY);
lastX = pt.x;
lastY = pt.y;
}
});
while (!shell.isDisposed()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
Before you mentioned such a thing, moving and resizing a J2S Shell do
not send out SWT.move and SWT.resize events. It was a bug. And I just
fixed that bug.
So before you can run the above snippet in Java2Script mode, you should
check out the latest code and build the whole things (Following
instructions of setting up Java2Script environment from SVN repository
by the website).
Regards
Sal wrote:
> Zhou,
>
> Thanks much for the info. I think I may have been a little unclear on
> the 'nested Shells' comment, I apologize for that.
>
> For example I have this snippet:
>
> Shell child = new Shell(parent);
> child.setSize(200, 200);
> child.open();
>
> My understanding is that this should put the child shell into the
> parent shell. So that they will nest inside of each other, and if the
> parent shell is moved, the child shell will also move. They'll appear
> 'nested' as in - the 'MDI' type interfaces supported in some Windows
> apps.
>
> It seems this feature is supported in the Windows-SWT, so I was
> curious as to if it will be implemented in j2s.
>
> The reason I am attempting this is because I need all the
> functionality of a Shell (title bar, open/close buttons, etc.) but
> have them as children of another window which has the same kind of
> title bar. (And use the same codebase for the Web/j2s version as the
> Desktop version).
>
> Thanks much for the help,
>
> - Sal
>
>
> On 10/14/06, *Zhou Renjian* <jo...@sj... <mailto:jo...@sj...>> wrote:
>
> Hi Sal,
>
> GWT has its advantages: its generated *.js file size is much smaller
> than Java2Script's and its performance is very good. GWT's *.js is
> project dependent while Java2Script's *.js is library dependent.
> And the
> motivation of GWT's code generation is "to be as small and as
> efficient
> as possible" while Java2Script's motivation is "to provide same
> familiar
> Java APIs in JavaScript". And there are lots of other differences. In
> fact, GWT is great in many designs.
>
> And about nested Shells: if a shell is designed to popup in a
> method B,
> the method B won't block later method C. For example:
> public void methodB() {
> ...
> shell.open();
> while (...)
> ...
> }
> public void callMethod() {
> methodA();
> methodB();
> methodC();
> }
>
> methodC will always be called after methodB without blocking of the
> shell inside methodB, which is incorrect. And developer should avoid
> such method calls by wrapping them into callbacks of methodB.
>
> If you popup shells orderly in the same method scope, Java2Script
> compiler will generate JavaScript correctly and shells will popup in
> correct order. For example:
> public void aMethod() {
> ...
> shell.open();
> while (...)
> ...
> ...
> anotherShell.open();
> while (...)
> ...
> }
> anotherShell open only after the first shell is closed, which is
> correct.
>
> You can inspect into the generated JavaScript to get the details.
>
> Concept of nested Shells is considered a problem of "Asynchronous
> Programming v.s. Synchronous Programming" in JavaScript. In
> JavaScript,
> no blocking by while loop or Thread.sleep or Object.wait exists. So
> synchronous programming should be converted into asynchronous
> programming. Java2Script compiler tries to help such conversions but
> won't help all. And I think nested Shells may not be implemented in
> release 1.0. If you find any possible ways to implement it, please
> discuss it on the mail list or implement it.
>
> Regards,
> Zhou Renjian
>
> Sal Ferro wrote:
> > Hi,
> >
> > I'm new to the list. By the way - j2s is really cool, hands down
> the
> > best Javascript/RIA framework in existence currently, in my opinion.
> > I just hope sourceforge is ready for the traffic, when word spreads
> > and people come flocking to use this great new technology!! I
> don't
> > understand the people comparing it to GWT. Very different products,
> > GWT's scope and functionality kindof pales in my comparison (and no
> > eclipse integration! yuck!).
> >
> > My question: I noticed nested Shells are not supported yet. Am I
> > missing anything, or is it just not yet implemented? If not are
> there
> > any plan for implementing the feature yet? I am willing to
> > help implement it.
> >
> > I've become somewhat familiar with j2s sources, using it for
> several
> > weeks now, but a pointer or two on the 'suggested' approach to
> > implement it would help a little to be sure I don't go off into
> the weeds.
> >
> > Thanks to the devs that make this library possible - I hope I
> can help
> > soon.
> >
> > Thanks,
> >
> > - Sal
> >
>
|