This commit is contained in:
Reinhard Pointner 2016-02-06 18:34:47 +00:00
parent 94605c2593
commit 1a4f1a5966
2 changed files with 33 additions and 38 deletions

View File

@ -95,7 +95,6 @@ class MovieEditor implements TableCellEditor {
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
try {
getWindow(table).setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
SubtitleMappingTableModel model = (SubtitleMappingTableModel) table.getModel();
@ -109,9 +108,7 @@ class MovieEditor implements TableCellEditor {
}, (error) -> {
reset(error, table);
}).execute();
} catch (Exception e) {
reset(e, table);
}
return null;
}

View File

@ -13,7 +13,6 @@ import java.awt.Point;
import java.awt.Window;
import java.awt.dnd.DnDConstants;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
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 Color interpolateHSB(Color c1, Color c2, float f) {
@ -158,7 +169,7 @@ public final class SwingUI {
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);
if (input == null || input.isEmpty()) {
return emptyList();
@ -184,24 +195,15 @@ public final class SwingUI {
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();
Runnable runnable = new Runnable() {
@Override
public void run() {
runOnEventDispatchThread(() -> {
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();
}
@ -255,12 +257,8 @@ public final class SwingUI {
}
public static Timer invokeLater(int delay, final Runnable runnable) {
Timer timer = new Timer(delay, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Timer timer = new Timer(delay, (evt) -> {
runnable.run();
}
});
timer.setRepeats(false);