예제 #1
0
 // div and mult
 private static void rule_a(DefaultMutableTreeNode parent) {
   int counter = 0;
   DefaultMutableTreeNode node = new DefaultMutableTreeNode("B");
   parent.add(node);
   rule_b(node);
   counter++;
   String op = "";
   while (tokens.get(currentToken).getWord().equals("/")
       || tokens.get(currentToken).getWord().equals("*")) {
     op = tokens.get(currentToken).getWord();
     // get operator number
     String getOpNum = "";
     if (op.equals("/")) getOpNum = "5";
     else if (op.equals("*")) getOpNum = "4";
     node = new DefaultMutableTreeNode(tokens.get(currentToken).getWord());
     parent.add(node);
     node = new DefaultMutableTreeNode("B");
     parent.add(node);
     if (currentToken < tokens.size() - 1) currentToken++;
     rule_b(node);
     counter++;
     if (counter == 2) {
       CodeGenerator.addInstruction("OPR", getOpNum, "0");
       codeLine++;
       String x = SemanticAnalyzer.popStack();
       String y = SemanticAnalyzer.popStack();
       String result = SemanticAnalyzer.calculateCube(x, y, op);
       SemanticAnalyzer.pushStack(result);
       counter--;
     }
   }
 }
예제 #2
0
 // and
 private static void rule_x(DefaultMutableTreeNode parent) {
   int counter = 0;
   DefaultMutableTreeNode node = new DefaultMutableTreeNode("Y");
   parent.add(node);
   rule_y(node);
   counter++;
   while (tokens.get(currentToken).getWord().equals("&")) {
     node = new DefaultMutableTreeNode("&");
     parent.add(node);
     node = new DefaultMutableTreeNode("Y");
     parent.add(node);
     if (currentToken < tokens.size() - 1) currentToken++;
     rule_y(node);
     counter++;
     // if visited twice
     if (counter == 2) {
       CodeGenerator.addInstruction("OPR", "9", "0");
       codeLine++;
       String x = SemanticAnalyzer.popStack();
       String y = SemanticAnalyzer.popStack();
       String result = SemanticAnalyzer.calculateCube(x, y, "&");
       SemanticAnalyzer.pushStack(result);
       counter--;
     }
   }
 }
 @NotNull
 private DefaultMutableTreeNode addPackage(PsiPackage aPackage) {
   final String qualifiedPackageName = aPackage.getQualifiedName();
   final PsiPackage parentPackage = aPackage.getParentPackage();
   if (parentPackage == null) {
     final DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) myModel.getRoot();
     if (qualifiedPackageName.length() == 0) {
       rootNode.setUserObject(aPackage);
       return rootNode;
     } else {
       DefaultMutableTreeNode packageNode = findPackageNode(rootNode, qualifiedPackageName);
       if (packageNode != null) return packageNode;
       packageNode = new DefaultMutableTreeNode(aPackage);
       rootNode.add(packageNode);
       return packageNode;
     }
   } else {
     final DefaultMutableTreeNode parentNode = addPackage(parentPackage);
     DefaultMutableTreeNode packageNode = findPackageNode(parentNode, qualifiedPackageName);
     if (packageNode != null) {
       return packageNode;
     }
     packageNode = new DefaultMutableTreeNode(aPackage);
     parentNode.add(packageNode);
     return packageNode;
   }
 }
예제 #4
0
 // while
 private static void rule_while(DefaultMutableTreeNode parent) {
   DefaultMutableTreeNode node = new DefaultMutableTreeNode("while");
   parent.add(node);
   String start = "whileS" + labelNum;
   final int num = labelNum;
   String end = "whileE" + labelNum;
   labelNum++;
   CodeGenerator.addLabel(start, codeLine);
   if (tokens.get(currentToken).getWord().equals("(")) {
     node = new DefaultMutableTreeNode("(");
     parent.add(node);
     if (currentToken < tokens.size() - 1) currentToken++;
   }
   node = new DefaultMutableTreeNode("expression");
   parent.add(node);
   rule_expression(node);
   CodeGenerator.addInstruction("JMC", "#" + end, "false");
   codeLine++;
   int n = tokens.get(currentToken).getLine();
   String x = SemanticAnalyzer.popStack();
   if (!x.equals("BOOLEAN")) SemanticAnalyzer.error(gui, 3, n, "");
   if (tokens.get(currentToken).getWord().equals(")")) {
     node = new DefaultMutableTreeNode(")");
     parent.add(node);
     if (currentToken < tokens.size() - 1) currentToken++;
   }
   node = new DefaultMutableTreeNode("program");
   parent.add(node);
   rule_program(node);
   CodeGenerator.addInstruction("JMP", "#" + start, "0");
   codeLine++;
   CodeGenerator.addLabel("whileE" + num, codeLine);
 }
예제 #5
0
  public MsnTreeTest() {
    String[] tab = {"hello", "test", "blabla"};

    container = getContentPane();
    container.setLayout(null);

    eleve = new DefaultMutableTreeNode("MSN");

    worker = new DefaultMutableTreeNode("Worker");
    prof = new DefaultMutableTreeNode("Profs");

    for (int i = 0; i < tab.length; i++) {
      worker.add(new DefaultMutableTreeNode(tab[i]));
      prof.add(new DefaultMutableTreeNode(tab[i]));
    }
    //        worker.add(new DefaultMutableTreeNode("hello world2"));

    eleve.add(worker);
    eleve.add(prof);

    tree = new JTree(eleve);

    scroll = new JScrollPane(tree);
    scroll.setBounds(10, 10, 100, 100);

    container.add(scroll);

    setSize(300, 300);
    setLocation(200, 200);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);

    //        worker.add(n);

  }
  public void treeWillExpand(TreeExpansionEvent e) {

    // get the tree path which will be expanded
    TreePath path = e.getPath();
    if (path == null) {
      return;
    }

    // get the directory at the node
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
    File selDir = (File) node.getUserObject();

    // remove old entries
    if (node.getChildCount() > 0) {
      node.removeAllChildren();
    }

    // get all the subdirectories
    File childDirs[] = selDir.listFiles(this);
    if (childDirs == null) {
      return;
    }

    // add the subdirectories
    Arrays.sort(childDirs);
    for (int i = 0; i < childDirs.length; i++) {
      if (childDirs[i].isHidden()) {
        if (showHidden) {
          node.add(new DefaultMutableTreeNode(childDirs[i]));
        }
      } else {
        node.add(new DefaultMutableTreeNode(childDirs[i]));
      }
    }
  }
예제 #7
0
  private static boolean rule_B(DefaultMutableTreeNode parent) {
    boolean error;
    DefaultMutableTreeNode node;
    int flag = 0;
    String operator = "";
    if (currentToken < tokens.size() && tokens.get(currentToken).getWord().equals("-")) {
      node = new DefaultMutableTreeNode("-");
      parent.add(node);
      currentToken++;
      flag = 1;
      operator = "-";
      CodeGenerator.addInstruction("LIT", "0", "0");
    }

    node = new DefaultMutableTreeNode("C");
    parent.add(node);
    error = rule_C(node);
    if (flag == 1) {
      String s = SemanticAnalyzer.popStack();
      SemanticAnalyzer.pushStack(SemanticAnalyzer.calculateCube(s, operator));
      CodeGenerator.addInstruction("OPR", "3", "0");
      System.out.println("here");
    }
    return error;
  }
예제 #8
0
  private static boolean rule_Y(DefaultMutableTreeNode parent) {
    // System.out.println("Inside Y");
    int flag = 0;
    String operator = "";
    boolean error = false;
    DefaultMutableTreeNode node;
    if (currentToken < tokens.size() && tokens.get(currentToken).getWord().equals("!")) {
      node = new DefaultMutableTreeNode("!");
      parent.add(node);
      currentToken++;
      flag = 1;
      operator = "!";
    }
    node = new DefaultMutableTreeNode("R");
    parent.add(node);
    error = rule_R(node);
    if (flag == 1) {
      String s = SemanticAnalyzer.popStack();
      SemanticAnalyzer.pushStack(SemanticAnalyzer.calculateCube(s, operator));
      CodeGenerator.addInstruction("OPR", "10", "0");
      System.out.println("Here in Y");
    }

    return error;
  }
예제 #9
0
  private static boolean rule_X(DefaultMutableTreeNode parent) {

    int flag = 1;
    String operator = "";
    boolean error = false;
    DefaultMutableTreeNode node;
    node = new DefaultMutableTreeNode("Y");
    parent.add(node);
    error = rule_Y(node);

    while (currentToken < tokens.size() && tokens.get(currentToken).getWord().equals("&")) {
      node = new DefaultMutableTreeNode("&");
      parent.add(node);
      currentToken++;
      node = new DefaultMutableTreeNode("Y");
      parent.add(node);
      error = rule_Y(node);
      flag++;
      operator = "&";
      if (flag == 2) {
        String type1 = SemanticAnalyzer.popStack();
        String type2 = SemanticAnalyzer.popStack();
        System.out.println("result: " + SemanticAnalyzer.calculateCube(type1, type2, operator));
        SemanticAnalyzer.pushStack(SemanticAnalyzer.calculateCube(type1, type2, operator));
        CodeGenerator.addInstruction("OPR", "9", "0");
        flag = 1;

      } else flag = 1;
    }
    return error;
  }
예제 #10
0
  private static boolean rule_while(DefaultMutableTreeNode parent) {

    boolean error = false;
    DefaultMutableTreeNode node;

    node = new DefaultMutableTreeNode("while");
    parent.add(node);
    currentToken++;

    if (currentToken < tokens.size() && tokens.get(currentToken).getWord().equals("(")) {
      node = new DefaultMutableTreeNode("(");
      parent.add(node);
      currentToken++;
    } else {
      error(8);
      while (currentToken < tokens.size()
          && !(tokens.get(currentToken).getWord().equals("!")
              || tokens.get(currentToken).getWord().equals("-")
              || tokens.get(currentToken).getToken().equals("INTEGER")
              || tokens.get(currentToken).getToken().equals("OCTAL")
              || tokens.get(currentToken).getToken().equals("HEXADECIMAL")
              || tokens.get(currentToken).getToken().equals("BINARY")
              || tokens.get(currentToken).getToken().equals("STRING")
              || tokens.get(currentToken).getToken().equals("CHARACTER")
              || tokens.get(currentToken).getToken().equals("FLOAT")
              || tokens.get(currentToken).getToken().equals("IDENTIFIER")
              || tokens.get(currentToken).getWord().equals("true")
              || tokens.get(currentToken).getWord().equals("false")
              || tokens.get(currentToken).getWord().equals("(")
              || tokens.get(currentToken).getWord().equals(")"))) {
        currentToken++;
      }
    }

    node = new DefaultMutableTreeNode("expression");
    parent.add(node);
    error = rule_expression(node);
    String type = SemanticAnalyzer.popStack();
    if (!type.equals("boolean")) SemanticAnalyzer.error(getgui(), 3, getlineno(), "");
    if (tokens.get(currentToken).getWord().equals(")")) {
      node = new DefaultMutableTreeNode(")");
      parent.add(node);
      currentToken++;
    } else {
      error(7);
      while (currentToken < tokens.size() && !tokens.get(currentToken).getWord().equals("{")) {
        currentToken++;
      }
    }
    CodeGenerator.addInstruction("JMC", "e" + label_count, "false");
    label_count++;
    node = new DefaultMutableTreeNode("program");
    parent.add(node);
    error = rule_program(node);

    CodeGenerator.addInstruction("JMP", "e" + label_count, "0");

    label_count++;
    return error;
  }
예제 #11
0
  /**
   * @param args
   * @throws JDOMException
   * @throws IOException
   */
  private DefaultMutableTreeNode armarArbol(String nameFile) throws IOException, JDOMException {
    File file = new File(nameFile);
    System.out.println("File name: " + file.getName());
    LeerXML xml = new LeerXML();
    HashSet<DtoXmlTree> dtoList = new HashSet<DtoXmlTree>();

    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Clases");
    dtoList = xml.LeerXML(file);
    this.setDtoList(dtoList);
    for (DtoXmlTree dt : dtoList) {
      DefaultMutableTreeNode clase =
          new DefaultMutableTreeNode(UtilTestGen.parsearTest(dt.getClassName()));
      System.out.println("Class name: " + dt.getClassName());
      root.add(clase);
      HashSet<String> metodos = new HashSet<String>();
      metodos = dt.getMetodoNameParam();
      for (String met : metodos) {
        DefaultMutableTreeNode metodo = new DefaultMutableTreeNode(UtilTestGen.parsearTest(met));
        clase.add(metodo);
        System.out.println("metodo Name : " + met);
      }
    }
    System.out.println("Root Name : " + root.getRoot());
    return root;
  }
예제 #12
0
 public static void refreshTree() {
   AgentsTree.AgentTree = new javax.swing.tree.DefaultMutableTreeNode("Agents");
   int i = 1;
   for (ArrayList<Modules.Agent> AllP : Modules.Agent.getAgentsGroups()) {
     DefaultMutableTreeNode node = new DefaultMutableTreeNode("Group (" + i++ + ")");
     DefaultMutableTreeNode node0;
     DefaultMutableTreeNode node1;
     DefaultMutableTreeNode node2;
     for (Modules.Agent a : AllP) {
       node0 = new DefaultMutableTreeNode("Agent" + a.getId());
       node1 = new DefaultMutableTreeNode("Name: " + a.getName());
       String prop = "Properties: ";
       boolean f = false;
       for (Modules.Property p : a.getProperties()) {
         if (f) {
           prop += ", ";
         } else {
           f = !f;
         }
         prop += p.getName() + "=" + p.getName() + "" + p.getMeteric();
       }
       node2 = new DefaultMutableTreeNode(prop);
       node0.add(node1);
       node0.add(node2);
       node.add(node0);
     }
     AgentsTree.AgentTree.add(node);
   }
   AgentsTree.jTree1.setModel(new DefaultTreeModel(AgentsTree.AgentTree));
 }
예제 #13
0
  /**
   * Recursively rebuild the tree nodes.
   *
   * @param root The full abstract path to the root saved layout directory.
   * @param local The current directory relative to root (null if none).
   * @param tnode The current parent tree node.
   */
  private void rebuildTreeModel(Path root, Path local, DefaultMutableTreeNode tnode) {
    TreeSet<Path> subdirs = new TreeSet<Path>();
    TreeSet<String> layouts = new TreeSet<String>();
    {
      Path current = new Path(root, local);
      File files[] = current.toFile().listFiles();
      if (files != null) {
        int wk;
        for (wk = 0; wk < files.length; wk++) {
          String name = files[wk].getName();
          if (files[wk].isDirectory()) subdirs.add(new Path(local, name));
          else if (files[wk].isFile()) layouts.add(name);
        }
      }
    }

    for (Path subdir : subdirs) {
      TreeData data = new TreeData(subdir);
      DefaultMutableTreeNode child = new DefaultMutableTreeNode(data, true);
      tnode.add(child);

      rebuildTreeModel(root, subdir, child);
    }

    for (String lname : layouts) {
      TreeData data = new TreeData(new Path(local, lname), lname);
      DefaultMutableTreeNode child = new DefaultMutableTreeNode(data, false);
      tnode.add(child);
    }
  }
예제 #14
0
  /** Add nodes from under "dir" into curTop. Highly recursive. */
  DefaultMutableTreeNode addNodes(DefaultMutableTreeNode curTop, File dir) {

    String curPath = dir.getPath();
    DefaultMutableTreeNode curDir = new DefaultMutableTreeNode(curPath);
    if (curTop != null) { // should only be null at root
      curTop.add(curDir);
    }
    Vector<String> ol = new Vector<String>();
    String[] tmp = dir.list();

    for (String aTmp : tmp) ol.addElement(aTmp);

    Collections.sort(ol, String.CASE_INSENSITIVE_ORDER);
    File f;
    Vector<String> files = new Vector<String>();
    // Make two passes, one for Dirs and one for Files. This is #1.
    for (int i = 0; i < ol.size(); i++) {
      String thisObject = ol.elementAt(i);
      String newPath;
      if (curPath.equals(".")) newPath = thisObject;
      else newPath = curPath + File.separator + thisObject;
      if ((f = new File(newPath)).isDirectory()) addNodes(curDir, f);
      else files.addElement(thisObject);
    }
    // Pass two: for files.
    for (int fnum = 0; fnum < files.size(); fnum++)
      curDir.add(new DefaultMutableTreeNode(files.elementAt(fnum)));
    return curDir;
  }
예제 #15
0
파일: Parser.java 프로젝트: jtribble/java
  /**
   * Rule: A
   *
   * @param DefaultMutableTreeNode parent
   * @return String
   */
  private static String rule_a(DefaultMutableTreeNode parent) {
    Boolean operatorFlag = false;
    String type, type2 = "", typeOp = "";
    DefaultMutableTreeNode node;

    node = new DefaultMutableTreeNode("B");
    parent.add(node);
    addTokenToStack();
    type = rule_b(node);

    currentWord = tokens.get(currentToken).getWord();

    while (currentToken < tokens.size() && (currentWord.equals("*") || currentWord.equals("/"))) {
      node = new DefaultMutableTreeNode(currentWord);
      parent.add(node);
      addTokenToStack();
      typeOp = currentWord;
      currentToken++;

      node = new DefaultMutableTreeNode("B");
      parent.add(node);
      addTokenToStack();
      type2 = rule_b(node);

      currentWord = tokens.get(currentToken).getWord();

      operatorFlag = true;
    }

    if (operatorFlag) {
      SemanticAnalyzer.calculateCube(type, type2, typeOp);
    }

    return type;
  }
예제 #16
0
파일: Parser.java 프로젝트: jtribble/java
  /**
   * Rule: B
   *
   * @param DefaultMutableTreeNode parent
   * @return String
   */
  private static String rule_b(DefaultMutableTreeNode parent) {
    Boolean operatorFlag = false;
    String type;
    DefaultMutableTreeNode node;

    if (currentToken < tokens.size() && tokens.get(currentToken).getWord().equals("-")) {
      node = new DefaultMutableTreeNode("-");
      parent.add(node);
      addTokenToStack();
      currentToken++;

      operatorFlag = true;
    }

    node = new DefaultMutableTreeNode("C");
    parent.add(node);
    addTokenToStack();
    type = rule_c(node);

    if (operatorFlag) {
      SemanticAnalyzer.calculateCube(type, "-");
    }

    return type;
  }
예제 #17
0
파일: Parser.java 프로젝트: jtribble/java
  /**
   * Rule: Assignment
   *
   * @param DefaultMutableTreeNode parent
   * @return boolean
   */
  public static void rule_assignment(DefaultMutableTreeNode parent) {
    DefaultMutableTreeNode node;
    String type1, type2;

    // identifier

    type1 = tokens.get(currentToken).getWord();
    node = new DefaultMutableTreeNode("identifier" + "(" + type1 + ")");
    parent.add(node);
    addTokenToStack();
    currentToken++;

    // '='

    if (currentToken < tokens.size() && tokens.get(currentToken).getWord().equals("=")) {
      node = new DefaultMutableTreeNode("=");
      parent.add(node);
      addTokenToStack();
      currentToken++;
    } else {
      error(5); // expected =
      return;
    }

    // <expression>

    node = new DefaultMutableTreeNode("expression");
    parent.add(node);
    addTokenToStack();
    type2 = rule_expression(node);

    // check for type equivalence
    SemanticAnalyzer.calculateCube(type1, type2, "=");
  }
  public void updateClientState(Node nodeUpdate) {
    for (int i = 0; i < rootNode.getChildCount(); i++) {
      TreeNode treeNode = rootNode.getChildAt(i);
      //            System.out.println(treeNode.toString());
      if (treeNode.toString().equals(nodeUpdate.getName())) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeNode;
        if (nodeUpdate.isOnline() && nodeUpdate.isValid()) {
          // 删除”状态:在线,可信“ 那一行
          node.remove(2);

          node.add(new DefaultMutableTreeNode("状态:在线,可信"));
          Log.i(this.getClass().getName(), nodeUpdate.getName() + " 已登录,状态可信.");

        } else if (nodeUpdate.isOnline() && !nodeUpdate.isValid()) {
          node.remove(2);
          node.add(new DefaultMutableTreeNode("状态:在线,不可信"));
          Log.v(
              this.getClass().getName(),
              nodeUpdate.getName() + "状态不可信,IP地址为:" + nodeUpdate.getIP());
        } else {
          node.remove(2);
          node.add(new DefaultMutableTreeNode("状态:离线"));
          Log.i(
              this.getClass().getName(), nodeUpdate.getName() + "不在线,IP地址为:" + nodeUpdate.getIP());
        }
        this.jTree.updateUI();
        return;
      }
    }
  }
예제 #19
0
  private static boolean rule_variable(DefaultMutableTreeNode parent) {
    boolean error = false;
    DefaultMutableTreeNode node;

    String type = tokens.get(currentToken).getWord();
    String iden = "";
    node = new DefaultMutableTreeNode(tokens.get(currentToken).getWord());
    parent.add(node);
    currentToken++;
    if (currentToken < tokens.size()
        && tokens.get(currentToken).getToken().equalsIgnoreCase("identifier")) {
      SemanticAnalyzer.checkVariable(
          tokens.get(currentToken - 1).getWord(), tokens.get(currentToken).getWord());
      node =
          new DefaultMutableTreeNode("identifier" + "(" + tokens.get(currentToken).getWord() + ")");
      iden = tokens.get(currentToken).getWord();
      CodeGenerator.addVariable(type, iden);
      parent.add(node);
      currentToken++;
    } else {

      error(6);
    }

    return error;
  }
예제 #20
0
파일: Parser.java 프로젝트: jtribble/java
  /**
   * Rule: Program
   *
   * @param DefaultMutableTreeNode parent
   * @return boolean
   */
  public static void rule_program(DefaultMutableTreeNode parent) {
    boolean error = false;
    DefaultMutableTreeNode node;

    // '{'

    if (currentToken < tokens.size() && tokens.get(currentToken).getWord().equals("{")) {
      node = new DefaultMutableTreeNode("{");
      parent.add(node);
      currentToken++;
    } else {
      error(1); // expected {
      return;
    }

    // <body>

    node = new DefaultMutableTreeNode("body");
    parent.add(node);
    rule_body(node);

    // '}'

    if (currentToken < tokens.size() && tokens.get(currentToken).getWord().equals("}")) {
      node = new DefaultMutableTreeNode("}");
      parent.add(node);
      currentToken++;
    } else {
      error(2); // expected }
    }
  }
예제 #21
0
  private void initialiseTrees() {
    AnalysedModuleDTO rootModule = new AnalysedModuleDTO("", "", "", "");
    DefaultMutableTreeNode rootTo = new DefaultMutableTreeNode(rootModule);
    DefaultMutableTreeNode rootFrom = new DefaultMutableTreeNode(rootModule);

    this.fromModuleTree = new JTree(rootTo);
    createTreeLayout(fromModuleTree);
    fromModuleTree.addTreeSelectionListener(this);

    this.toModuleTree = new JTree(rootFrom);
    createTreeLayout(toModuleTree);
    toModuleTree.addTreeSelectionListener(this);

    List<AnalysedModuleDTO> rootModules = dataControl.getRootModules();
    for (AnalysedModuleDTO module : rootModules) {
      DefaultMutableTreeNode toNode = new DefaultMutableTreeNode(module);
      DefaultMutableTreeNode fromNode = new DefaultMutableTreeNode(module);
      rootTo.add(toNode);
      fillNode(toNode);
      rootFrom.add(fromNode);
      fillNode(fromNode);
    }
    this.expandLeaf(toModuleTree, 1);
    this.expandLeaf(fromModuleTree, 1);

    fromModuleScrollPane.setBackground(UIManager.getColor("Panel.background"));
    fromModuleScrollPane.setViewportView(fromModuleTree);
    toModuleScrollPane.setBackground(UIManager.getColor("Panel.background"));
    toModuleScrollPane.setViewportView(toModuleTree);
  }
  private void updateInspectorTree() {
    if (treeinit) return;

    // inspectorTree = new JTree();

    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Coloured Trails World");

    Set<String> playerNames = ((CTWorld) Simulator.pworld).getPlayerNames();
    Iterator<String> iterator = playerNames.iterator();

    // Add the agents to the tree
    while (iterator.hasNext()) {
      String name = (String) iterator.next();
      rootNode.add(new DefaultMutableTreeNode(name));
    }

    // Add the auction house
    // TODO: Perform existence check for auction house
    rootNode.add(new DefaultMutableTreeNode(AUCTION_NAME));

    inspectorTreeModel = new DefaultTreeModel(rootNode);
    inspectorTree.setModel(inspectorTreeModel);
    ((JScrollPane) inspectorScrollPane).setViewportView(inspectorTree);
    inspectorTree.expandPath(inspectorTree.getPathForRow(0));
    expandAll(inspectorTree);
    treeinit = true;
    return;
  }
  public void setWsdlModel(WSDLModel wsdlModel) {
    if (this.wsdlModel == wsdlModel) {
      return;
    }

    this.wsdlModel = wsdlModel;
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    for (Port port : Util.getSortedPorts(wsdlModel)) {
      Binding binding = port.getBinding().get();
      List<BindingOperation> bindingOps = Util.getSortedBindingOperations(binding);
      if (bindingOps != null && bindingOps.size() > 0) {
        DefaultMutableTreeNode portNode = new DefaultMutableTreeNode(port);
        root.add(portNode);
        for (BindingOperation bindingOp : bindingOps) {
          DefaultMutableTreeNode bindingOpNode = new DefaultMutableTreeNode(bindingOp);
          portNode.add(bindingOpNode);
          bindingOpNode.setAllowsChildren(false);
        }
      }
    }
    DefaultTreeModel dtm = new DefaultTreeModel(root);
    mTree.setModel(dtm);
    int cnt = root.getChildCount();
    for (int i = 0; i < cnt; i++) {
      mTree.expandPath(new TreePath(((DefaultMutableTreeNode) root.getChildAt(i)).getPath()));
    }
  }
예제 #24
0
  private DefaultMutableTreeNode ProListToEquivTree(ArrayList<Protein> proList, String name) {
    DefaultMutableTreeNode root, child;
    int size = 0;
    PeptideProteinNameSet pps = ProteinListToPPNSet(proList);

    root = new DefaultMutableTreeNode(pps);
    HashSet<String> usedProteins = new HashSet<String>();
    for (Protein p : proList) {
      if (!usedProteins.contains(p.getName())) {
        if (p.getEquivalent().size() > 0) {
          ArrayList<Protein> equivList = new ArrayList<Protein>();
          equivList.add(p);
          equivList.addAll(p.getEquivalent());
          PeptideProteinNameSet ppsEquiv = ProteinListToPPNSet(equivList);
          ppsEquiv.setName(p.getName() + " Group (" + equivList.size() + ")");
          child = new DefaultMutableTreeNode(ppsEquiv);
          size++;
          for (Protein ps : equivList) {
            child.add(new DefaultMutableTreeNode(ps));
            usedProteins.add(ps.getName());
          }
          root.add(child);
        } else {
          root.add(new DefaultMutableTreeNode(p));
          usedProteins.add(p.getName());
          size++;
        }
      }
    }
    pps.setName(name + " (" + size + ")");
    return root;
  }
예제 #25
0
파일: Parser.java 프로젝트: jtribble/java
  /**
   * Rule: X
   *
   * @param DefaultMutableTreeNode parent
   * @return String
   */
  public static String rule_x(DefaultMutableTreeNode parent) {
    Boolean operatorFlag = false;
    String type, type2 = "";
    DefaultMutableTreeNode node;

    node = new DefaultMutableTreeNode("Y");
    parent.add(node);
    addTokenToStack();
    type = rule_y(node);

    while (currentToken < tokens.size() && tokens.get(currentToken).getWord().equals("&")) {
      node = new DefaultMutableTreeNode("&");
      parent.add(node);
      addTokenToStack();
      currentToken++;

      node = new DefaultMutableTreeNode("Y");
      parent.add(node);
      addTokenToStack();
      type2 = rule_y(node);

      operatorFlag = true;
    }

    if (operatorFlag) {
      SemanticAnalyzer.calculateCube(type, "&");
      SemanticAnalyzer.calculateCube(type2, "&");
    }

    return type;
  }
예제 #26
0
  private static boolean rule_assignment(DefaultMutableTreeNode parent) {

    boolean error = false;
    DefaultMutableTreeNode node;

    String iden = tokens.get(currentToken).getWord();
    node =
        new DefaultMutableTreeNode("identifier" + "(" + tokens.get(currentToken).getWord() + ")");
    parent.add(node);

    String s = tokens.get(currentToken).getWord();
    if (SemanticAnalyzer.getSymbolTable().get(s) != null)
      SemanticAnalyzer.pushStack(SemanticAnalyzer.getSymbolTable().get(s).firstElement().getType());
    else {
      SemanticAnalyzer.pushStack("ERROR");
      SemanticAnalyzer.error(getgui(), 0, getlineno(), s);
    }

    currentToken++;
    if (currentToken < tokens.size() && tokens.get(currentToken).getWord().equals("=")) {
      node = new DefaultMutableTreeNode("=");
      parent.add(node);
      currentToken++;
    } else {
      error(5);
      while (currentToken < tokens.size()
          && !(tokens.get(currentToken).getWord().equals("!")
              || tokens.get(currentToken).getWord().equals("-")
              || tokens.get(currentToken).getToken().equals("INTEGER")
              || tokens.get(currentToken).getToken().equals("OCTAL")
              || tokens.get(currentToken).getToken().equals("HEXADECIMAL")
              || tokens.get(currentToken).getToken().equals("BINARY")
              || tokens.get(currentToken).getToken().equals("STRING")
              || tokens.get(currentToken).getToken().equals("CHARACTER")
              || tokens.get(currentToken).getToken().equals("FLOAT")
              || tokens.get(currentToken).getToken().equals("IDENTIFIER")
              || tokens.get(currentToken).getWord().equals("true")
              || tokens.get(currentToken).getWord().equals("false")
              || tokens.get(currentToken).getWord().equals("(")
              || tokens.get(currentToken).getWord().equals(")")
              || tokens.get(currentToken).getWord().equals(";"))) {
        currentToken++;
      }
    }

    node = new DefaultMutableTreeNode("expression");
    parent.add(node);
    error = rule_expression(node);

    String s1 = SemanticAnalyzer.popStack();
    String s2 = SemanticAnalyzer.popStack();
    String operator = "=";
    String res = SemanticAnalyzer.calculateCube(s1, s2, operator);
    CodeGenerator.addInstruction("STO", iden, "0");

    if (res.equals("ERROR")) SemanticAnalyzer.error(getgui(), 2, getlineno(), "");

    return error;
  }
  /**
   * Creates a ternary tree node.
   *
   * @param caption The tree's caption (text to be shown when the tree is drawn).
   * @param child1 The first children node.
   * @param child2 The second children node.
   * @param child3 The third children node.
   * @return The tree node.
   */
  public DefaultMutableTreeNode createTernary(String caption, AST child1, AST child2, AST child3) {
    DefaultMutableTreeNode t = new DefaultMutableTreeNode(caption);
    t.add((DefaultMutableTreeNode) child1.visit(this, null));
    t.add((DefaultMutableTreeNode) child2.visit(this, null));
    t.add((DefaultMutableTreeNode) child3.visit(this, null));

    return (t);
  }
예제 #28
0
  /**
   * get 部首 tree view
   *
   * @returns root tree node object
   * @throws SQLException
   */
  public DefaultMutableTreeNode getRadicalTree() throws SQLException {
    TreeMap<Integer, String> strokesAndRadicalsMap = new TreeMap<Integer, String>();
    for (int i = 0; i < RADICAL_STROKES.length; ++i) {
      String sRadical = "" + HYDC_RADICALS.charAt(i);
      if (sRadical.equals(" ")) {
        continue;
      }
      int strokes = RADICAL_STROKES[i];
      String sRadicals = strokesAndRadicalsMap.get(strokes);
      if (sRadicals == null) {
        strokesAndRadicalsMap.put(strokes, sRadicals = "");
      }
      strokesAndRadicalsMap.put(strokes, sRadicals + sRadical);
    }
    String sSql =
        "SELECT parts_strokes, unicode FROM HYDC3 "
            + "WHERE bushou = ? "
            + "ORDER BY parts_strokes, unicode";
    PreparedStatement statement = connection.prepareStatement(sSql);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode("畫數 / 部首 / 畫數");
    for (Integer strokes : strokesAndRadicalsMap.keySet()) {
      String sRadicals = strokesAndRadicalsMap.get(strokes);
      DefaultMutableTreeNode strokesNode =
          new DefaultMutableTreeNode(strokes.toString() + " : " + sRadicals);
      for (int i = 0; i < sRadicals.length(); ++i) {
        String sRadical = sRadicals.substring(i, i + 1);
        DefaultMutableTreeNode radicalNode = new DefaultMutableTreeNode(sRadical);

        TreeMap<Integer, String> partsStrokesAndCharactersMap = new TreeMap<Integer, String>();
        statement.setString(1, sRadical);
        ResultSet resultSet = statement.executeQuery();
        while (resultSet.next()) {
          short partsStrokes = resultSet.getShort("parts_strokes");
          int unicode = resultSet.getInt("unicode");
          String sCharacters = partsStrokesAndCharactersMap.get((Integer) (int) partsStrokes);
          if (sCharacters == null) {
            partsStrokesAndCharactersMap.put((Integer) (int) partsStrokes, sCharacters = "");
          }
          sCharacters += new String(new int[] {unicode}, 0, 1);
          partsStrokesAndCharactersMap.put((Integer) (int) partsStrokes, sCharacters);
        }
        resultSet.close();
        strokesNode.add(radicalNode);
        for (Integer partsStrokes : partsStrokesAndCharactersMap.keySet()) {
          String sCharacters = partsStrokesAndCharactersMap.get(partsStrokes);
          DefaultMutableTreeNode partsStrokesNode =
              new DefaultMutableTreeNode(partsStrokes.toString() + " : " + sCharacters);
          radicalNode.add(partsStrokesNode);
        }
        strokesNode.add(radicalNode);
      }
      root.add(strokesNode);
    }

    statement.close();
    return root;
  }
예제 #29
0
  public int createTreeFromMenuBar(
      javax.swing.MenuElement subElements[],
      javax.swing.tree.DefaultMutableTreeNode treeNodes,
      javax.swing.tree.DefaultMutableTreeNode topReports,
      java.lang.String reportNodeTitle,
      java.lang.String utilitiesNodeTitle) {

    for (int i = 0; i < subElements.length; i++) {

      if (subElements[i].getClass().getName() != "javax.swing.JPopupMenu") {

        javax.swing.JMenuItem abstractButton = (javax.swing.JMenuItem) subElements[i];

        if (abstractButton.isEnabled()) {

          siblingNode = new javax.swing.tree.DefaultMutableTreeNode(abstractButton.getText());

          treeNodes.add(siblingNode);

          if (treeNodes.getUserObject() == "Reports") {

            treeNodes.setUserObject(reportNodeTitle);

            topReports.add(treeNodes);
          }

          if (treeNodes.getUserObject() == "Utility") {

            treeNodes.setUserObject(utilitiesNodeTitle);

            topReports.add(treeNodes);
          }
        }
      }

      if (subElements[i].getSubElements().length > 0) {

        createTreeFromMenuBar(
            subElements[i].getSubElements(),
            siblingNode,
            topReports,
            reportNodeTitle,
            utilitiesNodeTitle);

        if (treeNodes.isLeaf()) {

          javax.swing.tree.DefaultMutableTreeNode parentNode =
              (javax.swing.tree.DefaultMutableTreeNode) siblingNode.getParent();

          siblingNode.removeFromParent();
        }
      }

      treeCount++;
    }

    return treeCount;
  }
예제 #30
0
  public AllExample() {
    super();

    setTitle("Example Launcher");
    setBounds(50, 50, 300, 600);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Examples");

    DefaultMutableTreeNode node = null;
    for (String[] s : EXAMPLES) {
      if (s[1].isEmpty()) {
        node = new DefaultMutableTreeNode(s[0]);
        rootNode.add(node);
      } else {
        node.add(new DefaultMutableTreeNode(s[1]));
      }
    }

    DefaultTreeModel model = new DefaultTreeModel(rootNode);
    tree = new JTree(model);

    JScrollPane sp = new JScrollPane();
    sp.getViewport().setView(tree);

    JButton button = new JButton("Run");
    button.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent arg0) {
            TreePath path = tree.getSelectionPath();
            if (path == null) {
              return;
            }

            if (currentApplication != null) {
              currentApplication.dispose();
            }

            String title = path.getLastPathComponent().toString();

            for (String[] s : EXAMPLES) {
              if (title.equals(s[1])) {
                AppletRunner.run(s[0], s[1]);
                AppletRunner.frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                currentApplication = AppletRunner.frame;
                break;
              }
            }
          }
        });

    getContentPane().add(sp, BorderLayout.CENTER);
    getContentPane().add(button, BorderLayout.SOUTH);

    setVisible(true);
  }