source: trunk/src/org/apollo/ApolloSystem.java@ 1270

Last change on this file since 1270 was 1270, checked in by bln4, 5 years ago

On profile creation a new parameter has been introducted. By passing a map, the user is able to nominate settings frames for which to be notified of their construction.

The above functionalty has been used to programmatically establish the frame number for a users credentials frame.

On user account creation, the users credential frame is migrated to the <username>-credentials folder and a redirect is setup. Functionality for doing this has been generisised and placed in FrameIO.

File size: 7.7 KB
Line 
1package org.apollo;
2
3import java.util.Collection;
4import java.util.HashSet;
5import java.util.Set;
6
7import javax.swing.UIManager;
8
9import org.apollo.actions.ApolloActions;
10import org.apollo.agents.MelodySearch;
11import org.apollo.audio.ApolloPlaybackMixer;
12import org.apollo.audio.RecordManager;
13import org.apollo.audio.SampledAudioManager;
14import org.apollo.audio.util.MultiTrackPlaybackController;
15import org.apollo.audio.util.PlaybackClock;
16import org.apollo.audio.util.SoundDesk;
17import org.apollo.gui.FrameLayoutDaemon;
18import org.apollo.gui.FramePlaybackBarRenderer;
19import org.apollo.gui.FrameRenderPasses;
20import org.apollo.io.AudioPathManager;
21import org.apollo.io.SampledAudioFileImporter;
22import org.apollo.util.ApolloSystemLog;
23import org.apollo.util.Mutable;
24import org.apollo.widgets.FramePlayer;
25import org.expeditee.actions.Actions;
26import org.expeditee.core.BlockingRunnable;
27import org.expeditee.gio.EcosystemManager;
28import org.expeditee.gio.EcosystemManager.Ecosystem;
29import org.expeditee.gio.GraphicsManager;
30import org.expeditee.gio.InputManager.WindowEventListener;
31import org.expeditee.gio.InputManager.WindowEventType;
32import org.expeditee.gui.Browser;
33import org.expeditee.gui.Frame;
34import org.expeditee.gui.FrameIO;
35import org.expeditee.items.Item;
36import org.expeditee.items.Text;
37import org.expeditee.settings.UserSettings;
38
39/**
40 * Provides initialization and shutdown services for the Apollo system.
41 *
42 * @author Brook Novak
43 *
44 */
45public final class ApolloSystem {
46
47 private static final String APOLLO_ICON = "org/apollo/icons/mainicon.png";
48
49 // TODO: Create actual frames
50 public static final String SYSTEM_FRAMESET_NAME = "apollosystem";
51 public static final String HELP_TOP_FRAMENAME = SYSTEM_FRAMESET_NAME + 2;
52
53 // TODO: How to get good results: collection (moteef) and querry
54 // TODO: How to omit indexing on tracks
55 public static final String HELP_MELODYSEARCH_FRAMENAME = SYSTEM_FRAMESET_NAME + 3;
56
57 public static final String SETTINGS_NAME_TIMELINE_RMARGIN = "timelinerightmargin";
58 public static final String SETTINGS_NAME_TIMELINE_LMARGIN = "timelineleftmargin";
59
60 public static boolean useQualityGraphics = true;
61
62 private static boolean hasInitialized = false;
63
64 private ApolloSystem()
65 {
66 }
67
68 /**
69 * Initializes Apollo mod for expeditee - prepares all subsystems.
70 */
71 public static void initialize()
72 {
73 if (hasInitialized) return;
74
75 ApolloSystemLog.println("Initializing...");
76
77 // Ensure that resources are released before the application is closed.
78 EcosystemManager.getInputManager().addWindowEventListener(new WindowEventListener() {
79 @Override
80 public void onWindowEvent(WindowEventType type)
81 {
82 if (type != WindowEventType.WINDOW_CLOSED) return;
83 ApolloSystem.shutdown();
84 }
85 });
86
87 EcosystemManager.getInputManager().registerGestureListener(ApolloGestureActions.getInstance());
88 EcosystemManager.getInputManager().addInputEventToGestureTranslator(new ApolloKBMGestureTranslator());
89
90 // Set title
91 //Browser._theBrowser.setTitle("Apollo");
92
93 loadSettings();
94
95 ApolloSystemLog.println(" Preparing sub-systems...");
96
97 SampledAudioManager.getInstance();
98
99 RecordManager.getInstance();
100
101 ApolloPlaybackMixer.getInstance();
102
103 FrameLayoutDaemon.getInstance();
104
105 FrameRenderPasses.getInstance();
106
107 PlaybackClock.getInstance();
108
109 FramePlaybackBarRenderer.getInstance();
110
111 // Setup for importing audio
112 EcosystemManager.getDragAndDropManager().addCustomFileImporter(new SampledAudioFileImporter());
113
114 ApolloSystemLog.println(" Loading actions and agents...");
115
116 // Add apollo actions
117 Actions.LoadMethods(ApolloActions.class);
118
119 Set<String> agents = new HashSet<String>();
120 agents.add(MelodySearch.class.getName());
121
122 Collection<String> omitted = Actions.addAgents(agents);
123
124 for (String agent : omitted) {
125
126 if (agent == null || agent.length() == 0) continue;
127
128 String name = agent;
129
130 int index = agent.lastIndexOf('.');
131 if (index > 0 && agent.length() > (index - 1)) {
132 name = agent.substring(index);
133 }
134 ApolloSystemLog.println(" WARNING: Failed to add agent \"" + name + "\"");
135
136 }
137
138 ApolloSystemLog.println(" Loading banks...");
139 SoundDesk.getInstance(); // loads upon creation
140
141 ApolloSystemLog.println("Initialized");
142
143 hasInitialized = true;
144 }
145
146 /**
147 * TODO: This is temporary and should be integrated with expeditees settings system.. once it is desinged
148 * to support plugins...
149 *
150 * When invoked, the apollo setting frame is loaded and parsed... setting apollo-specific settings.
151 */
152 public static void loadSettings()
153 {
154 // Load apollo settings frame from the default profile
155 Frame profile = FrameIO.LoadProfile(UserSettings.DEFAULT_PROFILE_NAME);
156 if (profile == null) {
157 try {
158 profile = FrameIO.CreateNewProfile(UserSettings.DEFAULT_PROFILE_NAME, null, null);
159 } catch (Exception e) {
160 e.printStackTrace();
161 return;
162 }
163 }
164 assert(profile != null);
165
166 for (Item i : profile.getItems()) {
167 if (i instanceof Text) {
168 Text textItem = (Text)i;
169
170 if (textItem.getText().toLowerCase().trim().startsWith(SETTINGS_NAME_TIMELINE_LMARGIN)) {
171 Mutable.Integer val = stripNameValueStringInteger(textItem.getText());
172 if (val != null) {
173 FrameLayoutDaemon.getInstance().setTimelineMargins(
174 val.value,
175 FrameLayoutDaemon.getInstance().getRightMargin());
176 }
177
178 } else if (textItem.getText().toLowerCase().trim().startsWith(SETTINGS_NAME_TIMELINE_RMARGIN)) {
179 Mutable.Integer val = stripNameValueStringInteger(textItem.getText());
180 if (val != null) {
181 FrameLayoutDaemon.getInstance().setTimelineMargins(
182 FrameLayoutDaemon.getInstance().getLeftMargin(),
183 val.value);
184 }
185 }
186 }
187 }
188
189 }
190
191 private static Mutable.Integer stripNameValueStringInteger(String namevalue)
192 {
193 assert (namevalue != null);
194 int valueIndex = namevalue.indexOf(':') + 1;
195 if (valueIndex == 0 || valueIndex >= (namevalue.length() - 1)) return null;
196
197 try {
198 int value = Integer.parseInt(namevalue.substring(valueIndex));
199 return Mutable.createMutableInteger(value);
200 } catch (NumberFormatException e) { /* Consume*/ }
201
202 return null;
203 }
204
205
206
207 /**
208 * Releases all resources currently used by the SampledAudioManager.
209 */
210 public static void shutdown()
211 {
212 ApolloSystemLog.println("Saving banks...");
213 SoundDesk.getInstance().saveMasterMix();
214 SoundDesk.getInstance().saveMixes();
215
216 FramePlayer.saveTypedFrames();
217
218 ApolloSystemLog.println("Releasing resources...");
219
220 ApolloPlaybackMixer.getInstance().releaseResources();
221 RecordManager.getInstance().releaseResources(); // blocking
222 MultiTrackPlaybackController.getInstance().releaseResources();
223
224 ApolloSystemLog.println("Subsystems shutdown");
225 }
226
227 /**
228 * @return
229 * True if has initialized.
230 */
231 public static boolean isInitialized()
232 {
233 return hasInitialized;
234 }
235
236
237
238 /**
239 * The apollo main just ensures that apollo is initialized during startup.
240 *
241 * This may eventually become redundant once Expeditee implements a plugin system
242 * that allows a plugin / mod to initialize itself at started...
243 *
244 * @param args
245 */
246 public static void main(String[] args)
247 {
248 if (Browser.ECOSYSTEM_TYPE == Ecosystem.Swing) {
249 try {
250 UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
251 } catch (Exception e) {
252 e.printStackTrace();
253 return;
254 }
255 }
256
257 // Window icon must be set before initialisation
258 GraphicsManager.setWindowIcon(APOLLO_ICON);
259
260 // Run expeditee
261 Browser.main(args);
262
263 if (!Boolean.getBoolean("auth")) {
264 // If not running with authentication/login, then proceed with initializing Apollo
265 EcosystemManager.getMiscManager().runOnGIOThread(new BlockingRunnable() {
266 public void execute() {
267 ApolloSystem.initialize();
268 }
269 });
270 }
271 }
272
273}
Note: See TracBrowser for help on using the repository browser.