[openide-dev] Re: Can I make TopComponent a view without a Tab handle?

  • From: Tim Boudreau < >
  • To:
  • Subject: [openide-dev] Re: Can I make TopComponent a view without a Tab handle?
  • Date: Tue, 09 May 2006 18:36:56 -0700
  • Mailing-list: contact ; run by ezmlm

Melvin Zamora wrote:

Tim, I am sorry for being naive of what you're trying to say. The truth is - Am newbie don't get it. Can you provide a comprehensive code example (a miniature project module sort-of) to experiment?

For I am lost, especially to this you've point out - """Somewhere early in startup
(ModuleInstall) you'll want to do something like

UIManager.put ("ViewTabDisplayerUI", "com.foo.MyTablessUIDelegate")

where MyTablessUIDelegate implements
org.netbeans.swing.tabcontrol.TabDisplayerUI"""

The code needed is short enough to put in an email, so...first let me explain what it does: Swing controls have a notion of "UI delegate" in other words, a Swing component isn't responsible for painting itself, there is an object that it asks "please paint me" when it wants to be painted. Same for mouse and keyboard handling. Change the UI delegate and you get a different look or behavior. So this is what makes pluggable look and feels possible.

The tab control in NetBeans uses the exact same mechanisms for its appearance and behavior. So, if you replace the UI delegate, you can have different appearance and behavior, including having no tabs at all.

When a Swing component is instantiated, its updateUI() method is called. JComponent has another method, getUIClassID() which returns a String. The long and the short of it is that some code (see javax.swing.UIDefaults if you're really interested) will try to get a value out a String to Object map owned by the look and feel - it will call UIManager.get (someComponent.getUIClassID()). If it gets a class name, it will try to load that class, and then look for a static method called createUI(JComponent). That is then set as the UI delegate for the component. Pseudo-code for more or less what happens, less lots of special cases exception handling:

MyComponent comp;
  //What's the name of the class it wants
String classname = (String) UIManager.get(comp.getUIClassID();
  //Let's load the class
Class uiClass = Class.forName (classname);
  //Look for a createUI(JComponent) method
Method m = uiClass.getMethod("createUI", new Class[]{acClass});
  //Invoke it, passing in the component
ComponentUI uiDelegate = (ComponentUI) m.invoke (null, new Object[] { comp });
  //Set that delegate on the component - uiDelegate will now be
  //responsible for painting, behavior, etc.
comp.setUI (uiDelegate);


Anyway, for doing what I'm talking about in a real NetBeans module, first you want a ModuleInstall subclass. That contains code that NetBeans will automatically run when you start it.

package org.netbeans.examples.tablessness;
import javax.swing.UIManager;
import org.openide.modules.ModuleInstall;
public class Install extends ModuleInstall {
    public void restored() {
UIManager.put ("ViewTabDisplayerUI", "org.netbeans.examples.tablessness.NoTabsTabDisplayerUI");
    }
}

If you're not using the update of apisupport, add the following line to your module's manifest:
OpenIDE-Module-Install: org/netbeans/examples/tablessness/Install.class

Then just implement the UI delegate as follows; you'll need to set up your module to depend on Tab Control, Utilities API, Module System API and Look & Feel Customization Library in its properties dialog. What this does: It replaces the standard UI delegate for "view tabs" (like Projects, Files, Navigator) with one that is 0 size and does nothing. So, the content of the tab control still is visible, but the tabs themselves disappear.

Note that this does mean that if you ever open more than one view window, your users won't be able to switch between them - be sure that's really what you want.


package org.netbeans.examples.tablessness;
import java.awt.*;
import javax.swing.DefaultSingleSelectionModel;
import javax.swing.SingleSelectionModel;
import javax.swing.plaf.ComponentUI;
import javax.swing.JComponent;
import org.netbeans.swing.tabcontrol.TabDisplayer;
import org.netbeans.swing.tabcontrol.TabDisplayerUI;

public class NoTabsTabDisplayerUI extends TabDisplayerUI {

    /** Creates a new instance of NoTabsTabDisplayerUI */
    public NoTabsTabDisplayerUI(TabDisplayer displayer) {
        super (displayer);
    }

    public static ComponentUI createUI (JComponent jc) {
        assert jc instanceof TabDisplayer;
        return new NoTabsTabDisplayerUI((TabDisplayer) jc);
    }

    private static final int[] PTS = new int[] { 0, 0, 0 };
    public Polygon getExactTabIndication(int i) {
        //Should never be called
        return new Polygon (PTS, PTS, PTS.length);
    }

    public Polygon getInsertTabIndication(int i) {
        return new Polygon (PTS, PTS, PTS.length);
    }

    public int tabForCoordinate(Point point) {
        return -1;
    }

    public Rectangle getTabRect(int i, Rectangle rectangle) {
        return new Rectangle (0,0,0,0);
    }

    protected SingleSelectionModel createSelectionModel() {
        return new DefaultSingleSelectionModel();
    }

    public java.lang.String getCommandAtPoint(Point point) {
        return null;
    }

    public int dropIndexOfPoint(Point point) {
        return -1;
    }

    public void registerShortcuts(javax.swing.JComponent jComponent) {
        //do nothing
    }

    public void unregisterShortcuts(javax.swing.JComponent jComponent) {
        //do nothing
    }

    protected void requestAttention(int i) {
        //do nothing
    }

    protected void cancelRequestAttention(int i) {
        //do nothing
    }

    public Dimension getPreferredSize(javax.swing.JComponent c) {
        return new Dimension (0, 0);
    }

    public Dimension getMinimumSize(javax.swing.JComponent c) {
        return new Dimension (0, 0);
    }

    public Dimension getMaximumSize(javax.swing.JComponent c) {
        return new Dimension (0, 0);
    }
}






[openide-dev] Can I make TopComponent a view without a Tab handle?

Melvin Zamora 05/09/2006

Re: [openide-dev] Can I make TopComponent a view without a Tab handle?

Tom Wheeler 05/09/2006

[openide-dev] Re: Can I make TopComponent a view without a Tab handle?

Tim Boudreau 05/09/2006

Re: [openide-dev] Re: Can I make TopComponent a view without a Tab handle?

Melvin Zamora 05/09/2006

RE: [openide-dev] Re: Can I make TopComponent a view without a Tab handle?

Ramón Ramos 05/09/2006

[openide-dev] Re: Can I make TopComponent a view without a Tab handle?

Tim Boudreau 05/10/2006

[openide-dev] Re: Can I make TopComponent a view without a Tab handle?

Tim Boudreau 05/10/2006

Re: [openide-dev] Re: Can I make TopComponent a view without a Tab handle?

Melvin Zamora 05/11/2006

Project Features

Project Links

About this Project

Platform was started in November 2009, is owned by Antonin Nebuzelsky, and has 138 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close