KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > openide > explorer > TrivialTabbedContainerBridgeImpl


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 package org.netbeans.modules.openide.explorer;
20
21 import javax.swing.*;
22 import javax.swing.event.ChangeListener JavaDoc;
23
24 import java.awt.*;
25
26 /**
27  * Trivial implementation of TabbedContainerBridge for use with unit tests, etc.
28  * Does not actually support changing tabs, this is just so things link and do not
29  * throw NPEs.
30  * <p>
31  * Given sufficient interest, a JTabbedPane implementation could be provided,
32  * though there are some non-trivial difficulties getting a JTabbedPane to show
33  * the same component for all tabs, and the technique that worked on 1.4 does not
34  * work on 1.5.
35  *
36  */

37 public class TrivialTabbedContainerBridgeImpl extends TabbedContainerBridge {
38     public TrivialTabbedContainerBridgeImpl() {
39
40     }
41
42     public JComponent createTabbedContainer() {
43         JPanel result = new JPanel();
44         result.setLayout (new BorderLayout());
45         result.putClientProperty ("titles", new String JavaDoc[0]);
46         result.putClientProperty ("items", new Object JavaDoc[0]);
47         return result;
48     }
49
50     public void setInnerComponent(JComponent container, JComponent inner) {
51         if (container.getComponentCount() > 0) {
52             container.removeAll();
53         }
54         container.add (inner, BorderLayout.CENTER);
55     }
56
57     public JComponent getInnerComponent(JComponent jc) {
58         JComponent result = null;
59         if (jc.getComponentCount() > 0 && jc.getComponent(0) instanceof JComponent) {
60             result = (JComponent) jc.getComponent(0);
61         }
62         return result;
63     }
64
65     public Object JavaDoc[] getItems(JComponent jc) {
66         return new Object JavaDoc[0];
67     }
68
69     public void setItems(JComponent jc, Object JavaDoc[] objects, String JavaDoc[] titles) {
70         jc.putClientProperty ("items", objects);
71         jc.putClientProperty ("titles", titles);
72     }
73
74     public void attachSelectionListener(JComponent jc, ChangeListener JavaDoc listener) {
75         //do nothing
76
}
77
78     public void detachSelectionListener(JComponent jc, ChangeListener JavaDoc listener) {
79         //do nothing
80
}
81
82     public Object JavaDoc getSelectedItem(JComponent jc) {
83         Object JavaDoc[] items = (Object JavaDoc[]) jc.getClientProperty ("items");
84         if (items != null && items.length > 0) {
85             return items[0];
86         }
87         return null;
88     }
89
90     public void setSelectedItem(JComponent jc, Object JavaDoc selection) {
91         //do nothing
92
}
93
94     public boolean setSelectionByName(JComponent jc, String JavaDoc tabname) {
95         return false;
96     }
97
98     public String JavaDoc getCurrentSelectedTabName(JComponent jc) {
99         String JavaDoc[] titles = (String JavaDoc[]) jc.getClientProperty("titles");
100         if (titles != null && titles.length > 0) {
101             return titles[0];
102         }
103         return ""; //NOI18N
104
}
105 }
106
Popular Tags