Beispiel #1
0
  /**
   * We assume database files are stored on disk as given: - database | |- class0 |- image0 |-
   * image01 ... |- class1 |- image10 ... |- classN |- imageN0 ... |- |- imageNOTClASSIFIED-0 ... |-
   * imageNOTClASSIFIED-M
   *
   * <p>Other directories or files that are not images are ignored.
   */
  public ImagesModel(JFileChooser chooser) {
    this.saxRepresentation = new HashMap<String, SAXEnhanced>();
    this.currentClassification = new ArrayList<Pair<SAXEnhanced, String>>();
    File database = chooser.getSelectedFile();
    String[] childrenFiles = database.list();
    root = new DefaultMutableTreeNode(database.getName());

    for (String main : childrenFiles) {
      String imagePath = database + "/" + main;
      File imageFile = new File(imagePath);
      if (!imageFile.isDirectory()) {
        getSAXFromImageFile(imageFile, null, root);
      } else {
        childrenFiles = new File(imagePath).list();
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(database.getName() + "/" + main);
        for (String subMain : childrenFiles) {
          String subMainImagePath = imagePath + "/" + subMain;
          File subMainImageFile = new File(subMainImagePath);
          if (!subMainImageFile.isDirectory()) {
            getSAXFromImageFile(subMainImageFile, main, node);
          }
        }
        if (!node.isLeaf()) // images are in this directory
        root.add(node);
      }
    }
  }
 private static void replaceChildren(
     final DefaultMutableTreeNode node, final Collection<? extends ElementNode> arrayList) {
   node.removeAllChildren();
   for (ElementNode child : arrayList) {
     node.add(child);
   }
 }
  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;
  }
Beispiel #4
0
  /**
   * 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;
  }
Beispiel #5
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;
  }
Beispiel #6
0
  /**
   * 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 }
    }
  }
Beispiel #7
0
  /**
   * 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;
  }
 @Nullable
 private static String getActionId(DefaultMutableTreeNode node) {
   return (String)
       (node.getUserObject() instanceof String
           ? node.getUserObject()
           : node.getUserObject() instanceof Pair ? ((Pair) node.getUserObject()).first : null);
 }
Beispiel #9
0
  private void buildTreeFromString(DefaultTreeModel model, final String str) {
    // Fetch the root node
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();

    // Split the string around the delimiter
    String[] strings = str.split("/");

    // Create a node object to use for traversing down the tree as it
    // is being created
    DefaultMutableTreeNode node = root;
    // Iterate of the string array
    for (String s : strings) {
      // Look for the index of a node at the current level that
      // has a value equal to the current string
      int index = childIndex(node, s);

      // Index less than 0, this is a new node not currently present on
      // the tree
      if (index < 0) {
        // Add the new node
        DefaultMutableTreeNode newChild = new DefaultMutableTreeNode(s);
        node.insert(newChild, node.getChildCount());
        node = newChild;
      }
      // Else, existing node, skip to the next string
      else {
        node = (DefaultMutableTreeNode) node.getChildAt(index);
      }
    }
  }
Beispiel #10
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);

  }
 private static boolean isToolbarAction(DefaultMutableTreeNode node) {
   return node.getParent() != null
       && ((DefaultMutableTreeNode) node.getParent()).getUserObject() instanceof Group
       && ((Group) ((DefaultMutableTreeNode) node.getParent()).getUserObject())
           .getName()
           .equals(ActionsTreeUtil.MAIN_TOOLBAR);
 }
  /*
   * Adds a field to the format being composed
   */
  public void addField() {
    DefaultMutableTreeNode node =
        (DefaultMutableTreeNode) availableFieldsComp.getTree().getLastSelectedPathComponent();
    if (node == null
        || !node.isLeaf()
        || !(node.getUserObject() instanceof DataObjDataFieldWrapper)) {
      return; // not really a field that can be added, just empty or a string
    }

    Object obj = node.getUserObject();
    if (obj instanceof DataObjDataFieldWrapper) {
      DataObjDataFieldWrapper wrapper = (DataObjDataFieldWrapper) obj;
      String sep = sepText.getText();
      if (StringUtils.isNotEmpty(sep)) {
        try {
          DefaultStyledDocument doc = (DefaultStyledDocument) formatEditor.getStyledDocument();
          if (doc.getLength() > 0) {
            doc.insertString(doc.getLength(), sep, null);
          }
        } catch (BadLocationException ble) {
        }
      }
      insertFieldIntoTextEditor(wrapper);
      setHasChanged(true);
    }
  }
Beispiel #13
0
  /**
   * @param availBins the bins to choose from. This method asserts that they are sorted in
   *     descending order.
   * @param vol
   * @param weight
   * @return
   */
  private DefaultMutableTreeNode findBinNode(
      final List<DefaultMutableTreeNode> availBins, final BigDecimal vol, final BigDecimal weight) {

    if (availBins.isEmpty()) {
      throw new NoContainerException(false, false);
    }

    // check if everything fits into one bin, starting with the smallest one
    for (int i = availBins.size() - 1; i >= 0; i--) {

      final DefaultMutableTreeNode packNode = availBins.get(i);

      final AvailableBins bin = (AvailableBins) packNode.getUserObject();
      final I_M_PackagingContainer pc = bin.getPc();

      if (pc.getMaxVolume().compareTo(vol) >= 0
          && pc.getMaxWeight().compareTo(weight) >= 0
          && bin.getQtyAvail() > 0) {

        return packNode;
      }
    }

    // no bin is big enough, return the biggest one we got
    return availBins.get(0);
  }
Beispiel #14
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;
  }
Beispiel #15
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));
 }
Beispiel #16
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 jTree1ValueChanged(
      javax.swing.event.TreeSelectionEvent evt) { // GEN-FIRST:event_jTree1ValueChanged
    // TODO add your handling code here:

    selectedObject = null;

    if (jTree1.getLastSelectedPathComponent() != null) {
      DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) jTree1.getLastSelectedPathComponent();
      Object obj = dmtn.getUserObject();
      if (!dmtn.isLeaf()) {
        return;
      }

      if (obj instanceof CustomExpression) {
        // jRTextExpressionAreaDefaultExpression.setText( obj+"");
        jRTextExpressionAreaDefaultExpression.setEditable(true);
        jRTextExpressionAreaDefaultExpression.setBackground(java.awt.Color.WHITE);
        jRTextExpressionAreaDefaultExpression.setOpaque(true);
      } else {
        if (obj instanceof JRParameter)
          jRTextExpressionAreaDefaultExpression.setText("$P{" + obj + "}");
        if (obj instanceof JRVariable)
          jRTextExpressionAreaDefaultExpression.setText("$V{" + obj + "}");
        if (obj instanceof JRField)
          jRTextExpressionAreaDefaultExpression.setText("$F{" + obj + "}");
        jRTextExpressionAreaDefaultExpression.setEditable(false);

        jRTextExpressionAreaDefaultExpression.setBackground(java.awt.Color.GRAY);
        jRTextExpressionAreaDefaultExpression.setOpaque(true);
      }
      selectedObject = obj;
    }
  } // GEN-LAST:event_jTree1ValueChanged
Beispiel #18
0
  /**
   * get tree node text function
   *
   * @version 1.0
   * @author dinglinhui
   */
  public String getNodeName() {

    SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); // 设置日期格式

    DefaultMutableTreeNode selectedNode =
        (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
    if (selectedNode != null) {

      if (selectedNode.getParent() != null) {

        if (selectedNode.getParent().getParent() != null) {
          // 召唤具体通道下的某个类型数据
          if (selectedNode.toString().equals("遥测")) {
            return selectedNode.getParent().toString().trim() + "_遥测" + df.format(new Date());
          }

          if (selectedNode.toString().equals("遥信")) {
            return selectedNode.getParent().toString().trim() + "_遥信" + df.format(new Date());
          }

          if (selectedNode.toString().equals("遥控")) {
            return selectedNode.getParent().toString().trim() + "_遥控" + df.format(new Date());
          }
        } else {
          // 召唤具体通道
          return selectedNode.toString().trim() + "_" + df.format(new Date());
        }
      }
    }
    return null;
  }
Beispiel #19
0
  /**
   * 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, "=");
  }
  private TreePath find2(JTree tree, TreePath parent, Village pNode, int depth) {
    TreeNode node = (TreeNode) parent.getLastPathComponent();
    DefaultMutableTreeNode o = (DefaultMutableTreeNode) node;

    // If equal, go down the branch
    if (o.getUserObject().equals(pNode)) {
      // If at end, return match
      return parent;
    } else {
      // Traverse children
      if (node.getChildCount() >= 0) {
        for (Enumeration e = node.children(); e.hasMoreElements(); ) {
          TreeNode n = (TreeNode) e.nextElement();
          TreePath path = parent.pathByAddingChild(n);
          TreePath result = find2(tree, path, pNode, depth + 1);
          // Found a match
          if (result != null) {
            return result;
          }
        }
      }
    }
    // No match at this branch
    return null;
  }
Beispiel #21
0
  /**
   * 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;
  }
  /**
   * @param defaultTreeModel
   * @param root
   * @see BuildingTree
   */
  public void toTree(final DefaultTreeModel defaultTreeModel, DefaultMutableTreeNode root) {
    ArrayList a = (ArrayList) DataToTest.getBuildingCollection();
    DefaultMutableTreeNode bNode;
    DefaultMutableTreeNode fNode;
    DefaultMutableTreeNode rNode;
    for (Iterator i = a.iterator(); i.hasNext(); ) {
      Building building = (Building) i.next();
      bNode = new DefaultMutableTreeNode(building);
      defaultTreeModel.insertNodeInto(bNode, root, root.getChildCount());

      if (building.getFloor().length > 0) {
        for (int floorCount = 0; floorCount < building.getFloor().length; floorCount++) {
          Floor fl = (Floor) building.getFloor()[floorCount];
          fNode = new DefaultMutableTreeNode(fl);
          defaultTreeModel.insertNodeInto(fNode, bNode, bNode.getChildCount());

          if (fl.getRoom().length > 0) {
            for (int roomIterator = 0; roomIterator < fl.getRoom().length; roomIterator++) {
              Room r = (Room) fl.getRoom()[roomIterator];
              rNode = new DefaultMutableTreeNode(r);
              defaultTreeModel.insertNodeInto(rNode, fNode, fNode.getChildCount());
            }
          }
        }
      }
    }
  }
  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;
  }
 /** Expand the current node and return the list of leaves (MaterialVO objects). */
 private ArrayList getComponents(DefaultMutableTreeNode node) {
   ArrayList list = new ArrayList();
   for (int i = 0; i < node.getChildCount(); i++)
     list.addAll(getComponents((DefaultMutableTreeNode) node.getChildAt(i)));
   if (node.isLeaf()) list.add(node.getUserObject());
   return list;
 }
  /**
   * Copies all the mod files from the profileModDir to the factorioModDir.
   *
   * @param profileModDir The profileDir to copy mods from.
   * @param factorioModDir The factorioDir to copy mods to.
   * @param selectedNode The TreeNode that is currently selected.
   */
  private void copyAllEnabledMods(
      File profileModDir, File factorioModDir, DefaultMutableTreeNode selectedNode) {
    // Let's copy all enabled mods!

    // Get the selected node.
    Enumeration<DefaultMutableTreeNode> children = selectedNode.children(); // Get it's children.
    while (children.hasMoreElements()) {
      DefaultMutableTreeNode node = children.nextElement(); // Get the next element.
      ModManagerWindow.CheckBoxNode checkBox =
          (ModManagerWindow.CheckBoxNode) node.getUserObject(); // Get the checkbox.
      String name = checkBox.getText(); // Get the text from the checkbox.
      if (name.equals("base") || !checkBox.isSelected())
        continue; // If it is the "base" mod, ignore it (it's always on)

      // Get the file with the name of the mod and then copy it from the profile dir to the mods
      // dir.
      File file =
          FileUtils.findFileWithPartName(
              profileModDir, ((ModManagerWindow.CheckBoxNode) node.getUserObject()).getText());
      try {
        Files.copy(
            file.toPath(),
            Paths.get(
                factorioModDir.getPath()
                    + "/"
                    + file.getPath().substring(file.getPath().lastIndexOf('\\'))));
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
  private void addItemToNode(
      DefaultMutableTreeNode node, ArmylistWargearItem item, ArmylistWargearGroup group) {
    DefaultMutableTreeNode newNode = new DefaultMutableTreeNode();

    WargearTreeUserObjectContainer container =
        new WargearTreeUserObjectContainer(item, newNode, node);
    container.setItemGroup(group);
    newNode.setUserObject(container);

    node.add(newNode);

    /*Iterator subGroups = group.getSubGroups().iterator();
    while(subGroups.hasNext()){
        ArmylistWargearGroup subGroup = (ArmylistWargearGroup)subGroups.next();
        this.addGroupToNode(newNode, subGroup);
    }

    Iterator items = group.getItems().iterator();
    while(items.hasNext()){
        DefaultMutableTreeNode temp = new DefaultMutableTreeNode();
        ArmylistWargearItem item = (ArmylistWargearItem)items.next();
        WargearTreeUserObjectContainer container = new WargearTreeUserObjectContainer(item, temp, newNode);
        container.setItemGroup(group);
        temp.setUserObject(container);
        newNode.add(temp);
    }*/

  }
Beispiel #27
0
 /**
  * Returns whether all the parameters are correct. If param is null, all paremeters will be
  * checked, otherwise only the param, but other parameters will be checked only in the cache. This
  * is good if only one value is changed and we don't want to check everything.
  */
 boolean checkResourceFieldsCorrect(
     final String param,
     final String[] params,
     final boolean fromServicesInfo,
     final boolean fromCloneInfo) {
   boolean cor =
       super.checkResourceFieldsCorrect(param, params, fromServicesInfo, fromCloneInfo, true);
   final DefaultMutableTreeNode gn = getNode();
   if (gn != null) {
     @SuppressWarnings("unchecked")
     final Enumeration<DefaultMutableTreeNode> e = gn.children();
     if (!e.hasMoreElements()) {
       return false;
     }
     try {
       while (e.hasMoreElements()) {
         final DefaultMutableTreeNode n = e.nextElement();
         final ServiceInfo gsi = (ServiceInfo) n.getUserObject();
         if (!gsi.checkResourceFieldsCorrect(
             null, gsi.getParametersFromXML(), fromServicesInfo, fromCloneInfo, true)) {
           cor = false;
         }
       }
     } catch (java.util.NoSuchElementException ele) {
       return false;
     }
   }
   return cor;
 }
  private void removeNodeFromParent(DefaultMutableTreeNode node) {
    TreeNode parent = node.getParent();
    int idx = parent.getIndex(node);
    node.removeFromParent();

    (getModel()).nodesWereRemoved(parent, new int[] {idx}, new TreeNode[] {node});
  }
  /**
   * Creates a binary 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.
   * @return The tree node.
   */
  public DefaultMutableTreeNode createBinary(String caption, AST child1, AST child2) {
    DefaultMutableTreeNode t = new DefaultMutableTreeNode(caption);
    t.add((DefaultMutableTreeNode) child1.visit(this, null));
    t.add((DefaultMutableTreeNode) child2.visit(this, null));

    return (t);
  }
 private ArrayList<TreeNode> childrenToArray(DefaultMutableTreeNode node) {
   ArrayList<TreeNode> arrayList = new ArrayList<TreeNode>();
   for (int i = 0; i < node.getChildCount(); i++) {
     arrayList.add(node.getChildAt(i));
   }
   return arrayList;
 }