List Info

Thread: Modal Swing JDialog




Modal Swing JDialog
user name
2007-09-22 15:12:50
Hi,

my extension displays a dialog when certain Calc cells are 
double-clicked (which now works, thanks to the great support
here ). 
There should be no other interaction with the spreadsheet
during this 
dialog is shown, so a modal JDialog comes to mind. That
would require me 
to provide a java.awt.Frame as parent so that OOo doesn't
completely 
freeze as well as the dialog staying on top within the
application 
context (and not on top of ALL windows).
I'm currently a bit stuck with this. There has been a
similar request on 
the oooforums.org, but that has been (more or less)
unanswered.
I know about the XSystemDependentWindowPeer interface which
should be 
able to "[Return] a global reference to a
java.awt.Component object 
provided from the JNI-API" but on the one hand I don't
think that I 
could simply get a java.awt.Frame out of that Component and
on the other 
hand the "com.sun.star.frame.Desktop" doesn't
provide this interface.

So I have two questions: does OOo somehow provide a
java.awt.Frame I can 
use as parent? If not: is there a (prefered) way I can
manually lock OOo 
and implement its main loop? That way I could lock it, show
the JDialog 
modal in its own thread and while the thread is alive
process OOs main 
loop. When the thread ends, that loop is left, my code
proceeds and OOo 
can regain control. (I hope you know what I mean, it's been
a bit hard 
to describe).

Thanks in advance,
Andreas.

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


Re: Modal Swing JDialog
user name
2007-09-22 15:37:05
Hi Andreas,

On Sat, Sep 22, 2007 at 10:12:50PM +0200, Andreas Schneider
wrote:
> my extension displays a dialog when certain Calc cells
are 
> double-clicked (which now works, thanks to the great
support here ). 
> There should be no other interaction with the
spreadsheet during this 
> dialog is shown, so a modal JDialog comes to mind. That
would require me 
> to provide a java.awt.Frame as parent so that OOo
doesn't completely 
> freeze as well as the dialog staying on top within the
application 
> context (and not on top of ALL windows).
> I'm currently a bit stuck with this. There has been a
similar request on 
> the oooforums.org, but that has been (more or less)
unanswered.
> I know about the XSystemDependentWindowPeer interface
which should be 
> able to "[Return] a global reference to a
java.awt.Component object 
> provided from the JNI-API" but on the one hand I
don't think that I 
> could simply get a java.awt.Frame out of that Component
and on the other 
> hand the "com.sun.star.frame.Desktop" doesn't
provide this interface.
> 
> So I have two questions: does OOo somehow provide a
java.awt.Frame I can 
> use as parent? If not: is there a (prefered) way I can
manually lock OOo 
> and implement its main loop? That way I could lock it,
show the JDialog 
> modal in its own thread and while the thread is alive
process OOs main 
> loop. When the thread ends, that loop is left, my code
proceeds and OOo 
> can regain control. (I hope you know what I mean, it's
been a bit hard 
> to describe).

I don't have an answer to your questions. But here is
another approach that may
work for you. The Java API contains a class called
javax.swing.PopupFactory
which allows you to register and show JPanels as popups.
Basically you request
an instance of the currently used PopupFactory and then
connect the JPanel that
should be visible as popup to an instance of Component.
JComponent is a subclass
of Component so you should be able to connect the Popup to
your OOo instance.
Please see the API docs for PopupFactory for more details.
And please let me
know if you have any questions about this.




HTH, Wouter

-- 

People: "If she weighs the same as a Duck, she's made
of wood!"
Sir Bedevere: "And therefore...?"

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


Re: Modal Swing JDialog
user name
2007-09-22 15:52:49
Wouter van Reeven wrote:
> Hi Andreas,
>
> I don't have an answer to your questions. But here is
another approach that may
> work for you. The Java API contains a class called
javax.swing.PopupFactory
> which allows you to register and show JPanels as
popups. Basically you request
> an instance of the currently used PopupFactory and then
connect the JPanel that
> should be visible as popup to an instance of Component.
JComponent is a subclass
> of Component so you should be able to connect the Popup
to your OOo instance.
> Please see the API docs for PopupFactory for more
details. And please let me
> know if you have any questions about this.
>  
> HTH, Wouter

Nice, that would provide a good solution if my
interpretation of 
XSystemDependentWindowPeer.getWindowHandle is correct and
returns a 
java.awt.Component. But even if it is, I've not been able to
find a way 
to really use that interface yet (neither the Desktop nor
the 
SpreadsheetDocument did provide it).

Thanks so far!
Andreas.

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


Re: Modal Swing JDialog
user name
2007-09-23 15:05:14
Andreas Schneider escribió:
> Hi,
> 
> my extension displays a dialog when certain Calc cells
are 
> double-clicked (which now works, thanks to the great
support here ). 
> There should be no other interaction with the
spreadsheet during this 
> dialog is shown, so a modal JDialog comes to mind. That
would require me 
> to provide a java.awt.Frame as parent so that OOo
doesn't completely 
> freeze as well as the dialog staying on top within the
application 
> context (and not on top of ALL windows).
> I'm currently a bit stuck with this. There has been a
similar request on 
> the oooforums.org, but that has been (more or less)
unanswered.
> I know about the XSystemDependentWindowPeer interface
which should be 
> able to "[Return] a global reference to a
java.awt.Component object 
> provided from the JNI-API" but on the one hand I
don't think that I 
> could simply get a java.awt.Frame out of that Component
and on the other 
> hand the "com.sun.star.frame.Desktop" doesn't
provide this interface.
> 
> So I have two questions: does OOo somehow provide a
java.awt.Frame I can 
> use as parent? If not: is there a (prefered) way I can
manually lock OOo 
> and implement its main loop? That way I could lock it,
show the JDialog 
> modal in its own thread and while the thread is alive
process OOs main 
> loop. When the thread ends, that loop is left, my code
proceeds and OOo 
> can regain control. (I hope you know what I mean, it's
been a bit hard 
> to describe).
> 
> Thanks in advance,
> Andreas.
> 
>
------------------------------------------------------------
---------
> To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
> For additional commands, e-mail: dev-helpapi.openoffice.org
> 
> 

I'm not sure if it is possible to integrate a Java window
into OOo 
windowing system. On the contrary, the integration of
OpenOffice.org 
windows into Java windows (more precise a Java bean
environment) is 
documented in the Developer's Guide:

http://api
.openoffice.org/docs/DevelopersGuide/OfficeDev/OfficeDev.xht
ml#1_1_7_Java_Window_Integration

if reading this you get how to set an OOo window (the
component's 
container window) as parent of a Java frame, well...
congratulation and 
share it with us! For what I've seen, nobody has done it:
just test the 
Java extension using swing (for example the Object Inspector
and 
LanguageTool): all dialogs are non-modal, because modality
requires a 
Java frame as parent window. And if you test it, you will
see how 
horrible is the result: the Java window may be executed but
never shown 
on top of the other windows...

I've found no other solution than this: I only use Java
windows for top 
JFrames (if the window isn't shown to the user, at least it
isn't lost 
behind all the other open wins., because the user can check
in the task 
bar that the exists another window).
For modality, use OOo AWT... yes, I agree.... compared to
Java swing... 
but I've found no other solution.

Bye and luck with that.
Ariel.


-- 
Ariel Constenla-Haile
La Plata, Argentina

ariel.constenla.hailegmail.com
arielarielconstenlahaile.com.ar

http://www
.arielconstenlahaile.com.ar/ooo/

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


Re: Modal Swing JDialog
user name
2007-09-24 01:23:44
Andreas Schneider wrote:

> So I have two questions: does OOo somehow provide a
java.awt.Frame I can 
> use as parent? If not: is there a (prefered) way I can
manually lock OOo 
> and implement its main loop? That way I could lock it,
show the JDialog 
> modal in its own thread and while the thread is alive
process OOs main 
> loop. When the thread ends, that loop is left, my code
proceeds and OOo 
> can regain control. (I hope you know what I mean, it's
been a bit hard 
> to describe).

I'm not aware of any wa to provide a java.awt.Frame but
there is a
"hack" that can help you: when you start your Java
dialog also create a
1 pixel "big" dialog created by UNO AWT (with the
parent of your
choice). This will lock OOo's API sufficiently. Once your
dialog is
closed also close the "invisible" UNO AWT dialog.

Ciao,
Mathias

-- 
Mathias Bauer (mba) - Project Lead OpenOffice.org Writer
OpenOffice.org Engineering at Sun: http://blogs.sun.com/Gu
llFOSS
Please don't reply to "nospamformbagmx.de".
I use it for the OOo lists and only rarely read other mails
sent to it.

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


Re: Modal Swing JDialog
user name
2007-09-24 05:12:35

Mathias Bauer skrev:
> Andreas Schneider wrote:
> 
>> So I have two questions: does OOo somehow provide a
java.awt.Frame I can 
>> use as parent? If not: is there a (prefered) way I
can manually lock OOo 
>> and implement its main loop? That way I could lock
it, show the JDialog 
>> modal in its own thread and while the thread is
alive process OOs main 
>> loop. When the thread ends, that loop is left, my
code proceeds and OOo 
>> can regain control. (I hope you know what I mean,
it's been a bit hard 
>> to describe).
> 
> I'm not aware of any wa to provide a java.awt.Frame but
there is a
> "hack" that can help you: when you start your
Java dialog also create a
> 1 pixel "big" dialog created by UNO AWT (with
the parent of your
> choice). This will lock OOo's API sufficiently. Once
your dialog is
> closed also close the "invisible" UNO AWT
dialog.

I'm interested a bit in how to do this, are there any
examples on the
net you can point to?


-- 
Christian Andersson - caofs.no

Configuration and Collaboration for OpenOffice.org
Open Framework Systems AS http://www.ofs.no


------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org
Re: Modal Swing JDialog
user name
2007-09-24 05:23:34
Christian Andersson wrote:
> 
> I'm interested a bit in how to do this, are there any
examples on the
> net you can point to?
> 

I just implemented it that way:

     public void showModal(javax.swing.JDialog dialog) {
         try {
             Object tempDialogModel = 
multiComponentFactory.createInstanceWithContext("com.su
n.star.awt.UnoControlDialogModel", 
context);
             XPropertySet properties = (XPropertySet) 
UnoRuntime.queryInterface(XPropertySet.class,
tempDialogModel);
            
properties.setPropertyValue("PositionX", new
Integer(0));
            
properties.setPropertyValue("PositionY", new
Integer(0));
             properties.setPropertyValue("Width",
new Integer(1));
             properties.setPropertyValue("Height",
new Integer(1));

             final Object tempDialog = 
multiComponentFactory.createInstanceWithContext("com.su
n.star.awt.UnoControlDialog", 
context);
             XControl xControl = (XControl) 
UnoRuntime.queryInterface(XControl.class, tempDialog);
             XControlModel xControlModel = (XControlModel) 
UnoRuntime.queryInterface(XControlModel.class,
tempDialogModel);
             xControl.setModel(xControlModel);

             Object toolkit = 
multiComponentFactory.createInstanceWithContext("com.su
n.star.awt.Toolkit", 
context);
             XToolkit xToolkit = (XToolkit) 
UnoRuntime.queryInterface(XToolkit.class, toolkit);
             XWindow xWindow = (XWindow) 
UnoRuntime.queryInterface(XWindow.class, xControl);
             xWindow.setVisible(false);
             xControl.createPeer(xToolkit, null);

             final XDialog xTempDialog = (XDialog) 
UnoRuntime.queryInterface(XDialog.class, tempDialog);

             dialog.addWindowListener(new WindowAdapter() {
                 public void windowClosed(WindowEvent e) {
                     xTempDialog.endExecute();
                     XComponent component = (XComponent) 
UnoRuntime.queryInterface(XComponent.class, tempDialog);
                     component.dispose();
                 }
             });

             dialog.setVisible(true);
             xTempDialog.execute();
         } catch (com.sun.star.uno.Exception ex) {
             ex.printStackTrace();
         }
     }

But in my case that small dialog is still visible and
considerably 
larger than 1 pixel. I will try if I can somehow get it
off-screen or 
really invisible (but still modal). If you find something
out, please 
inform me.

Thanks Mathias for that hint. It's at least a good point to
start from 

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


Re: Modal Swing JDialog
user name
2007-09-25 11:50:07
Andreas Schneider wrote:

> Thanks Mathias for that hint. It's at least a good
point to start from 
s/hint/hack 

Ciao,
Mathias

-- 
Mathias Bauer (mba) - Project Lead OpenOffice.org Writer
OpenOffice.org Engineering at Sun: http://blogs.sun.com/Gu
llFOSS
Please don't reply to "nospamformbagmx.de".
I use it for the OOo lists and only rarely read other mails
sent to it.

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


[1-8]

about | contact  Other archives ( Real Estate discussion Medical topics )