Example #1
0
  /** *************************************************** */
  private void setCopyList(TreeNode copiedNode) {
    if (index++ == 0) {
      copyFile = new Vector<TreeNode>();
      copyFile.add(copiedNode);

      copiedList.add(copyFile);
      pos = copiedNode.getPath().toString().lastIndexOf(File.separator);
    }

    File[] copieFiles = copiedNode.getFile().listFiles();

    if (copieFiles != null) {
      for (File file : copieFiles) {
        if (file.isDirectory()) {
          copyFile = new Vector<TreeNode>();

          TreeNode node_ = new TreeNode(file);
          copyFile.add(node_);
          copiedList.add(copyFile);

          setCopyList(node_);
        } else {
          copyFile = new Vector<TreeNode>();

          TreeNode node_ = new TreeNode(file);
          copyFile.add(node_);
          copiedList.add(copyFile);
        }
      }
    }
  }
Example #2
0
 @Override
 public void mouseClicked(MouseEvent e) {
   int clickedIndex = table.getSelectedRow(); // 获取鼠标点击的行数
   if (clickedIndex >= 0) {
     EditSelectAll.setEnabled(true);
     SelectAll.setEnabled(true);
     isTable = true;
     currentfile = tablemodel.getFile(clickedIndex);
     addressText.setText(currentfile.getAbsolutePath()); // 地址栏显示路径
     if (!currentnode.getFile().getName().equals(fsv.getHomeDirectory())) {
       FileDelete.setEnabled(true);
       Delete.setEnabled(true);
     }
   }
   if (e.getClickCount() >= 2) {
     EditSelectAll.setEnabled(true);
     SelectAll.setEnabled(true);
     if (currentfile.isDirectory()) // 当单击的是目录
     {
       try {
         upbtn.setEnabled(true);
         if (!tree.isExpanded(currentPath)) tree.expandPath(currentPath); // 将树中对应的节点打开
         if (currentnode.getChildCount() > 0) {
           for (int i = 0; i < currentnode.getChildCount(); i++) {
             FileTreeNode temp =
                 (FileTreeNode) currentnode.getChildAt(i); // 返回currentNode的子节点数组中指定索引处的子节点。
             if (temp.GetFile()
                 .getPath()
                 .equalsIgnoreCase(currentfile.getPath())) // 判断子节点路径是否等于列表中选的的路径
             {
               TreeNode[] nodes = treemodel.getPathToRoot(temp); // 获取从根节点到 temp的路径
               currentPath = new TreePath(nodes);
               tree.setSelectionPath(currentPath); // 选择子节点的父节点
               break;
             }
           }
         }
       } catch (Exception ee) {
         ee.printStackTrace();
       }
     }
     if (currentfile.isFile()) {
       Runtime ce = Runtime.getRuntime();
       String Temp = new String(currentfile.getAbsolutePath());
       String cmdarray = "cmd /c start " + Temp;
       try {
         ce.exec(cmdarray);
       } catch (IOException e1) {
         e1.printStackTrace();
       }
     }
   } else if (e.getButton() == e.BUTTON3) {
     popup.show(e.getComponent(), e.getX(), e.getY());
   }
 }
Example #3
0
  /** *************************************************** */
  public String rename(TreeNode node, String newName) {
    if (node != null) {
      File file = node.getFile();
      String path = ((TreeNode) node.getParent()).getPath() + File.separator + newName;

      file.renameTo(new File(path));

      return path;
    } else {
      return "";
    }
  }
Example #4
0
 public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
   try {
     currentnode = (TreeNode) event.getPath().getLastPathComponent();
     if (!event.getPath().toString().equals(fsv.getHomeDirectory())) {
       Vector directories = treeview.GetAllDirectories(currentnode.getFile());
       appendNodes(currentnode, directories);
       treemodel.nodeStructureChanged(currentnode);
     }
   } catch (Exception ee) {
     JOptionPane.showMessageDialog(null, "读取文件错误!", "提示", JOptionPane.ERROR_MESSAGE);
     ee.printStackTrace();
   }
 }