Skip to content

Commit 7ea047d

Browse files
committed
UIService: add headless methods
Add isHeadless and setHeadless methods to the UIService. These methods delegate directly to the "java.awt.headless" system property.
1 parent 2252e33 commit 7ea047d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/main/java/org/scijava/ui/DefaultUIService.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,17 @@ public boolean isVisible(final String name) {
203203
return ui.isVisible();
204204
}
205205

206+
207+
@Override
208+
public void setHeadless(final boolean headless) {
209+
System.setProperty("java.awt.headless", String.valueOf(headless));
210+
}
211+
212+
@Override
213+
public boolean isHeadless() {
214+
return Boolean.getBoolean("java.awt.headless");
215+
}
216+
206217
@Override
207218
public UserInterface getDefaultUI() {
208219
if (defaultUI != null) return defaultUI;
@@ -527,5 +538,4 @@ private void addUserInterface(final String name, final UserInterface ui) {
527538
private String getTitle() {
528539
return appService.getApp().getTitle();
529540
}
530-
531541
}

src/main/java/org/scijava/ui/UIService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ public interface UIService extends SciJavaService {
102102
/** Gets whether the UI with the given name or class name is visible. */
103103
boolean isVisible(String name);
104104

105+
/** Sets whether the application is running in headless mode (no UI). */
106+
void setHeadless(boolean isHeadless);
107+
108+
/** Gets whether the UI is running in headless mode (no UI). */
109+
boolean isHeadless();
110+
105111
/**
106112
* Gets the default user interface.
107113
*

0 commit comments

Comments
 (0)