欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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)文章

  • Nacos配置中心設(shè)計(jì)原理分析

    Nacos配置中心設(shè)計(jì)原理分析

    今天分享一下Nacos配置變更的相關(guān)知識(shí)點(diǎn),現(xiàn)在使用Java生態(tài)如果使用微服務(wù),如果部署在K8s上,那么可能會(huì)使用ConfigMap來存儲(chǔ)配置文件,如果沒有使用K8s,那么基本上都使用Nacos來做配置中心,所以有必要了解一下Nacos的配置的知識(shí)點(diǎn),本文只是對其中的部分實(shí)現(xiàn)原理進(jìn)行分析
    2023-10-10
  • Mybatis?Plus?新版lambda?表達(dá)式查詢異常的處理

    Mybatis?Plus?新版lambda?表達(dá)式查詢異常的處理

    這篇文章主要介紹了Mybatis?Plus?新版lambda?表達(dá)式查詢異常的處理方案,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-01-01
  • Java OpenCV圖像處理之背景切換

    Java OpenCV圖像處理之背景切換

    這篇文章主要介紹了利用Java OpenCV實(shí)現(xiàn)圖像背景的切換,文中的示例代碼講解詳細(xì)。對我們學(xué)習(xí)OpenCV有一定幫助,感興趣的同學(xué)可以了解一下
    2022-01-01
  • Springboot+MybatisPlus+Oracle實(shí)現(xiàn)主鍵自增的示例代碼

    Springboot+MybatisPlus+Oracle實(shí)現(xiàn)主鍵自增的示例代碼

    這篇文章主要介紹了Springboot+MybatisPlus+Oracle實(shí)現(xiàn)主鍵自增的示例代碼,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-11-11
  • java中BCryptPasswordEncoder密碼的加密與驗(yàn)證方式

    java中BCryptPasswordEncoder密碼的加密與驗(yàn)證方式

    這篇文章主要介紹了java中BCryptPasswordEncoder密碼的加密與驗(yàn)證方式,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-08-08
  • Maven修改運(yùn)行環(huán)境配置代碼實(shí)例

    Maven修改運(yùn)行環(huán)境配置代碼實(shí)例

    這篇文章主要介紹了Maven修改運(yùn)行環(huán)境配置代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-04-04
  • SpringBoot之Refresh流程的簡單說明

    SpringBoot之Refresh流程的簡單說明

    這篇文章主要介紹了SpringBoot之Refresh流程的簡單說明,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-09-09
  • Java對日期Date類進(jìn)行加減運(yùn)算、年份加減月份加減、時(shí)間差等等

    Java對日期Date類進(jìn)行加減運(yùn)算、年份加減月份加減、時(shí)間差等等

    這篇文章主要介紹了Java對日期Date類進(jìn)行加減運(yùn)算、年份加減月份加減、時(shí)間差等等,在網(wǎng)上查閱資料,加上自己總結(jié)的一些關(guān)于Date類的工具類
    2017-01-01
  • Java設(shè)計(jì)模式之外觀模式解析

    Java設(shè)計(jì)模式之外觀模式解析

    這篇文章主要介紹了Java設(shè)計(jì)模式之外觀模式解析,外觀模式提供了一個(gè)統(tǒng)一的接口,用來訪問子系統(tǒng)中的一群接口,外觀定義了一個(gè)高層接口,讓子系統(tǒng)更容易使用,需要的朋友可以參考下
    2024-01-01
  • java 內(nèi)部類的實(shí)例詳解

    java 內(nèi)部類的實(shí)例詳解

    這篇文章主要介紹了java 內(nèi)部類的實(shí)例詳解的相關(guān)資料,希望通過本文大家能夠理解掌握java內(nèi)部類的使用,需要的朋友可以參考下
    2017-09-09

最新評論