home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &… the Search for Life CD 3 / 0_CD-ROM.iso / install / jre1_3 / lib / rt.jar / javax / swing / tree / VariableHeightLayoutCache$TreeStateNode.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  6.9 KB  |  460 lines

  1. package javax.swing.tree;
  2.  
  3. import java.awt.Rectangle;
  4. import java.util.Enumeration;
  5. import java.util.Vector;
  6.  
  7. class VariableHeightLayoutCache$TreeStateNode extends DefaultMutableTreeNode {
  8.    protected int preferredWidth;
  9.    protected int preferredHeight;
  10.    protected int xOrigin;
  11.    protected int yOrigin;
  12.    protected boolean expanded;
  13.    protected boolean hasBeenExpanded;
  14.    protected TreePath path;
  15.    // $FF: synthetic field
  16.    private final VariableHeightLayoutCache this$0;
  17.  
  18.    public VariableHeightLayoutCache$TreeStateNode(VariableHeightLayoutCache var1, Object var2) {
  19.       super(var2);
  20.       this.this$0 = var1;
  21.    }
  22.  
  23.    public void setParent(MutableTreeNode var1) {
  24.       super.setParent(var1);
  25.       if (var1 != null) {
  26.          this.path = ((VariableHeightLayoutCache$TreeStateNode)var1).getTreePath().pathByAddingChild(((DefaultMutableTreeNode)this).getUserObject());
  27.          VariableHeightLayoutCache.access$000(this.this$0, this);
  28.       }
  29.  
  30.    }
  31.  
  32.    public void remove(int var1) {
  33.       VariableHeightLayoutCache$TreeStateNode var2 = (VariableHeightLayoutCache$TreeStateNode)((DefaultMutableTreeNode)this).getChildAt(var1);
  34.       var2.removeFromMapping();
  35.       super.remove(var1);
  36.    }
  37.  
  38.    public void setUserObject(Object var1) {
  39.       super.setUserObject(var1);
  40.       if (this.path != null) {
  41.          VariableHeightLayoutCache$TreeStateNode var2 = (VariableHeightLayoutCache$TreeStateNode)((DefaultMutableTreeNode)this).getParent();
  42.          if (var2 != null) {
  43.             this.resetChildrenPaths(var2.getTreePath());
  44.          } else {
  45.             this.resetChildrenPaths((TreePath)null);
  46.          }
  47.       }
  48.  
  49.    }
  50.  
  51.    public Enumeration children() {
  52.       return !this.isExpanded() ? DefaultMutableTreeNode.EMPTY_ENUMERATION : super.children();
  53.    }
  54.  
  55.    public boolean isLeaf() {
  56.       return this.this$0.getModel().isLeaf(this.getValue());
  57.    }
  58.  
  59.    public Rectangle getNodeBounds(Rectangle var1) {
  60.       if (var1 == null) {
  61.          var1 = new Rectangle(this.getXOrigin(), this.getYOrigin(), this.getPreferredWidth(), this.getPreferredHeight());
  62.       } else {
  63.          var1.x = this.getXOrigin();
  64.          var1.y = this.getYOrigin();
  65.          var1.width = this.getPreferredWidth();
  66.          var1.height = this.getPreferredHeight();
  67.       }
  68.  
  69.       return var1;
  70.    }
  71.  
  72.    public int getXOrigin() {
  73.       if (!this.hasValidSize()) {
  74.          this.updatePreferredSize(this.getRow());
  75.       }
  76.  
  77.       return this.xOrigin;
  78.    }
  79.  
  80.    public int getYOrigin() {
  81.       if (this.this$0.isFixedRowHeight()) {
  82.          int var1 = this.getRow();
  83.          return var1 == -1 ? -1 : this.this$0.getRowHeight() * var1;
  84.       } else {
  85.          return this.yOrigin;
  86.       }
  87.    }
  88.  
  89.    public int getPreferredHeight() {
  90.       if (this.this$0.isFixedRowHeight()) {
  91.          return this.this$0.getRowHeight();
  92.       } else {
  93.          if (!this.hasValidSize()) {
  94.             this.updatePreferredSize(this.getRow());
  95.          }
  96.  
  97.          return this.preferredHeight;
  98.       }
  99.    }
  100.  
  101.    public int getPreferredWidth() {
  102.       if (!this.hasValidSize()) {
  103.          this.updatePreferredSize(this.getRow());
  104.       }
  105.  
  106.       return this.preferredWidth;
  107.    }
  108.  
  109.    public boolean hasValidSize() {
  110.       return this.preferredHeight != 0;
  111.    }
  112.  
  113.    public int getRow() {
  114.       return VariableHeightLayoutCache.access$100(this.this$0).indexOf(this);
  115.    }
  116.  
  117.    public boolean hasBeenExpanded() {
  118.       return this.hasBeenExpanded;
  119.    }
  120.  
  121.    public boolean isExpanded() {
  122.       return this.expanded;
  123.    }
  124.  
  125.    public VariableHeightLayoutCache$TreeStateNode getLastVisibleNode() {
  126.       VariableHeightLayoutCache$TreeStateNode var1;
  127.       for(var1 = this; var1.isExpanded() && ((DefaultMutableTreeNode)var1).getChildCount() > 0; var1 = (VariableHeightLayoutCache$TreeStateNode)((DefaultMutableTreeNode)var1).getLastChild()) {
  128.       }
  129.  
  130.       return var1;
  131.    }
  132.  
  133.    public boolean isVisible() {
  134.       if (this == VariableHeightLayoutCache.access$200(this.this$0)) {
  135.          return true;
  136.       } else {
  137.          VariableHeightLayoutCache$TreeStateNode var1 = (VariableHeightLayoutCache$TreeStateNode)((DefaultMutableTreeNode)this).getParent();
  138.          return var1 != null && var1.isExpanded() && var1.isVisible();
  139.       }
  140.    }
  141.  
  142.    public int getModelChildCount() {
  143.       return this.hasBeenExpanded ? super.getChildCount() : this.this$0.getModel().getChildCount(this.getValue());
  144.    }
  145.  
  146.    public int getVisibleChildCount() {
  147.       int var1 = 0;
  148.       if (this.isExpanded()) {
  149.          int var2 = ((DefaultMutableTreeNode)this).getChildCount();
  150.          var1 += var2;
  151.  
  152.          for(int var3 = 0; var3 < var2; ++var3) {
  153.             var1 += ((VariableHeightLayoutCache$TreeStateNode)((DefaultMutableTreeNode)this).getChildAt(var3)).getVisibleChildCount();
  154.          }
  155.       }
  156.  
  157.       return var1;
  158.    }
  159.  
  160.    public void toggleExpanded() {
  161.       if (this.isExpanded()) {
  162.          this.collapse();
  163.       } else {
  164.          this.expand();
  165.       }
  166.  
  167.    }
  168.  
  169.    public void makeVisible() {
  170.       VariableHeightLayoutCache$TreeStateNode var1 = (VariableHeightLayoutCache$TreeStateNode)((DefaultMutableTreeNode)this).getParent();
  171.       if (var1 != null) {
  172.          var1.expandParentAndReceiver();
  173.       }
  174.  
  175.    }
  176.  
  177.    public void expand() {
  178.       this.expand(true);
  179.    }
  180.  
  181.    public void collapse() {
  182.       this.collapse(true);
  183.    }
  184.  
  185.    public Object getValue() {
  186.       return ((DefaultMutableTreeNode)this).getUserObject();
  187.    }
  188.  
  189.    public TreePath getTreePath() {
  190.       return this.path;
  191.    }
  192.  
  193.    protected void resetChildrenPaths(TreePath var1) {
  194.       VariableHeightLayoutCache.access$300(this.this$0, this);
  195.       if (var1 == null) {
  196.          this.path = new TreePath(((DefaultMutableTreeNode)this).getUserObject());
  197.       } else {
  198.          this.path = var1.pathByAddingChild(((DefaultMutableTreeNode)this).getUserObject());
  199.       }
  200.  
  201.       VariableHeightLayoutCache.access$000(this.this$0, this);
  202.  
  203.       for(int var2 = ((DefaultMutableTreeNode)this).getChildCount() - 1; var2 >= 0; --var2) {
  204.          ((VariableHeightLayoutCache$TreeStateNode)((DefaultMutableTreeNode)this).getChildAt(var2)).resetChildrenPaths(this.path);
  205.       }
  206.  
  207.    }
  208.  
  209.    protected void setYOrigin(int var1) {
  210.       this.yOrigin = var1;
  211.    }
  212.  
  213.    protected void shiftYOriginBy(int var1) {
  214.       this.yOrigin += var1;
  215.    }
  216.  
  217.    protected void updatePreferredSize() {
  218.       this.updatePreferredSize(this.getRow());
  219.    }
  220.  
  221.    protected void updatePreferredSize(int var1) {
  222.       Rectangle var2 = this.this$0.getNodeDimensions(((DefaultMutableTreeNode)this).getUserObject(), var1, ((DefaultMutableTreeNode)this).getLevel(), this.isExpanded(), VariableHeightLayoutCache.access$400(this.this$0));
  223.       if (var2 == null) {
  224.          this.xOrigin = 0;
  225.          this.preferredWidth = this.preferredHeight = 0;
  226.          VariableHeightLayoutCache.access$502(this.this$0, true);
  227.       } else if (var2.height == 0) {
  228.          this.xOrigin = 0;
  229.          this.preferredWidth = this.preferredHeight = 0;
  230.          VariableHeightLayoutCache.access$502(this.this$0, true);
  231.       } else {
  232.          this.xOrigin = var2.x;
  233.          this.preferredWidth = var2.width;
  234.          if (this.this$0.isFixedRowHeight()) {
  235.             this.preferredHeight = this.this$0.getRowHeight();
  236.          } else {
  237.             this.preferredHeight = var2.height;
  238.          }
  239.       }
  240.  
  241.    }
  242.  
  243.    protected void markSizeInvalid() {
  244.       this.preferredHeight = 0;
  245.    }
  246.  
  247.    protected void deepMarkSizeInvalid() {
  248.       this.markSizeInvalid();
  249.  
  250.       for(int var1 = ((DefaultMutableTreeNode)this).getChildCount() - 1; var1 >= 0; --var1) {
  251.          ((VariableHeightLayoutCache$TreeStateNode)((DefaultMutableTreeNode)this).getChildAt(var1)).deepMarkSizeInvalid();
  252.       }
  253.  
  254.    }
  255.  
  256.    protected Enumeration getLoadedChildren(boolean var1) {
  257.       if (var1 && !this.hasBeenExpanded) {
  258.          Object var3 = this.getValue();
  259.          TreeModel var4 = this.this$0.getModel();
  260.          int var5 = var4.getChildCount(var3);
  261.          this.hasBeenExpanded = true;
  262.          int var6 = this.getRow();
  263.          if (var6 == -1) {
  264.             for(int var7 = 0; var7 < var5; ++var7) {
  265.                VariableHeightLayoutCache$TreeStateNode var2 = VariableHeightLayoutCache.access$600(this.this$0, var4.getChild(var3, var7));
  266.                ((DefaultMutableTreeNode)this).add(var2);
  267.                var2.updatePreferredSize(-1);
  268.             }
  269.          } else {
  270.             ++var6;
  271.  
  272.             for(int var10 = 0; var10 < var5; ++var10) {
  273.                VariableHeightLayoutCache$TreeStateNode var8 = VariableHeightLayoutCache.access$600(this.this$0, var4.getChild(var3, var10));
  274.                ((DefaultMutableTreeNode)this).add(var8);
  275.                var8.updatePreferredSize(var6++);
  276.             }
  277.          }
  278.  
  279.          return super.children();
  280.       } else {
  281.          return super.children();
  282.       }
  283.    }
  284.  
  285.    protected void didAdjustTree() {
  286.    }
  287.  
  288.    protected void expandParentAndReceiver() {
  289.       VariableHeightLayoutCache$TreeStateNode var1 = (VariableHeightLayoutCache$TreeStateNode)((DefaultMutableTreeNode)this).getParent();
  290.       if (var1 != null) {
  291.          var1.expandParentAndReceiver();
  292.       }
  293.  
  294.       this.expand();
  295.    }
  296.  
  297.    protected void expand(boolean var1) {
  298.       if (!this.isExpanded() && !this.isLeaf()) {
  299.          boolean var2 = this.this$0.isFixedRowHeight();
  300.          int var3 = this.getPreferredHeight();
  301.          int var4 = this.getRow();
  302.          this.expanded = true;
  303.          this.updatePreferredSize(var4);
  304.          if (!this.hasBeenExpanded) {
  305.             Object var6 = this.getValue();
  306.             TreeModel var7 = this.this$0.getModel();
  307.             int var8 = var7.getChildCount(var6);
  308.             this.hasBeenExpanded = true;
  309.             if (var4 == -1) {
  310.                for(int var18 = 0; var18 < var8; ++var18) {
  311.                   VariableHeightLayoutCache$TreeStateNode var11 = VariableHeightLayoutCache.access$600(this.this$0, var7.getChild(var6, var18));
  312.                   ((DefaultMutableTreeNode)this).add(var11);
  313.                   var11.updatePreferredSize(-1);
  314.                }
  315.             } else {
  316.                int var9 = var4 + 1;
  317.  
  318.                for(int var10 = 0; var10 < var8; ++var10) {
  319.                   VariableHeightLayoutCache$TreeStateNode var5 = VariableHeightLayoutCache.access$600(this.this$0, var7.getChild(var6, var10));
  320.                   ((DefaultMutableTreeNode)this).add(var5);
  321.                   var5.updatePreferredSize(var9);
  322.                }
  323.             }
  324.          }
  325.  
  326.          int var12 = var4;
  327.          Enumeration var14 = ((DefaultMutableTreeNode)this).preorderEnumeration();
  328.          var14.nextElement();
  329.          int var15;
  330.          if (var2) {
  331.             var15 = 0;
  332.          } else if (this == VariableHeightLayoutCache.access$200(this.this$0) && !this.this$0.isRootVisible()) {
  333.             var15 = 0;
  334.          } else {
  335.             var15 = this.getYOrigin() + this.getPreferredHeight();
  336.          }
  337.  
  338.          if (!var2) {
  339.             while(var14.hasMoreElements()) {
  340.                VariableHeightLayoutCache$TreeStateNode var17 = (VariableHeightLayoutCache$TreeStateNode)var14.nextElement();
  341.                if (!VariableHeightLayoutCache.access$500(this.this$0) && !var17.hasValidSize()) {
  342.                   var17.updatePreferredSize(var12 + 1);
  343.                }
  344.  
  345.                var17.setYOrigin(var15);
  346.                var15 += var17.getPreferredHeight();
  347.                Vector var21 = VariableHeightLayoutCache.access$100(this.this$0);
  348.                ++var12;
  349.                var21.insertElementAt(var17, var12);
  350.             }
  351.          } else {
  352.             while(var14.hasMoreElements()) {
  353.                VariableHeightLayoutCache$TreeStateNode var16 = (VariableHeightLayoutCache$TreeStateNode)var14.nextElement();
  354.                Vector var10000 = VariableHeightLayoutCache.access$100(this.this$0);
  355.                ++var12;
  356.                var10000.insertElementAt(var16, var12);
  357.             }
  358.          }
  359.  
  360.          if (var1 && (var4 != var12 || this.getPreferredHeight() != var3)) {
  361.             if (!var2) {
  362.                ++var12;
  363.                if (var12 < this.this$0.getRowCount()) {
  364.                   int var20 = var15 - (this.getYOrigin() + this.getPreferredHeight()) + (this.getPreferredHeight() - var3);
  365.  
  366.                   for(int var19 = VariableHeightLayoutCache.access$100(this.this$0).size() - 1; var19 >= var12; --var19) {
  367.                      ((VariableHeightLayoutCache$TreeStateNode)VariableHeightLayoutCache.access$100(this.this$0).elementAt(var19)).shiftYOriginBy(var20);
  368.                   }
  369.                }
  370.             }
  371.  
  372.             this.didAdjustTree();
  373.             VariableHeightLayoutCache.access$700(this.this$0);
  374.          }
  375.  
  376.          if (this.this$0.treeSelectionModel != null) {
  377.             this.this$0.treeSelectionModel.resetRowSelection();
  378.          }
  379.       }
  380.  
  381.    }
  382.  
  383.    protected void collapse(boolean var1) {
  384.       if (this.isExpanded()) {
  385.          Enumeration var2 = ((DefaultMutableTreeNode)this).preorderEnumeration();
  386.          var2.nextElement();
  387.          int var3 = 0;
  388.          boolean var4 = this.this$0.isFixedRowHeight();
  389.          int var5;
  390.          if (var4) {
  391.             var5 = 0;
  392.          } else {
  393.             var5 = this.getPreferredHeight() + this.getYOrigin();
  394.          }
  395.  
  396.          int var6 = this.getPreferredHeight();
  397.          int var7 = var5;
  398.          int var8 = this.getRow();
  399.          if (!var4) {
  400.             while(var2.hasMoreElements()) {
  401.                VariableHeightLayoutCache$TreeStateNode var14 = (VariableHeightLayoutCache$TreeStateNode)var2.nextElement();
  402.                if (var14.isVisible()) {
  403.                   ++var3;
  404.                   var5 = var14.getYOrigin() + var14.getPreferredHeight();
  405.                }
  406.             }
  407.          } else {
  408.             while(var2.hasMoreElements()) {
  409.                VariableHeightLayoutCache$TreeStateNode var9 = (VariableHeightLayoutCache$TreeStateNode)var2.nextElement();
  410.                if (var9.isVisible()) {
  411.                   ++var3;
  412.                }
  413.             }
  414.          }
  415.  
  416.          for(int var15 = var3 + var8; var15 > var8; --var15) {
  417.             VariableHeightLayoutCache.access$100(this.this$0).removeElementAt(var15);
  418.          }
  419.  
  420.          this.expanded = false;
  421.          if (var8 == -1) {
  422.             this.markSizeInvalid();
  423.          } else if (var1) {
  424.             this.updatePreferredSize(var8);
  425.          }
  426.  
  427.          if (var8 != -1 && var1 && (var3 > 0 || var6 != this.getPreferredHeight())) {
  428.             var7 += this.getPreferredHeight() - var6;
  429.             if (!var4 && var8 + 1 < this.this$0.getRowCount() && var7 != var5) {
  430.                int var12 = var7 - var5;
  431.                int var10 = var8 + 1;
  432.  
  433.                for(int var11 = VariableHeightLayoutCache.access$100(this.this$0).size(); var10 < var11; ++var10) {
  434.                   ((VariableHeightLayoutCache$TreeStateNode)VariableHeightLayoutCache.access$100(this.this$0).elementAt(var10)).shiftYOriginBy(var12);
  435.                }
  436.             }
  437.  
  438.             this.didAdjustTree();
  439.             VariableHeightLayoutCache.access$700(this.this$0);
  440.          }
  441.  
  442.          if (this.this$0.treeSelectionModel != null && var3 > 0 && var8 != -1) {
  443.             this.this$0.treeSelectionModel.resetRowSelection();
  444.          }
  445.       }
  446.  
  447.    }
  448.  
  449.    protected void removeFromMapping() {
  450.       if (this.path != null) {
  451.          VariableHeightLayoutCache.access$300(this.this$0, this);
  452.  
  453.          for(int var1 = ((DefaultMutableTreeNode)this).getChildCount() - 1; var1 >= 0; --var1) {
  454.             ((VariableHeightLayoutCache$TreeStateNode)((DefaultMutableTreeNode)this).getChildAt(var1)).removeFromMapping();
  455.          }
  456.       }
  457.  
  458.    }
  459. }
  460.