KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > windows > view > ui > tabcontrol > TabbedContainerBridgeImpl


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  * TabbedContainerBridgeImpl.java
21  *
22  * Created on June 1, 2004, 6:42 PM
23  */

24
25 package org.netbeans.core.windows.view.ui.tabcontrol;
26
27 import java.util.List JavaDoc;
28 import java.util.Arrays JavaDoc;
29 import javax.swing.JComponent JavaDoc;
30 import javax.swing.event.ChangeListener JavaDoc;
31 import org.netbeans.swing.tabcontrol.ComponentConverter;
32 import org.netbeans.swing.tabcontrol.TabData;
33 import org.netbeans.swing.tabcontrol.TabbedContainer;
34 import org.netbeans.swing.tabcontrol.TabDataModel;
35 import org.netbeans.modules.openide.explorer.TabbedContainerBridge;
36
37 /**
38  * Implementation of org.netbeans.modules.explorer.TabbedContainerBridge, as
39  * used by the property sheet. This class allows the property sheet to use
40  * TabbedContainer without openide explicitly depending on the TabControl
41  * library (currently impossible).
42  *
43  * @author Tim Boudreau
44  */

45 public class TabbedContainerBridgeImpl extends TabbedContainerBridge {
46     
47     /** Creates a new instance of TabbedContainerBridgeImpl */
48     public TabbedContainerBridgeImpl() {
49     }
50     
51     public void attachSelectionListener(JComponent JavaDoc jc, ChangeListener JavaDoc listener) {
52         TabbedContainer cont = (TabbedContainer) jc;
53         cont.getSelectionModel().addChangeListener(listener);
54     }
55     
56     public JComponent JavaDoc createTabbedContainer() {
57         return new TabbedContainer(TabbedContainer.TYPE_TOOLBAR);
58     }
59     
60     public void detachSelectionListener(JComponent JavaDoc jc, ChangeListener JavaDoc listener) {
61         TabbedContainer cont = (TabbedContainer) jc;
62         cont.getSelectionModel().removeChangeListener(listener);
63     }
64     
65     public Object JavaDoc[] getItems(JComponent JavaDoc jc) {
66         TabbedContainer cont = (TabbedContainer) jc;
67         List JavaDoc l = cont.getModel().getTabs();
68         Object JavaDoc[] items = new Object JavaDoc[l.size()];
69         for (int i=0; i < items.length; i++) {
70             items[i] = ((TabData) l.get(i)).getUserObject();
71         }
72         return items;
73     }
74     
75     public Object JavaDoc getSelectedItem(JComponent JavaDoc jc) {
76         Object JavaDoc result = null;
77         TabbedContainer cont = (TabbedContainer) jc;
78         int i = cont.getSelectionModel().getSelectedIndex();
79         if (i != -1) {
80             result = cont.getModel().getTab(i).getUserObject();
81         }
82         return result;
83     }
84
85     public void setSelectedItem(JComponent JavaDoc jc, Object JavaDoc selection) {
86         TabbedContainer cont = (TabbedContainer) jc;
87         TabDataModel mdl = cont.getModel();
88         int max = mdl.size();
89         for (int i=0; i < max; i++) {
90             TabData td = mdl.getTab(i);
91             if (td.getUserObject() == selection) {
92                 cont.getSelectionModel().setSelectedIndex(i);
93                 break;
94             }
95         }
96     }
97
98     public boolean setSelectionByName(JComponent JavaDoc jc, String JavaDoc tabname) {
99         TabbedContainer cont = (TabbedContainer) jc;
100         TabDataModel mdl = cont.getModel();
101         int max = mdl.size();
102         for (int i=0; i < max; i++) {
103             TabData td = mdl.getTab(i);
104             if (tabname.equals(td.getText())) {
105                 cont.getSelectionModel().setSelectedIndex(i);
106                 return true;
107             }
108         }
109         return false;
110     }
111
112     public String JavaDoc getCurrentSelectedTabName(JComponent JavaDoc jc) {
113         TabbedContainer cont = (TabbedContainer) jc;
114         int sel = cont.getSelectionModel().getSelectedIndex();
115         if (sel != -1) {
116             TabData td = cont.getModel().getTab(sel);
117             return td.getText();
118         }
119         return null;
120     }
121
122     public void setInnerComponent(JComponent JavaDoc jc, JComponent JavaDoc inner) {
123         TabbedContainer cont = (TabbedContainer) jc;
124         ComponentConverter cc = new ComponentConverter.Fixed (inner);
125         cont.setComponentConverter(cc);
126     }
127     
128     public JComponent JavaDoc getInnerComponent(JComponent JavaDoc jc) {
129         TabbedContainer cont = (TabbedContainer) jc;
130         return (JComponent JavaDoc) cont.getComponentConverter().getComponent(null);
131     }
132     
133     public void setItems(JComponent JavaDoc jc, Object JavaDoc[] objects, String JavaDoc[] titles) {
134         TabbedContainer cont = (TabbedContainer) jc;
135         assert objects.length == titles.length;
136         TabData[] td = new TabData [objects.length];
137         for (int i=0; i < objects.length; i++) {
138             td[i] = new TabData (objects[i], null, titles[i], null);
139         }
140         cont.getModel().setTabs(td);
141     }
142     
143 }
144
Popular Tags