* refactoring
This commit is contained in:
parent
419255bf34
commit
115c617a0c
Binary file not shown.
Before Width: | Height: | Size: 875 B |
|
@ -62,7 +62,7 @@ public abstract class AbstractSearchPanel<S, E> extends JComponent {
|
|||
JScrollPane historyScrollPane = new JScrollPane(historyPanel, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER);
|
||||
historyScrollPane.setBorder(BorderFactory.createEmptyBorder());
|
||||
|
||||
tabbedPane.addTab("History", ResourceManager.getIcon("tab.history"), historyScrollPane);
|
||||
tabbedPane.addTab("History", ResourceManager.getIcon("action.find"), historyScrollPane);
|
||||
|
||||
tabbedPaneGroup.setBorder(BorderFactory.createTitledBorder("Search Results"));
|
||||
tabbedPaneGroup.add(tabbedPane, "grow, wrap");
|
||||
|
|
|
@ -95,8 +95,6 @@ public class EpisodeFormatDialog extends JDialog {
|
|||
public EpisodeFormatDialog(Window owner) {
|
||||
super(owner, "Episode Format", ModalityType.DOCUMENT_MODAL);
|
||||
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
|
||||
editor.setText(Settings.userRoot().get("dialog.format"));
|
||||
editor.setFont(new Font(MONOSPACED, PLAIN, 14));
|
||||
|
||||
|
@ -173,6 +171,7 @@ public class EpisodeFormatDialog extends JDialog {
|
|||
firePreviewSampleChanged();
|
||||
|
||||
// initialize window properties
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
setLocation(TunedUtilities.getPreferredLocation(this));
|
||||
pack();
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@ import net.sourceforge.filebot.ui.panel.sfv.SfvPanelBuilder;
|
|||
import net.sourceforge.filebot.ui.panel.subtitle.SubtitlePanelBuilder;
|
||||
import net.sourceforge.tuned.PreferencesMap.PreferencesEntry;
|
||||
import net.sourceforge.tuned.PreferencesMap.SimpleAdapter;
|
||||
import net.sourceforge.tuned.ui.ArrayListModel;
|
||||
import net.sourceforge.tuned.ui.DefaultFancyListCellRenderer;
|
||||
import net.sourceforge.tuned.ui.ShadowBorder;
|
||||
import net.sourceforge.tuned.ui.TunedUtilities;
|
||||
|
@ -61,8 +60,6 @@ public class MainFrame extends JFrame {
|
|||
// set taskbar / taskswitch icons
|
||||
setIconImages(Arrays.asList(ResourceManager.getImage("window.icon.small"), ResourceManager.getImage("window.icon.big")));
|
||||
|
||||
selectionList.setModel(new ArrayListModel(createPanelBuilders()));
|
||||
|
||||
try {
|
||||
// restore selected panel
|
||||
selectionList.setSelectedIndex(persistentSelectedPanel.getValue());
|
||||
|
@ -151,7 +148,9 @@ public class MainFrame extends JFrame {
|
|||
private static final int SELECTDELAY_ON_DRAG_OVER = 300;
|
||||
|
||||
|
||||
public PanelSelectionList() {
|
||||
public PanelSelectionList(PanelBuilder... builders) {
|
||||
super(builders);
|
||||
|
||||
setCellRenderer(new PanelCellRenderer());
|
||||
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ import javax.swing.SwingUtilities;
|
|||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import net.sourceforge.filebot.ResourceManager;
|
||||
import net.sourceforge.tuned.ui.ArrayListModel;
|
||||
import net.sourceforge.tuned.ui.DefaultFancyListCellRenderer;
|
||||
import net.sourceforge.tuned.ui.TunedUtilities;
|
||||
|
||||
|
@ -42,7 +41,7 @@ public class SelectDialog<T> extends JDialog {
|
|||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
|
||||
// initialize list
|
||||
list = new JList(new ArrayListModel(options));
|
||||
list = new JList(options.toArray());
|
||||
|
||||
// select first element
|
||||
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
|
|
|
@ -15,6 +15,7 @@ import java.awt.event.ActionEvent;
|
|||
import java.util.List;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.AbstractListModel;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
|
@ -26,7 +27,6 @@ import javax.swing.KeyStroke;
|
|||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import net.sourceforge.filebot.ResourceManager;
|
||||
import net.sourceforge.tuned.ui.ArrayListModel;
|
||||
import net.sourceforge.tuned.ui.TunedUtilities;
|
||||
|
||||
|
||||
|
@ -51,7 +51,7 @@ class ValidateNamesDialog extends JDialog {
|
|||
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
|
||||
list = new JList(new ArrayListModel(source));
|
||||
list = new JList(source.toArray());
|
||||
list.setEnabled(false);
|
||||
|
||||
list.setCellRenderer(new HighlightListCellRenderer(INVALID_CHARACTERS_PATTERN, new CharacterHighlightPainter(new Color(0xFF4200), new Color(0xFF1200)), 4));
|
||||
|
@ -118,7 +118,19 @@ class ValidateNamesDialog extends JDialog {
|
|||
continueAction.putValue(ContinueAction.ALPHA, 1.0f);
|
||||
|
||||
// update displayed values
|
||||
list.setModel(new ArrayListModel(validatedValues));
|
||||
list.setModel(new AbstractListModel() {
|
||||
|
||||
@Override
|
||||
public Object getElementAt(int i) {
|
||||
return validatedValues[i];
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return validatedValues.length;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.util.logging.Level;
|
|||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JFileChooser;
|
||||
|
||||
import net.sourceforge.filebot.ResourceManager;
|
||||
|
@ -15,16 +16,27 @@ import net.sourceforge.filebot.ui.transfer.TransferablePolicy.TransferAction;
|
|||
|
||||
public class LoadAction extends AbstractAction {
|
||||
|
||||
public static final String TRANSFERABLE_POLICY = "transferable policy";
|
||||
public static final String TRANSFERABLE_POLICY = "transferablePolicy";
|
||||
|
||||
|
||||
public LoadAction(TransferablePolicy transferablePolicy) {
|
||||
super("Load", ResourceManager.getIcon("action.load"));
|
||||
|
||||
this("Load", ResourceManager.getIcon("action.load"), transferablePolicy);
|
||||
}
|
||||
|
||||
|
||||
public LoadAction(String name, Icon icon, TransferablePolicy transferablePolicy) {
|
||||
putValue(NAME, name);
|
||||
putValue(SMALL_ICON, icon);
|
||||
putValue(TRANSFERABLE_POLICY, transferablePolicy);
|
||||
}
|
||||
|
||||
|
||||
public TransferAction getTransferAction(ActionEvent evt) {
|
||||
// if CTRL was pressed when the button was clicked, assume ADD action (same as with dnd)
|
||||
return ((evt.getModifiers() & ActionEvent.CTRL_MASK) != 0) ? TransferAction.ADD : TransferAction.PUT;
|
||||
}
|
||||
|
||||
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
// get transferable policy from action properties
|
||||
TransferablePolicy transferablePolicy = (TransferablePolicy) getValue(TRANSFERABLE_POLICY);
|
||||
|
@ -44,16 +56,9 @@ public class LoadAction extends AbstractAction {
|
|||
|
||||
FileTransferable transferable = new FileTransferable(chooser.getSelectedFiles());
|
||||
|
||||
TransferAction action = TransferAction.PUT;
|
||||
|
||||
// if CTRL was pressed when the button was clicked, assume ADD action (same as with dnd)
|
||||
if ((evt.getModifiers() & ActionEvent.CTRL_MASK) != 0) {
|
||||
action = TransferAction.ADD;
|
||||
}
|
||||
|
||||
try {
|
||||
if (transferablePolicy.accept(transferable)) {
|
||||
transferablePolicy.handleTransferable(transferable, action);
|
||||
transferablePolicy.handleTransferable(transferable, getTransferAction(evt));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.getLogger("ui").log(Level.WARNING, e.getMessage(), e);
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.logging.Level;
|
|||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFileChooser;
|
||||
|
||||
|
@ -18,17 +19,23 @@ import net.sourceforge.filebot.ResourceManager;
|
|||
|
||||
public class SaveAction extends AbstractAction {
|
||||
|
||||
private final FileExportHandler exportHandler;
|
||||
public static final String EXPORT_HANDLER = "exportHandler";
|
||||
|
||||
|
||||
public SaveAction(FileExportHandler exportHandler) {
|
||||
super("Save as ...", ResourceManager.getIcon("action.save"));
|
||||
this.exportHandler = exportHandler;
|
||||
this("Save as ...", ResourceManager.getIcon("action.save"), exportHandler);
|
||||
}
|
||||
|
||||
|
||||
public SaveAction(String name, Icon icon, FileExportHandler exportHandler) {
|
||||
putValue(NAME, name);
|
||||
putValue(SMALL_ICON, icon);
|
||||
putValue(EXPORT_HANDLER, exportHandler);
|
||||
}
|
||||
|
||||
|
||||
public FileExportHandler getExportHandler() {
|
||||
return exportHandler;
|
||||
return (FileExportHandler) getValue(EXPORT_HANDLER);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
|
||||
package net.sourceforge.tuned.ui;
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.swing.ListModel;
|
||||
import javax.swing.event.ListDataListener;
|
||||
|
||||
|
||||
public class ArrayListModel implements ListModel {
|
||||
|
||||
private final Object[] data;
|
||||
|
||||
|
||||
public ArrayListModel(Collection<? extends Object> data) {
|
||||
this.data = data.toArray();
|
||||
}
|
||||
|
||||
|
||||
public ArrayListModel(Object[] data) {
|
||||
this.data = Arrays.copyOf(data, data.length);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getElementAt(int index) {
|
||||
return data[index];
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return data.length;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addListDataListener(ListDataListener l) {
|
||||
// ignore, model is unmodifiable
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void removeListDataListener(ListDataListener l) {
|
||||
// ignore, model is unmodifiable
|
||||
}
|
||||
|
||||
}
|
|
@ -94,14 +94,14 @@ public final class TunedUtilities {
|
|||
}
|
||||
|
||||
|
||||
public static Window getWindow(Component component) {
|
||||
if (component == null)
|
||||
return null;
|
||||
|
||||
public static Window getWindow(Object component) {
|
||||
if (component instanceof Window)
|
||||
return (Window) component;
|
||||
|
||||
return SwingUtilities.getWindowAncestor(component);
|
||||
if (component instanceof Component)
|
||||
return SwingUtilities.getWindowAncestor((Component) component);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue