1a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta/*
2a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * Copyright (c) 2009-2010 jMonkeyEngine
3a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * All rights reserved.
4a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta *
5a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * Redistribution and use in source and binary forms, with or without
6a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * modification, are permitted provided that the following conditions are
7a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * met:
8a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta *
9a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * * Redistributions of source code must retain the above copyright
10a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta *   notice, this list of conditions and the following disclaimer.
11a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta *
12a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * * Redistributions in binary form must reproduce the above copyright
13a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta *   notice, this list of conditions and the following disclaimer in the
14a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta *   documentation and/or other materials provided with the distribution.
15a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta *
16a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta *   may be used to endorse or promote products derived from this software
18a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta *   without specific prior written permission.
19a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta *
20a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta */
32a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartapackage com.jme3.system;
33a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
34a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport com.jme3.asset.AssetManager;
35a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport com.jme3.audio.AudioRenderer;
36a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport com.jme3.input.SoftTextDialogInput;
37a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport java.io.File;
38a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport java.io.InputStream;
39a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport java.net.URL;
40a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport java.util.logging.Level;
41a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport java.util.logging.Logger;
42a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
43a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartapublic class JmeSystem {
44a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
45a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    private static JmeSystemDelegate systemDelegate;
46a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
47a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public static void setSystemDelegate(JmeSystemDelegate systemDelegate) {
48a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        JmeSystem.systemDelegate = systemDelegate;
49a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
50a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
51a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public static synchronized File getStorageFolder() {
52a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        checkDelegate();
53a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        return systemDelegate.getStorageFolder();
54a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
55a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
56a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public static String getFullName() {
57a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        checkDelegate();
58a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        return systemDelegate.getFullName();
59a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
60a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
61a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public static InputStream getResourceAsStream(String name) {
62a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        checkDelegate();
63a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        return systemDelegate.getResourceAsStream(name);
64a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
65a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
66a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public static URL getResource(String name) {
67a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        checkDelegate();
68a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        return systemDelegate.getResource(name);
69a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
70a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
71a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public static boolean trackDirectMemory() {
72a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        checkDelegate();
73a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        return systemDelegate.trackDirectMemory();
74a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
75a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
76a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public static void setLowPermissions(boolean lowPerm) {
77a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        checkDelegate();
78a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        systemDelegate.setLowPermissions(lowPerm);
79a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
80a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
81a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public static boolean isLowPermissions() {
82a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        checkDelegate();
83a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        return systemDelegate.isLowPermissions();
84a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
85a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
86a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public static void setSoftTextDialogInput(SoftTextDialogInput input) {
87a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        checkDelegate();
88a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        systemDelegate.setSoftTextDialogInput(input);
89a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
90a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
91a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public static SoftTextDialogInput getSoftTextDialogInput() {
92a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        checkDelegate();
93a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        return systemDelegate.getSoftTextDialogInput();
94a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
95a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
96a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public static AssetManager newAssetManager(URL configFile) {
97a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        checkDelegate();
98a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        return systemDelegate.newAssetManager(configFile);
99a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
100a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
101a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public static AssetManager newAssetManager() {
102a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        checkDelegate();
103a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        return systemDelegate.newAssetManager();
104a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
105a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
106a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public static boolean showSettingsDialog(AppSettings sourceSettings, final boolean loadFromRegistry) {
107a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        checkDelegate();
108a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        return systemDelegate.showSettingsDialog(sourceSettings, loadFromRegistry);
109a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
110a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
111a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public static Platform getPlatform() {
112a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        checkDelegate();
113a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        return systemDelegate.getPlatform();
114a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
115a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
116a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public static JmeContext newContext(AppSettings settings, JmeContext.Type contextType) {
117a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        checkDelegate();
118a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        return systemDelegate.newContext(settings, contextType);
119a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
120a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
121a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public static AudioRenderer newAudioRenderer(AppSettings settings) {
122a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        checkDelegate();
123a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        return systemDelegate.newAudioRenderer(settings);
124a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
125a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
126a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public static void initialize(AppSettings settings) {
127a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        checkDelegate();
128a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        systemDelegate.initialize(settings);
129a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
130a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
131a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    @SuppressWarnings("unchecked")
132a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    private static void checkDelegate() {
133a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        if (systemDelegate == null) {
134a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            Class<JmeSystemDelegate> systemDelegateClass;
135a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            try {
136a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                systemDelegateClass = (Class<JmeSystemDelegate>) Class.forName("com.jme3.system.JmeDesktopSystem");
137a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                systemDelegate = systemDelegateClass.newInstance();
138a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            } catch (InstantiationException ex) {
139a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                Logger.getLogger(JmeSystem.class.getName()).log(Level.SEVERE, "No JmeSystemDelegate specified, cannot instantiate default JmeDesktopSystem:\n{0}", ex);
140a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            } catch (IllegalAccessException ex) {
141a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                Logger.getLogger(JmeSystem.class.getName()).log(Level.SEVERE, "No JmeSystemDelegate specified, cannot instantiate default JmeDesktopSystem:\n{0}", ex);
142a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            } catch (ClassNotFoundException ex) {
143a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                Logger.getLogger(JmeSystem.class.getName()).log(Level.SEVERE, "No JmeSystemDelegate specified, cannot instantiate default JmeDesktopSystem:\n{0}", ex);
144a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            }
145a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        }
146a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
147a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta}
148