Exemplo n.º 1
0
    public void nodeAdded(String fqn) {
      MyNode n, p;

      n = root.add(fqn);
      if (n != null) {
        p = (MyNode) n.getParent();
        tree_model.reload(p);
        jtree.scrollPathToVisible(new TreePath(n.getPath()));
      }
    }
Exemplo n.º 2
0
  private String textGen(TreePath p) {

    MyNode selectedNode = (MyNode) p.getLastPathComponent();
    String text = "men allt som";
    int n = selectedNode.getPath().length;

    for (int i = n - 1; i >= 0; i--) {
      text = text + " är " + selectedNode.getPath()[i].toString();
    }
    return text;
  }
Exemplo n.º 3
0
    public void nodeRemoved(String fqn) {
      MyNode n;
      TreeNode par;

      n = root.findNode(fqn);
      if (n != null) {
        n.removeAllChildren();
        par = n.getParent();
        n.removeFromParent();
        tree_model.reload(par);
      }
    }
Exemplo n.º 4
0
      MyNode findNode(String fqn) {
        MyNode curr, n;
        StringTokenizer tok;
        String child_name;

        if (fqn == null) return null;
        curr = this;
        tok = new StringTokenizer(fqn, ReplicatedTreeView.SEP);

        while (tok.hasMoreTokens()) {
          child_name = tok.nextToken();
          n = curr.findChild(child_name);
          if (n == null) return null;
          curr = n;
        }
        return curr;
      }
Exemplo n.º 5
0
  private void showDetails(TreePath p) {

    if (p == null) {
      return;
    }

    MyNode selectedNode = (MyNode) p.getLastPathComponent();
    String textPath = textGen(p);

    JOptionPane.showMessageDialog(
        this,
        selectedNode.getLevelName()
            + ": "
            + selectedNode.getUserObject()
            + "\n"
            + selectedNode.getText()
            + "\n"
            + textPath);
  }
Exemplo n.º 6
0
      /**
       * Adds a new node to the view. Intermediary nodes will be created if they don't yet exist.
       * Returns the first node that was created or null if node already existed
       */
      public MyNode add(String fqn) {
        MyNode curr, n, ret = null;
        StringTokenizer tok;
        String child_name;

        if (fqn == null) return null;
        curr = this;
        tok = new StringTokenizer(fqn, ReplicatedTreeView.SEP);

        while (tok.hasMoreTokens()) {
          child_name = tok.nextToken();
          n = curr.findChild(child_name);
          if (n == null) {
            n = new MyNode(child_name);
            if (ret == null) ret = n;
            curr.add(n);
          }
          curr = n;
        }
        return ret;
      }
Exemplo n.º 7
0
  private MyNode readNode() {

    String text = null;
    String level = null;
    String name = null;
    MyNode retNode = null;

    if (s.hasNextLine()) {

      try {
        String[] lineArray = thisLine.split("> ");
        text = lineArray[1];
        level = lineArray[0].split(" namn=")[0];
        name = lineArray[0].split(" namn=")[1];

        if (!level.startsWith("<") | !name.startsWith("\"") | !name.endsWith("\"")) {
          throw new Exception();
        } else {
          level = level.substring(1);
          name = name.substring(1, name.length() - 1);
        }
      } catch (Exception e) {
        System.err.println("Parse error");
        e.printStackTrace();
        System.exit(1);
      }

      retNode = new MyNode(name, level, text);
      thisLine = s.nextLine();

      while (!thisLine.startsWith("</")) {
        retNode.add(readNode());
        thisLine = s.nextLine();
      }
    }
    return retNode;
  }
Exemplo n.º 8
0
    /** Recursively adds GUI nodes starting from fqn */
    void addGuiNode(String fqn) {
      Set children;
      String child_name;

      if (fqn == null) return;

      // 1 . Add myself
      root.add(fqn);

      // 2. Then add my children
      children = tree.getChildrenNames(fqn);
      if (children != null) {
        for (Iterator it = children.iterator(); it.hasNext(); ) {
          child_name = (String) it.next();
          addGuiNode(fqn + SEP + child_name);
        }
      }
    }