duplicate display
This commit is contained in:
parent
499ed1cd20
commit
e62dce5065
|
@ -12,7 +12,6 @@ import com.bytezone.diskbrowser.utilities.Utility;
|
|||
|
||||
public class DuplicateHandler
|
||||
{
|
||||
private static String spaces = " ";
|
||||
private static final FileComparator fileComparator = new FileComparator ();
|
||||
private static final int MAX_NAME_WIDTH = 34;
|
||||
private static final String FORMAT = "%-" + MAX_NAME_WIDTH + "s %,10d%n";
|
||||
|
@ -37,27 +36,33 @@ public class DuplicateHandler
|
|||
public DuplicateHandler (File rootFolder)
|
||||
{
|
||||
this.rootFolder = rootFolder;
|
||||
|
||||
countDisks ();
|
||||
}
|
||||
|
||||
public Map<String, List<DiskDetails>> getDuplicateDisks ()
|
||||
{
|
||||
return duplicateDisks;
|
||||
}
|
||||
|
||||
void countDisks ()
|
||||
{
|
||||
traverse (rootFolder, 0);
|
||||
traverse (rootFolder);
|
||||
|
||||
System.out.printf ("%nFolders ..... %,5d%n", totalFolders);
|
||||
System.out.printf ("Disks ....... %,5d%n%n", totalDisks);
|
||||
System.out.printf ("%nFolders ..... %,7d%n", totalFolders);
|
||||
System.out.printf ("Disks ....... %,7d%n%n", totalDisks);
|
||||
|
||||
int grandTotal = 0;
|
||||
for (String key : typeList.keySet ())
|
||||
{
|
||||
int typeTotal = typeList.get (key);
|
||||
grandTotal += typeTotal;
|
||||
System.out.printf ("%13.13s %,6d%n", key + " ...........", typeTotal);
|
||||
System.out.printf ("%13.13s %,7d%n", key + " ...........", typeTotal);
|
||||
}
|
||||
System.out.printf ("%nTotal ....... %,6d%n%n", grandTotal);
|
||||
System.out.printf ("%nTotal ....... %,7d%n%n", grandTotal);
|
||||
}
|
||||
|
||||
private void traverse (File directory, int depth)
|
||||
private void traverse (File directory)
|
||||
{
|
||||
File[] files = directory.listFiles ();
|
||||
if (files == null || files.length == 0)
|
||||
|
@ -68,15 +73,16 @@ public class DuplicateHandler
|
|||
|
||||
Arrays.sort (files, fileComparator);
|
||||
|
||||
System.out.printf ("%nFolder: %s%n%n",
|
||||
directory.getAbsolutePath ().substring (rootFolder.getAbsolutePath ().length ()));
|
||||
if (false)
|
||||
System.out.printf ("%nFolder: %s%n%n", directory.getAbsolutePath ()
|
||||
.substring (rootFolder.getAbsolutePath ().length ()));
|
||||
|
||||
for (File file : files)
|
||||
{
|
||||
if (file.isDirectory ())
|
||||
{
|
||||
++totalFolders;
|
||||
traverse (file, depth + 1);
|
||||
traverse (file);
|
||||
}
|
||||
else if (Utility.validFileType (file.getName ()))
|
||||
{
|
||||
|
@ -85,15 +91,43 @@ public class DuplicateHandler
|
|||
|
||||
++totalDisks;
|
||||
|
||||
String name = file.getName ();
|
||||
int nameLength = name.length ();
|
||||
if (nameLength > MAX_NAME_WIDTH)
|
||||
name = name.substring (0, 15) + "..."
|
||||
+ name.substring (nameLength - MAX_NAME_WIDTH + 18);
|
||||
int pos = file.getName ().lastIndexOf ('.');
|
||||
if (pos > 0)
|
||||
{
|
||||
String type = file.getName ().substring (pos + 1).toLowerCase ();
|
||||
if (typeList.containsKey (type))
|
||||
{
|
||||
int t = typeList.get (type);
|
||||
typeList.put (type, ++t);
|
||||
}
|
||||
else
|
||||
typeList.put (type, 1);
|
||||
}
|
||||
|
||||
System.out.printf (FORMAT, name, file.length ());
|
||||
if (false)
|
||||
{
|
||||
String name = file.getName ();
|
||||
int nameLength = name.length ();
|
||||
if (nameLength > MAX_NAME_WIDTH)
|
||||
name = name.substring (0, 15) + "..."
|
||||
+ name.substring (nameLength - MAX_NAME_WIDTH + 18);
|
||||
|
||||
System.out.printf (FORMAT, name, file.length ());
|
||||
}
|
||||
|
||||
checkDuplicates (file);
|
||||
// checksumDos (file);
|
||||
}
|
||||
}
|
||||
|
||||
if (false)
|
||||
for (String key : duplicateDisks.keySet ())
|
||||
{
|
||||
List<DiskDetails> diskDetailsList = duplicateDisks.get (key);
|
||||
System.out.println (key);
|
||||
for (DiskDetails diskDetails : diskDetailsList)
|
||||
System.out.println (diskDetails);
|
||||
}
|
||||
}
|
||||
|
||||
private void checksumDos (File file)
|
||||
|
@ -133,9 +167,9 @@ public class DuplicateHandler
|
|||
diskNames.put (file.getName (), file);
|
||||
}
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
DuplicateHandler dh = new DuplicateHandler (
|
||||
new File ("/Users/denismolony/Apple II stuff/AppleDisk Images II/apple disks"));
|
||||
}
|
||||
// public static void main (String[] args)
|
||||
// {
|
||||
// DuplicateHandler dh = new DuplicateHandler (
|
||||
// new File ("/Users/denismolony/Apple II stuff/AppleDisk Images II/apple disks"));
|
||||
// }
|
||||
}
|
|
@ -24,27 +24,30 @@ public class DuplicatePanel extends JPanel
|
|||
setAlignmentX (LEFT_ALIGNMENT);
|
||||
|
||||
int count = 0;
|
||||
for (DiskDetails dd : duplicateDisks)
|
||||
for (DiskDetails diskDetails : duplicateDisks)
|
||||
{
|
||||
JCheckBox cb = new JCheckBox ();
|
||||
checkBoxes.add (cb);
|
||||
JCheckBox checkbox = new JCheckBox ();
|
||||
checkBoxes.add (checkbox);
|
||||
|
||||
cb.addActionListener (
|
||||
new CheckBoxActionListener (dd, disksSelected, deleteButton, clearButton));
|
||||
add (cb);
|
||||
checkbox.addActionListener (new CheckBoxActionListener (diskDetails, disksSelected,
|
||||
deleteButton, clearButton));
|
||||
add (checkbox);
|
||||
if (++count == 1)
|
||||
add (new JLabel ("Source disk"));
|
||||
add (new JLabel ("Original disk"));
|
||||
else
|
||||
{
|
||||
String text = dd.isDuplicate () ? "Duplicate" : "OK";
|
||||
String text = diskDetails.isDuplicate () ? "Duplicate" : "OK";
|
||||
add (new JLabel (text));
|
||||
}
|
||||
String checksum = dd.isDuplicate () || count == 1 ? ""
|
||||
: " (checksum = " + dd.getChecksum () + ")";
|
||||
add (new JLabel (dd.getAbsolutePath ().substring (folderNameLength) + checksum));
|
||||
String checksum = diskDetails.isDuplicate () || count == 1 ? ""
|
||||
: " (checksum = " + diskDetails.getChecksum () + ")";
|
||||
add (new JLabel (
|
||||
diskDetails.getAbsolutePath ().substring (folderNameLength) + checksum));
|
||||
}
|
||||
SpringUtilities.makeCompactGrid (this, duplicateDisks.size (), 3, //rows, cols
|
||||
10, 0, //initX, initY
|
||||
10, 0); //xPad, yPad
|
||||
|
||||
SpringUtilities.makeCompactGrid (this, //
|
||||
duplicateDisks.size (), 3, // rows, cols
|
||||
10, 0, // initX, initY
|
||||
10, 0); // xPad, yPad
|
||||
}
|
||||
}
|
|
@ -27,10 +27,17 @@ public class DuplicateWindow extends JFrame
|
|||
List<DiskDetails> disksSelected = new ArrayList<DiskDetails> ();
|
||||
List<DuplicatePanel> duplicatePanels = new ArrayList<DuplicatePanel> ();
|
||||
|
||||
DuplicateHandler duplicateHandler;
|
||||
|
||||
public DuplicateWindow (File rootFolder)
|
||||
{
|
||||
super ("Duplicate Disk Detection - " + rootFolder.getAbsolutePath ());
|
||||
|
||||
duplicateHandler = new DuplicateHandler (rootFolder);
|
||||
Map<String, List<DiskDetails>> duplicateDisks = duplicateHandler.getDuplicateDisks ();
|
||||
for (List<DiskDetails> diskList : duplicateDisks.values ())
|
||||
new DuplicateWorker (diskList, this).execute ();
|
||||
|
||||
unfinishedWorkers = duplicateDisks.size ();
|
||||
folderNameLength = rootFolder.getAbsolutePath ().length ();
|
||||
|
||||
|
@ -67,7 +74,7 @@ public class DuplicateWindow extends JFrame
|
|||
if (count > 0 && dp.duplicateDisks.get (count).isDuplicate ())
|
||||
if (!cb.isSelected ())
|
||||
{
|
||||
cb.setSelected (true); // doesn't fire the actionListener!
|
||||
cb.setSelected (true); // doesn't fire the actionListener!
|
||||
disksSelected.add (dp.duplicateDisks.get (count));
|
||||
}
|
||||
++count;
|
||||
|
@ -85,7 +92,8 @@ public class DuplicateWindow extends JFrame
|
|||
{
|
||||
for (DuplicatePanel dp : duplicatePanels)
|
||||
for (JCheckBox cb : dp.checkBoxes)
|
||||
cb.setSelected (false); // doesn't fire the actionListener!
|
||||
cb.setSelected (false); // doesn't fire the actionListener!
|
||||
|
||||
disksSelected.clear ();
|
||||
buttonDelete.setEnabled (false);
|
||||
buttonClear.setEnabled (false);
|
||||
|
|
|
@ -33,11 +33,11 @@ import com.bytezone.diskbrowser.disk.DualDosDisk;
|
|||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
import com.bytezone.diskbrowser.gui.RedoHandler.RedoEvent;
|
||||
import com.bytezone.diskbrowser.gui.RedoHandler.RedoListener;
|
||||
import com.bytezone.diskbrowser.gui.RootDirectoryAction.RootDirectoryListener;
|
||||
import com.bytezone.diskbrowser.gui.RootDirectoryAction.RootDirectoryChangeListener;
|
||||
import com.bytezone.diskbrowser.gui.TreeBuilder.FileNode;
|
||||
|
||||
class CatalogPanel extends JTabbedPane implements RedoListener, SectorSelectionListener,
|
||||
QuitListener, FontChangeListener, RootDirectoryListener
|
||||
QuitListener, FontChangeListener, RootDirectoryChangeListener
|
||||
{
|
||||
private static final String prefsLastDiskUsed = "Last disk used";
|
||||
private static final String prefsLastDosUsed = "Last dos used";
|
||||
|
@ -158,6 +158,9 @@ class CatalogPanel extends JTabbedPane implements RedoListener, SectorSelectionL
|
|||
@Override
|
||||
public void rootDirectoryChanged (File root)
|
||||
{
|
||||
if (root == rootDirectoryFile) // initial call or no need to change
|
||||
return;
|
||||
|
||||
// is the user replacing an existing root folder?
|
||||
if (fileTab != null)
|
||||
removeTabAt (0);
|
||||
|
|
|
@ -2,20 +2,15 @@ package com.bytezone.diskbrowser.gui;
|
|||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.Action;
|
||||
|
||||
import com.bytezone.common.DefaultAction;
|
||||
import com.bytezone.diskbrowser.duplicates.DiskDetails;
|
||||
import com.bytezone.diskbrowser.duplicates.DuplicateWindow;
|
||||
import com.bytezone.diskbrowser.duplicates.DuplicateWorker;
|
||||
import com.bytezone.diskbrowser.gui.RootDirectoryAction.RootDirectoryListener;
|
||||
import com.bytezone.diskbrowser.gui.RootDirectoryAction.RootDirectoryChangeListener;
|
||||
|
||||
public class DuplicateAction extends DefaultAction implements RootDirectoryListener
|
||||
public class DuplicateAction extends DefaultAction implements RootDirectoryChangeListener
|
||||
{
|
||||
Map<String, List<DiskDetails>> duplicateDisks;
|
||||
int rootFolderLength;
|
||||
File rootFolder;
|
||||
DuplicateWindow window;
|
||||
|
@ -27,39 +22,23 @@ public class DuplicateAction extends DefaultAction implements RootDirectoryListe
|
|||
|
||||
setIcon (Action.SMALL_ICON, "save_delete_16.png");
|
||||
setIcon (Action.LARGE_ICON_KEY, "save_delete_32.png");
|
||||
setEnabled (false);
|
||||
}
|
||||
|
||||
// public void setDuplicates (File rootFolder,
|
||||
// Map<String, List<DiskDetails>> duplicateDisks)
|
||||
// {
|
||||
// this.duplicateDisks = duplicateDisks;
|
||||
// this.rootFolderLength = rootFolder.getAbsolutePath ().length ();
|
||||
// setEnabled (duplicateDisks.size () > 0);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void rootDirectoryChanged (File newRootDirectory)
|
||||
public void rootDirectoryChanged (File rootFolder)
|
||||
{
|
||||
this.rootFolder = newRootDirectory;
|
||||
System.out.println ("gotcha");
|
||||
this.rootFolder = rootFolder;
|
||||
setEnabled (rootFolder != null);
|
||||
window = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent arg0)
|
||||
{
|
||||
if (duplicateDisks == null)
|
||||
{
|
||||
System.out.println ("No duplicate disks found");
|
||||
return;
|
||||
}
|
||||
|
||||
if (window != null)
|
||||
{
|
||||
if (window == null)
|
||||
window = new DuplicateWindow (rootFolder);
|
||||
else
|
||||
window.setVisible (true);
|
||||
return;
|
||||
}
|
||||
window = new DuplicateWindow (rootFolder);
|
||||
for (List<DiskDetails> diskList : duplicateDisks.values ())
|
||||
new DuplicateWorker (diskList, window).execute ();
|
||||
}
|
||||
}
|
|
@ -16,8 +16,8 @@ import com.bytezone.common.Platform;
|
|||
class RootDirectoryAction extends DefaultAction
|
||||
{
|
||||
private File rootDirectory;
|
||||
private final List<RootDirectoryListener> listeners =
|
||||
new ArrayList<RootDirectoryAction.RootDirectoryListener> ();
|
||||
private final List<RootDirectoryChangeListener> listeners =
|
||||
new ArrayList<RootDirectoryAction.RootDirectoryChangeListener> ();
|
||||
|
||||
public RootDirectoryAction (File rootDirectory)
|
||||
{
|
||||
|
@ -50,19 +50,22 @@ class RootDirectoryAction extends DefaultAction
|
|||
if (file != null)
|
||||
{
|
||||
rootDirectory = file;
|
||||
for (RootDirectoryListener listener : listeners)
|
||||
for (RootDirectoryChangeListener listener : listeners)
|
||||
listener.rootDirectoryChanged (file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addListener (RootDirectoryListener listener)
|
||||
public void addListener (RootDirectoryChangeListener listener)
|
||||
{
|
||||
if (!listeners.contains (listener))
|
||||
{
|
||||
listeners.add (listener);
|
||||
listener.rootDirectoryChanged (rootDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
interface RootDirectoryListener
|
||||
interface RootDirectoryChangeListener
|
||||
{
|
||||
public void rootDirectoryChanged (File newRootDirectory);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue