⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 left_treepane.java

📁 使用java技术写的一个图像处理框架,实现了目录树,分割窗格,任务栏图标等技术
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * Explores the directory specified by the parent tree node in the left tree
     * and the selected subdirectory in the right table.
     */  /*
    private void exploreDirectory(MyTreeNode parentTreeNode,
            File selectedSubDir) {
        if (!parentTreeNode.isExplored()) {
            parentTreeNode.explore();
        }

        int count = myTree.getModel().getChildCount(parentTreeNode);

        for (int i = 0; i < count; i++) {
            Object oneChild = myTree.getModel().getChild(parentTreeNode, i);

            if (oneChild instanceof MyTreeNode) {
                File file = (File) ((MyTreeNode) oneChild).getUserObject();

                if (file.equals(selectedSubDir)) {
                    selectedNode = (MyTreeNode) oneChild;
                    break;
                }
            }
        }

        TreePath newPath = new TreePath(selectedNode.getPath());

        if (myTree.isExpanded(newPath)) {
            // if the new path is already expanded, just select it.
            myTree.setSelectionPath(newPath);
            myTree.scrollPathToVisible(newPath);
        } else {
            myTree.expandPath(newPath);
        }
    }

    /**
     * Expands the tree to the given path.
     */    /*
    private void expandPaths(JTree tree, List paths) {
        Iterator iter = paths.iterator();

        if (!iter.hasNext()) {
            return;
        }

        MyTreeNode parentNode = (MyTreeNode) tree.getModel().getRoot();

        if (!parentNode.isExplored()) {
            parentNode.explore();
        }

        // ===
        // For Windows "My Computer" node only.
        // ===
        // Ignore the root node "My Computer", since the path for this node
        // is not in the path list of the expanded node.
        File parentFile = (File) ((MyTreeNode) parentNode).getUserObject();

        if (parentFile.equals(new File(temppath))) {
            int count = myTree.getModel().getChildCount(parentNode);
            boolean pathNotFound = true;

            for (int i = 0; i < count; i++) {
                Object oneChild = myTree.getModel().getChild(parentNode, i);
                String onePath = ((MyTreeNode) oneChild).toString();

                if (onePath.equalsIgnoreCase((String) iter.next())) {
                    parentNode = (MyTreeNode) oneChild;
                    pathNotFound = false;
                    break;
                }
            }
        } else {
            if (!parentFile.equals((String) iter.next())) {
                return;
            }
        }

        boolean pathNotFound = false;

        while (iter.hasNext() && !pathNotFound) {
            if (!parentNode.isExplored()) {
                parentNode.explore();
            }

            String nextPath = (String) iter.next();

            pathNotFound = true;
            int count = myTree.getModel().getChildCount(parentNode);

            for (int i = 0; i < count; i++) {
                Object oneChild = myTree.getModel().getChild(parentNode, i);
                String onePath = ((MyTreeNode) oneChild).toString();

                if (onePath.equalsIgnoreCase(nextPath)) {
                    parentNode = (MyTreeNode) oneChild;
                    pathNotFound = false;
                    break;
                }
            }
        }

        if (pathNotFound) {
            return;
        } else {
            selectedNode = parentNode;
            TreePath newPath = new TreePath(selectedNode.getPath());

            if (myTree.isExpanded(newPath)) {
                // if the new path is already expanded, just select it.
                myTree.setSelectionPath(newPath);
                myTree.scrollPathToVisible(newPath);
            } else {
                myTree.expandPath(newPath);
            }
        }
    }

    /**
     * Explores the specified directory by expanding the right tree to it path,
     * and display it's subdirectories and files in the right table.
     */ /*
    private void exploreDirectory(File selectedDir) {
        // First parse the given directory path into separate path names/fields.
        List paths = new ArrayList();
        String selectedAbsPath = selectedDir.getAbsolutePath();
        int beginIndex = 0;
        int endIndex = selectedAbsPath.indexOf(File.separator);

        // For the first path name, attach the path separator.
        // For Windows, it should be like 'C:\', for Unix, it should be like '/'.
        paths.add(selectedAbsPath.substring(beginIndex, endIndex + 1));
        beginIndex = endIndex + 1;
        endIndex = selectedAbsPath.indexOf(File.separator, beginIndex);
        while (endIndex != -1) {
            // For other path names, do not attach the path separator.
            paths.add(selectedAbsPath.substring(beginIndex, endIndex));
            beginIndex = endIndex + 1;
            endIndex = selectedAbsPath.indexOf(File.separator, beginIndex);
        }
        String lastPath = selectedAbsPath.substring(beginIndex,
                selectedAbsPath.length());

        if ((lastPath != null) && (lastPath.length() != 0)) {
            paths.add(lastPath);
        }

        expandPaths(myTree, paths);
    }

    class Left_treepane_myTree_treeSelectionAdapter
        implements javax.swing.event.TreeSelectionListener {
    Left_treepane adaptee;

    Left_treepane_myTree_treeSelectionAdapter(Left_treepane adaptee) {
        this.adaptee = adaptee;
    }

    public void valueChanged(TreeSelectionEvent e) {
        adaptee.myTree_valueChanged(e);
    }
}

class Left_treepane_myTree_treeExpansionAdapter implements javax.swing.event.TreeExpansionListener {
    Left_treepane adaptee;

    Left_treepane_myTree_treeExpansionAdapter(Left_treepane adaptee) {
        this.adaptee = adaptee;
    }

    public void treeExpanded(TreeExpansionEvent e) {
        adaptee.myTree_treeExpanded(e);
    }

    public void treeCollapsed(TreeExpansionEvent e) {}
}


class Left_treepane_myTree_mouseAdapter extends java.awt.event.MouseAdapter {
    Left_treepane adaptee;

    Left_treepane_myTree_mouseAdapter(Left_treepane adaptee) {
        this.adaptee = adaptee;
    }

    public void mouseClicked(MouseEvent e) {
        adaptee.myTree_mouseClicked(e);
    }
}


class Left_treepane_myTree_treeWillExpandAdapter implements javax.swing.event.TreeWillExpandListener {
    Left_treepane adaptee;

    Left_treepane_myTree_treeWillExpandAdapter(Left_treepane adaptee) {
        this.adaptee = adaptee;
    }

    public void treeWillExpand(TreeExpansionEvent e) throws ExpandVetoException {
        adaptee.myTree_treeWillExpand(e);
    }

    public void treeWillCollapse(TreeExpansionEvent e) {}
}
*/
}
class Left_treepane_willExpand implements TreeWillExpandListener
{
    Left_treepane left=null;
    public Left_treepane_willExpand(Left_treepane left)
    {
        this.left=left;
    }
    public void treeWillExpand(TreeExpansionEvent event)
    {
        left.leftwillExpand(event);
    }
    public void treeWillCollapse(TreeExpansionEvent event)
    {

    }
}
class Left_treepane_selection implements TreeSelectionListener
{
   Left_treepane left=null;
   public Left_treepane_selection(Left_treepane left)
   {
      this.left=left;
   }
   public void valueChanged(TreeSelectionEvent e)
   {
     left.treeSelection(e);
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -