KickJava   Java API By Example, From Geeks To Geeks.

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


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.Component JavaDoc;
28 import java.awt.Container JavaDoc;
29 import java.awt.Dimension JavaDoc;
30 import java.awt.FontMetrics JavaDoc;
31 import java.awt.Graphics JavaDoc;
32 import java.awt.Insets JavaDoc;
33 import java.awt.Rectangle JavaDoc;
34 import java.util.HashMap JavaDoc;
35 import java.util.Map JavaDoc;
36 import javax.swing.Icon JavaDoc;
37 import javax.swing.JComponent JavaDoc;
38 import javax.swing.UIManager JavaDoc;
39 import org.netbeans.swing.tabcontrol.TabDisplayer;
40 import javax.swing.plaf.ComponentUI JavaDoc;
41
42 /**
43  * Tab displayer UI for Metal look and feel
44  *
45  * @author Tim Boudreau
46  */

47 public final class MetalEditorTabDisplayerUI extends BasicScrollingTabDisplayerUI {
48     
49     private Rectangle JavaDoc scratch = new Rectangle JavaDoc();
50     private static Map JavaDoc<Integer JavaDoc, String JavaDoc[]> buttonIconPaths;
51
52     /**
53      * Creates a new instance of MetalEditorTabDisplayerUI
54      */

55     public MetalEditorTabDisplayerUI(TabDisplayer displayer) {
56         super(displayer);
57     }
58
59     protected TabCellRenderer createDefaultRenderer() {
60         return new MetalEditorTabCellRenderer();
61     }
62
63     public static ComponentUI JavaDoc createUI(JComponent JavaDoc c) {
64         return new MetalEditorTabDisplayerUI((TabDisplayer) c);
65     }
66
67     public Dimension JavaDoc getMinimumSize(JComponent JavaDoc c) {
68         return new Dimension JavaDoc (80, 28);
69     }
70     
71     public Dimension JavaDoc getPreferredSize(JComponent JavaDoc c) {
72         int prefHeight = 28;
73         Graphics JavaDoc g = BasicScrollingTabDisplayerUI.getOffscreenGraphics();
74         if (g != null) {
75             FontMetrics JavaDoc fm = g.getFontMetrics(displayer.getFont());
76             Insets JavaDoc ins = getTabAreaInsets();
77             prefHeight = fm.getHeight() + ins.top + ins.bottom + 9;
78         }
79         return new Dimension JavaDoc(displayer.getWidth(), prefHeight);
80     }
81
82     protected int createRepaintPolicy () {
83         return TabState.REPAINT_ALL_TABS_ON_ACTIVATION_CHANGE
84                 | TabState.REPAINT_ALL_TABS_ON_SELECTION_CHANGE
85                 | TabState.REPAINT_ON_MOUSE_PRESSED
86                 | TabState.REPAINT_ON_CLOSE_BUTTON_PRESSED
87                 | TabState.REPAINT_ON_MOUSE_ENTER_CLOSE_BUTTON;
88     }
89
90
91     public Insets JavaDoc getTabAreaInsets() {
92         Insets JavaDoc results = super.getTabAreaInsets();
93         results.bottom += 4;
94         results.right += 3;
95         return results;
96     }
97
98     public void install() {
99         super.install();
100         displayer.setBackground(UIManager.getColor("control")); //NOI18N
101
}
102
103     protected void paintAfterTabs(Graphics JavaDoc g) {
104         Rectangle JavaDoc r = new Rectangle JavaDoc();
105         getTabsVisibleArea(r);
106         r.width = displayer.getWidth();
107         g.setColor(displayer.isActive() ?
108                    defaultRenderer.getSelectedActivatedBackground() :
109                    defaultRenderer.getSelectedBackground());
110
111         Insets JavaDoc ins = getTabAreaInsets();
112         g.fillRect(r.x, r.y + r.height, r.x + r.width,
113                    displayer.getHeight() - (r.y + r.height));
114
115         g.setColor(UIManager.getColor("controlHighlight")); //NOI18N
116

117         int selEnd = 0;
118         int i = selectionModel.getSelectedIndex();
119         if (i != -1) {
120             getTabRect(i, scratch);
121             if (scratch.width != 0) {
122                 if (r.x < scratch.x) {
123                     g.drawLine(r.x, displayer.getHeight() - ins.bottom,
124                                scratch.x - 1,
125                                displayer.getHeight() - ins.bottom);
126                 }
127                 if (scratch.x + scratch.width < r.x + r.width) {
128                     selEnd = scratch.x + scratch.width;
129                     g.drawLine(selEnd, displayer.getHeight() - ins.bottom,
130                                r.x + r.width,
131                                displayer.getHeight() - ins.bottom);
132                 }
133             } else {
134                 //The selected tab is scrolled offscreen
135
g.drawLine (0, displayer.getHeight() - ins.bottom,
136                         displayer.getWidth(), displayer.getHeight() - ins.bottom);
137             }
138             g.setColor(UIManager.getColor("controlDkShadow")); //NOI18N
139
g.drawLine(selEnd, displayer.getHeight() - 5, displayer.getWidth(),
140                        displayer.getHeight() - 5);
141             return;
142         }
143
144         g.drawLine(r.x, displayer.getHeight() - ins.bottom, r.x + r.width,
145                    displayer.getHeight() - ins.bottom);
146
147         g.setColor(UIManager.getColor("controlDkShadow")); //NOI18N
148
g.drawLine(0, displayer.getHeight() - 5, displayer.getWidth(),
149                    displayer.getHeight() - 5);
150     }
151
152     private static void initIcons() {
153         if( null == buttonIconPaths ) {
154             buttonIconPaths = new HashMap JavaDoc<Integer JavaDoc, String JavaDoc[]>(7);
155             
156             //left button
157
String JavaDoc[] iconPaths = new String JavaDoc[4];
158             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/metal_scrollleft_enabled.png"; // NOI18N
159
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/metal_scrollleft_disabled.png"; // NOI18N
160
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/metal_scrollleft_rollover.png"; // NOI18N
161
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/metal_scrollleft_pressed.png"; // NOI18N
162
buttonIconPaths.put( TabControlButton.ID_SCROLL_LEFT_BUTTON, iconPaths );
163             
164             //right button
165
iconPaths = new String JavaDoc[4];
166             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/metal_scrollright_enabled.png"; // NOI18N
167
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/metal_scrollright_disabled.png"; // NOI18N
168
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/metal_scrollright_rollover.png"; // NOI18N
169
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/metal_scrollright_pressed.png"; // NOI18N
170
buttonIconPaths.put( TabControlButton.ID_SCROLL_RIGHT_BUTTON, iconPaths );
171             
172             //drop down button
173
iconPaths = new String JavaDoc[4];
174             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/metal_popup_enabled.png"; // NOI18N
175
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/metal_popup_disabled.png"; // NOI18N
176
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/metal_popup_rollover.png"; // NOI18N
177
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/metal_popup_pressed.png"; // NOI18N
178
buttonIconPaths.put( TabControlButton.ID_DROP_DOWN_BUTTON, iconPaths );
179             
180             //maximize/restore button
181
iconPaths = new String JavaDoc[4];
182             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/metal_maximize_enabled.png"; // NOI18N
183
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/metal_maximize_disabled.png"; // NOI18N
184
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/metal_maximize_rollover.png"; // NOI18N
185
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/metal_maximize_pressed.png"; // NOI18N
186
buttonIconPaths.put( TabControlButton.ID_MAXIMIZE_BUTTON, iconPaths );
187             
188             iconPaths = new String JavaDoc[4];
189             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/metal_restore_enabled.png"; // NOI18N
190
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/metal_restore_disabled.png"; // NOI18N
191
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/metal_restore_rollover.png"; // NOI18N
192
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/metal_restore_pressed.png"; // NOI18N
193
buttonIconPaths.put( TabControlButton.ID_RESTORE_BUTTON, iconPaths );
194         }
195     }
196
197     public Icon JavaDoc getButtonIcon(int buttonId, int buttonState) {
198         Icon JavaDoc res = null;
199         initIcons();
200         String JavaDoc[] paths = buttonIconPaths.get( buttonId );
201         if( null != paths && buttonState >=0 && buttonState < paths.length ) {
202             res = TabControlButtonFactory.getIcon( paths[buttonState] );
203         }
204         return res;
205     }
206     
207     protected Rectangle JavaDoc getControlButtonsRectangle( Container JavaDoc parent ) {
208         Component JavaDoc c = getControlButtons();
209         return new Rectangle JavaDoc( parent.getWidth()-c.getWidth()-3, 3, c.getWidth(), c.getHeight() );
210     }
211 }
212
Popular Tags