home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Java / JDesignerPro / Jdp3_0.exe / data1.cab / Program_Files / JDPMethodTree.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-04-09  |  6.6 KB  |  447 lines

  1. import java.awt.Event;
  2. import java.awt.Panel;
  3. import java.util.Date;
  4.  
  5. public class JDPMethodTree extends JDPTreePicker {
  6.    JDPSourceItem classHeader;
  7.    JDPTreeBranch globalBranch;
  8.    JDPTreeBranch constructorBranch;
  9.    JDPTreeBranch accessorBranch;
  10.    JDPTreeBranch generalBranch;
  11.    JDPTreeBranch publicBranch;
  12.    JDPTreeBranch privateBranch;
  13.    boolean displayParmTypes = true;
  14.    boolean displayParmNames = true;
  15.  
  16.    public boolean saveSource(String var1, String var2) {
  17.       boolean var3 = super.user.u.writeToFile(var1, this.getCompleteSource(var2), "w+");
  18.       if (var3) {
  19.          super.user.mainmsg.setStatusMsg("Source file successfully saved.", 10);
  20.       } else {
  21.          super.user.mainmsg.setStatusMsg("Write to source file failed.", 10);
  22.       }
  23.  
  24.       return var3;
  25.    }
  26.  
  27.    public void setSource(String var1) {
  28.       JDPTreeBranch var2 = ((JDPTreePicker)this).getCurrentBranch();
  29.       if (var2 != null && var2.thisObject != null) {
  30.          JDPSourceItem var3 = (JDPSourceItem)var2.thisObject;
  31.          var3.actualSource = var1;
  32.       }
  33.    }
  34.  
  35.    public void selectItemWithSourceLine(int var1) {
  36.       JDPSourceItem var5 = null;
  37.       JDPTreeBranch var2 = super.treeRoot;
  38.       if (var2 != null) {
  39.          JDPSourceItem var6 = (JDPSourceItem)var2.thisObject;
  40.  
  41.          for(int var7 = 0; var7 < var2.leaves.size(); ++var7) {
  42.             JDPTreeBranch var3 = (JDPTreeBranch)var2.leaves.elementAt(var7);
  43.  
  44.             for(int var8 = 0; var8 < var3.leaves.size(); ++var8) {
  45.                JDPTreeBranch var4 = (JDPTreeBranch)var3.leaves.elementAt(var8);
  46.                var6 = (JDPSourceItem)var4.thisObject;
  47.                if (var6.startingLineNumber > var1) {
  48.                   if (var5 != null) {
  49.                      this.select(var5);
  50.                   }
  51.  
  52.                   return;
  53.                }
  54.  
  55.                var5 = var6;
  56.             }
  57.          }
  58.  
  59.          if (var5 != null) {
  60.             this.select(var5);
  61.          }
  62.  
  63.       }
  64.    }
  65.  
  66.    public void setClassDescriptor(JDPSourceItem var1) {
  67.       this.classHeader = var1;
  68.       ((JDPTreePicker)this).setRoot(var1.name, true, 9);
  69.       super.treeRoot.thisObject = var1;
  70.       ((JDPTreePicker)this).addBranch(super.treeRoot, "Global Variables", 4);
  71.       ((JDPTreePicker)this).addBranch(super.treeRoot, "Constructors", 7);
  72.       ((JDPTreePicker)this).addBranch(super.treeRoot, "Accessors", 1);
  73.       ((JDPTreePicker)this).addBranch(super.treeRoot, "Public", 1);
  74.       ((JDPTreePicker)this).addBranch(super.treeRoot, "Methods", 0);
  75.       ((JDPTreePicker)this).addBranch(super.treeRoot, "Private", 2);
  76.       this.globalBranch = ((JDPTreePicker)this).getBranch("Global Variables");
  77.       this.constructorBranch = ((JDPTreePicker)this).getBranch("Constructors");
  78.       this.accessorBranch = ((JDPTreePicker)this).getBranch("Accessors");
  79.       this.generalBranch = ((JDPTreePicker)this).getBranch("Methods");
  80.       this.publicBranch = ((JDPTreePicker)this).getBranch("Public");
  81.       this.privateBranch = ((JDPTreePicker)this).getBranch("Private");
  82.  
  83.       for(int var3 = 0; var3 < var1.components.size(); ++var3) {
  84.          JDPSourceItem var2 = (JDPSourceItem)var1.components.elementAt(var3);
  85.          this.addItem(var2);
  86.       }
  87.  
  88.       ((JDPTreePicker)this).sortTree(this.globalBranch);
  89.       ((JDPTreePicker)this).sortTree(this.constructorBranch);
  90.       ((JDPTreePicker)this).sortTree(this.accessorBranch);
  91.       ((JDPTreePicker)this).sortTree(this.generalBranch);
  92.       ((JDPTreePicker)this).sortTree(this.publicBranch);
  93.       ((JDPTreePicker)this).sortTree(this.privateBranch);
  94.       ((JDPTreePicker)this).select(super.treeRoot);
  95.       ((JDPTreePicker)this).reDraw();
  96.    }
  97.  
  98.    void moveItem(JDPTreeBranch var1, JDPTreeBranch var2, JDPTreeBranch var3) {
  99.       var1.leaves.removeElement(var3);
  100.       ((JDPTreePicker)this).addBranch(var2, this.constructName((JDPSourceItem)var3.thisObject), this.chooseIcon((JDPSourceItem)var3.thisObject));
  101.       JDPTreeBranch var4 = ((JDPTreePicker)this).getLastAddedBranch();
  102.       var4.thisObject = var3.thisObject;
  103.       var3.thisObject = null;
  104.       Object var5 = null;
  105.       ((JDPTreePicker)this).sortTree(var1);
  106.       ((JDPTreePicker)this).sortTree(var2);
  107.       ((JDPTreePicker)this).select(var4);
  108.    }
  109.  
  110.    String constructName(JDPSourceItem var1) {
  111.       String var2 = var1.name;
  112.       if (var1.type == 3) {
  113.          var2 = var2 + "(" + var1.varType + ")";
  114.       } else if (var1.type == 1 || var1.type == 2) {
  115.          var2 = var2 + "(";
  116.          if (var1.parmTypes != null) {
  117.             for(int var3 = 0; var3 < var1.parmTypes.size(); ++var3) {
  118.                if (var3 > 0) {
  119.                   var2 = var2 + ", ";
  120.                }
  121.  
  122.                if (this.displayParmTypes) {
  123.                   var2 = var2 + (String)var1.parmTypes.elementAt(var3);
  124.                }
  125.  
  126.                if (this.displayParmNames && this.displayParmTypes) {
  127.                   var2 = var2 + " ";
  128.                }
  129.  
  130.                if (this.displayParmNames && var1.parmNames.size() > var3) {
  131.                   var2 = var2 + (String)var1.parmNames.elementAt(var3);
  132.                }
  133.             }
  134.          }
  135.  
  136.          var2 = var2 + ")";
  137.       }
  138.  
  139.       return var2;
  140.    }
  141.  
  142.    int chooseIcon(JDPSourceItem var1) {
  143.       int var2 = 0;
  144.       if (var1.isprivate) {
  145.          var2 += 2;
  146.       } else if (var1.ispublic) {
  147.          ++var2;
  148.       }
  149.  
  150.       if (var1.type == 3) {
  151.          var2 += 3;
  152.       }
  153.  
  154.       if (var1.type == 1) {
  155.          var2 += 6;
  156.       }
  157.  
  158.       if (var1.type == 0) {
  159.          var2 = 9;
  160.       }
  161.  
  162.       return var2;
  163.    }
  164.  
  165.    public void select(JDPSourceItem var1) {
  166.       JDPTreeBranch var2 = ((JDPTreePicker)this).getBranch((Object)var1);
  167.       if (var2 != null) {
  168.          ((JDPTreePicker)this).select(var2);
  169.       }
  170.  
  171.       ((JDPTreePicker)this).reDraw();
  172.    }
  173.  
  174.    public void changeAppName(String var1) {
  175.       JDPSourceItem var2 = (JDPSourceItem)super.treeRoot.thisObject;
  176.       var2.name = var1;
  177.       JDPSourceParser.reCreateHeader(var2);
  178.       this.refreshBranchFromItem(var2);
  179.  
  180.       for(int var4 = 0; var4 < var2.components.size(); ++var4) {
  181.          JDPSourceItem var3 = (JDPSourceItem)var2.components.elementAt(var4);
  182.          if (var3.type == 1) {
  183.             var3.name = var1;
  184.             JDPSourceParser.reCreateHeader(var3);
  185.             this.refreshBranchFromItem(var3);
  186.          }
  187.       }
  188.  
  189.    }
  190.  
  191.    public String getCompleteSource(String var1) {
  192.       StringBuffer var7 = new StringBuffer();
  193.       int var8 = 0;
  194.       JDPTreeBranch var2 = super.treeRoot;
  195.       if (var2 == null) {
  196.          return "";
  197.       } else {
  198.          JDPSourceItem var5 = (JDPSourceItem)var2.thisObject;
  199.          var5.name = var1;
  200.          var5.lastModified = new Date();
  201.          JDPSourceParser.reCreateHeader(var5);
  202.          this.refreshBranchFromItem(var5);
  203.  
  204.          for(int var9 = 0; var9 < var5.components.size(); ++var9) {
  205.             JDPSourceItem var6 = (JDPSourceItem)var5.components.elementAt(var9);
  206.             if (var6.type == 1) {
  207.                var6.name = var1;
  208.                JDPSourceParser.reCreateHeader(var6);
  209.                this.refreshBranchFromItem(var6);
  210.             }
  211.          }
  212.  
  213.          if (var5 != null && var5.actualSource != null) {
  214.             var7.append(var5.actualSource);
  215.             var7.append("\n");
  216.             var8 += this.countSourceLines(var5.actualSource) + 1;
  217.          }
  218.  
  219.          var5.startingLineNumber = 0;
  220.          int var14 = var5.type;
  221.  
  222.          for(int var10 = 0; var10 < var2.leaves.size(); ++var10) {
  223.             JDPTreeBranch var3 = (JDPTreeBranch)var2.leaves.elementAt(var10);
  224.  
  225.             for(int var11 = 0; var11 < var3.leaves.size(); ++var11) {
  226.                JDPTreeBranch var4 = (JDPTreeBranch)var3.leaves.elementAt(var11);
  227.                var5 = (JDPSourceItem)var4.thisObject;
  228.                if (var5.type != var14) {
  229.                   var7.append("\n");
  230.                   ++var8;
  231.                }
  232.  
  233.                var14 = var5.type;
  234.                if (var5 != null && var5.actualSource != null) {
  235.                   var7.append(var5.actualSource);
  236.                   var7.append("\n");
  237.                   ++var8;
  238.                   var5.startingLineNumber = var8;
  239.                   var8 += this.countSourceLines(var5.actualSource);
  240.                }
  241.             }
  242.          }
  243.  
  244.          var7.append("}\n");
  245.          super.treeRoot.name = var1;
  246.          ((JDPTreePicker)this).reDraw();
  247.          return var7.toString();
  248.       }
  249.    }
  250.  
  251.    public JDPMethodTree(JDPUser var1) {
  252.       super.showCompPosition = true;
  253.       ((JDPTreePicker)this).createTree(var1, (Panel)null, (JDPDragItem)null);
  254.       ((JDPTreePicker)this).setIconImagePath("Images/JDPSRCE.gif");
  255.       ((JDPTreePicker)this).setMinWidth(200);
  256.    }
  257.  
  258.    public JDPMethodTree(JDPUser var1, Panel var2) {
  259.       super.showCompPosition = true;
  260.       ((JDPTreePicker)this).createTree(var1, var2, (JDPDragItem)null);
  261.       ((JDPTreePicker)this).setIconImagePath("Images/JDPSRCE.gif");
  262.       ((JDPTreePicker)this).setMinWidth(200);
  263.    }
  264.  
  265.    public JDPMethodTree(JDPUser var1, Panel var2, JDPDragItem var3) {
  266.       super.showCompPosition = true;
  267.       ((JDPTreePicker)this).createTree(var1, var2, var3);
  268.       ((JDPTreePicker)this).setIconImagePath("Images/JDPSRCE.gif");
  269.       ((JDPTreePicker)this).setMinWidth(200);
  270.    }
  271.  
  272.    boolean addItem(JDPSourceItem var1) {
  273.       boolean var2 = false;
  274.       if (var1.type == 3) {
  275.          var2 = this.addItem(this.globalBranch, var1);
  276.       } else if (var1.type == 1) {
  277.          var2 = this.addItem(this.constructorBranch, var1);
  278.       } else if (var1.type == 2) {
  279.          if (var1.ispublic) {
  280.             if (!var1.name.startsWith("get") && !var1.name.startsWith("set") && !var1.name.startsWith("is")) {
  281.                var2 = this.addItem(this.publicBranch, var1);
  282.             } else {
  283.                var2 = this.addItem(this.accessorBranch, var1);
  284.             }
  285.          } else if (var1.isprivate) {
  286.             var2 = this.addItem(this.privateBranch, var1);
  287.          } else {
  288.             var2 = this.addItem(this.generalBranch, var1);
  289.          }
  290.       }
  291.  
  292.       this.checkIfUnsed();
  293.       return var2;
  294.    }
  295.  
  296.    boolean addItem(JDPTreeBranch var1, JDPSourceItem var2) {
  297.       if (((JDPTreePicker)this).getBranch(this.constructName(var2)) != null) {
  298.          return false;
  299.       } else {
  300.          ((JDPTreePicker)this).addBranch(var1, this.constructName(var2), this.chooseIcon(var2));
  301.          ((JDPTreePicker)this).getLastAddedBranch().thisObject = var2;
  302.          return true;
  303.       }
  304.    }
  305.  
  306.    void checkIfUnsed() {
  307.       JDPTreeBranch var1 = ((JDPTreePicker)this).getLastAddedBranch();
  308.       JDPSourceItem var2 = (JDPSourceItem)var1.thisObject;
  309.       var1.compPosition = "";
  310.       if (var2 != null) {
  311.          if (var2.node == null || var2.node.leftNodes == null) {
  312.             if (var2.type == 3 || var2.type == 2 && var2.isprivate) {
  313.                var1.compPosition = "UNUSED";
  314.             }
  315.  
  316.          }
  317.       }
  318.    }
  319.  
  320.    int countSourceLines(String var1) {
  321.       int var2 = 0;
  322.  
  323.       for(int var3 = var1.indexOf("\n"); var3 >= 0; var3 = var1.indexOf("\n", var3 + 1)) {
  324.          ++var2;
  325.       }
  326.  
  327.       return var2;
  328.    }
  329.  
  330.    public void setShowParmTypes(boolean var1) {
  331.       this.displayParmTypes = var1;
  332.       ((JDPTreePicker)this).reDraw();
  333.    }
  334.  
  335.    public boolean getShowParmTypes() {
  336.       return this.displayParmTypes;
  337.    }
  338.  
  339.    public void clear() {
  340.       ((JDPTreePicker)this).setRoot("", false, 9);
  341.    }
  342.  
  343.    public void setShowParmNames(boolean var1) {
  344.       this.displayParmNames = var1;
  345.       ((JDPTreePicker)this).reDraw();
  346.    }
  347.  
  348.    void recalcSourceLines() {
  349.       int var1 = 0;
  350.       JDPTreeBranch var2 = super.treeRoot;
  351.       JDPSourceItem var5 = (JDPSourceItem)var2.thisObject;
  352.       if (var5 != null && var5.actualSource != null) {
  353.          var1 += this.countSourceLines(var5.actualSource) + 1;
  354.       }
  355.  
  356.       var5.startingLineNumber = 0;
  357.       int var6 = var5.type;
  358.  
  359.       for(int var7 = 0; var7 < var2.leaves.size(); ++var7) {
  360.          JDPTreeBranch var3 = (JDPTreeBranch)var2.leaves.elementAt(var7);
  361.  
  362.          for(int var8 = 0; var8 < var3.leaves.size(); ++var8) {
  363.             JDPTreeBranch var4 = (JDPTreeBranch)var3.leaves.elementAt(var8);
  364.             var5 = (JDPSourceItem)var4.thisObject;
  365.             if (var5.type != var6) {
  366.                ++var1;
  367.             }
  368.  
  369.             var6 = var5.type;
  370.             if (var5 != null && var5.actualSource != null) {
  371.                ++var1;
  372.                var5.startingLineNumber = var1;
  373.                var1 += this.countSourceLines(var5.actualSource);
  374.             }
  375.          }
  376.       }
  377.  
  378.    }
  379.  
  380.    public boolean getShowParmNames() {
  381.       return this.displayParmNames;
  382.    }
  383.  
  384.    public boolean handleEvent(Event var1) {
  385.       return super.handleEvent(var1);
  386.    }
  387.  
  388.    public JDPSourceItem getSelectedSourceItem() {
  389.       JDPTreeBranch var1 = ((JDPTreePicker)this).getCurrentBranch();
  390.       return var1 != null ? (JDPSourceItem)var1.thisObject : null;
  391.    }
  392.  
  393.    public void refreshBranchFromItem(JDPSourceItem var1) {
  394.       JDPTreeBranch var2 = ((JDPTreePicker)this).getBranch((Object)var1);
  395.       if (var2 != null) {
  396.          var2.name = this.constructName(var1);
  397.          var2.icon = this.chooseIcon(var1);
  398.          this.checkItemPosition(var1);
  399.          ((JDPTreePicker)this).reDraw();
  400.       }
  401.  
  402.    }
  403.  
  404.    public void remove(JDPSourceItem var1) {
  405.       JDPTreeBranch var2 = ((JDPTreePicker)this).getBranch((Object)var1);
  406.       if (var2 != null) {
  407.          ((JDPTreePicker)this).removeTreeBranch(var2);
  408.          ((JDPTreePicker)this).reDraw();
  409.       }
  410.  
  411.    }
  412.  
  413.    void checkItemPosition(JDPSourceItem var1) {
  414.       if (var1.type == 2) {
  415.          JDPTreeBranch[] var2 = ((JDPTreePicker)this).getTreeBranch(var1);
  416.          if (var2 != null) {
  417.             int var3 = var2.length - 2;
  418.             if (var1.ispublic) {
  419.                if (!var1.name.startsWith("get") && !var1.name.startsWith("set") && !var1.name.startsWith("is")) {
  420.                   if (!var2[var3].equals(this.publicBranch)) {
  421.                      this.moveItem(var2[var3], this.publicBranch, var2[var3 + 1]);
  422.                      return;
  423.                   }
  424.                } else if (!var2[var3].equals(this.accessorBranch)) {
  425.                   this.moveItem(var2[var3], this.accessorBranch, var2[var3 + 1]);
  426.                   return;
  427.                }
  428.             } else {
  429.                if (var1.isprivate) {
  430.                   if (!var2[var3].equals(this.privateBranch)) {
  431.                      this.moveItem(var2[var3], this.privateBranch, var2[var3 + 1]);
  432.                   }
  433.  
  434.                   this.checkIfUnsed();
  435.                   return;
  436.                }
  437.  
  438.                if (!var2[var3].equals(this.generalBranch)) {
  439.                   this.moveItem(var2[var3], this.generalBranch, var2[var3 + 1]);
  440.                }
  441.             }
  442.          }
  443.       }
  444.  
  445.    }
  446. }
  447.