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