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;
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * add tree node function
   *
   * @version 1.0
   * @author dinglinhui
   */
  private boolean addTreeNode(String name) {

    for (int i = 0; i < root.getChildCount(); i++) {
      TreeNode node = root.getChildAt(i);
      if (name.equals(node.toString())) {
        return false;
      }
    }

    IconNode nodesChnl = new IconNode(name);
    IconNode[] nodesType = new IconNode[3];
    nodesChnl.setIcon(getImageIcon(RESOURCE_IMAGES_PATH + "ligthbulb_on.png", 16, 16));

    nodesType[0] = new IconNode("遥测");
    nodesType[0].setIcon(getImageIcon(RESOURCE_IMAGES_PATH + "Orange Ball.png", 16, 16));
    nodesChnl.add(nodesType[0]);

    nodesType[1] = new IconNode("遥信");
    nodesType[1].setIcon(getImageIcon(RESOURCE_IMAGES_PATH + "Green Ball.png", 16, 16));
    nodesChnl.add(nodesType[1]);

    nodesType[2] = new IconNode("遥控");
    nodesType[2].setIcon(getImageIcon(RESOURCE_IMAGES_PATH + "Yellow Ball.png", 16, 16));
    nodesChnl.add(nodesType[2]);

    root.add(nodesChnl);

    return true;
  }
Ejemplo n.º 3
0
  public String toXPath() {
    /* HOW TO CLIMB UP !!!!!*/
    TreeNode parent = getParent();

    if (parent == null) return (String.valueOf(myNode.getName()));
    else return (parent.toString() + "/" + myNode.getName());
  }
Ejemplo n.º 4
0
  private TreePath find2(TreePath parent, Object[] nodes, int depth, boolean byName) {
    TreeNode node = (TreeNode) parent.getLastPathComponent();
    if (depth > nodes.length - 1) {
      return parent;
    }

    if (node.getChildCount() >= 0) {
      for (Enumeration<TreeNode> e = node.children(); e.hasMoreElements(); ) {
        TreeNode n = e.nextElement();
        TreePath path = parent.pathByAddingChild(n);
        boolean find;

        if (byName) {
          find = n.toString().toUpperCase().contains(nodes[depth].toString().toUpperCase());
        } else {
          find = n.equals(nodes[depth]);
        }

        if (find) {
          TreePath result = find2(path, nodes, depth + 1, byName);
          if (result != null) {
            return result;
          }
        } else {
          TreePath result = find2(path, nodes, depth, byName);
          if (result != null) {
            return result;
          }
        }
      }
    }

    return null;
  }
Ejemplo n.º 5
0
 private void collectExisting(MPSTreeNode node, Collection<String> existing) {
   for (int idx = 0; idx < node.getChildCount(); idx++) {
     TreeNode child = node.getChildAt(idx);
     if (child instanceof MPSTreeNode) {
       existing.add(child.toString());
       collectExisting(((MPSTreeNode) child), existing);
     }
   }
 }
Ejemplo n.º 6
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);
  }
Ejemplo n.º 7
0
  private void initializeItems() {
    moveTo = new JMenu(model.getName("SPOT_POPUP_MOVE_ITEM"));

    add(moveTo);
    for (TreeNode n : groups) {
      JMenuItem item = new JMenuItem(n.toString());
      item.addActionListener(this);
      moveTo.add(item);
    }
  }
Ejemplo n.º 8
0
 /** {@inheritDoc} */
 @Override
 public void adviseTodo(String fieldName) {
   CompanionsModel model = (CompanionsModel) companionsTable.getTreeTableModel();
   CompanionsModel.RootNode root = (CompanionsModel.RootNode) model.getRoot();
   for (int i = 0; i < root.getChildCount(); i++) {
     TreeNode node = root.getChildAt(i);
     if (node.toString().startsWith(fieldName)) {
       companionsTable.getSelectionModel().setSelectionInterval(i, i);
       return;
     }
   }
 }
 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;
 }
 /**
  * Returns a copy of the tree starting at the given node.
  *
  * @param tree The tree to copy (may be {@code null}).
  * @return A mutable copy of the given tree, or {@code null} if the tree was null.
  * @todo Use {@code getUserObject} when we can.
  * @since 2.5
  */
 public static MutableTreeNode copy(final TreeNode node) {
   if (node == null) {
     return null;
   }
   final DefaultMutableTreeNode target =
       new DefaultMutableTreeNode(node.toString(), node.getAllowsChildren());
   final Enumeration children = node.children();
   if (children != null) {
     while (children.hasMoreElements()) {
       final TreeNode child = (TreeNode) children.nextElement();
       target.add(copy(child));
     }
   }
   return target;
 }
Ejemplo n.º 11
0
 private void collectNew(
     TreePath path, Collection<String> existing, Collection<TreePath> newNodes) {
   Object lastPathComponent = path.getLastPathComponent();
   if (lastPathComponent instanceof MPSTreeNode) {
     MPSTreeNode node = ((MPSTreeNode) lastPathComponent);
     for (int idx = 0; idx < node.getChildCount(); idx++) {
       TreeNode child = node.getChildAt(idx);
       if (child instanceof MPSTreeNode) {
         TreePath childPath = path.pathByAddingChild(child);
         if (!(existing.contains(child.toString()))) {
           newNodes.add(childPath);
         }
         collectNew(childPath, existing, newNodes);
       }
     }
   }
 }
Ejemplo n.º 12
0
  @Override
  public void valueChanged(TreeSelectionEvent e) {
    // TODO Auto-generated method stub
    try {
      currentPath = tree.getSelectionPath();
      currentnode = (FileTreeNode) e.getPath().getLastPathComponent();
      currentfile = currentnode.GetFile();
      tree.scrollPathToVisible(currentPath); // 确保路径中所有的路径组件均展开(最后一个路径组件除外)并滚动,以便显示curpath路径标识的节点
      addressText.setText(currentnode.GetFile().getAbsolutePath()); // 将点击的节点的路径在地址栏中显示出来
      isTable = false;

      if (!currentfile.getName().equals("Desktop")) {
        Vector files = treeview.GetAll(currentnode.GetFile()); // 获取点击节点下的所有文件
        tablemodel.addAllFiles(files); // 将这些文件加到列表中
        upbtn.setEnabled(true);
        FileNewFolder.setEnabled(true);
        NewFolder.setEnabled(true);
        FileNewFile.setEnabled(true);
        FileNature.setEnabled(true);
        FileRename.setEnabled(true);
        EditCut.setEnabled(true);
        EditCopy.setEnabled(true);
        EditPaste.setEnabled(true);
        NewFile.setEnabled(true);
        Nature.setEnabled(true);
        Rename.setEnabled(true);
        Cut.setEnabled(true);
        Copy.setEnabled(true);
        Paste.setEnabled(true);
        if (!(currentnode.getParent().toString()).equals(File.listRoots())
            && (currentnode.toString() != "网络")
            && (currentnode.toString() != "库")
            && (currentnode.toString() != "家庭组")) // 不是根节点
        {
          FileDelete.setEnabled(true);
          Delete.setEnabled(true);
        } else {
          FileDelete.setEnabled(false);
          Delete.setEnabled(true);
        }
      } else {
        downbtn.setEnabled(false);
        upbtn.setEnabled(false);
        FileNewFolder.setEnabled(false); //  菜单栏中的菜单选项
        FileNewFile.setEnabled(false);
        FileNature.setEnabled(false);
        FileRename.setEnabled(false);
        FileDelete.setEnabled(false);
        EditCut.setEnabled(false);
        EditCopy.setEnabled(false);
        NewFolder.setEnabled(false); //  右键菜单中的菜单选项
        NewFile.setEnabled(false);
        Nature.setEnabled(false);
        Rename.setEnabled(false);
        Delete.setEnabled(false);
        Cut.setEnabled(false);
        Copy.setEnabled(false);
        currentnode = (TreeNode) treemodel.getRoot();
        tablemodel.addAllFiles(treeview.GetRoot());
      }
    } catch (Exception ee) {
      JOptionPane.showMessageDialog(null, "读取文件错误!", "Error", JOptionPane.ERROR_MESSAGE);
      ee.printStackTrace();
    }
  }