jefdisk.java
来自「JavaExplorer是一个独立于平台的浏览器」· Java 代码 · 共 400 行
JAVA
400 行
/** * 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.disk;import java.awt.*;import java.awt.event.*;import javaexplorer.Launcher;import javaexplorer.gui.dnd.*;import javaexplorer.gui.renderer.*;import javaexplorer.gui.treenode.*;import javaexplorer.gui.treenode.xfile.*;import javaexplorer.gui.viewer.*;import javaexplorer.model.*;import javaexplorer.ressource.*;import javaexplorer.util.ExplorerUtil;import javaexplorer.util.filter.*;import javaexplorer.util.options.*;import javax.swing.*;import javax.swing.border.*;import javax.swing.event.*;import javax.swing.tree.*;/** *@author BOESCH Vincent *@created 21 janvier 2002 *@version 3.3 */public class JEFDisk extends JPanel implements EFDisk, TreeSelectionListener,ListSelectionListener, ActionListener { class FileParser implements Runnable { XFile ef = null; public FileParser(XFile xf) { ef = xf; } public void run() { ExplorerUtil.mouseDisabled(xtable); xtable.showWait(); xtable.setRoot(ef); ExplorerUtil.mouseEnabled(xtable); } } /** * Description of the Field */ protected boolean _booShowImagesOnly = false; /** * Description of the Field */ protected boolean _booShowImagesPreview = true; private Launcher _launcher = null; /** * Description of the Field */ protected XFile _root = null; private XFileTreeNode _rootNode = null; private BorderLayout borderLayout1 = new BorderLayout(); XFileTreeCellRenderer eftcr = new XFileTreeCellRenderer(); /** * Description of the Field */ protected ImageFilter fif = new ImageFilter(); /** */ protected boolean isGlobalExplorer = false; private JButton jbtSelectAll = new JButton(); private JButton jbtUpDir = new JButton(); JImageViewer jis = null; private JLabel jlbCurDir = new JLabel(); private JPanel jPanel1 = new JPanel(); JSplitPane jSplitPane1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); JScrollPane jspTree1 = null; JScrollPane jspTree2 = null; XTree jTree1 = null; private TitledBorder titledBorder1; XFileTableCellRenderer xftcr = new XFileTableCellRenderer(false); XTable xtable = null; /** * Constructor for the JAbstractDisk object * *@param launcher Description of the Parameter */ public JEFDisk(Launcher launcher) { try { _launcher = launcher; if (Options.getOptions().getUseDragAndDrop()) { jTree1 = new DNDTree(_launcher); xtable = new DNDTable(_launcher); } else { jTree1 = new XTree(); xtable = new XTable(_launcher); } xtable.setDefaultRenderer(Object.class, xftcr); jspTree1 = new JScrollPane(jTree1); jspTree2 = new JScrollPane(xtable); jbInit(); } catch (Exception e) { javaexplorer.util.Log.addError(e); } } /** *@param e Description of the Parameter */ public void actionPerformed(ActionEvent e) { Object obj = e.getSource(); if (obj == jbtUpDir) { XFile dir = getCurrentDir(); XFile pDir = dir.getXParent(); if (pDir != null) { setCurrentDir(pDir); } } else if (obj == jbtSelectAll) { xtable.selectAll(); _launcher.getFileModel().getSelectBuffer().set(getSelectedEntries()); _launcher.getMDIModel().updateStatus(); } } /** * Mise en oeuvre du dimensionnement automatique lors de la preview des images */ private void applyZoomFactor() { Dimension d1 = jis.getSize(); Dimension d2 = jis.getImageSize(); float zoomFactor = (float) Math.min((double) d1.getWidth() / (double) d2.getWidth(), (double) d1.getHeight() / (double) d2.getHeight()); jis.setZoomFactor(zoomFactor); } /** * Gets the component attribute of the JEFDisk object * *@return The component value */ public Component getComponent() { return this; } /** * Gets the CurrentDir attribute of the JAbstractDisk object * *@return The CurrentDir value */ public XFile getCurrentDir() { TreePath tp = jTree1.getSelectionPath(); if (tp != null) { XFileTreeNode jdtn = (XFileTreeNode) tp.getLastPathComponent(); if (jdtn != null) { return jdtn.getXFile(); } } return null; } /** * Gets the root attribute of the JEFDisk object * *@return The root value */ public XFile getRoot() { return _root; } /** * Gets the selectedEntries attribute of the JEFDisk object * *@return The selectedEntries value */ public XFile[] getSelectedEntries() { return xtable.getSelectedValues(); } //M閠hodes a impl閙enter /** * Description of the Method */ public void init() { if (isGlobalExplorer) { jTree1.setRootVisible(false); _rootNode = new JExplorerEFTreeNode(_launcher); jTree1.setModel(new ExplorerTreeModel(_rootNode)); } else { // _rootNode = new JEFDirTreeNode(_root); _rootNode = new JEFDirTreeNode(_root, false); jTree1.setModel(new ExtendedTreeModel(_rootNode)); } jTree1.setSelectionRow(0); } /** * Description of the Method * *@exception Exception Description of Exception */ private void jbInit() throws Exception { _booShowImagesOnly = Options.getOptions().getShowImagesOnly(); _booShowImagesPreview = Options.getOptions().getShowImagesPreview(); titledBorder1 = new TitledBorder(""); xtable.setFont(jTree1.getFont()); jTree1.setCellRenderer(eftcr); xtable.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(MouseEvent e) { xtable_mouseClicked(e); } }); //On ajoute un listener sur le JScrollPane afin de g閞er le click droit //Lorsque la table ne contient aucun element jspTree2.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(MouseEvent e) { if ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { _launcher.getMDIModel().makeXFilesPopup( new XFile[] {getCurrentDir()}, (int) jspTree2.getLocationOnScreen().getX() + e.getX(), (int) jspTree2.getLocationOnScreen().getY() + e.getY()); } } }); xtable.getSelectionModel().addListSelectionListener(this); jTree1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(MouseEvent e) { jTree1_mouseClicked(e); } }); jTree1.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); jTree1.addTreeSelectionListener(this); this.setLayout(new BorderLayout()); jPanel1.setLayout(borderLayout1); jlbCurDir.setForeground(Color.black); jlbCurDir.setBorder(BorderFactory.createLoweredBevelBorder()); jlbCurDir.setToolTipText(""); jPanel1.setBorder(titledBorder1); borderLayout1.setHgap(10); this.add(jSplitPane1, BorderLayout.CENTER); this.add(jPanel1, BorderLayout.NORTH); jPanel1.add(jlbCurDir, BorderLayout.CENTER); jPanel1.add(jbtUpDir, BorderLayout.WEST); jPanel1.add(jbtSelectAll, BorderLayout.EAST); jSplitPane1.add(jspTree1, JSplitPane.LEFT); jSplitPane1.setDividerLocation(100); jSplitPane1.setContinuousLayout(true); if (_booShowImagesPreview) { jis = new JImageViewer(); jis.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); jis.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); JSplitPane jSplitPane2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT); jSplitPane2.add(jspTree2, JSplitPane.TOP); jSplitPane2.add(jis, JSplitPane.BOTTOM); jSplitPane1.add(jSplitPane2, JSplitPane.RIGHT); } else { jSplitPane1.add(jspTree2, JSplitPane.RIGHT); } jbtUpDir.setIcon(ImageRessource.iiUpDir); jbtUpDir.addActionListener(this); jbtSelectAll.setIcon(ImageRessource.iiSelectAll); jbtSelectAll.addActionListener(this); } /** *@param e Description of the Parameter */ void jTree1_mouseClicked(MouseEvent e) { _launcher.getMDIModel().closePopups(); if ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { TreePath tp = jTree1.getClosestPathForLocation(e.getX(), e.getY()); if (tp != null) { XFile xf = ((XFileTreeNode) tp.getLastPathComponent()).getXFile(); _launcher.getMDIModel().makeXFilesPopup(new XFile[] { xf }, (int) jTree1.getLocationOnScreen().getX() + e.getX(), (int) jTree1.getLocationOnScreen().getY() + e.getY()); } } } /** * Description of the Method * *@param e_ftn Description of Parameter */ public void refreshView(XFile e_ftn) { XFile cDir = getCurrentDir(); TreePath tpold = jTree1.getSelectionPath(); //Si le fichier est null, refresh global, puis repositionnement sur rep courant if (e_ftn == null) { e_ftn = cDir; } XFile xPar = null; if (e_ftn.isDirectory()) { xPar = e_ftn; } else { xPar = e_ftn.getXParent(); } XFileTreeNode node = _rootNode.getNodeForRefresh(xPar); if( node != null ){ node.refreshChildren(); ((DefaultTreeModel)jTree1.getModel()).nodeStructureChanged(node); if( xPar.equals(cDir) ){ (new Thread(new FileParser(cDir))).start(); } } } /** * Description of the Method * *@param e_ftn Description of Parameter *//* public void refreshView(XFile e_ftn) { XFile cDir = getCurrentDir(); TreePath tpold = jTree1.getSelectionPath(); //Si le fichier est null, refresh global, puis repositionnement sur rep courant if (e_ftn == null) { _rootNode.refreshChildren(); e_ftn = cDir; } XFile xPar = null; if (e_ftn.isDirectory()) { xPar = e_ftn; } else { xPar = e_ftn.getXParent(); } if (xPar == null) { init(); jTree1.setSelectionPath(tpold); return; } TreeNode[] tb_tn = null; if (isGlobalExplorer) { tb_tn = ((ExplorerTreeModel) jTree1.getModel()).getPathToRoot(new JEFDirTreeNode( xPar)); } else { tb_tn = ((ExtendedTreeModel) jTree1.getModel()).getPathToRoot(new JEFDirTreeNode( xPar)); } //Chemin non trouv
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?