1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-22 07:48:52 -05:00

* remove analyze.tools package (refactor and move to analyze)

This commit is contained in:
Reinhard Pointner 2008-12-27 11:30:35 +00:00
parent 7d7913bc1e
commit 1cf51ae179
4 changed files with 0 additions and 417 deletions

View File

@ -1,51 +0,0 @@
package net.sourceforge.filebot.ui.panel.analyze.tools;
import java.awt.datatransfer.Transferable;
import java.io.File;
import java.util.LinkedHashSet;
import javax.swing.JComponent;
import javax.swing.TransferHandler;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import net.sourceforge.filebot.ui.FileBotTree;
import net.sourceforge.filebot.ui.transfer.TransferableExportHandler;
import net.sourceforge.filebot.ui.transfer.FileTransferable;
class FileTreeExportHandler implements TransferableExportHandler {
@Override
public Transferable createTransferable(JComponent c) {
FileBotTree tree = (FileBotTree) c;
LinkedHashSet<File> files = new LinkedHashSet<File>();
for (TreePath path : tree.getSelectionPaths()) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
files.addAll(tree.convertToList(node));
}
if (!files.isEmpty())
return new FileTransferable(files);
return null;
}
@Override
public void exportDone(JComponent source, Transferable data, int action) {
}
@Override
public int getSourceActions(JComponent c) {
return TransferHandler.COPY;
}
}

View File

@ -1,189 +0,0 @@
package net.sourceforge.filebot.ui.panel.analyze.tools;
import java.awt.Color;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingWorker;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import net.miginfocom.swing.MigLayout;
import net.sourceforge.filebot.ResourceManager;
import net.sourceforge.filebot.ui.FileBotTree;
import net.sourceforge.filebot.ui.transfer.DefaultTransferHandler;
import net.sourceforge.tuned.FileUtil;
import net.sourceforge.tuned.ui.GradientStyle;
import net.sourceforge.tuned.ui.LoadingOverlayPane;
import net.sourceforge.tuned.ui.notification.SeparatorBorder;
public class SplitPanel extends ToolPanel implements ChangeListener {
private FileBotTree tree = new FileBotTree();
private SpinnerNumberModel spinnerModel = new SpinnerNumberModel(4480, 0, Integer.MAX_VALUE, 100);
public SplitPanel() {
super("Split");
JScrollPane treeScrollPane = new JScrollPane(tree);
treeScrollPane.setBorder(BorderFactory.createEmptyBorder());
JSpinner spinner = new JSpinner(spinnerModel);
spinner.setEditor(new JSpinner.NumberEditor(spinner, "#"));
LoadingOverlayPane loadingOverlayPane = new LoadingOverlayPane(treeScrollPane, ResourceManager.getIcon("loading"));
loadingOverlayPane.setBorder(new SeparatorBorder(2, new Color(0, 0, 0, 90), GradientStyle.TOP_TO_BOTTOM, SeparatorBorder.Position.BOTTOM));
setLayout(new MigLayout("insets 0, nogrid, fill", "align center"));
add(loadingOverlayPane, "grow, wrap");
add(new JLabel("Split every"));
add(spinner, "wmax 80, gap top rel, gap bottom unrel");
add(new JLabel("MB."));
tree.setTransferHandler(new DefaultTransferHandler(null, new FileTreeExportHandler()));
tree.setDragEnabled(true);
spinnerModel.addChangeListener(this);
}
public void stateChanged(ChangeEvent e) {
if (fileChache != null) {
update();
}
}
private long getSplitSize() {
return spinnerModel.getNumber().intValue() * FileUtil.MEGA;
}
private UpdateTask updateTask;
private Collection<File> fileChache;
@Override
public void update(Collection<File> files) {
this.fileChache = files;
update();
}
private synchronized void update() {
if (updateTask != null) {
updateTask.cancel(false);
}
updateTask = new UpdateTask(fileChache);
tree.firePropertyChange(LoadingOverlayPane.LOADING_PROPERTY, false, true);
updateTask.execute();
}
private class UpdateTask extends SwingWorker<DefaultTreeModel, Void> {
private final Collection<File> files;
public UpdateTask(Collection<File> files) {
this.files = files;
}
@Override
protected DefaultTreeModel doInBackground() throws Exception {
List<List<File>> parts = new ArrayList<List<File>>();
List<File> remainder = new ArrayList<File>();
long splitSize = getSplitSize();
long currentSize = 0;
List<File> currentPart = null;
for (File file : files) {
long fileSize = file.length();
if (fileSize > splitSize) {
remainder.add(file);
continue;
}
if (currentSize + fileSize > splitSize) {
currentSize = 0;
currentPart = null;
}
if (currentPart == null) {
currentPart = new ArrayList<File>();
parts.add(currentPart);
}
currentSize += fileSize;
currentPart.add(file);
if (isCancelled()) {
return null;
}
}
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
int count = 1;
for (List<File> part : parts) {
root.add(createTreeNode(String.format("Part %d", count), part));
count++;
if (isCancelled()) {
return null;
}
}
if (!remainder.isEmpty()) {
root.add(createTreeNode("Remainder", remainder));
}
return new DefaultTreeModel(root);
}
@Override
protected void done() {
if (isCancelled()) {
return;
}
try {
tree.setModel(get());
} catch (Exception e) {
// should not happen
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString(), e);
}
tree.firePropertyChange(LoadingOverlayPane.LOADING_PROPERTY, true, false);
}
}
}

View File

@ -1,51 +0,0 @@
package net.sourceforge.filebot.ui.panel.analyze.tools;
import java.io.File;
import java.util.Collection;
import javax.swing.JPanel;
import javax.swing.tree.DefaultMutableTreeNode;
import net.sourceforge.tuned.FileUtil;
public abstract class ToolPanel extends JPanel {
private final String name;
public ToolPanel(String name) {
super(null);
this.name = name;
}
public String getToolName() {
return name;
}
public abstract void update(Collection<File> list);
protected DefaultMutableTreeNode createTreeNode(String name, Collection<File> files) {
DefaultMutableTreeNode node = new DefaultMutableTreeNode();
long totalSize = 0;
for (File file : files) {
node.add(new DefaultMutableTreeNode(file));
totalSize += file.length();
}
// format the number of files string (e.g. 1 file, 2 files, ...)
String numberOfFiles = String.format("%,d %s", files.size(), files.size() == 1 ? "file" : "files");
// set node text (e.g. txt (1 file, 42 Byte))
node.setUserObject(String.format("%s (%s, %s)", name, numberOfFiles, FileUtil.formatSize(totalSize)));
return node;
}
}

View File

@ -1,126 +0,0 @@
package net.sourceforge.filebot.ui.panel.analyze.tools;
import java.awt.BorderLayout;
import java.io.File;
import java.util.Collection;
import java.util.Map;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.JScrollPane;
import javax.swing.SwingWorker;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import net.sourceforge.filebot.ResourceManager;
import net.sourceforge.filebot.ui.FileBotTree;
import net.sourceforge.filebot.ui.transfer.DefaultTransferHandler;
import net.sourceforge.tuned.FileUtil;
import net.sourceforge.tuned.ui.LoadingOverlayPane;
public class TypePanel extends ToolPanel {
private FileBotTree tree = new FileBotTree();
public TypePanel() {
super("Types");
setLayout(new BorderLayout());
JScrollPane sp = new JScrollPane(tree);
sp.setBorder(BorderFactory.createEmptyBorder());
add(new LoadingOverlayPane(sp, ResourceManager.getIcon("loading")), BorderLayout.CENTER);
tree.setTransferHandler(new DefaultTransferHandler(null, new FileTreeExportHandler()));
tree.setDragEnabled(true);
}
private UpdateTask updateTask = null;
@Override
public synchronized void update(Collection<File> files) {
if (updateTask != null) {
updateTask.cancel(false);
}
updateTask = new UpdateTask(files);
tree.firePropertyChange(LoadingOverlayPane.LOADING_PROPERTY, false, true);
updateTask.execute();
}
private class UpdateTask extends SwingWorker<DefaultTreeModel, Void> {
private final Collection<File> files;
public UpdateTask(Collection<File> files) {
this.files = files;
}
@Override
protected DefaultTreeModel doInBackground() throws Exception {
SortedMap<String, SortedSet<File>> map = new TreeMap<String, SortedSet<File>>();
for (File file : files) {
String extension = FileUtil.getExtension(file);
SortedSet<File> set = map.get(extension);
if (set == null) {
set = new TreeSet<File>();
map.put(extension, set);
}
set.add(file);
if (isCancelled()) {
return null;
}
}
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
for (Map.Entry<String, SortedSet<File>> entry : map.entrySet()) {
root.add(createTreeNode(entry.getKey(), entry.getValue()));
if (isCancelled()) {
return null;
}
}
return new DefaultTreeModel(root);
}
@Override
protected void done() {
if (isCancelled()) {
return;
}
try {
tree.setModel(get());
} catch (Exception e) {
// should not happen
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString(), e);
}
tree.firePropertyChange(LoadingOverlayPane.LOADING_PROPERTY, true, false);
}
}
}