1 30 31 package com.jgoodies.looks.plastic; 32 33 import java.awt.Component ; 34 import java.awt.Graphics ; 35 import java.beans.PropertyChangeEvent ; 36 import java.beans.PropertyChangeListener ; 37 38 import javax.swing.Icon ; 39 import javax.swing.JComponent ; 40 import javax.swing.plaf.ComponentUI ; 41 import javax.swing.plaf.basic.BasicTreeUI ; 42 43 import com.jgoodies.looks.Options; 44 45 75 76 public final class PlasticTreeUI extends BasicTreeUI { 77 78 private boolean linesEnabled = true; 79 private PropertyChangeListener lineStyleHandler; 80 81 82 public static ComponentUI createUI(JComponent b) { 83 return new PlasticTreeUI(); 84 } 85 86 88 public void installUI(JComponent c) { 89 super.installUI(c); 90 updateLineStyle(c.getClientProperty(Options.TREE_LINE_STYLE_KEY)); 91 lineStyleHandler = new LineStyleHandler(); 92 c.addPropertyChangeListener(lineStyleHandler); 93 } 94 95 public void uninstallUI(JComponent c) { 96 c.removePropertyChangeListener(lineStyleHandler); 97 super.uninstallUI(c); 98 } 99 100 101 103 protected void paintVerticalLine(Graphics g, JComponent c, int x, int top, int bottom) { 104 if (linesEnabled) { 105 drawDashedVerticalLine(g, x, top, bottom); 106 } 107 } 108 109 protected void paintHorizontalLine(Graphics g, JComponent c, int y, int left, int right) { 110 if (linesEnabled) { 111 drawDashedHorizontalLine(g, y, left, right); 112 } 113 } 114 115 protected void drawCentered(Component c, Graphics graphics, Icon icon, int x, int y) { 117 icon.paintIcon( 118 c, 119 graphics, 120 x - icon.getIconWidth() / 2 - 1, 121 y - icon.getIconHeight() / 2); 122 } 123 124 126 private void updateLineStyle(Object lineStyle) { 127 linesEnabled = !Options.TREE_LINE_STYLE_NONE_VALUE.equals(lineStyle); 128 } 129 130 private class LineStyleHandler implements PropertyChangeListener { 132 public void propertyChange(PropertyChangeEvent e) { 133 String name = e.getPropertyName(); 134 Object value = e.getNewValue(); 135 if (name.equals(Options.TREE_LINE_STYLE_KEY)) { 136 updateLineStyle(value); 137 } 138 } 139 } 140 141 } | Popular Tags |