2016-12-07 10:56:25 +00:00
|
|
|
package com.bytezone.diskbrowser.duplicates;
|
|
|
|
|
|
|
|
import java.awt.BorderLayout;
|
2016-12-10 07:36:44 +00:00
|
|
|
import java.awt.Color;
|
2016-12-12 10:53:28 +00:00
|
|
|
import java.awt.Dimension;
|
|
|
|
import java.awt.FlowLayout;
|
2016-12-10 07:36:44 +00:00
|
|
|
import java.awt.Rectangle;
|
2016-12-07 10:56:25 +00:00
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
import java.awt.event.ActionListener;
|
2016-12-12 23:46:09 +00:00
|
|
|
import java.util.ArrayList;
|
2016-12-07 10:56:25 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import javax.swing.*;
|
2016-12-10 07:36:44 +00:00
|
|
|
import javax.swing.event.ListSelectionEvent;
|
|
|
|
import javax.swing.event.ListSelectionListener;
|
2016-12-09 12:12:35 +00:00
|
|
|
import javax.swing.table.JTableHeader;
|
2016-12-12 07:43:19 +00:00
|
|
|
import javax.swing.table.TableColumnModel;
|
2016-12-10 07:36:44 +00:00
|
|
|
import javax.swing.table.TableRowSorter;
|
|
|
|
|
|
|
|
import com.bytezone.diskbrowser.gui.DuplicateAction.DiskTableSelectionListener;
|
2016-12-12 07:43:19 +00:00
|
|
|
import com.bytezone.diskbrowser.utilities.NumberRenderer;
|
2016-12-12 10:53:28 +00:00
|
|
|
import com.bytezone.diskbrowser.utilities.Utility;
|
2016-12-07 10:56:25 +00:00
|
|
|
|
|
|
|
public class DuplicateWindow extends JFrame
|
|
|
|
{
|
2016-12-09 11:31:03 +00:00
|
|
|
private final JTable table;
|
2016-12-07 10:56:25 +00:00
|
|
|
|
2016-12-10 07:36:44 +00:00
|
|
|
private final JButton btnExport = new JButton ("Export");
|
|
|
|
private final JButton btnHide = new JButton ("Close");
|
2016-12-12 23:46:09 +00:00
|
|
|
// private final JLabel lblTotalDisks = new JLabel ();
|
2016-12-12 10:53:28 +00:00
|
|
|
private final JPanel topPanel = new JPanel ();
|
2016-12-12 23:46:09 +00:00
|
|
|
private final List<JCheckBox> boxes = new ArrayList<JCheckBox> ();
|
|
|
|
private TableRowSorter<DiskTableModel> sorter;
|
|
|
|
private final CheckBoxActionListener checkBoxActionListener =
|
|
|
|
new CheckBoxActionListener ();
|
2016-12-07 10:56:25 +00:00
|
|
|
|
2016-12-12 23:46:09 +00:00
|
|
|
public DuplicateWindow (RootFolderData rootFolderData)
|
2016-12-07 10:56:25 +00:00
|
|
|
{
|
2016-12-12 23:46:09 +00:00
|
|
|
super ("Disk List - " + rootFolderData.rootFolder.getAbsolutePath ());
|
2016-12-07 10:56:25 +00:00
|
|
|
|
2016-12-09 11:31:03 +00:00
|
|
|
table = new JTable ();
|
|
|
|
JScrollPane scrollPane =
|
|
|
|
new JScrollPane (table, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
|
2016-12-07 10:56:25 +00:00
|
|
|
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
2016-12-10 07:36:44 +00:00
|
|
|
|
2016-12-09 11:31:03 +00:00
|
|
|
table.setFillsViewportHeight (true);
|
2016-12-10 07:36:44 +00:00
|
|
|
table.setAutoCreateRowSorter (true);
|
2016-12-09 11:31:03 +00:00
|
|
|
|
2016-12-10 07:36:44 +00:00
|
|
|
table.setShowGrid (true);
|
|
|
|
table.setGridColor (Color.LIGHT_GRAY);
|
2016-12-09 11:31:03 +00:00
|
|
|
|
|
|
|
add (scrollPane, BorderLayout.CENTER);
|
2016-12-07 10:56:25 +00:00
|
|
|
|
|
|
|
JPanel panel = new JPanel ();
|
2016-12-10 07:36:44 +00:00
|
|
|
panel.add (btnHide);
|
|
|
|
panel.add (btnExport);
|
2016-12-07 10:56:25 +00:00
|
|
|
add (panel, BorderLayout.SOUTH);
|
|
|
|
|
2016-12-12 10:53:28 +00:00
|
|
|
topPanel.setLayout (new FlowLayout (FlowLayout.LEFT, 10, 5));
|
|
|
|
add (topPanel, BorderLayout.NORTH);
|
|
|
|
|
2016-12-10 07:36:44 +00:00
|
|
|
btnHide.setEnabled (true);
|
|
|
|
btnExport.setEnabled (false);
|
2016-12-07 10:56:25 +00:00
|
|
|
|
2016-12-10 07:36:44 +00:00
|
|
|
btnHide.addActionListener (new ActionListener ()
|
2016-12-07 10:56:25 +00:00
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void actionPerformed (ActionEvent e)
|
|
|
|
{
|
2016-12-12 23:46:09 +00:00
|
|
|
setVisible (false);
|
2016-12-07 10:56:25 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-12 10:53:28 +00:00
|
|
|
scrollPane.setPreferredSize (new Dimension (1200, 700));
|
2016-12-07 10:56:25 +00:00
|
|
|
setDefaultCloseOperation (HIDE_ON_CLOSE);
|
|
|
|
}
|
|
|
|
|
2016-12-12 08:31:58 +00:00
|
|
|
// called from DuplicateSwingWorker
|
2016-12-12 23:46:09 +00:00
|
|
|
public void setTableData (final RootFolderData rootFolderData)
|
2016-12-07 10:56:25 +00:00
|
|
|
{
|
2016-12-12 10:53:28 +00:00
|
|
|
DiskTableModel diskTableModel = new DiskTableModel (rootFolderData);
|
2016-12-12 08:31:58 +00:00
|
|
|
table.setModel (diskTableModel);
|
2016-12-12 23:46:09 +00:00
|
|
|
// lblTotalDisks.setText (diskTableModel.getRowCount () + "");
|
2016-12-10 07:36:44 +00:00
|
|
|
|
2016-12-11 05:18:04 +00:00
|
|
|
int[] columnWidths = { 300, 300, 30, 40, 40, 40, 100 };
|
2016-12-12 07:43:19 +00:00
|
|
|
TableColumnModel tcm = table.getColumnModel ();
|
2016-12-10 07:36:44 +00:00
|
|
|
for (int i = 0; i < columnWidths.length; i++)
|
2016-12-12 07:43:19 +00:00
|
|
|
tcm.getColumn (i).setPreferredWidth (columnWidths[i]);
|
|
|
|
|
|
|
|
tcm.getColumn (3).setCellRenderer (NumberRenderer.getIntegerRenderer ());
|
2016-12-10 07:36:44 +00:00
|
|
|
|
2016-12-12 23:46:09 +00:00
|
|
|
sorter = new TableRowSorter<DiskTableModel> ((DiskTableModel) table.getModel ());
|
2016-12-10 07:36:44 +00:00
|
|
|
table.setRowSorter (sorter);
|
|
|
|
|
|
|
|
ListSelectionModel listSelectionModel = table.getSelectionModel ();
|
|
|
|
listSelectionModel.addListSelectionListener (new ListSelectionListener ()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void valueChanged (ListSelectionEvent e)
|
|
|
|
{
|
|
|
|
if (e.getValueIsAdjusting ())
|
|
|
|
return;
|
|
|
|
|
|
|
|
ListSelectionModel lsm = (ListSelectionModel) e.getSource ();
|
|
|
|
if (lsm.isSelectionEmpty ())
|
|
|
|
return;
|
|
|
|
|
|
|
|
table.scrollRectToVisible (
|
|
|
|
new Rectangle (table.getCellRect (lsm.getMinSelectionIndex (), 0, true)));
|
|
|
|
int selectedRow = table.getSelectedRow ();
|
|
|
|
int actualRow = sorter.convertRowIndexToModel (selectedRow);
|
|
|
|
|
|
|
|
DiskTableModel diskTableModel = (DiskTableModel) table.getModel ();
|
|
|
|
DiskDetails diskDetails = diskTableModel.lines.get (actualRow).diskDetails;
|
|
|
|
|
2016-12-12 23:46:09 +00:00
|
|
|
for (DiskTableSelectionListener listener : rootFolderData.listeners)
|
2016-12-10 07:36:44 +00:00
|
|
|
listener.diskSelected (diskDetails);
|
|
|
|
}
|
|
|
|
});
|
2016-12-09 12:12:35 +00:00
|
|
|
|
2016-12-12 10:53:28 +00:00
|
|
|
for (int i = 0; i < Utility.suffixes.size (); i++)
|
|
|
|
{
|
|
|
|
int total = rootFolderData.progressState.getTotalType (i);
|
|
|
|
JCheckBox btn =
|
|
|
|
new JCheckBox (String.format ("%s (%,d)", Utility.suffixes.get (i), total));
|
|
|
|
topPanel.add (btn);
|
2016-12-12 23:46:09 +00:00
|
|
|
boxes.add (btn);
|
2016-12-12 10:53:28 +00:00
|
|
|
|
|
|
|
if (total > 0)
|
2016-12-12 23:46:09 +00:00
|
|
|
{
|
2016-12-12 10:53:28 +00:00
|
|
|
btn.setSelected (true);
|
2016-12-12 23:46:09 +00:00
|
|
|
btn.addActionListener (checkBoxActionListener);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
btn.setEnabled (false);
|
2016-12-12 10:53:28 +00:00
|
|
|
}
|
|
|
|
|
2016-12-09 12:12:35 +00:00
|
|
|
JTableHeader header = table.getTableHeader ();
|
|
|
|
header.setFont (header.getFont ().deriveFont ((float) 13.0));
|
|
|
|
|
2016-12-12 10:53:28 +00:00
|
|
|
pack ();
|
|
|
|
setLocationRelativeTo (null);
|
2016-12-12 23:46:09 +00:00
|
|
|
|
|
|
|
if (!rootFolderData.showTotals)
|
|
|
|
setVisible (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getFilterText ()
|
|
|
|
{
|
|
|
|
StringBuilder filterText = new StringBuilder ();
|
|
|
|
for (JCheckBox box : boxes)
|
|
|
|
if (box.isSelected ())
|
|
|
|
{
|
|
|
|
String text = box.getText ();
|
|
|
|
int pos = text.indexOf (' ');
|
|
|
|
filterText.append (text.substring (0, pos) + "|");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filterText.length () > 0)
|
|
|
|
filterText.deleteCharAt (filterText.length () - 1);
|
|
|
|
|
|
|
|
return filterText.toString ();
|
|
|
|
}
|
|
|
|
|
|
|
|
class CheckBoxActionListener implements ActionListener
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void actionPerformed (ActionEvent e)
|
|
|
|
{
|
|
|
|
RowFilter<DiskTableModel, Object> rf = null;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
rf = RowFilter.regexFilter (getFilterText (), 2);
|
|
|
|
}
|
|
|
|
catch (java.util.regex.PatternSyntaxException exception)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sorter.setRowFilter (rf);
|
|
|
|
}
|
2016-12-07 10:56:25 +00:00
|
|
|
}
|
2016-12-09 11:31:03 +00:00
|
|
|
}
|