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:
parent
95427f05b3
commit
13e6360c4d
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,25 +297,20 @@ 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(() -> {
|
||||||
|
try {
|
||||||
@Override
|
int offset = textComponent.getDocument().getLength();
|
||||||
public void run() {
|
textComponent.getDocument().insertString(offset, line, null);
|
||||||
try {
|
textComponent.setCaretPosition(textComponent.getDocument().getLength());
|
||||||
int offset = textComponent.getDocument().getLength();
|
} catch (Exception e) {
|
||||||
textComponent.getDocument().insertString(offset, line, null);
|
// ignore
|
||||||
textComponent.setCaretPosition(textComponent.getDocument().getLength());
|
|
||||||
} catch (BadLocationException e) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -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));
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
@ -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,36 +42,28 @@ 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(() -> {
|
||||||
|
if (completedTaskCount == totalTaskCount) {
|
||||||
|
// delayed hide on reset, immediate hide on finish
|
||||||
|
delayed.toggle(HIDE, totalTaskCount == 0 ? millisToSetVisible : 0, visibilityActionHandler);
|
||||||
|
} else if (totalTaskCount != 0) {
|
||||||
|
delayed.toggle(SHOW, millisToSetVisible, visibilityActionHandler);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
if (totalTaskCount != 0) {
|
||||||
public void run() {
|
progressBar.setValue(completedTaskCount);
|
||||||
|
progressBar.setMaximum(totalTaskCount);
|
||||||
if (completedTaskCount == totalTaskCount) {
|
progressBar.setString(String.format("%d / %d", completedTaskCount, totalTaskCount));
|
||||||
// delayed hide on reset, immediate hide on finish
|
}
|
||||||
delayed.toggle(HIDE, totalTaskCount == 0 ? millisToSetVisible : 0, visibilityActionHandler);
|
|
||||||
} else if (totalTaskCount != 0) {
|
|
||||||
delayed.toggle(SHOW, millisToSetVisible, visibilityActionHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (totalTaskCount != 0) {
|
|
||||||
progressBar.setValue(completedTaskCount);
|
|
||||||
progressBar.setMaximum(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())) {
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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> {
|
||||||
|
Loading…
Reference in New Issue
Block a user