1. /*
  2. * @(#)WindowsBorders.java 1.27 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.java.swing.plaf.windows;
  8. import javax.swing.*;
  9. import javax.swing.border.*;
  10. import javax.swing.plaf.*;
  11. import javax.swing.plaf.basic.*;
  12. import java.awt.Component;
  13. import java.awt.Insets;
  14. import java.awt.Dimension;
  15. import java.awt.Image;
  16. import java.awt.Rectangle;
  17. import java.awt.Color;
  18. import java.awt.Graphics;
  19. import java.io.Serializable;
  20. /**
  21. * Factory object that can vend Borders appropriate for the Windows 95 L & F.
  22. * @version 1.27 01/23/03
  23. * @author Rich Schiavi
  24. */
  25. public class WindowsBorders {
  26. /**
  27. * Returns a border instance for a Windows Progress Bar
  28. * @since 1.4
  29. */
  30. public static Border getProgressBarBorder() {
  31. UIDefaults table = UIManager.getLookAndFeelDefaults();
  32. Border progressBarBorder = new BorderUIResource.CompoundBorderUIResource(
  33. new WindowsBorders.ProgressBarBorder(
  34. table.getColor("ProgressBar.shadow"),
  35. table.getColor("ProgressBar.highlight")),
  36. new EmptyBorder(1,1,1,1)
  37. );
  38. return progressBarBorder;
  39. }
  40. /**
  41. * Returns a border instance for a Windows ToolBar
  42. *
  43. * @return a border used for the toolbar
  44. * @since 1.4
  45. */
  46. public static Border getToolBarBorder() {
  47. UIDefaults table = UIManager.getLookAndFeelDefaults();
  48. Border toolBarBorder = new WindowsBorders.ToolBarBorder(
  49. table.getColor("ToolBar.shadow"),
  50. table.getColor("ToolBar.highlight"));
  51. return toolBarBorder;
  52. }
  53. /**
  54. * Returns an new instance of a border used to indicate which cell item
  55. * has focus.
  56. *
  57. * @return a dashed border with the control highlight value as the color
  58. * @since 1.4
  59. */
  60. public static Border getFocusCellHighlightBorder() {
  61. UIDefaults table = UIManager.getLookAndFeelDefaults();
  62. Border focusCellBorder = new DashedBorder(table.getColor("List.focusCellBorderColor"));
  63. return focusCellBorder;
  64. }
  65. public static Border getTableHeaderBorder() {
  66. UIDefaults table = UIManager.getLookAndFeelDefaults();
  67. Border tableHeaderBorder = new BorderUIResource.CompoundBorderUIResource(
  68. new BasicBorders.ButtonBorder(
  69. table.getColor("Table.shadow"),
  70. table.getColor("Table.darkShadow"),
  71. table.getColor("Table.light"),
  72. table.getColor("Table.highlight")),
  73. new BasicBorders.MarginBorder());
  74. return tableHeaderBorder;
  75. }
  76. public static Border getInternalFrameBorder() {
  77. UIDefaults table = UIManager.getLookAndFeelDefaults();
  78. Border internalFrameBorder = new
  79. BorderUIResource.CompoundBorderUIResource(
  80. BorderFactory.createBevelBorder(BevelBorder.RAISED,
  81. table.getColor("InternalFrame.borderColor"),
  82. table.getColor("InternalFrame.borderHighlight"),
  83. table.getColor("InternalFrame.borderDarkShadow"),
  84. table.getColor("InternalFrame.borderShadow")),
  85. new WindowsBorders.InternalFrameLineBorder(
  86. table.getColor("InternalFrame.activeBorderColor"),
  87. table.getColor("InternalFrame.inactiveBorderColor"),
  88. table.getInt("InternalFrame.borderWidth")));
  89. return internalFrameBorder;
  90. }
  91. public static class ProgressBarBorder extends AbstractBorder implements UIResource {
  92. protected Color shadow;
  93. protected Color highlight;
  94. public ProgressBarBorder(Color shadow, Color highlight) {
  95. this.highlight = highlight;
  96. this.shadow = shadow;
  97. }
  98. public void paintBorder(Component c, Graphics g, int x, int y,
  99. int width, int height) {
  100. g.setColor(shadow);
  101. g.drawLine(x,y, width-1,y); // draw top
  102. g.drawLine(x,y, x,height-1); // draw left
  103. g.setColor(highlight);
  104. g.drawLine(x,height-1, width-1,height-1); // draw bottom
  105. g.drawLine(width-1,y, width-1,height-1); // draw right
  106. }
  107. public Insets getBorderInsets(Component c) {
  108. return new Insets(1,1,1,1);
  109. }
  110. public Insets getBorderInsets(Component c, Insets insets) {
  111. insets.top = insets.left = insets.bottom = insets.right = 1;
  112. return insets;
  113. }
  114. }
  115. /**
  116. * A border for the ToolBar. If the ToolBar is floatable then the handle grip is drawn
  117. * <p>
  118. * @since 1.4
  119. */
  120. public static class ToolBarBorder extends AbstractBorder implements UIResource, SwingConstants {
  121. protected Color shadow;
  122. protected Color highlight;
  123. private XPStyle xp = XPStyle.getXP();
  124. public ToolBarBorder(Color shadow, Color highlight) {
  125. this.highlight = highlight;
  126. this.shadow = shadow;
  127. }
  128. public void paintBorder(Component c, Graphics g, int x, int y,
  129. int width, int height) {
  130. g.translate(x, y);
  131. if (((JToolBar)c).isFloatable()) {
  132. boolean vertical = ((JToolBar)c).getOrientation() == VERTICAL;
  133. if (xp != null) {
  134. Border xpBorder = xp.getBorder("toolbar");
  135. if (xpBorder != null) {
  136. xpBorder.paintBorder(c, g, 0, 0, width, height);
  137. }
  138. String category = vertical ? "rebar.grippervert" : "rebar.gripper";
  139. XPStyle.Skin skin = xp.getSkin(category);
  140. int dw = vertical ? (width-1) : skin.getWidth();
  141. int dh = vertical ? skin.getHeight() : (height-1);
  142. int dx = (vertical || c.getComponentOrientation().isLeftToRight())
  143. ? 1 : (width-dw-1);
  144. skin.paintSkin(g, dx, 1, dw, dh, 0);
  145. } else {
  146. if (!vertical) {
  147. if (c.getComponentOrientation().isLeftToRight()) {
  148. g.setColor(shadow);
  149. g.drawLine(4, 3, 4, height - 4);
  150. g.drawLine(4, height - 4, 2, height - 4);
  151. g.setColor(highlight);
  152. g.drawLine(2, 3, 3, 3);
  153. g.drawLine(2, 3, 2, height - 5);
  154. } else {
  155. g.setColor(shadow);
  156. g.drawLine(width - 3, 3, width - 3, height - 4);
  157. g.drawLine(width - 4, height - 4, width - 4, height - 4);
  158. g.setColor(highlight);
  159. g.drawLine(width - 5, 3, width - 4, 3);
  160. g.drawLine(width - 5, 3, width - 5, height - 5);
  161. }
  162. } else { // Vertical
  163. g.setColor(shadow);
  164. g.drawLine(3, 4, width - 4, 4);
  165. g.drawLine(width - 4, 2, width - 4, 4);
  166. g.setColor(highlight);
  167. g.drawLine(3, 2, width - 4, 2);
  168. g.drawLine(3, 2, 3, 3);
  169. }
  170. }
  171. }
  172. g.translate(-x, -y);
  173. }
  174. public Insets getBorderInsets(Component c) {
  175. return getBorderInsets(c, new Insets(1,1,1,1));
  176. }
  177. public Insets getBorderInsets(Component c, Insets insets) {
  178. insets.top = insets.left = insets.bottom = insets.right = 1;
  179. if (((JToolBar)c).isFloatable()) {
  180. if (((JToolBar)c).getOrientation() == HORIZONTAL) {
  181. if (c.getComponentOrientation().isLeftToRight()) {
  182. insets.left = 9;
  183. } else {
  184. insets.right = 9;
  185. }
  186. } else {
  187. insets.top = 9;
  188. }
  189. }
  190. return insets;
  191. }
  192. }
  193. /**
  194. * This class is an implementation of a dashed border.
  195. * @since 1.4
  196. */
  197. public static class DashedBorder extends LineBorder implements UIResource {
  198. public DashedBorder(Color color) {
  199. super(color);
  200. }
  201. public DashedBorder(Color color, int thickness) {
  202. super(color, thickness);
  203. }
  204. public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  205. Color oldColor = g.getColor();
  206. int i;
  207. g.setColor(lineColor);
  208. for(i = 0; i < thickness; i++) {
  209. BasicGraphicsUtils.drawDashedRect(g, x+i, y+i, width-i-i, height-i-i);
  210. }
  211. g.setColor(oldColor);
  212. }
  213. }
  214. /**
  215. * This class is an implementation of the InternalFrameLine border.
  216. * @since 1.4
  217. */
  218. public static class InternalFrameLineBorder extends LineBorder implements
  219. UIResource {
  220. protected Color activeColor;
  221. protected Color inactiveColor;
  222. public InternalFrameLineBorder(Color activeBorderColor,
  223. Color inactiveBorderColor,
  224. int thickness) {
  225. super(activeBorderColor, thickness);
  226. activeColor = activeBorderColor;
  227. inactiveColor = inactiveBorderColor;
  228. }
  229. public void paintBorder(Component c, Graphics g, int x, int y,
  230. int width, int height) {
  231. JInternalFrame jif = null;
  232. if (c instanceof JInternalFrame) {
  233. jif = (JInternalFrame)c;
  234. } else if (c instanceof JInternalFrame.JDesktopIcon) {
  235. jif = ((JInternalFrame.JDesktopIcon)c).getInternalFrame();
  236. } else {
  237. return;
  238. }
  239. if (jif.isSelected()) {
  240. // Set the line color so the line border gets the correct
  241. // color.
  242. lineColor = activeColor;
  243. super.paintBorder(c, g, x, y, width, height);
  244. } else {
  245. lineColor = inactiveColor;
  246. super.paintBorder(c, g, x, y, width, height);
  247. }
  248. }
  249. }
  250. }