- private static ConfigBundle config;
- private static UiConfigBundle uiconfig;
- private static StringIdBundle trans;
- private static DataLoader cache;
- private static StringIdGuiBundle transGui;
- private static BasicLibrary lib;
- private static File coverDir;
- private static File readerTmp;
- private static File remoteDir;
- private static String configDir;
- private static TraceHandler tracer;
- private static TempFiles tempFiles;
-
- static {
+ static private Instance instance;
+ static private Object instancelock = new Object();
+
+ private ConfigBundle config;
+ private UiConfigBundle uiconfig;
+ private StringIdBundle trans;
+ private DataLoader cache;
+ private StringIdGuiBundle transGui;
+ private BasicLibrary lib;
+ private File coverDir;
+ private File readerTmp;
+ private File remoteDir;
+ private String configDir;
+ private TraceHandler tracer;
+ private TempFiles tempFiles;
+
+ /**
+ * Initialise the instance -- if already initialised, nothing will happen.
+ * <p>
+ * Before calling this method, you may call {@link Bundles#setDirectory(String)}
+ * if wanted.
+ */
+ static public void init() {
+ init(false);
+ }
+
+ /**
+ * Initialise the instance -- if already initialised, nothing will happen unless
+ * you pass TRUE to <tt>force</tt>.
+ * <p>
+ * Before calling this method, you may call {@link Bundles#setDirectory(String)}
+ * if wanted.
+ * <p>
+ * Note: forcing the initialisation can be dangerous, so make sure to only make
+ * it under controlled circumstances -- for instance, at the start of the
+ * program, you could call {@link Instance#init()}, change some settings because
+ * you want to force those settings (it will also forbid users to change them!)
+ * and then call {@link Instance#init(boolean)} with <tt>force</tt> set to TRUE.
+ *
+ * @param force force the initialisation even if already initialised
+ */
+ static public void init(boolean force) {
+ synchronized (instancelock) {
+ if (instance == null || force) {
+ instance = new Instance();
+ }
+ }
+
+ }
+
+ /**
+ * Force-initialise the {@link Instance} to a known value.
+ * <p>
+ * Usually for DEBUG/Test purposes.
+ *
+ * @param instance the actual Instance to use
+ */
+ static public void init(Instance instance) {
+ Instance.instance = instance;
+ }
+
+ /**
+ * The (mostly unique) instance of this {@link Instance}.
+ *
+ * @return the (mostly unique) instance
+ */
+ public static Instance getInstance() {
+ return instance;
+ }
+
+ /**
+ * Actually initialise the instance.
+ * <p>
+ * Before calling this method, you may call {@link Bundles#setDirectory(String)}
+ * if wanted.
+ */
+ protected Instance() {