home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161a.iso / handson / files / copyjava.exe / com / sun / java / swing / plaf / metal / MetalTreeUI.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-02-26  |  4.1 KB  |  134 lines

  1. package com.sun.java.swing.plaf.metal;
  2.  
  3. import com.sun.java.swing.JComponent;
  4. import com.sun.java.swing.UIManager;
  5. import com.sun.java.swing.plaf.ComponentUI;
  6. import com.sun.java.swing.plaf.basic.AbstractTreeUI;
  7. import com.sun.java.swing.plaf.basic.BasicTreeUI;
  8. import com.sun.java.swing.plaf.basic.LargeTreeModelNode;
  9. import com.sun.java.swing.plaf.basic.VisibleTreeNode;
  10. import com.sun.java.swing.tree.DefaultMutableTreeNode;
  11. import java.awt.Color;
  12. import java.awt.Graphics;
  13. import java.awt.Rectangle;
  14. import java.beans.PropertyChangeListener;
  15.  
  16. public class MetalTreeUI extends BasicTreeUI {
  17.    private static Color lineColor;
  18.    private static final String LINE_STYLE = "JTree.lineStyle";
  19.    private static final String LEG_LINE_STYLE_STRING = "Angled";
  20.    private static final String HORIZ_STYLE_STRING = "Horizontal";
  21.    private static final String NO_STYLE_STRING = "None";
  22.    private static final int LEG_LINE_STYLE = 2;
  23.    private static final int HORIZ_LINE_STYLE = 1;
  24.    private static final int NO_LINE_STYLE = 0;
  25.    private int lineStyle = 1;
  26.    private PropertyChangeListener lineStyleListener = new LineListener(this);
  27.  
  28.    public static ComponentUI createUI(JComponent var0) {
  29.       return new MetalTreeUI();
  30.    }
  31.  
  32.    protected int getHorizontalLegBuffer() {
  33.       return 4;
  34.    }
  35.  
  36.    public void installUI(JComponent var1) {
  37.       super.installUI(var1);
  38.       if (!super.tree.isLargeModel()) {
  39.          ((AbstractTreeUI)this).setRowHeight(0);
  40.       }
  41.  
  42.       lineColor = UIManager.getColor("Tree.line");
  43.       Object var2 = var1.getClientProperty("JTree.lineStyle");
  44.       this.decodeLineStyle(var2);
  45.       var1.addPropertyChangeListener(this.lineStyleListener);
  46.    }
  47.  
  48.    public void uninstallUI(JComponent var1) {
  49.       var1.removePropertyChangeListener(this.lineStyleListener);
  50.       super.uninstallUI(var1);
  51.    }
  52.  
  53.    protected void decodeLineStyle(Object var1) {
  54.       if (var1 != null && !var1.equals("Horizontal")) {
  55.          if (var1.equals("Angled")) {
  56.             this.lineStyle = 2;
  57.          } else {
  58.             if (var1.equals("None")) {
  59.                this.lineStyle = 0;
  60.             }
  61.  
  62.          }
  63.       } else {
  64.          this.lineStyle = 1;
  65.       }
  66.    }
  67.  
  68.    protected boolean clickedInExpandControl(VisibleTreeNode var1, LargeTreeModelNode var2, int var3, int var4, int var5, int var6) {
  69.       if (var1 != null && var1.isLeaf()) {
  70.          return false;
  71.       } else {
  72.          int var7;
  73.          if (((BasicTreeUI)this).getExpandedIcon() != null) {
  74.             var7 = ((BasicTreeUI)this).getExpandedIcon().getIconWidth() + 6;
  75.          } else {
  76.             var7 = 8;
  77.          }
  78.  
  79.          int var8;
  80.          if (((AbstractTreeUI)this).getShowsRootHandles()) {
  81.             var8 = var4 * super.totalChildIndent + ((BasicTreeUI)this).getLeftChildIndent() - var7 / 2;
  82.          } else {
  83.             var8 = (var4 - 1) * super.totalChildIndent + ((BasicTreeUI)this).getLeftChildIndent() - var7 / 2;
  84.          }
  85.  
  86.          int var9 = var8 + var7;
  87.          return var5 >= var8 && var5 <= var9;
  88.       }
  89.    }
  90.  
  91.    public void paint(Graphics var1, JComponent var2) {
  92.       super.paint(var1, var2);
  93.       if (this.lineStyle == 1) {
  94.          this.paintHorizontalSeparators(var1, var2);
  95.       }
  96.  
  97.    }
  98.  
  99.    protected void paintHorizontalSeparators(Graphics var1, JComponent var2) {
  100.       var1.setColor(lineColor);
  101.       Rectangle var3 = var1.getClipBounds();
  102.       int var4 = ((AbstractTreeUI)this).getRowContainingYLocation(var3.y);
  103.       int var5 = ((AbstractTreeUI)this).getRowContainingYLocation(var3.y + (var3.height - 1));
  104.       if (var4 > -1 && var5 > -1) {
  105.          for(int var6 = var4; var6 <= var5; ++var6) {
  106.             VisibleTreeNode var7 = ((AbstractTreeUI)this).getNode(var6);
  107.             if (((DefaultMutableTreeNode)var7).getParent() == ((DefaultMutableTreeNode)var7).getRoot()) {
  108.                var1.drawLine(var3.x, ((BasicTreeUI)this).getNodeY(var7), var3.x + var3.width, ((BasicTreeUI)this).getNodeY(var7));
  109.             }
  110.          }
  111.  
  112.       }
  113.    }
  114.  
  115.    public void drawVerticalPartOfLeg(Graphics var1, JComponent var2, int var3, int var4, int var5, int var6, int var7) {
  116.       if (this.lineStyle == 2) {
  117.          super.drawVerticalPartOfLeg(var1, var2, var3, var4, var5, var6, var7);
  118.       }
  119.  
  120.    }
  121.  
  122.    public void drawHorizontalPartOfLeg(Graphics var1, JComponent var2, int var3, int var4, int var5) {
  123.       if (this.lineStyle == 2) {
  124.          super.drawHorizontalPartOfLeg(var1, var2, var3, var4, var5);
  125.       }
  126.  
  127.    }
  128.  
  129.    // $FF: synthetic method
  130.    static String access$0() {
  131.       return "JTree.lineStyle";
  132.    }
  133. }
  134.