1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-02 00:15:02 -04:00

Java 8 Refactoring

This commit is contained in:
Reinhard Pointner 2016-08-17 05:37:59 +08:00
parent 95427f05b3
commit 13e6360c4d
7 changed files with 31 additions and 57 deletions

View File

@ -313,7 +313,7 @@ public class Main {
started.flush(); started.flush();
// open Getting Started // open Getting Started
SwingUtilities.invokeLater(() -> GettingStartedStage.start()); SwingUtilities.invokeLater(GettingStartedStage::start);
} }
} }

View File

@ -27,7 +27,6 @@ import javax.swing.JToolBar;
import javax.swing.KeyStroke; import javax.swing.KeyStroke;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.SwingWorker; import javax.swing.SwingWorker;
import javax.swing.text.BadLocationException;
import javax.swing.text.JTextComponent; import javax.swing.text.JTextComponent;
import org.fife.ui.rsyntaxtextarea.FileLocation; import org.fife.ui.rsyntaxtextarea.FileLocation;
@ -298,26 +297,21 @@ public class GroovyPad extends JFrame {
try { try {
String message = this.toString("UTF-8"); String message = this.toString("UTF-8");
reset(); reset();
commit(message); commit(message);
} catch (UnsupportedEncodingException e) { } catch (Exception e) {
// can't happen // can't happen
} }
} }
private void commit(final String line) { private void commit(final String line) {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(() -> {
@Override
public void run() {
try { try {
int offset = textComponent.getDocument().getLength(); int offset = textComponent.getDocument().getLength();
textComponent.getDocument().insertString(offset, line, null); textComponent.getDocument().insertString(offset, line, null);
textComponent.setCaretPosition(textComponent.getDocument().getLength()); textComponent.setCaretPosition(textComponent.getDocument().getLength());
} catch (BadLocationException e) { } catch (Exception e) {
// ignore // ignore
} }
}
}); });
} }
} }

View File

@ -81,7 +81,7 @@ class ConflictDialog extends JDialog {
c.add(b, "tag next"); c.add(b, "tag next");
// focus "Continue" button // focus "Continue" button
SwingUtilities.invokeLater(() -> c.getComponent(2).requestFocusInWindow()); SwingUtilities.invokeLater(c.getComponent(2)::requestFocusInWindow);
installAction(c, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), newAction("Cancel", this::cancel)); installAction(c, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), newAction("Cancel", this::cancel));

View File

@ -37,7 +37,7 @@ import net.miginfocom.swing.MigLayout;
class ValidateDialog extends JDialog { class ValidateDialog extends JDialog {
private final JList list; private JList list;
private File[] model; private File[] model;
@ -61,7 +61,7 @@ class ValidateDialog extends JDialog {
c.add(new JButton(continueAction), "tag ok"); c.add(new JButton(continueAction), "tag ok");
// focus "Validate" button // focus "Validate" button
SwingUtilities.invokeLater(() -> c.getComponent(2).requestFocusInWindow()); SwingUtilities.invokeLater(c.getComponent(2)::requestFocusInWindow);
installAction(c, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelAction); installAction(c, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelAction);
@ -140,9 +140,8 @@ class ValidateDialog extends JDialog {
private static class IndexView<E> extends AbstractList<E> { private static class IndexView<E> extends AbstractList<E> {
private final List<Integer> mapping = new ArrayList<Integer>(); private List<Integer> mapping = new ArrayList<Integer>();
private List<E> source;
private final List<E> source;
public IndexView(List<E> source) { public IndexView(List<E> source) {
this.source = source; this.source = source;

View File

@ -1,7 +1,6 @@
package net.filebot.ui.sfv; package net.filebot.ui.sfv;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
@ -15,14 +14,12 @@ import javax.swing.border.TitledBorder;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
class TotalProgressPanel extends JComponent { class TotalProgressPanel extends JComponent {
private final JProgressBar progressBar = new JProgressBar(0, 0); private final JProgressBar progressBar = new JProgressBar(0, 0);
private final int millisToSetVisible = 200; private final int millisToSetVisible = 200;
public TotalProgressPanel(ChecksumComputationService computationService) { public TotalProgressPanel(ChecksumComputationService computationService) {
setLayout(new MigLayout("insets 1px")); setLayout(new MigLayout("insets 1px"));
@ -45,18 +42,13 @@ class TotalProgressPanel extends JComponent {
private final DelayedToggle delayed = new DelayedToggle(); private final DelayedToggle delayed = new DelayedToggle();
@Override @Override
public void propertyChange(PropertyChangeEvent evt) { public void propertyChange(PropertyChangeEvent evt) {
final int completedTaskCount = getComputationService(evt).getCompletedTaskCount(); int completedTaskCount = getComputationService(evt).getCompletedTaskCount();
final int totalTaskCount = getComputationService(evt).getTotalTaskCount(); int totalTaskCount = getComputationService(evt).getTotalTaskCount();
// invoke on EDT // invoke on EDT
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(() -> {
@Override
public void run() {
if (completedTaskCount == totalTaskCount) { if (completedTaskCount == totalTaskCount) {
// delayed hide on reset, immediate hide on finish // delayed hide on reset, immediate hide on finish
delayed.toggle(HIDE, totalTaskCount == 0 ? millisToSetVisible : 0, visibilityActionHandler); delayed.toggle(HIDE, totalTaskCount == 0 ? millisToSetVisible : 0, visibilityActionHandler);
@ -67,14 +59,11 @@ class TotalProgressPanel extends JComponent {
if (totalTaskCount != 0) { if (totalTaskCount != 0) {
progressBar.setValue(completedTaskCount); progressBar.setValue(completedTaskCount);
progressBar.setMaximum(totalTaskCount); progressBar.setMaximum(totalTaskCount);
progressBar.setString(String.format("%d / %d", completedTaskCount, totalTaskCount)); progressBar.setString(String.format("%d / %d", completedTaskCount, totalTaskCount));
} }
};
}); });
} }
private ChecksumComputationService getComputationService(PropertyChangeEvent evt) { private ChecksumComputationService getComputationService(PropertyChangeEvent evt) {
return ((ChecksumComputationService) evt.getSource()); return ((ChecksumComputationService) evt.getSource());
} }
@ -89,12 +78,10 @@ class TotalProgressPanel extends JComponent {
}; };
protected static class DelayedToggle { protected static class DelayedToggle {
private Timer timer = null; private Timer timer = null;
public void toggle(String action, int delay, final ActionListener actionHandler) { public void toggle(String action, int delay, final ActionListener actionHandler) {
if (timer != null) { if (timer != null) {
if (action.equals(timer.getActionCommand())) { if (action.equals(timer.getActionCommand())) {

View File

@ -219,7 +219,7 @@ class SubtitleAutoMatchDialog extends JDialog {
@Override @Override
protected void done() { protected void done() {
SwingUtilities.invokeLater(() -> mappingModel.fireTableStructureChanged()); // make sure UI is refershed after completion SwingUtilities.invokeLater(mappingModel::fireTableStructureChanged); // make sure UI is refershed after completion
} }
}; };

View File

@ -75,14 +75,8 @@ public abstract class BackgroundFileTransferablePolicy<V> extends FileTransferab
worker.offer(chunks); worker.offer(chunks);
} }
protected final void publish(final Exception exception) { protected final void publish(Exception exception) {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(() -> process(exception));
@Override
public void run() {
process(exception);
}
});
} }
protected class BackgroundWorker extends SwingWorker<Object, V> { protected class BackgroundWorker extends SwingWorker<Object, V> {