* some refactoring

This commit is contained in:
Reinhard Pointner 2009-02-15 21:11:03 +00:00
parent 4c94679a64
commit 051cf3362b
5 changed files with 34 additions and 53 deletions

View File

@ -29,7 +29,7 @@
<attribute name="Built-Date" value="${today}" />
<attribute name="Implementation-Title" value="${title}" />
<attribute name="Implementation-Version" value="${version}" />
<attribute name="Class-Path" value="args4j.jar miglayout.jar glazedlists.jar nekohtml.jar xercesImpl.jar simmetrics.jar xmlrpc-client.jar" />
<attribute name="Class-Path" value="args4j.jar miglayout.jar glazedlists.jar nekohtml.jar xercesImpl.jar ehcache.jar simmetrics.jar xmlrpc-client.jar" />
<attribute name="Main-Class" value="net.sourceforge.filebot.Main" />
</manifest>
</jar>
@ -53,13 +53,8 @@
<!-- include libs -->
<zipfileset src="${dir.lib}/xercesImpl.jar">
<include name="org/apache/html/dom/**" />
<include name="org/apache/xerces/dom/**" />
<include name="org/apache/xerces/impl/**" />
<include name="org/apache/xerces/parsers/**" />
<include name="org/apache/xerces/util/**" />
<include name="org/apache/xerces/xni/**" />
<include name="org/apache/xerces/xs/**" />
<include name="**/*.class" />
<include name="**/*.properties" />
</zipfileset>
<zipfileset src="${dir.lib}/nekohtml.jar">
@ -68,14 +63,11 @@
</zipfileset>
<zipfileset src="${dir.lib}/simmetrics.jar">
<include name="uk/ac/shef/wit/simmetrics/math/**" />
<include name="uk/ac/shef/wit/simmetrics/similaritymetrics/**" />
<include name="uk/ac/shef/wit/simmetrics/tokenisers/**" />
<include name="uk/ac/shef/wit/simmetrics/wordhandlers/**" />
<include name="**/*.class" />
</zipfileset>
<zipfileset src="${dir.lib}/glazedlists.jar">
<include name="ca/odell/glazedlists/**" />
<include name="**/*.class" />
</zipfileset>
<zipfileset src="${dir.lib}/miglayout.jar">
@ -94,7 +86,7 @@
</zipfileset>
<zipfileset src="${dir.lib}/ehcache.jar">
<include name="net/sf/ehcache/**" />
<include name="**/*.class" />
</zipfileset>
</jar>
</target>
@ -155,4 +147,8 @@
</junit>
</target>
<target name="run-fatjar" depends="fatjar">
<java jar="${dir.dist}/fatjar/FileBot.jar" fork="true" />
</target>
</project>

View File

@ -7,8 +7,9 @@ import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
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;
@ -23,7 +24,6 @@ import net.sourceforge.filebot.ui.panel.analyze.FileTree.FolderNode;
import net.sourceforge.filebot.ui.transfer.DefaultTransferHandler;
import net.sourceforge.tuned.FileUtilities;
import net.sourceforge.tuned.ui.GradientStyle;
import net.sourceforge.tuned.ui.LoadingOverlayPane;
import net.sourceforge.tuned.ui.notification.SeparatorBorder;
@ -38,17 +38,14 @@ public class SplitTool extends Tool<TreeModel> implements ChangeListener {
super("Split");
JScrollPane treeScrollPane = new JScrollPane(tree);
treeScrollPane.setBorder(BorderFactory.createEmptyBorder());
treeScrollPane.setBorder(new SeparatorBorder(2, new Color(0, 0, 0, 90), GradientStyle.TOP_TO_BOTTOM, SeparatorBorder.Position.BOTTOM));
JSpinner spinner = new JSpinner(spinnerModel);
spinner.setEditor(new JSpinner.NumberEditor(spinner, "#"));
LoadingOverlayPane loadingOverlayPane = new LoadingOverlayPane(treeScrollPane, this);
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(treeScrollPane, "grow, wrap");
add(new JLabel("Split every"));
add(spinner, "wmax 80, gap top rel, gap bottom unrel");
@ -68,9 +65,16 @@ public class SplitTool extends Tool<TreeModel> implements ChangeListener {
private FolderNode sourceModel = null;
public void stateChanged(ChangeEvent e) {
if (sourceModel != null)
setSourceModel(sourceModel);
public void stateChanged(ChangeEvent evt) {
if (sourceModel != null) {
try {
// update model in foreground, will be much faster than the initial load because length() is cached now
setModel(createModelInBackground(sourceModel));
} catch (InterruptedException e) {
// will not happen
Logger.getLogger("global").log(Level.SEVERE, e.getMessage(), e);
}
}
}

View File

@ -2,12 +2,9 @@
package net.sourceforge.filebot.ui.panel.analyze;
import static net.sourceforge.tuned.ui.LoadingOverlayPane.LOADING_PROPERTY;
import java.io.File;
import java.util.ConcurrentModificationException;
import java.util.List;
import java.util.concurrent.Semaphore;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -18,13 +15,11 @@ import net.sourceforge.filebot.ui.panel.analyze.FileTree.FileNode;
import net.sourceforge.filebot.ui.panel.analyze.FileTree.FolderNode;
import net.sourceforge.tuned.ExceptionUtilities;
import net.sourceforge.tuned.FileUtilities;
import net.sourceforge.tuned.ui.TunedUtilities;
abstract class Tool<M> extends JComponent {
private UpdateModelTask updateTask = null;
private Semaphore updateSemaphore = new Semaphore(1);
public Tool(String name) {
@ -32,16 +27,12 @@ abstract class Tool<M> extends JComponent {
}
public synchronized void setSourceModel(FolderNode sourceModel) {
public void setSourceModel(FolderNode sourceModel) {
if (updateTask != null) {
updateTask.cancel(true);
}
updateTask = new UpdateModelTask(sourceModel);
// sync events for loading overlay
TunedUtilities.syncPropertyChangeEvents(boolean.class, LOADING_PROPERTY, updateTask, this);
updateTask.execute();
}
@ -64,29 +55,14 @@ abstract class Tool<M> extends JComponent {
@Override
protected M doInBackground() throws Exception {
// acquire semaphore
updateSemaphore.acquireUninterruptibly();
try {
M model = null;
if (!isCancelled()) {
firePropertyChange(LOADING_PROPERTY, false, true);
model = createModelInBackground(sourceModel);
firePropertyChange(LOADING_PROPERTY, true, false);
}
return model;
} finally {
updateSemaphore.release();
}
return createModelInBackground(sourceModel);
}
@Override
protected void done() {
// update task will only be cancelled if a newer update task has been started
if (!isCancelled()) {
if (this == updateTask && !isCancelled()) {
try {
setModel(get());
} catch (Exception e) {

View File

@ -20,7 +20,6 @@ import net.miginfocom.swing.MigLayout;
import net.sourceforge.filebot.ui.panel.analyze.FileTree.FolderNode;
import net.sourceforge.filebot.ui.transfer.DefaultTransferHandler;
import net.sourceforge.tuned.FileUtilities;
import net.sourceforge.tuned.ui.LoadingOverlayPane;
public class TypeTool extends Tool<TreeModel> {
@ -35,7 +34,8 @@ public class TypeTool extends Tool<TreeModel> {
JScrollPane treeScrollPane = new JScrollPane(tree);
treeScrollPane.setBorder(BorderFactory.createEmptyBorder());
add(new LoadingOverlayPane(treeScrollPane, this), "grow");
add(treeScrollPane, "grow");
tree.setTransferHandler(new DefaultTransferHandler(null, new FileTreeExportHandler()));
tree.setDragEnabled(true);

View File

@ -62,6 +62,11 @@ public class IconViewPanel extends JPanel {
}
public JList getList() {
return list;
}
public JPanel getHeaderPanel() {
return headerPanel;
}