refactor
This commit is contained in:
parent
94605c2593
commit
1a4f1a5966
|
@ -95,23 +95,20 @@ class MovieEditor implements TableCellEditor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
|
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
|
||||||
try {
|
getWindow(table).setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||||
getWindow(table).setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
|
||||||
|
|
||||||
SubtitleMappingTableModel model = (SubtitleMappingTableModel) table.getModel();
|
SubtitleMappingTableModel model = (SubtitleMappingTableModel) table.getModel();
|
||||||
SubtitleMapping mapping = model.getData()[table.convertRowIndexToModel(row)];
|
SubtitleMapping mapping = model.getData()[table.convertRowIndexToModel(row)];
|
||||||
|
|
||||||
|
newSwingWorker(() -> {
|
||||||
|
return runSearch(mapping, table);
|
||||||
|
}, (options) -> {
|
||||||
|
runSelect(options, mapping, table);
|
||||||
|
reset(null, table);
|
||||||
|
}, (error) -> {
|
||||||
|
reset(error, table);
|
||||||
|
}).execute();
|
||||||
|
|
||||||
newSwingWorker(() -> {
|
|
||||||
return runSearch(mapping, table);
|
|
||||||
}, (options) -> {
|
|
||||||
runSelect(options, mapping, table);
|
|
||||||
reset(null, table);
|
|
||||||
}, (error) -> {
|
|
||||||
reset(error, table);
|
|
||||||
}).execute();
|
|
||||||
} catch (Exception e) {
|
|
||||||
reset(e, table);
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ import java.awt.Point;
|
||||||
import java.awt.Window;
|
import java.awt.Window;
|
||||||
import java.awt.dnd.DnDConstants;
|
import java.awt.dnd.DnDConstants;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
@ -52,6 +51,18 @@ public final class SwingUI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void runOnEventDispatchThread(Runnable r) {
|
||||||
|
if (SwingUtilities.isEventDispatchThread()) {
|
||||||
|
r.run();
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
SwingUtilities.invokeAndWait(r);
|
||||||
|
} catch (InvocationTargetException | InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static final Color TRANSLUCENT = new Color(255, 255, 255, 0);
|
public static final Color TRANSLUCENT = new Color(255, 255, 255, 0);
|
||||||
|
|
||||||
public static Color interpolateHSB(Color c1, Color c2, float f) {
|
public static Color interpolateHSB(Color c1, Color c2, float f) {
|
||||||
|
@ -158,7 +169,7 @@ public final class SwingUI {
|
||||||
return (frame.getExtendedState() & Frame.MAXIMIZED_BOTH) != 0;
|
return (frame.getExtendedState() & Frame.MAXIMIZED_BOTH) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> showMultiValueInputDialog(final Object message, final String initialValue, final String title, final Component parent) throws InvocationTargetException, InterruptedException {
|
public static List<String> showMultiValueInputDialog(final Object message, final String initialValue, final String title, final Component parent) {
|
||||||
String input = showInputDialog(message, initialValue, title, parent);
|
String input = showInputDialog(message, initialValue, title, parent);
|
||||||
if (input == null || input.isEmpty()) {
|
if (input == null || input.isEmpty()) {
|
||||||
return emptyList();
|
return emptyList();
|
||||||
|
@ -184,24 +195,15 @@ public final class SwingUI {
|
||||||
return singletonList(input);
|
return singletonList(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String showInputDialog(final Object message, final String initialValue, final String title, final Component parent) throws InvocationTargetException, InterruptedException {
|
public static String showInputDialog(final Object message, final String initialValue, final String title, final Component parent) {
|
||||||
final StringBuilder buffer = new StringBuilder();
|
final StringBuilder buffer = new StringBuilder();
|
||||||
|
|
||||||
Runnable runnable = new Runnable() {
|
runOnEventDispatchThread(() -> {
|
||||||
|
Object value = JOptionPane.showInputDialog(parent, message, title, PLAIN_MESSAGE, null, null, initialValue);
|
||||||
@Override
|
if (value != null) {
|
||||||
public void run() {
|
buffer.append(value.toString().trim());
|
||||||
Object value = JOptionPane.showInputDialog(parent, message, title, PLAIN_MESSAGE, null, null, initialValue);
|
|
||||||
if (value != null) {
|
|
||||||
buffer.append(value.toString().trim());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
if (SwingUtilities.isEventDispatchThread()) {
|
|
||||||
runnable.run();
|
|
||||||
} else {
|
|
||||||
SwingUtilities.invokeAndWait(runnable);
|
|
||||||
}
|
|
||||||
|
|
||||||
return buffer.length() == 0 ? null : buffer.toString();
|
return buffer.length() == 0 ? null : buffer.toString();
|
||||||
}
|
}
|
||||||
|
@ -255,12 +257,8 @@ public final class SwingUI {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Timer invokeLater(int delay, final Runnable runnable) {
|
public static Timer invokeLater(int delay, final Runnable runnable) {
|
||||||
Timer timer = new Timer(delay, new ActionListener() {
|
Timer timer = new Timer(delay, (evt) -> {
|
||||||
|
runnable.run();
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
runnable.run();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
timer.setRepeats(false);
|
timer.setRepeats(false);
|
||||||
|
|
Loading…
Reference in New Issue