KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.HashMap JavaDoc;
28 import java.util.Map JavaDoc;
29 import javax.swing.Icon JavaDoc;
30 import javax.swing.JComponent JavaDoc;
31 import org.netbeans.swing.tabcontrol.TabDisplayer;
32
33 import javax.swing.plaf.ComponentUI JavaDoc;
34
35 /**
36  * Windows Vista impl of tabs ui
37  *
38  * @author S. Aubrecht
39  */

40 public final class WinVistaEditorTabDisplayerUI extends BasicScrollingTabDisplayerUI {
41     
42     private static final Rectangle JavaDoc scratch5 = new Rectangle JavaDoc();
43     private static Map JavaDoc<Integer JavaDoc, String JavaDoc[]> buttonIconPaths;
44
45     public WinVistaEditorTabDisplayerUI(TabDisplayer displayer) {
46         super (displayer);
47     }
48
49     public static ComponentUI JavaDoc createUI(JComponent JavaDoc c) {
50         return new WinVistaEditorTabDisplayerUI ((TabDisplayer) c);
51     }
52
53     public Dimension JavaDoc getPreferredSize(JComponent JavaDoc c) {
54         int prefHeight = 22;
55         Graphics JavaDoc g = BasicScrollingTabDisplayerUI.getOffscreenGraphics();
56         if (g != null) {
57             FontMetrics JavaDoc fm = g.getFontMetrics(displayer.getFont());
58             Insets JavaDoc ins = getTabAreaInsets();
59             prefHeight = fm.getHeight() + ins.top + ins.bottom + 6;
60         }
61         return new Dimension JavaDoc(displayer.getWidth(), prefHeight);
62     }
63     
64     public void paintBackground (Graphics JavaDoc g) {
65         g.setColor (displayer.getBackground());
66         g.fillRect (0, 0, displayer.getWidth(), displayer.getHeight());
67     }
68
69     protected void paintAfterTabs(Graphics JavaDoc g) {
70         Rectangle JavaDoc r = new Rectangle JavaDoc();
71         getTabsVisibleArea(r);
72         r.width = displayer.getWidth();
73
74         Insets JavaDoc ins = getTabAreaInsets();
75
76         int y = displayer.getHeight() - WinVistaEditorTabCellRenderer.BOTTOM_INSET;
77         int tabsWidth = getTabsAreaWidth();
78
79         g.setColor(WinVistaEditorTabCellRenderer.getBorderColor());
80         
81         //Draw a line tracking the bottom of the tabs under the control
82
//buttons, out to the right edge of the control
83

84         //Find the last visible tab
85
int last = scroll().getLastVisibleTab(tabsWidth);
86         int l = 0;
87         if (last >= 0) {
88             //If it's onscreen (usually will be unless there are no tabs,
89
//find the edge of the last tab - it may be scrolled)
90
getTabRect(last, scratch5);
91             last = scratch5.x + scratch5.width;
92         }
93         //Draw the dark line under the controls button area that closes the
94
//tabs bottom margin on top
95
g.drawLine(last, y - 1, displayer.getWidth(), y - 1);
96     }
97
98     protected TabCellRenderer createDefaultRenderer() {
99         return new WinVistaEditorTabCellRenderer();
100     }
101     
102     protected Rectangle JavaDoc getTabRectForRepaint( int tab, Rectangle JavaDoc rect ) {
103         Rectangle JavaDoc res = super.getTabRectForRepaint( tab, rect );
104         //we need to repaint extra vertical lines on both sides when mouse-over
105
//or selection changes
106
res.x--;
107         res.width += 2;
108         return res;
109     }
110
111     private static void initIcons() {
112         if( null == buttonIconPaths ) {
113             buttonIconPaths = new HashMap JavaDoc<Integer JavaDoc, String JavaDoc[]>(7);
114             
115             //left button
116
String JavaDoc[] iconPaths = new String JavaDoc[4];
117             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/vista_scrollleft_enabled.png"; // NOI18N
118
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/vista_scrollleft_disabled.png"; // NOI18N
119
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/vista_scrollleft_rollover.png"; // NOI18N
120
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/vista_scrollleft_pressed.png"; // NOI18N
121
buttonIconPaths.put( TabControlButton.ID_SCROLL_LEFT_BUTTON, iconPaths );
122             
123             //right button
124
iconPaths = new String JavaDoc[4];
125             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/vista_scrollright_enabled.png"; // NOI18N
126
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/vista_scrollright_disabled.png"; // NOI18N
127
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/vista_scrollright_rollover.png"; // NOI18N
128
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/vista_scrollright_pressed.png"; // NOI18N
129
buttonIconPaths.put( TabControlButton.ID_SCROLL_RIGHT_BUTTON, iconPaths );
130             
131             //drop down button
132
iconPaths = new String JavaDoc[4];
133             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/vista_popup_enabled.png"; // NOI18N
134
iconPaths[TabControlButton.STATE_DISABLED] = iconPaths[TabControlButton.STATE_DEFAULT];
135             iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/vista_popup_rollover.png"; // NOI18N
136
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/vista_popup_pressed.png"; // NOI18N
137
buttonIconPaths.put( TabControlButton.ID_DROP_DOWN_BUTTON, iconPaths );
138             
139             //maximize/restore button
140
iconPaths = new String JavaDoc[4];
141             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/vista_maximize_enabled.png"; // NOI18N
142
iconPaths[TabControlButton.STATE_DISABLED] = iconPaths[TabControlButton.STATE_DEFAULT];
143             iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/vista_maximize_rollover.png"; // NOI18N
144
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/vista_maximize_pressed.png"; // NOI18N
145
buttonIconPaths.put( TabControlButton.ID_MAXIMIZE_BUTTON, iconPaths );
146             
147             iconPaths = new String JavaDoc[4];
148             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/vista_restore_enabled.png"; // NOI18N
149
iconPaths[TabControlButton.STATE_DISABLED] = iconPaths[TabControlButton.STATE_DEFAULT];
150             iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/vista_restore_rollover.png"; // NOI18N
151
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/vista_restore_pressed.png"; // NOI18N
152
buttonIconPaths.put( TabControlButton.ID_RESTORE_BUTTON, iconPaths );
153         }
154     }
155
156     public Icon JavaDoc getButtonIcon(int buttonId, int buttonState) {
157         Icon JavaDoc res = null;
158         initIcons();
159         String JavaDoc[] paths = buttonIconPaths.get( buttonId );
160         if( null != paths && buttonState >=0 && buttonState < paths.length ) {
161             res = TabControlButtonFactory.getIcon( paths[buttonState] );
162         }
163         return res;
164     }
165 }
166
Popular Tags