mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-11-23 19:31:00 +00:00
Refactoring
This commit is contained in:
parent
af90a850a4
commit
e5681ef18b
@ -17,10 +17,10 @@ public class DiskTableModel extends AbstractTableModel
|
||||
Map<Long, DiskDetails> checkSumMap;
|
||||
List<TableLine> lines = new ArrayList<DiskTableModel.TableLine> ();
|
||||
|
||||
public DiskTableModel (DuplicateHandler duplicateHandler)
|
||||
public DiskTableModel (RootFolderData rootFolderData)
|
||||
{
|
||||
fileNameMap = duplicateHandler.getFileNameMap ();
|
||||
checkSumMap = duplicateHandler.getChecksumMap ();
|
||||
fileNameMap = rootFolderData.fileNameMap;
|
||||
checkSumMap = rootFolderData.checksumMap;
|
||||
|
||||
for (String key : fileNameMap.keySet ())
|
||||
{
|
||||
|
@ -3,10 +3,7 @@ package com.bytezone.diskbrowser.duplicates;
|
||||
import java.awt.Dimension;
|
||||
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;
|
||||
@ -14,7 +11,7 @@ import javax.swing.SwingWorker;
|
||||
|
||||
import com.bytezone.diskbrowser.utilities.Utility;
|
||||
|
||||
public class DuplicateHandler extends SwingWorker<Void, ProgressState>
|
||||
public class DuplicateSwingWorker extends SwingWorker<Void, ProgressState>
|
||||
{
|
||||
private final File rootFolder;
|
||||
private final int rootFolderNameLength;
|
||||
@ -23,21 +20,17 @@ public class DuplicateHandler extends SwingWorker<Void, ProgressState>
|
||||
private final JDialog dialog;
|
||||
private final ProgressPanel progressPanel;
|
||||
private final boolean doChecksums;
|
||||
private final RootFolderData rootFolderData;
|
||||
|
||||
// list of checksum -> DiskDetails
|
||||
private final Map<Long, DiskDetails> checksumMap = new HashMap<Long, DiskDetails> ();
|
||||
|
||||
// list of unique disk names -> DiskDetails
|
||||
private final Map<String, DiskDetails> fileNameMap =
|
||||
new TreeMap<String, DiskDetails> ();
|
||||
|
||||
public DuplicateHandler (File rootFolder, DuplicateWindow owner, boolean doChecksums)
|
||||
public DuplicateSwingWorker (File rootFolder, DuplicateWindow owner, boolean doChecksums)
|
||||
{
|
||||
this.rootFolder = rootFolder;
|
||||
this.owner = owner;
|
||||
this.doChecksums = doChecksums;
|
||||
rootFolderNameLength = rootFolder.getAbsolutePath ().length ();
|
||||
|
||||
rootFolderData = new RootFolderData ();
|
||||
|
||||
dialog = new JDialog (owner);
|
||||
progressPanel = new ProgressPanel ();
|
||||
progressPanel.setPreferredSize (new Dimension (485, 300));
|
||||
@ -48,16 +41,6 @@ public class DuplicateHandler extends SwingWorker<Void, ProgressState>
|
||||
dialog.setVisible (true);
|
||||
}
|
||||
|
||||
public Map<String, DiskDetails> getFileNameMap ()
|
||||
{
|
||||
return fileNameMap;
|
||||
}
|
||||
|
||||
public Map<Long, DiskDetails> getChecksumMap ()
|
||||
{
|
||||
return checksumMap;
|
||||
}
|
||||
|
||||
File getRootFolder ()
|
||||
{
|
||||
return rootFolder;
|
||||
@ -98,18 +81,18 @@ public class DuplicateHandler extends SwingWorker<Void, ProgressState>
|
||||
String rootName = file.getAbsolutePath ().substring (rootFolderNameLength);
|
||||
DiskDetails diskDetails = new DiskDetails (file, rootName, filename, doChecksums);
|
||||
|
||||
if (fileNameMap.containsKey (filename))
|
||||
fileNameMap.get (filename).addDuplicateName (diskDetails);
|
||||
if (rootFolderData.fileNameMap.containsKey (filename))
|
||||
rootFolderData.fileNameMap.get (filename).addDuplicateName (diskDetails);
|
||||
else
|
||||
fileNameMap.put (filename, diskDetails);
|
||||
rootFolderData.fileNameMap.put (filename, diskDetails);
|
||||
|
||||
if (doChecksums)
|
||||
{
|
||||
long checksum = diskDetails.getChecksum ();
|
||||
if (checksumMap.containsKey (checksum))
|
||||
checksumMap.get (checksum).addDuplicateChecksum (diskDetails);
|
||||
if (rootFolderData.checksumMap.containsKey (checksum))
|
||||
rootFolderData.checksumMap.get (checksum).addDuplicateChecksum (diskDetails);
|
||||
else
|
||||
checksumMap.put (checksum, diskDetails);
|
||||
rootFolderData.checksumMap.put (checksum, diskDetails);
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,7 +102,7 @@ public class DuplicateHandler extends SwingWorker<Void, ProgressState>
|
||||
try
|
||||
{
|
||||
dialog.setVisible (false);
|
||||
owner.setDuplicateHandler (this);
|
||||
owner.setTableModel (new DiskTableModel (rootFolderData));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
@ -70,9 +70,10 @@ public class DuplicateWindow extends JFrame
|
||||
setDefaultCloseOperation (HIDE_ON_CLOSE);
|
||||
}
|
||||
|
||||
public void setDuplicateHandler (DuplicateHandler duplicateHandler)
|
||||
// called from DuplicateSwingWorker
|
||||
public void setTableModel (DiskTableModel diskTableModel)
|
||||
{
|
||||
table.setModel (new DiskTableModel (duplicateHandler));
|
||||
table.setModel (diskTableModel);
|
||||
|
||||
int[] columnWidths = { 300, 300, 30, 40, 40, 40, 100 };
|
||||
TableColumnModel tcm = table.getColumnModel ();
|
||||
|
19
src/com/bytezone/diskbrowser/duplicates/RootFolderData.java
Normal file
19
src/com/bytezone/diskbrowser/duplicates/RootFolderData.java
Normal file
@ -0,0 +1,19 @@
|
||||
package com.bytezone.diskbrowser.duplicates;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class RootFolderData
|
||||
{
|
||||
// list of checksum -> DiskDetails
|
||||
public final Map<Long, DiskDetails> checksumMap = new HashMap<Long, DiskDetails> ();
|
||||
|
||||
// list of unique disk names -> DiskDetails
|
||||
public final Map<String, DiskDetails> fileNameMap = new TreeMap<String, DiskDetails> ();
|
||||
|
||||
public RootFolderData ()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ import javax.swing.KeyStroke;
|
||||
|
||||
import com.bytezone.common.DefaultAction;
|
||||
import com.bytezone.diskbrowser.duplicates.DiskDetails;
|
||||
import com.bytezone.diskbrowser.duplicates.DuplicateHandler;
|
||||
import com.bytezone.diskbrowser.duplicates.DuplicateSwingWorker;
|
||||
import com.bytezone.diskbrowser.duplicates.DuplicateWindow;
|
||||
import com.bytezone.diskbrowser.gui.RootDirectoryAction.RootDirectoryChangeListener;
|
||||
|
||||
@ -50,17 +50,17 @@ public class DuplicateAction extends DefaultAction implements RootDirectoryChang
|
||||
if (window == null)
|
||||
{
|
||||
Object[] options = { "Generate checksums", "Disk names only", "Cancel" };
|
||||
int n = JOptionPane.showOptionDialog (null,
|
||||
int option = JOptionPane.showOptionDialog (null,
|
||||
"This command will list all of the disks in the root folder (including\n"
|
||||
+ "nested folders). If you wish to generate a checksum for each disk, it\n"
|
||||
+ "will slow the process down considerably.\n\n"
|
||||
+ "may slow the process down considerably.\n\n"
|
||||
+ "Do you wish to generate checksums?",
|
||||
"Generate Disk Listing", JOptionPane.YES_NO_CANCEL_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE, null, options, options[2]);
|
||||
if (n < 2)
|
||||
JOptionPane.QUESTION_MESSAGE, null, options, options[1]); // just disk names
|
||||
if (option < 2)
|
||||
{
|
||||
window = new DuplicateWindow (rootFolder, listeners);
|
||||
new DuplicateHandler (rootFolder, window, n == 0).execute ();
|
||||
new DuplicateSwingWorker (rootFolder, window, option == 0).execute ();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user