2014-04-19 02:30:29 -04:00
|
|
|
package net.filebot.ui;
|
2009-03-13 20:30:24 -04:00
|
|
|
|
2013-01-19 01:50:48 -05:00
|
|
|
import static java.awt.event.InputEvent.*;
|
|
|
|
import static java.awt.event.KeyEvent.*;
|
|
|
|
import static javax.swing.KeyStroke.*;
|
2009-05-17 13:14:03 -04:00
|
|
|
import static javax.swing.ScrollPaneConstants.*;
|
2015-03-24 08:39:05 -04:00
|
|
|
import static net.filebot.Settings.*;
|
2014-04-19 02:30:29 -04:00
|
|
|
import static net.filebot.ui.NotificationLogging.*;
|
2009-03-14 06:20:59 -04:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
import java.awt.Color;
|
2014-03-07 12:42:40 -05:00
|
|
|
import java.awt.Cursor;
|
|
|
|
import java.awt.Dialog.ModalExclusionType;
|
2009-03-13 20:30:24 -04:00
|
|
|
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;
|
2013-01-19 01:50:48 -05:00
|
|
|
import java.awt.event.ActionEvent;
|
2014-03-07 12:42:40 -05:00
|
|
|
import java.awt.event.WindowAdapter;
|
|
|
|
import java.awt.event.WindowEvent;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
2009-03-14 06:20:59 -04:00
|
|
|
|
2013-01-19 01:50:48 -05:00
|
|
|
import javax.swing.AbstractAction;
|
2009-03-13 20:30:24 -04:00
|
|
|
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;
|
2015-03-15 04:21:19 -04:00
|
|
|
import javax.swing.border.LineBorder;
|
2009-03-13 20:30:24 -04:00
|
|
|
import javax.swing.event.ListSelectionEvent;
|
|
|
|
import javax.swing.event.ListSelectionListener;
|
|
|
|
|
2014-04-19 02:30:29 -04:00
|
|
|
import net.filebot.Settings;
|
|
|
|
import net.filebot.cli.GroovyPad;
|
2014-08-05 07:55:28 -04:00
|
|
|
import net.filebot.mac.MacAppUtilities;
|
2014-04-19 02:30:29 -04:00
|
|
|
import net.filebot.ui.analyze.AnalyzePanelBuilder;
|
|
|
|
import net.filebot.ui.episodelist.EpisodeListPanelBuilder;
|
|
|
|
import net.filebot.ui.list.ListPanelBuilder;
|
|
|
|
import net.filebot.ui.rename.RenamePanelBuilder;
|
|
|
|
import net.filebot.ui.sfv.SfvPanelBuilder;
|
|
|
|
import net.filebot.ui.subtitle.SubtitlePanelBuilder;
|
|
|
|
import net.filebot.util.PreferencesMap.PreferencesEntry;
|
|
|
|
import net.filebot.util.ui.DefaultFancyListCellRenderer;
|
|
|
|
import net.filebot.util.ui.ShadowBorder;
|
2014-07-29 02:45:15 -04:00
|
|
|
import net.filebot.util.ui.SwingUI;
|
2014-07-24 07:31:24 -04:00
|
|
|
import net.miginfocom.swing.MigLayout;
|
|
|
|
import net.sf.ehcache.CacheManager;
|
2009-03-13 20:30:24 -04:00
|
|
|
|
|
|
|
public class MainFrame extends JFrame {
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-05-17 13:14:03 -04:00
|
|
|
private JList selectionList = new PanelSelectionList(createPanelBuilders());
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
private HeaderPanel headerPanel = new HeaderPanel();
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2013-12-30 02:37:01 -05:00
|
|
|
private static final PreferencesEntry<String> persistentSelectedPanel = Settings.forPackage(MainFrame.class).entry("panel.selected").defaultValue("0");
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
public MainFrame() {
|
2014-11-17 03:54:40 -05:00
|
|
|
super(Settings.isInstalled() ? Settings.getApplicationName() : Settings.getApplicationIdentifier());
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-14 06:20:59 -04:00
|
|
|
try {
|
|
|
|
// restore selected panel
|
2009-07-29 16:31:08 -04:00
|
|
|
selectionList.setSelectedIndex(Integer.parseInt(persistentSelectedPanel.getValue()));
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
// ignore
|
2009-03-14 06:20:59 -04:00
|
|
|
}
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
JScrollPane selectionListScrollPane = new JScrollPane(selectionList, VERTICAL_SCROLLBAR_NEVER, HORIZONTAL_SCROLLBAR_NEVER);
|
|
|
|
selectionListScrollPane.setOpaque(false);
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2015-03-24 08:39:05 -04:00
|
|
|
if (isMacApp()) {
|
|
|
|
selectionListScrollPane.setBorder(new CompoundBorder(new ShadowBorder(), new LineBorder(new Color(0x809DB8), 1, false)));
|
|
|
|
} else {
|
|
|
|
selectionListScrollPane.setBorder(new CompoundBorder(new ShadowBorder(), selectionListScrollPane.getBorder()));
|
|
|
|
}
|
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
headerPanel.getTitleLabel().setBorder(new EmptyBorder(8, 90, 10, 0));
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
JComponent c = (JComponent) getContentPane();
|
2009-03-13 21:01:01 -04:00
|
|
|
c.setLayout(new MigLayout("insets 0, fill, hidemode 3", "95px[fill]", "fill"));
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-14 12:02:27 -04:00
|
|
|
c.add(selectionListScrollPane, "pos 6px 10px n 100%-12px");
|
2009-03-13 20:30:24 -04:00
|
|
|
c.add(headerPanel, "growx, dock north");
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-14 06:20:59 -04:00
|
|
|
// show initial panel
|
|
|
|
showPanel((PanelBuilder) selectionList.getSelectedValue());
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
selectionList.addListSelectionListener(new ListSelectionListener() {
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
@Override
|
|
|
|
public void valueChanged(ListSelectionEvent e) {
|
|
|
|
showPanel((PanelBuilder) selectionList.getSelectedValue());
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-14 06:20:59 -04:00
|
|
|
if (!e.getValueIsAdjusting()) {
|
2009-07-29 16:31:08 -04:00
|
|
|
persistentSelectedPanel.setValue(Integer.toString(selectionList.getSelectedIndex()));
|
2009-03-14 06:20:59 -04:00
|
|
|
}
|
2009-03-13 20:30:24 -04:00
|
|
|
}
|
|
|
|
});
|
2013-12-19 06:40:44 -05:00
|
|
|
|
|
|
|
setSize(980, 630);
|
|
|
|
|
2013-01-19 01:50:48 -05:00
|
|
|
// KEYBOARD SHORTCUTS
|
2014-07-29 02:45:15 -04:00
|
|
|
SwingUI.installAction(this.getRootPane(), getKeyStroke(VK_DELETE, CTRL_MASK | SHIFT_MASK), new AbstractAction("Clear Cache") {
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2013-01-19 01:50:48 -05:00
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
CacheManager.getInstance().clearAll();
|
|
|
|
UILogger.info("Cache has been cleared");
|
|
|
|
}
|
|
|
|
});
|
2013-12-20 16:38:22 -05:00
|
|
|
|
2014-07-29 02:45:15 -04:00
|
|
|
SwingUI.installAction(this.getRootPane(), getKeyStroke(VK_F5, 0), new AbstractAction("Run") {
|
2013-12-20 16:38:22 -05:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent evt) {
|
2014-03-07 12:42:40 -05:00
|
|
|
try {
|
|
|
|
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); // loading Groovy might take a while
|
|
|
|
GroovyPad pad = new GroovyPad();
|
|
|
|
|
|
|
|
pad.addWindowListener(new WindowAdapter() {
|
|
|
|
public void windowOpened(WindowEvent e) {
|
|
|
|
MainFrame.this.setVisible(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
public void windowClosing(WindowEvent e) {
|
|
|
|
MainFrame.this.setVisible(true);
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
pad.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
2014-08-02 15:04:25 -04:00
|
|
|
pad.setModalExclusionType(ModalExclusionType.TOOLKIT_EXCLUDE);
|
2014-03-07 12:42:40 -05:00
|
|
|
pad.setLocationByPlatform(true);
|
|
|
|
pad.setVisible(true);
|
|
|
|
} catch (IOException e) {
|
|
|
|
Logger.getLogger(GroovyPad.class.getName()).log(Level.WARNING, e.getMessage(), e);
|
|
|
|
} finally {
|
|
|
|
setCursor(Cursor.getDefaultCursor());
|
|
|
|
}
|
2013-12-20 16:38:22 -05:00
|
|
|
}
|
|
|
|
});
|
2009-03-13 20:30:24 -04:00
|
|
|
}
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2013-04-09 13:55:54 -04:00
|
|
|
public static PanelBuilder[] createPanelBuilders() {
|
2013-12-30 02:37:01 -05:00
|
|
|
return new PanelBuilder[] { new RenamePanelBuilder(), new EpisodeListPanelBuilder(), new SubtitlePanelBuilder(), new SfvPanelBuilder(), new AnalyzePanelBuilder(), new ListPanelBuilder() };
|
2009-03-13 20:30:24 -04:00
|
|
|
}
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-05-17 13:14:03 -04:00
|
|
|
protected void showPanel(PanelBuilder selectedBuilder) {
|
2009-03-13 21:01:01 -04:00
|
|
|
final JComponent contentPane = (JComponent) getContentPane();
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
JComponent panel = null;
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 21:01:01 -04:00
|
|
|
for (int i = 0; i < contentPane.getComponentCount(); i++) {
|
|
|
|
JComponent c = (JComponent) contentPane.getComponent(i);
|
2009-03-13 20:30:24 -04:00
|
|
|
PanelBuilder builder = (PanelBuilder) c.getClientProperty("panelBuilder");
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
if (builder != null) {
|
|
|
|
if (builder.equals(selectedBuilder)) {
|
|
|
|
panel = c;
|
2009-03-13 21:01:01 -04:00
|
|
|
} else {
|
|
|
|
c.setVisible(false);
|
2009-03-13 20:30:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
if (panel == null) {
|
|
|
|
panel = selectedBuilder.create();
|
2011-11-13 01:49:34 -05:00
|
|
|
panel.setVisible(false); // invisible by default
|
2009-03-13 20:30:24 -04:00
|
|
|
panel.putClientProperty("panelBuilder", selectedBuilder);
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 21:01:01 -04:00
|
|
|
contentPane.add(panel);
|
2009-03-13 20:30:24 -04:00
|
|
|
}
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2011-11-13 01:49:34 -05:00
|
|
|
// make visible, ignore action is visible already
|
|
|
|
if (!panel.isVisible()) {
|
|
|
|
headerPanel.setTitle(selectedBuilder.getName());
|
|
|
|
panel.setVisible(true);
|
|
|
|
}
|
2009-03-13 20:30:24 -04:00
|
|
|
}
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
private static class PanelSelectionList extends JList {
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
private static final int SELECTDELAY_ON_DRAG_OVER = 300;
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-05-17 13:14:03 -04:00
|
|
|
public PanelSelectionList(PanelBuilder[] builders) {
|
2009-05-17 11:09:09 -04:00
|
|
|
super(builders);
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
setCellRenderer(new PanelCellRenderer());
|
|
|
|
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
setBorder(new EmptyBorder(4, 5, 4, 5));
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
// initialize "drag over" panel selection
|
|
|
|
new DropTarget(this, new DragDropListener());
|
|
|
|
}
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
private class DragDropListener extends DropTargetAdapter {
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
private boolean selectEnabled = false;
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
private Timer dragEnterTimer;
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
@Override
|
|
|
|
public void dragOver(DropTargetDragEvent dtde) {
|
|
|
|
if (selectEnabled) {
|
|
|
|
int index = locationToIndex(dtde.getLocation());
|
|
|
|
setSelectedIndex(index);
|
|
|
|
}
|
|
|
|
}
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
@Override
|
|
|
|
public void dragEnter(final DropTargetDragEvent dtde) {
|
2014-07-29 02:45:15 -04:00
|
|
|
dragEnterTimer = SwingUI.invokeLater(SELECTDELAY_ON_DRAG_OVER, new Runnable() {
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
selectEnabled = true;
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
// bring window to front when on dnd
|
2014-08-10 02:31:47 -04:00
|
|
|
if (Settings.isMacApp()) {
|
2014-08-05 07:55:28 -04:00
|
|
|
MacAppUtilities.requestForeground();
|
2014-07-30 21:20:27 -04:00
|
|
|
} else {
|
|
|
|
SwingUtilities.getWindowAncestor(((DropTarget) dtde.getSource()).getComponent()).toFront();
|
|
|
|
}
|
2009-03-13 20:30:24 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
@Override
|
|
|
|
public void dragExit(DropTargetEvent dte) {
|
|
|
|
selectEnabled = false;
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
if (dragEnterTimer != null) {
|
|
|
|
dragEnterTimer.stop();
|
|
|
|
}
|
|
|
|
}
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
@Override
|
|
|
|
public void drop(DropTargetDropEvent dtde) {
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
}
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
}
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
}
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
private static class PanelCellRenderer extends DefaultFancyListCellRenderer {
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
public PanelCellRenderer() {
|
|
|
|
super(10, 0, new Color(0x163264));
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
// center labels in list
|
|
|
|
setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
setHighlightingEnabled(false);
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
setVerticalTextPosition(SwingConstants.BOTTOM);
|
|
|
|
setHorizontalTextPosition(SwingConstants.CENTER);
|
|
|
|
}
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
@Override
|
|
|
|
public void configureListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
|
|
|
super.configureListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
PanelBuilder panel = (PanelBuilder) value;
|
|
|
|
setText(panel.getName());
|
|
|
|
setIcon(panel.getIcon());
|
|
|
|
}
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
}
|
2013-12-19 06:40:44 -05:00
|
|
|
|
2009-03-13 20:30:24 -04:00
|
|
|
}
|