001    /*
002     * Copyright 2002-2004 the original author or authors.
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005     * use this file except in compliance with the License. You may obtain a copy of
006     * the License at
007     * 
008     * http://www.apache.org/licenses/LICENSE-2.0
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012     * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013     * License for the specific language governing permissions and limitations under
014     * the License.
015     */
016    package org.springframework.richclient.application.config;
017    
018    import java.awt.Dimension;
019    
020    import org.springframework.beans.factory.InitializingBean;
021    import org.springframework.util.Assert;
022    
023    import com.jgoodies.looks.FontPolicy;
024    import com.jgoodies.looks.Options;
025    import com.jgoodies.looks.plastic.PlasticLookAndFeel;
026    import com.jgoodies.looks.plastic.PlasticTheme;
027    
028    /**
029     * <p>JGoodies looks configurer bean. Allows to set various options available in the JGoodies looks library.
030     * Use this as follows:</p>
031     * <p/>
032     * <pre>
033     * &lt;bean id="lookAndFeelConfigurer"
034     * class="org.springframework.richclient.application.config.JGoodiesLooksConfigurer"&gt;
035     *  &lt;property name="popupDropShadowEnabled" value="false" /&gt;
036     *  &lt;property name="theme"&gt;
037     *      &lt;bean class="com.jgoodies.looks.plastic.theme.ExperienceBlue" /&gt;
038     *  &lt;/property&gt;
039     *  &lt;/bean&gt;
040     * </pre>
041     * <p/>
042     * <p>Additionally the LaF FQN can be set using {@link #setLaFName(String)}. Use the static name constants defined in
043     * JGoodies {@link com.jgoodies.looks.Options} to set this property. Default LaF if not specified is the Options#PLASTICXP_NAME.
044     * It is possible to define other LaF's as well, but any other property set in this bean will not be in effect if used in that way.
045     * If you do need to set another LaF without additional configuration use {@link org.springframework.richclient.application.config.UIManagerConfigurer}
046     * and/or create a specific configurer bean for the LaF of your choice. 
047     * </p>
048     */
049    public class JGoodiesLooksConfigurer implements InitializingBean {
050    
051        private UIManagerConfigurer configurer;
052    
053        private String laFName = Options.PLASTICXP_NAME;
054    
055        /**
056         * Default constructor.
057         */
058        public JGoodiesLooksConfigurer() {
059            this(new UIManagerConfigurer());
060        }
061    
062        /**
063         * Constructor allowing to pass your own UIManagerConfigurer.
064         *
065         * @param configurer the UIManagerConfigurer to use when setting the LaF.
066         */
067        public JGoodiesLooksConfigurer(UIManagerConfigurer configurer) {
068            Assert.notNull(configurer);
069            this.configurer = configurer;
070        }
071    
072        /**
073         * @param size default Dimension for the icons.
074         * @see com.jgoodies.looks.Options#setDefaultIconSize(java.awt.Dimension)
075         */
076        public void setDefaultIconSize(Dimension size) {
077            Options.setDefaultIconSize(size);
078        }
079    
080        /**
081         * @param theme PlasticTheme to use.
082         * @see com.jgoodies.looks.plastic.PlasticLookAndFeel#setPlasticTheme(com.jgoodies.looks.plastic.PlasticTheme)
083         */
084        public void setTheme(PlasticTheme theme) {
085            PlasticLookAndFeel.setPlasticTheme(theme);
086        }
087    
088        /**
089         * @param enabled set to <code>true</true> if drop shadows should be used.
090         * @see com.jgoodies.looks.Options#setPopupDropShadowEnabled(boolean)
091         */
092        public void setPopupDropShadowEnabled(boolean enabled) {
093            Options.setPopupDropShadowEnabled(enabled);
094        }
095    
096        /**
097         * @param enabled set to <code>true</code> if tab icons should be enabled.
098         * @see com.jgoodies.looks.Options#setTabIconsEnabled(boolean)
099         */
100        public void setTabIconsEnabled(boolean enabled) {
101            Options.setTabIconsEnabled(enabled);
102        }
103    
104        /**
105         * @param enabled set to <code>true</code> if narrow buttons should be used.
106         * @see com.jgoodies.looks.Options#setUseNarrowButtons(boolean)
107         */
108        public void setUseNarrowButtons(boolean enabled) {
109            Options.setUseNarrowButtons(enabled);
110        }
111    
112        /**
113         * @param enabled set to <code>true</code> if narrow buttons should be used.
114         * @see com.jgoodies.looks.Options#setUseSystemFonts(boolean)
115         */
116        public void setUseSystemFonts(boolean enabled) {
117            Options.setUseSystemFonts(enabled);
118        }
119    
120        /**
121         * @param fontPolicy the font policy.
122         * @see com.jgoodies.looks.plastic.PlasticLookAndFeel#setFontPolicy(com.jgoodies.looks.FontPolicy)
123         */
124        public void setFontSizeHints(FontPolicy fontPolicy) {
125            PlasticLookAndFeel.setFontPolicy(fontPolicy);
126        }
127    
128        /**
129         * @param threeDEnabled set to <code>true</code> if 3D should be enabled.
130         * @see com.jgoodies.looks.plastic.PlasticLookAndFeel#set3DEnabled(boolean)
131         */
132        public void set3DEnabled(boolean threeDEnabled) {
133            PlasticLookAndFeel.set3DEnabled(threeDEnabled);
134        }
135    
136        /**
137         * @param highContrastEnabled set to <code>true</code> if high contrast should be enabled.
138         * @see com.jgoodies.looks.plastic.PlasticLookAndFeel#setHighContrastFocusColorsEnabled(boolean)
139         */
140        public void setHighContrastFocusColorsEnabled(boolean highContrastEnabled) {
141            PlasticLookAndFeel
142                    .setHighContrastFocusColorsEnabled(highContrastEnabled);
143        }
144    
145        /**
146         * @param tabStyle set the tab style that should be used.
147         * @see com.jgoodies.looks.plastic.PlasticLookAndFeel#setTabStyle(String)   
148         */
149        public void setTabStyle(String tabStyle) {
150            PlasticLookAndFeel.setTabStyle(tabStyle);
151        }
152    
153        /**
154         * <p>
155         * Set the FQN of the LaF to use. This should be on of:
156         * </p>
157         * <ul>
158         * <li>{@link com.jgoodies.looks.Options#PLASTIC_NAME</li>
159         * <li>{@link com.jgoodies.looks.Options#PLASTIC3D_NAME</li>
160         * <li>{@link com.jgoodies.looks.Options#PLASTICXP_NAME</li>
161         * <li>{@link com.jgoodies.looks.Options#JGOODIES_WINDOWS_NAME</li>
162         * <li>{@link com.jgoodies.looks.Options#DEFAULT_LOOK_NAME</li>
163         * </ul>
164         *
165         * <p>Default LaF if not specified is Options#PLASTICXP_NAME. Note that you could mention any LaF FQN here, but all other options would then be ignored.</p> 
166         *
167         * @param laFName the FQN of the LaF you want to install on the UIManagerConfigurer.
168         */
169        public void setLaFName(String laFName) {
170            this.laFName = laFName;
171        }
172    
173        public void afterPropertiesSet() throws Exception {
174            configurer.setLookAndFeel(laFName);
175        }
176    }