xfiletablemodel.java
来自「JavaExplorer是一个独立于平台的浏览器」· Java 代码 · 共 173 行
JAVA
173 行
/** * File and FTP Explorer * Copyright 2003 * BOESCH Vincent * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */package javaexplorer.gui.renderer;import java.util.Arrays;import javaexplorer.model.XFile;import javaexplorer.ressource.TextRessource;import javaexplorer.util.comparator.XFileComparator;import javaexplorer.util.filter.ImageFilter;import javaexplorer.util.options.Options;import javax.swing.table.*;public class XFileTableModel extends AbstractTableModel implements Runnable{ private XFile _root = null; private XFile[] _lst = null; //Par d閒aut, tri sur le nom public XFileComparator xfc = new XFileComparator(); public XFileTableModel() { } public int size() { return ((_lst == null) ? 0 : _lst.length); } public void removeAll() { _root = null; _lst = null; fireTableDataChanged(); } public void addElement(XFile xf) { if (xf == null) { return; } if (_lst == null) { _lst = new XFile[1]; _lst[0] = xf; } else { XFile[] tmp = new XFile[_lst.length + 1]; System.arraycopy(_lst, 0, tmp, 0, _lst.length); tmp[_lst.length] = xf; _lst = null; _lst = tmp; } fireTableDataChanged(); } public void setRoot(XFile root) { _root = root; populate(); } public void showWait(){ _lst = new XFile[]{new XFileTableFiler(TextRessource.INTERNAL_CREATING)}; fireTableDataChanged(); } public void run(){ populate(); } private void populate() { if ((_root == null) || (!_root.isDirectory())) { _lst = null; fireTableDataChanged(); return; } if (Options.getOptions().getShowImagesOnly()) { _lst = _root.listXFiles(new ImageFilter()); } else { _lst = _root.listXFiles(); } if (_lst != null) { Arrays.sort(_lst, xfc); } fireTableDataChanged(); } public XFile getRoot() { return _root; } public String getColumnName(int col) { switch (col) { case 0: return TextRessource.INTERNAL_NAME; case 1: return TextRessource.INTERNAL_SIZE; case 2: return TextRessource.INTERNAL_MODIFIED; default: return super.getColumnName(col); } } public void sort(int colIndex) { switch (colIndex) { case 0: xfc.setSortMethod(XFileComparator.SORT_NAME); break; case 1: xfc.setSortMethod(XFileComparator.SORT_SIZE); break; case 2: xfc.setSortMethod(XFileComparator.SORT_DATE); break; default: xfc.setSortMethod(XFileComparator.SORT_NAME); } Arrays.sort(_lst, xfc); fireTableDataChanged(); } public int getColumnCount() { return 3; } public int getRowCount() { if (_lst == null) { return 0; } return _lst.length; } public Object getValueAt(int row, int column) { if ((_lst == null) || (row < 0) || (row >= _lst.length)) { return null; } return (Object) _lst[row]; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?