Skip to content

Commit 9de270c

Browse files
committed
UIService: make isVisible methods more permissive
If the requested UI does not exist in the context, no need to throw an exception -- it's not visible. :-) If _no_ UI exists in the context, no worries -- not visible.
1 parent 1f93f64 commit 9de270c

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

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

+7-12
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@ public void addUI(final String name, final UserInterface ui) {
138138
public void showUI() {
139139
if (disposed) return;
140140
final UserInterface ui = getDefaultUI();
141-
if (ui == null) throw noUIsAvailableException();
141+
if (ui == null) {
142+
throw new IllegalStateException("No UIs available. " +
143+
"Please add a component containing a UIPlugin " +
144+
"(e.g., scijava-ui-swing) to your class-path.");
145+
}
142146
showUI(ui);
143147
}
144148

@@ -165,17 +169,14 @@ public void showUI(final UserInterface ui) {
165169
@Override
166170
public boolean isVisible() {
167171
final UserInterface ui = getDefaultUI();
168-
if (ui == null) throw noUIsAvailableException();
172+
if (ui == null) return false;
169173
return ui.isVisible();
170174
}
171175

172176
@Override
173177
public boolean isVisible(final String name) {
174178
final UserInterface ui = uiMap().get(name);
175-
if (ui == null) {
176-
throw new IllegalArgumentException("No such user interface: " + name);
177-
}
178-
return ui.isVisible();
179+
return ui != null && ui.isVisible();
179180
}
180181

181182
@Override
@@ -533,10 +534,4 @@ private void addUserInterface(final String name, final UserInterface ui) {
533534
private String getTitle() {
534535
return appService.getApp().getTitle();
535536
}
536-
537-
private IllegalStateException noUIsAvailableException() {
538-
return new IllegalStateException("No UIs available. " +
539-
"Please add a component containing a UIPlugin " +
540-
"(e.g., scijava-ui-swing) to your class-path.");
541-
}
542537
}

0 commit comments

Comments
 (0)