1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-22 15:58:52 -05:00

Refactor PanelBuilder[]

This commit is contained in:
Reinhard Pointner 2019-02-26 12:20:26 +07:00
parent 1cf72f24e7
commit 0815aa6532
2 changed files with 17 additions and 10 deletions

View File

@ -3,7 +3,9 @@ package net.filebot.cli;
import static java.awt.GraphicsEnvironment.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.util.stream.Collectors.*;
import static net.filebot.Logging.*;
import static net.filebot.Settings.*;
import static net.filebot.hash.VerificationUtilities.*;
import static net.filebot.media.XattrMetaInfo.*;
import static net.filebot.subtitle.SubtitleUtilities.*;
@ -333,19 +335,24 @@ public class ArgumentBean {
}
}
public PanelBuilder[] getPanelBuilders() {
// default multi panel mode
public List<PanelBuilder> getPanelBuilders() {
if (mode == null) {
return PanelBuilder.defaultSequence();
// MAS does not allow subtitle applications
if (isMacSandbox()) {
return stream(PanelBuilder.defaultSequence()).filter(p -> !p.getName().equals("Subtitles")).collect(toList());
}
// default multi panel mode
return asList(PanelBuilder.defaultSequence());
}
// only selected panels
return optional(mode).map(m -> {
Pattern pattern = Pattern.compile(mode, Pattern.CASE_INSENSITIVE);
PanelBuilder[] panel = stream(PanelBuilder.defaultSequence()).filter(p -> pattern.matcher(p.getName()).matches()).toArray(PanelBuilder[]::new);
List<PanelBuilder> panel = stream(PanelBuilder.defaultSequence()).filter(p -> pattern.matcher(p.getName()).matches()).collect(toList());
// throw exception if illegal pattern was passed in
if (panel.length == 0) {
if (panel.isEmpty()) {
return null;
}

View File

@ -2,7 +2,6 @@ package net.filebot.ui;
import static java.awt.event.InputEvent.*;
import static java.awt.event.KeyEvent.*;
import static java.util.Arrays.*;
import static java.util.Comparator.*;
import static javax.swing.BorderFactory.*;
import static javax.swing.KeyStroke.*;
@ -23,6 +22,7 @@ import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.List;
import java.util.logging.Level;
import javax.swing.JComponent;
@ -53,7 +53,7 @@ public class MainFrame extends JFrame {
private JList selectionList;
private HeaderPanel headerPanel;
public MainFrame(PanelBuilder[] panels) {
public MainFrame(List<PanelBuilder> panels) {
super(getWindowTitle());
selectionList = new PanelSelectionList(panels);
@ -187,11 +187,11 @@ public class MainFrame extends JFrame {
private static final int SELECTDELAY_ON_DRAG_OVER = 300;
public PanelSelectionList(PanelBuilder[] builders) {
super(builders);
public PanelSelectionList(List<PanelBuilder> builders) {
super(builders.toArray(PanelBuilder[]::new));
setCellRenderer(new PanelCellRenderer());
setPrototypeCellValue(stream(builders).max(comparingInt(p -> p.getName().length())).get());
setPrototypeCellValue(builders.stream().max(comparingInt(p -> p.getName().length())).get());
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
setBorder(createEmptyBorder(4, 5, 4, 5));