KickJava   Java API By Example, From Geeks To Geeks.

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


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  * TabbedContainerUI.java
21  *
22  * Created on March 14, 2004, 3:25 PM
23  */

24
25 package org.netbeans.swing.tabcontrol;
26
27 import org.netbeans.swing.tabcontrol.event.TabActionEvent;
28
29 import javax.swing.*;
30 import javax.swing.plaf.ComponentUI JavaDoc;
31 import java.awt.*;
32 import java.awt.event.HierarchyEvent JavaDoc;
33 import java.awt.event.MouseEvent JavaDoc;
34
35 /**
36  * Basic UI for tabbed containers. Note this is distinct from the UI for the
37  * embedded tab displayer component - that where all the interesting painting
38  * logic is.
39  * <p>
40  * To provide an implementation of TabbedContainerUI, it is a far better idea to
41  * subclass
42  * <a HREF="plaf/AbstractTabbedContainerUI.html">AbstractTabbedContainerUI</a>,
43  * <a HREF="plaf/BasicTabbedContainerUI.html">BasicTabbedContainerUI</a>, or
44  * <a HREF="plaf/BasicScrollingTabbedContainerUI.html">BasicScrollingTabbedContainerUI</a>.
45  *
46  * @author Tim Boudreau
47  */

48 public abstract class TabbedContainerUI extends ComponentUI JavaDoc {
49     /** The TabbedContainer this instance is acting as a ui delegate for.
50      * <strong>do not alter the value in this field. </strong>
51      */

52     protected TabbedContainer container = null;
53
54     /**
55      * Creates a new instance of TabbedContainerUI
56      */

57     public TabbedContainerUI(TabbedContainer container) {
58         this.container = container;
59     }
60
61     public void installUI(JComponent c) {
62         assert c == container;
63     }
64     
65     /**
66      * This method is called if TabbedContainer.updateUI() gets called after
67      * a UI delegate has been installed (in other words, the user did something
68      * like switch look and feels or switch the Windows desktop theme).
69      * <p>
70      * Normally, the only UI delegate that exists for TabbedContainer is
71      * DefaultTabbedContainerUI, so it makes no sense to replace one with
72      * another, since they do the same thing.
73      * <p>
74      * However, this method can be used to update the tab displayer component's
75      * UI. Subclasses are expected to override this method to call
76      * updateUI() on the displayer, or do whatever is appropriate to ensure that
77      * the UI will look right after the change - or to return true from this
78      * method, in which the entire UI delegate for the tabbed container will
79      * be replaced.
80      * @return false
81      */

82     protected boolean uichange() {
83         return false;
84     }
85     
86     /**
87      * Accessor method for TabbedContainer
88      * @see uichange
89      */

90     final boolean shouldReplaceUI() {
91         return uichange();
92     }
93
94
95     /** Get the bounds of a tab. Note that for non-rectangular tabs
96      * this may not correspond exactly to the area in which it will
97      * respond to mouse clicks.
98      *
99      * @param tab A tab index
100      * @param r A rectangle to configure with the information, or null
101      * @return The passed rectangle, or a new one if null was passed
102      */

103     public abstract Rectangle getTabRect(int tab, Rectangle r);
104
105     /** Get the tab at a given point in the coordinate space of the
106      * container.
107      *
108      * @param p A point
109      * @return The tab index at this point, or -1 if no tab
110      */

111     public abstract int tabForCoordinate (Point p);
112
113     /** Make a tab visible. No-op except in the case of scrolling tabs,
114      * in which case the tab may be scrolled offscreen.
115      *
116      * @param index A tab index
117      */

118     public abstract void makeTabVisible (int index);
119
120    /**
121      * Allows ActionListeners attached to the container to determine if the
122      * event should be acted on. Delegates to <code>displayer.postActionEvent()</code>.
123      * This method will create a TabActionEvent with the passed string as an
124      * action command, and cause the displayer to fire this event. It will
125      * return true if no listener on the displayer consumed the TabActionEvent;
126      * consuming the event is the way a listener can veto a change, or provide
127      * special handling for it.
128      *
129      * @param command The action command - this should be TabDisplayer.COMMAND_SELECT
130      * or TabDisplayer.COMMAND_CLOSE, but private contracts
131      * between custom UIs and components are also an option.
132      * @param tab The index of the tab upon which the action should act, or
133      * -1 if non-applicable
134      * @param event A mouse event which initiated the action, or null
135      * @return true if the event posted was not consumed by any listener
136      */

137     protected final boolean shouldPerformAction(String JavaDoc command, int tab,
138                                                 MouseEvent JavaDoc event) {
139         TabActionEvent evt = new TabActionEvent(container, command, tab, event);
140         container.postActionEvent(evt);
141         return !evt.isConsumed();
142     }
143
144     /**
145      * Get the selection model that tracks and determines which tab is selected.
146      *
147      * @return The selection model (in the default implementation, this is the selection model of the
148      * embedded tab displayer)
149      */

150     public abstract SingleSelectionModel getSelectionModel();
151
152     /** Create an image suitable for use in drag and drop operations, of a tab */
153     public abstract Image createImageOfTab(int idx);
154
155     /** Get a polygon matching the shape of the tab */
156     public abstract Polygon getExactTabIndication (int idx);
157
158     /** Get a polygon indicating the insertion of a tab before the passed
159      * index, unless the index is equal to the model size, in which case
160      * it will return an indication for inserting a tab at the end.
161      *
162      * @param idx A tab index
163      * @return A shape representing the shape of the tab as it is displayed onscreen,
164      * in the coordinate space of the displayer
165      */

166     public abstract Polygon getInsertTabIndication (int idx);
167
168     /** Get a rectangle matching the area in which content is displayed */
169     public abstract Rectangle getContentArea ();
170
171     /** Get a rectangle matching the area in which tabs are displayed */
172     public abstract Rectangle getTabsArea ();
173     
174     /**
175      * Index at which a tab would be inserted if a suitable object were dropped
176      * at this point.
177      *
178      * @param p A point
179      * @return A tab index which may be equal to the size of the model (past the
180      * last tab index) if the tab should be inserted at the end.
181      */

182     public abstract int dropIndexOfPoint(Point p);
183     
184     public abstract void setShowCloseButton (boolean val);
185     
186     public abstract boolean isShowCloseButton ();
187
188     protected abstract void requestAttention (int tab);
189     
190     protected abstract void cancelRequestAttention (int tab);
191     
192 }
193
Popular Tags