Ignore:
Timestamp:
2016-05-24T17:30:46+02:00 (4 years ago)
Author:
stoecker
Message:

GSOC core rework - LayerManager, fix #12863, by Michael Zangl

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/util/GuiHelper.java

    r10172 r10271  
    131131
    132132    /**
     133     * Executes synchronously a runnable in
     134     * <a href="http://docs.oracle.com/javase/tutorial/uiswing/concurrency/dispatch.html">Event Dispatch Thread</a>.
     135     * <p>
     136     * Passes on the exception that was thrown to the thread calling this. The exception is wrapped in a {@link RuntimeException} if it was a normal {@link Throwable}.
     137     * @param task The runnable to execute
     138     * @see SwingUtilities#invokeAndWait
     139     * @since 10271
     140     */
     141    public static void runInEDTAndWaitWithException(Runnable task) {
     142        if (SwingUtilities.isEventDispatchThread()) {
     143            task.run();
     144        } else {
     145            try {
     146                SwingUtilities.invokeAndWait(task);
     147            } catch (InterruptedException e) {
     148                Main.error(e);
     149            } catch (InvocationTargetException e) {
     150                if (e.getCause() instanceof RuntimeException) {
     151                    throw (RuntimeException) e.getCause();
     152                } else {
     153                    throw new RuntimeException("Exception while clling " + task, e.getCause());
     154                }
     155            }
     156        }
     157    }
     158
     159    /**
    133160     * Executes synchronously a callable in
    134161     * <a href="http://docs.oracle.com/javase/tutorial/uiswing/concurrency/dispatch.html">Event Dispatch Thread</a>
     
    156183                return null;
    157184            }
     185        }
     186    }
     187
     188    /**
     189     * This function fails if it was not called from the EDT thread.
     190     * @throws IllegalStateException if called from wrong thread.
     191     * @since 10271
     192     */
     193    public static void assertCallFromEdt() {
     194        if (!SwingUtilities.isEventDispatchThread()) {
     195            throw new IllegalStateException(
     196                    "Needs to be called from the EDT thread, not from " + Thread.currentThread().getName());
    158197        }
    159198    }
Note: See TracChangeset for help on using the changeset viewer.