Announcement Announcement Module
Collapse
No announcement yet.
More about JGoodies really... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • More about JGoodies really...

    Hi

    Facing some difficult customers (well... normal customer, we all have experienced this...) The question is "can I change the Look and Feel whenever I want"...

    I know it is a nice to have but it's kind of give and take... so I'm trying to give this to them...

    The aim is to select an option on the menu and tadaaa the THEME changes instantaneously and any internal frame also change.

    I noticed the JGoodiesLooksConfigurer being called in the XML setting:
    Code:
    	<bean id="lookAndFeelConfigurer"
    		class="org.springframework.richclient.application.config.JGoodiesLooksConfigurer">
    		<property name="popupDropShadowEnabled" value="false" />
    		<property name="theme">	
    			<bean class="com.jgoodies.looks.plastic.theme.ExperienceBlue"/>
    		</property>
    	</bean>
    So I thought... why not creating a tiny command for each allowed theme?
    and calling this:
    Code:
        protected void doExecuteCommand() {
            PlasticLookAndFeel.setMyCurrentTheme(newTheme);
        }
    This does not seem to change the current THEME on the fly... how can I force a "refresh" on all windows?

    The Alloy package has something quite explicit:
    com.incors.plaf.alloy.AlloyLookAndFeel.updateAllUI s();

    Is there something similar for JGoodies?

    Many thanks!

    regards from a late London....

    Benoit
    Last edited by benoitx; Nov 18th, 2005, 06:37 PM.

  • #2
    Possible solution...

    Hi

    I think that I got it... Could someone correct me if this is a crazy solution..

    Code:
        protected void doExecuteCommand() {
            PlasticLookAndFeel.setMyCurrentTheme(theme);
            try {
                UIManager.setLookAndFeel(new PlasticXPLookAndFeel());
             } catch (Exception e) {}
             updateAllUIs();
        }
    and the updateAllUIs() is as follows:

    Code:
        /**
         * Method to attempt a dynamic update for any GUI accessible by this JVM. It will
         * filter through all frames and sub-components of the frames.
         */
        public static void updateAllUIs()
        {
            Frame frames[];
            int i1;
            frames = Frame.getFrames();
            i1 = 0;
    
            for (int i = 0; i < frames.length; i++)
            {
                updateWindowUI(frames[i]);
            }
        }
    
        /**
         * Method to attempt a dynamic update for all components of the given <code>Window</code>.
         * @param window The <code>Window</code> for which the look and feel update has to be performed against.
         */
        public static void updateWindowUI(Window window)
        {
            try
            {
                updateComponentTreeUI(window);
            }
            catch(Exception exception) { }
    
            Window windows[] = window.getOwnedWindows();
    
            for (int i = 0; i < windows.length; i++)
                updateWindowUI(windows[i]);
        }
    
        /**
         * A simple minded look and feel change: ask each node in the tree
         * to <code>updateUI()</code> -- that is, to initialize its UI property
         * with the current look and feel.
         *
         * Based on the Sun SwingUtilities.updateComponentTreeUI, but ensures that
         * the update happens on the components of a JToolbar before the JToolbar
         * itself.
         */
        public static void updateComponentTreeUI(Component c) {
            updateComponentTreeUI0(c);
            c.invalidate();
            c.validate();
            c.repaint();
        }
    
        private static void updateComponentTreeUI0(Component c) {
    
            Component[] children = null;
    
            if (c instanceof JToolBar)
            {
                children = ((JToolBar)c).getComponents();
    
                if (children != null)
                {
                    for(int i = 0; i < children.length; i++)
                    {
                        updateComponentTreeUI0(children[i]);
                    }
                }
    
                ((JComponent) c).updateUI();
            }
            else
            {
                if (c instanceof JComponent) {
                    ((JComponent) c).updateUI();
                }
    
                if (c instanceof JMenu) {
                    children = ((JMenu)c).getMenuComponents();
                }
                else if (c instanceof Container) {
                    children = ((Container)c).getComponents();
                }
    
                if (children != null)
                {
                    for(int i = 0; i < children.length; i++)
                    {
                        updateComponentTreeUI0(children[i]);
                    }
                }
            }
        }
    Credit to "BigLee" for updateAllUIs() following a post on http://forum.java.sun.com/thread.jsp...sageID=3160062

    However, you need to reset a LookAndFeel and then call the updateAllUIs()...
    HTH,
    Regards
    Benoit

    Comment


    • #3
      I 've been thinking about this funcationally too, although it's not a priority to me.
      You can ask to get a list of all available look and feels to popule a combobox for the user to pick one.

      Maybe we can make a Util for this methods?

      Also, maybe the lookAndFeelConfigurer should be an interface which has a static configurer implementation (basically set the LAF in the app context) and a settings based implementation (remember the LAF, but with a default defined in the app context)?

      Comment

      Working...
      X