Example #1
0
  @Override
  public void adoptElement(SceneElement elem) {
    if (!(elem instanceof NenyaImageSceneElement
        || elem instanceof NenyaTileSceneElement
        || elem instanceof NenyaComponentSceneElement)) {
      enableEditor(false);
      return;
    }

    DefaultComboBoxModel dcm = (DefaultComboBoxModel) itemList.getModel();

    // Important: Work on a copy, not on the original. Otherwise we mess up the undomanager
    sceneElement = elem.copy();

    if ((sceneElement instanceof NenyaImageSceneElement) && !locked) {
      dcm.removeAllElements();
      String[] tmp = ((NenyaImageSceneElement) sceneElement).getPath();
      dcm.addElement(tmp[tmp.length - 1]);
    }
    if ((sceneElement instanceof NenyaTileSceneElement) && !locked) {
      dcm.removeAllElements();
      dcm.addElement(((NenyaTileSceneElement) sceneElement).getTileName());
    }
    if ((sceneElement instanceof NenyaComponentSceneElement) && !locked) {
      dcm.removeAllElements();
      NenyaComponentItem[] ni = ((NenyaComponentSceneElement) sceneElement).getComponents();
      for (NenyaComponentItem element : ni) {
        dcm.addElement(element);
      }
    }

    try {
      ClassedItem[] cols = null;
      if (elem instanceof NenyaTileSceneElement)
        cols = ((NenyaTileSceneElement) elem).getColorList();
      if (elem instanceof NenyaImageSceneElement)
        cols = ((NenyaImageSceneElement) elem).getColorList();
      if (elem instanceof NenyaComponentSceneElement) {
        NenyaComponentItem nci = (NenyaComponentItem) dcm.getSelectedItem();
        cols = nci.getColorList();
      }
      Vector<TreePath> collect = new Vector<TreePath>();
      TreeNode root = (TreeNode) colors.getModel().getRoot();
      for (ClassedItem col : cols) {
        String[] tmp = {root.toString(), col.getClassName(), col.getItemName()};
        collect.add(TreeUtil.findPath(root, tmp));
      }
      TreePath[] path = collect.toArray(new TreePath[0]);
      colors.getSelectionModel().setSelectionPaths(path);
    } catch (Exception e) {
      // Either the tree is filtered away or the selected item is not colorized.
    }

    enableEditor(true);
    itemList.setEnabled(elem instanceof NenyaComponentSceneElement);
  }
Example #2
0
  /*
  Method: toString
  Purpose: sends the database to a string
  Parameters:
      TreeNode currentNode - the current node in the binary tree
  Returns:
  */
  private String toString(TreeNode currentNode) {
    String returnString = "";
    if (currentNode == null) {
      return returnString;
    }

    returnString += toString(currentNode.getLeftBranch());
    returnString += currentNode.toString() + "\r\n";
    returnString += toString(currentNode.getRightBranch());

    return returnString;
  }
 private static MyTreeNode ensureGroup(
     @NotNull DefaultMutableTreeNode root, @NotNull List<String> path, int index) {
   String groupName = path.get(index++);
   for (int i = 0; i < root.getChildCount(); i++) {
     TreeNode child = root.getChildAt(i);
     if (child instanceof MyTreeNode && groupName.equals(child.toString())) {
       return index < path.size() - 1
           ? ensureGroup((MyTreeNode) child, path, index)
           : (MyTreeNode) child;
     }
   }
   MyTreeNode groupNode = new MyTreeNode(groupName);
   root.add(groupNode);
   return index < path.size() - 1 ? ensureGroup(groupNode, path, index) : groupNode;
 }
Example #4
0
  private String searchForSynonym(String searchedFor, TreeNode currentNode) {
    String returnString = "";

    if (currentNode == null) {
      return returnString;
    }

    returnString += searchForSynonym(searchedFor, currentNode.getLeftBranch());

    if (currentNode.containsSynonym(searchedFor)) {
      returnString += "\r\n" + currentNode.toString() + "\r\n";
    }

    returnString += searchForSynonym(searchedFor, currentNode.getRightBranch());

    return returnString;
  }
Example #5
0
  /*
  Method: searchForWord - database search
  Purpose: Searches database for matching word
              and returns the results of the search
  Parameters:
      String wordSearched      the word to be found
  Returns:
      String        What we found/not found
  */
  public String searchForWord(String wordSearched) {
    if (this.isEmpty()) {
      // can't search an empty list
      return "There are no entries to search";
    }
    if (wordSearched.equals("")) {
      // can't search for an empty string
      return ("I can't search for nothing");
    }
    if (this.containsEntry(wordSearched)) {
      // its in the list, so get it
      TreeNode found = TreeNode.getNodeByString(wordSearched, entryRoot);

      return found.toString();
    }

    // I couldn't find it
    return ("I can't find: \"" + wordSearched + "\"");
  }