Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Using SWT via JNI Invocation on Mac OS X
Using SWT via JNI Invocation on Mac OS X [message #439693] Wed, 14 July 2004 18:26 Go to next message
Eclipse UserFriend
Originally posted by: good.dolet.net

We are writing a plug-in for Finale 2004, an application that runs on both
Windows and Macintosh OS X. We want to write the user interface in Java to
keep as much as possible cross-platform. Since Finale is a Carbon
application on OS X, that means we can't use Swing but we should be able to
use SWT.

Finale plug-ins need to be written in C++ to provide Finale with specified
function entry points. So we do the bulk of the plug-in in Java by using the
JNI invocation interface, then using JNI to call back into the Finale
application. (Similar to SWT, our JNI interface back into Finale provides a
thin Java veneer over the native Finale API.)

Since this is a plug-in, not a main application, all we are doing for the
user interface is putting up dialog boxes. Here's the test Java code we're
using. Our real-life examples will be application modal dialogs, not message
boxes, but otherwise not much more complicated:

// Testing use of SWT dialogs within a plug-in
Display display = Display.getDefault();
Shell shell = new Shell(display);
MessageBox mbox = new MessageBox(shell, SWT.ICON_INFORMATION |
SWT.OK);
mbox.setText("Our Finale Plug-In");
mbox.setMessage("This is an SWT message box");
int mboxResult = mbox.open();
shell.dispose();
display.dispose();

On Windows this works fine. On Mac OS X 10.3, the windows appear, but the
main application menu gets zapped as if the shell were creating its own
menu. After the plug-in runs, any use of the GUI crashes Finale. This is
with SWT 3.0.

I suspect this may be related to the need for the java_swt program on OS X
that I have read about on this newsgroup. But as I understand it, this is a
wrapper application, so I don't understand how to invoke it via JNI
invocation's JNI_CreateJavaVM call in C++.

Another possibility is that creating a Shell implies creating a new
top-level window, but all we want are dialog boxes for an existing C++
application and top-level window. But since things work OK on Windows,
java_swt seems the more likely suspect. There are probably other
possibilities for trouble that I have overlooked. Googling for SWT plus JNI
Invocation did not reveal much, and what I did find was Windows-specific.

Any advice as to how to get SWT working on Mac OS X from JNI Invocation
would be most appreciated!

Thanks,

Michael Good
Recordare LLC
www.recordare.com
Re: Using SWT via JNI Invocation on Mac OS X [message #439746 is a reply to message #439693] Thu, 15 July 2004 16:24 Go to previous messageGo to next message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
Sounds like there are 2 problems:

1) The menu bar gets zapped as if the shell were creating its own menu
2) Any use of the GUI crashes Finale

I'm not sure what "zapped" means. Does it disappear?
Does Finale do any UI work? Does it run an event loop?
Can you make a simple JNI + SWT program that zaps the menu bar and crashes?

"Michael Good" <good@dolet.net> wrote in message
news:cd3tqk$t67$1@eclipse.org...
> We are writing a plug-in for Finale 2004, an application that runs on both
> Windows and Macintosh OS X. We want to write the user interface in Java to
> keep as much as possible cross-platform. Since Finale is a Carbon
> application on OS X, that means we can't use Swing but we should be able
to
> use SWT.
>
> Finale plug-ins need to be written in C++ to provide Finale with specified
> function entry points. So we do the bulk of the plug-in in Java by using
the
> JNI invocation interface, then using JNI to call back into the Finale
> application. (Similar to SWT, our JNI interface back into Finale provides
a
> thin Java veneer over the native Finale API.)
>
> Since this is a plug-in, not a main application, all we are doing for the
> user interface is putting up dialog boxes. Here's the test Java code we're
> using. Our real-life examples will be application modal dialogs, not
message
> boxes, but otherwise not much more complicated:
>
> // Testing use of SWT dialogs within a plug-in
> Display display = Display.getDefault();
> Shell shell = new Shell(display);
> MessageBox mbox = new MessageBox(shell, SWT.ICON_INFORMATION |
> SWT.OK);
> mbox.setText("Our Finale Plug-In");
> mbox.setMessage("This is an SWT message box");
> int mboxResult = mbox.open();
> shell.dispose();
> display.dispose();
>
> On Windows this works fine. On Mac OS X 10.3, the windows appear, but the
> main application menu gets zapped as if the shell were creating its own
> menu. After the plug-in runs, any use of the GUI crashes Finale. This is
> with SWT 3.0.
>
> I suspect this may be related to the need for the java_swt program on OS X
> that I have read about on this newsgroup. But as I understand it, this is
a
> wrapper application, so I don't understand how to invoke it via JNI
> invocation's JNI_CreateJavaVM call in C++.
>
> Another possibility is that creating a Shell implies creating a new
> top-level window, but all we want are dialog boxes for an existing C++
> application and top-level window. But since things work OK on Windows,
> java_swt seems the more likely suspect. There are probably other
> possibilities for trouble that I have overlooked. Googling for SWT plus
JNI
> Invocation did not reveal much, and what I did find was Windows-specific.
>
> Any advice as to how to get SWT working on Mac OS X from JNI Invocation
> would be most appreciated!
>
> Thanks,
>
> Michael Good
> Recordare LLC
> www.recordare.com
>
>
Re: Using SWT via JNI Invocation on Mac OS X [message #439752 is a reply to message #439746] Thu, 15 July 2004 17:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: good.dolet.net

Hi Steve,

Thanks for the reply. Sorry for the unhelpful "zapped" description. When
Finale starts up, the menu bar looks like this:

Apple - Finale 2004b - File - Edit - View - Options - MIDI - Tools -
Window - Plug-ins - Help

Once our SWT dialog box appears, the menu bar looks like this:

Apple - Finale 2004b - Help (grayed out)

It stays like this after our plug-in completes and returns to Finale. When I
try to do any menu choices, either via the menu or keyboard shortcuts,
Finale crashes.

Finale does have its own UI and event loop. We want to supplement the UI
with some modal SWT dialog boxes.

A standalone JNI + SWT program should have it's own menu bar. But in our
case, we don't want ourSWT UI to affect Finale's menu bar at all - we're
just a plug-in. If you still think it would be helpful for diagnosis to try
out the standalone JNI program, please let me know.

Thanks for your help!

Michael Good
Recordare LLC

"Steve Northover" <steve_northover@ca.ibm.com> wrote in message
news:cd6b2b$qak$1@eclipse.org...
> Sounds like there are 2 problems:
>
> 1) The menu bar gets zapped as if the shell were creating its own menu
> 2) Any use of the GUI crashes Finale
>
> I'm not sure what "zapped" means. Does it disappear?
> Does Finale do any UI work? Does it run an event loop?
> Can you make a simple JNI + SWT program that zaps the menu bar and
crashes?
>
> "Michael Good" <good@dolet.net> wrote in message
> news:cd3tqk$t67$1@eclipse.org...
> > We are writing a plug-in for Finale 2004, an application that runs on
both
> > Windows and Macintosh OS X. We want to write the user interface in Java
to
> > keep as much as possible cross-platform. Since Finale is a Carbon
> > application on OS X, that means we can't use Swing but we should be able
> to
> > use SWT.
> >
> > Finale plug-ins need to be written in C++ to provide Finale with
specified
> > function entry points. So we do the bulk of the plug-in in Java by using
> the
> > JNI invocation interface, then using JNI to call back into the Finale
> > application. (Similar to SWT, our JNI interface back into Finale
provides
> a
> > thin Java veneer over the native Finale API.)
> >
> > Since this is a plug-in, not a main application, all we are doing for
the
> > user interface is putting up dialog boxes. Here's the test Java code
we're
> > using. Our real-life examples will be application modal dialogs, not
> message
> > boxes, but otherwise not much more complicated:
> >
> > // Testing use of SWT dialogs within a plug-in
> > Display display = Display.getDefault();
> > Shell shell = new Shell(display);
> > MessageBox mbox = new MessageBox(shell, SWT.ICON_INFORMATION
|
> > SWT.OK);
> > mbox.setText("Our Finale Plug-In");
> > mbox.setMessage("This is an SWT message box");
> > int mboxResult = mbox.open();
> > shell.dispose();
> > display.dispose();
> >
> > On Windows this works fine. On Mac OS X 10.3, the windows appear, but
the
> > main application menu gets zapped as if the shell were creating its own
> > menu. After the plug-in runs, any use of the GUI crashes Finale. This is
> > with SWT 3.0.
> >
> > I suspect this may be related to the need for the java_swt program on OS
X
> > that I have read about on this newsgroup. But as I understand it, this
is
> a
> > wrapper application, so I don't understand how to invoke it via JNI
> > invocation's JNI_CreateJavaVM call in C++.
> >
> > Another possibility is that creating a Shell implies creating a new
> > top-level window, but all we want are dialog boxes for an existing C++
> > application and top-level window. But since things work OK on Windows,
> > java_swt seems the more likely suspect. There are probably other
> > possibilities for trouble that I have overlooked. Googling for SWT plus
> JNI
> > Invocation did not reveal much, and what I did find was
Windows-specific.
> >
> > Any advice as to how to get SWT working on Mac OS X from JNI Invocation
> > would be most appreciated!
> >
> > Thanks,
> >
> > Michael Good
> > Recordare LLC
> > www.recordare.com
> >
> >
>
>
Re: Using SWT via JNI Invocation on Mac OS X [message #439914 is a reply to message #439752] Mon, 19 July 2004 16:22 Go to previous messageGo to next message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
You can't have multiple event loops on the Macintosh. Strange things happen
when you do. Not sure how to proceed ...

"Michael Good" <good@dolet.net> wrote in message
news:cd6e2i$vr8$1@eclipse.org...
> Hi Steve,
>
> Thanks for the reply. Sorry for the unhelpful "zapped" description. When
> Finale starts up, the menu bar looks like this:
>
> Apple - Finale 2004b - File - Edit - View - Options - MIDI - Tools -
> Window - Plug-ins - Help
>
> Once our SWT dialog box appears, the menu bar looks like this:
>
> Apple - Finale 2004b - Help (grayed out)
>
> It stays like this after our plug-in completes and returns to Finale. When
I
> try to do any menu choices, either via the menu or keyboard shortcuts,
> Finale crashes.
>
> Finale does have its own UI and event loop. We want to supplement the UI
> with some modal SWT dialog boxes.
>
> A standalone JNI + SWT program should have it's own menu bar. But in our
> case, we don't want ourSWT UI to affect Finale's menu bar at all - we're
> just a plug-in. If you still think it would be helpful for diagnosis to
try
> out the standalone JNI program, please let me know.
>
> Thanks for your help!
>
> Michael Good
> Recordare LLC
>
> "Steve Northover" <steve_northover@ca.ibm.com> wrote in message
> news:cd6b2b$qak$1@eclipse.org...
> > Sounds like there are 2 problems:
> >
> > 1) The menu bar gets zapped as if the shell were creating its own menu
> > 2) Any use of the GUI crashes Finale
> >
> > I'm not sure what "zapped" means. Does it disappear?
> > Does Finale do any UI work? Does it run an event loop?
> > Can you make a simple JNI + SWT program that zaps the menu bar and
> crashes?
> >
> > "Michael Good" <good@dolet.net> wrote in message
> > news:cd3tqk$t67$1@eclipse.org...
> > > We are writing a plug-in for Finale 2004, an application that runs on
> both
> > > Windows and Macintosh OS X. We want to write the user interface in
Java
> to
> > > keep as much as possible cross-platform. Since Finale is a Carbon
> > > application on OS X, that means we can't use Swing but we should be
able
> > to
> > > use SWT.
> > >
> > > Finale plug-ins need to be written in C++ to provide Finale with
> specified
> > > function entry points. So we do the bulk of the plug-in in Java by
using
> > the
> > > JNI invocation interface, then using JNI to call back into the Finale
> > > application. (Similar to SWT, our JNI interface back into Finale
> provides
> > a
> > > thin Java veneer over the native Finale API.)
> > >
> > > Since this is a plug-in, not a main application, all we are doing for
> the
> > > user interface is putting up dialog boxes. Here's the test Java code
> we're
> > > using. Our real-life examples will be application modal dialogs, not
> > message
> > > boxes, but otherwise not much more complicated:
> > >
> > > // Testing use of SWT dialogs within a plug-in
> > > Display display = Display.getDefault();
> > > Shell shell = new Shell(display);
> > > MessageBox mbox = new MessageBox(shell,
SWT.ICON_INFORMATION
> |
> > > SWT.OK);
> > > mbox.setText("Our Finale Plug-In");
> > > mbox.setMessage("This is an SWT message box");
> > > int mboxResult = mbox.open();
> > > shell.dispose();
> > > display.dispose();
> > >
> > > On Windows this works fine. On Mac OS X 10.3, the windows appear, but
> the
> > > main application menu gets zapped as if the shell were creating its
own
> > > menu. After the plug-in runs, any use of the GUI crashes Finale. This
is
> > > with SWT 3.0.
> > >
> > > I suspect this may be related to the need for the java_swt program on
OS
> X
> > > that I have read about on this newsgroup. But as I understand it, this
> is
> > a
> > > wrapper application, so I don't understand how to invoke it via JNI
> > > invocation's JNI_CreateJavaVM call in C++.
> > >
> > > Another possibility is that creating a Shell implies creating a new
> > > top-level window, but all we want are dialog boxes for an existing C++
> > > application and top-level window. But since things work OK on Windows,
> > > java_swt seems the more likely suspect. There are probably other
> > > possibilities for trouble that I have overlooked. Googling for SWT
plus
> > JNI
> > > Invocation did not reveal much, and what I did find was
> Windows-specific.
> > >
> > > Any advice as to how to get SWT working on Mac OS X from JNI
Invocation
> > > would be most appreciated!
> > >
> > > Thanks,
> > >
> > > Michael Good
> > > Recordare LLC
> > > www.recordare.com
> > >
> > >
> >
> >
>
>
Re: Using SWT via JNI Invocation on Mac OS X [message #439940 is a reply to message #439914] Mon, 19 July 2004 18:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: good.dolet.net

Hi Steve,

Thanks again for your assistance. It sounds like we will need to do our
dialog boxes in platform-specific C++ then.

If SWT adds a way to somehow hook into the Mac OS X event loop in the
future, I'd be interested in testing it. My correct e-mail address is
available on the "About Us" page at www.recordare.com.

Thanks,

Michael Good
Recordare LLC

"Steve Northover" <steve_northover@ca.ibm.com> wrote in message
news:cdgsd9$ca1$1@eclipse.org...
> You can't have multiple event loops on the Macintosh. Strange things
happen
> when you do. Not sure how to proceed ...
Re: Using SWT via JNI Invocation on Mac OS X [message #439996 is a reply to message #439940] Tue, 20 July 2004 13:01 Go to previous messageGo to next message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
I think so. Sounds like a bit of overkill to use SWT just for dialog boxes.
Might be cool to do the whole thing in Java some day? Sorry it couldn't be
made to work for you.

"Michael Good" <good@dolet.net> wrote in message
news:cdh2gv$ofm$1@eclipse.org...
> Hi Steve,
>
> Thanks again for your assistance. It sounds like we will need to do our
> dialog boxes in platform-specific C++ then.
>
> If SWT adds a way to somehow hook into the Mac OS X event loop in the
> future, I'd be interested in testing it. My correct e-mail address is
> available on the "About Us" page at www.recordare.com.
>
> Thanks,
>
> Michael Good
> Recordare LLC
>
> "Steve Northover" <steve_northover@ca.ibm.com> wrote in message
> news:cdgsd9$ca1$1@eclipse.org...
> > You can't have multiple event loops on the Macintosh. Strange things
> happen
> > when you do. Not sure how to proceed ...
>
>
Re: Using SWT via JNI Invocation on Mac OS X [message #440177 is a reply to message #439996] Fri, 23 July 2004 23:33 Go to previous message
Eclipse UserFriend
Originally posted by: good.dolet.net

The application is not our code - just the plug-in - so we don't get the
chance to rewrite it in Java!

This one plug-in is just a dialog box UI, just in case it had to be done in
C++. But we would like to use the same framework for other larger UIs, and
not have to learn the separate C++ UI tools for Mac and Windows. (This is a
port from Visual Basic, so the Mac stuff is all new to me.) Instead we will
leave the more complex UIs to standalone applications that are all-Java.

Thanks again! We'll certainly be considering SWT for our future standalone
Java apps.

Michael Good
Recordare LLC
Previous Topic:date/calendar drop-down
Next Topic:date/calendar drop-down
Goto Forum:
  


Current Time: Fri Apr 26 05:13:19 GMT 2024

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

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

Back to the top