📄 virtualfilesystemview.java
字号:
VirtualFileSystemNode destinationNode; String result; selectedPaths = directoryTree.getSelectionPaths(); if (selectedPaths == null) return; /* do not try to paste if there is more than one destination */ if (selectedPaths.length != 1) return; destinationNode = (VirtualFileSystemNode)selectedPaths[0].getLastPathComponent(); try { setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); dataHolder = getClipboard().getContents(null); if ((dataHolder != null) && (dataHolder.isDataFlavorSupported(DataFlavor.stringFlavor))) { transferData = (String)dataHolder.getTransferData(DataFlavor.stringFlavor); if (transferData != null){ pathsEnum = new StringTokenizer(transferData, clipboardDelimiter); while (pathsEnum.hasMoreTokens()) { nextToken = (String)pathsEnum.nextToken(); result = destinationNode.graftPath(lastNameFromPathString(nextToken), nextToken, true); if (result != null){ //System.out.println(result); /* showing following message box hangs up the application. need to debug */ JOptionPane.showMessageDialog(this, result); } } //((DefaultTreeModel)directoryTree.getModel()).nodeChanged(destinationNode); //directoryTree.expandRow(0); ((DefaultTreeModel)directoryTree.getModel()).reload(destinationNode); printVirtualFileSystemSize(); } else { System.out.println("Nothing in clipboard"); } } } catch(java.awt.datatransfer.UnsupportedFlavorException ufe) { System.out.println("Unsupported data flavor in clipboard"); } catch (java.io.IOException ioe) { System.out.println("IO Exception while pasting."); } finally{ setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } } public java.awt.datatransfer.Clipboard getClipboard() { return Clipboard.defaultInstance(); } public void treeCollapsed(javax.swing.event.TreeExpansionEvent treeExpansionEvent) { } public void treeExpanded(javax.swing.event.TreeExpansionEvent treeExpansionEvent) { } public void treeWillCollapse(javax.swing.event.TreeExpansionEvent treeExpansionEvent) throws javax.swing.tree.ExpandVetoException { } public void treeWillExpand(javax.swing.event.TreeExpansionEvent treeExpansionEvent) throws javax.swing.tree.ExpandVetoException { } private String lastNameFromPathString(String pathStr) { StringTokenizer pathTokenizer = new StringTokenizer(pathStr, pathSeparator); String lastName = "NO_NAME"; while(pathTokenizer.hasMoreTokens()) { lastName = pathTokenizer.nextToken(); } return lastName; } private String pathToString(Object path[]) { StringBuffer s = new StringBuffer(); for(int i = 1; i < path.length; i++) { s.append(path[i]); if(i > 1 && i < path.length) s.append(pathSeparator); } return s.toString(); } public String getPrintableTreeStructure() { return(""); } public void printTree(){ ((VirtualFileSystemNode)directoryTree.getModel().getRoot()).printTree(0); } public void printVirtualFileSystemSize(){ // totalFileSystemSize = ((VirtualFileSystemNode)directoryTree.getModel().getRoot()).fileSystemSize("/"); double sizeInReadableFormat; String units; totalFileSystemSize = ((VirtualFileSystemNode)directoryTree.getModel().getRoot()).fileSystemSize(null); if (totalFileSystemSize > (1024.0 * 1024.00 * 1024.00)){ sizeInReadableFormat = totalFileSystemSize/(1024.0 * 1024.0 * 1024.00); sizeInReadableFormat = ((int)(sizeInReadableFormat * 100.0))/100.0; units = "GB"; } else { sizeInReadableFormat = totalFileSystemSize/(1024.0 * 1024.0); sizeInReadableFormat = ((int)(sizeInReadableFormat * 100.0))/100.0; units = "MB"; } statusBar.setText("Total Size: " + sizeInReadableFormat + units + " (" + totalFileSystemSize + " bytes)"); } public void printGraftPoints(){ ((VirtualFileSystemNode)directoryTree.getModel().getRoot()).printGraftPoints(); } public boolean isEmpty() { // is virtual file system empty (no directories or files) ? return (((VirtualFileSystemNode)directoryTree.getModel().getRoot()).childCount() == 0); } public Vector graftPoints(){ return (((VirtualFileSystemNode)directoryTree.getModel().getRoot()).graftPoints(null)); } public Vector excludedPaths(){ return new Vector(); /****** SHOULD GET RID OF excludedPaths functionality as there is no clean way of excluding things */ //return (((VirtualFileSystemNode)directoryTree.getModel().getRoot()).excludedPaths(null)); } private void refreshFileListForPath(TreePath path){ VirtualFileSystemNode selectedDirNode, nextNode; File selectedDir; File[] dirContents; ListModel listModel; Vector aVector = new Vector(); Iterator anIterator; try { selectedDirNode = (VirtualFileSystemNode)path.getLastPathComponent(); Iterator filesInDir = selectedDirNode.files().iterator(); listModel = fileList.getModel(); ((DefaultListModel)listModel).clear(); while (filesInDir.hasNext()){ nextNode = (VirtualFileSystemNode)filesInDir.next(); aVector.add(nextNode.name()); } java.util.Collections.sort(aVector); anIterator = aVector.iterator(); while(anIterator.hasNext()) { ((DefaultListModel)listModel).addElement(anIterator.next()); } } catch(Exception e) { System.out.println(e); } finally { } } public void dragEnter(java.awt.dnd.DropTargetDragEvent dropTargetDragEvent) { } public void dragExit(java.awt.dnd.DropTargetEvent dropTargetEvent) { } public void dragOver(java.awt.dnd.DropTargetDragEvent dropTargetDragEvent) { Point dragOrigin = dropTargetDragEvent.getLocation(); TreePath draggedPath = (TreePath)((directoryTree.getPathForLocation((int)dragOrigin.getX(), (int)dragOrigin.getY()))); if(draggedPath != null){ directoryTree.setSelectionPath(draggedPath); String aPathStr = pathToString(draggedPath.getPath()); } } public void drop(java.awt.dnd.DropTargetDropEvent dropTargetDropEvent) { pasteFromClipboard(); } public void dropActionChanged(java.awt.dnd.DropTargetDragEvent dropTargetDragEvent) { } public TreeModel getModel() { return(directoryTree.getModel()); } public void setModel(TreeModel newModel) { directoryTree.setModel(newModel); } public void setStatusBar(JLabel sBar){ statusBar = sBar; } public void initializeTreeModel() { initializeFileSystemRoots(); fileList.setModel(new DefaultListModel()); } private javax.swing.JScrollPane fileListScrollPane; private javax.swing.JSplitPane dirAndFilesSplitPane; private javax.swing.JList fileList; private javax.swing.JTree directoryTree; private javax.swing.JScrollPane directoryTreeScrollPane; private int pasteKey = java.awt.event.KeyEvent.CTRL_MASK | java.awt.event.KeyEvent.VK_V; private String clipboardDelimiter = "|"; private String pathSeparator = "/"; private DropTarget dropTarget; private JLabel statusBar; private long totalFileSystemSize = 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -