* refactoring ...
* changed cmd line args (single panel frame) * simplified multi panel frame * changed window icon * create panels via PanelBuilder
This commit is contained in:
parent
bfe459b50c
commit
9ed970de05
|
@ -106,8 +106,7 @@
|
|||
<!-- copy resources -->
|
||||
<copy todir="${dir.build}">
|
||||
<fileset dir="${dir.source}">
|
||||
<include name="**/*.png" />
|
||||
<include name="**/*.xml" />
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
|
|
|
@ -2,18 +2,16 @@
|
|||
package net.sourceforge.filebot;
|
||||
|
||||
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.reflect.Field;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.sourceforge.tuned.MessageBus;
|
||||
import net.sourceforge.filebot.ui.transfer.FileTransferable;
|
||||
|
||||
import org.kohsuke.args4j.Argument;
|
||||
import org.kohsuke.args4j.Option;
|
||||
|
||||
|
||||
|
@ -25,71 +23,59 @@ public class ArgumentBean {
|
|||
@Option(name = "-clear", usage = "Clear history and settings")
|
||||
private boolean clear = false;
|
||||
|
||||
@Message(topic = "list")
|
||||
@Option(name = "--list", usage = "Open file in 'List' panel", metaVar = "<file>")
|
||||
private File listPanelFile;
|
||||
|
||||
@Message(topic = "analyze")
|
||||
@Option(name = "--analyze", usage = "Open file in 'Analyze' panel", metaVar = "<file>")
|
||||
private File analyzePanelFile;
|
||||
private boolean analyze;
|
||||
|
||||
@Message(topic = "sfv")
|
||||
@Option(name = "--sfv", usage = "Open file in 'SFV' panel", metaVar = "<file>")
|
||||
private File sfvPanelFile;
|
||||
private boolean sfv;
|
||||
|
||||
@Argument
|
||||
private List<File> arguments;
|
||||
|
||||
|
||||
public boolean isHelp() {
|
||||
public boolean help() {
|
||||
return help;
|
||||
}
|
||||
|
||||
|
||||
public boolean isClear() {
|
||||
public boolean clear() {
|
||||
return clear;
|
||||
}
|
||||
|
||||
|
||||
public File getListPanelFile() {
|
||||
return listPanelFile;
|
||||
public boolean sfv() {
|
||||
return sfv;
|
||||
}
|
||||
|
||||
|
||||
public File getAnalyzePanelFile() {
|
||||
return analyzePanelFile;
|
||||
public boolean analyze() {
|
||||
return analyze;
|
||||
}
|
||||
|
||||
|
||||
public File getSfvPanelFile() {
|
||||
return sfvPanelFile;
|
||||
public List<File> arguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
|
||||
public void publishMessages() {
|
||||
for (Field field : getClass().getDeclaredFields()) {
|
||||
|
||||
Message message = field.getAnnotation(Message.class);
|
||||
|
||||
if (message == null)
|
||||
continue;
|
||||
|
||||
try {
|
||||
Object value = field.get(this);
|
||||
|
||||
if (value != null) {
|
||||
MessageBus.getDefault().publish(message.topic(), value);
|
||||
public FileTransferable transferable() {
|
||||
List<File> files = new ArrayList<File>(arguments.size());
|
||||
|
||||
for (File argument : arguments) {
|
||||
if (argument.exists()) {
|
||||
try {
|
||||
// path may be relative, use absolute path
|
||||
files.add(argument.getCanonicalFile());
|
||||
} catch (IOException e) {
|
||||
Logger.getLogger("global").log(Level.SEVERE, e.toString(), e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// should not happen
|
||||
Logger.getLogger("global").log(Level.SEVERE, e.toString(), e);
|
||||
} else {
|
||||
// file doesn't exist
|
||||
Logger.getLogger("global").log(Level.WARNING, String.format("Invalid File: %s", argument));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target(FIELD)
|
||||
private @interface Message {
|
||||
|
||||
String topic();
|
||||
return new FileTransferable(files);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,16 +2,21 @@
|
|||
package net.sourceforge.filebot;
|
||||
|
||||
|
||||
import static javax.swing.JFrame.*;
|
||||
|
||||
import java.util.logging.ConsoleHandler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import net.sourceforge.filebot.ui.FileBotWindow;
|
||||
import net.sourceforge.filebot.ui.MainFrame;
|
||||
import net.sourceforge.filebot.ui.NotificationLoggingHandler;
|
||||
|
||||
import net.sourceforge.filebot.ui.SinglePanelFrame;
|
||||
import net.sourceforge.filebot.ui.panel.analyze.AnalyzePanelBuilder;
|
||||
import net.sourceforge.filebot.ui.panel.sfv.SfvPanelBuilder;
|
||||
import org.kohsuke.args4j.CmdLineException;
|
||||
import org.kohsuke.args4j.CmdLineParser;
|
||||
|
||||
|
@ -25,14 +30,14 @@ public class Main {
|
|||
|
||||
final ArgumentBean argumentBean = initializeArgumentBean(args);
|
||||
|
||||
if (argumentBean.isHelp()) {
|
||||
if (argumentBean.help()) {
|
||||
printUsage(argumentBean);
|
||||
|
||||
// just print help message and exit afterwards
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
if (argumentBean.isClear()) {
|
||||
if (argumentBean.clear()) {
|
||||
// clear preferences
|
||||
Settings.userRoot().clear();
|
||||
}
|
||||
|
@ -56,13 +61,22 @@ public class Main {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
FileBotWindow window = new FileBotWindow();
|
||||
JFrame frame;
|
||||
|
||||
// publish messages from arguments to the newly created components
|
||||
argumentBean.publishMessages();
|
||||
if (argumentBean.analyze()) {
|
||||
frame = new SinglePanelFrame(new AnalyzePanelBuilder()).publish(argumentBean.transferable());
|
||||
} else if (argumentBean.sfv()) {
|
||||
frame = new SinglePanelFrame(new SfvPanelBuilder()).publish(argumentBean.transferable());
|
||||
} else {
|
||||
// default
|
||||
frame = new MainFrame();
|
||||
}
|
||||
|
||||
frame.setLocationByPlatform(true);
|
||||
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
|
||||
// start
|
||||
window.setVisible(true);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 2.3 KiB |
Binary file not shown.
Before Width: | Height: | Size: 768 B After Width: | Height: | Size: 854 B |
|
@ -36,7 +36,7 @@ import ca.odell.glazedlists.matchers.TextMatcherEditor;
|
|||
import ca.odell.glazedlists.swing.AutoCompleteSupport;
|
||||
|
||||
|
||||
public abstract class AbstractSearchPanel<S, E> extends FileBotPanel {
|
||||
public abstract class AbstractSearchPanel<S, E> extends JComponent {
|
||||
|
||||
protected final JPanel tabbedPaneGroup = new JPanel(new MigLayout("nogrid, fill, insets 0", "align center", "[fill]8px[pref!]4px"));
|
||||
|
||||
|
@ -49,8 +49,7 @@ public abstract class AbstractSearchPanel<S, E> extends FileBotPanel {
|
|||
protected final EventList<String> searchHistory = createSearchHistory();
|
||||
|
||||
|
||||
public AbstractSearchPanel(String title, Icon icon) {
|
||||
super(title, icon);
|
||||
public AbstractSearchPanel() {
|
||||
|
||||
historyPanel.setColumnHeader(2, "Duration");
|
||||
|
||||
|
|
|
@ -91,7 +91,6 @@ public class EpisodeFormatDialog extends JDialog {
|
|||
JLabel title = new JLabel(this.getTitle());
|
||||
title.setFont(title.getFont().deriveFont(BOLD));
|
||||
|
||||
// status.setVisible(false);
|
||||
JPanel header = new JPanel(new MigLayout("insets dialog, nogrid, fillx"));
|
||||
|
||||
header.setBackground(Color.white);
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
|
||||
package net.sourceforge.filebot.ui;
|
||||
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import net.sourceforge.tuned.MessageHandler;
|
||||
|
||||
|
||||
public class FileBotPanel extends JComponent {
|
||||
|
||||
private final String name;
|
||||
private final Icon icon;
|
||||
|
||||
|
||||
public FileBotPanel(String title, Icon icon) {
|
||||
this.name = title;
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
|
||||
public Icon getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
|
||||
public String getPanelName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public MessageHandler getMessageHandler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getPanelName();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,128 +0,0 @@
|
|||
|
||||
package net.sourceforge.filebot.ui;
|
||||
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.dnd.DropTarget;
|
||||
import java.awt.dnd.DropTargetAdapter;
|
||||
import java.awt.dnd.DropTargetDragEvent;
|
||||
import java.awt.dnd.DropTargetDropEvent;
|
||||
import java.awt.dnd.DropTargetEvent;
|
||||
|
||||
import javax.swing.JList;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.Timer;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import net.sourceforge.tuned.ui.DefaultFancyListCellRenderer;
|
||||
import net.sourceforge.tuned.ui.TunedUtilities;
|
||||
import ca.odell.glazedlists.BasicEventList;
|
||||
import ca.odell.glazedlists.EventList;
|
||||
import ca.odell.glazedlists.swing.EventListModel;
|
||||
|
||||
|
||||
class FileBotPanelSelectionList extends JList {
|
||||
|
||||
private static final int SELECTDELAY_ON_DRAG_OVER = 300;
|
||||
|
||||
private final EventList<FileBotPanel> panelModel = new BasicEventList<FileBotPanel>();
|
||||
|
||||
|
||||
public FileBotPanelSelectionList() {
|
||||
|
||||
setModel(new EventListModel<FileBotPanel>(panelModel));
|
||||
|
||||
setCellRenderer(new PanelCellRenderer());
|
||||
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
|
||||
setBorder(new EmptyBorder(4, 5, 4, 5));
|
||||
|
||||
// initialize "drag over" panel selection
|
||||
new DropTarget(this, new DragDropListener());
|
||||
}
|
||||
|
||||
|
||||
public EventList<FileBotPanel> getPanelModel() {
|
||||
return panelModel;
|
||||
}
|
||||
|
||||
|
||||
private static class PanelCellRenderer extends DefaultFancyListCellRenderer {
|
||||
|
||||
public PanelCellRenderer() {
|
||||
super(10, 0, new Color(0x163264));
|
||||
|
||||
// center labels in list
|
||||
setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
|
||||
|
||||
setHighlightingEnabled(false);
|
||||
|
||||
setVerticalTextPosition(SwingConstants.BOTTOM);
|
||||
setHorizontalTextPosition(SwingConstants.CENTER);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void configureListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||
super.configureListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
|
||||
FileBotPanel panel = (FileBotPanel) value;
|
||||
setText(panel.getPanelName());
|
||||
setIcon(panel.getIcon());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private class DragDropListener extends DropTargetAdapter {
|
||||
|
||||
private boolean selectEnabled = false;
|
||||
|
||||
private Timer dragEnterTimer;
|
||||
|
||||
|
||||
@Override
|
||||
public void dragOver(DropTargetDragEvent dtde) {
|
||||
if (selectEnabled) {
|
||||
int index = locationToIndex(dtde.getLocation());
|
||||
setSelectedIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void dragEnter(DropTargetDragEvent dtde) {
|
||||
dragEnterTimer = TunedUtilities.invokeLater(SELECTDELAY_ON_DRAG_OVER, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
selectEnabled = true;
|
||||
|
||||
// bring window to front when on dnd
|
||||
SwingUtilities.getWindowAncestor(FileBotPanelSelectionList.this).toFront();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void dragExit(DropTargetEvent dte) {
|
||||
selectEnabled = false;
|
||||
|
||||
if (dragEnterTimer != null) {
|
||||
dragEnterTimer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drop(DropTargetDropEvent dtde) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,178 +0,0 @@
|
|||
|
||||
package net.sourceforge.filebot.ui;
|
||||
|
||||
|
||||
import static net.sourceforge.filebot.Settings.getApplicationName;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.CardLayout;
|
||||
import java.awt.Image;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.OverlayLayout;
|
||||
import javax.swing.ScrollPaneConstants;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import net.sourceforge.filebot.ResourceManager;
|
||||
import net.sourceforge.filebot.Settings;
|
||||
import net.sourceforge.filebot.ui.panel.analyze.AnalyzePanel;
|
||||
import net.sourceforge.filebot.ui.panel.episodelist.EpisodeListPanel;
|
||||
import net.sourceforge.filebot.ui.panel.list.ListPanel;
|
||||
import net.sourceforge.filebot.ui.panel.rename.RenamePanel;
|
||||
import net.sourceforge.filebot.ui.panel.sfv.ChecksumPanel;
|
||||
import net.sourceforge.filebot.ui.panel.subtitle.SubtitlePanel;
|
||||
import net.sourceforge.tuned.MessageBus;
|
||||
import net.sourceforge.tuned.MessageHandler;
|
||||
import net.sourceforge.tuned.ui.ShadowBorder;
|
||||
|
||||
|
||||
public class FileBotWindow extends JFrame implements ListSelectionListener {
|
||||
|
||||
private JPanel pagePanel = new JPanel(new CardLayout());
|
||||
|
||||
private FileBotPanelSelectionList panelSelectionList = new FileBotPanelSelectionList();
|
||||
|
||||
private HeaderPanel headerPanel = new HeaderPanel();
|
||||
|
||||
|
||||
public FileBotWindow() {
|
||||
super(getApplicationName());
|
||||
|
||||
setLocationByPlatform(true);
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
|
||||
// set taskbar / taskswitch icons
|
||||
ArrayList<Image> icons = new ArrayList<Image>(2);
|
||||
icons.add(ResourceManager.getImage("window.icon.small"));
|
||||
icons.add(ResourceManager.getImage("window.icon.big"));
|
||||
setIconImages(icons);
|
||||
|
||||
panelSelectionList.getPanelModel().addAll(createPanels());
|
||||
panelSelectionList.addListSelectionListener(this);
|
||||
|
||||
JComponent contentPane = createContentPane();
|
||||
|
||||
setContentPane(contentPane);
|
||||
|
||||
setSize(760, 615);
|
||||
|
||||
//TODO restore the panel selection from last time,
|
||||
// switch to EpisodeListPanel by default (e.g. first start)
|
||||
// int selectedPanel = asStringList(panelSelectionList.getPanelModel()).indexOf(Settings.userRoot().get("selectedPanel"));
|
||||
// panelSelectionList.setSelectedIndex(selectedPanel);
|
||||
|
||||
// connect message handlers to message bus
|
||||
MessageBus.getDefault().addMessageHandler("panel", panelSelectMessageHandler);
|
||||
|
||||
for (FileBotPanel panel : panelSelectionList.getPanelModel()) {
|
||||
MessageBus.getDefault().addMessageHandler(panel.getPanelName(), panel.getMessageHandler());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private List<FileBotPanel> createPanels() {
|
||||
List<FileBotPanel> panels = new ArrayList<FileBotPanel>(6);
|
||||
|
||||
panels.add(new ListPanel());
|
||||
panels.add(new RenamePanel());
|
||||
panels.add(new AnalyzePanel());
|
||||
panels.add(new EpisodeListPanel());
|
||||
panels.add(new SubtitlePanel());
|
||||
panels.add(new ChecksumPanel());
|
||||
|
||||
return panels;
|
||||
}
|
||||
|
||||
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
FileBotPanel currentPanel = (FileBotPanel) panelSelectionList.getSelectedValue();
|
||||
|
||||
headerPanel.setTitle(currentPanel.getPanelName());
|
||||
CardLayout cardLayout = (CardLayout) pagePanel.getLayout();
|
||||
cardLayout.show(pagePanel, currentPanel.getPanelName());
|
||||
|
||||
JComponent c = (JComponent) getContentPane();
|
||||
|
||||
c.revalidate();
|
||||
c.repaint();
|
||||
|
||||
Settings.userRoot().put("selectedPanel", panelSelectionList.getSelectedValue().toString());
|
||||
}
|
||||
|
||||
|
||||
private JComponent createSelectionListLayer() {
|
||||
JPanel selectionListLayer = new JPanel(new BorderLayout());
|
||||
selectionListLayer.setOpaque(false);
|
||||
|
||||
JPanel shadowBorderPanel = new JPanel(new BorderLayout());
|
||||
shadowBorderPanel.setOpaque(false);
|
||||
|
||||
JScrollPane selectListScrollPane = new JScrollPane(panelSelectionList);
|
||||
selectListScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
selectListScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
|
||||
shadowBorderPanel.add(selectListScrollPane, BorderLayout.CENTER);
|
||||
shadowBorderPanel.setBorder(new ShadowBorder());
|
||||
|
||||
selectionListLayer.setBorder(new EmptyBorder(10, 6, 12, 0));
|
||||
selectionListLayer.add(shadowBorderPanel, BorderLayout.WEST);
|
||||
|
||||
selectionListLayer.setAlignmentX(0.0f);
|
||||
selectionListLayer.setAlignmentY(0.0f);
|
||||
selectionListLayer.setMaximumSize(selectionListLayer.getPreferredSize());
|
||||
|
||||
return selectionListLayer;
|
||||
}
|
||||
|
||||
|
||||
private JComponent createPageLayer() {
|
||||
JPanel pageLayer = new JPanel(new BorderLayout());
|
||||
pagePanel.setBorder(new EmptyBorder(0, 95, 0, 0));
|
||||
|
||||
pageLayer.add(headerPanel, BorderLayout.NORTH);
|
||||
pageLayer.add(pagePanel, BorderLayout.CENTER);
|
||||
|
||||
for (FileBotPanel panel : panelSelectionList.getPanelModel()) {
|
||||
pagePanel.add(panel, panel.getPanelName());
|
||||
}
|
||||
|
||||
pageLayer.setAlignmentX(0.0f);
|
||||
pageLayer.setAlignmentY(0.0f);
|
||||
|
||||
return pageLayer;
|
||||
}
|
||||
|
||||
|
||||
private JComponent createContentPane() {
|
||||
JPanel contentPane = new JPanel(null);
|
||||
contentPane.setLayout(new OverlayLayout(contentPane));
|
||||
|
||||
contentPane.add(createSelectionListLayer());
|
||||
contentPane.add(createPageLayer());
|
||||
|
||||
return contentPane;
|
||||
}
|
||||
|
||||
private final MessageHandler panelSelectMessageHandler = new MessageHandler() {
|
||||
|
||||
@Override
|
||||
public void handle(String topic, Object... messages) {
|
||||
if (messages.length >= 1) {
|
||||
// get last element in array
|
||||
Object panel = messages[messages.length - 1];
|
||||
|
||||
// switch to this panel
|
||||
if (panel instanceof FileBotPanel)
|
||||
panelSelectionList.setSelectedValue(panel, true);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
|
||||
package net.sourceforge.filebot.ui;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
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.TransferablePolicy;
|
||||
import net.sourceforge.filebot.ui.transfer.TransferablePolicy.TransferAction;
|
||||
import net.sourceforge.tuned.MessageBus;
|
||||
import net.sourceforge.tuned.MessageHandler;
|
||||
|
||||
|
||||
public class FileTransferableMessageHandler implements MessageHandler {
|
||||
|
||||
private final FileBotPanel panel;
|
||||
private final TransferablePolicy transferablePolicy;
|
||||
|
||||
|
||||
public FileTransferableMessageHandler(FileBotPanel panel, TransferablePolicy transferablePolicy) {
|
||||
this.panel = panel;
|
||||
this.transferablePolicy = transferablePolicy;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handle(String topic, Object... messages) throws Exception {
|
||||
// switch to panel
|
||||
MessageBus.getDefault().publish("panel", panel);
|
||||
|
||||
List<File> files = new ArrayList<File>(messages.length);
|
||||
|
||||
for (Object message : messages) {
|
||||
File file = fromMessage(message);
|
||||
|
||||
if (file == null)
|
||||
continue;
|
||||
|
||||
if (file.exists()) {
|
||||
try {
|
||||
// path may be relative, use absolute path
|
||||
files.add(file.getCanonicalFile());
|
||||
} catch (IOException e) {
|
||||
Logger.getLogger("global").log(Level.SEVERE, e.toString(), e);
|
||||
}
|
||||
} else {
|
||||
// file doesn't exist
|
||||
Logger.getLogger("global").log(Level.WARNING, "Invalid File: " + file);
|
||||
}
|
||||
}
|
||||
|
||||
transferablePolicy.handleTransferable(new FileTransferable(files), TransferAction.PUT);
|
||||
}
|
||||
|
||||
|
||||
private File fromMessage(Object message) {
|
||||
|
||||
if (message instanceof File)
|
||||
return (File) message;
|
||||
|
||||
if (message instanceof String)
|
||||
return new File((String) message);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -42,9 +42,6 @@ class HeaderPanel extends JComponent {
|
|||
titleLabel.setForeground(new Color(0x101010));
|
||||
titleLabel.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 24));
|
||||
|
||||
int margin = 9;
|
||||
titleLabel.setBorder(new EmptyBorder(margin - 1, 90, margin + 1, 0));
|
||||
|
||||
JLabel decorationLabel = new JLabel(ResourceManager.getIcon("decoration.header"));
|
||||
decorationLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
decorationLabel.setVerticalAlignment(SwingConstants.CENTER);
|
||||
|
@ -64,6 +61,11 @@ class HeaderPanel extends JComponent {
|
|||
}
|
||||
|
||||
|
||||
public JLabel getTitleLabel() {
|
||||
return titleLabel;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
|
|
|
@ -0,0 +1,234 @@
|
|||
|
||||
package net.sourceforge.filebot.ui;
|
||||
|
||||
|
||||
import static javax.swing.ScrollPaneConstants.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.dnd.DropTarget;
|
||||
import java.awt.dnd.DropTargetAdapter;
|
||||
import java.awt.dnd.DropTargetDragEvent;
|
||||
import java.awt.dnd.DropTargetDropEvent;
|
||||
import java.awt.dnd.DropTargetEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.Timer;
|
||||
import javax.swing.border.CompoundBorder;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import net.sourceforge.filebot.ResourceManager;
|
||||
import net.sourceforge.filebot.Settings;
|
||||
import net.sourceforge.filebot.ui.panel.analyze.AnalyzePanelBuilder;
|
||||
import net.sourceforge.filebot.ui.panel.episodelist.EpisodeListPanelBuilder;
|
||||
import net.sourceforge.filebot.ui.panel.list.ListPanelBuilder;
|
||||
import net.sourceforge.filebot.ui.panel.rename.RenamePanelBuilder;
|
||||
import net.sourceforge.filebot.ui.panel.sfv.SfvPanelBuilder;
|
||||
import net.sourceforge.tuned.PreferencesMap.PreferencesEntry;
|
||||
import net.sourceforge.tuned.ui.ArrayListModel;
|
||||
import net.sourceforge.tuned.ui.DefaultFancyListCellRenderer;
|
||||
import net.sourceforge.tuned.ui.ShadowBorder;
|
||||
import net.sourceforge.tuned.ui.TunedUtilities;
|
||||
|
||||
|
||||
public class MainFrame extends JFrame {
|
||||
|
||||
private JList selectionList = new PanelSelectionList();
|
||||
|
||||
private HeaderPanel headerPanel = new HeaderPanel();
|
||||
|
||||
private final PreferencesEntry<String> persistentSelectedPanel = Settings.userRoot().entry("selectedPanel");
|
||||
|
||||
|
||||
public MainFrame() {
|
||||
super(Settings.getApplicationName());
|
||||
|
||||
// set taskbar / taskswitch icons
|
||||
setIconImages(Arrays.asList(ResourceManager.getImage("window.icon.small"), ResourceManager.getImage("window.icon.big")));
|
||||
|
||||
selectionList.setModel(new ArrayListModel(createPanelBuilders()));
|
||||
|
||||
JScrollPane selectionListScrollPane = new JScrollPane(selectionList, VERTICAL_SCROLLBAR_NEVER, HORIZONTAL_SCROLLBAR_NEVER);
|
||||
selectionListScrollPane.setBorder(new CompoundBorder(new ShadowBorder(), selectionListScrollPane.getBorder()));
|
||||
selectionListScrollPane.setOpaque(false);
|
||||
|
||||
headerPanel.getTitleLabel().setBorder(new EmptyBorder(8, 90, 10, 0));
|
||||
|
||||
JComponent c = (JComponent) getContentPane();
|
||||
c.setLayout(new MigLayout("insets 0, fill", "95px[fill]", "fill"));
|
||||
|
||||
c.add(selectionListScrollPane, "pos visual.x+6 visual.y+10 n visual.y2-12");
|
||||
c.add(headerPanel, "growx, dock north");
|
||||
|
||||
setSize(760, 615);
|
||||
|
||||
selectionList.addListSelectionListener(new ListSelectionListener() {
|
||||
|
||||
@Override
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
showPanel((PanelBuilder) selectionList.getSelectedValue());
|
||||
persistentSelectedPanel.setValue(Integer.toString(selectionList.getSelectedIndex()));
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
// restore selected panel
|
||||
selectionList.setSelectedIndex(Integer.parseInt(persistentSelectedPanel.getValue()));
|
||||
} catch (Exception e) {
|
||||
// default panel
|
||||
selectionList.setSelectedIndex(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected List<PanelBuilder> createPanelBuilders() {
|
||||
List<PanelBuilder> builders = new ArrayList<PanelBuilder>();
|
||||
|
||||
builders.add(new ListPanelBuilder());
|
||||
builders.add(new RenamePanelBuilder());
|
||||
builders.add(new AnalyzePanelBuilder());
|
||||
builders.add(new EpisodeListPanelBuilder());
|
||||
builders.add(new SfvPanelBuilder());
|
||||
|
||||
return builders;
|
||||
}
|
||||
|
||||
|
||||
protected void showPanel(final PanelBuilder selectedBuilder) {
|
||||
headerPanel.setTitle(selectedBuilder.getName());
|
||||
|
||||
JComponent panel = null;
|
||||
|
||||
for (int i = 0; i < getContentPane().getComponentCount(); i++) {
|
||||
JComponent c = (JComponent) getContentPane().getComponent(i);
|
||||
PanelBuilder builder = (PanelBuilder) c.getClientProperty("panelBuilder");
|
||||
|
||||
if (builder != null) {
|
||||
c.setVisible(false);
|
||||
|
||||
if (builder.equals(selectedBuilder)) {
|
||||
panel = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JComponent contentPane = (JComponent) getContentPane();
|
||||
|
||||
if (panel == null) {
|
||||
panel = selectedBuilder.create();
|
||||
panel.putClientProperty("panelBuilder", selectedBuilder);
|
||||
|
||||
contentPane.add(panel, "hidemode 3");
|
||||
}
|
||||
|
||||
panel.setVisible(true);
|
||||
|
||||
// update layout now
|
||||
contentPane.validate();
|
||||
}
|
||||
|
||||
|
||||
private static class PanelSelectionList extends JList {
|
||||
|
||||
private static final int SELECTDELAY_ON_DRAG_OVER = 300;
|
||||
|
||||
|
||||
public PanelSelectionList() {
|
||||
setCellRenderer(new PanelCellRenderer());
|
||||
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
|
||||
setBorder(new EmptyBorder(4, 5, 4, 5));
|
||||
|
||||
// initialize "drag over" panel selection
|
||||
new DropTarget(this, new DragDropListener());
|
||||
}
|
||||
|
||||
|
||||
private class DragDropListener extends DropTargetAdapter {
|
||||
|
||||
private boolean selectEnabled = false;
|
||||
|
||||
private Timer dragEnterTimer;
|
||||
|
||||
|
||||
@Override
|
||||
public void dragOver(DropTargetDragEvent dtde) {
|
||||
if (selectEnabled) {
|
||||
int index = locationToIndex(dtde.getLocation());
|
||||
setSelectedIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void dragEnter(final DropTargetDragEvent dtde) {
|
||||
dragEnterTimer = TunedUtilities.invokeLater(SELECTDELAY_ON_DRAG_OVER, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
selectEnabled = true;
|
||||
|
||||
// bring window to front when on dnd
|
||||
SwingUtilities.getWindowAncestor((JComponent) dtde.getSource()).toFront();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void dragExit(DropTargetEvent dte) {
|
||||
selectEnabled = false;
|
||||
|
||||
if (dragEnterTimer != null) {
|
||||
dragEnterTimer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drop(DropTargetDropEvent dtde) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static class PanelCellRenderer extends DefaultFancyListCellRenderer {
|
||||
|
||||
public PanelCellRenderer() {
|
||||
super(10, 0, new Color(0x163264));
|
||||
|
||||
// center labels in list
|
||||
setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
|
||||
|
||||
setHighlightingEnabled(false);
|
||||
|
||||
setVerticalTextPosition(SwingConstants.BOTTOM);
|
||||
setHorizontalTextPosition(SwingConstants.CENTER);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void configureListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||
super.configureListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
|
||||
PanelBuilder panel = (PanelBuilder) value;
|
||||
setText(panel.getName());
|
||||
setIcon(panel.getIcon());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
package net.sourceforge.filebot.ui;
|
||||
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
|
||||
public interface PanelBuilder {
|
||||
|
||||
public String getName();
|
||||
|
||||
|
||||
public Icon getIcon();
|
||||
|
||||
|
||||
public JComponent create();
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
|
||||
package net.sourceforge.filebot.ui;
|
||||
|
||||
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import net.sourceforge.filebot.ResourceManager;
|
||||
import net.sourceforge.filebot.ui.transfer.TransferablePolicy;
|
||||
import net.sourceforge.filebot.ui.transfer.TransferablePolicy.TransferAction;
|
||||
import net.sourceforge.tuned.ExceptionUtilities;
|
||||
|
||||
|
||||
public class SinglePanelFrame extends JFrame {
|
||||
|
||||
private final JComponent panel;
|
||||
|
||||
|
||||
public SinglePanelFrame(PanelBuilder builder) {
|
||||
super(builder.getName());
|
||||
|
||||
panel = builder.create();
|
||||
|
||||
// set taskbar / taskswitch icons
|
||||
setIconImages(Arrays.asList(ResourceManager.getImage("window.icon.small"), ResourceManager.getImage("window.icon.big")));
|
||||
|
||||
JComponent c = (JComponent) getContentPane();
|
||||
c.setLayout(new MigLayout("insets 0, nogrid, fill", "fill", "fill"));
|
||||
|
||||
HeaderPanel headerPanel = new HeaderPanel();
|
||||
headerPanel.setTitle(builder.getName());
|
||||
|
||||
c.add(headerPanel, "growx, dock north");
|
||||
c.add(panel);
|
||||
|
||||
setSize(760, 615);
|
||||
}
|
||||
|
||||
|
||||
public SinglePanelFrame publish(Transferable transferable) {
|
||||
TransferablePolicy policy = (TransferablePolicy) panel.getClientProperty("transferablePolicy");
|
||||
|
||||
try {
|
||||
if (policy != null && policy.accept(transferable)) {
|
||||
policy.handleTransferable(transferable, TransferAction.ADD);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw ExceptionUtilities.asRuntimeException(e);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
|
@ -6,25 +6,18 @@ import java.beans.PropertyChangeEvent;
|
|||
import java.beans.PropertyChangeListener;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JTabbedPane;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import net.sourceforge.filebot.ResourceManager;
|
||||
import net.sourceforge.filebot.ui.FileBotPanel;
|
||||
import net.sourceforge.filebot.ui.FileTransferableMessageHandler;
|
||||
import net.sourceforge.tuned.MessageHandler;
|
||||
|
||||
|
||||
public class AnalyzePanel extends FileBotPanel {
|
||||
public class AnalyzePanel extends JComponent {
|
||||
|
||||
private final FileTreePanel fileTreePanel = new FileTreePanel();
|
||||
private final JTabbedPane toolsPanel = new JTabbedPane();
|
||||
|
||||
private final MessageHandler messageHandler = new FileTransferableMessageHandler(this, fileTreePanel.getTransferablePolicy());
|
||||
|
||||
|
||||
public AnalyzePanel() {
|
||||
super("Analyze", ResourceManager.getIcon("panel.analyze"));
|
||||
|
||||
toolsPanel.setBorder(BorderFactory.createTitledBorder("Tools"));
|
||||
|
||||
setLayout(new MigLayout("insets dialog, gapx 50, fill"));
|
||||
|
@ -35,6 +28,8 @@ public class AnalyzePanel extends FileBotPanel {
|
|||
addTool(new TypeTool());
|
||||
addTool(new SplitTool());
|
||||
|
||||
putClientProperty("transferablePolicy", fileTreePanel.getTransferablePolicy());
|
||||
|
||||
fileTreePanel.addPropertyChangeListener("filetree", filetreeListener);
|
||||
}
|
||||
|
||||
|
@ -43,12 +38,6 @@ public class AnalyzePanel extends FileBotPanel {
|
|||
toolsPanel.addTab(tool.getName(), tool);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MessageHandler getMessageHandler() {
|
||||
return messageHandler;
|
||||
}
|
||||
|
||||
private final PropertyChangeListener filetreeListener = new PropertyChangeListener() {
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
package net.sourceforge.filebot.ui.panel.analyze;
|
||||
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import net.sourceforge.filebot.ResourceManager;
|
||||
import net.sourceforge.filebot.ui.PanelBuilder;
|
||||
|
||||
|
||||
public class AnalyzePanelBuilder implements PanelBuilder {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Analyze";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return ResourceManager.getIcon("panel.analyze");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public JComponent create() {
|
||||
return new AnalyzePanel();
|
||||
}
|
||||
|
||||
}
|
|
@ -3,6 +3,7 @@ package net.sourceforge.filebot.ui.panel.episodelist;
|
|||
|
||||
|
||||
import static net.sourceforge.filebot.ui.panel.episodelist.SeasonSpinnerModel.ALL_SEASONS;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
|
@ -19,7 +20,6 @@ import javax.swing.JButton;
|
|||
import javax.swing.JSpinner;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import net.sourceforge.filebot.ResourceManager;
|
||||
import net.sourceforge.filebot.Settings;
|
||||
import net.sourceforge.filebot.ui.AbstractSearchPanel;
|
||||
import net.sourceforge.filebot.ui.FileBotList;
|
||||
|
@ -49,8 +49,6 @@ public class EpisodeListPanel extends AbstractSearchPanel<EpisodeListClient, Epi
|
|||
|
||||
|
||||
public EpisodeListPanel() {
|
||||
super("Episodes", ResourceManager.getIcon("panel.episodelist"));
|
||||
|
||||
historyPanel.setColumnHeader(0, "Show");
|
||||
historyPanel.setColumnHeader(1, "Number of Episodes");
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
package net.sourceforge.filebot.ui.panel.episodelist;
|
||||
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import net.sourceforge.filebot.ResourceManager;
|
||||
import net.sourceforge.filebot.ui.PanelBuilder;
|
||||
|
||||
|
||||
public class EpisodeListPanelBuilder implements PanelBuilder {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Episodes";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return ResourceManager.getIcon("panel.episodelist");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public JComponent create() {
|
||||
return new EpisodeListPanel();
|
||||
}
|
||||
|
||||
}
|
|
@ -18,6 +18,7 @@ import java.util.regex.Pattern;
|
|||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JSpinner;
|
||||
|
@ -27,19 +28,15 @@ import javax.swing.SpinnerNumberModel;
|
|||
import javax.swing.JSpinner.NumberEditor;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import net.sourceforge.filebot.ResourceManager;
|
||||
import net.sourceforge.filebot.similarity.SeriesNameMatcher;
|
||||
import net.sourceforge.filebot.ui.FileBotList;
|
||||
import net.sourceforge.filebot.ui.FileBotListExportHandler;
|
||||
import net.sourceforge.filebot.ui.FileBotPanel;
|
||||
import net.sourceforge.filebot.ui.FileTransferableMessageHandler;
|
||||
import net.sourceforge.filebot.ui.transfer.LoadAction;
|
||||
import net.sourceforge.filebot.ui.transfer.SaveAction;
|
||||
import net.sourceforge.tuned.MessageHandler;
|
||||
import net.sourceforge.tuned.ui.TunedUtilities;
|
||||
|
||||
|
||||
public class ListPanel extends FileBotPanel {
|
||||
public class ListPanel extends JComponent {
|
||||
|
||||
private static final String INDEX_VARIABLE = "<i>";
|
||||
|
||||
|
@ -49,11 +46,8 @@ public class ListPanel extends FileBotPanel {
|
|||
private SpinnerNumberModel fromSpinnerModel = new SpinnerNumberModel(1, 0, Integer.MAX_VALUE, 1);
|
||||
private SpinnerNumberModel toSpinnerModel = new SpinnerNumberModel(20, 0, Integer.MAX_VALUE, 1);
|
||||
|
||||
private final MessageHandler messageHandler = new FileTransferableMessageHandler(this, list.getTransferablePolicy());
|
||||
|
||||
|
||||
public ListPanel() {
|
||||
super("List", ResourceManager.getIcon("panel.list"));
|
||||
|
||||
list.setTitle("Title");
|
||||
|
||||
|
@ -90,12 +84,6 @@ public class ListPanel extends FileBotPanel {
|
|||
TunedUtilities.putActionForKeystroke(this, KeyStroke.getKeyStroke("ENTER"), createAction);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MessageHandler getMessageHandler() {
|
||||
return messageHandler;
|
||||
}
|
||||
|
||||
private AbstractAction createAction = new AbstractAction("Create") {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
package net.sourceforge.filebot.ui.panel.list;
|
||||
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import net.sourceforge.filebot.ResourceManager;
|
||||
import net.sourceforge.filebot.ui.PanelBuilder;
|
||||
|
||||
|
||||
public class ListPanelBuilder implements PanelBuilder {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "List";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return ResourceManager.getIcon("panel.list");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public JComponent create() {
|
||||
return new ListPanel();
|
||||
}
|
||||
|
||||
}
|
|
@ -38,7 +38,6 @@ import net.sourceforge.filebot.similarity.NameSimilarityMetric;
|
|||
import net.sourceforge.filebot.similarity.SimilarityMetric;
|
||||
import net.sourceforge.filebot.ui.EpisodeExpressionFormat;
|
||||
import net.sourceforge.filebot.ui.EpisodeFormatDialog;
|
||||
import net.sourceforge.filebot.ui.FileBotPanel;
|
||||
import net.sourceforge.filebot.ui.SelectDialog;
|
||||
import net.sourceforge.filebot.web.AnidbClient;
|
||||
import net.sourceforge.filebot.web.Episode;
|
||||
|
@ -56,7 +55,7 @@ import ca.odell.glazedlists.event.ListEvent;
|
|||
import ca.odell.glazedlists.event.ListEventListener;
|
||||
|
||||
|
||||
public class RenamePanel extends FileBotPanel {
|
||||
public class RenamePanel extends JComponent {
|
||||
|
||||
protected final RenameModel<Object, File> model = RenameModel.create();
|
||||
|
||||
|
@ -74,7 +73,6 @@ public class RenamePanel extends FileBotPanel {
|
|||
|
||||
|
||||
public RenamePanel() {
|
||||
super("Rename", ResourceManager.getIcon("panel.rename"));
|
||||
|
||||
namesList.setTitle("Proposed");
|
||||
namesList.setTransferablePolicy(new NamesListTransferablePolicy(model.names()));
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
package net.sourceforge.filebot.ui.panel.rename;
|
||||
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import net.sourceforge.filebot.ResourceManager;
|
||||
import net.sourceforge.filebot.ui.PanelBuilder;
|
||||
|
||||
|
||||
public class RenamePanelBuilder implements PanelBuilder {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Rename";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return ResourceManager.getIcon("panel.rename");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public JComponent create() {
|
||||
return new RenamePanel();
|
||||
}
|
||||
|
||||
}
|
|
@ -20,6 +20,7 @@ import java.util.concurrent.ExecutorService;
|
|||
import javax.swing.AbstractAction;
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JToggleButton;
|
||||
|
@ -29,18 +30,15 @@ import javax.swing.border.TitledBorder;
|
|||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import net.sourceforge.filebot.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.DefaultTransferHandler;
|
||||
import net.sourceforge.filebot.ui.transfer.LoadAction;
|
||||
import net.sourceforge.filebot.ui.transfer.SaveAction;
|
||||
import net.sourceforge.tuned.FileUtilities;
|
||||
import net.sourceforge.tuned.MessageHandler;
|
||||
import net.sourceforge.tuned.ui.TunedUtilities;
|
||||
|
||||
|
||||
public class ChecksumPanel extends FileBotPanel {
|
||||
public class SfvPanel extends JComponent {
|
||||
|
||||
private final ChecksumComputationService computationService = new ChecksumComputationService();
|
||||
|
||||
|
@ -49,16 +47,13 @@ public class ChecksumPanel extends FileBotPanel {
|
|||
private final ChecksumTableTransferablePolicy transferablePolicy = new ChecksumTableTransferablePolicy(table.getModel(), computationService);
|
||||
private final ChecksumTableExportHandler exportHandler = new ChecksumTableExportHandler(table.getModel());
|
||||
|
||||
private final MessageHandler messageHandler = new FileTransferableMessageHandler(this, transferablePolicy);
|
||||
|
||||
|
||||
public ChecksumPanel() {
|
||||
super("SFV", ResourceManager.getIcon("panel.sfv"));
|
||||
public SfvPanel() {
|
||||
|
||||
table.setTransferHandler(new DefaultTransferHandler(transferablePolicy, exportHandler));
|
||||
|
||||
JPanel contentPane = new JPanel(new MigLayout("insets 0, nogrid, fill", "", "[fill]10px[bottom, pref!]4px"));
|
||||
contentPane.setBorder(new TitledBorder(getPanelName()));
|
||||
contentPane.setBorder(new TitledBorder("SFV"));
|
||||
|
||||
setLayout(new MigLayout("insets dialog, fill"));
|
||||
add(contentPane, "grow");
|
||||
|
@ -92,6 +87,8 @@ public class ChecksumPanel extends FileBotPanel {
|
|||
}
|
||||
});
|
||||
|
||||
putClientProperty("transferablePolicy", transferablePolicy);
|
||||
|
||||
// Shortcut DELETE
|
||||
TunedUtilities.putActionForKeystroke(this, KeyStroke.getKeyStroke("pressed DELETE"), removeAction);
|
||||
}
|
||||
|
@ -130,12 +127,6 @@ public class ChecksumPanel extends FileBotPanel {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MessageHandler getMessageHandler() {
|
||||
return messageHandler;
|
||||
}
|
||||
|
||||
private final SaveAction saveAction = new ChecksumTableSaveAction();
|
||||
|
||||
private final LoadAction loadAction = new LoadAction(transferablePolicy);
|
||||
|
@ -281,7 +272,7 @@ public class ChecksumPanel extends FileBotPanel {
|
|||
this.selectedColumn = options.get(0);
|
||||
} else if (options.size() > 1) {
|
||||
// user must select one option
|
||||
SelectDialog<File> selectDialog = new SelectDialog<File>(SwingUtilities.getWindowAncestor(ChecksumPanel.this), options) {
|
||||
SelectDialog<File> selectDialog = new SelectDialog<File>(SwingUtilities.getWindowAncestor(SfvPanel.this), options) {
|
||||
|
||||
@Override
|
||||
protected String convertValueToString(Object value) {
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
package net.sourceforge.filebot.ui.panel.sfv;
|
||||
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import net.sourceforge.filebot.ResourceManager;
|
||||
import net.sourceforge.filebot.ui.PanelBuilder;
|
||||
|
||||
|
||||
public class SfvPanelBuilder implements PanelBuilder {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "SFV";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return ResourceManager.getIcon("panel.sfv");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public JComponent create() {
|
||||
return new SfvPanel();
|
||||
}
|
||||
|
||||
}
|
|
@ -15,7 +15,6 @@ import javax.swing.Icon;
|
|||
|
||||
import ca.odell.glazedlists.BasicEventList;
|
||||
import ca.odell.glazedlists.EventList;
|
||||
import net.sourceforge.filebot.ResourceManager;
|
||||
import net.sourceforge.filebot.Settings;
|
||||
import net.sourceforge.filebot.ui.AbstractSearchPanel;
|
||||
import net.sourceforge.filebot.ui.SelectDialog;
|
||||
|
@ -33,8 +32,6 @@ import net.sourceforge.tuned.ui.SimpleLabelProvider;
|
|||
public class SubtitlePanel extends AbstractSearchPanel<SubtitleClient, SubtitlePackage> {
|
||||
|
||||
public SubtitlePanel() {
|
||||
super("Subtitles", ResourceManager.getIcon("panel.subtitle"));
|
||||
|
||||
historyPanel.setColumnHeader(0, "Show / Movie");
|
||||
historyPanel.setColumnHeader(1, "Number of Subtitles");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
package net.sourceforge.filebot.ui.panel.subtitle;
|
||||
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import net.sourceforge.filebot.ResourceManager;
|
||||
import net.sourceforge.filebot.ui.PanelBuilder;
|
||||
|
||||
|
||||
public class SubtitlePanelBuilder implements PanelBuilder {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Subtitles";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return ResourceManager.getIcon("panel.subtitle");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public JComponent create() {
|
||||
return new SubtitlePanel();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
|
||||
package net.sourceforge.tuned;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
|
||||
public class MessageBus {
|
||||
|
||||
private static final MessageBus instance = new MessageBus();
|
||||
|
||||
|
||||
public static MessageBus getDefault() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private final Map<String, List<MessageHandler>> handlers = new HashMap<String, List<MessageHandler>>();
|
||||
|
||||
|
||||
public synchronized void addMessageHandler(String topic, MessageHandler handler) {
|
||||
if (handler == null)
|
||||
return;
|
||||
|
||||
List<MessageHandler> list = handlers.get(topic.toLowerCase());
|
||||
|
||||
if (list == null) {
|
||||
list = new ArrayList<MessageHandler>(3);
|
||||
handlers.put(topic.toLowerCase(), list);
|
||||
}
|
||||
|
||||
list.add(handler);
|
||||
}
|
||||
|
||||
|
||||
public synchronized void removeMessageHandler(String topic, MessageHandler handler) {
|
||||
List<MessageHandler> list = handlers.get(topic.toLowerCase());
|
||||
|
||||
if (list != null) {
|
||||
list.remove(handler);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public synchronized MessageHandler[] getHandlers(String topic) {
|
||||
List<MessageHandler> list = handlers.get(topic.toLowerCase());
|
||||
|
||||
if (list == null)
|
||||
return new MessageHandler[0];
|
||||
|
||||
return list.toArray(new MessageHandler[0]);
|
||||
}
|
||||
|
||||
|
||||
public void publish(final String topic, final Object... messages) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
publishDirect(topic, messages);
|
||||
} else {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
publishDirect(topic, messages);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void publishDirect(String topic, Object... messages) {
|
||||
for (MessageHandler handler : getHandlers(topic.toLowerCase())) {
|
||||
try {
|
||||
handler.handle(topic.toLowerCase(), messages);
|
||||
} catch (Exception e) {
|
||||
Logger.getLogger("global").log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
|
||||
package net.sourceforge.tuned;
|
||||
|
||||
|
||||
public interface MessageHandler {
|
||||
|
||||
public void handle(String topic, Object... messages) throws Exception;
|
||||
|
||||
}
|
|
@ -15,40 +15,23 @@ public class ArgumentBeanTest {
|
|||
|
||||
@Test
|
||||
public void clear() throws Exception {
|
||||
ArgumentBean bean = parse("--sfv", "One Piece", "-clear");
|
||||
ArgumentBean bean = parse("-clear", "--analyze", "One Piece", "Naruto");
|
||||
|
||||
assertTrue(bean.isClear());
|
||||
assertFalse(bean.isHelp());
|
||||
assertEquals("One Piece", bean.getSfvPanelFile().getName());
|
||||
assertTrue(bean.clear());
|
||||
assertFalse(bean.help());
|
||||
|
||||
assertEquals("One Piece", bean.arguments().get(0).toString());
|
||||
assertEquals("Naruto", bean.arguments().get(1).toString());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void noClear() throws Exception {
|
||||
ArgumentBean bean = parse("-help", "--sfv", "One Piece");
|
||||
|
||||
assertTrue(bean.isHelp());
|
||||
assertFalse(bean.isClear());
|
||||
assertEquals("One Piece", bean.getSfvPanelFile().getName());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void oneArgument() throws Exception {
|
||||
ArgumentBean bean = parse("--sfv", "One Piece.sfv");
|
||||
|
||||
assertFalse(bean.isClear());
|
||||
assertFalse(bean.isHelp());
|
||||
assertEquals("One Piece.sfv", bean.getSfvPanelFile().getName());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void mixedArguments() throws Exception {
|
||||
ArgumentBean bean = parse("--list", "Twin Peaks.txt", "--sfv", "Death Note.sfv");
|
||||
|
||||
assertEquals("Twin Peaks.txt", bean.getListPanelFile().getName());
|
||||
assertEquals("Death Note.sfv", bean.getSfvPanelFile().getName());
|
||||
assertFalse(bean.help());
|
||||
assertFalse(bean.clear());
|
||||
assertEquals("One Piece.sfv", bean.arguments().get(0).toString());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue