File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed
src/main/java/org/scijava/ui Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -116,6 +116,14 @@ public final class DefaultUIService extends AbstractService implements
116
116
/** The default user interface to use, if one is not explicitly specified. */
117
117
private UserInterface defaultUI ;
118
118
119
+ /**
120
+ * When true, {@link #isHeadless()} will return true regardless of the value
121
+ * of the {@code java.awt.headless} system property. When false, {@link
122
+ * #isHeadless()} matches the global JVM headless state defined by {@code
123
+ * java.awt.headless}.
124
+ */
125
+ private boolean forceHeadless ;
126
+
119
127
private boolean activationInvocationPending = false ;
120
128
121
129
// -- UIService methods --
@@ -178,12 +186,14 @@ public boolean isVisible(final String name) {
178
186
179
187
@ Override
180
188
public void setHeadless (final boolean headless ) {
181
- System . setProperty ( "java.awt.headless" , String . valueOf ( headless )) ;
189
+ forceHeadless = headless ;
182
190
}
183
191
184
192
@ Override
185
193
public boolean isHeadless () {
186
- return Boolean .getBoolean ("java.awt.headless" );
194
+ // NB: We do not use java.awt.GraphicsConfiguration.isHeadless()
195
+ // because scijava-common eschews java.awt.* classes when possible.
196
+ return forceHeadless || Boolean .getBoolean ("java.awt.headless" );
187
197
}
188
198
189
199
@ Override
Original file line number Diff line number Diff line change @@ -101,7 +101,22 @@ public interface UIService extends SciJavaService {
101
101
/** Gets whether the UI with the given name or class name is visible. */
102
102
boolean isVisible (String name );
103
103
104
- /** Sets whether the application is running in headless mode (no UI). */
104
+ /**
105
+ * Sets whether the application should run in headless mode (no UI).
106
+ * <p>
107
+ * Note that if the system itself is headless—which can be detected via
108
+ * the {@code java.awt.headless} system property or by calling
109
+ * {@code java.awt.GraphicsEnvironment.isHeadless()}—then calling
110
+ * {@code setHeadless(false)} will have no effect; the system will still be
111
+ * headless, and {@link #isHeadless()} will still return true.
112
+ * </p>
113
+ * <p>
114
+ * But if the system itself is <em>not</em> headless, calling
115
+ * {@code setHeadless(true)} will force {@link #isHeadless()} to return true,
116
+ * instructing the application to behave in a headless manner insofar as it
117
+ * can.
118
+ * </p>
119
+ */
105
120
void setHeadless (boolean isHeadless );
106
121
107
122
/** Gets whether the UI is running in headless mode (no UI). */
You can’t perform that action at this time.
0 commit comments