home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / javax / swing / tree / DefaultTreeCellRenderer.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  5.1 KB  |  272 lines

  1. package javax.swing.tree;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Dimension;
  6. import java.awt.Font;
  7. import java.awt.Graphics;
  8. import java.awt.Rectangle;
  9. import javax.swing.Icon;
  10. import javax.swing.JComponent;
  11. import javax.swing.JLabel;
  12. import javax.swing.JTree;
  13. import javax.swing.UIManager;
  14. import javax.swing.plaf.ColorUIResource;
  15. import javax.swing.plaf.FontUIResource;
  16.  
  17. public class DefaultTreeCellRenderer extends JLabel implements TreeCellRenderer {
  18.    protected boolean selected;
  19.    protected boolean hasFocus;
  20.    private boolean drawsFocusBorderAroundIcon;
  21.    protected transient Icon closedIcon;
  22.    protected transient Icon leafIcon;
  23.    protected transient Icon openIcon;
  24.    protected Color textSelectionColor;
  25.    protected Color textNonSelectionColor;
  26.    protected Color backgroundSelectionColor;
  27.    protected Color backgroundNonSelectionColor;
  28.    protected Color borderSelectionColor;
  29.  
  30.    public DefaultTreeCellRenderer() {
  31.       ((JLabel)this).setHorizontalAlignment(2);
  32.       this.setLeafIcon(UIManager.getIcon("Tree.leafIcon"));
  33.       this.setClosedIcon(UIManager.getIcon("Tree.closedIcon"));
  34.       this.setOpenIcon(UIManager.getIcon("Tree.openIcon"));
  35.       this.setTextSelectionColor(UIManager.getColor("Tree.selectionForeground"));
  36.       this.setTextNonSelectionColor(UIManager.getColor("Tree.textForeground"));
  37.       this.setBackgroundSelectionColor(UIManager.getColor("Tree.selectionBackground"));
  38.       this.setBackgroundNonSelectionColor(UIManager.getColor("Tree.textBackground"));
  39.       this.setBorderSelectionColor(UIManager.getColor("Tree.selectionBorderColor"));
  40.       Object var1 = UIManager.get("Tree.drawsFocusBorderAroundIcon");
  41.       this.drawsFocusBorderAroundIcon = var1 != null && (Boolean)var1;
  42.    }
  43.  
  44.    public Icon getDefaultOpenIcon() {
  45.       return UIManager.getIcon("Tree.openIcon");
  46.    }
  47.  
  48.    public Icon getDefaultClosedIcon() {
  49.       return UIManager.getIcon("Tree.closedIcon");
  50.    }
  51.  
  52.    public Icon getDefaultLeafIcon() {
  53.       return UIManager.getIcon("Tree.leafIcon");
  54.    }
  55.  
  56.    public void setOpenIcon(Icon var1) {
  57.       this.openIcon = var1;
  58.    }
  59.  
  60.    public Icon getOpenIcon() {
  61.       return this.openIcon;
  62.    }
  63.  
  64.    public void setClosedIcon(Icon var1) {
  65.       this.closedIcon = var1;
  66.    }
  67.  
  68.    public Icon getClosedIcon() {
  69.       return this.closedIcon;
  70.    }
  71.  
  72.    public void setLeafIcon(Icon var1) {
  73.       this.leafIcon = var1;
  74.    }
  75.  
  76.    public Icon getLeafIcon() {
  77.       return this.leafIcon;
  78.    }
  79.  
  80.    public void setTextSelectionColor(Color var1) {
  81.       this.textSelectionColor = var1;
  82.    }
  83.  
  84.    public Color getTextSelectionColor() {
  85.       return this.textSelectionColor;
  86.    }
  87.  
  88.    public void setTextNonSelectionColor(Color var1) {
  89.       this.textNonSelectionColor = var1;
  90.    }
  91.  
  92.    public Color getTextNonSelectionColor() {
  93.       return this.textNonSelectionColor;
  94.    }
  95.  
  96.    public void setBackgroundSelectionColor(Color var1) {
  97.       this.backgroundSelectionColor = var1;
  98.    }
  99.  
  100.    public Color getBackgroundSelectionColor() {
  101.       return this.backgroundSelectionColor;
  102.    }
  103.  
  104.    public void setBackgroundNonSelectionColor(Color var1) {
  105.       this.backgroundNonSelectionColor = var1;
  106.    }
  107.  
  108.    public Color getBackgroundNonSelectionColor() {
  109.       return this.backgroundNonSelectionColor;
  110.    }
  111.  
  112.    public void setBorderSelectionColor(Color var1) {
  113.       this.borderSelectionColor = var1;
  114.    }
  115.  
  116.    public Color getBorderSelectionColor() {
  117.       return this.borderSelectionColor;
  118.    }
  119.  
  120.    public void setFont(Font var1) {
  121.       if (var1 instanceof FontUIResource) {
  122.          var1 = null;
  123.       }
  124.  
  125.       super.setFont(var1);
  126.    }
  127.  
  128.    public void setBackground(Color var1) {
  129.       if (var1 instanceof ColorUIResource) {
  130.          var1 = null;
  131.       }
  132.  
  133.       super.setBackground(var1);
  134.    }
  135.  
  136.    public Component getTreeCellRendererComponent(JTree var1, Object var2, boolean var3, boolean var4, boolean var5, int var6, boolean var7) {
  137.       String var8 = var1.convertValueToText(var2, var3, var4, var5, var6, var7);
  138.       this.hasFocus = var7;
  139.       ((JLabel)this).setText(var8);
  140.       if (var3) {
  141.          ((JComponent)this).setForeground(this.getTextSelectionColor());
  142.       } else {
  143.          ((JComponent)this).setForeground(this.getTextNonSelectionColor());
  144.       }
  145.  
  146.       if (!((Component)var1).isEnabled()) {
  147.          ((JComponent)this).setEnabled(false);
  148.          if (var5) {
  149.             ((JLabel)this).setDisabledIcon(this.getLeafIcon());
  150.          } else if (var4) {
  151.             ((JLabel)this).setDisabledIcon(this.getOpenIcon());
  152.          } else {
  153.             ((JLabel)this).setDisabledIcon(this.getClosedIcon());
  154.          }
  155.       } else {
  156.          ((JComponent)this).setEnabled(true);
  157.          if (var5) {
  158.             ((JLabel)this).setIcon(this.getLeafIcon());
  159.          } else if (var4) {
  160.             ((JLabel)this).setIcon(this.getOpenIcon());
  161.          } else {
  162.             ((JLabel)this).setIcon(this.getClosedIcon());
  163.          }
  164.       }
  165.  
  166.       ((Component)this).setComponentOrientation(((Component)var1).getComponentOrientation());
  167.       this.selected = var3;
  168.       return this;
  169.    }
  170.  
  171.    public void paint(Graphics var1) {
  172.       Color var2;
  173.       if (this.selected) {
  174.          var2 = this.getBackgroundSelectionColor();
  175.       } else {
  176.          var2 = this.getBackgroundNonSelectionColor();
  177.          if (var2 == null) {
  178.             var2 = ((Component)this).getBackground();
  179.          }
  180.       }
  181.  
  182.       int var3 = -1;
  183.       if (var2 != null) {
  184.          Icon var4 = ((JLabel)this).getIcon();
  185.          var3 = this.getLabelStart();
  186.          var1.setColor(var2);
  187.          if (((Component)this).getComponentOrientation().isLeftToRight()) {
  188.             var1.fillRect(var3, 0, ((JComponent)this).getWidth() - 1 - var3, ((JComponent)this).getHeight());
  189.          } else {
  190.             var1.fillRect(0, 0, ((JComponent)this).getWidth() - 1 - var3, ((JComponent)this).getHeight());
  191.          }
  192.       }
  193.  
  194.       if (this.hasFocus) {
  195.          if (this.drawsFocusBorderAroundIcon) {
  196.             var3 = 0;
  197.          } else if (var3 == -1) {
  198.             var3 = this.getLabelStart();
  199.          }
  200.  
  201.          Color var5 = this.getBorderSelectionColor();
  202.          if (var5 != null) {
  203.             var1.setColor(var5);
  204.             if (((Component)this).getComponentOrientation().isLeftToRight()) {
  205.                var1.drawRect(var3, 0, ((JComponent)this).getWidth() - 1 - var3, ((JComponent)this).getHeight() - 1);
  206.             } else {
  207.                var1.drawRect(0, 0, ((JComponent)this).getWidth() - 1 - var3, ((JComponent)this).getHeight() - 1);
  208.             }
  209.          }
  210.       }
  211.  
  212.       super.paint(var1);
  213.    }
  214.  
  215.    private int getLabelStart() {
  216.       Icon var1 = ((JLabel)this).getIcon();
  217.       return var1 != null && ((JLabel)this).getText() != null ? var1.getIconWidth() + Math.max(0, ((JLabel)this).getIconTextGap() - 1) : 0;
  218.    }
  219.  
  220.    public Dimension getPreferredSize() {
  221.       Dimension var1 = super.getPreferredSize();
  222.       if (var1 != null) {
  223.          var1 = new Dimension(var1.width + 3, var1.height);
  224.       }
  225.  
  226.       return var1;
  227.    }
  228.  
  229.    public void validate() {
  230.    }
  231.  
  232.    public void revalidate() {
  233.    }
  234.  
  235.    public void repaint(long var1, int var3, int var4, int var5, int var6) {
  236.    }
  237.  
  238.    public void repaint(Rectangle var1) {
  239.    }
  240.  
  241.    protected void firePropertyChange(String var1, Object var2, Object var3) {
  242.       if (var1 == "text") {
  243.          super.firePropertyChange(var1, var2, var3);
  244.       }
  245.  
  246.    }
  247.  
  248.    public void firePropertyChange(String var1, byte var2, byte var3) {
  249.    }
  250.  
  251.    public void firePropertyChange(String var1, char var2, char var3) {
  252.    }
  253.  
  254.    public void firePropertyChange(String var1, short var2, short var3) {
  255.    }
  256.  
  257.    public void firePropertyChange(String var1, int var2, int var3) {
  258.    }
  259.  
  260.    public void firePropertyChange(String var1, long var2, long var4) {
  261.    }
  262.  
  263.    public void firePropertyChange(String var1, float var2, float var3) {
  264.    }
  265.  
  266.    public void firePropertyChange(String var1, double var2, double var4) {
  267.    }
  268.  
  269.    public void firePropertyChange(String var1, boolean var2, boolean var3) {
  270.    }
  271. }
  272.