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