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

📄 cachetable.java

📁 world wind java sdk 源码
💻 JAVA
字号:
/*Copyright (C) 2001, 2008 United States Governmentas represented by the Administrator of theNational Aeronautics and Space Administration.All Rights Reserved.*/package gov.nasa.worldwind.examples.util.cachecleaner;import gov.nasa.worldwind.cache.FileStoreDataSet;import javax.swing.*;import javax.swing.table.*;import java.awt.*;import java.text.*;import java.util.*;import java.util.List;/** * @author tag * @version $Id: CacheTable.java 9778 2009-03-30 01:47:35Z tgaskins $ */public class CacheTable extends JTable{    private CacheModel model;    private static class CacheModel extends AbstractTableModel    {        private static final String[] columnTitles =            new String[] {"Dataset", "Last Used", "Size (MB)", "Day Old", "Week Old", "Month Old", "Year Old"};        private static final Class[] columnTypes =            new Class[] {String.class, String.class, Long.class, Long.class, Long.class, Long.class, Long.class};        private ArrayList<FileStoreDataSet> datasets = new ArrayList<FileStoreDataSet>();        private String rootName;        public void setDataSets(String rootName, List<FileStoreDataSet> sets)        {            this.datasets.clear();            this.rootName = rootName;            this.datasets.addAll(sets);        }        public int getRowCount()        {            return this.datasets.size() + 1;        }        public int getColumnCount()        {            return columnTitles.length;        }        @Override        public String getColumnName(int column)        {            return columnTitles[column];        }        @Override        public Class<?> getColumnClass(int columnIndex)        {            return columnTypes[columnIndex];        }        public Object getValueAt(int rowIndex, int columnIndex)        {            if (rowIndex == this.datasets.size()) // Summary row            {                if (columnIndex == 0)                    return "Total Size";                if (columnIndex == 1)                    return "";                Formatter formatter = new Formatter();                return formatter.format("%5.1f", ((float) this.computeColumnSum(columnIndex)) / 1e6);            }            FileStoreDataSet ds = this.datasets.get(rowIndex);            switch (columnIndex)            {                case 0:                {                    return ds.getPath().replace(this.rootName.subSequence(0, this.rootName.length()),                        "".subSequence(0, 0));                }                case 1:                {                    GregorianCalendar cal = new GregorianCalendar();                    cal.setTimeInMillis(ds.getLastModified());                    SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy, hh:mm a");                    return sdf.format(cal.getTime());                }                case 2:                {                    Formatter formatter = new Formatter();                    return formatter.format("%5.1f", ((float) ds.getSize()) / 1e6);                }                case 3:                {                    Formatter formatter = new Formatter();                    return formatter.format("%5.1f", ((float) ds.getOutOfScopeSize(FileStoreDataSet.DAY, 1)) / 1e6);                }                case 4:                {                    Formatter formatter = new Formatter();                    return formatter.format("%5.1f", ((float) ds.getOutOfScopeSize(FileStoreDataSet.WEEK, 1)) / 1e6);                }                case 5:                {                    Formatter formatter = new Formatter();                    return formatter.format("%5.1f", ((float) ds.getOutOfScopeSize(FileStoreDataSet.MONTH, 1)) / 1e6);                }                case 6:                {                    Formatter formatter = new Formatter();                    return formatter.format("%5.1f", ((float) ds.getOutOfScopeSize(FileStoreDataSet.YEAR, 1)) / 1e6);                }            }            return null;        }        private long computeColumnSum(int columnIndex)        {            long size = 0;            for (int row = 0; row < this.datasets.size(); row++)            {                String s = this.getValueAt(row, columnIndex).toString();                long cs = (long) (Double.parseDouble(s) * 1e6);                size += cs;            }            return size;        }    }    public CacheTable()    {        super(new CacheModel());        this.model = ((CacheModel) this.getModel());//        this.setAutoResizeMode(AUTO_RESIZE_OFF);        this.setShowGrid(true);        this.setGridColor(Color.BLACK);        this.setShowHorizontalLines(true);        this.setShowVerticalLines(true);        this.setIntercellSpacing(new Dimension(5, 5));        this.setColumnSelectionAllowed(false);        this.setRowSelectionAllowed(true);        this.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);    }    public void setDataSets(String rootDir, List<FileStoreDataSet> sets)    {        this.model.setDataSets(rootDir, sets);        this.setPreferredColumnWidths();    }    public void deleteDataSet(FileStoreDataSet dataset)    {        this.model.datasets.remove(dataset);        this.resizeAndRepaint();    }    public List<FileStoreDataSet> getSelectedDataSets()    {        int[] rows = this.getSelectedRows();        if (rows.length == 0)            return Collections.emptyList();        ArrayList<FileStoreDataSet> selected = new ArrayList<FileStoreDataSet>();        for (int i : rows)        {            if (i < this.model.datasets.size())                selected.add(this.model.datasets.get(i));        }        return selected;    }    private void setPreferredColumnWidths()    {        for (int col = 0; col < getColumnModel().getColumnCount(); col++)        {            // Start with size of column header            JLabel label = new JLabel(this.getColumnName(col));            int size = label.getPreferredSize().width;            // Find any cells in column that have a wider value            TableColumn column = getColumnModel().getColumn(col);            for (int row = 0; row < this.model.getRowCount(); row++)            {                label = new JLabel(this.getValueAt(row, col).toString());                if (label.getPreferredSize().width > size)                    size = label.getPreferredSize().width;            }            column.setPreferredWidth(size);        }    }}

⌨️ 快捷键说明

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