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 @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();
@ -109,9 +108,7 @@ class MovieEditor implements TableCellEditor {
}, (error) -> { }, (error) -> {
reset(error, table); reset(error, table);
}).execute(); }).execute();
} catch (Exception e) {
reset(e, table);
}
return null; return null;
} }

View File

@ -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(() -> {
@Override
public void run() {
Object value = JOptionPane.showInputDialog(parent, message, title, PLAIN_MESSAGE, null, null, initialValue); Object value = JOptionPane.showInputDialog(parent, message, title, PLAIN_MESSAGE, null, null, initialValue);
if (value != null) { if (value != null) {
buffer.append(value.toString().trim()); 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) -> {
@Override
public void actionPerformed(ActionEvent e) {
runnable.run(); runnable.run();
}
}); });
timer.setRepeats(false); timer.setRepeats(false);