KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > swing > tabcontrol > ComponentConverter


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * ComponentConverter.java
21  *
22  * Created on March 28, 2004, 9:20 PM
23  */

24
25 package org.netbeans.swing.tabcontrol;
26
27 import java.awt.*;
28
29 /**
30  * A class which can provide a component corresponding to a TabData object.
31  * While TabData.getComponent can provide a Component via its getComponent()
32  * method, there are use cases where the tabbed container should contain a
33  * single component, and the data model should be used to control it (the
34  * tabbed form of NetBeans' property sheet is one example).
35  * <p>
36  * A ComponentConvertor can be plugged into an instance of TabbedContainer
37  * to enable it to display, for example, the same component for all tabs, which a listener
38  * on its selection model will reconfigure for the selected tab; or it can
39  * be used for lazy initialization, to construct components on demand.
40  *
41  * @author Tim Boudreau
42  */

43 public interface ComponentConverter {
44     Component getComponent (TabData data);
45     
46     /** A default implementation which simply delegates to
47      * TabData.getComponent() */

48     static final ComponentConverter DEFAULT = new ComponentConverter() {
49         public Component getComponent(TabData data) {
50             return data.getComponent();
51         }
52     };
53     
54     /** A ComponentConverter implementation which always returns the same
55      * component */

56     public static final class Fixed implements ComponentConverter {
57         private final Component component;
58         public Fixed (Component component) {
59             this.component = component;
60         }
61         
62         public Component getComponent(TabData data) {
63             return component;
64         }
65     }
66 }
67
Popular Tags