The OOoBean by Example

From Apache OpenOffice Wiki
Jump to: navigation, search



The OOoBeanViewer is a Java application that displays Apache OpenOffice documents in a Java AWT applet, which allows for the control of some toolboxes, the menu bar and the status bar, as well as storing and loading the document content to/from an internal buffer.

The OOoBean Viewer

The OOoBeanViewer utilizes the class OOoBean directly without subclassing it:

  public class OOoBeanViewer extends java.applet.Applet
  {
      ...
      private OOoBean aBean;
      ...
 
      public void init()
      {
          aBean = new OOoBean();
      }
 
      ...
      {
          add( aBean );
      }
  }

Initially, the OOoBean component does not contain a document. A document can be created with the loadFromURL method:

  private void createBlankDoc(String url, String desc)
  {
      //Create a blank document
      try
      {
          aBean.loadFromURL( url, null );
          ....
      }
      catch ( com.sun.star.comp.beans.SystemWindowException aExc )
      {
          // this exception will be thrown when no system window parent can be found
          ...
      }
      catch ( com.sun.star.comp.beans.NoConnectionException aExc )
      {
          // this exception is thrown  
          // when no connection to a [PRODUCTNAME] instance can be established
          ...
      }
      catch ( Exception aExc )
      {
          ...
      }
  }

Some tool windows of the document window within the Java Bean can be controlled directly by the OOoBean API. For example, to toggle visibility of the menu bar:

  aBean.setMenuBarVisible( !aBean.isMenuBarVisible() );

The examples above provide an overview of how the OOoBean API is used to create Java Beans that can be used in Java applications and applets. For concrete Java Beans, you usually subclass OOoBean and create appropriate BeanInfo classes for integrating within an IDE (Integrated Development Environment), such as the Bean Development Kit or Forte for Java. Developers can use the examples as a guideline when using the OOoBean API to write new beans, or use or extend the example beans.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages