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();
|
||||
|
||||
// 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.SwingUtilities;
|
||||
import javax.swing.SwingWorker;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.JTextComponent;
|
||||
|
||||
import org.fife.ui.rsyntaxtextarea.FileLocation;
|
||||
@ -298,25 +297,20 @@ public class GroovyPad extends JFrame {
|
||||
try {
|
||||
String message = this.toString("UTF-8");
|
||||
reset();
|
||||
|
||||
commit(message);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
} catch (Exception e) {
|
||||
// can't happen
|
||||
}
|
||||
}
|
||||
|
||||
private void commit(final String line) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
int offset = textComponent.getDocument().getLength();
|
||||
textComponent.getDocument().insertString(offset, line, null);
|
||||
textComponent.setCaretPosition(textComponent.getDocument().getLength());
|
||||
} catch (BadLocationException e) {
|
||||
// ignore
|
||||
}
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
try {
|
||||
int offset = textComponent.getDocument().getLength();
|
||||
textComponent.getDocument().insertString(offset, line, null);
|
||||
textComponent.setCaretPosition(textComponent.getDocument().getLength());
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ class ConflictDialog extends JDialog {
|
||||
c.add(b, "tag next");
|
||||
|
||||
// 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));
|
||||
|
||||
|
@ -37,7 +37,7 @@ import net.miginfocom.swing.MigLayout;
|
||||
|
||||
class ValidateDialog extends JDialog {
|
||||
|
||||
private final JList list;
|
||||
private JList list;
|
||||
|
||||
private File[] model;
|
||||
|
||||
@ -61,7 +61,7 @@ class ValidateDialog extends JDialog {
|
||||
c.add(new JButton(continueAction), "tag ok");
|
||||
|
||||
// focus "Validate" button
|
||||
SwingUtilities.invokeLater(() -> c.getComponent(2).requestFocusInWindow());
|
||||
SwingUtilities.invokeLater(c.getComponent(2)::requestFocusInWindow);
|
||||
|
||||
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 final List<Integer> mapping = new ArrayList<Integer>();
|
||||
|
||||
private final List<E> source;
|
||||
private List<Integer> mapping = new ArrayList<Integer>();
|
||||
private List<E> source;
|
||||
|
||||
public IndexView(List<E> source) {
|
||||
this.source = source;
|
||||
|
@ -1,7 +1,6 @@
|
||||
|
||||
package net.filebot.ui.sfv;
|
||||
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
@ -15,14 +14,12 @@ import javax.swing.border.TitledBorder;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
|
||||
class TotalProgressPanel extends JComponent {
|
||||
|
||||
private final JProgressBar progressBar = new JProgressBar(0, 0);
|
||||
|
||||
private final int millisToSetVisible = 200;
|
||||
|
||||
|
||||
public TotalProgressPanel(ChecksumComputationService computationService) {
|
||||
setLayout(new MigLayout("insets 1px"));
|
||||
|
||||
@ -45,36 +42,28 @@ class TotalProgressPanel extends JComponent {
|
||||
|
||||
private final DelayedToggle delayed = new DelayedToggle();
|
||||
|
||||
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
final int completedTaskCount = getComputationService(evt).getCompletedTaskCount();
|
||||
final int totalTaskCount = getComputationService(evt).getTotalTaskCount();
|
||||
int completedTaskCount = getComputationService(evt).getCompletedTaskCount();
|
||||
int totalTaskCount = getComputationService(evt).getTotalTaskCount();
|
||||
|
||||
// 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
|
||||
public void run() {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if (totalTaskCount != 0) {
|
||||
progressBar.setValue(completedTaskCount);
|
||||
progressBar.setMaximum(totalTaskCount);
|
||||
|
||||
progressBar.setString(String.format("%d / %d", completedTaskCount, totalTaskCount));
|
||||
}
|
||||
};
|
||||
if (totalTaskCount != 0) {
|
||||
progressBar.setValue(completedTaskCount);
|
||||
progressBar.setMaximum(totalTaskCount);
|
||||
progressBar.setString(String.format("%d / %d", completedTaskCount, totalTaskCount));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private ChecksumComputationService getComputationService(PropertyChangeEvent evt) {
|
||||
return ((ChecksumComputationService) evt.getSource());
|
||||
}
|
||||
@ -89,12 +78,10 @@ class TotalProgressPanel extends JComponent {
|
||||
|
||||
};
|
||||
|
||||
|
||||
protected static class DelayedToggle {
|
||||
|
||||
private Timer timer = null;
|
||||
|
||||
|
||||
public void toggle(String action, int delay, final ActionListener actionHandler) {
|
||||
if (timer != null) {
|
||||
if (action.equals(timer.getActionCommand())) {
|
||||
|
@ -219,7 +219,7 @@ class SubtitleAutoMatchDialog extends JDialog {
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
protected final void publish(final Exception exception) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
process(exception);
|
||||
}
|
||||
});
|
||||
protected final void publish(Exception exception) {
|
||||
SwingUtilities.invokeLater(() -> process(exception));
|
||||
}
|
||||
|
||||
protected class BackgroundWorker extends SwingWorker<Object, V> {
|
||||
|
Loading…
Reference in New Issue
Block a user