jsearchdisk.java
来自「JavaExplorer是一个独立于平台的浏览器」· Java 代码 · 共 526 行 · 第 1/2 页
JAVA
526 行
/** * File and FTP Explorer * Copyright 2002 * 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.disk;import java.awt.*;import java.awt.event.*;import java.util.*;import javaexplorer.Launcher;import javaexplorer.gui.dnd.*;import javaexplorer.gui.renderer.*;import javaexplorer.gui.treenode.*;import javaexplorer.gui.treenode.xfile.*;import javaexplorer.model.*;import javaexplorer.ressource.*;import javaexplorer.util.filter.CustomFilter;import javaexplorer.util.options.Options;import javax.swing.*;import javax.swing.border.*;import javax.swing.tree.*;/** *@author BOESCH Vincent *@created 21 janvier 2002 *@version 3.3 */public class JSearchDisk extends JPanel implements Runnable, ActionListener, Disk { private boolean _booSearchStopped = true; private Launcher _launcher = null; private XFile _xroot = null; Border border1; Border border2; BorderLayout borderLayout1 = new BorderLayout(); BorderLayout borderLayout2 = new BorderLayout(); BorderLayout borderLayout3 = new BorderLayout(); BorderLayout borderLayout4 = new BorderLayout(); private CustomFilter cf = new CustomFilter(); JButton JButtonSearch = new JButton(); JTextField JTextFieldSearchForText = new JTextField(); JCheckBox JCheckBoxMatchCase = new JCheckBox(); JLabel JLabelSearchForText = new JLabel(); JLabel jLabel1 = new JLabel(); JLabel JLabelStatus = new JLabel(); XTable xtable = null; XFileTableCellRenderer xftcr = new XFileTableCellRenderer(true); JPanel JPanelTab1Main = new JPanel(); JPanel JPanelSearchResults = new JPanel(); JPanel JPanelSearchCriteria = new JPanel(); JPanel JPanelSearchCriteriaFileName = new JPanel(); JPanel JPanelSearchCriteriaFileContents = new JPanel(); JPanel JPanelSearchCriteriaFileDate = new JPanel(); JLabel JLabelDateFrom = new JLabel(); JTextField JTextFieldFromDate = new JTextField(); JLabel JLabelDateTo = new JLabel(); JTextField JTextFieldToDate = new JTextField(); boolean SearchContents = false; String SearchString = ""; boolean UseDateRange = false; java.util.Date DateFrom; java.util.Date DateTo; JTabbedPane jTabbedPane1 = new JTabbedPane(); JTextField JTextFieldFileCriteria = new JTextField(); XTree jTree1 = new XTree(); JScrollPane jScrollPane1 = new JScrollPane(jTree1); JScrollPane jScrollPane2 = null; private Thread threadSearcher = null; TitledBorder titledBorder1; TitledBorder titledBorder2; /** * Constructor for the JSearchDisk object * *@param launcher Description of the * Parameter */ public JSearchDisk(Launcher launcher) { this(null, launcher); } /** * Constructor for the JSearchDisk object * *@param root Description of the * Parameter *@param launcher Description of the * Parameter */ public JSearchDisk(XFile root, Launcher launcher) { _xroot = root; _launcher = launcher; if (Options.getOptions().getUseDragAndDrop()) { xtable = new DNDTable(_launcher); } else { xtable = new XTable(_launcher); } xtable.setDefaultRenderer(Object.class, xftcr); jScrollPane2 = new JScrollPane(xtable); try { jbInit(); } catch (Exception e) { javaexplorer.util.Log.addError(e); } } /** * Implementation de l'action Listener * *@param e Description of the Parameter */ public void actionPerformed(ActionEvent e) { Object obj = e.getSource(); if ((obj == JButtonSearch) || (obj == JTextFieldFileCriteria)) { startStopSearch(); } } /** * Adds a feature to the Recursive attribute * of the JSearchDisk object * *@param f The feature to be added to * the Recursive attribute */ private void addRecursive(XFile f) { if (_booSearchStopped) { return; } if (f.isDirectory()) { XFile[] tb_file = f.listXFiles(cf); if (tb_file != null) { for (int i = 0; i < tb_file.length; i++) { addRecursive(tb_file[i]); } } } else { if (cf.accept(f)) { boolean DateOK = true; if (UseDateRange) { DateOK = false; java.util.Date DateFileLastModified = new java.util.Date(f.lastModified()); if (DateFileLastModified.after(DateFrom) && DateFileLastModified.before(DateTo)) { DateOK = true; } } if (DateOK) { if (SearchContents) { if (searchBytesFromFile(f, SearchString, JCheckBoxMatchCase.isSelected())) { xtable.addElement(f); } } else { xtable.addElement(f); } } JLabelStatus.setText(TextRessource.SEARCHSCREEN_PERFORMING_SEARCH + " : " + TextRessource.SEARCHSCREEN_ELEMENTS_FOUND + " " + xtable.getElementCount()); } } } public boolean searchBytesFromFile(XFile xfile, String search, boolean caseSensitive) { try { if ((search == null) || (search.length() == 0)) { return false; } java.io.InputStream in = xfile.getInputStream(0); StringBuffer sb = new StringBuffer(); int len = search.length() * 8; byte[] buff = new byte[len * 100]; javax.swing.ProgressMonitorInputStream pm = new javax.swing.ProgressMonitorInputStream(this, TextRessource.SEARCHSCREEN_READING_FILE + " " + xfile.getPath(), in); // read the file. If it's taking too long, the progress // monitor will appear. The amount of time is roughly // 1/100th of the estimated read time (based on how long // it took to read the first 1/100th of the file.) // Note that by default, the dialog won't appear unless // the overall estimate is over 2 seconds. while ((pm.read(buff) != -1) && (!_booSearchStopped)) { sb.append(new String(buff)); String readStr = caseSensitive ? sb.toString() : sb.toString().toUpperCase(); if (readStr.indexOf(caseSensitive ? search : search.toUpperCase()) != -1) { pm.close(); return true; } sb.delete(0, sb.length() - len); } pm.close(); return false; } catch (Exception e) { return false; } } /** * Gets the root attribute of the JSearchDisk * object * *@return The root value */ public Object getRoot() { //Sans objet return _xroot; } /** * Gets the selectedEntries attribute * of the JSearchDisk object * *@return The selectedEntries value */ public XFile[] getSelectedEntries() { return xtable.getSelectedValues();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?