method header lines
This commit is contained in:
parent
add2b8f946
commit
1043b8964f
|
@ -7,9 +7,13 @@ import java.io.IOException;
|
|||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JTable;
|
||||
|
||||
public class CSVFileWriter
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class CSVFileWriter
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
public static void write (DiskTableModel diskTableModel, JTable table)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
static void write (DiskTableModel diskTableModel, JTable table)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
String csvFile =
|
||||
System.getProperty ("user.home") + File.separator + "DiskBrowser.csv";
|
||||
|
|
|
@ -20,7 +20,9 @@ import javax.swing.table.TableColumnModel;
|
|||
|
||||
import com.bytezone.diskbrowser.gui.DuplicateAction.DiskTableSelectionListener;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public class DeleteWindow extends JFrame implements DiskTableSelectionListener
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private List<DiskDetails> lines = new ArrayList<> ();
|
||||
private final JButton btnHide = new JButton ("Close");
|
||||
|
@ -29,7 +31,9 @@ public class DeleteWindow extends JFrame implements DiskTableSelectionListener
|
|||
private final DeleteTableModel deleteTableModel = new DeleteTableModel ();
|
||||
private final JTable table = new JTable (deleteTableModel);
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public DeleteWindow (RootFolderData rootFolderData)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("Duplicate Disks");
|
||||
|
||||
|
@ -72,14 +76,18 @@ public class DeleteWindow extends JFrame implements DiskTableSelectionListener
|
|||
setLocationRelativeTo (null);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void diskSelected (DiskDetails diskDetails)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
lines = rootFolderData.listDuplicates (diskDetails.getChecksum ());
|
||||
deleteTableModel.fireTableDataChanged ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
class DeleteTableModel extends AbstractTableModel
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
final String[] headers = { "Name", "Type", "Size", "Checksum", };
|
||||
|
||||
|
|
|
@ -7,7 +7,9 @@ import java.util.List;
|
|||
import com.bytezone.common.ComputeCRC32;
|
||||
import com.bytezone.diskbrowser.utilities.Utility;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public class DiskDetails
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private final File file;
|
||||
private long checksum;
|
||||
|
@ -22,7 +24,9 @@ public class DiskDetails
|
|||
private boolean isDuplicateName;
|
||||
private boolean isDuplicateChecksum;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public DiskDetails (File file, String rootName, String shortName, boolean doChecksum)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
this.file = file;
|
||||
this.rootName = rootName;
|
||||
|
@ -36,12 +40,16 @@ public class DiskDetails
|
|||
checksum = 0;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public File getFile ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return file;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void addDuplicateChecksum (DiskDetails diskDetails)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (this.checksum == diskDetails.checksum)
|
||||
{
|
||||
|
@ -50,7 +58,9 @@ public class DiskDetails
|
|||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void addDuplicateName (DiskDetails diskDetails)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (this.shortName.equals (diskDetails.shortName))
|
||||
{
|
||||
|
@ -59,64 +69,88 @@ public class DiskDetails
|
|||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public List<DiskDetails> getDuplicateChecksums ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return duplicateChecksums;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public List<DiskDetails> getDuplicateNames ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return duplicateNames;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public boolean isDuplicateChecksum ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return isDuplicateChecksum;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public boolean isDuplicateName ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return isDuplicateName;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public String getRootName ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return rootName;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public String getType ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public long getSize ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public String getShortName ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return shortName;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public String getFileName ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return file.getName ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public long calculateChecksum ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
checksum = ComputeCRC32.getChecksumValue (file);
|
||||
return checksum;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public long getChecksum ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return checksum;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public String toString ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return String.format ("%3d %1.1s %3d %1.1s %-40s ", duplicateChecksums.size (),
|
||||
isDuplicateChecksum, duplicateNames.size (), isDuplicateName, rootName);
|
||||
|
|
|
@ -5,7 +5,9 @@ import java.util.List;
|
|||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
|
||||
public class DiskTableModel extends AbstractTableModel
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class DiskTableModel extends AbstractTableModel
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
static final String[] headers =
|
||||
{ "Path", "Name", "Type", "Size", "# names", "Checksum", "# checksums" };
|
||||
|
@ -13,7 +15,9 @@ public class DiskTableModel extends AbstractTableModel
|
|||
private final List<TableLine> lines = new ArrayList<> ();
|
||||
private final RootFolderData rootFolderData;
|
||||
|
||||
public DiskTableModel (RootFolderData rootFolderData)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
DiskTableModel (RootFolderData rootFolderData)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
this.rootFolderData = rootFolderData;
|
||||
|
||||
|
@ -27,25 +31,33 @@ public class DiskTableModel extends AbstractTableModel
|
|||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public DiskDetails getDiskDetails (int rowIndex)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return lines.get (rowIndex).diskDetails;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public String getColumnName (int column)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return headers[column];
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public int getRowCount ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return lines.size ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public int getColumnCount ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (rootFolderData.doChecksums)
|
||||
return headers.length;
|
||||
|
@ -53,14 +65,18 @@ public class DiskTableModel extends AbstractTableModel
|
|||
return headers.length - 1;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public Class<?> getColumnClass (int columnIndex)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return lines.isEmpty () ? Object.class : getValueAt (0, columnIndex).getClass ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public Object getValueAt (int rowIndex, int columnIndex)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
TableLine line = lines.get (rowIndex);
|
||||
switch (columnIndex)
|
||||
|
@ -84,7 +100,9 @@ public class DiskTableModel extends AbstractTableModel
|
|||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public String getCSV (int rowIndex)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
TableLine line = lines.get (rowIndex);
|
||||
return String.format ("\"%s\",\"%s\",%s,%d,%s,%s,%d%n", line.path, line.shortName,
|
||||
|
@ -92,14 +110,18 @@ public class DiskTableModel extends AbstractTableModel
|
|||
line.checksum);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
void updateChecksum (int rowIndex)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
TableLine line = lines.get (rowIndex);
|
||||
line.checksum = line.diskDetails.calculateChecksum ();
|
||||
fireTableCellUpdated (rowIndex, 5);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
class TableLine
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
private final String shortName;
|
||||
private final String fileName;
|
||||
|
|
|
@ -31,7 +31,9 @@ import com.bytezone.diskbrowser.gui.DuplicateAction.DiskTableSelectionListener;
|
|||
import com.bytezone.diskbrowser.utilities.NumberRenderer;
|
||||
import com.bytezone.diskbrowser.utilities.Utility;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public class DisksWindow extends JFrame
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private final JTable table;
|
||||
|
||||
|
@ -50,7 +52,9 @@ public class DisksWindow extends JFrame
|
|||
private final RootFolderData rootFolderData;
|
||||
private final DeleteWindow deleteWindow;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public DisksWindow (RootFolderData rootFolderData)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super (rootFolderData.getRootFolderPathText ());
|
||||
this.rootFolderData = rootFolderData;
|
||||
|
@ -123,7 +127,9 @@ public class DisksWindow extends JFrame
|
|||
}
|
||||
|
||||
// called from DuplicateSwingWorker
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void setTableData (final RootFolderData rootFolderData)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
diskTableModel = new DiskTableModel (rootFolderData);
|
||||
table.setModel (diskTableModel);
|
||||
|
@ -209,7 +215,9 @@ public class DisksWindow extends JFrame
|
|||
setVisible (true);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private String getFilterText ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
StringBuilder filterText = new StringBuilder ();
|
||||
|
||||
|
@ -227,7 +235,9 @@ public class DisksWindow extends JFrame
|
|||
return filterText.toString ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
class CheckBoxActionListener implements ActionListener
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
|
|
|
@ -7,35 +7,47 @@ import javax.swing.SwingWorker;
|
|||
|
||||
import com.bytezone.diskbrowser.utilities.Utility;
|
||||
|
||||
public class DuplicateSwingWorker extends SwingWorker<Void, RootFolderData>
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class DuplicateSwingWorker extends SwingWorker<Void, RootFolderData>
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private final RootFolderData rootFolderData;
|
||||
|
||||
public DuplicateSwingWorker (RootFolderData rootFolderData)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
DuplicateSwingWorker (RootFolderData rootFolderData)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
this.rootFolderData = rootFolderData;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
protected Void doInBackground () throws Exception
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
traverse (rootFolderData.getRootFolder ());
|
||||
return null;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
protected void done ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
rootFolderData.done ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
protected void process (List<RootFolderData> chunks)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
rootFolderData.progressPanel.repaint ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void traverse (File directory)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (rootFolderData.progressPanel.cancelled)
|
||||
return;
|
||||
|
|
|
@ -23,7 +23,9 @@ import com.bytezone.diskbrowser.gui.DuplicateAction.DiskTableSelectionListener;
|
|||
import com.bytezone.diskbrowser.gui.RootDirectoryChangeListener;
|
||||
import com.bytezone.diskbrowser.utilities.Utility;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public class RootFolderData implements RootDirectoryChangeListener
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private static final String header =
|
||||
" type uncmp .gz .zip total";
|
||||
|
@ -55,7 +57,9 @@ public class RootFolderData implements RootDirectoryChangeListener
|
|||
JButton btnCancel;
|
||||
JButton btnOK;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void createWindows ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
southPanel = new JPanel ();
|
||||
btnCancel = new JButton ("Cancel");
|
||||
|
@ -91,7 +95,9 @@ public class RootFolderData implements RootDirectoryChangeListener
|
|||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void count (boolean doChecksums)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (dialogTotals == null)
|
||||
createWindows ();
|
||||
|
@ -106,7 +112,9 @@ public class RootFolderData implements RootDirectoryChangeListener
|
|||
new DuplicateSwingWorker (this).execute (); // start SwingWorker
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void done () // SwingWorker has completed
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
print ();
|
||||
dialogTotals.repaint ();
|
||||
|
@ -121,7 +129,9 @@ public class RootFolderData implements RootDirectoryChangeListener
|
|||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void setButton (JButton button)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
southPanel.removeAll ();
|
||||
southPanel.add (button);
|
||||
|
@ -129,7 +139,9 @@ public class RootFolderData implements RootDirectoryChangeListener
|
|||
dialogTotals.repaint ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
String getRootFolderPathText ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
String text = rootFolder.getAbsolutePath ();
|
||||
String homeDir = System.getProperty ("user.home");
|
||||
|
@ -138,7 +150,9 @@ public class RootFolderData implements RootDirectoryChangeListener
|
|||
return text;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void clear ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
typeTotals = new int[4][Utility.suffixes.size ()];
|
||||
totalDisks = 0;
|
||||
|
@ -148,17 +162,23 @@ public class RootFolderData implements RootDirectoryChangeListener
|
|||
fileNameMap.clear ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public File getRootFolder ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return rootFolder;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void incrementFolders ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
++totalFolders;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void incrementType (File file, String filename)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
int pos = Utility.getSuffixNo (filename);
|
||||
if (pos >= 0)
|
||||
|
@ -178,7 +198,9 @@ public class RootFolderData implements RootDirectoryChangeListener
|
|||
checkDuplicates (file, filename);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void checkDuplicates (File file, String filename)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
String rootName = file.getAbsolutePath ().substring (rootFolderNameLength);
|
||||
DiskDetails diskDetails = new DiskDetails (file, rootName, filename, doChecksums);
|
||||
|
@ -198,7 +220,9 @@ public class RootFolderData implements RootDirectoryChangeListener
|
|||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public List<DiskDetails> listDuplicates (long checksum)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
List<DiskDetails> list = new ArrayList<> ();
|
||||
DiskDetails original = checksumMap.get (checksum);
|
||||
|
@ -212,12 +236,16 @@ public class RootFolderData implements RootDirectoryChangeListener
|
|||
return list;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public int getTotalType (int type)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return typeTotals[0][type] + typeTotals[1][type] + typeTotals[2][type];
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void print ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
System.out.printf ("%nFolders ...... %,7d%n", totalFolders);
|
||||
System.out.printf ("Disks ........ %,7d%n%n", totalDisks);
|
||||
|
@ -248,8 +276,20 @@ public class RootFolderData implements RootDirectoryChangeListener
|
|||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void rootDirectoryChanged (File oldRootFolder, File newRootFolder)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
rootFolder = newRootFolder;
|
||||
rootFolderNameLength = rootFolder.getAbsolutePath ().length ();
|
||||
disksWindow = null; // force a recount
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public String toString ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
StringBuilder text = new StringBuilder ();
|
||||
|
||||
|
@ -260,7 +300,9 @@ public class RootFolderData implements RootDirectoryChangeListener
|
|||
return text.toString ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
class ProgressPanel extends JPanel
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
public volatile boolean cancelled;
|
||||
|
||||
|
@ -309,12 +351,4 @@ public class RootFolderData implements RootDirectoryChangeListener
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rootDirectoryChanged (File oldRootFolder, File newRootFolder)
|
||||
{
|
||||
rootFolder = newRootFolder;
|
||||
rootFolderNameLength = rootFolder.getAbsolutePath ().length ();
|
||||
disksWindow = null; // force a recount
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue