home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 144 / DPCS0200.iso / Internet / Supanet / system / swing.jar / javax / swing / plaf / metal / MetalTreeUI.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-05  |  4.0 KB  |  120 lines

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