1. /*
  2. * @(#)MotifSplitPaneDivider.java 1.11 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 javax.swing.JSplitPane;
  10. import javax.swing.UIManager;
  11. import javax.swing.plaf.basic.BasicSplitPaneUI;
  12. import javax.swing.plaf.basic.BasicSplitPaneDivider;
  13. /**
  14. * Divider used for Motif split pane.
  15. * <p>
  16. * <strong>Warning:</strong>
  17. * Serialized objects of this class will not be compatible with
  18. * future Swing releases. The current serialization support is appropriate
  19. * for short term storage or RMI between applications running the same
  20. * version of Swing. A future release of Swing will provide support for
  21. * long term persistence.
  22. *
  23. * @version 1.11 11/29/01
  24. * @author Jeff Dinkins
  25. */
  26. public class MotifSplitPaneDivider extends BasicSplitPaneDivider
  27. {
  28. public static final int minimumThumbSize = 6;
  29. public static final int defaultDividerSize = 18;
  30. protected static final int pad = 6;
  31. protected int hThumbWidth = 12;
  32. protected int hThumbHeight = 18;
  33. protected int vThumbWidth = 18;
  34. protected int vThumbHeight = 12;
  35. protected Color highlightColor;
  36. protected Color shadowColor;
  37. protected Color focusedColor;
  38. /**
  39. * Creates a new Motif SplitPaneDivider
  40. */
  41. public MotifSplitPaneDivider(BasicSplitPaneUI ui) {
  42. super(ui);
  43. highlightColor = UIManager.getColor("SplitPane.highlight");
  44. shadowColor = UIManager.getColor("SplitPane.shadow");
  45. focusedColor = UIManager.getColor("SplitPane.activeThumb");
  46. setDividerSize(hThumbWidth + pad);
  47. }
  48. /**
  49. * overrides to hardcode the size of the divider
  50. * PENDING(jeff) - rewrite JSplitPane so that this ins't needed
  51. */
  52. public void setDividerSize(int newSize) {
  53. if (newSize < pad + minimumThumbSize) {
  54. setDividerSize(pad + minimumThumbSize);
  55. } else {
  56. vThumbHeight = hThumbWidth = newSize - pad;
  57. super.setDividerSize(newSize);
  58. }
  59. }
  60. /**
  61. * Paints the divider.
  62. */
  63. // PENDING(jeff) - the thumb's location and size is currently hard coded.
  64. // It should be dynamic.
  65. public void paint(Graphics g) {
  66. Color bgColor = getBackground();
  67. Dimension size = getSize();
  68. // fill
  69. g.setColor(getBackground());
  70. g.fillRect(0, 0, size.width, size.height);
  71. if(getBasicSplitPaneUI().getOrientation() ==
  72. JSplitPane.HORIZONTAL_SPLIT) {
  73. int center = size.width2;
  74. int x = size.width2 - hThumbWidth2;
  75. int y = 30; // PENDING(jeff) - don't hard code this.
  76. // split line
  77. g.setColor(shadowColor);
  78. g.drawLine(center-1, 0, center-1, size.height);
  79. g.setColor(highlightColor);
  80. g.drawLine(center, 0, center, size.height);
  81. // draw thumb
  82. g.setColor((splitPane.hasFocus()) ? focusedColor :
  83. getBackground());
  84. g.fillRect(x+1, y+1, hThumbWidth-2, hThumbHeight-1);
  85. g.setColor(highlightColor);
  86. g.drawLine(x, y, x+hThumbWidth-1, y); // top
  87. g.drawLine(x, y+1, x, y+hThumbHeight-1); // left
  88. g.setColor(shadowColor);
  89. g.drawLine(x+1, y+hThumbHeight-1,
  90. x+hThumbWidth-1, y+hThumbHeight-1); // bottom
  91. g.drawLine(x+hThumbWidth-1, y+1,
  92. x+hThumbWidth-1, y+hThumbHeight-2); // right
  93. } else {
  94. int center = size.height2;
  95. int x = size.width - 40; // PENDING(jeff) - don't hard code this
  96. int y = size.height2 - vThumbHeight2;
  97. // split line
  98. g.setColor(shadowColor);
  99. g.drawLine(0, center-1, size.width, center-1);
  100. g.setColor(highlightColor);
  101. g.drawLine(0, center, size.width, center);
  102. // draw thumb
  103. g.setColor((splitPane.hasFocus()) ? focusedColor :
  104. getBackground());
  105. g.fillRect(x+1, y+1, vThumbWidth-1, vThumbHeight-1);
  106. g.setColor(highlightColor);
  107. g.drawLine(x, y, x+vThumbWidth, y); // top
  108. g.drawLine(x, y+1, x, y+vThumbHeight); // left
  109. g.setColor(shadowColor);
  110. g.drawLine(x+1, y+vThumbHeight,
  111. x+vThumbWidth, y+vThumbHeight); // bottom
  112. g.drawLine(x+vThumbWidth, y+1,
  113. x+vThumbWidth, y+vThumbHeight-1); // right
  114. }
  115. super.paint(g);
  116. }
  117. /**
  118. * The minimums size is the same as the preferredSize
  119. */
  120. public Dimension getMinimumSize() {
  121. return getPreferredSize();
  122. }
  123. }