Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] SWT_AWT bridge - SWT in Swing


Hi Chris,

Windows problem:
 -> your code should say "if (!display.readAndDispatch())"

Linux problem (not visible, Sun bug)
-> https://bugs.eclipse.org/bugs/show_bug.cgi?id=161911

Mac problem (not implemented)
-> https://bugs.eclipse.org/bugs/show_bug.cgi?id=145890

Steve



"Christopher Deckers" <chrriis@xxxxxxxxx>
Sent by: platform-swt-dev-bounces@xxxxxxxxxxx

09/10/2007 03:27 PM

Please respond to
"Eclipse Platform SWT component developers list."        <platform-swt-dev@xxxxxxxxxxx>

To
"Eclipse Platform SWT component developers list." <platform-swt-dev@xxxxxxxxxxx>
cc
Subject
[platform-swt-dev] SWT_AWT bridge - SWT in Swing





Hi all,

I spent some time investigating the SWT_AWT bridge, but in the other
direction than the usual way: SWT in a Swing frame. I have a few
discoveries to share, and some concerns.
Note that I added the simplest working test at the end of this e-mail.

1. On Windows it works, except that some events get stuck. As a work
around, I have to artifically create a thread that wakes up the SWT
thread. If you remove that thread, you can notice that the first click
on the button does not seem to activate the button (the problem is
more serious with more complex components of course). I am not sure
why this thread needs to be created, and if this can be fixed in SWT,
but since a work around exists we probably can live with it for the
time being...

2. On Linux, the bridge seems to work, but nothing is visible. I know
the component is properly instantiated and that it has a proper life
cycle (for example a web browser loads a page, and calls the listeners
to notify about the status) but nothing is displayed. This is critical
because Linux is typically the second platform that we usually need to
support.
With AWT, native integration requires to subclass a Canvas, to mark
its paint(g) method native, and in the native code there is an access
to the native handle (with the JAWT native library). In our case, the
SWT_AWT bridge does not require subclassing. Is there a design issue
with getting the native handle on Linux? Or is the problem elsewhere,
when using this native handle? Is there any work around?

3. I haven't investigated on OSX as I don't have this OS, and I know
the threading may make it impossible.

First, have I done something wrong in my test case?
Second, and if I am correct, is there any plan to fix this side of the bridge?

Cheers,
-Christopher


---------------------- CODE ------------------

public class TestFrame extends JFrame {

 public TestFrame() {
   setDefaultCloseOperation(EXIT_ON_CLOSE);
   Canvas canvas = new Canvas() {
     public void addNotify() {
       super.addNotify();
       final Canvas canvas_ = this;
       display.asyncExec(new Runnable() {
         public void run() {
           final Shell shell = SWT_AWT.new_Shell(display, canvas_);
           shell.setLayout(new FillLayout());
           Button button = new Button(shell, SWT.PUSH);
           button.setText("push");
           // The initial size is wrong so we have to force it
           shell.setSize(canvas_.getWidth(), canvas_.getHeight());
         }
       });
     }
   };
   getContentPane().add(canvas, BorderLayout.CENTER);
   setSize(400, 400);
 }

 protected static Display display = new Display();

 public static void main(String[] args) {
   SwingUtilities.invokeLater(new Runnable() {
     public void run() {
       new TestFrame().setVisible(true);
     }
   });
   new Thread("SWT wake-up thread") {
     public void run() {
       while(true) {
         try {
           sleep(50);
           // for some reasons, need to wake up everytime it sleeps
using a fake event, or it may never process certain events
           display.asyncExec(new Runnable() {
             public void run() {
             }
           });
         } catch(Exception e) {
           e.printStackTrace();
         }
       }
     }
   }.start();
   while(true) {
     if(display.readAndDispatch()) {
       display.sleep();
     }
   }
 }

}
_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev


Back to the top