1 30 31 package com.jgoodies.looks.windows; 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 42 import com.jgoodies.looks.Options; 43 44 74 75 public final class WindowsTreeUI extends com.sun.java.swing.plaf.windows.WindowsTreeUI { 76 77 private boolean linesEnabled = true; 78 private PropertyChangeListener lineStyleHandler; 79 80 public static ComponentUI createUI(JComponent b) { 81 return new WindowsTreeUI(); 82 } 83 84 85 87 public void installUI(JComponent c) { 88 super.installUI(c); 89 updateLineStyle(c.getClientProperty(Options.TREE_LINE_STYLE_KEY)); 90 lineStyleHandler = new LineStyleHandler(); 91 c.addPropertyChangeListener(lineStyleHandler); 92 } 93 94 public void uninstallUI(JComponent c) { 95 c.removePropertyChangeListener(lineStyleHandler); 96 super.uninstallUI(c); 97 } 98 99 100 102 protected void paintVerticalLine(Graphics g, JComponent c, int x, int top, int bottom) { 103 if (linesEnabled) { 104 super.paintVerticalLine(g, c, x, top, bottom); 105 } 106 } 107 108 protected void paintHorizontalLine(Graphics g, JComponent c, int y, int left, int right) { 109 if (linesEnabled) { 110 super.paintHorizontalLine(g, c, y, left, right); 111 } 112 } 113 114 protected void drawCentered(Component c, Graphics graphics, Icon icon, int x, int y) { 116 icon.paintIcon(c, graphics, 117 x - icon.getIconWidth() / 2 - 1, 118 y - icon.getIconHeight() / 2); 119 } 120 121 122 124 private void updateLineStyle(Object lineStyle) { 125 linesEnabled = !Options.TREE_LINE_STYLE_NONE_VALUE.equals(lineStyle); 126 } 127 128 private class LineStyleHandler implements PropertyChangeListener { 130 public void propertyChange(PropertyChangeEvent e) { 131 String name = e.getPropertyName(); 132 Object value = e.getNewValue(); 133 if (name.equals(Options.TREE_LINE_STYLE_KEY)) { 134 updateLineStyle(value); 135 } 136 } 137 } 138 139 } | Popular Tags |