最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java實(shí)現(xiàn)的Windows資源管理器實(shí)例

 更新時(shí)間:2015年07月21日 16:48:12   作者:華宰  
這篇文章主要介紹了Java實(shí)現(xiàn)的Windows資源管理器,實(shí)例分析了基于java實(shí)現(xiàn)windows資源管理器的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了Java實(shí)現(xiàn)的Windows資源管理器。分享給大家供大家參考。具體如下:

FileTree.java文件如下:

// FileTree.java
/***********************************************************
 *  Author: Jason
 *   email: tl21cen@hotmail.com
 * CSDN blog: http://blog.csdn.net/UnAgain/
 ***********************************************************/
package tl.exercise.swing;
import java.awt.Component;
import java.io.File;
import java.util.Vector;
import javax.swing.Icon;
import javax.swing.JTree;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.event.TreeExpansionListener;
import javax.swing.event.TreeModelListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.filechooser.FileSystemView;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
public class FileTree extends JTree {
  static final long serialVersionUID = 0;
  private FileList theList;
  public FileTree(FileList list) {
    theList = list;
    setModel(new FileSystemModel(new FolderNode()));
    this.setCellRenderer(new FolderRenderer());
    addTreeSelectionListener(new TreeSelectionListener() {
      public void valueChanged(TreeSelectionEvent tse) {
      }
    });   
    this.setSelectionRow(0);
  }
  public void fireValueChanged(TreeSelectionEvent tse) {
    TreePath tp = tse.getNewLeadSelectionPath();
    Object o = tp.getLastPathComponent();
    // theList.fireTreeSelectionChanged((PathNode)o);
    theList.fireTreeSelectionChanged((FolderNode) o);
  }
  public void fireTreeCollapsed(TreePath path) {
    super.fireTreeCollapsed(path);
    TreePath curpath = getSelectionPath();
    if (path.isDescendant(curpath)) {
      setSelectionPath(path);
    }
  }
  public void fireTreeWillExpand(TreePath path) {
    System.out.println("Path will expand is " + path);
  }
  public void fireTreeWillCollapse(TreePath path) {
    System.out.println("Path will collapse is " + path);
  }
  class ExpansionListener implements TreeExpansionListener {
    FileTree tree;
    public ExpansionListener(FileTree ft) {
      tree = ft;
    }
    public void treeCollapsed(TreeExpansionEvent tee) {
    }
    public void treeExpanded(TreeExpansionEvent tee) {
    }
  }
}
class FileSystemModel implements TreeModel {
  I_fileSystem theRoot;
  char fileType = I_fileSystem.DIRECTORY;
  public FileSystemModel(I_fileSystem fs) {
    theRoot = fs;
  }
  public Object getRoot() {
    return theRoot;
  }
  public Object getChild(Object parent, int index) {
    return ((I_fileSystem) parent).getChild(fileType, index);
  }
  public int getChildCount(Object parent) {
    return ((I_fileSystem) parent).getChildCount(fileType);
  }
  public boolean isLeaf(Object node) {
    return ((I_fileSystem) node).isLeaf(fileType);
  }
  public int getIndexOfChild(Object parent, Object child) {
    return ((I_fileSystem) parent).getIndexOfChild(fileType, child);
  }
  public void valueForPathChanged(TreePath path, Object newValue) {
  }
  public void addTreeModelListener(TreeModelListener l) {
  }
  public void removeTreeModelListener(TreeModelListener l) {
  }
}
interface I_fileSystem {
  final public static char DIRECTORY = 'D';
  final public static char FILE = 'F';
  final public static char ALL = 'A';
  public Icon getIcon();
  public I_fileSystem getChild(char fileType, int index);
  public int getChildCount(char fileType);
  public boolean isLeaf(char fileType);
  public int getIndexOfChild(char fileType, Object child);
}
/**
 * A data model for a JTree. This model explorer windows file system directly.
 *
 * <p>
 * Perhaps there is a fatal bug with this design. For speed, each of instances
 * of this model contains file objects of subdirectory, up to now, there isn't
 * any method to release them until program be end. I'm afraid that the memory
 * would be full of if the file system is large enough and JVM memery size
 * setted too small.
 *
 * <p>
 * I won't pay more attention to solve it. it isn't goal of current a exercise.
 *
 * @author Jason
 */
class FolderNode implements I_fileSystem {
  // private static FolderNode theRoot;
  private static FileSystemView fsView;
  private static boolean showHiden = true;;
  private File theFile;
  private Vector<File> all = new Vector<File>();
  private Vector<File> folder = new Vector<File>();
  /**
   * set that whether apply hiden file.
   *
   * @param ifshow
   */
  public void setShowHiden(boolean ifshow) {
    showHiden = ifshow;
  }
  public Icon getIcon() {
    return fsView.getSystemIcon(theFile);
  }
  public String toString() {
    // return fsView.
    return fsView.getSystemDisplayName(theFile);
  }
  /**
   * create a root node. by default, it should be the DeskTop in window file
   * system.
   *
   */
  public FolderNode() {
    fsView = FileSystemView.getFileSystemView();
    theFile = fsView.getHomeDirectory();
    prepareChildren();
  }
  private void prepareChildren() {
   File[] files = fsView.getFiles(theFile, showHiden);
    for (int i = 0; i < files.length; i++) {
      all.add(files[i]);
      if (files[i].isDirectory()
          && !files[i].toString().toLowerCase().endsWith(".lnk")) {
        folder.add(files[i]);
      }
    }
  }
  private FolderNode(File file) {
    theFile = file;
    prepareChildren();
  }
  public FolderNode getChild(char fileType, int index) {
    if (I_fileSystem.DIRECTORY == fileType) {
      return new FolderNode(folder.get(index));
    } else if (I_fileSystem.ALL == fileType) {
      return new FolderNode(all.get(index));
    } else if (I_fileSystem.FILE == fileType) {
      return null;
    } else {
      return null;
    }
  }
  public int getChildCount(char fileType) {
    if (I_fileSystem.DIRECTORY == fileType) {
      return folder.size();
    } else if (I_fileSystem.ALL == fileType) {
      return all.size();
    } else if (I_fileSystem.FILE == fileType) {
      return -1;
    } else {
      return -1;
    }
  }
  public boolean isLeaf(char fileType) {
    if (I_fileSystem.DIRECTORY == fileType) {
      return folder.size() == 0;
    } else if (I_fileSystem.ALL == fileType) {
      return all.size() == 0;
    } else if (I_fileSystem.FILE == fileType) {
      return true;
    } else {
      return true;
    }
  }
  public int getIndexOfChild(char fileType, Object child) {
    if (child instanceof FolderNode) {
      if (I_fileSystem.DIRECTORY == fileType) {
        return folder.indexOf(((FolderNode) child).theFile);
      } else if (I_fileSystem.ALL == fileType) {
        return all.indexOf(((FolderNode) child).theFile);
      } else if (I_fileSystem.FILE == fileType) {
        return -1;
      } else {
        return -1;
      }
    } else {
      return -1;
    }
  }
}
class FolderRenderer extends DefaultTreeCellRenderer {
  private static final long serialVersionUID = 1L;
  public Component getTreeCellRendererComponent(JTree tree, Object value,
      boolean sel, boolean expanded, boolean leaf, int row,
      boolean hasFocus) {
    I_fileSystem node = (I_fileSystem) value;
    Icon icon = node.getIcon();
    setLeafIcon(icon);
    setOpenIcon(icon);
    setClosedIcon(icon);
    return super.getTreeCellRendererComponent(tree, value, sel, expanded,
       leaf, row, hasFocus);
  }
}

希望本文所述對大家的java程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • java實(shí)現(xiàn)雙色球彩票游戲

    java實(shí)現(xiàn)雙色球彩票游戲

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)雙色球彩票游戲,超級簡單的邏輯,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-06-06
  • java實(shí)現(xiàn)死鎖的示例代碼

    java實(shí)現(xiàn)死鎖的示例代碼

    本篇文章主要介紹了java實(shí)現(xiàn)死鎖的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-01-01
  • Java接入微信支付超級詳細(xì)保姆級教程

    Java接入微信支付超級詳細(xì)保姆級教程

    這篇文章主要給大家介紹了關(guān)于Java接入微信支付的相關(guān)資料,包括l 準(zhǔn)備開發(fā)所需的賬號和配置信息、準(zhǔn)備環(huán)境、設(shè)置開發(fā)參數(shù)以及實(shí)現(xiàn)支付接口,回調(diào)地址的設(shè)置和異步回調(diào)通知的處理也是文章的重點(diǎn)內(nèi)容,需要的朋友可以參考下
    2024-12-12
  • SpringBoot整合sharding-jdbc?實(shí)現(xiàn)分庫分表操作的示例代碼

    SpringBoot整合sharding-jdbc?實(shí)現(xiàn)分庫分表操作的示例代碼

    在Spring?Boot中使用ShardingSphere的Sharding-JDBC來實(shí)現(xiàn)數(shù)據(jù)庫的分庫分表是一個(gè)常見的需求,下面就拉具體介紹一下實(shí)現(xiàn)步驟,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2025-04-04
  • IDEA Error:java: 無效的源發(fā)行版: 17錯(cuò)誤

    IDEA Error:java: 無效的源發(fā)行版: 17錯(cuò)誤

    本文主要介紹了IDEA Error:java: 無效的源發(fā)行版: 17錯(cuò)誤,這個(gè)錯(cuò)誤是因?yàn)槟腎DEA編譯器不支持Java 17版本,您需要更新您的IDEA編譯器或者將您的Java版本降級到IDEA支持的版本,本文就來詳細(xì)的介紹一下
    2023-08-08
  • Java初始化List方法代碼實(shí)例

    Java初始化List方法代碼實(shí)例

    這篇文章主要介紹了Java初始化List方法代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-06-06
  • java依賴jave-all-deps實(shí)現(xiàn)視頻格式轉(zhuǎn)換

    java依賴jave-all-deps實(shí)現(xiàn)視頻格式轉(zhuǎn)換

    jave-all-deps是一款基于FFmpeg庫的Java音視頻編解碼庫,本文主要介紹了java依賴jave-all-deps實(shí)現(xiàn)視頻格式轉(zhuǎn)換,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-07-07
  • SpringBoot使用Apache?POI實(shí)現(xiàn)導(dǎo)入導(dǎo)出Excel文件

    SpringBoot使用Apache?POI實(shí)現(xiàn)導(dǎo)入導(dǎo)出Excel文件

    Apache?POI?是一個(gè)強(qiáng)大的?Java?庫,用于處理?Microsoft?Office?文檔,下面我們來看看SpringBoot如何使用Apache?POI導(dǎo)入導(dǎo)出Excel文件功能吧
    2025-01-01
  • mybatis如何使用Map接收返回值

    mybatis如何使用Map接收返回值

    這篇文章主要介紹了mybatis如何使用Map接收返回值問題,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-12-12
  • Java編程實(shí)現(xiàn)打地鼠文字游戲?qū)嵗a

    Java編程實(shí)現(xiàn)打地鼠文字游戲?qū)嵗a

    這篇文章主要介紹了Java編程實(shí)現(xiàn)打地鼠文字游戲?qū)嵗a,具有一定借鑒價(jià)值,需要的朋友可以參考下。
    2017-11-11

最新評論

绍兴县| 锡林郭勒盟| 伊通| 北辰区| 淮北市| 冕宁县| 谷城县| 英德市| 常宁市| 万载县| 政和县| 于都县| 福州市| 长丰县| 沽源县| 隆化县| 曲靖市| 凤翔县| 中山市| 鹰潭市| 密云县| 永德县| 漯河市| 浮山县| 达日县| 龙州县| 珲春市| 龙胜| 绥中县| 额敏县| 阿合奇县| 天全县| 武邑县| 邵阳市| 彩票| 奉节县| 南皮县| 随州市| 永靖县| 华安县| 桂平市|