KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.swing.tabcontrol.plaf;
21
22 import java.awt.Dimension JavaDoc;
23 import java.awt.FontMetrics JavaDoc;
24 import java.awt.Graphics JavaDoc;
25 import java.awt.Insets JavaDoc;
26 import java.awt.Rectangle JavaDoc;
27 import org.netbeans.swing.tabcontrol.TabDisplayer;
28
29 import javax.swing.plaf.ComponentUI JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.Map JavaDoc;
32 import javax.swing.Icon JavaDoc;
33 import javax.swing.JComponent JavaDoc;
34 import javax.swing.UIManager JavaDoc;
35
36 /**
37  * Windows xp impl of tabs ui
38  *
39  * @author Tim Boudreau
40  */

41 public final class WinXPEditorTabDisplayerUI extends BasicScrollingTabDisplayerUI {
42     
43     private static final Rectangle JavaDoc scratch5 = new Rectangle JavaDoc();
44     private static Map JavaDoc<Integer JavaDoc, String JavaDoc[]> buttonIconPaths;
45
46     public WinXPEditorTabDisplayerUI(TabDisplayer displayer) {
47         super (displayer);
48     }
49
50     public static ComponentUI JavaDoc createUI(JComponent JavaDoc c) {
51         return new WinXPEditorTabDisplayerUI ((TabDisplayer) c);
52     }
53
54     public Dimension JavaDoc getPreferredSize(JComponent JavaDoc c) {
55         int prefHeight = 24;
56         Graphics JavaDoc g = BasicScrollingTabDisplayerUI.getOffscreenGraphics();
57         if (g != null) {
58             FontMetrics JavaDoc fm = g.getFontMetrics(displayer.getFont());
59             Insets JavaDoc ins = getTabAreaInsets();
60             prefHeight = fm.getHeight() + ins.top + ins.bottom + 8;
61         }
62         return new Dimension JavaDoc(displayer.getWidth(), prefHeight);
63     }
64     
65     public void paintBackground (Graphics JavaDoc g) {
66         g.setColor (displayer.getBackground());
67         g.fillRect (0, 0, displayer.getWidth(), displayer.getHeight());
68     }
69
70     protected void paintAfterTabs(Graphics JavaDoc g) {
71         Rectangle JavaDoc r = new Rectangle JavaDoc();
72         getTabsVisibleArea(r);
73         r.width = displayer.getWidth();
74
75         Insets JavaDoc ins = getTabAreaInsets();
76
77         int y = displayer.getHeight() - WinXPEditorTabCellRenderer.BOTTOM_INSET;
78         //Draw the fill line that will be under the white highlight line - this
79
//goes across the whole component.
80
int selEnd = 0;
81         int i = selectionModel.getSelectedIndex();
82         g.setColor(WinXPEditorTabCellRenderer.getSelectedTabBottomLineColor());
83         g.drawLine(0, y + 1, displayer.getWidth(), y + 1);
84         
85         //Draw the white highlight under all tabs but the selected one:
86

87         //Check if we will need to draw a white line from the left edge to the
88
//selection, and another from the left edge of the selection to the
89
//end of the control, skipping the selection area. If the selection is
90
//visible we should skip it.
91
int tabsWidth = getTabsAreaWidth();
92         boolean needSplitLine = i != -1 && ((i
93                 < scroll().getLastVisibleTab(tabsWidth) || i
94                 <= scroll().getLastVisibleTab(tabsWidth)
95                 && !scroll().isLastTabClipped())
96                 && i >= scroll().getFirstVisibleTab(tabsWidth));
97
98         g.setColor(UIManager.getColor("controlLtHighlight"));
99         if (needSplitLine) {
100             //Find the rectangle of the selection to skip it
101
getTabRect(i, scratch5);
102             //Make sure it's not offscreen
103
if (scratch5.width != 0) {
104                 //draw the first part of the line
105
if (r.x < scratch5.x) {
106                     g.drawLine(r.x, y, scratch5.x + 1, y);
107                 }
108                 //Now draw the second part out to the right edge
109
if (scratch5.x + scratch5.width < r.x + r.width) {
110                     //Find the right edge of the selected tab rectangle
111
selEnd = scratch5.x + scratch5.width;
112                     //If the last tab is not clipped, the final tab is one
113
//pixel smaller; we need to overwrite one pixel of the
114
//border or there will be a small stub sticking down
115
if (!scroll().isLastTabClipped()) {
116                         selEnd--;
117                     }
118                     //Really draw the second part, now that we know where to
119
//start
120
g.drawLine(selEnd, y, r.x + r.width, y);
121                 }
122             }
123         } else {
124             //The selection is not visible - draw the white highlight line
125
//across the entire width of the container
126
g.drawLine(r.x, y, r.x + r.width, y);
127         }
128
129         //Draw the left and right edges so the area below the tabs looks
130
//closed
131
g.setColor(WinXPEditorTabCellRenderer.getBorderColor());
132         g.drawLine(0, y - 1, 0, displayer.getHeight());
133         g.drawLine(displayer.getWidth() - 1, y - 1, displayer.getWidth() - 1,
134                    displayer.getHeight());
135         
136         //Draw a line tracking the bottom of the tabs under the control
137
//buttons, out to the right edge of the control
138

139         //Find the last visible tab
140
int last = scroll().getLastVisibleTab(tabsWidth);
141         int l = 0;
142         if (last >= 0) {
143             //If it's onscreen (usually will be unless there are no tabs,
144
//find the edge of the last tab - it may be scrolled)
145
getTabRect(last, scratch5);
146             last = scratch5.x + scratch5.width;
147         }
148         //Draw the dark line under the controls button area that closes the
149
//tabs bottom margin on top
150
g.drawLine(last, y - 1, displayer.getWidth(), y - 1);
151     }
152
153     protected TabCellRenderer createDefaultRenderer() {
154         return new WinXPEditorTabCellRenderer();
155     }
156
157     private static void initIcons() {
158         if( null == buttonIconPaths ) {
159             buttonIconPaths = new HashMap JavaDoc<Integer JavaDoc, String JavaDoc[]>(7);
160             
161             //left button
162
String JavaDoc[] iconPaths = new String JavaDoc[4];
163             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/xp_scrollleft_enabled.png"; // NOI18N
164
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/xp_scrollleft_disabled.png"; // NOI18N
165
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/xp_scrollleft_rollover.png"; // NOI18N
166
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/xp_scrollleft_pressed.png"; // NOI18N
167
buttonIconPaths.put( TabControlButton.ID_SCROLL_LEFT_BUTTON, iconPaths );
168             
169             //right button
170
iconPaths = new String JavaDoc[4];
171             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/xp_scrollright_enabled.png"; // NOI18N
172
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/xp_scrollright_disabled.png"; // NOI18N
173
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/xp_scrollright_rollover.png"; // NOI18N
174
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/xp_scrollright_pressed.png"; // NOI18N
175
buttonIconPaths.put( TabControlButton.ID_SCROLL_RIGHT_BUTTON, iconPaths );
176             
177             //drop down button
178
iconPaths = new String JavaDoc[4];
179             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/xp_popup_enabled.png"; // NOI18N
180
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/xp_popup_disabled.png"; // NOI18N
181
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/xp_popup_rollover.png"; // NOI18N
182
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/xp_popup_pressed.png"; // NOI18N
183
buttonIconPaths.put( TabControlButton.ID_DROP_DOWN_BUTTON, iconPaths );
184             
185             //maximize/restore button
186
iconPaths = new String JavaDoc[4];
187             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/xp_maximize_enabled.png"; // NOI18N
188
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/xp_maximize_disabled.png"; // NOI18N
189
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/xp_maximize_rollover.png"; // NOI18N
190
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/xp_maximize_pressed.png"; // NOI18N
191
buttonIconPaths.put( TabControlButton.ID_MAXIMIZE_BUTTON, iconPaths );
192             
193             iconPaths = new String JavaDoc[4];
194             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/xp_restore_enabled.png"; // NOI18N
195
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/xp_restore_disabled.png"; // NOI18N
196
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/xp_restore_rollover.png"; // NOI18N
197
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/xp_restore_pressed.png"; // NOI18N
198
buttonIconPaths.put( TabControlButton.ID_RESTORE_BUTTON, iconPaths );
199         }
200     }
201
202     public Icon JavaDoc getButtonIcon(int buttonId, int buttonState) {
203         Icon JavaDoc res = null;
204         initIcons();
205         String JavaDoc[] paths = buttonIconPaths.get( buttonId );
206         if( null != paths && buttonState >=0 && buttonState < paths.length ) {
207             res = TabControlButtonFactory.getIcon( paths[buttonState] );
208         }
209         return res;
210     }
211 }
212
Popular Tags