Saturday Jan 30, 2010

Create Your Own Window System on the NetBeans Window System

One big reason for using the NetBeans Platform is its out-of-the-box window system. However, maybe you like the concept of a window system, but not how it is implemented in the NetBeans Platform? Not to worry. You can create your own window system on top of the NetBeans Platform's Window System API, which means you'll have a custom window system that still integrates with all of the other NetBeans idioms, via ExplorerManager to explorer views (e.g., BeanTreeView) and Nodes.

Eppleton, the Munich-based NetBeans Platform consultancy, has been learning about this area of the NetBeans Platform recently, for one of its customers. The end result was the integration of the SwingX project's "org.jdesktop.swingx.JXPanel", together with "javax.swing.JLayeredPane", to create the translucent effects of the TopComponents in the screenshot below:

I.e., your TopComponents could be JXPanels, if that's the way you'd prefer them to be. Or something else.

In the image above, there are in fact 3 TopComponents, one of which has this client property in its constructor:

// setting this property informs the Windowmanager that this window is
// our Main Window. Not a standard property.
putClientProperty(TranslucentWindowManager.MAINWINDOW, Boolean.TRUE);

But how to get started with all of this? There's a "DummyWindowManager" in the NetBeans sources that you can start experimenting with. Let's do so now.

     

  1. In your application, remove core-windows.jar, i.e., you do not want the "Core - Windows" module to be installed in your application, since you'll be providing your own window system.

    A simple way to remove that JAR is to go to "platform.properties" in your application and use this list of disabled modules (definitely won't work in all cases, since your dependencies will be different depending on what else you're using, but if you're starting from scratch, this will be all you'll need):

    disabled.modules=\\
        org.netbeans.api.visual,\\
        org.netbeans.core.execution,\\
        org.netbeans.core.multiview,\\
        org.netbeans.core.nativeaccess,\\
        org.netbeans.core.windows,\\
        org.netbeans.libs.jsr223,\\
        org.netbeans.modules.applemenu,\\
        org.netbeans.modules.autoupdate.services,\\
        org.netbeans.modules.autoupdate.ui,\\
        org.netbeans.modules.core.kit,\\
        org.netbeans.modules.favorites,\\
        org.netbeans.modules.options.keymap,\\
        org.netbeans.modules.templates,\\
        org.openide.compat,\\
        org.openide.execution,\\
        org.openide.options,\\
        org.openide.util.enumerations

    Note the line in bold below, i.e., that's the line that will result in the "core-windows.jar" to be excluded.

     

  2. Now add this class to a module in your application:

    MyWindowManager.java

    Especially note this class-level annotation, which results in your window manager replacing the one provided by the NetBeans Platform:

    @ServiceProvider(service = WindowManager.class, supersedes = "org.netbeans.core.windows.WindowManagerImpl")

    In other words, when the module has been built, you'll find a META-INF/services registration consisting of these entries:

    org.demo.winsys.MyWindowManager
    #-org.netbeans.core.windows.WindowManagerImpl

    Note: Make sure to add the required NetBeans API modules to the application (i.e., Nodes API, Window System API, and Utilities API).

     

  3. Somehow you now need to open your TopComponents into your new window system. Normally the opening of the TopComponents would be handled by core-windows.jar, which you have now excluded. So now you need to open them manually, i.e., yourself. For example, in a ModuleInstall class, add this code:
    @Override
    public void restored() {
        WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
            public void run() {
                View1TopComponent.findInstance().open();
                View2TopComponent.findInstance().open();
            }
        });
    }

     

  4. When you run the application, you'll see this result:

Now look more closely at MyWindowManager.java and change it to fit your business requirements.

About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« January 2010 »
SunMonTueWedThuFriSat
     
2
4
9
10
16
20
22
      
Today