CIB jrec technischer Leitfaden

6. Einbindung des CIB jrec in Java

6.2. Einbindung in eine Java SWT-Applikation

Um JCibRec in eine SWT-Applikation zu integrieren, müssen einige Besonderheiten beachtet werden. JCibRec muss in einen AWT-Frame eingebettet werden, der als oberstes Objekt eine Instanz von RootPaneContainer (z.B. JApplet) enthält. In diesen RootPaneContainer werden dann alle weiteren Komponenten eingefügt.

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
 
import de.cib.gui.framework.ICibApplication;
import de.cib.jrec.ICibRecApplication;
import de.cib.jrec.JCibRec;
 
 
public class JRecInSWT {
 
      public static final String TEST_FILENAME = "Testdokument2.rtf";
 
      public static void main(String[] args) {
            final Display display = new Display();
            final Shell shell = new Shell(display);
            shell.setLayout(new FillLayout());
            shell.setText("Shell for JRec integriert in SWT");
            Composite composite = new Composite(shell, SWT.NO_BACKGROUND
                        | SWT.EMBEDDED);
           
            /*
             * Set a Windows specific AWT property that prevents
             * heavyweight components from erasing their background.
             * Note that this is a global property and cannot be scoped.
             * It might not be suitable for your application.
             */
            try {
                System.setProperty("sun.awt.noerasebackground", "true");
            }
            catch (NoSuchMethodError error) {
            }
 
            final JCibRec cibRec = new JCibRec(composite);
           
      cibRec.setProperty(ICibApplication.PROPERTY_INPUTFILE,                   TEST_FILENAME);
      cibRec.setProperty(ICibApplication.PROPERTY_TITLE,                   "CIB JRec integriert in SWT");
      cibRec.setProperty(ICibRecApplication.PROPERTY_POPUP_ENABLED,                   Boolean.TRUE);
 
            // disable jrec menu bar – must be done             // if custom application uses its own menu bar
      cibRec.setProperty(ICibApplication.PROPERTY_MENU_ENABLED,                   Boolean.FALSE);
 
           
            cibRec.setVisible(true);
            cibRec.start();
            cibRec.load();
           
            shell.open();
            cibRec.grabFocus();
           
            while (!shell.isDisposed()) {
                  if (!display.readAndDispatch())
                        display.sleep();
            }
            display.dispose();
      }
}