diff --git a/source/net/sourceforge/filebot/ui/panel/analyze/AnalyzePanel.java b/source/net/sourceforge/filebot/ui/panel/analyze/AnalyzePanel.java index c79ab70e..d8a32a18 100644 --- a/source/net/sourceforge/filebot/ui/panel/analyze/AnalyzePanel.java +++ b/source/net/sourceforge/filebot/ui/panel/analyze/AnalyzePanel.java @@ -2,21 +2,16 @@ package net.sourceforge.filebot.ui.panel.analyze; -import java.awt.BorderLayout; -import java.awt.Dimension; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.File; -import java.util.ArrayList; import java.util.List; import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.SwingConstants; +import net.miginfocom.swing.MigLayout; import net.sourceforge.filebot.ResourceManager; import net.sourceforge.filebot.ui.FileBotPanel; import net.sourceforge.filebot.ui.FileTransferableMessageHandler; @@ -31,31 +26,16 @@ public class AnalyzePanel extends FileBotPanel { private final FileTreePanel fileTreePanel = new FileTreePanel(); private final JTabbedPane toolsPanel = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT); - private final List toolPanels = new ArrayList(); - public AnalyzePanel() { super("Analyze", ResourceManager.getIcon("panel.analyze")); - Box panel = new Box(BoxLayout.X_AXIS); + toolsPanel.setBorder(BorderFactory.createTitledBorder("Tools")); - panel.add(fileTreePanel); + setLayout(new MigLayout("insets 0,gapx 50, fill")); - panel.add(Box.createHorizontalStrut(50)); - - JPanel right = new JPanel(); - right.setLayout(new BorderLayout()); - right.setBorder(BorderFactory.createTitledBorder("Tools")); - - right.add(toolsPanel, BorderLayout.CENTER); - - panel.add(right); - - add(panel, BorderLayout.CENTER); - - Dimension min = new Dimension(300, 300); - fileTreePanel.setMinimumSize(min); - toolsPanel.setMinimumSize(min); + add(fileTreePanel, "grow"); + add(toolsPanel, "grow"); addTool(new TypePanel()); addTool(new SplitPanel()); @@ -68,7 +48,6 @@ public class AnalyzePanel extends FileBotPanel { private void addTool(ToolPanel toolPanel) { toolsPanel.addTab(toolPanel.getToolName(), toolPanel); - toolPanels.add(toolPanel); } private PropertyChangeListener fileTreeChangeListener = new PropertyChangeListener() { @@ -77,7 +56,8 @@ public class AnalyzePanel extends FileBotPanel { public void propertyChange(PropertyChangeEvent evt) { List files = (List) evt.getNewValue(); - for (ToolPanel toolPanel : toolPanels) { + for (int i = 0; i < toolsPanel.getTabCount(); i++) { + ToolPanel toolPanel = (ToolPanel) toolsPanel.getComponentAt(i); toolPanel.update(files); } } diff --git a/source/net/sourceforge/filebot/ui/panel/analyze/tools/SplitPanel.java b/source/net/sourceforge/filebot/ui/panel/analyze/tools/SplitPanel.java index e893a79f..2cbd3aa0 100644 --- a/source/net/sourceforge/filebot/ui/panel/analyze/tools/SplitPanel.java +++ b/source/net/sourceforge/filebot/ui/panel/analyze/tools/SplitPanel.java @@ -2,9 +2,7 @@ package net.sourceforge.filebot.ui.panel.analyze.tools; -import java.awt.BorderLayout; import java.awt.Color; -import java.awt.Dimension; import java.io.File; import java.util.ArrayList; import java.util.Collection; @@ -13,19 +11,18 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.BorderFactory; -import javax.swing.Box; import javax.swing.JLabel; +import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSpinner; import javax.swing.SpinnerNumberModel; import javax.swing.SwingWorker; -import javax.swing.border.CompoundBorder; -import javax.swing.border.EmptyBorder; 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; @@ -44,35 +41,31 @@ public class SplitPanel extends ToolPanel implements ChangeListener { public SplitPanel() { super("Split"); - setLayout(new BorderLayout()); - JScrollPane sp = new JScrollPane(tree); - sp.setBorder(BorderFactory.createEmptyBorder()); + setLayout(new MigLayout("nogrid, flowx, insets 0, fill", "align center")); + + JScrollPane treeScrollPane = new JScrollPane(tree); + treeScrollPane.setBorder(BorderFactory.createEmptyBorder()); + JSpinner spinner = new JSpinner(spinnerModel); - spinner.setMaximumSize(spinner.getPreferredSize()); spinner.setEditor(new JSpinner.NumberEditor(spinner, "#")); - Box spinnerBox = Box.createHorizontalBox(); - spinnerBox.add(Box.createGlue()); - spinnerBox.add(new JLabel("Split every")); - spinnerBox.add(Box.createHorizontalStrut(5)); - spinnerBox.add(spinner); - spinnerBox.add(Box.createHorizontalStrut(5)); - spinnerBox.add(new JLabel("MB.")); - spinnerBox.add(Box.createGlue()); + JPanel spinnerPanel = new JPanel(new MigLayout("nogrid, flowx")); + spinnerPanel.setOpaque(false); - add(new LoadingOverlayPane(sp, ResourceManager.getIcon("loading")), BorderLayout.CENTER); - add(spinnerBox, BorderLayout.SOUTH); + 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)); + + 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); - Color beginColor = new Color(0, 0, 0, 90); - SeparatorBorder separatorBorder = new SeparatorBorder(2, beginColor, GradientStyle.TOP_TO_BOTTOM, SeparatorBorder.Position.TOP); - spinnerBox.setBorder(new CompoundBorder(separatorBorder, new EmptyBorder(6, 5, 7, 5))); - spinnerModel.addChangeListener(this); - spinner.setPreferredSize(new Dimension(80, 20)); } diff --git a/source/net/sourceforge/filebot/ui/panel/rename/MatchAction.java b/source/net/sourceforge/filebot/ui/panel/rename/MatchAction.java index 187853fc..0ff27dbd 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/MatchAction.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/MatchAction.java @@ -25,7 +25,6 @@ import net.sourceforge.filebot.ui.panel.rename.matcher.Matcher; import net.sourceforge.filebot.ui.panel.rename.metric.CompositeSimilarityMetric; import net.sourceforge.filebot.ui.panel.rename.metric.NumericSimilarityMetric; import net.sourceforge.filebot.ui.panel.rename.metric.SimilarityMetric; -import net.sourceforge.tuned.ui.ProgressDialog; import net.sourceforge.tuned.ui.SwingWorkerProgressMonitor; @@ -88,12 +87,7 @@ class MatchAction extends AbstractAction { RenameList secondaryList = (RenameList) (matchName2File ? filesList : namesList); BackgroundMatcher backgroundMatcher = new BackgroundMatcher(primaryList, secondaryList, metrics); - SwingWorkerProgressMonitor monitor = new SwingWorkerProgressMonitor(SwingUtilities.getWindowAncestor(source), backgroundMatcher); - - ProgressDialog progressDialog = monitor.getProgressDialog(); - progressDialog.setTitle("Matching ..."); - progressDialog.setHeader(progressDialog.getTitle()); - progressDialog.setIcon((Icon) getValue(SMALL_ICON)); + SwingWorkerProgressMonitor monitor = new SwingWorkerProgressMonitor(SwingUtilities.getWindowAncestor(source), backgroundMatcher, (Icon) getValue(SMALL_ICON)); backgroundMatcher.execute(); @@ -102,7 +96,7 @@ class MatchAction extends AbstractAction { backgroundMatcher.get(monitor.getMillisToPopup(), TimeUnit.MILLISECONDS); } catch (TimeoutException ex) { // matcher will take longer, stop blocking EDT - progressDialog.setVisible(true); + monitor.getProgressDialog().setVisible(true); } catch (Exception e) { Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString(), e); } @@ -129,6 +123,9 @@ class MatchAction extends AbstractAction { @Override protected List doInBackground() throws Exception { + + firePropertyChange(SwingWorkerProgressMonitor.PROPERTY_TITLE, null, "Matching..."); + int total = matcher.remainingMatches(); List matches = new ArrayList(total); diff --git a/source/net/sourceforge/filebot/ui/transfer/TextFileTransferable.java b/source/net/sourceforge/filebot/ui/transfer/LazyTextFileTransferable.java similarity index 93% rename from source/net/sourceforge/filebot/ui/transfer/TextFileTransferable.java rename to source/net/sourceforge/filebot/ui/transfer/LazyTextFileTransferable.java index 86d6b41a..90b5fd88 100644 --- a/source/net/sourceforge/filebot/ui/transfer/TextFileTransferable.java +++ b/source/net/sourceforge/filebot/ui/transfer/LazyTextFileTransferable.java @@ -15,7 +15,7 @@ import net.sourceforge.filebot.FileBotUtil; import net.sourceforge.tuned.TemporaryFolder; -public class TextFileTransferable implements Transferable { +public class LazyTextFileTransferable implements Transferable { private final String text; private final String defaultFileName; @@ -23,7 +23,7 @@ public class TextFileTransferable implements Transferable { private FileTransferable fileTransferable = null; - public TextFileTransferable(String text, String defaultFileName) { + public LazyTextFileTransferable(String text, String defaultFileName) { this.text = text; this.defaultFileName = defaultFileName; } diff --git a/source/net/sourceforge/filebot/ui/transfer/TextFileExportHandler.java b/source/net/sourceforge/filebot/ui/transfer/TextFileExportHandler.java index c3f0b3c6..7a21a2b9 100644 --- a/source/net/sourceforge/filebot/ui/transfer/TextFileExportHandler.java +++ b/source/net/sourceforge/filebot/ui/transfer/TextFileExportHandler.java @@ -50,7 +50,7 @@ public abstract class TextFileExportHandler implements TransferableExportHandler StringWriter buffer = new StringWriter(); export(new PrintWriter(buffer)); - return new TextFileTransferable(buffer.toString(), getDefaultFileName()); + return new LazyTextFileTransferable(buffer.toString(), getDefaultFileName()); } diff --git a/source/net/sourceforge/tuned/ui/DefaultFancyListCellRenderer.java b/source/net/sourceforge/tuned/ui/DefaultFancyListCellRenderer.java index b2c37a44..713d95bc 100644 --- a/source/net/sourceforge/tuned/ui/DefaultFancyListCellRenderer.java +++ b/source/net/sourceforge/tuned/ui/DefaultFancyListCellRenderer.java @@ -38,7 +38,7 @@ public class DefaultFancyListCellRenderer extends AbstractFancyListCellRenderer label.setOpaque(false); - setText(value.toString()); + setText(String.valueOf(value)); } diff --git a/source/net/sourceforge/tuned/ui/ProgressDialog.java b/source/net/sourceforge/tuned/ui/ProgressDialog.java index 59fa1e9e..b78b6b72 100644 --- a/source/net/sourceforge/tuned/ui/ProgressDialog.java +++ b/source/net/sourceforge/tuned/ui/ProgressDialog.java @@ -2,8 +2,7 @@ package net.sourceforge.tuned.ui; -import java.awt.BorderLayout; -import java.awt.FlowLayout; +import java.awt.Font; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.WindowAdapter; @@ -12,18 +11,14 @@ import java.awt.event.WindowListener; import javax.swing.AbstractAction; import javax.swing.Action; -import javax.swing.Box; import javax.swing.Icon; import javax.swing.JButton; -import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JProgressBar; -import javax.swing.KeyStroke; -import javax.swing.SwingConstants; -import javax.swing.border.Border; -import javax.swing.border.EmptyBorder; + +import net.miginfocom.swing.MigLayout; public class ProgressDialog extends JDialog { @@ -41,59 +36,27 @@ public class ProgressDialog extends JDialog { public ProgressDialog(Window owner) { super(owner, ModalityType.DOCUMENT_MODAL); - if (!owner.getIconImages().isEmpty()) { - setIconImages(owner.getIconImages()); - } - - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(closeListener); - cancelButton = new JButton(cancelAction); + addWindowListener(closeListener); + + headerLabel.setFont(headerLabel.getFont().deriveFont(Font.BOLD)); progressBar.setStringPainted(true); - iconLabel.setHorizontalAlignment(SwingConstants.CENTER); - iconLabel.setVerticalAlignment(SwingConstants.CENTER); - iconLabel.setBorder(new EmptyBorder(0, 2, 0, 10)); + JPanel c = (JPanel) getContentPane(); - Border labelBorder = new EmptyBorder(3, 0, 0, 0); - headerLabel.setBorder(labelBorder); - noteLabel.setBorder(labelBorder); + c.setLayout(new MigLayout("insets panel, fill")); - JComponent c = (JComponent) getContentPane(); + c.add(iconLabel, "spany 2, grow 0 0, gap right 1mm"); + c.add(headerLabel, "align left, wmax 70%, grow 100 0, wrap"); + c.add(noteLabel, "align left, wmax 70%, grow 100 0, wrap"); + c.add(progressBar, "spanx 2, gap top unrel, gap bottom unrel, grow, wrap"); - c.setBorder(new EmptyBorder(5, 5, 5, 5)); + c.add(cancelButton, "spanx 2, align center"); - JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); - buttonPanel.add(cancelButton); - - Box messageBox = Box.createVerticalBox(); - messageBox.add(headerLabel); - messageBox.add(noteLabel); - messageBox.add(Box.createVerticalGlue()); - - JPanel messagePanel = new JPanel(new BorderLayout()); - messagePanel.add(iconLabel, BorderLayout.WEST); - messagePanel.add(messageBox, BorderLayout.CENTER); - - JPanel progressBarPanel = new JPanel(new BorderLayout()); - progressBarPanel.add(progressBar, BorderLayout.CENTER); - progressBarPanel.setBorder(new EmptyBorder(8, 12, 3, 12)); - - Box progressBox = Box.createVerticalBox(); - progressBox.add(messagePanel); - progressBox.add(progressBarPanel); - - c.add(progressBox, BorderLayout.CENTER); - c.add(buttonPanel, BorderLayout.SOUTH); - - setSize(240, 138); - setResizable(false); + setSize(240, 155); setLocation(TunedUtil.getPreferredLocation(this)); - - // Shortcut Escape - TunedUtil.putActionForKeystroke(c, KeyStroke.getKeyStroke("released ESCAPE"), cancelAction); } @@ -117,23 +80,8 @@ public class ProgressDialog extends JDialog { } - public void setProgressMaximum(int n) { - progressBar.setMaximum(n); - } - - - public void setProgressMinimum(int n) { - progressBar.setMinimum(n); - } - - - public void setProgressValue(int n) { - progressBar.setValue(n); - } - - - public void setProgressString(String text) { - progressBar.setString(text); + public JProgressBar getProgressBar() { + return progressBar; } @@ -161,8 +109,8 @@ public class ProgressDialog extends JDialog { @Override public void windowClosing(WindowEvent e) { - cancelled = true; - close(); + cancelAction.actionPerformed(null); } }; + } diff --git a/source/net/sourceforge/tuned/ui/SwingWorkerProgressMonitor.java b/source/net/sourceforge/tuned/ui/SwingWorkerProgressMonitor.java index 10c4a0df..ab0c4e68 100644 --- a/source/net/sourceforge/tuned/ui/SwingWorkerProgressMonitor.java +++ b/source/net/sourceforge/tuned/ui/SwingWorkerProgressMonitor.java @@ -7,12 +7,14 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.beans.PropertyChangeEvent; +import javax.swing.Icon; import javax.swing.SwingWorker; import javax.swing.Timer; public class SwingWorkerProgressMonitor { + public static final String PROPERTY_TITLE = "title"; public static final String PROPERTY_NOTE = "note"; public static final String PROPERTY_PROGRESS_STRING = "progress string"; @@ -22,12 +24,14 @@ public class SwingWorkerProgressMonitor { private int millisToPopup = 2000; - public SwingWorkerProgressMonitor(Window owner, SwingWorker worker) { + public SwingWorkerProgressMonitor(Window owner, SwingWorker worker, Icon progressDialogIcon) { this.worker = worker; progressDialog = new ProgressDialog(owner); + progressDialog.setIcon(progressDialogIcon); worker.addPropertyChangeListener(listener); + progressDialog.getCancelButton().addActionListener(cancelListener); } @@ -48,27 +52,29 @@ public class SwingWorkerProgressMonitor { private final SwingWorkerPropertyChangeAdapter listener = new SwingWorkerPropertyChangeAdapter() { - private Timer popupTimer; + private Timer popupTimer = null; @Override public void propertyChange(PropertyChangeEvent evt) { - if (evt.getPropertyName().equals(PROPERTY_NOTE)) - note(evt); - else if (evt.getPropertyName().equals(PROPERTY_PROGRESS_STRING)) + if (evt.getPropertyName().equals(PROPERTY_PROGRESS_STRING)) progressString(evt); + else if (evt.getPropertyName().equals(PROPERTY_NOTE)) + note(evt); + else if (evt.getPropertyName().equals(PROPERTY_TITLE)) + title(evt); else super.propertyChange(evt); } @Override - public void started(PropertyChangeEvent evt) { + protected void started(PropertyChangeEvent evt) { popupTimer = TunedUtil.invokeLater(millisToPopup, new Runnable() { @Override public void run() { - if (!worker.isDone()) { + if (!worker.isDone() && !progressDialog.isVisible()) { progressDialog.setVisible(true); } } @@ -77,7 +83,7 @@ public class SwingWorkerProgressMonitor { @Override - public void done(PropertyChangeEvent evt) { + protected void done(PropertyChangeEvent evt) { if (popupTimer != null) { popupTimer.stop(); } @@ -87,20 +93,28 @@ public class SwingWorkerProgressMonitor { @Override - public void progress(PropertyChangeEvent evt) { - progressDialog.setProgressValue((Integer) evt.getNewValue()); + protected void progress(PropertyChangeEvent evt) { + progressDialog.getProgressBar().setValue((Integer) evt.getNewValue()); } - public void progressString(PropertyChangeEvent evt) { - progressDialog.setProgressString(evt.getNewValue().toString()); + protected void progressString(PropertyChangeEvent evt) { + progressDialog.getProgressBar().setString(evt.getNewValue().toString()); } - public void note(PropertyChangeEvent evt) { + protected void note(PropertyChangeEvent evt) { progressDialog.setNote(evt.getNewValue().toString()); } + + protected void title(PropertyChangeEvent evt) { + String title = evt.getNewValue().toString(); + + progressDialog.setHeader(title); + progressDialog.setTitle(title); + } + }; private final ActionListener cancelListener = new ActionListener() { diff --git a/source/net/sourceforge/tuned/ui/SwingWorkerPropertyChangeAdapter.java b/source/net/sourceforge/tuned/ui/SwingWorkerPropertyChangeAdapter.java index 749e1b03..0b27db45 100644 --- a/source/net/sourceforge/tuned/ui/SwingWorkerPropertyChangeAdapter.java +++ b/source/net/sourceforge/tuned/ui/SwingWorkerPropertyChangeAdapter.java @@ -18,7 +18,7 @@ public abstract class SwingWorkerPropertyChangeAdapter implements PropertyChange } - public void state(PropertyChangeEvent evt) { + protected void state(PropertyChangeEvent evt) { switch ((StateValue) evt.getNewValue()) { case STARTED: started(evt); @@ -30,15 +30,15 @@ public abstract class SwingWorkerPropertyChangeAdapter implements PropertyChange } - public void progress(PropertyChangeEvent evt) { + protected void progress(PropertyChangeEvent evt) { } - public void started(PropertyChangeEvent evt) { + protected void started(PropertyChangeEvent evt) { } - public void done(PropertyChangeEvent evt) { + protected void done(PropertyChangeEvent evt) { } }