KickJava   Java API By Example, From Geeks To Geeks.

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


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  * MetalEditorTabDisplayerUI.java
21  *
22  * Created on December 2, 2003, 9:40 PM
23  */

24
25 package org.netbeans.swing.tabcontrol.plaf;
26
27 import java.awt.Color JavaDoc;
28 import java.awt.Container JavaDoc;
29 import java.awt.Dimension JavaDoc;
30 import java.awt.Font JavaDoc;
31 import java.awt.FontMetrics JavaDoc;
32 import java.awt.Graphics JavaDoc;
33 import java.awt.Insets JavaDoc;
34 import java.awt.Rectangle JavaDoc;
35 import org.netbeans.swing.tabcontrol.TabDisplayer;
36 import javax.swing.plaf.ComponentUI JavaDoc;
37 import java.util.HashMap JavaDoc;
38 import java.util.Map JavaDoc;
39 import javax.swing.Icon JavaDoc;
40 import javax.swing.JComponent JavaDoc;
41 import javax.swing.UIManager JavaDoc;
42
43 /**
44  * A provisional look and feel for OS-X, round 2, using Java2d to emulate the
45  * aqua look.
46  *
47  * @author Tim Boudreau
48  */

49 public class AquaEditorTabDisplayerUI extends BasicScrollingTabDisplayerUI {
50
51     /** Color used in drawing the line behind the tabs */
52     private Color JavaDoc lineMiddleColor = null;
53     /** Color used in drawing the line behind the tabs */
54     private Color JavaDoc lineHlColor = null;
55
56     private static Map JavaDoc<Integer JavaDoc, String JavaDoc[]> buttonIconPaths;
57
58     public AquaEditorTabDisplayerUI (TabDisplayer displayer) {
59         super (displayer);
60     }
61
62     public void install() {
63         super.install();
64         scroll().setMinimumXposition(9);
65     }
66
67     protected TabCellRenderer createDefaultRenderer() {
68         return new AquaEditorTabCellRenderer();
69     }
70
71     public Insets JavaDoc getTabAreaInsets() {
72         Insets JavaDoc result = super.getTabAreaInsets();
73         result.bottom = 2;
74         return result;
75     }
76     
77     public static ComponentUI JavaDoc createUI(JComponent JavaDoc c) {
78         return new AquaEditorTabDisplayerUI ((TabDisplayer) c);
79     }
80
81     protected boolean isAntialiased() {
82         return true;
83     }
84     
85     protected Font JavaDoc createFont() {
86         return UIManager.getFont("Label.font"); //NOI18N
87
}
88     
89     protected int createRepaintPolicy () {
90         return TabState.REPAINT_SELECTION_ON_ACTIVATION_CHANGE
91                 | TabState.REPAINT_ON_SELECTION_CHANGE
92                 | TabState.REPAINT_ALL_ON_MOUSE_ENTER_TABS_AREA
93                 | TabState.REPAINT_ON_MOUSE_ENTER_CLOSE_BUTTON
94                 | TabState.REPAINT_ON_CLOSE_BUTTON_PRESSED
95                 | TabState.REPAINT_ON_MOUSE_PRESSED;
96     }
97     
98     public Dimension JavaDoc getPreferredSize(JComponent JavaDoc c) {
99         int prefHeight = 28;
100         //Never call getGraphics() on the control, it resets in-process
101
//painting on OS-X 1.4.1 and triggers gratuitous repaints
102
Graphics JavaDoc g = BasicScrollingTabDisplayerUI.getOffscreenGraphics();
103         if (g != null) {
104             FontMetrics JavaDoc fm = g.getFontMetrics(displayer.getFont());
105             Insets JavaDoc ins = getTabAreaInsets();
106             prefHeight = fm.getHeight() + ins.top + ins.bottom + 7;
107         }
108         if (prefHeight % 2 == 0) {
109             prefHeight += 1;
110         }
111         return new Dimension JavaDoc(displayer.getWidth(), prefHeight);
112     }
113
114     protected void paintAfterTabs(Graphics JavaDoc g) {
115         //Draw the continuation of the rounded border behind the buttons
116
//and tabs
117

118         int centerY = (((displayer.getHeight() -
119             (AquaEditorTabCellRenderer.TOP_INSET + AquaEditorTabCellRenderer.BOTTOM_INSET)) / 2)
120             + AquaEditorTabCellRenderer.TOP_INSET - 1) + getTabAreaInsets().top + 1;
121         
122         if (lineMiddleColor == null) {
123             lineMiddleColor = ColorUtil.getMiddle(UIManager.getColor("controlShadow"),
124             UIManager.getColor("control")); //NOI18N
125
}
126         g.setColor (lineMiddleColor);
127         
128         int rightLineStart = getTabsAreaWidth() - 13;
129         int rightLineEnd = displayer.getWidth() - 9;
130         
131         if (displayer.getModel().size() > 0 && !scroll().isLastTabClipped()) {
132             //Extend the line out to the edge of the last visible tab
133
//if none are clipped
134
int idx = scroll().getLastVisibleTab(displayer.getWidth());
135             rightLineStart = scroll().getX(idx) + scroll().getW(idx);
136         } else if (displayer.getModel().size() == 0) {
137             rightLineStart = 6;
138         }
139         
140         if (scroll().getOffset() >= 0) {
141             //fill the left edge notch
142
g.drawLine(6, centerY, 11, centerY);
143         }
144         g.drawLine(rightLineStart, centerY, rightLineEnd, centerY);
145         
146         if (lineHlColor == null) {
147             lineHlColor = ColorUtil.getMiddle (lineMiddleColor,
148             UIManager.getColor("control"));
149         }
150         
151         g.setColor (lineHlColor); //NOI18N
152
g.drawLine(rightLineStart, centerY+1, rightLineEnd, centerY+1);
153         if (scroll().getOffset() > 0) {
154             //fill the left edge notch
155
g.drawLine(6, centerY+1, 11, centerY+1);
156         }
157     }
158     
159
160     private static void initIcons() {
161         if( null == buttonIconPaths ) {
162             buttonIconPaths = new HashMap JavaDoc<Integer JavaDoc, String JavaDoc[]>(7);
163             
164             //left button
165
String JavaDoc[] iconPaths = new String JavaDoc[4];
166             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_scrollleft_enabled.png"; // NOI18N
167
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_scrollleft_disabled.png"; // NOI18N
168
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_scrollleft_rollover.png"; // NOI18N
169
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_scrollleft_pressed.png"; // NOI18N
170
buttonIconPaths.put( TabControlButton.ID_SCROLL_LEFT_BUTTON, iconPaths );
171             
172             //right button
173
iconPaths = new String JavaDoc[4];
174             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_scrollright_enabled.png"; // NOI18N
175
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_scrollright_disabled.png"; // NOI18N
176
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_scrollright_rollover.png"; // NOI18N
177
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_scrollright_pressed.png"; // NOI18N
178
buttonIconPaths.put( TabControlButton.ID_SCROLL_RIGHT_BUTTON, iconPaths );
179             
180             //drop down button
181
iconPaths = new String JavaDoc[4];
182             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_popup_enabled.png"; // NOI18N
183
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_popup_disabled.png"; // NOI18N
184
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_popup_rollover.png"; // NOI18N
185
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_popup_pressed.png"; // NOI18N
186
buttonIconPaths.put( TabControlButton.ID_DROP_DOWN_BUTTON, iconPaths );
187             
188             //maximize/restore button
189
iconPaths = new String JavaDoc[4];
190             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_maximize_enabled.png"; // NOI18N
191
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_maximize_disabled.png"; // NOI18N
192
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_maximize_rollover.png"; // NOI18N
193
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_maximize_pressed.png"; // NOI18N
194
buttonIconPaths.put( TabControlButton.ID_MAXIMIZE_BUTTON, iconPaths );
195             
196             iconPaths = new String JavaDoc[4];
197             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_restore_enabled.png"; // NOI18N
198
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_restore_disabled.png"; // NOI18N
199
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_restore_rollover.png"; // NOI18N
200
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_restore_pressed.png"; // NOI18N
201
buttonIconPaths.put( TabControlButton.ID_RESTORE_BUTTON, iconPaths );
202         }
203     }
204
205     public Icon JavaDoc getButtonIcon(int buttonId, int buttonState) {
206         Icon JavaDoc res = null;
207         initIcons();
208         String JavaDoc[] paths = buttonIconPaths.get( buttonId );
209         if( null != paths && buttonState >=0 && buttonState < paths.length ) {
210             res = TabControlButtonFactory.getIcon( paths[buttonState] );
211         }
212         return res;
213     }
214
215     protected Rectangle JavaDoc getControlButtonsRectangle(Container JavaDoc parent) {
216         int centerY = (((displayer.getHeight() - (AquaEditorTabCellRenderer.TOP_INSET
217                 + AquaEditorTabCellRenderer.BOTTOM_INSET)) / 2) + AquaEditorTabCellRenderer.TOP_INSET)
218                 + getTabAreaInsets().top;
219         
220         int width = parent.getWidth();
221         int height = parent.getHeight();
222         int buttonsWidth = getControlButtons().getWidth();
223         int buttonsHeight = getControlButtons().getHeight();
224         return new Rectangle JavaDoc( width-buttonsWidth-3, centerY-buttonsHeight/2, buttonsWidth, buttonsHeight );
225     }
226 }
227
Popular Tags