OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Problems when opening OOo document in a java Swing

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
feasil
General User
General User


Joined: 07 Aug 2006
Posts: 16
Location: Clermont-Ferrand, France

PostPosted: Mon Aug 21, 2006 12:34 am    Post subject: Problems when opening OOo document in a java Swing Reply with quote

Hello,

I'm working on having a preview of an OOo document in a java swing but all doesn't work.

Indeed, I used OOoBeanViewer http://api.openoffice.org/source/browse/api/odk/examples/DevelopersGuide/OfficeBean/OOoBeanViewer.java and I changed it (deletting some buttons, panels, ... and renamed to OOoViewer) to work in my project.

But I have a problem :
When I create and add to my component a new OOoViewer, I try to open directly my document and it doesn't works (an Exception appears or the document open itself out of the component in full screen).
Here's the Exception :
Code:
OOoBeanViewer.1:
com.sun.star.comp.beans.SystemWindowException
   at com.sun.star.comp.beans.OOoBean.aquireSystemWindow(OOoBean.java:488)
   at fr.crosstalk.com.hrd.traitementTexte.manipOpenOffice.OOoViewer.openDoc(OOoViewer.java:98)
   at fr.crosstalk.com.hrd.traitementTexte.manipOpenOffice.OOoViewer.load(OOoViewer.java:70)
   at fr.crosstalk.com.ihm.files.IHMVisualisationFichier.actionAfficherFichier(IHMVisualisationFichier.java:268)
   at fr.crosstalk.com.ihm.files.IHMVisualisationFichier.setFichierNewVersion(IHMVisualisationFichier.java:482)
   at fr.crosstalk.com.ihm.documents.visue.IHMVisueDocuments$3.construct(IHMVisueDocuments.java:154)
   at fr.crosstalk.com.ihm.SwingWorker$2.run(SwingWorker.java:122)
   at java.lang.Thread.run(Unknown Source)


And the code which make it appearing :
Code:
   private void openDoc(String url){
      try{
         //Get the office process to load the URL
         
         PropertyValue[] prop = new PropertyValue[2];
         prop[0] = new PropertyValue();
         prop[0].Name = "ReadOnly";
         prop[0].Value = Boolean.TRUE;
         prop[1] = new PropertyValue();
         prop[1].Name = "Preview";
         prop[1].Value = Boolean.TRUE;

         aBean.loadFromURL( url, prop);
         aBean.aquireSystemWindow();
      }
      catch ( com.sun.star.comp.beans.SystemWindowException aExc ){
         System.err.println( "OOoBeanViewer.1:" );
         aExc.printStackTrace();
      }
      catch ( com.sun.star.comp.beans.NoConnectionException aExc ){
         System.err.println( "OOoBeanViewer.2:" );
         aExc.printStackTrace();
      }
      catch ( Exception aExc ){
         System.err.println( "OOoBeanViewer.3:" );
         aExc.printStackTrace();
      }
   }



This error doesn't come when I open the doc by clicking on a button :
Code:
newDocumentButton = new javax.swing.JButton("Voir l'Aperçu !");
      newDocumentButton.addActionListener(new java.awt.event.ActionListener(){
         public void actionPerformed(java.awt.event.ActionEvent evt){
            //openDoc("private:factory/swriter");
            openDoc(url);
         }
      });


But I want an automatic preview !



MoreOver, I would have wanted to choose te zoom of the document but I don't find how to do !



So If anyone can help me, thanks doing it.
_________________
Sorry for my english !...
Back to top
View user's profile Send private message
GenezypKapen
General User
General User


Joined: 06 Mar 2006
Posts: 29
Location: Poland

PostPosted: Mon Aug 21, 2006 4:54 am    Post subject: Reply with quote

Maybe you should read 3.3.8 Lifetime of UNO Objects from Developers Guide. It may have something to do with your problem.
Back to top
View user's profile Send private message
feasil
General User
General User


Joined: 07 Aug 2006
Posts: 16
Location: Clermont-Ferrand, France

PostPosted: Mon Aug 21, 2006 7:26 am    Post subject: Reply with quote

Thanks for your answer, I read it but I don't think I have something to do with my problem.

If anyone have another idea, thanks telling me !
_________________
Sorry for my english !...
Back to top
View user's profile Send private message
orahn
Newbie
Newbie


Joined: 19 Jul 2006
Posts: 4
Location: Germany

PostPosted: Wed Aug 30, 2006 6:15 am    Post subject: Reply with quote

Hi!

I am also new in OO development and had a similar problem (guess it's some timeout problem). I found a solution that may not be the nicest, but at least it works. Here is what I do:

I override the "paint()" method of the component that contains the bean (in my case a special ized panel with some controls and the office bean) and - on the first painting - initialize the bean.

When the panel is shown for the first time it takes a few seconds and then there is a fully functional OO bean.

Best regards!
Ole
Back to top
View user's profile Send private message
harwey
General User
General User


Joined: 21 Feb 2006
Posts: 22

PostPosted: Mon Sep 04, 2006 10:32 pm    Post subject: Reply with quote

Hi,

The problem here is, that aquireSystemWindow() in OOoBean crashes because the OOoBean ist not visible yet, but this method tries to determine the size needed for OOo. That's why overriding paint() works at least without that error.

I actually had similar problem that made me override paint(). Office was visible in the upper left corner of a Swinp Panel of 1x1cm size instead of using the whole Panel. I had to make sure that loading my document will be called after all Swing-calls in the current Thread (i.e. painting) are done:

Code:

super.paint(aGraphics);

SwingUtilities.invokeLater(new Runnable(){
  public void run() {
  loadDocumentInternal();
}});


If loading documents are triggered by user interaction, this method is called within the Event Dispatcher Thread of Swing. Within this thread you can not modify any controls (i.e you can not show a ProgresBar) and if you move your application window it will not repaint and users might think the application hangs or crashed. InvoceLater detaches loading from this Thread and and will make the application much more responsive and solved my problem.

Hope this might be of some help.

Cheers
Harald
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group