1. /*
  2. * @(#)MotifTabbedPaneUI.java 1.42 01/11/29
  3. *
  4. * Copyright 2002 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.42 11/29/01
  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. g.setColor(lightHighlight);
  60. if (tabPlacement != TOP || selectedIndex < 0) {
  61. g.drawLine(x, y, x+w-2, y);
  62. } else {
  63. Rectangle selRect = rects[selectedIndex];
  64. g.drawLine(x, y, selRect.x - 1, y);
  65. if (selRect.x + selRect.width < x + w - 2) {
  66. g.drawLine(selRect.x + selRect.width, y,
  67. x+w-2, y);
  68. }
  69. }
  70. }
  71. protected void paintContentBorderBottomEdge(Graphics g, int tabPlacement,
  72. int selectedIndex,
  73. int x, int y, int w, int h) {
  74. g.setColor(shadow);
  75. if (tabPlacement != BOTTOM || selectedIndex < 0) {
  76. g.drawLine(x+1, y+h-1, x+w-1, y+h-1);
  77. } else {
  78. Rectangle selRect = rects[selectedIndex];
  79. g.drawLine(x+1, y+h-1, selRect.x - 1, y+h-1);
  80. if (selRect.x + selRect.width < x + w - 2) {
  81. g.drawLine(selRect.x + selRect.width, y+h-1, x+w-2, y+h-1);
  82. }
  83. }
  84. }
  85. protected void paintContentBorderRightEdge(Graphics g, int tabPlacement,
  86. int selectedIndex,
  87. int x, int y, int w, int h) {
  88. g.setColor(shadow);
  89. if (tabPlacement != RIGHT || selectedIndex < 0) {
  90. g.drawLine(x+w-1, y+1, x+w-1, y+h-1);
  91. } else {
  92. Rectangle selRect = rects[selectedIndex];
  93. g.drawLine(x+w-1, y+1, x+w-1, selRect.y - 1);
  94. if (selRect.y + selRect.height < y + h - 2 ) {
  95. g.drawLine(x+w-1, selRect.y + selRect.height,
  96. x+w-1, y+h-2);
  97. }
  98. }
  99. }
  100. protected void paintTabBackground(Graphics g,
  101. int tabPlacement, int tabIndex,
  102. int x, int y, int w, int h,
  103. boolean isSelected ) {
  104. g.setColor(isSelected? tabPane.getBackgroundAt(tabIndex) : unselectedTabBackground);
  105. switch(tabPlacement) {
  106. case LEFT:
  107. g.fillRect(x+1, y+1, w-1, h-2);
  108. break;
  109. case RIGHT:
  110. g.fillRect(x, y+1, w-1, h-2);
  111. break;
  112. case BOTTOM:
  113. g.fillRect(x+1, y, w-2, h-3);
  114. g.drawLine(x+2, y+h-3, x+w-3, y+h-3);
  115. g.drawLine(x+3, y+h-2, x+w-4, y+h-2);
  116. break;
  117. case TOP:
  118. default:
  119. g.fillRect(x+1, y+3, w-2, h-3);
  120. g.drawLine(x+2, y+2, x+w-3, y+2);
  121. g.drawLine(x+3, y+1, x+w-4, y+1);
  122. }
  123. }
  124. protected void paintTabBorder(Graphics g,
  125. int tabPlacement, int tabIndex,
  126. int x, int y, int w, int h,
  127. boolean isSelected) {
  128. g.setColor(isSelected? lightHighlight : unselectedTabHighlight);
  129. switch(tabPlacement) {
  130. case LEFT:
  131. g.drawLine(x, y+2, x, y+h-3);
  132. g.drawLine(x+1, y+1, x+1, y+2);
  133. g.drawLine(x+2, y, x+2, y+1);
  134. g.drawLine(x+3, y, x+w-1, y);
  135. g.setColor(isSelected? shadow : unselectedTabShadow);
  136. g.drawLine(x+1, y+h-3, x+1, y+h-2);
  137. g.drawLine(x+2, y+h-2, x+2, y+h-1);
  138. g.drawLine(x+3, y+h-1, x+w-1, y+h-1);
  139. break;
  140. case RIGHT:
  141. g.drawLine(x, y, x+w-3, y);
  142. g.setColor(isSelected? shadow : unselectedTabShadow);
  143. g.drawLine(x+w-3, y, x+w-3, y+1);
  144. g.drawLine(x+w-2, y+1, x+w-2, y+2);
  145. g.drawLine(x+w-1, y+2, x+w-1, y+h-3);
  146. g.drawLine(x+w-2, y+h-3, x+w-2, y+h-2);
  147. g.drawLine(x+w-3, y+h-2, x+w-3, y+h-1);
  148. g.drawLine(x, y+h-1, x+w-3, y+h-1);
  149. break;
  150. case BOTTOM:
  151. g.drawLine(x, y, x, y+h-3);
  152. g.drawLine(x+1, y+h-3, x+1, y+h-2);
  153. g.drawLine(x+2, y+h-2, x+2, y+h-1);
  154. g.setColor(isSelected? shadow : unselectedTabShadow);
  155. g.drawLine(x+3, y+h-1, x+w-4, y+h-1);
  156. g.drawLine(x+w-3, y+h-2, x+w-3, y+h-1);
  157. g.drawLine(x+w-2, y+h-3, x+w-2, y+h-2);
  158. g.drawLine(x+w-1, y, x+w-1, y+h-3);
  159. break;
  160. case TOP:
  161. default:
  162. g.drawLine(x, y+2, x, y+h-1);
  163. g.drawLine(x+1, y+1, x+1, y+2);
  164. g.drawLine(x+2, y, x+2, y+1);
  165. g.drawLine(x+3, y, x+w-4, y);
  166. g.setColor(isSelected? shadow : unselectedTabShadow);
  167. g.drawLine(x+w-3, y, x+w-3, y+1);
  168. g.drawLine(x+w-2, y+1, x+w-2, y+2);
  169. g.drawLine(x+w-1, y+2, x+w-1, y+h-1);
  170. }
  171. }
  172. protected void paintFocusIndicator(Graphics g, int tabPlacement,
  173. Rectangle[] rects, int tabIndex,
  174. Rectangle iconRect, Rectangle textRect,
  175. boolean isSelected) {
  176. Rectangle tabRect = rects[tabIndex];
  177. if (tabPane.hasFocus() && isSelected) {
  178. int x, y, w, h;
  179. g.setColor(focus);
  180. switch(tabPlacement) {
  181. case LEFT:
  182. x = tabRect.x + 3;
  183. y = tabRect.y + 3;
  184. w = tabRect.width - 6;
  185. h = tabRect.height - 7;
  186. break;
  187. case RIGHT:
  188. x = tabRect.x + 2;
  189. y = tabRect.y + 3;
  190. w = tabRect.width - 6;
  191. h = tabRect.height - 7;
  192. break;
  193. case BOTTOM:
  194. x = tabRect.x + 3;
  195. y = tabRect.y + 2;
  196. w = tabRect.width - 7;
  197. h = tabRect.height - 6;
  198. break;
  199. case TOP:
  200. default:
  201. x = tabRect.x + 3;
  202. y = tabRect.y + 3;
  203. w = tabRect.width - 7;
  204. h = tabRect.height - 6;
  205. }
  206. g.drawRect(x, y, w, h);
  207. }
  208. }
  209. protected int getTabRunIndent(int tabPlacement, int run) {
  210. return run*3;
  211. }
  212. protected int getTabRunOverlay(int tabPlacement) {
  213. tabRunOverlay = (tabPlacement == LEFT || tabPlacement == RIGHT)?
  214. (int)Math.round((float)maxTabWidth * .10) :
  215. (int)Math.round((float)maxTabHeight * .22);
  216. return tabRunOverlay;
  217. }
  218. }