1. /*
  2. * @(#)MotifTreeUI.java 1.17 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 java.io.*;
  11. import java.util.*;
  12. import javax.swing.*;
  13. import javax.swing.plaf.*;
  14. import javax.swing.tree.*;
  15. import javax.swing.plaf.basic.*;
  16. /**
  17. * Motif rendition of the tree component.
  18. * <p>
  19. * <strong>Warning:</strong>
  20. * Serialized objects of this class will not be compatible with
  21. * future Swing releases. The current serialization support is appropriate
  22. * for short term storage or RMI between applications running the same
  23. * version of Swing. A future release of Swing will provide support for
  24. * long term persistence.
  25. *
  26. * @version 1.17 11/29/01
  27. * @author Jeff Dinkins
  28. */
  29. public class MotifTreeUI extends BasicTreeUI
  30. {
  31. static final int HALF_SIZE = 7;
  32. static final int SIZE = 14;
  33. /**
  34. * creates a UI object to represent a Motif Tree widget
  35. */
  36. public MotifTreeUI() {
  37. super();
  38. }
  39. public void installUI(JComponent c) {
  40. super.installUI(c);
  41. }
  42. // BasicTreeUI overrides
  43. protected void paintVerticalLine( Graphics g, JComponent c, int x, int top, int bottom )
  44. {
  45. g.fillRect( x - 1, top, 2, bottom - top );
  46. }
  47. protected void paintHorizontalLine( Graphics g, JComponent c, int y, int left, int right )
  48. {
  49. g.fillRect( left - 1, y, right - left, 2 );
  50. }
  51. /**
  52. * The minus sign button icon.
  53. * <p>
  54. * <strong>Warning:</strong>
  55. * Serialized objects of this class will not be compatible with
  56. * future Swing releases. The current serialization support is appropriate
  57. * for short term storage or RMI between applications running the same
  58. * version of Swing. A future release of Swing will provide support for
  59. * long term persistence.
  60. */
  61. public static class MotifExpandedIcon implements Icon, Serializable {
  62. static Color bg;
  63. static Color fg;
  64. static Color highlight;
  65. static Color shadow;
  66. public MotifExpandedIcon() {
  67. bg = UIManager.getColor("Tree.iconBackground");
  68. fg = UIManager.getColor("Tree.iconForeground");
  69. highlight = UIManager.getColor("Tree.iconHighlight");
  70. shadow = UIManager.getColor("Tree.iconShadow");
  71. }
  72. public static Icon createExpandedIcon() {
  73. return new MotifExpandedIcon();
  74. }
  75. public void paintIcon(Component c, Graphics g, int x, int y) {
  76. g.setColor(highlight);
  77. g.drawLine(x, y, x+SIZE-1, y);
  78. g.drawLine(x, y+1, x, y+SIZE-1);
  79. g.setColor(shadow);
  80. g.drawLine(x+SIZE-1, y+1, x+SIZE-1, y+SIZE-1);
  81. g.drawLine(x+1, y+SIZE-1, x+SIZE-1, y+SIZE-1);
  82. g.setColor(bg);
  83. g.fillRect(x+1, y+1, SIZE-2, SIZE-2);
  84. g.setColor(fg);
  85. g.drawLine(x+3, y+HALF_SIZE-1, x+SIZE-4, y+HALF_SIZE-1);
  86. g.drawLine(x+3, y+HALF_SIZE, x+SIZE-4, y+HALF_SIZE);
  87. }
  88. public int getIconWidth() { return SIZE; }
  89. public int getIconHeight() { return SIZE; }
  90. }
  91. /**
  92. * The plus sign button icon.
  93. * <p>
  94. * <strong>Warning:</strong>
  95. * Serialized objects of this class will not be compatible with
  96. * future Swing releases. The current serialization support is appropriate
  97. * for short term storage or RMI between applications running the same
  98. * version of Swing. A future release of Swing will provide support for
  99. * long term persistence.
  100. */
  101. public static class MotifCollapsedIcon extends MotifExpandedIcon {
  102. public static Icon createCollapsedIcon() {
  103. return new MotifCollapsedIcon();
  104. }
  105. public void paintIcon(Component c, Graphics g, int x, int y) {
  106. super.paintIcon(c, g, x, y);
  107. g.drawLine(x + HALF_SIZE-1, y + 3, x + HALF_SIZE-1, y + (SIZE - 4));
  108. g.drawLine(x + HALF_SIZE, y + 3, x + HALF_SIZE, y + (SIZE - 4));
  109. }
  110. }
  111. public static ComponentUI createUI(JComponent x) {
  112. return new MotifTreeUI();
  113. }
  114. /**
  115. * Returns the default cell renderer that is used to do the
  116. * stamping of each node.
  117. */
  118. public TreeCellRenderer createDefaultCellRenderer() {
  119. return new MotifTreeCellRenderer();
  120. }
  121. }