1 7 8 package com.sun.java.swing.plaf.motif; 9 10 import java.awt.*; 11 import java.awt.event.*; 12 13 import java.io.*; 14 import java.util.*; 15 16 import javax.swing.*; 17 import javax.swing.plaf.*; 18 import javax.swing.tree.*; 19 import javax.swing.plaf.basic.*; 20 21 34 public class MotifTreeUI extends BasicTreeUI 35 { 36 static final int HALF_SIZE = 7; 37 static final int SIZE = 14; 38 39 42 public MotifTreeUI() { 43 super(); 44 } 45 46 public void installUI(JComponent c) { 47 super.installUI(c); 48 } 49 50 52 protected void paintVerticalLine( Graphics g, JComponent c, int x, int top, int bottom ) 53 { 54 g.fillRect( x - 1, top, 2, bottom - top + 2 ); 55 } 56 57 protected void paintHorizontalLine( Graphics g, JComponent c, int y, int left, int right ) 58 { 59 g.fillRect( left - 1, y, right - left, 2 ); 60 } 61 62 63 73 public static class MotifExpandedIcon implements Icon, Serializable { 74 static Color bg; 75 static Color fg; 76 static Color highlight; 77 static Color shadow; 78 79 public MotifExpandedIcon() { 80 bg = UIManager.getColor("Tree.iconBackground"); 81 fg = UIManager.getColor("Tree.iconForeground"); 82 highlight = UIManager.getColor("Tree.iconHighlight"); 83 shadow = UIManager.getColor("Tree.iconShadow"); 84 } 85 86 public static Icon createExpandedIcon() { 87 return new MotifExpandedIcon(); 88 } 89 90 public void paintIcon(Component c, Graphics g, int x, int y) { 91 g.setColor(highlight); 92 g.drawLine(x, y, x+SIZE-1, y); 93 g.drawLine(x, y+1, x, y+SIZE-1); 94 95 g.setColor(shadow); 96 g.drawLine(x+SIZE-1, y+1, x+SIZE-1, y+SIZE-1); 97 g.drawLine(x+1, y+SIZE-1, x+SIZE-1, y+SIZE-1); 98 99 g.setColor(bg); 100 g.fillRect(x+1, y+1, SIZE-2, SIZE-2); 101 102 g.setColor(fg); 103 g.drawLine(x+3, y+HALF_SIZE-1, x+SIZE-4, y+HALF_SIZE-1); 104 g.drawLine(x+3, y+HALF_SIZE, x+SIZE-4, y+HALF_SIZE); 105 } 106 107 public int getIconWidth() { return SIZE; } 108 public int getIconHeight() { return SIZE; } 109 } 110 111 121 public static class MotifCollapsedIcon extends MotifExpandedIcon { 122 public static Icon createCollapsedIcon() { 123 return new MotifCollapsedIcon(); 124 } 125 126 public void paintIcon(Component c, Graphics g, int x, int y) { 127 super.paintIcon(c, g, x, y); 128 g.drawLine(x + HALF_SIZE-1, y + 3, x + HALF_SIZE-1, y + (SIZE - 4)); 129 g.drawLine(x + HALF_SIZE, y + 3, x + HALF_SIZE, y + (SIZE - 4)); 130 } 131 } 132 133 public static ComponentUI createUI(JComponent x) { 134 return new MotifTreeUI(); 135 } 136 137 141 public TreeCellRenderer createDefaultCellRenderer() { 142 return new MotifTreeCellRenderer(); 143 } 144 145 } 146 | Popular Tags |