Duplicate dialog

This commit is contained in:
Denis Molony 2016-12-12 08:32:18 +11:00
parent b728fe1f16
commit cdb32786f4
7 changed files with 99 additions and 48 deletions

View File

@ -426,6 +426,18 @@ public class AppleDisk implements Disk
notifyListeners ("Sector size changed"); notifyListeners ("Sector size changed");
} }
@Override
public DiskAddress getDiskAddress (int track, int sector)
{
if (!isValidAddress (track, sector))
{
System.out.println ("Invalid block : " + track + "/" + sector);
return null;
// return new AppleDiskAddress (this, 0); this was looping 26/07/2016
}
return new AppleDiskAddress (this, track, sector);
}
@Override @Override
public DiskAddress getDiskAddress (int block) public DiskAddress getDiskAddress (int block)
{ {
@ -451,18 +463,6 @@ public class AppleDisk implements Disk
return addressList; return addressList;
} }
@Override
public DiskAddress getDiskAddress (int track, int sector)
{
if (!isValidAddress (track, sector))
{
System.out.println ("Invalid block : " + track + "/" + sector);
return null;
// return new AppleDiskAddress (this, 0); this was looping 26/07/2016
}
return new AppleDiskAddress (this, track, sector);
}
@Override @Override
public boolean isValidAddress (int block) public boolean isValidAddress (int block)
{ {

View File

@ -1,11 +1,14 @@
package com.bytezone.diskbrowser.duplicates; package com.bytezone.diskbrowser.duplicates;
import java.awt.Graphics;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.SwingWorker; import javax.swing.SwingWorker;
import com.bytezone.diskbrowser.utilities.Utility; import com.bytezone.diskbrowser.utilities.Utility;
@ -15,7 +18,9 @@ public class DuplicateHandler extends SwingWorker<Void, ProgressState>
private final File rootFolder; private final File rootFolder;
private final int rootFolderNameLength; private final int rootFolderNameLength;
private final ProgressState progressState = new ProgressState (); private final ProgressState progressState = new ProgressState ();
DuplicateWindow owner; private final DuplicateWindow owner;
private final JDialog dialog;
private final ProgressPanel progressPanel;
// list of checksum -> DiskDetails // list of checksum -> DiskDetails
private final Map<Long, DiskDetails> checksumMap = new HashMap<Long, DiskDetails> (); private final Map<Long, DiskDetails> checksumMap = new HashMap<Long, DiskDetails> ();
@ -29,6 +34,14 @@ public class DuplicateHandler extends SwingWorker<Void, ProgressState>
this.rootFolder = rootFolder; this.rootFolder = rootFolder;
this.owner = owner; this.owner = owner;
rootFolderNameLength = rootFolder.getAbsolutePath ().length (); rootFolderNameLength = rootFolder.getAbsolutePath ().length ();
dialog = new JDialog (owner);
progressPanel = new ProgressPanel ();
dialog.add (progressPanel);
dialog.setSize (500, 400);
dialog.setLocationRelativeTo (null);
dialog.setTitle ("Reading disks");
dialog.setVisible (true);
} }
public Map<String, DiskDetails> getFileNameMap () public Map<String, DiskDetails> getFileNameMap ()
@ -41,11 +54,6 @@ public class DuplicateHandler extends SwingWorker<Void, ProgressState>
return checksumMap; return checksumMap;
} }
public ProgressState getProgressState ()
{
return progressState;
}
File getRootFolder () File getRootFolder ()
{ {
return rootFolder; return rootFolder;
@ -103,6 +111,7 @@ public class DuplicateHandler extends SwingWorker<Void, ProgressState>
{ {
try try
{ {
dialog.setVisible (false);
owner.setDuplicateHandler (this); owner.setDuplicateHandler (this);
} }
catch (Exception e) catch (Exception e)
@ -122,8 +131,18 @@ public class DuplicateHandler extends SwingWorker<Void, ProgressState>
@Override @Override
protected void process (List<ProgressState> chunks) protected void process (List<ProgressState> chunks)
{ {
if (false) // for (ProgressState progressState : chunks)
for (ProgressState progressState : chunks) // progressState.print ();
progressState.print (); progressPanel.repaint ();
}
class ProgressPanel extends JPanel
{
@Override
protected void paintComponent (Graphics graphics)
{
super.paintComponent (graphics);
progressState.paintComponent (graphics);
}
} }
} }

View File

@ -24,7 +24,7 @@ public class DuplicateWindow extends JFrame
private final JButton btnExport = new JButton ("Export"); private final JButton btnExport = new JButton ("Export");
private final JButton btnHide = new JButton ("Close"); private final JButton btnHide = new JButton ("Close");
private DuplicateHandler duplicateHandler; // private DuplicateHandler duplicateHandler;
private final List<DiskTableSelectionListener> listeners; private final List<DiskTableSelectionListener> listeners;
public DuplicateWindow (File rootFolder, public DuplicateWindow (File rootFolder,
@ -71,7 +71,7 @@ public class DuplicateWindow extends JFrame
public void setDuplicateHandler (DuplicateHandler duplicateHandler) public void setDuplicateHandler (DuplicateHandler duplicateHandler)
{ {
this.duplicateHandler = duplicateHandler; // this.duplicateHandler = duplicateHandler;
table.setModel (new DiskTableModel (duplicateHandler)); table.setModel (new DiskTableModel (duplicateHandler));

View File

@ -1,5 +1,9 @@
package com.bytezone.diskbrowser.duplicates; package com.bytezone.diskbrowser.duplicates;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
@ -7,18 +11,17 @@ import com.bytezone.diskbrowser.utilities.Utility;
public class ProgressState public class ProgressState
{ {
List<String> suffixes = Utility.suffixes; private static final String header = " type uncmp .gz .zip";
private static final String line = "-------------- ------- ------- -------";
private static final List<String> suffixes = Utility.suffixes;
private static final Font font = new Font ("Monaco", Font.BOLD, 15);
int totalDisks; int totalDisks;
int totalFolders; int totalFolders;
// total files for each suffix (uncompressed, .gz, .zip) // total files for each suffix (uncompressed, .gz, .zip)
private final int[][] typeTotals = new int[3][suffixes.size ()]; private final int[][] typeTotals = new int[3][suffixes.size ()];
public ProgressState ()
{
}
public void incrementFolders () public void incrementFolders ()
{ {
++totalFolders; ++totalFolders;
@ -41,6 +44,41 @@ public class ProgressState
System.out.println ("no suffix: " + filename); System.out.println ("no suffix: " + filename);
} }
void paintComponent (Graphics graphics)
{
Graphics2D g = (Graphics2D) graphics;
g.setColor (Color.BLACK);
g.setFont (font);
int x = 55;
int y = 55;
int lineHeight = 23;
String line;
g.drawString (header, x, y);
y += lineHeight + 10;
int grandTotal[] = new int[3];
for (int i = 0; i < typeTotals[0].length; i++)
{
line = String.format ("%14.14s %,7d %,7d %,7d",
Utility.suffixes.get (i) + " ...........", typeTotals[0][i], typeTotals[1][i],
typeTotals[2][i]);
g.drawString (line, x, y);
for (int j = 0; j < typeTotals.length; j++)
grandTotal[j] += typeTotals[j][i];
y += lineHeight;
}
line = String.format ("Total %,7d %,7d %,7d%n%n", grandTotal[0],
grandTotal[1], grandTotal[2]);
y += 10;
g.drawString (line, x, y);
}
public void print () public void print ()
{ {
System.out.printf ("%nFolders ...... %,7d%n", totalFolders); System.out.printf ("%nFolders ...... %,7d%n", totalFolders);
@ -48,8 +86,7 @@ public class ProgressState
int grandTotal[] = new int[3]; int grandTotal[] = new int[3];
String line = "-------------- ------- ------- -------"; System.out.println (header);
System.out.println (" type uncmp .gz .zip");
System.out.println (line); System.out.println (line);
for (int i = 0; i < typeTotals[0].length; i++) for (int i = 0; i < typeTotals[0].length; i++)
{ {

View File

@ -49,8 +49,7 @@ public class DuplicateAction extends DefaultAction implements RootDirectoryChang
if (window == null) if (window == null)
{ {
window = new DuplicateWindow (rootFolder, listeners); window = new DuplicateWindow (rootFolder, listeners);
DuplicateHandler duplicateHandler = new DuplicateHandler (rootFolder, window); new DuplicateHandler (rootFolder, window).execute ();
duplicateHandler.execute ();
} }
else else
window.setVisible (true); window.setVisible (true);

View File

@ -123,9 +123,6 @@ class FileSystemTab extends AbstractTab
void selectDisk (String path) void selectDisk (String path)
{ {
File file = new File (rootFolder.getAbsolutePath () + path);
System.out.println (file);
System.out.println (file.exists ());
DefaultMutableTreeNode node = findNode (rootFolder.getAbsolutePath () + path); DefaultMutableTreeNode node = findNode (rootFolder.getAbsolutePath () + path);
if (node != null) if (node != null)
showNode (node); showNode (node);
@ -162,7 +159,6 @@ class FileSystemTab extends AbstractTab
if (fn2.file.isDirectory () && absolutePath.startsWith (path)) if (fn2.file.isDirectory () && absolutePath.startsWith (path))
{ {
System.out.println (absolutePath.charAt (path.length ()));
if (absolutePath.charAt (path.length ()) == File.separatorChar) if (absolutePath.charAt (path.length ()) == File.separatorChar)
{ {
DefaultMutableTreeNode node2 = search (childNode, absolutePath); DefaultMutableTreeNode node2 = search (childNode, absolutePath);

View File

@ -22,9 +22,9 @@ import com.bytezone.diskbrowser.utilities.Utility;
public class TreeBuilder public class TreeBuilder
{ {
private static SimpleDateFormat sdf = new SimpleDateFormat ("dd MMM yyyy"); private static SimpleDateFormat sdf = new SimpleDateFormat ("dd MMM yyyy");
private static final int DISK_13_SIZE = 116480; // private static final int DISK_13_SIZE = 116480;
private static final int DISK_16_SIZE = 143360; // private static final int DISK_16_SIZE = 143360;
private static final int DISK_800K_SIZE = 819264; // private static final int DISK_800K_SIZE = 819264;
private final FileComparator fileComparator = new FileComparator (); private final FileComparator fileComparator = new FileComparator ();
private final JTree tree; private final JTree tree;
@ -75,15 +75,15 @@ public class TreeBuilder
continue; continue;
} }
if (file.length () != DISK_16_SIZE && file.length () != DISK_13_SIZE // if (file.length () != DISK_16_SIZE && file.length () != DISK_13_SIZE
&& file.length () != DISK_800K_SIZE && file.length () < 200000) // && file.length () != DISK_800K_SIZE && file.length () < 200000)
{ // {
String name = file.getName ().toLowerCase (); // String name = file.getName ().toLowerCase ();
if (!name.endsWith (".sdk") && !name.endsWith (".dsk.gz")) // if (!name.endsWith (".sdk") && !name.endsWith (".dsk.gz"))
continue; // continue;
} // }
if (Utility.validFileType (file.getAbsolutePath ())) if (Utility.validFileType (file.getName ()) && file.length () > 0)
{ {
FileNode fileNode = new FileNode (file); FileNode fileNode = new FileNode (file);
DefaultMutableTreeNode newNode = new DefaultMutableTreeNode (fileNode); DefaultMutableTreeNode newNode = new DefaultMutableTreeNode (fileNode);