Beispiel #1
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;
  }
Beispiel #2
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);
  }
 public int removeAfter(MyNode node) {
   if (node.next == null) {
     throw new IndexOutOfBoundsException();
   }
   MyNode obsolete = node.next;
   int ans = obsolete.value;
   node.next = obsolete.next;
   obsolete = null;
   size--;
   return ans;
 }
Beispiel #4
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;
  }
 public void insertAfter(MyNode after, MyNode newNode) {
   newNode.next = after.next;
   after.next = newNode;
   size++;
 }
 public void insertHead(MyNode newHead) {
   newHead.next = head;
   head = newHead;
   size++;
 }
 public void insertHead(int x) {
   MyNode n = new MyNode(x);
   n.next = head;
   head = n;
   size++;
 }