mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2025-01-12 10:29:45 +00:00
Duplicate dialog
This commit is contained in:
parent
b728fe1f16
commit
cdb32786f4
@ -426,6 +426,18 @@ public class AppleDisk implements Disk
|
||||
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
|
||||
public DiskAddress getDiskAddress (int block)
|
||||
{
|
||||
@ -451,18 +463,6 @@ public class AppleDisk implements Disk
|
||||
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
|
||||
public boolean isValidAddress (int block)
|
||||
{
|
||||
|
@ -1,11 +1,14 @@
|
||||
package com.bytezone.diskbrowser.duplicates;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingWorker;
|
||||
|
||||
import com.bytezone.diskbrowser.utilities.Utility;
|
||||
@ -15,7 +18,9 @@ public class DuplicateHandler extends SwingWorker<Void, ProgressState>
|
||||
private final File rootFolder;
|
||||
private final int rootFolderNameLength;
|
||||
private final ProgressState progressState = new ProgressState ();
|
||||
DuplicateWindow owner;
|
||||
private final DuplicateWindow owner;
|
||||
private final JDialog dialog;
|
||||
private final ProgressPanel progressPanel;
|
||||
|
||||
// list of checksum -> 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.owner = owner;
|
||||
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 ()
|
||||
@ -41,11 +54,6 @@ public class DuplicateHandler extends SwingWorker<Void, ProgressState>
|
||||
return checksumMap;
|
||||
}
|
||||
|
||||
public ProgressState getProgressState ()
|
||||
{
|
||||
return progressState;
|
||||
}
|
||||
|
||||
File getRootFolder ()
|
||||
{
|
||||
return rootFolder;
|
||||
@ -103,6 +111,7 @@ public class DuplicateHandler extends SwingWorker<Void, ProgressState>
|
||||
{
|
||||
try
|
||||
{
|
||||
dialog.setVisible (false);
|
||||
owner.setDuplicateHandler (this);
|
||||
}
|
||||
catch (Exception e)
|
||||
@ -122,8 +131,18 @@ public class DuplicateHandler extends SwingWorker<Void, ProgressState>
|
||||
@Override
|
||||
protected void process (List<ProgressState> chunks)
|
||||
{
|
||||
if (false)
|
||||
for (ProgressState progressState : chunks)
|
||||
progressState.print ();
|
||||
// for (ProgressState progressState : chunks)
|
||||
// progressState.print ();
|
||||
progressPanel.repaint ();
|
||||
}
|
||||
|
||||
class ProgressPanel extends JPanel
|
||||
{
|
||||
@Override
|
||||
protected void paintComponent (Graphics graphics)
|
||||
{
|
||||
super.paintComponent (graphics);
|
||||
progressState.paintComponent (graphics);
|
||||
}
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@ public class DuplicateWindow extends JFrame
|
||||
private final JButton btnExport = new JButton ("Export");
|
||||
private final JButton btnHide = new JButton ("Close");
|
||||
|
||||
private DuplicateHandler duplicateHandler;
|
||||
// private DuplicateHandler duplicateHandler;
|
||||
private final List<DiskTableSelectionListener> listeners;
|
||||
|
||||
public DuplicateWindow (File rootFolder,
|
||||
@ -71,7 +71,7 @@ public class DuplicateWindow extends JFrame
|
||||
|
||||
public void setDuplicateHandler (DuplicateHandler duplicateHandler)
|
||||
{
|
||||
this.duplicateHandler = duplicateHandler;
|
||||
// this.duplicateHandler = duplicateHandler;
|
||||
|
||||
table.setModel (new DiskTableModel (duplicateHandler));
|
||||
|
||||
|
@ -1,5 +1,9 @@
|
||||
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.util.List;
|
||||
|
||||
@ -7,18 +11,17 @@ import com.bytezone.diskbrowser.utilities.Utility;
|
||||
|
||||
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 totalFolders;
|
||||
|
||||
// total files for each suffix (uncompressed, .gz, .zip)
|
||||
private final int[][] typeTotals = new int[3][suffixes.size ()];
|
||||
|
||||
public ProgressState ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void incrementFolders ()
|
||||
{
|
||||
++totalFolders;
|
||||
@ -41,6 +44,41 @@ public class ProgressState
|
||||
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 ()
|
||||
{
|
||||
System.out.printf ("%nFolders ...... %,7d%n", totalFolders);
|
||||
@ -48,8 +86,7 @@ public class ProgressState
|
||||
|
||||
int grandTotal[] = new int[3];
|
||||
|
||||
String line = "-------------- ------- ------- -------";
|
||||
System.out.println (" type uncmp .gz .zip");
|
||||
System.out.println (header);
|
||||
System.out.println (line);
|
||||
for (int i = 0; i < typeTotals[0].length; i++)
|
||||
{
|
||||
|
@ -49,8 +49,7 @@ public class DuplicateAction extends DefaultAction implements RootDirectoryChang
|
||||
if (window == null)
|
||||
{
|
||||
window = new DuplicateWindow (rootFolder, listeners);
|
||||
DuplicateHandler duplicateHandler = new DuplicateHandler (rootFolder, window);
|
||||
duplicateHandler.execute ();
|
||||
new DuplicateHandler (rootFolder, window).execute ();
|
||||
}
|
||||
else
|
||||
window.setVisible (true);
|
||||
|
@ -123,9 +123,6 @@ class FileSystemTab extends AbstractTab
|
||||
|
||||
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);
|
||||
if (node != null)
|
||||
showNode (node);
|
||||
@ -162,7 +159,6 @@ class FileSystemTab extends AbstractTab
|
||||
|
||||
if (fn2.file.isDirectory () && absolutePath.startsWith (path))
|
||||
{
|
||||
System.out.println (absolutePath.charAt (path.length ()));
|
||||
if (absolutePath.charAt (path.length ()) == File.separatorChar)
|
||||
{
|
||||
DefaultMutableTreeNode node2 = search (childNode, absolutePath);
|
||||
|
@ -22,9 +22,9 @@ import com.bytezone.diskbrowser.utilities.Utility;
|
||||
public class TreeBuilder
|
||||
{
|
||||
private static SimpleDateFormat sdf = new SimpleDateFormat ("dd MMM yyyy");
|
||||
private static final int DISK_13_SIZE = 116480;
|
||||
private static final int DISK_16_SIZE = 143360;
|
||||
private static final int DISK_800K_SIZE = 819264;
|
||||
// private static final int DISK_13_SIZE = 116480;
|
||||
// private static final int DISK_16_SIZE = 143360;
|
||||
// private static final int DISK_800K_SIZE = 819264;
|
||||
|
||||
private final FileComparator fileComparator = new FileComparator ();
|
||||
private final JTree tree;
|
||||
@ -75,15 +75,15 @@ public class TreeBuilder
|
||||
continue;
|
||||
}
|
||||
|
||||
if (file.length () != DISK_16_SIZE && file.length () != DISK_13_SIZE
|
||||
&& file.length () != DISK_800K_SIZE && file.length () < 200000)
|
||||
{
|
||||
String name = file.getName ().toLowerCase ();
|
||||
if (!name.endsWith (".sdk") && !name.endsWith (".dsk.gz"))
|
||||
continue;
|
||||
}
|
||||
// if (file.length () != DISK_16_SIZE && file.length () != DISK_13_SIZE
|
||||
// && file.length () != DISK_800K_SIZE && file.length () < 200000)
|
||||
// {
|
||||
// String name = file.getName ().toLowerCase ();
|
||||
// if (!name.endsWith (".sdk") && !name.endsWith (".dsk.gz"))
|
||||
// continue;
|
||||
// }
|
||||
|
||||
if (Utility.validFileType (file.getAbsolutePath ()))
|
||||
if (Utility.validFileType (file.getName ()) && file.length () > 0)
|
||||
{
|
||||
FileNode fileNode = new FileNode (file);
|
||||
DefaultMutableTreeNode newNode = new DefaultMutableTreeNode (fileNode);
|
||||
|
Loading…
x
Reference in New Issue
Block a user