001: /*
002: * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.java.swing.plaf.motif;
027:
028: import java.awt.*;
029: import java.awt.event.*;
030:
031: import java.io.*;
032: import java.util.*;
033:
034: import javax.swing.*;
035: import javax.swing.plaf.*;
036: import javax.swing.tree.*;
037: import javax.swing.plaf.basic.*;
038:
039: /**
040: * Motif rendition of the tree component.
041: * <p>
042: * <strong>Warning:</strong>
043: * Serialized objects of this class will not be compatible with
044: * future Swing releases. The current serialization support is appropriate
045: * for short term storage or RMI between applications running the same
046: * version of Swing. A future release of Swing will provide support for
047: * long term persistence.
048: *
049: * @version 1.16 08/28/98
050: * @author Jeff Dinkins
051: */
052: public class MotifTreeUI extends BasicTreeUI {
053: static final int HALF_SIZE = 7;
054: static final int SIZE = 14;
055:
056: /**
057: * creates a UI object to represent a Motif Tree widget
058: */
059: public MotifTreeUI() {
060: super ();
061: }
062:
063: public void installUI(JComponent c) {
064: super .installUI(c);
065: }
066:
067: // BasicTreeUI overrides
068:
069: protected void paintVerticalLine(Graphics g, JComponent c, int x,
070: int top, int bottom) {
071: if (tree.getComponentOrientation().isLeftToRight()) {
072: g.fillRect(x, top, 2, bottom - top + 2);
073: } else {
074: g.fillRect(x - 1, top, 2, bottom - top + 2);
075: }
076: }
077:
078: protected void paintHorizontalLine(Graphics g, JComponent c, int y,
079: int left, int right) {
080: g.fillRect(left, y, right - left + 1, 2);
081: }
082:
083: /**
084: * The minus sign button icon.
085: * <p>
086: * <strong>Warning:</strong>
087: * Serialized objects of this class will not be compatible with
088: * future Swing releases. The current serialization support is appropriate
089: * for short term storage or RMI between applications running the same
090: * version of Swing. A future release of Swing will provide support for
091: * long term persistence.
092: */
093: public static class MotifExpandedIcon implements Icon, Serializable {
094: static Color bg;
095: static Color fg;
096: static Color highlight;
097: static Color shadow;
098:
099: public MotifExpandedIcon() {
100: bg = UIManager.getColor("Tree.iconBackground");
101: fg = UIManager.getColor("Tree.iconForeground");
102: highlight = UIManager.getColor("Tree.iconHighlight");
103: shadow = UIManager.getColor("Tree.iconShadow");
104: }
105:
106: public static Icon createExpandedIcon() {
107: return new MotifExpandedIcon();
108: }
109:
110: public void paintIcon(Component c, Graphics g, int x, int y) {
111: g.setColor(highlight);
112: g.drawLine(x, y, x + SIZE - 1, y);
113: g.drawLine(x, y + 1, x, y + SIZE - 1);
114:
115: g.setColor(shadow);
116: g.drawLine(x + SIZE - 1, y + 1, x + SIZE - 1, y + SIZE - 1);
117: g.drawLine(x + 1, y + SIZE - 1, x + SIZE - 1, y + SIZE - 1);
118:
119: g.setColor(bg);
120: g.fillRect(x + 1, y + 1, SIZE - 2, SIZE - 2);
121:
122: g.setColor(fg);
123: g.drawLine(x + 3, y + HALF_SIZE - 1, x + SIZE - 4, y
124: + HALF_SIZE - 1);
125: g.drawLine(x + 3, y + HALF_SIZE, x + SIZE - 4, y
126: + HALF_SIZE);
127: }
128:
129: public int getIconWidth() {
130: return SIZE;
131: }
132:
133: public int getIconHeight() {
134: return SIZE;
135: }
136: }
137:
138: /**
139: * The plus sign button icon.
140: * <p>
141: * <strong>Warning:</strong>
142: * Serialized objects of this class will not be compatible with
143: * future Swing releases. The current serialization support is appropriate
144: * for short term storage or RMI between applications running the same
145: * version of Swing. A future release of Swing will provide support for
146: * long term persistence.
147: */
148: public static class MotifCollapsedIcon extends MotifExpandedIcon {
149: public static Icon createCollapsedIcon() {
150: return new MotifCollapsedIcon();
151: }
152:
153: public void paintIcon(Component c, Graphics g, int x, int y) {
154: super .paintIcon(c, g, x, y);
155: g.drawLine(x + HALF_SIZE - 1, y + 3, x + HALF_SIZE - 1, y
156: + (SIZE - 4));
157: g.drawLine(x + HALF_SIZE, y + 3, x + HALF_SIZE, y
158: + (SIZE - 4));
159: }
160: }
161:
162: public static ComponentUI createUI(JComponent x) {
163: return new MotifTreeUI();
164: }
165:
166: /**
167: * Returns the default cell renderer that is used to do the
168: * stamping of each node.
169: */
170: public TreeCellRenderer createDefaultCellRenderer() {
171: return new MotifTreeCellRenderer();
172: }
173:
174: }
|