* support for arguments
* better tempfile management * lots of refactoring
This commit is contained in:
parent
9a307588c8
commit
04c4baf9b9
|
@ -1,10 +1,20 @@
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import net.sourceforge.filebot.Settings;
|
||||
import net.sourceforge.filebot.ui.FileBotWindow;
|
||||
import net.sourceforge.tuned.MessageBus;
|
||||
|
||||
|
||||
public class Main {
|
||||
|
@ -14,18 +24,69 @@ public class Main {
|
|||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
final Arguments arguments = new Arguments(args);
|
||||
|
||||
if (arguments.containsParameter("clear")) {
|
||||
Settings.getSettings().clear();
|
||||
}
|
||||
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
} catch (Exception e) {
|
||||
// should not happen
|
||||
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString(), e);
|
||||
}
|
||||
|
||||
final FileBotWindow window = new FileBotWindow();
|
||||
|
||||
// publish messages from arguments to the newly created components
|
||||
arguments.publishMessages();
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
new FileBotWindow().setVisible(true);
|
||||
window.setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private static class Arguments {
|
||||
|
||||
private final Set<String> parameters = new HashSet<String>(3);
|
||||
private final Map<String, List<String>> messages = new LinkedHashMap<String, List<String>>();
|
||||
|
||||
|
||||
public Arguments(String[] args) {
|
||||
Pattern topicPattern = Pattern.compile("--(\\w+)");
|
||||
|
||||
String currentTopic = null;
|
||||
|
||||
for (String arg : args) {
|
||||
Matcher m = topicPattern.matcher(arg);
|
||||
|
||||
if (m.matches()) {
|
||||
currentTopic = m.group(1).toLowerCase();
|
||||
messages.put(currentTopic, new ArrayList<String>(1));
|
||||
} else if (currentTopic != null) {
|
||||
messages.get(currentTopic).add(arg);
|
||||
} else {
|
||||
parameters.add(arg.toLowerCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean containsParameter(String argument) {
|
||||
return parameters.contains(argument);
|
||||
}
|
||||
|
||||
|
||||
public void publishMessages() {
|
||||
for (String topic : messages.keySet()) {
|
||||
MessageBus.getDefault().publish(topic, messages.get(topic).toArray(new String[0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,11 +2,15 @@
|
|||
package net.sourceforge.filebot;
|
||||
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Point;
|
||||
import java.awt.Window;
|
||||
import java.util.Iterator;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
|
||||
|
@ -70,4 +74,17 @@ public class FileBotUtil {
|
|||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
public static Point getPreferredLocation(JDialog dialog) {
|
||||
Window owner = dialog.getOwner();
|
||||
|
||||
if (owner == null)
|
||||
return new Point(120, 80);
|
||||
|
||||
Point p = owner.getLocation();
|
||||
Dimension d = owner.getSize();
|
||||
|
||||
return new Point(p.x + d.width / 4, p.y + d.height / 7);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.text.NumberFormat;
|
|||
|
||||
public class FileFormat {
|
||||
|
||||
private static NumberFormat nf = NumberFormat.getNumberInstance();
|
||||
private static final NumberFormat numberFormat = NumberFormat.getNumberInstance();
|
||||
|
||||
public final static long KILO = 1024;
|
||||
|
||||
|
@ -17,17 +17,17 @@ public class FileFormat {
|
|||
public final static long GIGA = MEGA * 1024;
|
||||
|
||||
static {
|
||||
nf.setMaximumFractionDigits(0);
|
||||
numberFormat.setMaximumFractionDigits(0);
|
||||
}
|
||||
|
||||
|
||||
public static String formatSize(long size) {
|
||||
if (size >= MEGA)
|
||||
return nf.format((double) size / MEGA) + " MB";
|
||||
return numberFormat.format((double) size / MEGA) + " MB";
|
||||
else if (size >= KILO)
|
||||
return nf.format((double) size / KILO) + " KB";
|
||||
return numberFormat.format((double) size / KILO) + " KB";
|
||||
else
|
||||
return nf.format(size) + " Byte";
|
||||
return numberFormat.format(size) + " Byte";
|
||||
}
|
||||
|
||||
|
||||
|
@ -37,7 +37,7 @@ public class FileFormat {
|
|||
if (f.isDirectory())
|
||||
return name;
|
||||
|
||||
return getNameWithoutSuffix(name);
|
||||
return getNameWithoutExtension(name);
|
||||
}
|
||||
|
||||
|
||||
|
@ -49,16 +49,16 @@ public class FileFormat {
|
|||
}
|
||||
|
||||
|
||||
public static String getSuffix(File f) {
|
||||
return getSuffix(f, false);
|
||||
public static String getExtension(File f) {
|
||||
return getExtension(f, false);
|
||||
}
|
||||
|
||||
|
||||
public static String getSuffix(File f, boolean includeDot) {
|
||||
public static String getExtension(File f, boolean includeDot) {
|
||||
String name = f.getName();
|
||||
int dotIndex = name.lastIndexOf(".");
|
||||
|
||||
// .config -> no suffix
|
||||
// .config -> no extension
|
||||
if (dotIndex >= 1) {
|
||||
int startIndex = dotIndex;
|
||||
|
||||
|
@ -74,7 +74,7 @@ public class FileFormat {
|
|||
}
|
||||
|
||||
|
||||
public static String getNameWithoutSuffix(String name) {
|
||||
public static String getNameWithoutExtension(String name) {
|
||||
int dotIndex = name.lastIndexOf(".");
|
||||
|
||||
if (dotIndex < 1)
|
||||
|
@ -84,8 +84,8 @@ public class FileFormat {
|
|||
}
|
||||
|
||||
|
||||
public static String getNameWithoutSuffix(File file) {
|
||||
return getNameWithoutSuffix(file.getName());
|
||||
public static String getNameWithoutExtension(File file) {
|
||||
return getNameWithoutExtension(file.getName());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ public class Settings {
|
|||
|
||||
private static Settings settings = new Settings();
|
||||
|
||||
private static final String ROOT = "filebot";
|
||||
public static final String ROOT = "filebot";
|
||||
|
||||
public static final String SELECTED_PANEL = "panel";
|
||||
public static final String SEARCH_HISTORY = "history/search";
|
||||
|
|
|
@ -52,10 +52,10 @@ public class ResourceManager {
|
|||
|
||||
|
||||
public static ImageIcon getArchiveIcon(String type) {
|
||||
URL url = ResourceManager.class.getResource(String.format("archive/%s.png", type.toLowerCase()));
|
||||
URL url = ResourceManager.class.getResource(String.format("archives/%s.png", type.toLowerCase()));
|
||||
|
||||
if (url == null)
|
||||
url = ResourceManager.class.getResource(String.format("archive/default.png"));
|
||||
url = ResourceManager.class.getResource(String.format("archives/default.png"));
|
||||
|
||||
return new ImageIcon(url);
|
||||
}
|
||||
|
|
Before Width: | Height: | Size: 775 B After Width: | Height: | Size: 775 B |
|
@ -65,7 +65,7 @@ public class Torrent {
|
|||
Map<?, ?> fileMap = (Map<?, ?>) fileMapObject;
|
||||
List<?> pathList = (List<?>) fileMap.get("path");
|
||||
|
||||
StringBuffer pathBuffer = new StringBuffer();
|
||||
StringBuilder pathBuffer = new StringBuilder();
|
||||
String entryName = null;
|
||||
|
||||
Iterator<?> iterator = pathList.iterator();
|
||||
|
|
|
@ -3,20 +3,54 @@ package net.sourceforge.filebot.ui;
|
|||
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import net.sourceforge.filebot.ui.panel.analyze.AnalyzePanel;
|
||||
import net.sourceforge.filebot.ui.panel.list.ListPanel;
|
||||
import net.sourceforge.filebot.ui.panel.rename.RenamePanel;
|
||||
import net.sourceforge.filebot.ui.panel.search.SearchPanel;
|
||||
import net.sourceforge.filebot.ui.panel.sfv.SfvPanel;
|
||||
import net.sourceforge.filebot.ui.panel.subtitle.SubtitlePanel;
|
||||
|
||||
|
||||
public class FileBotPanel extends JPanel {
|
||||
|
||||
private String title;
|
||||
private Icon icon;
|
||||
private static final LinkedHashSet<FileBotPanel> registry = new LinkedHashSet<FileBotPanel>();
|
||||
|
||||
static {
|
||||
registry.add(new ListPanel());
|
||||
registry.add(new RenamePanel());
|
||||
registry.add(new AnalyzePanel());
|
||||
registry.add(new SearchPanel());
|
||||
registry.add(new SubtitlePanel());
|
||||
registry.add(new SfvPanel());
|
||||
}
|
||||
|
||||
|
||||
public static Iterable<FileBotPanel> getAvailablePanels() {
|
||||
return registry;
|
||||
}
|
||||
|
||||
|
||||
public static FileBotPanel forName(String name) {
|
||||
for (FileBotPanel panel : registry) {
|
||||
if (name.equalsIgnoreCase(panel.getPanelName()))
|
||||
return panel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private final String name;
|
||||
private final Icon icon;
|
||||
|
||||
|
||||
public FileBotPanel(String title, Icon icon) {
|
||||
super(new BorderLayout(10, 0));
|
||||
this.title = title;
|
||||
this.name = title;
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
|
@ -26,8 +60,7 @@ public class FileBotPanel extends JPanel {
|
|||
}
|
||||
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
public String getPanelName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,8 +11,6 @@ import java.awt.dnd.DropTargetDropEvent;
|
|||
import java.awt.dnd.DropTargetEvent;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JList;
|
||||
import javax.swing.ListSelectionModel;
|
||||
|
@ -21,12 +19,6 @@ import javax.swing.SwingUtilities;
|
|||
import javax.swing.Timer;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import net.sourceforge.filebot.ui.panel.analyze.AnalyzePanel;
|
||||
import net.sourceforge.filebot.ui.panel.list.ListPanel;
|
||||
import net.sourceforge.filebot.ui.panel.rename.RenamePanel;
|
||||
import net.sourceforge.filebot.ui.panel.search.SearchPanel;
|
||||
import net.sourceforge.filebot.ui.panel.sfv.SfvPanel;
|
||||
import net.sourceforge.filebot.ui.panel.subtitle.SubtitlePanel;
|
||||
import net.sourceforge.tuned.ui.FancyListCellRenderer;
|
||||
import net.sourceforge.tuned.ui.GradientStyle;
|
||||
import net.sourceforge.tuned.ui.SimpleListModel;
|
||||
|
@ -45,16 +37,13 @@ class FileBotPanelSelectionList extends JList {
|
|||
|
||||
new DropTarget(this, new DragDropListener());
|
||||
|
||||
List<FileBotPanel> panels = new ArrayList<FileBotPanel>();
|
||||
SimpleListModel model = new SimpleListModel();
|
||||
|
||||
panels.add(new ListPanel());
|
||||
panels.add(new RenamePanel());
|
||||
panels.add(new AnalyzePanel());
|
||||
panels.add(new SearchPanel());
|
||||
panels.add(new SubtitlePanel());
|
||||
panels.add(new SfvPanel());
|
||||
for (FileBotPanel panel : FileBotPanel.getAvailablePanels()) {
|
||||
model.add(panel);
|
||||
}
|
||||
|
||||
setModel(new SimpleListModel(panels));
|
||||
setModel(model);
|
||||
}
|
||||
|
||||
|
||||
|
@ -72,7 +61,7 @@ class FileBotPanelSelectionList extends JList {
|
|||
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
|
||||
FileBotPanel panel = (FileBotPanel) value;
|
||||
setText(panel.getTitle());
|
||||
setText(panel.getPanelName());
|
||||
setIcon(panel.getIcon());
|
||||
|
||||
return this;
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.awt.CardLayout;
|
|||
import java.awt.Image;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.JComponent;
|
||||
|
@ -14,7 +15,6 @@ import javax.swing.JFrame;
|
|||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.ListModel;
|
||||
import javax.swing.OverlayLayout;
|
||||
import javax.swing.ScrollPaneConstants;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
@ -24,7 +24,10 @@ import javax.swing.event.ListSelectionListener;
|
|||
import net.sourceforge.filebot.FileBotUtil;
|
||||
import net.sourceforge.filebot.Settings;
|
||||
import net.sourceforge.filebot.resources.ResourceManager;
|
||||
import net.sourceforge.tuned.MessageBus;
|
||||
import net.sourceforge.tuned.MessageHandler;
|
||||
import net.sourceforge.tuned.ui.ShadowBorder;
|
||||
import net.sourceforge.tuned.ui.SimpleListModel;
|
||||
|
||||
|
||||
public class FileBotWindow extends JFrame implements ListSelectionListener {
|
||||
|
@ -58,15 +61,17 @@ public class FileBotWindow extends JFrame implements ListSelectionListener {
|
|||
setSize(760, 615);
|
||||
|
||||
selectionListPanel.setSelectedIndex(Settings.getSettings().getInt(Settings.SELECTED_PANEL, 3));
|
||||
|
||||
MessageBus.getDefault().addMessageHandler("panel", panelMessageHandler);
|
||||
}
|
||||
|
||||
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
FileBotPanel currentPanel = (FileBotPanel) selectionListPanel.getSelectedValue();
|
||||
|
||||
headerPanel.setTitle(currentPanel.getTitle());
|
||||
headerPanel.setTitle(currentPanel.getPanelName());
|
||||
CardLayout cardLayout = (CardLayout) pagePanel.getLayout();
|
||||
cardLayout.show(pagePanel, currentPanel.getTitle());
|
||||
cardLayout.show(pagePanel, currentPanel.getPanelName());
|
||||
|
||||
JComponent c = (JComponent) getContentPane();
|
||||
|
||||
|
@ -101,6 +106,7 @@ public class FileBotWindow extends JFrame implements ListSelectionListener {
|
|||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private JComponent createPageLayer() {
|
||||
JPanel pageLayer = new JPanel(new BorderLayout());
|
||||
|
||||
|
@ -109,12 +115,11 @@ public class FileBotWindow extends JFrame implements ListSelectionListener {
|
|||
pageLayer.add(headerPanel, BorderLayout.NORTH);
|
||||
pageLayer.add(pagePanel, BorderLayout.CENTER);
|
||||
|
||||
ListModel model = selectionListPanel.getModel();
|
||||
SimpleListModel model = (SimpleListModel) selectionListPanel.getModel();
|
||||
|
||||
for (int i = 0; i < model.getSize(); i++) {
|
||||
FileBotPanel panel = (FileBotPanel) model.getElementAt(i);
|
||||
for (FileBotPanel panel : (List<FileBotPanel>) model.getCopy()) {
|
||||
panel.setVisible(false);
|
||||
pagePanel.add(panel, panel.getTitle());
|
||||
pagePanel.add(panel, panel.getPanelName());
|
||||
}
|
||||
|
||||
pageLayer.setAlignmentX(0.0f);
|
||||
|
@ -134,6 +139,17 @@ public class FileBotWindow extends JFrame implements ListSelectionListener {
|
|||
return contentPane;
|
||||
}
|
||||
|
||||
private final MessageHandler panelMessageHandler = new MessageHandler() {
|
||||
|
||||
@Override
|
||||
public void handle(String topic, String... messages) {
|
||||
for (String panel : messages) {
|
||||
selectionListPanel.setSelectedValue(FileBotPanel.forName(panel), true);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private final AbstractAction closeAction = new AbstractAction("Close") {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
@ -142,4 +158,5 @@ public class FileBotWindow extends JFrame implements ListSelectionListener {
|
|||
System.exit(0);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
package net.sourceforge.filebot.ui;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.sourceforge.filebot.ui.transfer.FileTransferable;
|
||||
import net.sourceforge.filebot.ui.transfer.TransferablePolicySupport;
|
||||
import net.sourceforge.tuned.MessageBus;
|
||||
import net.sourceforge.tuned.MessageHandler;
|
||||
|
||||
|
||||
public class FileTransferableMessageHandler implements MessageHandler {
|
||||
|
||||
private final String name;
|
||||
private final TransferablePolicySupport transferablePolicySupport;
|
||||
|
||||
|
||||
public FileTransferableMessageHandler(String name, TransferablePolicySupport transferablePolicySupport) {
|
||||
this.name = name;
|
||||
this.transferablePolicySupport = transferablePolicySupport;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handle(String topic, String... messages) {
|
||||
|
||||
MessageBus.getDefault().publish("panel", name);
|
||||
|
||||
List<File> files = new ArrayList<File>(messages.length);
|
||||
|
||||
for (String filename : messages) {
|
||||
File file = new File(filename);
|
||||
|
||||
if (file.exists()) {
|
||||
files.add(file);
|
||||
} else {
|
||||
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.WARNING, String.format("Invalid File: %s", filename));
|
||||
}
|
||||
}
|
||||
|
||||
transferablePolicySupport.getTransferablePolicy().handleTransferable(new FileTransferable(files), true);
|
||||
}
|
||||
}
|
|
@ -1,11 +1,10 @@
|
|||
|
||||
package net.sourceforge.tuned.ui;
|
||||
package net.sourceforge.filebot.ui;
|
||||
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Point;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
|
@ -26,6 +25,11 @@ import javax.swing.KeyStroke;
|
|||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import net.sourceforge.filebot.FileBotUtil;
|
||||
import net.sourceforge.filebot.resources.ResourceManager;
|
||||
import net.sourceforge.tuned.ui.FancyListCellRenderer;
|
||||
import net.sourceforge.tuned.ui.SimpleListModel;
|
||||
|
||||
|
||||
public class SelectDialog<T> extends JDialog {
|
||||
|
||||
|
@ -72,7 +76,7 @@ public class SelectDialog<T> extends JDialog {
|
|||
// bounds and location
|
||||
setMinimumSize(new Dimension(175, 175));
|
||||
setSize(new Dimension(200, 190));
|
||||
setLocation(getDefaultLocation());
|
||||
setLocation(FileBotUtil.getPreferredLocation(this));
|
||||
|
||||
// default selection
|
||||
list.setModel(new SimpleListModel(options));
|
||||
|
@ -90,16 +94,6 @@ public class SelectDialog<T> extends JDialog {
|
|||
}
|
||||
|
||||
|
||||
public Point getDefaultLocation() {
|
||||
Point p = getOwner().getLocation();
|
||||
Dimension d = getOwner().getSize();
|
||||
|
||||
Point offset = new Point(d.width / 4, d.height / 7);
|
||||
|
||||
return new Point(p.x + offset.x, p.y + offset.y);
|
||||
}
|
||||
|
||||
|
||||
public void setText(String s) {
|
||||
label.setText(s);
|
||||
}
|
||||
|
@ -115,7 +109,7 @@ public class SelectDialog<T> extends JDialog {
|
|||
list.setSelectedValue(value, true);
|
||||
}
|
||||
|
||||
private AbstractAction selectAction = new AbstractAction("Select") {
|
||||
private AbstractAction selectAction = new AbstractAction("Select", ResourceManager.getIcon("dialog.continue")) {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
@ -125,7 +119,7 @@ public class SelectDialog<T> extends JDialog {
|
|||
}
|
||||
};
|
||||
|
||||
private AbstractAction cancelAction = new AbstractAction("Cancel") {
|
||||
private AbstractAction cancelAction = new AbstractAction("Cancel", ResourceManager.getIcon("dialog.cancel")) {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
selectedValue = null;
|
|
@ -19,15 +19,19 @@ import javax.swing.SwingConstants;
|
|||
|
||||
import net.sourceforge.filebot.resources.ResourceManager;
|
||||
import net.sourceforge.filebot.ui.FileBotPanel;
|
||||
import net.sourceforge.filebot.ui.FileTransferableMessageHandler;
|
||||
import net.sourceforge.filebot.ui.panel.analyze.tools.SplitPanel;
|
||||
import net.sourceforge.filebot.ui.panel.analyze.tools.ToolPanel;
|
||||
import net.sourceforge.filebot.ui.panel.analyze.tools.TypePanel;
|
||||
import net.sourceforge.tuned.MessageBus;
|
||||
|
||||
|
||||
public class AnalyzePanel extends FileBotPanel {
|
||||
|
||||
private FileTreePanel filePanel = new FileTreePanel();
|
||||
private JTabbedPane toolsPanel = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
|
||||
private final FileTreePanel fileTreePanel = new FileTreePanel();
|
||||
private final JTabbedPane toolsPanel = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
|
||||
|
||||
private final List<ToolPanel> toolPanels = new ArrayList<ToolPanel>();
|
||||
|
||||
|
||||
public AnalyzePanel() {
|
||||
|
@ -35,7 +39,7 @@ public class AnalyzePanel extends FileBotPanel {
|
|||
|
||||
Box panel = new Box(BoxLayout.X_AXIS);
|
||||
|
||||
panel.add(filePanel);
|
||||
panel.add(fileTreePanel);
|
||||
|
||||
panel.add(Box.createHorizontalStrut(50));
|
||||
|
||||
|
@ -49,14 +53,22 @@ public class AnalyzePanel extends FileBotPanel {
|
|||
|
||||
add(panel, BorderLayout.CENTER);
|
||||
|
||||
filePanel.getFileTree().addPropertyChangeListener(FileTree.CONTENT_PROPERTY, fileTreeChangeListener);
|
||||
|
||||
addTool(new TypePanel());
|
||||
addTool(new SplitPanel());
|
||||
|
||||
Dimension min = new Dimension(300, 300);
|
||||
filePanel.setMinimumSize(min);
|
||||
fileTreePanel.setMinimumSize(min);
|
||||
toolsPanel.setMinimumSize(min);
|
||||
|
||||
addTool(new SplitPanel());
|
||||
addTool(new TypePanel());
|
||||
|
||||
fileTreePanel.getFileTree().addPropertyChangeListener(FileTree.CONTENT_PROPERTY, fileTreeChangeListener);
|
||||
|
||||
MessageBus.getDefault().addMessageHandler(getPanelName(), new FileTransferableMessageHandler(getPanelName(), fileTreePanel.getFileTree()));
|
||||
}
|
||||
|
||||
|
||||
private void addTool(ToolPanel toolPanel) {
|
||||
toolsPanel.addTab(toolPanel.getToolName(), toolPanel);
|
||||
toolPanels.add(toolPanel);
|
||||
}
|
||||
|
||||
private PropertyChangeListener fileTreeChangeListener = new PropertyChangeListener() {
|
||||
|
@ -65,17 +77,10 @@ public class AnalyzePanel extends FileBotPanel {
|
|||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
List<File> files = (List<File>) evt.getNewValue();
|
||||
|
||||
for (ToolPanel toolPanel : toolPanels)
|
||||
for (ToolPanel toolPanel : toolPanels) {
|
||||
toolPanel.update(files);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private List<ToolPanel> toolPanels = new ArrayList<ToolPanel>();
|
||||
|
||||
|
||||
public void addTool(ToolPanel toolPanel) {
|
||||
toolsPanel.addTab(toolPanel.getName(), toolPanel);
|
||||
toolPanels.add(toolPanel);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@ package net.sourceforge.filebot.ui.panel.analyze;
|
|||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.BorderFactory;
|
||||
|
@ -19,24 +17,19 @@ import javax.swing.border.EmptyBorder;
|
|||
import net.sourceforge.filebot.FileBotUtil;
|
||||
import net.sourceforge.filebot.resources.ResourceManager;
|
||||
import net.sourceforge.filebot.ui.transfer.LoadAction;
|
||||
import net.sourceforge.tuned.ui.LoadingOverlayPanel;
|
||||
import net.sourceforge.tuned.ui.LoadingOverlayPane;
|
||||
|
||||
|
||||
class FileTreePanel extends JPanel {
|
||||
|
||||
private FileTree fileTree = new FileTree();
|
||||
|
||||
private LoadingOverlayPanel loadingOverlay;
|
||||
|
||||
|
||||
public FileTreePanel() {
|
||||
super(new BorderLayout());
|
||||
fileTree.addPropertyChangeListener(FileTree.LOADING_PROPERTY, loadingOverlayUpdateListener);
|
||||
|
||||
setBorder(BorderFactory.createTitledBorder("File Tree"));
|
||||
|
||||
loadingOverlay = new LoadingOverlayPanel(new JScrollPane(fileTree), ResourceManager.getIcon("loading"));
|
||||
|
||||
Box buttons = Box.createHorizontalBox();
|
||||
buttons.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
buttons.add(Box.createGlue());
|
||||
|
@ -48,21 +41,11 @@ class FileTreePanel extends JPanel {
|
|||
// Shortcut DELETE
|
||||
FileBotUtil.registerActionForKeystroke(fileTree, KeyStroke.getKeyStroke("pressed DELETE"), removeAction);
|
||||
|
||||
add(loadingOverlay, BorderLayout.CENTER);
|
||||
add(new LoadingOverlayPane(new JScrollPane(fileTree), ResourceManager.getIcon("loading")), BorderLayout.CENTER);
|
||||
add(buttons, BorderLayout.SOUTH);
|
||||
}
|
||||
|
||||
private PropertyChangeListener loadingOverlayUpdateListener = new PropertyChangeListener() {
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
Boolean loading = (Boolean) evt.getNewValue();
|
||||
|
||||
loadingOverlay.setOverlayVisible(loading);
|
||||
loadingOverlay.updateOverlay();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
public FileTree getFileTree() {
|
||||
return fileTree;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ import net.sourceforge.filebot.resources.ResourceManager;
|
|||
import net.sourceforge.filebot.ui.FileBotTree;
|
||||
import net.sourceforge.filebot.ui.transfer.DefaultTransferHandler;
|
||||
import net.sourceforge.tuned.ui.GradientStyle;
|
||||
import net.sourceforge.tuned.ui.LoadingOverlayPanel;
|
||||
import net.sourceforge.tuned.ui.LoadingOverlayPane;
|
||||
import net.sourceforge.tuned.ui.notification.SeparatorBorder;
|
||||
|
||||
|
||||
|
@ -46,7 +46,6 @@ public class SplitPanel extends ToolPanel implements ChangeListener {
|
|||
|
||||
JScrollPane sp = new JScrollPane(tree);
|
||||
sp.setBorder(BorderFactory.createEmptyBorder());
|
||||
LoadingOverlayPanel loadingOverlay = new LoadingOverlayPanel(sp, ResourceManager.getIcon("loading"));
|
||||
JSpinner spinner = new JSpinner(spinnerModel);
|
||||
spinner.setMaximumSize(spinner.getPreferredSize());
|
||||
spinner.setEditor(new JSpinner.NumberEditor(spinner, "#"));
|
||||
|
@ -60,7 +59,7 @@ public class SplitPanel extends ToolPanel implements ChangeListener {
|
|||
spinnerBox.add(new JLabel("MB."));
|
||||
spinnerBox.add(Box.createGlue());
|
||||
|
||||
add(loadingOverlay, BorderLayout.CENTER);
|
||||
add(new LoadingOverlayPane(sp, ResourceManager.getIcon("loading")), BorderLayout.CENTER);
|
||||
add(spinnerBox, BorderLayout.SOUTH);
|
||||
|
||||
tree.setTransferHandler(new DefaultTransferHandler(null, new FileTreeExportHandler()));
|
||||
|
@ -70,7 +69,6 @@ public class SplitPanel extends ToolPanel implements ChangeListener {
|
|||
SeparatorBorder separatorBorder = new SeparatorBorder(2, beginColor, GradientStyle.TOP_TO_BOTTOM, SeparatorBorder.Position.TOP);
|
||||
spinnerBox.setBorder(new CompoundBorder(separatorBorder, new EmptyBorder(6, 5, 7, 5)));
|
||||
|
||||
setLoadingOverlayPane(loadingOverlay);
|
||||
spinnerModel.addChangeListener(this);
|
||||
spinner.setPreferredSize(new Dimension(80, 20));
|
||||
}
|
||||
|
@ -103,7 +101,7 @@ public class SplitPanel extends ToolPanel implements ChangeListener {
|
|||
|
||||
private void update() {
|
||||
latestUpdateTask = new UpdateTask();
|
||||
firePropertyChange(LOADING_PROPERTY, null, true);
|
||||
tree.firePropertyChange(LoadingOverlayPane.LOADING_PROPERTY, false, true);
|
||||
latestUpdateTask.execute();
|
||||
}
|
||||
|
||||
|
@ -185,7 +183,7 @@ public class SplitPanel extends ToolPanel implements ChangeListener {
|
|||
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString(), e);
|
||||
}
|
||||
|
||||
SplitPanel.this.firePropertyChange(LOADING_PROPERTY, null, false);
|
||||
tree.firePropertyChange(LoadingOverlayPane.LOADING_PROPERTY, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,54 +2,26 @@
|
|||
package net.sourceforge.filebot.ui.panel.analyze.tools;
|
||||
|
||||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import net.sourceforge.tuned.ui.LoadingOverlayPanel;
|
||||
|
||||
|
||||
public abstract class ToolPanel extends JComponent {
|
||||
|
||||
private String name = null;
|
||||
|
||||
private LoadingOverlayPanel loadingOverlay;
|
||||
|
||||
public static final String LOADING_PROPERTY = "loading";
|
||||
private final String name;
|
||||
|
||||
|
||||
public ToolPanel(String name) {
|
||||
this.name = name;
|
||||
addPropertyChangeListener(LOADING_PROPERTY, loadingOverlayUpdateListener);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
public String getToolName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
protected void setLoadingOverlayPane(LoadingOverlayPanel c) {
|
||||
loadingOverlay = c;
|
||||
}
|
||||
|
||||
private PropertyChangeListener loadingOverlayUpdateListener = new PropertyChangeListener() {
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
Boolean loading = (Boolean) evt.getNewValue();
|
||||
|
||||
if (loadingOverlay == null)
|
||||
return;
|
||||
|
||||
loadingOverlay.setOverlayVisible(loading);
|
||||
loadingOverlay.updateOverlay();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public abstract void update(Collection<File> list);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import net.sourceforge.filebot.FileFormat;
|
|||
import net.sourceforge.filebot.resources.ResourceManager;
|
||||
import net.sourceforge.filebot.ui.FileBotTree;
|
||||
import net.sourceforge.filebot.ui.transfer.DefaultTransferHandler;
|
||||
import net.sourceforge.tuned.ui.LoadingOverlayPanel;
|
||||
import net.sourceforge.tuned.ui.LoadingOverlayPane;
|
||||
|
||||
|
||||
public class TypePanel extends ToolPanel {
|
||||
|
@ -36,13 +36,10 @@ public class TypePanel extends ToolPanel {
|
|||
|
||||
JScrollPane sp = new JScrollPane(tree);
|
||||
sp.setBorder(BorderFactory.createEmptyBorder());
|
||||
LoadingOverlayPanel loadingOverlay = new LoadingOverlayPanel(sp, ResourceManager.getIcon("loading"));
|
||||
add(loadingOverlay, BorderLayout.CENTER);
|
||||
add(new LoadingOverlayPane(sp, ResourceManager.getIcon("loading")), BorderLayout.CENTER);
|
||||
|
||||
tree.setTransferHandler(new DefaultTransferHandler(null, new FileTreeExportHandler()));
|
||||
tree.setDragEnabled(true);
|
||||
|
||||
setLoadingOverlayPane(loadingOverlay);
|
||||
}
|
||||
|
||||
private UpdateTask latestUpdateTask;
|
||||
|
@ -52,7 +49,7 @@ public class TypePanel extends ToolPanel {
|
|||
public void update(Collection<File> files) {
|
||||
latestUpdateTask = new UpdateTask(files);
|
||||
|
||||
firePropertyChange(LOADING_PROPERTY, null, true);
|
||||
tree.firePropertyChange(LoadingOverlayPane.LOADING_PROPERTY, false, true);
|
||||
latestUpdateTask.execute();
|
||||
}
|
||||
|
||||
|
@ -80,16 +77,16 @@ public class TypePanel extends ToolPanel {
|
|||
Map<String, Collection<File>> map = new HashMap<String, Collection<File>>();
|
||||
|
||||
for (File f : files) {
|
||||
String suffix = FileFormat.getSuffix(f);
|
||||
String extension = FileFormat.getExtension(f);
|
||||
|
||||
Collection<File> list = map.get(suffix);
|
||||
Collection<File> list = map.get(extension);
|
||||
|
||||
if (list != null)
|
||||
list.add(f);
|
||||
else {
|
||||
list = new ArrayList<File>();
|
||||
list.add(f);
|
||||
map.put(suffix, list);
|
||||
map.put(extension, list);
|
||||
}
|
||||
|
||||
if (!isLatest())
|
||||
|
@ -135,7 +132,7 @@ public class TypePanel extends ToolPanel {
|
|||
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString(), e);
|
||||
}
|
||||
|
||||
TypePanel.this.firePropertyChange(LOADING_PROPERTY, null, false);
|
||||
tree.firePropertyChange(LoadingOverlayPane.LOADING_PROPERTY, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ class FileListTransferablePolicy extends FileTransferablePolicy {
|
|||
|
||||
@Override
|
||||
protected boolean accept(File file) {
|
||||
return file.isDirectory() || FileFormat.getSuffix(file).equalsIgnoreCase("torrent");
|
||||
return file.isDirectory() || FileFormat.getExtension(file).equalsIgnoreCase("torrent");
|
||||
}
|
||||
|
||||
|
||||
|
@ -44,13 +44,13 @@ class FileListTransferablePolicy extends FileTransferablePolicy {
|
|||
list.getModel().add(FileFormat.formatName(f));
|
||||
}
|
||||
} else {
|
||||
if (FileFormat.getSuffix(file).equalsIgnoreCase("torrent")) {
|
||||
if (FileFormat.getExtension(file).equalsIgnoreCase("torrent")) {
|
||||
try {
|
||||
Torrent torrent = new Torrent(file);
|
||||
list.setTitle(FileFormat.getNameWithoutSuffix(torrent.getName()));
|
||||
list.setTitle(FileFormat.getNameWithoutExtension(torrent.getName()));
|
||||
|
||||
for (Torrent.Entry entry : torrent.getFiles()) {
|
||||
list.getModel().add(FileFormat.getNameWithoutSuffix(entry.getName()));
|
||||
list.getModel().add(FileFormat.getNameWithoutExtension(entry.getName()));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// should not happen
|
||||
|
|
|
@ -26,8 +26,10 @@ import net.sourceforge.filebot.resources.ResourceManager;
|
|||
import net.sourceforge.filebot.ui.FileBotList;
|
||||
import net.sourceforge.filebot.ui.FileBotPanel;
|
||||
import net.sourceforge.filebot.ui.MessageManager;
|
||||
import net.sourceforge.filebot.ui.FileTransferableMessageHandler;
|
||||
import net.sourceforge.filebot.ui.transfer.LoadAction;
|
||||
import net.sourceforge.filebot.ui.transfer.SaveAction;
|
||||
import net.sourceforge.tuned.MessageBus;
|
||||
|
||||
|
||||
public class ListPanel extends FileBotPanel {
|
||||
|
@ -87,6 +89,8 @@ public class ListPanel extends FileBotPanel {
|
|||
add(list, BorderLayout.CENTER);
|
||||
|
||||
FileBotUtil.registerActionForKeystroke(this, KeyStroke.getKeyStroke("ENTER"), createAction);
|
||||
|
||||
MessageBus.getDefault().addMessageHandler(getPanelName(), new FileTransferableMessageHandler(getPanelName(), list));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -45,11 +45,13 @@ class NamesListTransferablePolicy extends MultiTransferablePolicy {
|
|||
invalidEntries.add(entry);
|
||||
}
|
||||
|
||||
ValidateNamesDialog dialog = new ValidateNamesDialog(SwingUtilities.getWindowAncestor(list), invalidEntries);
|
||||
dialog.setVisible(true);
|
||||
|
||||
if (dialog.isCancelled())
|
||||
return;
|
||||
if (!invalidEntries.isEmpty()) {
|
||||
ValidateNamesDialog dialog = new ValidateNamesDialog(SwingUtilities.getWindowAncestor(list), invalidEntries);
|
||||
dialog.setVisible(true);
|
||||
|
||||
if (dialog.isCancelled())
|
||||
return;
|
||||
}
|
||||
|
||||
list.getModel().addAll(entries);
|
||||
}
|
||||
|
@ -77,7 +79,7 @@ class NamesListTransferablePolicy extends MultiTransferablePolicy {
|
|||
try {
|
||||
List<ListEntry<?>> entries = new ArrayList<ListEntry<?>>();
|
||||
|
||||
if (FileFormat.getSuffix(file).equalsIgnoreCase("torrent")) {
|
||||
if (FileFormat.getExtension(file).equalsIgnoreCase("torrent")) {
|
||||
Torrent torrent = new Torrent(file);
|
||||
|
||||
for (Torrent.Entry entry : torrent.getFiles()) {
|
||||
|
|
|
@ -45,7 +45,7 @@ public class RenameAction extends AbstractAction {
|
|||
FileEntry fileEntry = fileEntries.get(i);
|
||||
File f = fileEntry.getValue();
|
||||
|
||||
String newName = nameEntries.get(i).toString() + FileFormat.getSuffix(f, true);
|
||||
String newName = nameEntries.get(i).toString() + FileFormat.getExtension(f, true);
|
||||
|
||||
File newFile = new File(f.getParentFile(), newName);
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@ import javax.swing.event.ListDataListener;
|
|||
|
||||
import net.sourceforge.filebot.resources.ResourceManager;
|
||||
import net.sourceforge.filebot.ui.FileBotPanel;
|
||||
import net.sourceforge.filebot.ui.FileTransferableMessageHandler;
|
||||
import net.sourceforge.tuned.MessageBus;
|
||||
|
||||
|
||||
public class RenamePanel extends FileBotPanel {
|
||||
|
@ -80,6 +82,8 @@ public class RenamePanel extends FileBotPanel {
|
|||
|
||||
namesList.getModel().addListDataListener(repaintOnDataChange);
|
||||
filesList.getModel().addListDataListener(repaintOnDataChange);
|
||||
|
||||
MessageBus.getDefault().addMessageHandler(getPanelName(), new FileTransferableMessageHandler(getPanelName(), namesList));
|
||||
}
|
||||
|
||||
|
||||
|
@ -117,16 +121,16 @@ public class RenamePanel extends FileBotPanel {
|
|||
|
||||
|
||||
public void intervalAdded(ListDataEvent e) {
|
||||
update();
|
||||
repaintBoth();
|
||||
}
|
||||
|
||||
|
||||
public void intervalRemoved(ListDataEvent e) {
|
||||
update();
|
||||
repaintBoth();
|
||||
}
|
||||
|
||||
|
||||
public void update() {
|
||||
public void repaintBoth() {
|
||||
namesList.repaint();
|
||||
filesList.repaint();
|
||||
}
|
||||
|
|
|
@ -5,10 +5,8 @@ package net.sourceforge.filebot.ui.panel.rename;
|
|||
import java.awt.AlphaComposite;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.util.List;
|
||||
|
@ -84,7 +82,7 @@ public class ValidateNamesDialog extends JDialog {
|
|||
c.add(listPanel, BorderLayout.CENTER);
|
||||
c.add(buttonBox, BorderLayout.SOUTH);
|
||||
|
||||
setLocation(getDefaultLocation());
|
||||
setLocation(FileBotUtil.getPreferredLocation(this));
|
||||
|
||||
// Shortcut Escape
|
||||
FileBotUtil.registerActionForKeystroke(c, KeyStroke.getKeyStroke("released ESCAPE"), cancelAction);
|
||||
|
@ -93,16 +91,6 @@ public class ValidateNamesDialog extends JDialog {
|
|||
}
|
||||
|
||||
|
||||
public Point getDefaultLocation() {
|
||||
Point p = getOwner().getLocation();
|
||||
Dimension d = getOwner().getSize();
|
||||
|
||||
Point offset = new Point(d.width / 4, d.height / 7);
|
||||
|
||||
return new Point(p.x + offset.x, p.y + offset.y);
|
||||
}
|
||||
|
||||
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
@ -119,7 +107,7 @@ public class ValidateNamesDialog extends JDialog {
|
|||
private class ValidateAction extends AbstractAction {
|
||||
|
||||
public ValidateAction() {
|
||||
super("Validate", ResourceManager.getIcon("dialog.continue.valid"));
|
||||
super("Validate", ResourceManager.getIcon("dialog.continue"));
|
||||
putValue(SHORT_DESCRIPTION, "Remove invalid characters");
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ public class FileEntry extends AbstractFileEntry<File> {
|
|||
|
||||
@Override
|
||||
public String getName(File value) {
|
||||
return FileFormat.getNameWithoutSuffix(getValue());
|
||||
return FileFormat.getNameWithoutExtension(getValue());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ public class TorrentEntry extends AbstractFileEntry<Torrent.Entry> {
|
|||
|
||||
@Override
|
||||
public String getName(Torrent.Entry value) {
|
||||
return FileFormat.getNameWithoutSuffix(getValue().getName());
|
||||
return FileFormat.getNameWithoutExtension(getValue().getName());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -10,7 +10,8 @@ import net.sourceforge.filebot.ui.FileBotList;
|
|||
|
||||
class EpisodeListPanel extends FileBotList {
|
||||
|
||||
private TabComponentWithClose tabComponent;
|
||||
private final TabComponentWithClose tabComponent = new TabComponentWithClose();
|
||||
|
||||
private ImageIcon icon;
|
||||
|
||||
private boolean loading = false;
|
||||
|
@ -18,7 +19,6 @@ class EpisodeListPanel extends FileBotList {
|
|||
|
||||
public EpisodeListPanel() {
|
||||
super(false, true, true, false);
|
||||
tabComponent = new TabComponentWithClose();
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,10 +35,12 @@ class EpisodeListPanel extends FileBotList {
|
|||
|
||||
|
||||
public void setIcon(ImageIcon icon) {
|
||||
this.icon = icon;
|
||||
|
||||
if (!loading) {
|
||||
tabComponent.setIcon(icon);
|
||||
synchronized (tabComponent) {
|
||||
this.icon = icon;
|
||||
|
||||
if (!loading) {
|
||||
tabComponent.setIcon(icon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,10 +51,12 @@ class EpisodeListPanel extends FileBotList {
|
|||
|
||||
|
||||
public void setLoading(boolean loading) {
|
||||
if (loading) {
|
||||
tabComponent.setIcon(ResourceManager.getIcon("tab.loading"));
|
||||
} else {
|
||||
tabComponent.setIcon(icon);
|
||||
synchronized (tabComponent) {
|
||||
if (loading) {
|
||||
tabComponent.setIcon(ResourceManager.getIcon("tab.loading"));
|
||||
} else {
|
||||
tabComponent.setIcon(icon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,14 +34,14 @@ import javax.swing.border.EmptyBorder;
|
|||
import net.sourceforge.filebot.FileBotUtil;
|
||||
import net.sourceforge.filebot.Settings;
|
||||
import net.sourceforge.filebot.resources.ResourceManager;
|
||||
import net.sourceforge.filebot.ui.FileBotList;
|
||||
import net.sourceforge.filebot.ui.FileBotPanel;
|
||||
import net.sourceforge.filebot.ui.MessageManager;
|
||||
import net.sourceforge.filebot.ui.SelectDialog;
|
||||
import net.sourceforge.filebot.ui.transfer.SaveAction;
|
||||
import net.sourceforge.filebot.ui.transfer.Saveable;
|
||||
import net.sourceforge.filebot.web.Episode;
|
||||
import net.sourceforge.filebot.web.EpisodeListClient;
|
||||
import net.sourceforge.tuned.ui.SelectButton;
|
||||
import net.sourceforge.tuned.ui.SelectDialog;
|
||||
import net.sourceforge.tuned.ui.SwingWorkerPropertyChangeAdapter;
|
||||
import net.sourceforge.tuned.ui.TextCompletion;
|
||||
import net.sourceforge.tuned.ui.TextFieldWithSelect;
|
||||
|
@ -176,15 +176,15 @@ public class SearchPanel extends FileBotPanel {
|
|||
|
||||
private final SaveAction saveAction = new SaveAction(null) {
|
||||
|
||||
private FileBotList current;
|
||||
private Saveable current;
|
||||
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Component c = tabbedPane.getSelectedComponent();
|
||||
|
||||
if (c instanceof FileBotList) {
|
||||
current = (FileBotList) c;
|
||||
if (c instanceof Saveable) {
|
||||
current = (Saveable) c;
|
||||
super.actionPerformed(e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,9 +21,11 @@ import net.sourceforge.filebot.FileBotUtil;
|
|||
import net.sourceforge.filebot.FileFormat;
|
||||
import net.sourceforge.filebot.resources.ResourceManager;
|
||||
import net.sourceforge.filebot.ui.FileBotPanel;
|
||||
import net.sourceforge.filebot.ui.FileTransferableMessageHandler;
|
||||
import net.sourceforge.filebot.ui.SelectDialog;
|
||||
import net.sourceforge.filebot.ui.transfer.LoadAction;
|
||||
import net.sourceforge.filebot.ui.transfer.SaveAction;
|
||||
import net.sourceforge.tuned.ui.SelectDialog;
|
||||
import net.sourceforge.tuned.MessageBus;
|
||||
|
||||
|
||||
public class SfvPanel extends FileBotPanel {
|
||||
|
@ -60,6 +62,8 @@ public class SfvPanel extends FileBotPanel {
|
|||
|
||||
// Shortcut DELETE
|
||||
FileBotUtil.registerActionForKeystroke(this, KeyStroke.getKeyStroke("pressed DELETE"), removeAction);
|
||||
|
||||
MessageBus.getDefault().addMessageHandler(getPanelName(), new FileTransferableMessageHandler(getPanelName(), sfvTable));
|
||||
}
|
||||
|
||||
private final SaveAction saveAction = new SaveAction(sfvTable) {
|
||||
|
@ -114,7 +118,7 @@ public class SfvPanel extends FileBotPanel {
|
|||
return;
|
||||
|
||||
index = options.indexOf(selected);
|
||||
name = FileFormat.getNameWithoutSuffix(selected);
|
||||
name = FileFormat.getNameWithoutExtension(selected);
|
||||
|
||||
if (name.isEmpty())
|
||||
name = "name";
|
||||
|
|
|
@ -122,7 +122,7 @@ class SfvTable extends JTable implements TransferablePolicySupport, Saveable {
|
|||
String name = "";
|
||||
|
||||
if (columnRoot != null)
|
||||
name = FileFormat.getNameWithoutSuffix(columnRoot);
|
||||
name = FileFormat.getNameWithoutExtension(columnRoot);
|
||||
|
||||
if (name.isEmpty())
|
||||
name = "name";
|
||||
|
|
|
@ -91,7 +91,7 @@ class SfvTransferablePolicy extends BackgroundFileTransferablePolicy<SfvTableMod
|
|||
|
||||
private boolean isSfvFileList(List<File> files) {
|
||||
for (File file : files) {
|
||||
if (!FileFormat.getSuffix(file).equalsIgnoreCase("sfv"))
|
||||
if (!FileFormat.getExtension(file).equalsIgnoreCase("sfv"))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,20 +34,20 @@ public class DefaultClipboardHandler implements ClipboardHandler {
|
|||
JTable table = (JTable) comp;
|
||||
|
||||
for (int row : table.getSelectedRows()) {
|
||||
StringBuffer b = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int maxCol = table.getColumnCount() - 1;
|
||||
for (int col = 0; col <= maxCol; col++) {
|
||||
b.append(table.getModel().getValueAt(row, col));
|
||||
sb.append(table.getModel().getValueAt(row, col));
|
||||
|
||||
if (col != maxCol)
|
||||
b.append("\t");
|
||||
sb.append("\t");
|
||||
}
|
||||
|
||||
lines.add(b.toString());
|
||||
lines.add(sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
Iterator<String> it = lines.iterator();
|
||||
|
||||
while (it.hasNext()) {
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.awt.datatransfer.Transferable;
|
|||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
@ -29,21 +30,18 @@ public class FileTransferable implements Transferable {
|
|||
return null;
|
||||
}
|
||||
|
||||
private List<File> files;
|
||||
private final List<File> files;
|
||||
|
||||
private DataFlavor[] supportedFlavors = { DataFlavor.javaFileListFlavor, uriListFlavor };
|
||||
private final DataFlavor[] supportedFlavors = { DataFlavor.javaFileListFlavor, uriListFlavor };
|
||||
|
||||
|
||||
public FileTransferable(File... fileArray) {
|
||||
files = new ArrayList<File>(fileArray.length);
|
||||
|
||||
for (File file : fileArray)
|
||||
files.add(file);
|
||||
public FileTransferable(File... files) {
|
||||
this(Arrays.asList(files));
|
||||
}
|
||||
|
||||
|
||||
public FileTransferable(Collection<File> fileCollection) {
|
||||
files = new ArrayList<File>(fileCollection);
|
||||
public FileTransferable(Collection<File> files) {
|
||||
this.files = new ArrayList<File>(files);
|
||||
}
|
||||
|
||||
|
||||
|
@ -62,7 +60,7 @@ public class FileTransferable implements Transferable {
|
|||
* @return line separated list of file uris
|
||||
*/
|
||||
private String getUriList() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (File file : files) {
|
||||
sb.append("file://" + file.toURI().getPath());
|
||||
|
|
|
@ -2,11 +2,9 @@
|
|||
package net.sourceforge.filebot.ui.transfer;
|
||||
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
@ -14,13 +12,13 @@ import javax.swing.JComponent;
|
|||
import javax.swing.TransferHandler;
|
||||
|
||||
import net.sourceforge.filebot.FileBotUtil;
|
||||
import net.sourceforge.filebot.Settings;
|
||||
import net.sourceforge.tuned.TemporaryFolder;
|
||||
|
||||
|
||||
public class SaveableExportHandler implements ExportHandler {
|
||||
|
||||
private Saveable saveable;
|
||||
|
||||
private String tmpdir = System.getProperty("java.io.tmpdir");
|
||||
private final Saveable saveable;
|
||||
|
||||
|
||||
public SaveableExportHandler(Saveable saveable) {
|
||||
|
@ -28,23 +26,6 @@ public class SaveableExportHandler implements ExportHandler {
|
|||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void exportDone(JComponent source, Transferable data, int action) {
|
||||
try {
|
||||
List<File> files = (List<File>) data.getTransferData(DataFlavor.javaFileListFlavor);
|
||||
|
||||
for (File file : files) {
|
||||
if (file.exists())
|
||||
file.deleteOnExit();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// should not happen
|
||||
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {
|
||||
if ((saveable == null) || !saveable.isSaveable())
|
||||
|
@ -57,10 +38,12 @@ public class SaveableExportHandler implements ExportHandler {
|
|||
@Override
|
||||
public Transferable createTransferable(JComponent c) {
|
||||
try {
|
||||
File temporaryFile = new File(tmpdir, FileBotUtil.validateFileName(saveable.getDefaultFileName()));
|
||||
temporaryFile.createNewFile();
|
||||
// Remove invalid characters from default filename
|
||||
String name = FileBotUtil.validateFileName(saveable.getDefaultFileName());
|
||||
|
||||
File temporaryFile = TemporaryFolder.getFolder(Settings.ROOT).createFile(name);
|
||||
saveable.save(temporaryFile);
|
||||
|
||||
return new FileTransferable(temporaryFile);
|
||||
} catch (IOException e) {
|
||||
// should not happen
|
||||
|
@ -69,4 +52,10 @@ public class SaveableExportHandler implements ExportHandler {
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void exportDone(JComponent source, Transferable data, int action) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ public abstract class FileTransferablePolicy implements TransferablePolicy {
|
|||
public void handleTransferable(Transferable tr, boolean add) {
|
||||
List<File> files = getFilesFromTransferable(tr);
|
||||
|
||||
if (files == null)
|
||||
if ((files == null) || files.isEmpty())
|
||||
return;
|
||||
|
||||
Collections.sort(files);
|
||||
|
|
|
@ -40,13 +40,14 @@ public class MultiTransferablePolicy implements TransferablePolicy {
|
|||
public void handleTransferable(Transferable tr, boolean add) {
|
||||
TransferablePolicy policy = getFirstAccepted(tr);
|
||||
|
||||
if (policy != null) {
|
||||
if (!add)
|
||||
clear();
|
||||
|
||||
policy.handleTransferable(tr, add);
|
||||
if (policy == null)
|
||||
return;
|
||||
|
||||
if (!add) {
|
||||
clear();
|
||||
}
|
||||
|
||||
policy.handleTransferable(tr, add);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -18,6 +18,9 @@ public abstract class TextTransferablePolicy implements TransferablePolicy {
|
|||
|
||||
@Override
|
||||
public void handleTransferable(Transferable tr, boolean add) {
|
||||
if (!accept(tr))
|
||||
return;
|
||||
|
||||
try {
|
||||
String string = (String) tr.getTransferData(DataFlavor.stringFlavor);
|
||||
|
||||
|
|
|
@ -27,7 +27,10 @@ public class DownloadTask extends SwingWorker<ByteBuffer, Object> {
|
|||
|
||||
|
||||
public static enum DownloadState {
|
||||
PENDING, CONNECTING, DOWNLOADING, DONE;
|
||||
PENDING,
|
||||
CONNECTING,
|
||||
DOWNLOADING,
|
||||
DONE;
|
||||
}
|
||||
|
||||
private static final int BUFFER_SIZE = 4 * 1024;
|
||||
|
@ -132,7 +135,7 @@ public class DownloadTask extends SwingWorker<ByteBuffer, Object> {
|
|||
|
||||
|
||||
private static ByteBuffer encodeParameters(Map<String, String> parameters) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
int i = 0;
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ public class Episode {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append(showName + " - ");
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ import javax.swing.ImageIcon;
|
|||
|
||||
public abstract class EpisodeListClient {
|
||||
|
||||
private static LinkedHashSet<EpisodeListClient> registry = new LinkedHashSet<EpisodeListClient>();
|
||||
private static final LinkedHashSet<EpisodeListClient> registry = new LinkedHashSet<EpisodeListClient>();
|
||||
|
||||
static {
|
||||
registry.add(new TvdotcomClient());
|
||||
|
@ -27,7 +27,7 @@ public abstract class EpisodeListClient {
|
|||
|
||||
public static EpisodeListClient forName(String name) {
|
||||
for (EpisodeListClient client : registry) {
|
||||
if (name.equals(client.getName()))
|
||||
if (name.equalsIgnoreCase(client.getName()))
|
||||
return client;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
|
||||
package net.sourceforge.tuned;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
|
||||
public class MessageBus {
|
||||
|
||||
private static final MessageBus instance = new MessageBus();
|
||||
|
||||
|
||||
public static MessageBus getDefault() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
private MessageBus() {
|
||||
|
||||
}
|
||||
|
||||
private final Map<String, List<MessageHandler>> handlers = new HashMap<String, List<MessageHandler>>() {
|
||||
|
||||
@Override
|
||||
public List<MessageHandler> get(Object key) {
|
||||
return super.get(key.toString().toLowerCase());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<MessageHandler> put(String key, List<MessageHandler> value) {
|
||||
return super.put(key.toLowerCase(), value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public synchronized void addMessageHandler(String topic, MessageHandler handler) {
|
||||
List<MessageHandler> list = handlers.get(topic);
|
||||
|
||||
if (list == null) {
|
||||
list = new ArrayList<MessageHandler>(3);
|
||||
handlers.put(topic, list);
|
||||
}
|
||||
|
||||
list.add(handler);
|
||||
}
|
||||
|
||||
|
||||
public synchronized void removeMessageHandler(String topic, MessageHandler handler) {
|
||||
List<MessageHandler> list = handlers.get(topic);
|
||||
|
||||
if (list != null) {
|
||||
list.remove(handler);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public synchronized MessageHandler[] getHandlers(String topic) {
|
||||
List<MessageHandler> list = handlers.get(topic);
|
||||
|
||||
if (list == null)
|
||||
return new MessageHandler[0];
|
||||
|
||||
return list.toArray(new MessageHandler[0]);
|
||||
}
|
||||
|
||||
|
||||
public void publish(final String topic, final String... messages) {
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (MessageHandler handler : getHandlers(topic)) {
|
||||
handler.handle(topic, messages);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
package net.sourceforge.tuned;
|
||||
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
|
||||
public interface MessageHandler extends EventListener {
|
||||
|
||||
public void handle(String topic, String... messages);
|
||||
|
||||
}
|
|
@ -22,6 +22,7 @@ public class PausableThreadPoolExecutor extends ThreadPoolExecutor {
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void beforeExecute(Thread t, Runnable r) {
|
||||
super.beforeExecute(t, r);
|
||||
pauseLock.lock();
|
||||
|
@ -56,8 +57,8 @@ public class PausableThreadPoolExecutor extends ThreadPoolExecutor {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean isPaused() {
|
||||
return paused;
|
||||
|
||||
public boolean isPaused() {
|
||||
return paused;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
|
||||
package net.sourceforge.tuned;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class TemporaryFolder {
|
||||
|
||||
private static final String tmpdir = System.getProperty("java.io.tmpdir");
|
||||
|
||||
private static final Map<String, TemporaryFolder> folders = new HashMap<String, TemporaryFolder>();
|
||||
|
||||
|
||||
public static TemporaryFolder getFolder(String name) {
|
||||
synchronized (folders) {
|
||||
TemporaryFolder folder = folders.get(name);
|
||||
|
||||
if (folder == null) {
|
||||
folder = new TemporaryFolder(new File(tmpdir, name));
|
||||
folders.put(name, folder);
|
||||
}
|
||||
|
||||
return folder;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all temporary folders on shutdown
|
||||
*/
|
||||
static {
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (folders) {
|
||||
for (TemporaryFolder folder : folders.values()) {
|
||||
folder.delete();
|
||||
}
|
||||
|
||||
folders.clear();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private final File root;
|
||||
|
||||
|
||||
private TemporaryFolder(File root) {
|
||||
this.root = root;
|
||||
this.root.mkdir();
|
||||
}
|
||||
|
||||
|
||||
public File createFile(String name) throws IOException {
|
||||
File file = new File(root, name);
|
||||
file.createNewFile();
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
public void deleteFile(String name) {
|
||||
File file = new File(root, name);
|
||||
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void delete() {
|
||||
delete(root);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete files/folders recursively
|
||||
*
|
||||
* @param file file/folder that will be deleted
|
||||
*/
|
||||
private void delete(File file) {
|
||||
if (file.isDirectory()) {
|
||||
for (File entry : file.listFiles()) {
|
||||
delete(entry);
|
||||
}
|
||||
}
|
||||
|
||||
file.delete();
|
||||
}
|
||||
|
||||
}
|
|
@ -25,13 +25,13 @@ public class TimeIntervalFormat {
|
|||
negativ = true;
|
||||
}
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (long unitBaseTime : unitMap.descendingKeySet()) {
|
||||
int quotient = (int) (millis / unitBaseTime);
|
||||
|
||||
boolean isLastKey = (unitBaseTime == unitMap.firstKey());
|
||||
|
||||
if (zerounits || quotient != 0 || isLastKey) {
|
||||
if (zerounits || (quotient != 0) || isLastKey) {
|
||||
sb.append(quotient + unitMap.get(unitBaseTime));
|
||||
|
||||
if (!isLastKey)
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
|
||||
package net.sourceforge.tuned.ui;
|
||||
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.OverlayLayout;
|
||||
import javax.swing.Timer;
|
||||
|
||||
|
||||
public class LoadingOverlayPane extends JComponent {
|
||||
|
||||
public static final String LOADING_PROPERTY = "loading";
|
||||
|
||||
private final JLabel loadingLabel;
|
||||
|
||||
private boolean overlayEnabled = false;
|
||||
|
||||
private int millisToOverlay = 500;
|
||||
|
||||
private final JComponent view;
|
||||
|
||||
|
||||
public LoadingOverlayPane(JComponent component, Icon animation) {
|
||||
this(component, animation, getView(component));
|
||||
}
|
||||
|
||||
|
||||
public LoadingOverlayPane(JComponent component, Icon animation, JComponent view) {
|
||||
this.view = view;
|
||||
|
||||
setLayout(new OverlayLayout(this));
|
||||
|
||||
component.setAlignmentX(1.0f);
|
||||
component.setAlignmentY(0.0f);
|
||||
|
||||
loadingLabel = new JLabel(animation);
|
||||
loadingLabel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 20));
|
||||
|
||||
loadingLabel.setAlignmentX(1.0f);
|
||||
loadingLabel.setAlignmentY(0.0f);
|
||||
loadingLabel.setMaximumSize(loadingLabel.getPreferredSize());
|
||||
|
||||
add(loadingLabel);
|
||||
add(component);
|
||||
|
||||
setOverlayVisible(false);
|
||||
|
||||
view.addPropertyChangeListener(LOADING_PROPERTY, loadingListener);
|
||||
}
|
||||
|
||||
|
||||
private static JComponent getView(JComponent component) {
|
||||
if (component instanceof JScrollPane) {
|
||||
JScrollPane scrollPane = (JScrollPane) component;
|
||||
return (JComponent) scrollPane.getViewport().getView();
|
||||
}
|
||||
|
||||
return component;
|
||||
}
|
||||
|
||||
|
||||
public JComponent getView() {
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
public void setOverlayVisible(boolean b) {
|
||||
overlayEnabled = b;
|
||||
|
||||
if (overlayEnabled) {
|
||||
new OverlayTimer().start();
|
||||
} else {
|
||||
loadingLabel.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class OverlayTimer extends Timer implements ActionListener {
|
||||
|
||||
public OverlayTimer() {
|
||||
super(millisToOverlay, null);
|
||||
addActionListener(this);
|
||||
setRepeats(false);
|
||||
}
|
||||
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (overlayEnabled) {
|
||||
loadingLabel.setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final PropertyChangeListener loadingListener = new PropertyChangeListener() {
|
||||
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
Boolean loading = (Boolean) evt.getNewValue();
|
||||
|
||||
setOverlayVisible(loading);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
|
||||
package net.sourceforge.tuned.ui;
|
||||
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.OverlayLayout;
|
||||
import javax.swing.Timer;
|
||||
|
||||
|
||||
public class LoadingOverlayPanel extends JPanel {
|
||||
|
||||
private JLabel loadingLabel = new JLabel();
|
||||
|
||||
private boolean overlayEnabled = false;
|
||||
|
||||
private int millisToOverlay = 500;
|
||||
|
||||
|
||||
public LoadingOverlayPanel(JComponent component, Icon animation) {
|
||||
setLayout(new OverlayLayout(this));
|
||||
|
||||
component.setAlignmentX(1.0f);
|
||||
component.setAlignmentY(0.0f);
|
||||
|
||||
loadingLabel.setIcon(animation);
|
||||
loadingLabel.setOpaque(false);
|
||||
loadingLabel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 20));
|
||||
|
||||
loadingLabel.setAlignmentX(1.0f);
|
||||
loadingLabel.setAlignmentY(0.0f);
|
||||
loadingLabel.setMaximumSize(loadingLabel.getPreferredSize());
|
||||
|
||||
add(loadingLabel);
|
||||
add(component);
|
||||
|
||||
setOverlayVisible(false);
|
||||
}
|
||||
|
||||
|
||||
public void setMillisToOverlay(int millisToOverlay) {
|
||||
this.millisToOverlay = millisToOverlay;
|
||||
}
|
||||
|
||||
|
||||
public int getMillisToOverlay() {
|
||||
return millisToOverlay;
|
||||
}
|
||||
|
||||
|
||||
public void setOverlayVisible(boolean b) {
|
||||
overlayEnabled = b;
|
||||
|
||||
if (overlayEnabled) {
|
||||
new EnableOverlayTimer().start();
|
||||
} else {
|
||||
loadingLabel.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class EnableOverlayTimer extends Timer implements ActionListener {
|
||||
|
||||
public EnableOverlayTimer() {
|
||||
super(millisToOverlay, null);
|
||||
addActionListener(this);
|
||||
setRepeats(false);
|
||||
}
|
||||
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (overlayEnabled) {
|
||||
loadingLabel.setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void updateOverlay() {
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
}
|
|
@ -12,7 +12,7 @@ import javax.swing.AbstractListModel;
|
|||
|
||||
public class SimpleListModel extends AbstractListModel {
|
||||
|
||||
private List<Object> list;
|
||||
private final List<Object> list;
|
||||
|
||||
|
||||
public SimpleListModel() {
|
||||
|
|
Loading…
Reference in New Issue