1. /*
  2. * @(#)MotifTabbedPaneUI.java 1.43 00/02/02
  3. *
  4. * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package com.sun.java.swing.plaf.motif;
  11. import java.awt.*;
  12. import java.awt.event.*;
  13. import javax.swing.*;
  14. import javax.swing.event.*;
  15. import javax.swing.plaf.*;
  16. import javax.swing.plaf.basic.BasicTabbedPaneUI;
  17. import java.io.Serializable;
  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.43 02/02/00
  29. * @author Amy Fowler
  30. * @author Philip Milne
  31. */
  32. public class MotifTabbedPaneUI extends BasicTabbedPaneUI
  33. {
  34. // Instance variables initialized at installation
  35. protected Color unselectedTabBackground;
  36. protected Color unselectedTabForeground;
  37. protected Color unselectedTabShadow;
  38. protected Color unselectedTabHighlight;
  39. // UI creation
  40. public static ComponentUI createUI(JComponent tabbedPane) {
  41. return new MotifTabbedPaneUI();
  42. }
  43. // UI Installation/De-installation
  44. protected void installDefaults() {
  45. super.installDefaults();
  46. unselectedTabBackground = UIManager.getColor("TabbedPane.unselectedTabBackground");
  47. unselectedTabForeground = UIManager.getColor("TabbedPane.unselectedTabForeground");
  48. unselectedTabShadow = UIManager.getColor("TabbedPane.unselectedTabShadow");
  49. unselectedTabHighlight = UIManager.getColor("TabbedPane.unselectedTabHighlight");
  50. }
  51. protected void uninstallDefaults() {
  52. super.uninstallDefaults();
  53. unselectedTabBackground = null;
  54. unselectedTabForeground = null;
  55. unselectedTabShadow = null;
  56. unselectedTabHighlight = null;
  57. }
  58. // UI Rendering
  59. protected void paintContentBorderTopEdge(Graphics g, int tabPlacement,
  60. int selectedIndex,
  61. int x, int y, int w, int h) {
  62. g.setColor(lightHighlight);
  63. if (tabPlacement != TOP || selectedIndex < 0) {
  64. g.drawLine(x, y, x+w-2, y);
  65. } else {
  66. Rectangle selRect = rects[selectedIndex];
  67. g.drawLine(x, y, selRect.x - 1, y);
  68. if (selRect.x + selRect.width < x + w - 2) {
  69. g.drawLine(selRect.x + selRect.width, y,
  70. x+w-2, y);
  71. }
  72. }
  73. }
  74. protected void paintContentBorderBottomEdge(Graphics g, int tabPlacement,
  75. int selectedIndex,
  76. int x, int y, int w, int h) {
  77. g.setColor(shadow);
  78. if (tabPlacement != BOTTOM || selectedIndex < 0) {
  79. g.drawLine(x+1, y+h-1, x+w-1, y+h-1);
  80. } else {
  81. Rectangle selRect = rects[selectedIndex];
  82. g.drawLine(x+1, y+h-1, selRect.x - 1, y+h-1);
  83. if (selRect.x + selRect.width < x + w - 2) {
  84. g.drawLine(selRect.x + selRect.width, y+h-1, x+w-2, y+h-1);
  85. }
  86. }
  87. }
  88. protected void paintContentBorderRightEdge(Graphics g, int tabPlacement,
  89. int selectedIndex,
  90. int x, int y, int w, int h) {
  91. g.setColor(shadow);
  92. if (tabPlacement != RIGHT || selectedIndex < 0) {
  93. g.drawLine(x+w-1, y+1, x+w-1, y+h-1);
  94. } else {
  95. Rectangle selRect = rects[selectedIndex];
  96. g.drawLine(x+w-1, y+1, x+w-1, selRect.y - 1);
  97. if (selRect.y + selRect.height < y + h - 2 ) {
  98. g.drawLine(x+w-1, selRect.y + selRect.height,
  99. x+w-1, y+h-2);
  100. }
  101. }
  102. }
  103. protected void paintTabBackground(Graphics g,
  104. int tabPlacement, int tabIndex,
  105. int x, int y, int w, int h,
  106. boolean isSelected ) {
  107. g.setColor(isSelected? tabPane.getBackgroundAt(tabIndex) : unselectedTabBackground);
  108. switch(tabPlacement) {
  109. case LEFT:
  110. g.fillRect(x+1, y+1, w-1, h-2);
  111. break;
  112. case RIGHT:
  113. g.fillRect(x, y+1, w-1, h-2);
  114. break;
  115. case BOTTOM:
  116. g.fillRect(x+1, y, w-2, h-3);
  117. g.drawLine(x+2, y+h-3, x+w-3, y+h-3);
  118. g.drawLine(x+3, y+h-2, x+w-4, y+h-2);
  119. break;
  120. case TOP:
  121. default:
  122. g.fillRect(x+1, y+3, w-2, h-3);
  123. g.drawLine(x+2, y+2, x+w-3, y+2);
  124. g.drawLine(x+3, y+1, x+w-4, y+1);
  125. }
  126. }
  127. protected void paintTabBorder(Graphics g,
  128. int tabPlacement, int tabIndex,
  129. int x, int y, int w, int h,
  130. boolean isSelected) {
  131. g.setColor(isSelected? lightHighlight : unselectedTabHighlight);
  132. switch(tabPlacement) {
  133. case LEFT:
  134. g.drawLine(x, y+2, x, y+h-3);
  135. g.drawLine(x+1, y+1, x+1, y+2);
  136. g.drawLine(x+2, y, x+2, y+1);
  137. g.drawLine(x+3, y, x+w-1, y);
  138. g.setColor(isSelected? shadow : unselectedTabShadow);
  139. g.drawLine(x+1, y+h-3, x+1, y+h-2);
  140. g.drawLine(x+2, y+h-2, x+2, y+h-1);
  141. g.drawLine(x+3, y+h-1, x+w-1, y+h-1);
  142. break;
  143. case RIGHT:
  144. g.drawLine(x, y, x+w-3, y);
  145. g.setColor(isSelected? shadow : unselectedTabShadow);
  146. g.drawLine(x+w-3, y, x+w-3, y+1);
  147. g.drawLine(x+w-2, y+1, x+w-2, y+2);
  148. g.drawLine(x+w-1, y+2, x+w-1, y+h-3);
  149. g.drawLine(x+w-2, y+h-3, x+w-2, y+h-2);
  150. g.drawLine(x+w-3, y+h-2, x+w-3, y+h-1);
  151. g.drawLine(x, y+h-1, x+w-3, y+h-1);
  152. break;
  153. case BOTTOM:
  154. g.drawLine(x, y, x, y+h-3);
  155. g.drawLine(x+1, y+h-3, x+1, y+h-2);
  156. g.drawLine(x+2, y+h-2, x+2, y+h-1);
  157. g.setColor(isSelected? shadow : unselectedTabShadow);
  158. g.drawLine(x+3, y+h-1, x+w-4, y+h-1);
  159. g.drawLine(x+w-3, y+h-2, x+w-3, y+h-1);
  160. g.drawLine(x+w-2, y+h-3, x+w-2, y+h-2);
  161. g.drawLine(x+w-1, y, x+w-1, y+h-3);
  162. break;
  163. case TOP:
  164. default:
  165. g.drawLine(x, y+2, x, y+h-1);
  166. g.drawLine(x+1, y+1, x+1, y+2);
  167. g.drawLine(x+2, y, x+2, y+1);
  168. g.drawLine(x+3, y, x+w-4, y);
  169. g.setColor(isSelected? shadow : unselectedTabShadow);
  170. g.drawLine(x+w-3, y, x+w-3, y+1);
  171. g.drawLine(x+w-2, y+1, x+w-2, y+2);
  172. g.drawLine(x+w-1, y+2, x+w-1, y+h-1);
  173. }
  174. }
  175. protected void paintFocusIndicator(Graphics g, int tabPlacement,
  176. Rectangle[] rects, int tabIndex,
  177. Rectangle iconRect, Rectangle textRect,
  178. boolean isSelected) {
  179. Rectangle tabRect = rects[tabIndex];
  180. if (tabPane.hasFocus() && isSelected) {
  181. int x, y, w, h;
  182. g.setColor(focus);
  183. switch(tabPlacement) {
  184. case LEFT:
  185. x = tabRect.x + 3;
  186. y = tabRect.y + 3;
  187. w = tabRect.width - 6;
  188. h = tabRect.height - 7;
  189. break;
  190. case RIGHT:
  191. x = tabRect.x + 2;
  192. y = tabRect.y + 3;
  193. w = tabRect.width - 6;
  194. h = tabRect.height - 7;
  195. break;
  196. case BOTTOM:
  197. x = tabRect.x + 3;
  198. y = tabRect.y + 2;
  199. w = tabRect.width - 7;
  200. h = tabRect.height - 6;
  201. break;
  202. case TOP:
  203. default:
  204. x = tabRect.x + 3;
  205. y = tabRect.y + 3;
  206. w = tabRect.width - 7;
  207. h = tabRect.height - 6;
  208. }
  209. g.drawRect(x, y, w, h);
  210. }
  211. }
  212. protected int getTabRunIndent(int tabPlacement, int run) {
  213. return run*3;
  214. }
  215. protected int getTabRunOverlay(int tabPlacement) {
  216. tabRunOverlay = (tabPlacement == LEFT || tabPlacement == RIGHT)?
  217. (int)Math.round((float)maxTabWidth * .10) :
  218. (int)Math.round((float)maxTabHeight * .22);
  219. return tabRunOverlay;
  220. }
  221. }