Crossfire JXClient, Trunk
SwingUtilities2.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff
19  * Copyright (C) 2006-2017,2019-2023 Andreas Kirschbaum
20  * Copyright (C) 2010-2012,2014-2018,2020-2023 Nicolas Weeger
21  */
22 
23 package com.realtime.crossfire.jxclient.util;
24 
25 import java.awt.GraphicsEnvironment;
26 import java.lang.reflect.InvocationTargetException;
27 import javax.swing.SwingUtilities;
28 import org.jetbrains.annotations.NotNull;
29 
34 public class SwingUtilities2 {
35 
39  private SwingUtilities2() {
40  }
41 
47  public static void invokeAndWait(@NotNull final Runnable runnable) {
48  if (Thread.currentThread().isInterrupted()) {
49  return;
50  }
51  if (GraphicsEnvironment.isHeadless()) {
52  // skip in unit tests
53  return;
54  }
55  if (SwingUtilities.isEventDispatchThread()) {
56  runnable.run();
57  } else {
58  try {
59  SwingUtilities.invokeAndWait(runnable);
60  } catch (final InterruptedException ignored) {
61  Thread.currentThread().interrupt();
62  } catch (final InvocationTargetException ex) {
63  throw new AssertionError(ex);
64  }
65  }
66  }
67 
73  public static void invokeLater(@NotNull final Runnable runnable) {
74  if (SwingUtilities.isEventDispatchThread()) {
75  runnable.run();
76  } else {
77  SwingUtilities.invokeLater(runnable);
78  }
79  }
80 
81 }
com.realtime.crossfire.jxclient.util.SwingUtilities2.SwingUtilities2
SwingUtilities2()
Definition: SwingUtilities2.java:39
com.realtime.crossfire.jxclient.util.SwingUtilities2.invokeAndWait
static void invokeAndWait(@NotNull final Runnable runnable)
Definition: SwingUtilities2.java:47
com.realtime.crossfire.jxclient.util.SwingUtilities2.invokeLater
static void invokeLater(@NotNull final Runnable runnable)
Definition: SwingUtilities2.java:73
com.realtime.crossfire.jxclient.util.SwingUtilities2
Definition: SwingUtilities2.java:34