KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > swing > tabcontrol > plaf > TabCellRenderer


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  * TabCellRenderer.java
21  *
22  * Created on December 2, 2003, 6:25 PM
23  */

24
25 package org.netbeans.swing.tabcontrol.plaf;
26
27 import org.netbeans.swing.tabcontrol.TabData;
28
29 import javax.swing.*;
30 import java.awt.*;
31
32 /**
33  * Interface for a component that can render a tab and handle other aspects of
34  * its functionality. Implementing this interface is the main aspect of implementing
35  * an additional look and feel.
36  * <p>
37  * Note: The component returned by getRendererComponent() should be capable of
38  * painting itself properly without needing to be added into the AWT hierarchy - it
39  * will be painted directly with a call to its paint() method, not by using
40  * SwingUtilities.paintComponent(), for performance reasons.
41  */

42 public interface TabCellRenderer {
43     /**
44      * Configures and returns a component which can appropriately paint the
45      * passed tab in its current state
46      */

47     public JComponent getRendererComponent(TabData data, Rectangle bounds,
48                                            int state);
49
50     /**
51      * Get a command string which is identified with a region of the tab cell
52      * renderer, such as TabbedContainer.COMMAND_CLOSE if the point is inside the
53      * close button, or TabbedContainer.COMMAND_SELECT if the point is over the
54      * tab title. The command returned should be the one that would be executed
55      * were the default mouse button to be pressed. Primarily this method is used
56      * to determine what, if any, visual feedback to show to the user as the mouse
57      * is moved over tabs.
58      *
59      * @param p A point (presumably) within the bounds of the passed rectangle
60      * @param tabState The state of the tab, such as selected, clip right, etc.
61      * @param bounds The bounds of the tab, defining the coordinate space in which
62      * the point parameter should be evaluated
63      * @return A command string. TabDisplayer/TabbedContainer define a small number,
64      * but other UIs can define whatever private contract they want. If the
65      * action is performed, an action event with this string will be fired
66      * from the tabbed container, so client code can handle the actual work
67      * of the action as needed
68      */

69     public String JavaDoc getCommandAtPoint (Point p, int tabState, Rectangle bounds);
70
71
72     /**
73      * Get a command string which is identified with a region of the tab cell
74      * renderer, such as TabbedContainer.COMMAND_CLOSE if the point is inside the
75      * close button, or TabbedContainer.COMMAND_SELECT if the point is over the
76      * tab title.
77      *
78      * Note that this method may return a different result than
79      * <code>getCommandAtPoint (Point p, int tabState, Rectangle bounds)</code> -
80      * that method is primarily used for painting logic (such as whether to
81      * draw a rectangle around a close button); this one is to determine the
82      * actual action, if any to perform. So it is free to return null, some
83      * other action, etc.
84      *
85      * @param p A point (presumably) within the bounds of the passed rectangle
86      * @param tabState The state of the tab, such as selected, clip right, etc.
87      * @param bounds The bounds of the tab, defining the coordinate space in which
88      * the point parameter should be evaluated
89      * @param mouseButton The mouse button used to produce the event, as defined in MouseEvent
90      * @param eventType The event type, as defined in MouseEvent
91      * @param modifiers The modifiers mask, as defined in MouseEvent
92      *
93      * @return A command string or null
94      */

95     public String JavaDoc getCommandAtPoint (Point p, int tabState, Rectangle bounds, int mouseButton,
96                                      int eventType, int modifiers);
97
98
99     /**
100      * Get the shape that represents those pixels actually occupied by the tab
101      * on-screen. This is used for determining whether a mouse event really
102      * occured on a tab, and for painting.<p> <b>A note on painting of tab drag
103      * and drop indication: <code>AbstractTabsUI</code> contains generic
104      * support for drawing drag and drop target indications. If want to use it
105      * rather than write your own, you need to specify the polygon returned by
106      * this method with the following point order: The last two points in the
107      * point array of the polygon <strong>must be the bottom left corner,
108      * followed by the bottom right corner</strong>. In other words, start at
109      * the upper left corner when constructing the polygon, and end at the
110      * bottom right corner, using no more than one point for the bottom left and
111      * right corners:
112      * <pre>
113      * start here --> /---------
114      * |
115      * finish here --> ----------
116      * </pre>
117      */

118     public Polygon getTabShape(int tabState, Rectangle bounds);
119
120     /**
121      * Returns the number of pixels this renderer wants added to the base width
122      * and height of the icon and text to fit decorations such as close butons,
123      * drag indicators, etc. This method is called only <strong>once</strong>,
124      * during initialization, if this renderer is the default renderer created
125      * by <code>TabsUI.createDefaultRenderer()</code>. The values it returns
126      * cannot be changed dynamically. The result will be passed as padX/padY
127      * arguments to the constructor of DefaultTabLayoutModel (unless
128      * createLayoutModel is overridden with some custom model - then all bets
129      * are off).
130      */

131     public Dimension getPadding();
132
133     /**
134      * Returns the number of pixels to be added to the width of a cell if the
135      * cell is the selected index. This method is also called only once, on
136      * initialization, for the default renderer
137      */

138     public int getPixelsToAddToSelection();
139
140     public Color getSelectedBackground(); //XXX delete me
141

142     public Color getSelectedActivatedBackground(); //XXX delete me
143

144     public boolean isShowCloseButton();
145     
146     public void setShowCloseButton(boolean val);
147 }
148
Popular Tags