Help - Working with toolkits

From LibrAlign Documentation

LibrAlign provides all GUI components in a Swing and a SWT version. Toolkit independence is achieved using TIC, which is a dependency of LibrAlign.

Basic example

Swing application window showing the result of the example above. The according source code can be found in SwingApplication.

Swing

The following example shows how to display a MultipleAlignmentsContainer in a JFrame. The complete example can be found in the demo class SwingApplication.

// Create main container instance (TIC component):
MultipleAlignmentsContainer container = createContainer();

// Create Swing-specific component from TIC component:
JComponent swingContainer = SwingComponentFactory.getInstance().getSwingComponent(container);

// Add Swing component to GUI:
frame.getContentPane().add(swingContainer, BorderLayout.CENTER);

First a TIC component instance (a toolkit independent GUI component object) is created using a method that is not shown here. MultipleAlignmentsContainer is used as an example here, but the principle would be the same with every GUI component available in LibrAlign.

To create a toolkit specific component, the according TIC factory needs to be used. In this case SwingComponentFactory from the module info.bioinfweb.tic.swing is used, which returns an instance of a class inherited from JComponent.

The returned Swing component can then be integrated in the GUI like any other Swing component.

SWT application window showing the result of the example above. The according source code can be found in SWTApplication.

SWT

The same as above can be done in an SWT application as shown below. The complete example can be found in the demo class SWTApplication.

// Create main container instance (TIC component):
MultipleAlignmentsContainer container = createContainer();

// Create SWT-specific component from TIC component and add it to the SWT GUI:
SWTComponentFactory.getInstance().getSWTComponent(container, shell, SWT.NONE);

In this example the TIC component is created first (as in the Swing example) and then a SWT specific component is created using SWTComponentFactory from the module info.bioinfweb.tic.swt. Note that due to the different strategy of creating component trees in SWT, the parent SWT component and the SWT style parameter need to be passed to the factory method.

Toolkit specific dependencies

Like TIC, LibrAlign also contains a swing and a swt module. Swing applications need to have access only to info.bioinfweb.libralign.swing and info.bioinfweb.tic.swing, while SWT applications only need access to the info.bioinfweb.libralign.swt and info.bioinfweb.tic.swt JARs. It is not necessary to provide all modules (JARs) for all applications. (The core modules of both TIC and LibrAlign must of course always be present.)

See also