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. package com.sun.java.swing.plaf.motif;
  8. import java.awt.*;
  9. import java.awt.event.*;
  10. import javax.swing.*;
  11. import javax.swing.event.*;
  12. import javax.swing.plaf.*;
  13. import javax.swing.plaf.basic.BasicTabbedPaneUI;
  14. import java.io.Serializable;
  15. /**
  16. * A Motif L&F implementation of TabbedPaneUI.
  17. * <p>
  18. * <strong>Warning:</strong>
  19. * Serialized objects of this class will not be compatible with
  20. * future Swing releases. The current serialization support is appropriate
  21. * for short term storage or RMI between applications running the same
  22. * version of Swing. A future release of Swing will provide support for
  23. * long term persistence.
  24. *
  25. * @version 1.49 12/19/03
  26. * @author Amy Fowler
  27. * @author Philip Milne
  28. */
  29. public class MotifTabbedPaneUI extends BasicTabbedPaneUI
  30. {
  31. // Instance variables initialized at installation
  32. protected Color unselectedTabBackground;
  33. protected Color unselectedTabForeground;
  34. protected Color unselectedTabShadow;
  35. protected Color unselectedTabHighlight;
  36. // UI creation
  37. public static ComponentUI createUI(JComponent tabbedPane) {
  38. return new MotifTabbedPaneUI();
  39. }
  40. // UI Installation/De-installation
  41. protected void installDefaults() {
  42. super.installDefaults();
  43. unselectedTabBackground = UIManager.getColor("TabbedPane.unselectedTabBackground");
  44. unselectedTabForeground = UIManager.getColor("TabbedPane.unselectedTabForeground");
  45. unselectedTabShadow = UIManager.getColor("TabbedPane.unselectedTabShadow");
  46. unselectedTabHighlight = UIManager.getColor("TabbedPane.unselectedTabHighlight");
  47. }
  48. protected void uninstallDefaults() {
  49. super.uninstallDefaults();
  50. unselectedTabBackground = null;
  51. unselectedTabForeground = null;
  52. unselectedTabShadow = null;
  53. unselectedTabHighlight = null;
  54. }
  55. // UI Rendering
  56. protected void paintContentBorderTopEdge(Graphics g, int tabPlacement,
  57. int selectedIndex,
  58. int x, int y, int w, int h) {
  59. Rectangle selRect = selectedIndex < 0? null :
  60. getTabBounds(selectedIndex, calcRect);
  61. g.setColor(lightHighlight);
  62. // Draw unbroken line if tabs are not on TOP, OR
  63. // selected tab is not visible (SCROLL_TAB_LAYOUT)
  64. //
  65. if (tabPlacement != TOP || selectedIndex < 0 ||
  66. (selRect.x < x || selRect.x > x + w)) {
  67. g.drawLine(x, y, x+w-2, y);
  68. } else {
  69. // Break line to show visual connection to selected tab
  70. g.drawLine(x, y, selRect.x - 1, y);
  71. if (selRect.x + selRect.width < x + w - 2) {
  72. g.drawLine(selRect.x + selRect.width, y,
  73. x+w-2, y);
  74. }
  75. }
  76. }
  77. protected void paintContentBorderBottomEdge(Graphics g, int tabPlacement,
  78. int selectedIndex,
  79. int x, int y, int w, int h) {
  80. Rectangle selRect = selectedIndex < 0? null :
  81. getTabBounds(selectedIndex, calcRect);
  82. g.setColor(shadow);
  83. // Draw unbroken line if tabs are not on BOTTOM, OR
  84. // selected tab is not visible (SCROLL_TAB_LAYOUT)
  85. //
  86. if (tabPlacement != BOTTOM || selectedIndex < 0 ||
  87. (selRect.x < x || selRect.x > x + w)) {
  88. g.drawLine(x+1, y+h-1, x+w-1, y+h-1);
  89. } else {
  90. // Break line to show visual connection to selected tab
  91. g.drawLine(x+1, y+h-1, selRect.x - 1, y+h-1);
  92. if (selRect.x + selRect.width < x + w - 2) {
  93. g.drawLine(selRect.x + selRect.width, y+h-1, x+w-2, y+h-1);
  94. }
  95. }
  96. }
  97. protected void paintContentBorderRightEdge(Graphics g, int tabPlacement,
  98. int selectedIndex,
  99. int x, int y, int w, int h) {
  100. Rectangle selRect = selectedIndex < 0? null :
  101. getTabBounds(selectedIndex, calcRect);
  102. g.setColor(shadow);
  103. // Draw unbroken line if tabs are not on RIGHT, OR
  104. // selected tab is not visible (SCROLL_TAB_LAYOUT)
  105. //
  106. if (tabPlacement != RIGHT || selectedIndex < 0 ||
  107. (selRect.y < y || selRect.y > y + h)) {
  108. g.drawLine(x+w-1, y+1, x+w-1, y+h-1);
  109. } else {
  110. // Break line to show visual connection to selected tab
  111. g.drawLine(x+w-1, y+1, x+w-1, selRect.y - 1);
  112. if (selRect.y + selRect.height < y + h - 2 ) {
  113. g.drawLine(x+w-1, selRect.y + selRect.height,
  114. x+w-1, y+h-2);
  115. }
  116. }
  117. }
  118. protected void paintTabBackground(Graphics g,
  119. int tabPlacement, int tabIndex,
  120. int x, int y, int w, int h,
  121. boolean isSelected ) {
  122. g.setColor(isSelected? tabPane.getBackgroundAt(tabIndex) : unselectedTabBackground);
  123. switch(tabPlacement) {
  124. case LEFT:
  125. g.fillRect(x+1, y+1, w-1, h-2);
  126. break;
  127. case RIGHT:
  128. g.fillRect(x, y+1, w-1, h-2);
  129. break;
  130. case BOTTOM:
  131. g.fillRect(x+1, y, w-2, h-3);
  132. g.drawLine(x+2, y+h-3, x+w-3, y+h-3);
  133. g.drawLine(x+3, y+h-2, x+w-4, y+h-2);
  134. break;
  135. case TOP:
  136. default:
  137. g.fillRect(x+1, y+3, w-2, h-3);
  138. g.drawLine(x+2, y+2, x+w-3, y+2);
  139. g.drawLine(x+3, y+1, x+w-4, y+1);
  140. }
  141. }
  142. protected void paintTabBorder(Graphics g,
  143. int tabPlacement, int tabIndex,
  144. int x, int y, int w, int h,
  145. boolean isSelected) {
  146. g.setColor(isSelected? lightHighlight : unselectedTabHighlight);
  147. switch(tabPlacement) {
  148. case LEFT:
  149. g.drawLine(x, y+2, x, y+h-3);
  150. g.drawLine(x+1, y+1, x+1, y+2);
  151. g.drawLine(x+2, y, x+2, y+1);
  152. g.drawLine(x+3, y, x+w-1, y);
  153. g.setColor(isSelected? shadow : unselectedTabShadow);
  154. g.drawLine(x+1, y+h-3, x+1, y+h-2);
  155. g.drawLine(x+2, y+h-2, x+2, y+h-1);
  156. g.drawLine(x+3, y+h-1, x+w-1, y+h-1);
  157. break;
  158. case RIGHT:
  159. g.drawLine(x, y, x+w-3, y);
  160. g.setColor(isSelected? shadow : unselectedTabShadow);
  161. g.drawLine(x+w-3, y, x+w-3, y+1);
  162. g.drawLine(x+w-2, y+1, x+w-2, y+2);
  163. g.drawLine(x+w-1, y+2, x+w-1, y+h-3);
  164. g.drawLine(x+w-2, y+h-3, x+w-2, y+h-2);
  165. g.drawLine(x+w-3, y+h-2, x+w-3, y+h-1);
  166. g.drawLine(x, y+h-1, x+w-3, y+h-1);
  167. break;
  168. case BOTTOM:
  169. g.drawLine(x, y, x, y+h-3);
  170. g.drawLine(x+1, y+h-3, x+1, y+h-2);
  171. g.drawLine(x+2, y+h-2, x+2, y+h-1);
  172. g.setColor(isSelected? shadow : unselectedTabShadow);
  173. g.drawLine(x+3, y+h-1, x+w-4, y+h-1);
  174. g.drawLine(x+w-3, y+h-2, x+w-3, y+h-1);
  175. g.drawLine(x+w-2, y+h-3, x+w-2, y+h-2);
  176. g.drawLine(x+w-1, y, x+w-1, y+h-3);
  177. break;
  178. case TOP:
  179. default:
  180. g.drawLine(x, y+2, x, y+h-1);
  181. g.drawLine(x+1, y+1, x+1, y+2);
  182. g.drawLine(x+2, y, x+2, y+1);
  183. g.drawLine(x+3, y, x+w-4, y);
  184. g.setColor(isSelected? shadow : unselectedTabShadow);
  185. g.drawLine(x+w-3, y, x+w-3, y+1);
  186. g.drawLine(x+w-2, y+1, x+w-2, y+2);
  187. g.drawLine(x+w-1, y+2, x+w-1, y+h-1);
  188. }
  189. }
  190. protected void paintFocusIndicator(Graphics g, int tabPlacement,
  191. Rectangle[] rects, int tabIndex,
  192. Rectangle iconRect, Rectangle textRect,
  193. boolean isSelected) {
  194. Rectangle tabRect = rects[tabIndex];
  195. if (tabPane.hasFocus() && isSelected) {
  196. int x, y, w, h;
  197. g.setColor(focus);
  198. switch(tabPlacement) {
  199. case LEFT:
  200. x = tabRect.x + 3;
  201. y = tabRect.y + 3;
  202. w = tabRect.width - 6;
  203. h = tabRect.height - 7;
  204. break;
  205. case RIGHT:
  206. x = tabRect.x + 2;
  207. y = tabRect.y + 3;
  208. w = tabRect.width - 6;
  209. h = tabRect.height - 7;
  210. break;
  211. case BOTTOM:
  212. x = tabRect.x + 3;
  213. y = tabRect.y + 2;
  214. w = tabRect.width - 7;
  215. h = tabRect.height - 6;
  216. break;
  217. case TOP:
  218. default:
  219. x = tabRect.x + 3;
  220. y = tabRect.y + 3;
  221. w = tabRect.width - 7;
  222. h = tabRect.height - 6;
  223. }
  224. g.drawRect(x, y, w, h);
  225. }
  226. }
  227. protected int getTabRunIndent(int tabPlacement, int run) {
  228. return run*3;
  229. }
  230. protected int getTabRunOverlay(int tabPlacement) {
  231. tabRunOverlay = (tabPlacement == LEFT || tabPlacement == RIGHT)?
  232. (int)Math.round((float)maxTabWidth * .10) :
  233. (int)Math.round((float)maxTabHeight * .22);
  234. // Ensure that runover lay is not more than insets
  235. // 2 pixel offset is set from insets to each run
  236. switch(tabPlacement) {
  237. case LEFT:
  238. if( tabRunOverlay > tabInsets.right - 2 )
  239. tabRunOverlay = tabInsets.right - 2 ;
  240. break;
  241. case RIGHT:
  242. if( tabRunOverlay > tabInsets.left - 2 )
  243. tabRunOverlay = tabInsets.left - 2 ;
  244. break;
  245. case TOP:
  246. if( tabRunOverlay > tabInsets.bottom - 2 )
  247. tabRunOverlay = tabInsets.bottom - 2 ;
  248. break;
  249. case BOTTOM:
  250. if( tabRunOverlay > tabInsets.top - 2 )
  251. tabRunOverlay = tabInsets.top - 2 ;
  252. break;
  253. }
  254. return tabRunOverlay;
  255. }
  256. }