/* * Moonlight|3D * Copyright (C) 2005 The Moonlight|3D team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Created on Jan 5, 2005 */ package ml; /** * \package ml * * This package contains the main class for Moonlight|3D. */ import ml.core.State; import ml.core.exceptions.Exception; import ml.core.helper.Property; import ml.core.helper.Value; import ml.core.preferences.PreferencesGroup; import ml.ui.core.SplashScreen; import ml.ui.core.UIPalette; import com.trolltech.qt.gui.QApplication; import com.trolltech.qt.gui.QFont; import com.trolltech.qt.gui.QPlastiqueStyle; import com.trolltech.qt.gui.QStyleFactory; /** * This is the main application class for Moonlight|3D. * * @author gregor */ public class ML3D { /** * The main constructor for the application * * @throws Exception if something went terribly wrong */ public ML3D(String[] args) throws Exception { /* * args[] contains the full path to Moonlight|3D in the filesystem. * This parameter is only passed to main because there is no way * to determine this in Java and should be treated as internal. * Therefore it is removed from the command line here and treated * separately. */ String[] strippedArgs=new String[args.length-1]; String installDir=args[0]; if(args.length>1) { System.arraycopy(args, 1, strippedArgs, 0, args.length-1); } args=strippedArgs; /* * On Windows, quotation marks around the installation directory * argument are neccessary to protect white spaces in it, but * the Windows shell does not remove them before passing the * argument to the program. Instead, we have to work around that * here. */ if(installDir.charAt(0)=='"') { installDir=installDir.substring(1,installDir.length()-2); } QApplication qApp=new QApplication(args); State state=ml.core.State.getInstance(); state.setBatchMode(false); state.setInstallationDirectory(installDir); state.setCommandLineArguments(args); state.logger().info("Moonlight|3D " + State.Version.asString() + " starting"); SplashScreen.open(); SplashScreen.setStartupMessage("Loading preferences..."); state.getPreferencesManager().loadPreferences(); SplashScreen.setStartupMessage("Loading plugins..."); state.getPluginManager().loadPlugins(); PreferencesGroup preferences=new PreferencesGroup(); preferences.setName("GeneralUI"); Property useSystemTheme=new Property(preferences); useSystemTheme.setName("useSystemTheme"); useSystemTheme.setType(Value.Type.Boolean); useSystemTheme.setValue(false); state.getPreferencesManager().getCurrentPreferences().addPreferencesGroup(preferences); SplashScreen.setStartupMessage("Applying preferences..."); state.getPreferencesManager().applyLoadedPreferences(); if(useSystemTheme.getBooleanValue()==false) { // QApplication.setStyle(new QPlastiqueStyle()); QApplication.setStyle(QStyleFactory.create("plastique")); QApplication.setPalette(new UIPalette()); // QApplication.setFont(new QFont(QApplication.font().family(),8)); QApplication.setFont(new QFont("Trebuchet",8)); } SplashScreen.setStartupMessage("Running startup scripts..."); state.getScriptManager().runStartupScripts(); SplashScreen.setStartupMessage("Creating main window..."); ml.ui.core.propertysheet.PropertySheetDefinition.parsePropertySheetDefinitions(); state.createMainWindow(); state.getDocumentManager().createNewMainDocument("MoonlightScene"); SplashScreen.remove(); state.getMainWindow().show(); QApplication.exec(); state.getPluginManager().unloadPlugins(); state.getPreferencesManager().updatePreferenceFiles(); } /** * The main entry point for Moonlight|3D * * @param args command line arguments */ public static void main(String[] args) { try { ML3D app=new ML3D(args); } catch(ml.core.exceptions.Exception e) { System.err.print(e.getFullText()); } } }