001: /*
002: * SmoothGradientTreeUI.java
003: *
004: * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021:
022: package org.underworldlabs.swing.plaf.smoothgradient;
023:
024: import java.awt.Component;
025: import java.awt.Graphics;
026: import java.beans.PropertyChangeEvent;
027: import java.beans.PropertyChangeListener;
028:
029: import javax.swing.Icon;
030: import javax.swing.JComponent;
031: import javax.swing.plaf.ComponentUI;
032: import javax.swing.plaf.basic.BasicTreeUI;
033:
034: /* ----------------------------------------------------------
035: * CVS NOTE: Changes to the CVS repository prior to the
036: * release of version 3.0.0beta1 has meant a
037: * resetting of CVS revision numbers.
038: * ----------------------------------------------------------
039: */
040:
041: /**
042: *
043: * @author Takis Diakoumis
044: * @version $Revision: 1.4 $
045: * @date $Date: 2006/05/14 06:56:07 $
046: */
047: public final class SmoothGradientTreeUI extends BasicTreeUI {
048:
049: private boolean linesEnabled = true;
050: private PropertyChangeListener lineStyleHandler;
051:
052: public static ComponentUI createUI(JComponent b) {
053: return new SmoothGradientTreeUI();
054: }
055:
056: // Installation ***********************************************************
057:
058: public void installUI(JComponent c) {
059: super .installUI(c);
060: updateLineStyle(c.getClientProperty("Angled"));
061: lineStyleHandler = new LineStyleHandler();
062: c.addPropertyChangeListener(lineStyleHandler);
063: }
064:
065: public void uninstallUI(JComponent c) {
066: c.removePropertyChangeListener(lineStyleHandler);
067: super .uninstallUI(c);
068: }
069:
070: // Painting ***************************************************************
071:
072: protected void paintVerticalLine(Graphics g, JComponent c, int x,
073: int top, int bottom) {
074: if (linesEnabled) {
075: drawDashedVerticalLine(g, x, top, bottom);
076: }
077: }
078:
079: protected void paintHorizontalLine(Graphics g, JComponent c, int y,
080: int left, int right) {
081: if (linesEnabled) {
082: drawDashedHorizontalLine(g, y, left, right);
083: }
084: }
085:
086: // Draws the icon centered at (x,y)
087: protected void drawCentered(Component c, Graphics graphics,
088: Icon icon, int x, int y) {
089: icon.paintIcon(c, graphics, x - icon.getIconWidth() / 2 - 1, y
090: - icon.getIconHeight() / 2);
091: }
092:
093: // Helper Code ************************************************************
094:
095: private void updateLineStyle(Object lineStyle) {
096: linesEnabled = !"None".equals(lineStyle);
097: }
098:
099: // Listens for changes of the line style property
100: private class LineStyleHandler implements PropertyChangeListener {
101: public void propertyChange(PropertyChangeEvent e) {
102: String name = e.getPropertyName();
103: Object value = e.getNewValue();
104: if (name.equals("Angled")) {
105: updateLineStyle(value);
106: }
107: }
108: }
109:
110: }
|