Author: tchemit Date: 2008-01-18 01:47:19 +0000 (Fri, 18 Jan 2008) New Revision: 176 Added: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorer.java Log: l'application :) Added: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorer.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorer.java (rev 0) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorer.java 2008-01-18 01:47:19 UTC (rev 176) @@ -0,0 +1,121 @@ +/* +* \#\#% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, +* Tony Chemit +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program 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 General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* \#\#% */ +package fr.cemagref.simexplorer.is; + +import fr.cemagref.simexplorer.is.ui.swing.JConfigUI; +import org.codelutin.i18n.I18n; +import org.codelutin.option.ui.ConfigTableModel; + +import java.io.IOException; + +/** @author tony */ +public class SimExplorer { + + /** le context principal de l'application */ + protected static SimExplorerContext context; + + /** l'ui principale de l'application */ + protected static SimExplorerMainUI ui; + + public static SimExplorerContext getContext() { + checkInitContext(); + return context; + } + + public static SimExplorerMainUI getUI() { + checkInitContext(); + if (ui == null) { + ui = new SimExplorerMainUI(); + } + return ui; + } + + public static void reloadUI() { + ui = null; + JConfigUI.reloadUI(); + } + + /** + * initialisation de l'application : + * <p/> + * chargement du context + * + * @param args les arguments passés à l'application + */ + public static void init(String... args) { + + // init context + context = new SimExplorerContext(); + + // init i18n + I18n.initISO88591(); + + // init parser + context.initParser(args); + + // init config + context.initConfig(); + + // save config + try { + context.save(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + /** + * Lancement de l'ui. + * <p/> + * TODO ne doit être lancée que si nécessaire. + */ + public static void launch() { + + getUI().setVisible(true); + } + + public static void main(String... args) throws Exception { + + init(args); + + // launch actions required + context.getParser().doAllActions(); + + // show edit config if first launch + if (SimExplorer.context.isFirstLaunch()) { + JConfigUI.showUI(context.getConfig(), ConfigTableModel.TypeModel.all); + } + + // launch ui only if required + if (!context.isQuit() && context.isLaunchUI()) { + launch(); + } + + } + + protected SimExplorer() { + // protected restricted access + } + + protected static void checkInitContext() { + if (context == null) { + throw new IllegalStateException("context is null, you must init first the " + SimExplorer.class.getName() + " class via init method"); + } + } +}
participants (1)
-
tchemit@users.labs.libre-entreprise.org