package filerogue.client.gui; import filerogue.*; import javax.swing.tree.*; import java.awt.Component; import javax.swing.JTree; /** * Title: FileRogue * Description: Global unrestricted file sharing * Copyright: Copyright (c) 2000 * Company: ITP Web Solutions * @author Brian Cairns * @version 1.0 */ public class CDirSummaryRenderer extends DefaultTreeCellRenderer { int iFiles, iDirs, iRecursionDepth; long lBytes; public CDirSummaryRenderer() { super(); setLeafIcon( getDefaultClosedIcon() ); } private void addNodeSummary( DefaultMutableTreeNode a_node, boolean recursive ) { SubDirSummary sdSum = ( SubDirSummary )a_node.getUserObject(); iFiles += sdSum.getFiles(); lBytes += sdSum.getBytes(); iDirs++; if( a_node.getLevel() > iRecursionDepth ) iRecursionDepth = a_node.getLevel(); if( recursive ) for( int i = 0; i < a_node.getChildCount(); i++ ) addNodeSummary( ( DefaultMutableTreeNode )a_node.getChildAt( i ), recursive ); } public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent( tree, value, selected, expanded, leaf, row, hasFocus ); iFiles = 0; lBytes = 0; iDirs = 0; iRecursionDepth = 0; addNodeSummary( ( DefaultMutableTreeNode )value, !expanded || row == 0 ); // set the text and tooltip to the calculated values this.setText( ( ( SubDirSummary )( ( DefaultMutableTreeNode )value ).getUserObject() ).getName() + ( row == 0 ? ": " : " (" ) + Utilities.abbreviateFileSize( lBytes ) + ", " + iFiles + " file" + ( iFiles == 1 ? "" : "s" ) + ( row == 0 ? "" : ")" ) ); this.setToolTipText( Utilities.formatNumber( lBytes ) + " bytes in " //+ Utilities.formatNumber( iFiles ) + " file" + ( iFiles == 1 ? "" : "s" ) + ", " + Utilities.formatNumber( iDirs ) + " director" + ( iDirs == 1 ? "y" : "ies" ) ); // + " (" + iRecursionDepth + " deep)" ); // if( lBytes > 0 ) // this.setToolTipText( Utilities.formatNumber( lBytes ) + " bytes in " + iFiles + " file" + ( iFiles == 1 ? "" : "s" ) ); // else // this.setToolTipText( "No files" ); return this; } }