Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / February 2006

Tip: Looking for answers? Try searching our database.

How to use proxy/decorator design pattern for UIComponents ?

Thread view: 
Filip Sielimowicz - 15 Feb 2006 23:05 GMT
I'd like to add some small functionality do default
TabbedPaneUI component. It is now like this:

public class HBasicTabbedPaneUI extends BasicTabbedPaneUI {
   public static ComponentUI createUI(JComponent c) {
       return new HBasicTabbedPaneUI();
   }

   @Override
   public void installUI(JComponent c) {
       super.installUI(c);
       // Everything is like in parent, but we add a listener.
       c.addContainerListener(new ContainerListener() {

           public void componentAdded(ContainerEvent e) {
               System.err.println("Comp added: "+e.getChild().getClass());
           }

           public void componentRemoved(ContainerEvent e) {
               System.err.println("Comp rmvd: "+e.getChild().getClass());
           }
           
       });
   }
}

I install this using UIManager and it works ok, until i use some
extended L&F.
It always reverts my tabbed panes to the basicui behavior ... So when I
use some L&F (like JGoodies) it is a step backward, because
tab panes do not look like originally in jgoodies.

I'd prefer to make an UI component, that does not extend the basic ui,
but can decorate any other implementation of TabbedPaneUI installed
previously by L&F. Is it possible, at least to decorate ui components
from jgoodies ? I need only to add a small listener.
Kleopatra - 16 Feb 2006 11:45 GMT
> I'd like to add some small functionality do default
> TabbedPaneUI component.

[..]

> I'd prefer to make an UI component, that does not extend the basic ui,
> but can decorate any other implementation of TabbedPaneUI installed
> previously by L&F. Is it possible, at least to decorate ui components
> from jgoodies ? I need only to add a small listener.

The way to go is to implement a "incomplete" LookAndFeel (handling only
the components you want to decorate) and register it with the UIManager via

UIManager.addAuxiliaryLookAndFeel(myDecoratingLF);

rough code sketch:

[code]

public MyDecoratingLF extends LookAndFeel {

    //...

    public UIDefaults getDefaults() {
        if (myDefaults == null) {
            initDefaults();
        }
        return myDefaults;
    }

    private void initDefaults() {
        myDefaults = new MyUIDefaults();
        Object[] mydefaults = { "TabbedPaneUI",
                "snippets.focus.tabbedpane.CrossLFTabbedPaneUI",
        };
        myDefaults.putDefaults(mydefaults);
    }

    /**
     * UIDefaults without error msg.
     *
     */
    private static class MyUIDefaults extends UIDefaults {

        protected void getUIError(String msg) {
            // overridden to do nothing - the LF is incomplete as of
component types

        }
    }

}

public class CrossLFTabbedPaneUI extends TabbedPaneUI {

    private ContainerListener listener;

    public static ComponentUI createUI(JComponent c) {
        return new CrossLFTabbedPaneUI();
    }

    public void installUI(JComponent comp) {
        comp.addContainerListener(getContainerListener());
    }

    public void uninstallUI(JComponent comp) {
        comp.removeContainerListener(getContainerListener());
    }

    // implement the abstract TabbedPaneUI methods to do nothing
    // ...
}

There's a catch, though: some UIDelegates don't play well with the
MultiXXUI delegates because they expect a BasicXXUI - for more details, see

http://forums.java.net/jive/thread.jspa?forumID=73&threadID=7713

and the resulting #6307075 in Sun's BugParade. Feel free to vote for the
bug - maybe we can build pressure to tackle it soon :-)

Cheers
Jeanette


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.