CIB jrec technical documentation (EN)

6. Integration of CIB jrec in Java

6.2. Integration into a Java SWT application

In order to integrate JCibRec into an SWT application, some special features have to be considered. JCibRec must be embedded into an AWT frame, which contains an instance of RootPaneContainer (e.g. JApplet) as the topmost object. All further components are then inserted into this RootPaneContainer.

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();
      }
}