From 382aa51de3153c3a329401f2d92f1708d89bad4a Mon Sep 17 00:00:00 2001 From: Joachim Klein Date: Wed, 7 Mar 2018 19:42:15 +0100 Subject: [PATCH] FileSetting: On-first-use allocation of file selector The FileSetting object stores a FileSelector, which is allocated using defaultSelector() during construction. It can also be set via setFileSelector(). To avoid constructing a FileSelector (and thus call into the Swing/AWT Java package) in headless / command-line mode, we allocate the default selector on first use, i.e., whenever the selector is null in a call to getFileSelector(). --- prism/src/settings/FileSetting.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/prism/src/settings/FileSetting.java b/prism/src/settings/FileSetting.java index 6cb8edc3..09d9dd0d 100644 --- a/prism/src/settings/FileSetting.java +++ b/prism/src/settings/FileSetting.java @@ -72,8 +72,6 @@ public class FileSetting extends Setting super(name, value, comment, owner, editableWhenMultiple); if(value != null) validFile = value.isFile(); else validFile = false; - - selector = defaultSelector(); } public FileSetting(String name, File value, String comment, SettingOwner owner, boolean editableWhenMultiple, FontColorConstraint constraint) @@ -81,8 +79,6 @@ public class FileSetting extends Setting super(name, value, comment, owner, editableWhenMultiple, constraint); if(value != null) validFile = value.isFile(); else validFile = false; - - selector = defaultSelector(); } public void checkObjectWithConstraints(Object obj) throws SettingException @@ -153,6 +149,9 @@ public class FileSetting extends Setting public FileSelector getFileSelector() { + if (selector == null) { + selector = defaultSelector(); + } return selector; }