KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > java > swing > plaf > motif > MotifTabbedPaneUI


1 /*
2  * @(#)MotifTabbedPaneUI.java 1.49 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.java.swing.plaf.motif;
9
10 import java.awt.*;
11 import java.awt.event.*;
12 import javax.swing.*;
13 import javax.swing.event.*;
14 import javax.swing.plaf.*;
15 import javax.swing.plaf.basic.BasicTabbedPaneUI JavaDoc;
16 import java.io.Serializable JavaDoc;
17
18 /**
19  * A Motif L&F implementation of TabbedPaneUI.
20  * <p>
21  * <strong>Warning:</strong>
22  * Serialized objects of this class will not be compatible with
23  * future Swing releases. The current serialization support is appropriate
24  * for short term storage or RMI between applications running the same
25  * version of Swing. A future release of Swing will provide support for
26  * long term persistence.
27  *
28  * @version 1.49 12/19/03
29  * @author Amy Fowler
30  * @author Philip Milne
31  */

32 public class MotifTabbedPaneUI extends BasicTabbedPaneUI JavaDoc
33 {
34
35 // Instance variables initialized at installation
36

37     protected Color unselectedTabBackground;
38     protected Color unselectedTabForeground;
39     protected Color unselectedTabShadow;
40     protected Color unselectedTabHighlight;
41
42
43 // UI creation
44

45     public static ComponentUI createUI(JComponent tabbedPane) {
46         return new MotifTabbedPaneUI();
47     }
48
49
50 // UI Installation/De-installation
51

52
53     protected void installDefaults() {
54         super.installDefaults();
55
56         unselectedTabBackground = UIManager.getColor("TabbedPane.unselectedTabBackground");
57         unselectedTabForeground = UIManager.getColor("TabbedPane.unselectedTabForeground");
58         unselectedTabShadow = UIManager.getColor("TabbedPane.unselectedTabShadow");
59         unselectedTabHighlight = UIManager.getColor("TabbedPane.unselectedTabHighlight");
60     }
61
62     protected void uninstallDefaults() {
63         super.uninstallDefaults();
64
65         unselectedTabBackground = null;
66         unselectedTabForeground = null;
67         unselectedTabShadow = null;
68         unselectedTabHighlight = null;
69     }
70
71 // UI Rendering
72

73    protected void paintContentBorderTopEdge(Graphics g, int tabPlacement,
74                                             int selectedIndex,
75                                             int x, int y, int w, int h) {
76         Rectangle selRect = selectedIndex < 0? null :
77                            getTabBounds(selectedIndex, calcRect);
78         g.setColor(lightHighlight);
79
80     // Draw unbroken line if tabs are not on TOP, OR
81
// selected tab is not visible (SCROLL_TAB_LAYOUT)
82
//
83
if (tabPlacement != TOP || selectedIndex < 0 ||
84         (selRect.x < x || selRect.x > x + w)) {
85             g.drawLine(x, y, x+w-2, y);
86         } else {
87         // Break line to show visual connection to selected tab
88
g.drawLine(x, y, selRect.x - 1, y);
89             if (selRect.x + selRect.width < x + w - 2) {
90                 g.drawLine(selRect.x + selRect.width, y,
91                            x+w-2, y);
92             }
93         }
94     }
95
96     protected void paintContentBorderBottomEdge(Graphics g, int tabPlacement,
97                                                int selectedIndex,
98                                                int x, int y, int w, int h) {
99         Rectangle selRect = selectedIndex < 0? null :
100                            getTabBounds(selectedIndex, calcRect);
101         g.setColor(shadow);
102
103     // Draw unbroken line if tabs are not on BOTTOM, OR
104
// selected tab is not visible (SCROLL_TAB_LAYOUT)
105
//
106
if (tabPlacement != BOTTOM || selectedIndex < 0 ||
107          (selRect.x < x || selRect.x > x + w)) {
108             g.drawLine(x+1, y+h-1, x+w-1, y+h-1);
109         } else {
110         // Break line to show visual connection to selected tab
111
g.drawLine(x+1, y+h-1, selRect.x - 1, y+h-1);
112             if (selRect.x + selRect.width < x + w - 2) {
113                 g.drawLine(selRect.x + selRect.width, y+h-1, x+w-2, y+h-1);
114             }
115         }
116     }
117
118     protected void paintContentBorderRightEdge(Graphics g, int tabPlacement,
119                                                int selectedIndex,
120                                                int x, int y, int w, int h) {
121         Rectangle selRect = selectedIndex < 0? null :
122                            getTabBounds(selectedIndex, calcRect);
123         g.setColor(shadow);
124     // Draw unbroken line if tabs are not on RIGHT, OR
125
// selected tab is not visible (SCROLL_TAB_LAYOUT)
126
//
127
if (tabPlacement != RIGHT || selectedIndex < 0 ||
128          (selRect.y < y || selRect.y > y + h)) {
129             g.drawLine(x+w-1, y+1, x+w-1, y+h-1);
130         } else {
131         // Break line to show visual connection to selected tab
132
g.drawLine(x+w-1, y+1, x+w-1, selRect.y - 1);
133             if (selRect.y + selRect.height < y + h - 2 ) {
134                 g.drawLine(x+w-1, selRect.y + selRect.height,
135                            x+w-1, y+h-2);
136             }
137         }
138     }
139
140     protected void paintTabBackground(Graphics g,
141                                       int tabPlacement, int tabIndex,
142                                       int x, int y, int w, int h,
143                       boolean isSelected ) {
144         g.setColor(isSelected? tabPane.getBackgroundAt(tabIndex) : unselectedTabBackground);
145         switch(tabPlacement) {
146           case LEFT:
147               g.fillRect(x+1, y+1, w-1, h-2);
148               break;
149           case RIGHT:
150               g.fillRect(x, y+1, w-1, h-2);
151               break;
152           case BOTTOM:
153               g.fillRect(x+1, y, w-2, h-3);
154               g.drawLine(x+2, y+h-3, x+w-3, y+h-3);
155               g.drawLine(x+3, y+h-2, x+w-4, y+h-2);
156               break;
157           case TOP:
158           default:
159               g.fillRect(x+1, y+3, w-2, h-3);
160               g.drawLine(x+2, y+2, x+w-3, y+2);
161               g.drawLine(x+3, y+1, x+w-4, y+1);
162         }
163
164     }
165
166     protected void paintTabBorder(Graphics g,
167                                   int tabPlacement, int tabIndex,
168                                   int x, int y, int w, int h,
169                   boolean isSelected) {
170         g.setColor(isSelected? lightHighlight : unselectedTabHighlight);
171
172         switch(tabPlacement) {
173           case LEFT:
174               g.drawLine(x, y+2, x, y+h-3);
175               g.drawLine(x+1, y+1, x+1, y+2);
176               g.drawLine(x+2, y, x+2, y+1);
177               g.drawLine(x+3, y, x+w-1, y);
178               g.setColor(isSelected? shadow : unselectedTabShadow);
179               g.drawLine(x+1, y+h-3, x+1, y+h-2);
180               g.drawLine(x+2, y+h-2, x+2, y+h-1);
181               g.drawLine(x+3, y+h-1, x+w-1, y+h-1);
182               break;
183           case RIGHT:
184               g.drawLine(x, y, x+w-3, y);
185               g.setColor(isSelected? shadow : unselectedTabShadow);
186               g.drawLine(x+w-3, y, x+w-3, y+1);
187               g.drawLine(x+w-2, y+1, x+w-2, y+2);
188               g.drawLine(x+w-1, y+2, x+w-1, y+h-3);
189               g.drawLine(x+w-2, y+h-3, x+w-2, y+h-2);
190               g.drawLine(x+w-3, y+h-2, x+w-3, y+h-1);
191               g.drawLine(x, y+h-1, x+w-3, y+h-1);
192               break;
193           case BOTTOM:
194               g.drawLine(x, y, x, y+h-3);
195               g.drawLine(x+1, y+h-3, x+1, y+h-2);
196               g.drawLine(x+2, y+h-2, x+2, y+h-1);
197               g.setColor(isSelected? shadow : unselectedTabShadow);
198               g.drawLine(x+3, y+h-1, x+w-4, y+h-1);
199               g.drawLine(x+w-3, y+h-2, x+w-3, y+h-1);
200               g.drawLine(x+w-2, y+h-3, x+w-2, y+h-2);
201               g.drawLine(x+w-1, y, x+w-1, y+h-3);
202               break;
203           case TOP:
204           default:
205               g.drawLine(x, y+2, x, y+h-1);
206               g.drawLine(x+1, y+1, x+1, y+2);
207               g.drawLine(x+2, y, x+2, y+1);
208               g.drawLine(x+3, y, x+w-4, y);
209               g.setColor(isSelected? shadow : unselectedTabShadow);
210               g.drawLine(x+w-3, y, x+w-3, y+1);
211               g.drawLine(x+w-2, y+1, x+w-2, y+2);
212               g.drawLine(x+w-1, y+2, x+w-1, y+h-1);
213         }
214
215     }
216
217     protected void paintFocusIndicator(Graphics g, int tabPlacement,
218                                        Rectangle[] rects, int tabIndex,
219                                        Rectangle iconRect, Rectangle textRect,
220                                        boolean isSelected) {
221         Rectangle tabRect = rects[tabIndex];
222         if (tabPane.hasFocus() && isSelected) {
223             int x, y, w, h;
224         g.setColor(focus);
225             switch(tabPlacement) {
226               case LEFT:
227                   x = tabRect.x + 3;
228                   y = tabRect.y + 3;
229                   w = tabRect.width - 6;
230                   h = tabRect.height - 7;
231                   break;
232               case RIGHT:
233                   x = tabRect.x + 2;
234                   y = tabRect.y + 3;
235                   w = tabRect.width - 6;
236                   h = tabRect.height - 7;
237                   break;
238               case BOTTOM:
239                   x = tabRect.x + 3;
240                   y = tabRect.y + 2;
241                   w = tabRect.width - 7;
242                   h = tabRect.height - 6;
243                   break;
244               case TOP:
245               default:
246                   x = tabRect.x + 3;
247                   y = tabRect.y + 3;
248                   w = tabRect.width - 7;
249                   h = tabRect.height - 6;
250             }
251             g.drawRect(x, y, w, h);
252         }
253     }
254
255     protected int getTabRunIndent(int tabPlacement, int run) {
256         return run*3;
257     }
258
259     protected int getTabRunOverlay(int tabPlacement) {
260         tabRunOverlay = (tabPlacement == LEFT || tabPlacement == RIGHT)?
261             (int)Math.round((float)maxTabWidth * .10) :
262             (int)Math.round((float)maxTabHeight * .22);
263
264     // Ensure that runover lay is not more than insets
265
// 2 pixel offset is set from insets to each run
266
switch(tabPlacement) {
267         case LEFT:
268                 if( tabRunOverlay > tabInsets.right - 2 )
269                     tabRunOverlay = tabInsets.right - 2 ;
270                 break;
271         case RIGHT:
272                 if( tabRunOverlay > tabInsets.left - 2 )
273                     tabRunOverlay = tabInsets.left - 2 ;
274                 break;
275         case TOP:
276                 if( tabRunOverlay > tabInsets.bottom - 2 )
277                     tabRunOverlay = tabInsets.bottom - 2 ;
278                 break;
279         case BOTTOM:
280                 if( tabRunOverlay > tabInsets.top - 2 )
281                     tabRunOverlay = tabInsets.top - 2 ;
282                 break;
283
284         }
285
286         return tabRunOverlay;
287     }
288        
289 }
290
Popular Tags