1. /*
  2. * @(#)SynthSplitPaneDivider.java 1.7 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 javax.swing.plaf.synth;
  8. import java.awt.*;
  9. import java.beans.*;
  10. import javax.swing.*;
  11. import javax.swing.plaf.basic.*;
  12. import sun.swing.DefaultLookup;
  13. /**
  14. * Synth's SplitPaneDivider.
  15. *
  16. * @version 1.7, 12/19/03
  17. * @author Scott Violet
  18. */
  19. class SynthSplitPaneDivider extends BasicSplitPaneDivider {
  20. public SynthSplitPaneDivider(BasicSplitPaneUI ui) {
  21. super(ui);
  22. }
  23. protected void setMouseOver(boolean mouseOver) {
  24. if (isMouseOver() != mouseOver) {
  25. repaint();
  26. }
  27. super.setMouseOver(mouseOver);
  28. }
  29. public void propertyChange(PropertyChangeEvent e) {
  30. super.propertyChange(e);
  31. if (e.getSource() == splitPane) {
  32. if (e.getPropertyName() == JSplitPane.ORIENTATION_PROPERTY) {
  33. if (leftButton instanceof SynthArrowButton) {
  34. ((SynthArrowButton)leftButton).setDirection(
  35. mapDirection(true));
  36. }
  37. if (rightButton instanceof SynthArrowButton) {
  38. ((SynthArrowButton)rightButton).setDirection(
  39. mapDirection(false));
  40. }
  41. }
  42. }
  43. }
  44. public void paint(Graphics g) {
  45. Graphics g2 = g.create();
  46. SynthContext context = ((SynthSplitPaneUI)splitPaneUI).getContext(
  47. splitPane, Region.SPLIT_PANE_DIVIDER);
  48. Rectangle bounds = getBounds();
  49. bounds.x = bounds.y = 0;
  50. SynthLookAndFeel.updateSubregion(context, g, bounds);
  51. context.getPainter().paintSplitPaneDividerBackground(context,
  52. g, 0, 0, bounds.width, bounds.height);
  53. SynthPainter foreground = null;
  54. context.getPainter().paintSplitPaneDividerForeground(context, g, 0, 0,
  55. getWidth(), getHeight(), splitPane.getOrientation());
  56. context.dispose();
  57. // super.paint(g2);
  58. for (int counter = 0; counter < getComponentCount(); counter++) {
  59. Component child = getComponent(counter);
  60. Rectangle childBounds = child.getBounds();
  61. Graphics childG = g.create(childBounds.x, childBounds.y,
  62. childBounds.width, childBounds.height);
  63. child.paint(childG);
  64. childG.dispose();
  65. }
  66. g2.dispose();
  67. }
  68. private int mapDirection(boolean isLeft) {
  69. if (isLeft) {
  70. if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT){
  71. return SwingConstants.WEST;
  72. }
  73. return SwingConstants.NORTH;
  74. }
  75. if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT){
  76. return SwingConstants.EAST;
  77. }
  78. return SwingConstants.SOUTH;
  79. }
  80. /**
  81. * Creates and return an instance of JButton that can be used to
  82. * collapse the left component in the split pane.
  83. */
  84. protected JButton createLeftOneTouchButton() {
  85. SynthArrowButton b = new SynthArrowButton(SwingConstants.NORTH);
  86. int oneTouchSize = lookupOneTouchSize();
  87. b.setName("SplitPaneDivider.leftOneTouchButton");
  88. b.setMinimumSize(new Dimension(oneTouchSize, oneTouchSize));
  89. b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  90. b.setFocusPainted(false);
  91. b.setBorderPainted(false);
  92. b.setRequestFocusEnabled(false);
  93. b.setDirection(mapDirection(true));
  94. return b;
  95. }
  96. private int lookupOneTouchSize() {
  97. return DefaultLookup.getInt(splitPaneUI.getSplitPane(), splitPaneUI,
  98. "SplitPaneDivider.oneTouchButtonSize", ONE_TOUCH_SIZE);
  99. }
  100. /**
  101. * Creates and return an instance of JButton that can be used to
  102. * collapse the right component in the split pane.
  103. */
  104. protected JButton createRightOneTouchButton() {
  105. SynthArrowButton b = new SynthArrowButton(SwingConstants.NORTH);
  106. int oneTouchSize = lookupOneTouchSize();
  107. b.setName("SplitPaneDivider.rightOneTouchButton");
  108. b.setMinimumSize(new Dimension(oneTouchSize, oneTouchSize));
  109. b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  110. b.setFocusPainted(false);
  111. b.setBorderPainted(false);
  112. b.setRequestFocusEnabled(false);
  113. b.setDirection(mapDirection(false));
  114. return b;
  115. }
  116. }