1. /*
  2. * @(#)MotifTreeCellRenderer.java 1.13 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 javax.swing.*;
  12. import javax.swing.plaf.*;
  13. import javax.swing.tree.*;
  14. import java.awt.*;
  15. import java.awt.event.*;
  16. import java.beans.*;
  17. import java.io.*;
  18. import java.util.*;
  19. /**
  20. * Motif rendered to display a tree cell.
  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.13 02/02/00
  30. * @author Jeff Dinkins
  31. */
  32. public class MotifTreeCellRenderer extends DefaultTreeCellRenderer
  33. {
  34. static final int LEAF_SIZE = 13;
  35. static final Icon LEAF_ICON = new IconUIResource(new TreeLeafIcon());
  36. public MotifTreeCellRenderer() {
  37. super();
  38. }
  39. public static Icon loadLeafIcon() {
  40. return LEAF_ICON;
  41. }
  42. /**
  43. * Icon for a node with no children.
  44. * <p>
  45. * <strong>Warning:</strong>
  46. * Serialized objects of this class will not be compatible with
  47. * future Swing releases. The current serialization support is appropriate
  48. * for short term storage or RMI between applications running the same
  49. * version of Swing. A future release of Swing will provide support for
  50. * long term persistence.
  51. */
  52. public static class TreeLeafIcon implements Icon, Serializable {
  53. Color bg;
  54. Color shadow;
  55. Color highlight;
  56. public TreeLeafIcon() {
  57. bg = UIManager.getColor("Tree.iconBackground");
  58. shadow = UIManager.getColor("Tree.iconShadow");
  59. highlight = UIManager.getColor("Tree.iconHighlight");
  60. }
  61. public void paintIcon(Component c, Graphics g, int x, int y) {
  62. g.setColor(bg);
  63. y -= 3;
  64. g.fillRect(x + 4, y + 7, 5, 5);
  65. g.drawLine(x + 6, y + 6, x + 6, y + 6);
  66. g.drawLine(x + 3, y + 9, x + 3, y + 9);
  67. g.drawLine(x + 6, y + 12, x + 6, y + 12);
  68. g.drawLine(x + 9, y + 9, x + 9, y + 9);
  69. g.setColor(highlight);
  70. g.drawLine(x + 2, y + 9, x + 5, y + 6);
  71. g.drawLine(x + 3, y + 10, x + 5, y + 12);
  72. g.setColor(shadow);
  73. g.drawLine(x + 6, y + 13, x + 10, y + 9);
  74. g.drawLine(x + 9, y + 8, x + 7, y + 6);
  75. }
  76. public int getIconWidth() {
  77. return LEAF_SIZE;
  78. }
  79. public int getIconHeight() {
  80. return LEAF_SIZE;
  81. }
  82. }
  83. }