1 package net.sf.openrocket.startup;
3 import net.sf.openrocket.database.ComponentPresetDao;
4 import net.sf.openrocket.database.MotorDatabase;
5 import net.sf.openrocket.l10n.ClassBasedTranslator;
6 import net.sf.openrocket.l10n.DebugTranslator;
7 import net.sf.openrocket.l10n.ExceptionSuppressingTranslator;
8 import net.sf.openrocket.l10n.Translator;
9 import net.sf.openrocket.logging.LogHelper;
10 import net.sf.openrocket.logging.LogLevel;
11 import net.sf.openrocket.logging.LogLevelBufferLogger;
12 import net.sf.openrocket.logging.PrintStreamLogger;
15 * A class that provides singleton instances / beans for other classes to utilize.
17 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
19 public final class Application {
21 private static LogHelper logger;
22 private static LogLevelBufferLogger logBuffer;
24 private static Translator baseTranslator = new DebugTranslator(null);
26 private static MotorDatabase motorSetDatabase;
28 private static ComponentPresetDao componentPresetDao;
30 private static Preferences preferences;
32 private static ExceptionHandler exceptionHandler;
34 // Initialize the logger to something sane for testing without executing Startup
36 setLogOutputLevel(LogLevel.DEBUG);
40 * Return whether to use additional safety code checks.
42 public static boolean useSafetyChecks() {
43 // Currently default to false unless openrocket.debug.safetycheck is defined
44 String s = System.getProperty("openrocket.debug.safetycheck");
45 if (s != null && !(s.equalsIgnoreCase("false") || s.equalsIgnoreCase("off"))) {
52 * Retrieve the logger to be used in logging. By default this returns
53 * a logger that outputs to stdout/stderr even if not separately initialized,
54 * useful for development and debugging.
56 public static LogHelper getLogger() {
61 * Set the logger to be used in logging. Note that calling this will only have effect
62 * on not-yet loaded classes, as the instance is stored in a static variable.
64 public static void setLogger(LogHelper logger) {
65 Application.logger = logger;
71 * Return the log buffer.
73 * @return the logBuffer or null if not initialized
75 public static LogLevelBufferLogger getLogBuffer() {
80 * Set the log buffer logger. The logger must be separately configured
81 * to receive the logging.
83 public static void setLogBuffer(LogLevelBufferLogger logBuffer) {
84 Application.logBuffer = logBuffer;
89 * Set the logging to output the specified log level and upwards to standard output.
91 * @param level the minimum logging level to output.
93 public static void setLogOutputLevel(LogLevel level) {
94 logger = new PrintStreamLogger();
95 for (LogLevel l : LogLevel.values()) {
96 if (l.atLeast(level)) {
97 ((PrintStreamLogger) logger).setOutput(l, System.out);
105 * Return the translator to use for obtaining translated strings.
106 * @return a translator.
108 public static Translator getTranslator() {
109 Translator t = baseTranslator;
110 t = new ClassBasedTranslator(t, 1);
111 t = new ExceptionSuppressingTranslator(t);
116 * Set the translator used in obtaining translated strings.
117 * @param translator the translator to set.
119 public static void setBaseTranslator(Translator translator) {
120 Application.baseTranslator = translator;
125 * @return the preferences
127 public static Preferences getPreferences() {
132 * @param preferences the preferences to set
134 public static void setPreferences(Preferences preferences) {
135 Application.preferences = preferences;
139 * @return the exceptionHandler
141 public static ExceptionHandler getExceptionHandler() {
142 return exceptionHandler;
146 * @param exceptionHandler the exceptionHandler to set
148 public static void setExceptionHandler(ExceptionHandler exceptionHandler) {
149 Application.exceptionHandler = exceptionHandler;
153 * Return the database of all thrust curves loaded into the system.
155 public static MotorDatabase getMotorSetDatabase() {
156 return motorSetDatabase;
160 * Set the database of thrust curves loaded into the system.
162 public static void setMotorSetDatabase(MotorDatabase motorSetDatabase) {
163 Application.motorSetDatabase = motorSetDatabase;
166 public static ComponentPresetDao getComponentPresetDao() {
167 return componentPresetDao;
171 public static void setComponentPresetDao(ComponentPresetDao componentPresetDao) {
172 Application.componentPresetDao = componentPresetDao;