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

📄 filesystemitem.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
字号:
package com.sslexplorer.vfs;

import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import org.apache.commons.vfs.FileType;

import com.sslexplorer.boot.Util;
import com.sslexplorer.table.TableItem;

/**
 * <p>
 * FileSystemItems are the entries in the file system view. Implements <@link
 * com.sslexplorer.table.TableItem> and <@link java.lang.Comparable>.  
 * 
 * @author James D Robinson
 * 
 * @mail <a href="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
 */
public abstract class FileSystemItem implements TableItem, Comparable {

    private String fileName;
    private Calendar dateModified;
    private String fileType;
    private boolean checked;
    private String bytes;
    private long size;
    private boolean sortFoldersFirst;
    private boolean sortCaseSensitive;
    private int idx;

    /**
     * Constructor sets up class attributes.
     * 
     * @param fileName The name of the file.
     * @param dateModified The date the file was last modified.
     * @param fileType The type of file.
     * @param checked weather the item is to be selected.
     * @param bytes The number of bytes in the file.
     */
    public FileSystemItem(String fileName, Calendar dateModified, String fileType, boolean checked, long bytes, int idx) {
        this.fileName = fileName;
        this.dateModified = dateModified;
        this.fileType = fileType;
        this.checked = checked;
        this.bytes = formatSize(bytes);
        this.size = bytes;
        this.sortFoldersFirst = true;
        this.sortCaseSensitive = false;
        this.idx = idx;
    }

    /**
     * @return Get the date the file was last modified.
     */
    public String getDateModified() {
        return (new SimpleDateFormat()).format(dateModified.getTime());
    }

    /**
     * @param dateModified Set the date the file was last modified.
     */
    public void setDateModified(Calendar dateModified) {
        this.dateModified = dateModified;
    }

    /**
     * @return Get the file name.
     */
    public String getFileName() {
        return fileName;
    }

    /**
     * @return Get the encoded file name.
     */
    public String getEncodedFileName() {
        return Util.urlEncode(getFileName());
    }

    /**
     * @param fileName Set the file name.
     */
    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    /**
     * @return Get the file type.
     */
    public String getFileType() {
        return fileType;
    }

    /**
     * @param fileType Set the file type.
     */
    public void setFileType(String fileType) {
        this.fileType = fileType;
    }

    /**
     * @return Get the selected state.
     */
    public boolean getChecked() {
        return checked;
    }

    /**
     * @param checked Set the selected state.
     */
    public void setChecked(boolean checked) {
        this.checked = checked;
    }

    /* (non-Javadoc)
     * @see com.sslexplorer.table.TableItem#getColumnValue(int)
     */
    public Object getColumnValue(int col) {
        switch (col) {
            case 0:
                return this;
            case 1:
                return dateModified;
            case 2:
                return new Long(size);
        }
        return null;
    }

    /* (non-Javadoc)
     * @see java.lang.Comparable#compareTo(Object)
     */
    public int compareTo(Object arg0) {
        FileSystemItem fsi = (FileSystemItem) arg0;
        int lessThan = -1;
        int moreThan = 1;
        if (!sortFoldersFirst) {
            lessThan = 1;
            moreThan = -1;
        }
        if (fsi.getFileType().equals(FileType.FOLDER.getName()) && this.getFileType().equals(FileType.FILE.getName())) {
            return moreThan;
        } else if (fsi.getFileType().equals(FileType.FILE.getName()) && this.getFileType().equals(FileType.FOLDER.getName())) {
            return lessThan;
        } else {
            if (sortCaseSensitive)
                return fileName.compareToIgnoreCase(fsi.getFileName());
            else
                return fileName.compareTo(fsi.getFileName());
        }
    }

    /**
     * @param path The current path to this location.
     * @return Return the String defining the path when clicked.
     */
    public abstract String onClick(String path);

    /**
     * @return The String to open a folder in web folder view.
     */
    public abstract String getWebFolderPath();

    /**
     * @return The Size of the file in bytes.
     */
    public String getBytes() {
        return bytes;
    }

    /**
     * @param bytes The Size of the file in bytes.
     */
    public void setBytes(long bytes) {
        this.bytes = formatSize(bytes);
    }

    /**
     * @param val Format the size to a specified number of decimal places.
     * @return The new formatted String.
     */
    private String formatSizeDPS(String val) {
        int position = 2 + 1;
        if (val.indexOf(".") + position < val.length()) {
            return val.substring(0, val.indexOf(".") + position);
        } else {
            return val;
        }
    }

    private String formatSize(long bytes) {

        NumberFormat formatMb = NumberFormat.getNumberInstance();
        NumberFormat formatGb = NumberFormat.getNumberInstance();
        NumberFormat formatKb = NumberFormat.getNumberInstance();

        if ((bytes / 1099511627776L) > 0) {
            // Were in the gigabytes
            return formatSizeDPS(formatGb.format((double) bytes / 1099511627776L)) + " GB";
        } else if ((bytes / 1048576) > 0) {
            // Were in the megabytes
            return formatSizeDPS(formatMb.format((double) bytes / 1048576)) + " MB";
        } else {
            // Were still in Kilobytes
            return formatSizeDPS(formatKb.format((double) bytes / 1024)) + " KB";
        }
    }

    public boolean isSortFoldersFirst() {
        return sortFoldersFirst;
    }

    public void setSortFoldersFirst(boolean sortFoldersFirst) {
        this.sortFoldersFirst = sortFoldersFirst;
    }

    public boolean isSortCaseSensitive() {
        return sortCaseSensitive;
    }

    public void setSortCaseSensitive(boolean sortCaseSensitive) {
        this.sortCaseSensitive = sortCaseSensitive;
    }
    
    /**
     * Return a string representation of this file system item. This is
     * used by the generic filter.
     * 
     * @return string representation of file system item
     */
    public String toString() {
        return getFileName();
    }
    
    public int getIdx() {
        return idx;
    }

}

⌨️ 快捷键说明

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