1. /*
  2. * @(#)WindowsTreeUI.java 1.15 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.windows;
  8. import java.awt.*;
  9. import java.awt.event.*;
  10. import java.io.*;
  11. import java.util.*;
  12. import javax.swing.plaf.basic.*;
  13. import javax.swing.*;
  14. import javax.swing.plaf.*;
  15. /**
  16. * A Windows tree.
  17. * <p>
  18. * <strong>Warning:</strong>
  19. * Serialized objects of this class will not be compatible with
  20. * future Swing releases. The current serialization support is appropriate
  21. * for short term storage or RMI between applications running the same
  22. * version of Swing. A future release of Swing will provide support for
  23. * long term persistence.
  24. *
  25. * @version 1.15 11/29/01
  26. * @author Scott Violet
  27. */
  28. public class WindowsTreeUI extends BasicTreeUI {
  29. public static ComponentUI createUI( JComponent c )
  30. {
  31. return new WindowsTreeUI();
  32. }
  33. protected void paintVerticalLine( Graphics g, JComponent c, int x, int top, int bottom )
  34. {
  35. drawDashedVerticalLine( g, x, top, bottom );
  36. }
  37. protected void paintHorizontalLine( Graphics g, JComponent c, int y, int left, int right )
  38. {
  39. drawDashedHorizontalLine( g, y, left, right );
  40. }
  41. static protected final int HALF_SIZE = 4;
  42. static protected final int SIZE = 9;
  43. /**
  44. * The minus sign button icon
  45. * <p>
  46. * <strong>Warning:</strong>
  47. * Serialized objects of this class will not be compatible with
  48. * future Swing releases. The current serialization support is appropriate
  49. * for short term storage or RMI between applications running the same
  50. * version of Swing. A future release of Swing will provide support for
  51. * long term persistence.
  52. */
  53. public static class ExpandedIcon implements Icon, Serializable {
  54. static public Icon createExpandedIcon() {
  55. return new ExpandedIcon();
  56. }
  57. public void paintIcon(Component c, Graphics g, int x, int y) {
  58. Color backgroundColor = c.getBackground();
  59. if(backgroundColor != null)
  60. g.setColor(backgroundColor);
  61. else
  62. g.setColor(Color.white);
  63. g.fillRect(x, y, SIZE-1, SIZE-1);
  64. g.setColor(Color.gray);
  65. g.drawRect(x, y, SIZE-1, SIZE-1);
  66. g.setColor(Color.black);
  67. g.drawLine(x + 2, y + HALF_SIZE, x + (SIZE - 3), y + HALF_SIZE);
  68. }
  69. public int getIconWidth() { return SIZE; }
  70. public int getIconHeight() { return SIZE; }
  71. }
  72. /**
  73. * The plus sign button icon
  74. * <p>
  75. * <strong>Warning:</strong>
  76. * Serialized objects of this class will not be compatible with
  77. * future Swing releases. The current serialization support is appropriate
  78. * for short term storage or RMI between applications running the same
  79. * version of Swing. A future release of Swing will provide support for
  80. * long term persistence.
  81. */
  82. public static class CollapsedIcon extends ExpandedIcon {
  83. static public Icon createCollapsedIcon() {
  84. return new CollapsedIcon();
  85. }
  86. public void paintIcon(Component c, Graphics g, int x, int y) {
  87. super.paintIcon(c, g, x, y);
  88. g.drawLine(x + HALF_SIZE, y + 2, x + HALF_SIZE, y + (SIZE - 3));
  89. }
  90. }
  91. }