Source Code Cross Referenced for LookAndFeel.java in  » 6.0-JDK-Core » swing » javax » swing » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » swing » javax.swing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
003         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004         *
005         * This code is free software; you can redistribute it and/or modify it
006         * under the terms of the GNU General Public License version 2 only, as
007         * published by the Free Software Foundation.  Sun designates this
008         * particular file as subject to the "Classpath" exception as provided
009         * by Sun in the LICENSE file that accompanied this code.
010         *
011         * This code is distributed in the hope that it will be useful, but WITHOUT
012         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014         * version 2 for more details (a copy is included in the LICENSE file that
015         * accompanied this code).
016         *
017         * You should have received a copy of the GNU General Public License version
018         * 2 along with this work; if not, write to the Free Software Foundation,
019         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020         *
021         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022         * CA 95054 USA or visit www.sun.com if you need additional information or
023         * have any questions.
024         */
025
026        package javax.swing;
027
028        import java.awt.Font;
029        import java.awt.event.InputEvent;
030        import java.awt.event.KeyEvent;
031        import java.awt.Color;
032        import java.awt.Component;
033        import java.awt.SystemColor;
034        import java.awt.Toolkit;
035
036        import javax.swing.text.*;
037        import javax.swing.border.*;
038        import javax.swing.plaf.*;
039
040        import java.net.URL;
041        import sun.swing.SwingUtilities2;
042        import sun.swing.DefaultLayoutStyle;
043        import sun.swing.ImageIconUIResource;
044
045        import java.util.StringTokenizer;
046
047        /**
048         * {@code LookAndFeel}, as the name implies, encapsulates a look and
049         * feel. Beyond installing a look and feel most developers never need to
050         * interact directly with {@code LookAndFeel}. In general only developers
051         * creating a custom look and feel need to concern themselves with this class.
052         * <p>
053         * Swing is built upon the foundation that each {@code JComponent}
054         * subclass has an implementation of a specific {@code ComponentUI}
055         * subclass. The {@code ComponentUI} is often referred to as "the ui",
056         * "component ui", or "look and feel delegate". The {@code ComponentUI}
057         * subclass is responsible for providing the look and feel specific
058         * functionality of the component. For example, {@code JTree} requires
059         * an implementation of the {@code ComponentUI} subclass {@code
060         * TreeUI}. The implementation of the specific {@code
061         * ComponentUI} subclass is provided by the {@code LookAndFeel}. Each
062         * {@code JComponent} subclass identifies the {@code ComponentUI}
063         * subclass it requires by way of the {@code JComponent} method {@code
064         * getUIClassID}.
065         * <p>
066         * Each {@code LookAndFeel} implementation must provide
067         * an implementation of the appropriate {@code ComponentUI} subclass by
068         * specifying a value for each of Swing's ui class ids in the {@code
069         * UIDefaults} object returned from {@code getDefaults}. For example,
070         * {@code BasicLookAndFeel} uses {@code BasicTreeUI} as the concrete
071         * implementation for {@code TreeUI}. This is accomplished by {@code
072         * BasicLookAndFeel} providing the key-value pair {@code
073         * "TreeUI"-"javax.swing.plaf.basic.BasicTreeUI"}, in the
074         * {@code UIDefaults} returned from {@code getDefaults}. Refer to
075         * {@link UIDefaults#getUI(JComponent)} for defails on how the implementation
076         * of the {@code ComponentUI} subclass is obtained.
077         * <p>
078         * When a {@code LookAndFeel} is installed the {@code UIManager} does
079         * not check that an entry exists for all ui class ids. As such,
080         * random exceptions will occur if the current look and feel has not
081         * provided a value for a particular ui class id and an instance of
082         * the {@code JComponent} subclass is created.
083         *
084         * <h2>Recommendations for Look and Feels</h2>
085         *
086         * As noted in {@code UIManager} each {@code LookAndFeel} has the opportunity
087         * to provide a set of defaults that are layered in with developer and
088         * system defaults. Some of Swing's components require the look and feel
089         * to provide a specific set of defaults. These are documented in the
090         * classes that require the specific default.
091         *
092         * <h3><a name="#defaultRecommendation">ComponentUIs and defaults</a></h2>
093         *
094         * All {@code ComponentUIs} typically need to set various properties
095         * on the {@code JComponent} the {@code ComponentUI} is providing the
096         * look and feel for. This is typically done when the {@code
097         * ComponentUI} is installed on the {@code JComponent}. Setting a
098         * property should only be done if the developer has not set the
099         * property. For non-primitive values it is recommended that the
100         * {@code ComponentUI} only change the property on the {@code
101         * JComponent} if the current value is {@code null} or implements
102         * {@code UIResource}. If the current value is {@code null} or
103         * implements {@code UIResource} it indicates the property has not
104         * been set by the developer, and the ui is free to change it.  For
105         * example, {@code BasicButtonUI.installDefaults} only changes the
106         * font on the {@code JButton} if the return value from {@code
107         * button.getFont()} is {@code null} or implements {@code
108         * UIResource}. On the other hand if {@code button.getFont()} returned
109         * a {@code non-null} value that did not implement {@code UIResource}
110         * then {@code BasicButtonUI.installDefaults} would not change the
111         * {@code JButton}'s font.
112         * <p>
113         * For primitive values, such as {@code opaque}, the method {@code
114         * installProperty} should be invoked.  {@code installProperty} only changes
115         * the correspoding property if the value has not been changed by the
116         * developer.
117         * <p>
118         * {@code ComponentUI} implementations should use the various install methods
119         * provided by this class as they handle the necessary checking and install
120         * the property using the recommended guidelines.
121         * <p>
122         * <h3><a name="exceptions"></a>Exceptions</h3>
123         *
124         * All of the install methods provided by {@code LookAndFeel} need to
125         * access the defaults if the value of the property being changed is
126         * {@code null} or a {@code UIResource}. For example, installing the
127         * font does the following:
128         * <pre>
129         *   JComponent c;
130         *   Font font = c.getFont();
131         *   if (font == null || (font instanceof UIResource)) {
132         *       c.setFont(UIManager.getFont("fontKey"));
133         *   }
134         * </pre>
135         * If the font is {@code null} or a {@code UIResource}, the
136         * defaults table is queried with the key {@code fontKey}. All of
137         * {@code UIDefault's} get methods throw a {@code
138         * NullPointerException} if passed in {@code null}. As such, unless
139         * otherwise noted each of the various install methods of {@code
140         * LookAndFeel} throw a {@code NullPointerException} if the current
141         * value is {@code null} or a {@code UIResource} and the supplied
142         * defaults key is {@code null}. In addition, unless otherwise specified
143         * all of the {@code install} methods throw a {@code NullPointerException} if
144         * a {@code null} component is passed in.
145         * 
146         * @version 1.50 05/05/07
147         * @author Tom Ball
148         * @author Hans Muller
149         */
150        public abstract class LookAndFeel {
151
152            /**
153             * Convenience method for setting a component's foreground
154             * and background color properties with values from the
155             * defaults.  The properties are only set if the current
156             * value is either {@code null} or a {@code UIResource}. 
157             * 
158             * @param c component to set the colors on
159             * @param defaultBgName key for the background
160             * @param defaultFgName key for the foreground
161             * 
162             * @see #installColorsAndFont
163             * @see UIManager#getColor
164             * @throws NullPointerException as described in
165             *         <a href="#exceptions">exceptions</a>
166             */
167            public static void installColors(JComponent c,
168                    String defaultBgName, String defaultFgName) {
169                Color bg = c.getBackground();
170                if (bg == null || bg instanceof  UIResource) {
171                    c.setBackground(UIManager.getColor(defaultBgName));
172                }
173
174                Color fg = c.getForeground();
175                if (fg == null || fg instanceof  UIResource) {
176                    c.setForeground(UIManager.getColor(defaultFgName));
177                }
178            }
179
180            /**
181             * Convenience method for setting a component's foreground,
182             * background and font properties with values from the
183             * defaults.  The properties are only set if the current
184             * value is either {@code null} or a {@code UIResource}.
185             * 
186             * @param c component set to the colors and font on
187             * @param defaultBgName key for the background
188             * @param defaultFgName key for the foreground
189             * @param defaultFontName key for the font
190             * @throws NullPointerException as described in
191             *         <a href="#exceptions">exceptions</a>
192             * 
193             * @see #installColors
194             * @see UIManager#getColor
195             * @see UIManager#getFont
196             */
197            public static void installColorsAndFont(JComponent c,
198                    String defaultBgName, String defaultFgName,
199                    String defaultFontName) {
200                Font f = c.getFont();
201                if (f == null || f instanceof  UIResource) {
202                    c.setFont(UIManager.getFont(defaultFontName));
203                }
204
205                installColors(c, defaultBgName, defaultFgName);
206            }
207
208            /**
209             * Convenience method for setting a component's border property with
210             * a value from the defaults. The border is only set if the border is 
211             * {@code null} or an instance of {@code UIResource}.
212             *
213             * @param c component to set the border on
214             * @param defaultBorderName key specifying the border
215             * @throws NullPointerException as described in
216             *         <a href="#exceptions">exceptions</a>
217             */
218            public static void installBorder(JComponent c,
219                    String defaultBorderName) {
220                Border b = c.getBorder();
221                if (b == null || b instanceof  UIResource) {
222                    c.setBorder(UIManager.getBorder(defaultBorderName));
223                }
224            }
225
226            /**
227             * Convenience method for uninstalling a border. If the border of
228             * the component is a {@code UIResource}, it is set to {@code
229             * null}.
230             *
231             * @param c component to uninstall the border on
232             * @throws NullPointerException if {@code c} is {@code null}
233             */
234            public static void uninstallBorder(JComponent c) {
235                if (c.getBorder() instanceof  UIResource) {
236                    c.setBorder(null);
237                }
238            }
239
240            /**
241             * Convenience method for installing a property with the specified name
242             * and value on a component if that property has not already been set
243             * by the developer.  This method is intended to be used by
244             * ui delegate instances that need to specify a default value for a
245             * property of primitive type (boolean, int, ..), but do not wish
246             * to override a value set by the client.  Since primitive property
247             * values cannot be wrapped with the {@code UIResource} marker, this method
248             * uses private state to determine whether the property has been set
249             * by the client.
250             *
251             * @throws IllegalArgumentException if the specified property is not
252             *         one which can be set using this method
253             * @throws ClassCastException if the property value has not been set
254             *         by the developer and the type does not match the property's type
255             * @throws NullPointerException if {@code c} is {@code null}, or the
256             *         named property has not been set by the developer and 
257             *         {@code propertyValue} is {@code null}
258             * @param c target component to set the property on
259             * @param propertyName name of the property to set
260             * @param propertyValue value of the property
261             * @since 1.5
262             */
263            public static void installProperty(JComponent c,
264                    String propertyName, Object propertyValue) {
265                // this is a special case because the JPasswordField's ancestor heirarchy
266                // includes a class outside of javax.swing, thus we cannot call setUIProperty
267                // directly.
268                if (c instanceof  JPasswordField) {
269                    if (!((JPasswordField) c).customSetUIProperty(propertyName,
270                            propertyValue)) {
271                        c.setUIProperty(propertyName, propertyValue);
272                    }
273                } else {
274                    c.setUIProperty(propertyName, propertyValue);
275                }
276            }
277
278            /**
279             * Convenience method for building an array of {@code
280             * KeyBindings}. While this method is not deprecated, developers
281             * should instead use {@code ActionMap} and {@code InputMap} for
282             * supplying key bindings.
283             * <p>
284             * This method returns an array of {@code KeyBindings}, one for each
285             * alternating {@code key-action} pair in {@code keyBindingList}.
286             * A {@code key} can either be a {@code String} in the format
287             * specified by the <code>KeyStroke.getKeyStroke</code> method, or
288             * a {@code KeyStroke}. The {@code action} part of the pair is a
289             * {@code String} that corresponds to the name of the {@code
290             * Action}.
291             * <p>
292             * The following example illustrates creating a {@code KeyBinding} array
293             * from six alternating {@code key-action} pairs:
294             * <pre>
295             * 	JTextComponent.KeyBinding[] multilineBindings = makeKeyBindings( new Object[] {
296             *          "UP", DefaultEditorKit.upAction,
297             *        "DOWN", DefaultEditorKit.downAction,
298             *     "PAGE_UP", DefaultEditorKit.pageUpAction,
299             *   "PAGE_DOWN", DefaultEditorKit.pageDownAction,
300             *       "ENTER", DefaultEditorKit.insertBreakAction,
301             *         "TAB", DefaultEditorKit.insertTabAction
302             *  });
303             * </pre>
304             * If {@code keyBindingList's} length is odd, the last element is
305             * ignored.
306             * <p>
307             * Supplying a {@code null} value for either the {@code key} or
308             * {@code action} part of the {@code key-action} pair results in
309             * creating a {@code KeyBinding} with the corresponding value 
310             * {@code null}. As other parts of Swing's expect {@code non-null} values
311             * in a {@code KeyBinding}, you should avoid supplying {@code null} as
312             * either the {@code key} or {@code action} part of the {@code key-action}
313             * pair.
314             *
315             * @param keyBindingList an array of {@code key-action} pairs
316             * @return an array of {@code KeyBindings}
317             * @throws NullPointerException if {@code keyBindingList} is {@code null}
318             * @throws ClassCastException if the {@code key} part of the pair is
319             *         not a {@code KeyStroke} or {@code String}, or the
320             *         {@code action} part of the pair is not a {@code String}
321             * @see ActionMap
322             * @see InputMap
323             * @see KeyStroke#getKeyStroke
324             */
325            public static JTextComponent.KeyBinding[] makeKeyBindings(
326                    Object[] keyBindingList) {
327                JTextComponent.KeyBinding[] rv = new JTextComponent.KeyBinding[keyBindingList.length / 2];
328
329                for (int i = 0; i < keyBindingList.length; i += 2) {
330                    KeyStroke keystroke = (keyBindingList[i] instanceof  KeyStroke) ? (KeyStroke) keyBindingList[i]
331                            : KeyStroke
332                                    .getKeyStroke((String) keyBindingList[i]);
333                    String action = (String) keyBindingList[i + 1];
334                    rv[i / 2] = new JTextComponent.KeyBinding(keystroke, action);
335                }
336
337                return rv;
338            }
339
340            /**
341             * Creates a {@code InputMapUIResource} from <code>keys</code>. This is
342             * a convenience method for creating a new {@code InputMapUIResource},
343             * invoking {@code loadKeyBindings(map, keys)}, and returning the
344             * {@code InputMapUIResource}.
345             *
346             * @param keys alternating pairs of {@code keystroke-action key}
347             *        pairs as described in {@link #loadKeyBindings}
348             * @return newly created and populated {@code InputMapUIResource}
349             * @see #loadKeyBindings
350             *
351             * @since 1.3
352             */
353            public static InputMap makeInputMap(Object[] keys) {
354                InputMap retMap = new InputMapUIResource();
355                loadKeyBindings(retMap, keys);
356                return retMap;
357            }
358
359            /**
360             * Creates a {@code ComponentInputMapUIResource} from
361             * <code>keys</code>. This is a convenience method for creating a
362             * new {@code ComponentInputMapUIResource}, invoking {@code
363             * loadKeyBindings(map, keys)}, and returning the {@code
364             * ComponentInputMapUIResource}.
365             *
366             * @param c component to create the {@code ComponentInputMapUIResource}
367             *          with
368             * @param keys alternating pairs of {@code keystroke-action key}
369             *        pairs as described in {@link #loadKeyBindings}
370             * @return newly created and populated {@code InputMapUIResource}
371             * @throws IllegalArgumentException if {@code c} is {@code null}
372             *
373             * @see #loadKeyBindings
374             * @see ComponentInputMapUIResource
375             * 
376             * @since 1.3
377             */
378            public static ComponentInputMap makeComponentInputMap(JComponent c,
379                    Object[] keys) {
380                ComponentInputMap retMap = new ComponentInputMapUIResource(c);
381                loadKeyBindings(retMap, keys);
382                return retMap;
383            }
384
385            /**
386             * Populates an {@code InputMap} with the specified bindings.
387             * The bindings are supplied as a list of alternating
388             * {@code keystroke-action key} pairs. The {@code keystroke} is either
389             * an instance of {@code KeyStroke}, or a {@code String}
390             * that identifies the {@code KeyStroke} for the binding. Refer
391             * to {@code KeyStroke.getKeyStroke(String)} for the specific
392             * format. The {@code action key} part of the pair is the key
393             * registered in the {@code InputMap} for the {@code KeyStroke}.
394             * <p>
395             * The following illustrates loading an {@code InputMap} with two
396             * {@code key-action} pairs:
397             * <pre>
398             *   LookAndFeel.loadKeyBindings(inputMap, new Object[] {
399             *     "control X", "cut",
400             *     "control V", "paste"
401             *   });
402             * </pre>
403             * <p>
404             * Supplying a {@code null} list of bindings ({@code keys}) does not
405             * change {@code retMap} in any way.
406             * <p>
407             * Specifying a {@code null} {@code action key} results in
408             * removing the {@code keystroke's} entry from the {@code InputMap}.
409             * A {@code null} {@code keystroke} is ignored.
410             *
411             * @param retMap {@code InputMap} to add the {@code key-action}
412             *               pairs to
413             * @param keys bindings to add to {@code retMap}
414             * @throws NullPointerException if {@code keys} is
415             *         {@code non-null}, not empty, and {@code retMap} is
416             *         {@code null}
417             *
418             * @see KeyStroke#getKeyStroke(String)
419             * @see InputMap
420             *
421             * @since 1.3
422             */
423            public static void loadKeyBindings(InputMap retMap, Object[] keys) {
424                if (keys != null) {
425                    for (int counter = 0, maxCounter = keys.length; counter < maxCounter; counter++) {
426                        Object keyStrokeO = keys[counter++];
427                        KeyStroke ks = (keyStrokeO instanceof  KeyStroke) ? (KeyStroke) keyStrokeO
428                                : KeyStroke.getKeyStroke((String) keyStrokeO);
429                        retMap.put(ks, keys[counter]);
430                    }
431                }
432            }
433
434            /**
435             * Creates and returns a {@code UIDefault.LazyValue} that loads an
436             * image. The returned value is an implementation of {@code
437             * UIDefaults.LazyValue}. When {@code createValue} is invoked on
438             * the returned object, the image is loaded. If the image is {@code
439             * non-null}, it is then wrapped in an {@code Icon} that implements {@code
440             * UIResource}. The image is loaded using {@code
441             * Class.getResourceAsStream(gifFile)}.
442             * <p>
443             * This method does not check the arguments in any way. It is
444             * strongly recommended that {@code non-null} values are supplied else
445             * exceptions may occur when {@code createValue} is invoked on the
446             * returned object.
447             *
448             * @param baseClass {@code Class} used to load the resource
449             * @param gifFile path to the image to load
450             * @return a {@code UIDefaults.LazyValue}; when resolved the
451             *         {@code LazyValue} loads the specified image
452             * @see UIDefaults.LazyValue
453             * @see Icon
454             * @see Class#getResourceAsStream(String)
455             */
456            public static Object makeIcon(final Class<?> baseClass,
457                    final String gifFile) {
458                return SwingUtilities2.makeIcon(baseClass, baseClass, gifFile);
459            }
460
461            /**
462             * Returns the <code>LayoutStyle</code> for this look
463             * and feel.  This never returns {@code null}.
464             * <p>
465             * You generally don't use the <code>LayoutStyle</code> from
466             * the look and feel, instead use the <code>LayoutStyle</code>
467             * method <code>getInstance</code>.
468             *
469             * @see LayoutStyle#getInstance
470             * @return the <code>LayoutStyle</code> for this look and feel
471             * @since 1.6
472             */
473            public LayoutStyle getLayoutStyle() {
474                return DefaultLayoutStyle.getInstance();
475            }
476
477            /**
478             * Invoked when the user attempts an invalid operation, 
479             * such as pasting into an uneditable <code>JTextField</code> 
480             * that has focus. The default implementation beeps. Subclasses 
481             * that wish different behavior should override this and provide 
482             * the additional feedback.
483             *
484             * @param component the <code>Component</code> the error occurred in,
485             *                  may be <code>null</code>
486             *			indicating the error condition is not directly 
487             *			associated with a <code>Component</code>
488             * @since 1.4
489             */
490            public void provideErrorFeedback(Component component) {
491                Toolkit toolkit = null;
492                if (component != null) {
493                    toolkit = component.getToolkit();
494                } else {
495                    toolkit = Toolkit.getDefaultToolkit();
496                }
497                toolkit.beep();
498            } // provideErrorFeedback()
499
500            /**
501             * Returns the value of the specified system desktop property by
502             * invoking <code>Toolkit.getDefaultToolkit().getDesktopProperty()</code>.
503             * If the value of the specified property is {@code null},
504             * {@code fallbackValue} is returned.
505             *
506             * @param systemPropertyName the name of the system desktop property being queried
507             * @param fallbackValue the object to be returned as the value if the system value is null
508             * @return the current value of the desktop property
509             *
510             * @see java.awt.Toolkit#getDesktopProperty
511             *
512             * @since 1.4
513             */
514            public static Object getDesktopPropertyValue(
515                    String systemPropertyName, Object fallbackValue) {
516                Object value = Toolkit.getDefaultToolkit().getDesktopProperty(
517                        systemPropertyName);
518                if (value == null) {
519                    return fallbackValue;
520                } else if (value instanceof  Color) {
521                    return new ColorUIResource((Color) value);
522                } else if (value instanceof  Font) {
523                    return new FontUIResource((Font) value);
524                }
525                return value;
526            }
527
528            /**
529             * Returns an <code>Icon</code> with a disabled appearance.
530             * This method is used to generate a disabled <code>Icon</code> when
531             * one has not been specified.  For example, if you create a
532             * <code>JButton</code> and only specify an <code>Icon</code> via
533             * <code>setIcon</code> this method will be called to generate the
534             * disabled <code>Icon</code>. If {@code null} is passed as
535             * <code>icon</code> this method returns {@code null}. 
536             * <p>
537             * Some look and feels might not render the disabled {@code Icon}, in which
538             * case they will ignore this.
539             *
540             * @param component {@code JComponent} that will display the {@code Icon},
541             *         may be {@code null}
542             * @param icon {@code Icon} to generate the disabled icon from
543             * @return disabled {@code Icon}, or {@code null} if a suitable
544             *         {@code Icon} can not be generated
545             * @since 1.5
546             */
547            public Icon getDisabledIcon(JComponent component, Icon icon) {
548                if (icon instanceof  ImageIcon) {
549                    return new ImageIconUIResource(GrayFilter
550                            .createDisabledImage(((ImageIcon) icon).getImage()));
551                }
552                return null;
553            }
554
555            /**
556             * Returns an <code>Icon</code> for use by disabled
557             * components that are also selected. This method is used to generate an
558             * <code>Icon</code> for components that are in both the disabled and
559             * selected states but do not have a specific <code>Icon</code> for this
560             * state.  For example, if you create a <code>JButton</code> and only
561             * specify an <code>Icon</code> via <code>setIcon</code> this method
562             * will be called to generate the disabled and selected
563             * <code>Icon</code>. If {@code null} is passed as <code>icon</code> this
564             * methods returns {@code null}.
565             * <p>
566             * Some look and feels might not render the disabled and selected
567             * {@code Icon}, in which case they will ignore this.
568             *
569             * @param component {@code JComponent} that will display the {@code Icon},
570             *        may be {@code null}
571             * @param icon {@code Icon} to generate disabled and selected icon from
572             * @return disabled and selected icon, or {@code null} if a suitable
573             *         {@code Icon} can not be generated.
574             * @since 1.5
575             */
576            public Icon getDisabledSelectedIcon(JComponent component, Icon icon) {
577                return getDisabledIcon(component, icon);
578            }
579
580            /**
581             * Return a short string that identifies this look and feel, e.g.
582             * "CDE/Motif".  This string should be appropriate for a menu item.
583             * Distinct look and feels should have different names, e.g. 
584             * a subclass of MotifLookAndFeel that changes the way a few components
585             * are rendered should be called "CDE/Motif My Way"; something
586             * that would be useful to a user trying to select a L&F from a list
587             * of names.
588             *
589             * @return short identifier for the look and feel
590             */
591            public abstract String getName();
592
593            /**
594             * Return a string that identifies this look and feel.  This string 
595             * will be used by applications/services that want to recognize
596             * well known look and feel implementations.  Presently
597             * the well known names are "Motif", "Windows", "Mac", "Metal".  Note 
598             * that a LookAndFeel derived from a well known superclass 
599             * that doesn't make any fundamental changes to the look or feel 
600             * shouldn't override this method.
601             *
602             * @return identifier for the look and feel
603             */
604            public abstract String getID();
605
606            /** 
607             * Return a one line description of this look and feel implementation, 
608             * e.g. "The CDE/Motif Look and Feel".   This string is intended for 
609             * the user, e.g. in the title of a window or in a ToolTip message.
610             *
611             * @return short description for the look and feel
612             */
613            public abstract String getDescription();
614
615            /**
616             * Returns {@code true} if the <code>LookAndFeel</code> returned
617             * <code>RootPaneUI</code> instances support providing {@code Window}
618             * decorations in a <code>JRootPane</code>.
619             * <p>
620             * The default implementation returns {@code false}, subclasses that
621             * support {@code Window} decorations should override this and return
622             * {@code true}.
623             *
624             * @return {@code true} if the {@code RootPaneUI} instances created by
625             *         this look and feel support client side decorations
626             * @see JDialog#setDefaultLookAndFeelDecorated
627             * @see JFrame#setDefaultLookAndFeelDecorated
628             * @see JRootPane#setWindowDecorationStyle
629             * @since 1.4
630             */
631            public boolean getSupportsWindowDecorations() {
632                return false;
633            }
634
635            /**
636             * If the underlying platform has a "native" look and feel, and
637             * this is an implementation of it, return {@code true}.  For
638             * example, when the underlying platform is Solaris running CDE
639             * a CDE/Motif look and feel implementation would return {@code
640             * true}.
641             *
642             * @return {@code true} if this look and feel represents the underlying
643             *         platform look and feel
644             */
645            public abstract boolean isNativeLookAndFeel();
646
647            /**
648             * Return {@code true} if the underlying platform supports and or permits
649             * this look and feel.  This method returns {@code false} if the look 
650             * and feel depends on special resources or legal agreements that
651             * aren't defined for the current platform.  
652             * 
653             *
654             * @return {@code true} if this is a supported look and feel
655             * @see UIManager#setLookAndFeel
656             */
657            public abstract boolean isSupportedLookAndFeel();
658
659            /**
660             * Initializes the look and feel. While this method is public,
661             * it should only be invoked by the {@code UIManager} when a
662             * look and feel is installed as the current look and feel. This
663             * method is invoked before the {@code UIManager} invokes
664             * {@code getDefaults}. This method is intended to perform any
665             * initialization for the look and feel. Subclasses
666             * should do any one-time setup they need here, rather than 
667             * in a static initializer, because look and feel class objects
668             * may be loaded just to discover that {@code isSupportedLookAndFeel()}
669             * returns {@code false}.
670             *
671             * @see #uninitialize
672             * @see UIManager#setLookAndFeel
673             */
674            public void initialize() {
675            }
676
677            /**
678             * Uninitializes the look and feel. While this method is public,
679             * it should only be invoked by the {@code UIManager} when
680             * the look and feel is uninstalled. For example,
681             * {@code UIManager.setLookAndFeel} invokes this when the look and
682             * feel is changed.
683             * <p>
684             * Subclasses may choose to free up some resources here.
685             *
686             * @see #initialize
687             * @see UIManager#setLookAndFeel
688             */
689            public void uninitialize() {
690            }
691
692            /**
693             * Returns the look and feel defaults. While this method is public,
694             * it should only be invoked by the {@code UIManager} when the
695             * look and feel is set as the current look and feel and after
696             * {@code initialize} has been invoked.
697             *
698             * @return the look and feel defaults
699             * @see #initialize
700             * @see #uninitialize
701             * @see UIManager#setLookAndFeel
702             */
703            public UIDefaults getDefaults() {
704                return null;
705            }
706
707            /**
708             * Returns a string that displays and identifies this
709             * object's properties.
710             *
711             * @return a String representation of this object
712             */
713            public String toString() {
714                return "[" + getDescription() + " - " + getClass().getName()
715                        + "]";
716            }
717        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.