package de.espirit.firstspirit.client.gui.applications; import de.espirit.firstspirit.access.ServicesBroker; import de.espirit.firstspirit.client.gui.applications.SwingApplicationConfiguration.ComponentFactory; import javax.swing.JLabel; import java.awt.Component; /** * Examples how to use a swing application * * @since 4.2.416 */ public class SwingApplicationExample { /** * Creates a swing application tab. * * @param title the title used for the application tab * @return the created application * @since 4.2.416 */ public SwingApplication createSwingApplication(final ServicesBroker servicesBroker, final String title) { // get the applicationservice from servicesBroker final ApplicationService appService = servicesBroker.getService(ApplicationService.class); // create a new swing application configuration final SwingApplicationConfiguration swingConfig = SwingApplicationConfiguration.GENERATOR.invoke(). title(title). componentFactory(new ComponentFactory<MyLabel>() { public MyLabel createComponent() { return new MyLabel("Swing app component"); } public void dispose(final MyLabel label) { label.cleanUp(); } }); // open an application tab of type multitab final ApplicationTab<SwingApplication> swingTab = appService.openApplication(SwingApplication.TYPE, swingConfig); return swingTab.getApplication(); } public static class MyLabel extends JLabel { public MyLabel(final String label) { super(label); } public void cleanUp() { // clean up resources } } }