home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.plaf.basic;
-
- import com.sun.java.swing.Icon;
- import com.sun.java.swing.JComponent;
- import com.sun.java.swing.JLabel;
- import com.sun.java.swing.JTree;
- import com.sun.java.swing.UIManager;
- import com.sun.java.swing.tree.TreeCellRenderer;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Graphics;
-
- public class BasicTreeCellRenderer extends JLabel implements TreeCellRenderer {
- protected boolean selected;
- protected transient Icon closedIcon;
- protected transient Icon leafIcon;
- protected transient Icon openIcon;
- protected Color textSelectionColor;
- protected Color textNonSelectionColor;
- protected Color backgroundSelectionColor;
- protected Color backgroundNonSelectionColor;
- protected Color borderSelectionColor;
-
- public BasicTreeCellRenderer() {
- ((JLabel)this).setHorizontalAlignment(2);
- this.setLeafIcon(UIManager.getIcon("Tree.leafIcon"));
- this.setClosedIcon(UIManager.getIcon("Tree.closedIcon"));
- this.setOpenIcon(UIManager.getIcon("Tree.openIcon"));
- this.setTextSelectionColor(UIManager.getColor("Tree.textSelectionColor"));
- this.setTextNonSelectionColor(UIManager.getColor("Tree.textNonSelectionColor"));
- this.setBackgroundSelectionColor(UIManager.getColor("Tree.backgroundSelectionColor"));
- this.setBackgroundNonSelectionColor(UIManager.getColor("Tree.backgroundNonSelectionColor"));
- this.setBorderSelectionColor(UIManager.getColor("Tree.borderSelectionColor"));
- }
-
- public Icon getDefaultOpenIcon() {
- return this.openIcon;
- }
-
- public Icon getDefaultClosedIcon() {
- return this.closedIcon;
- }
-
- public Icon getDefaultLeafIcon() {
- return this.leafIcon;
- }
-
- public void setOpenIcon(Icon var1) {
- this.openIcon = var1;
- }
-
- public Icon getOpenIcon() {
- return this.openIcon;
- }
-
- public void setClosedIcon(Icon var1) {
- this.closedIcon = var1;
- }
-
- public Icon getClosedIcon() {
- return this.closedIcon;
- }
-
- public void setLeafIcon(Icon var1) {
- this.leafIcon = var1;
- }
-
- public Icon getLeafIcon() {
- return this.leafIcon;
- }
-
- public void setTextSelectionColor(Color var1) {
- this.textSelectionColor = var1;
- }
-
- public Color getTextSelectionColor() {
- return this.textSelectionColor;
- }
-
- public void setTextNonSelectionColor(Color var1) {
- this.textNonSelectionColor = var1;
- }
-
- public Color getTextNonSelectionColor() {
- return this.textNonSelectionColor;
- }
-
- public void setBackgroundSelectionColor(Color var1) {
- this.backgroundSelectionColor = var1;
- }
-
- public Color getBackgroundSelectionColor() {
- return this.backgroundSelectionColor;
- }
-
- public void setBackgroundNonSelectionColor(Color var1) {
- this.backgroundNonSelectionColor = var1;
- }
-
- public Color getBackgroundNonSelectionColor() {
- return this.backgroundNonSelectionColor;
- }
-
- public void setBorderSelectionColor(Color var1) {
- this.borderSelectionColor = var1;
- }
-
- public Color getBorderSelectionColor() {
- return this.borderSelectionColor;
- }
-
- public Component getTreeCellRendererComponent(JTree var1, Object var2, boolean var3, boolean var4, boolean var5, int var6, boolean var7) {
- String var8 = var1.convertValueToText(var2, var3, var4, var5, var6, var7);
- ((JLabel)this).setText(var8);
- if (var3) {
- ((Component)this).setForeground(this.getTextSelectionColor());
- } else {
- ((Component)this).setForeground(this.getTextNonSelectionColor());
- }
-
- if (var5) {
- ((JLabel)this).setIcon(this.getLeafIcon());
- } else if (var4) {
- ((JLabel)this).setIcon(this.getOpenIcon());
- } else {
- ((JLabel)this).setIcon(this.getClosedIcon());
- }
-
- this.selected = var3;
- return this;
- }
-
- public void paint(Graphics var1) {
- Color var2;
- if (this.selected) {
- var2 = this.getBackgroundSelectionColor();
- } else {
- var2 = this.getBackgroundNonSelectionColor();
- if (var2 == null) {
- var2 = ((Component)this).getBackground();
- }
- }
-
- if (var2 != null) {
- Icon var3 = ((JLabel)this).getIcon();
- var1.setColor(var2);
- if (var3 != null && ((JLabel)this).getText() != null) {
- int var4 = var3.getIconWidth() + ((JLabel)this).getIconTextGap();
- var1.fillRect(var4, 0, ((JComponent)this).getWidth() - 1 - var4, ((JComponent)this).getHeight() - 1);
- } else {
- var1.fillRect(0, 0, ((JComponent)this).getWidth() - 1, ((JComponent)this).getHeight() - 1);
- }
- }
-
- if (this.selected) {
- var1.setColor(this.getBorderSelectionColor());
- var1.drawRect(0, 0, ((JComponent)this).getWidth() - 1, ((JComponent)this).getHeight() - 1);
- }
-
- super.paint(var1);
- }
-
- public Dimension getPreferredSize() {
- Dimension var1 = super.getPreferredSize();
- if (var1 != null) {
- var1 = new Dimension(var1.width + 3, var1.height);
- }
-
- return var1;
- }
- }
-