SJGuiClient.java :  » Source-Control » sourcejammer » org » sourcejammer » client » gui » Java Open Source

Java Open Source » Source Control » sourcejammer 
sourcejammer » org » sourcejammer » client » gui » SJGuiClient.java
/*
 *  Copyright (C) 2001, 2002 Robert MacGrogan
 *
 *  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 *
 * $Archive: SourceJammer$
 * $FileName: SJGuiClient.java$
 * $FileID: 4121$
 *
 * Last change:
 * $AuthorName: Timo Haberkern$
 * $Date: 9/11/03 5:35 AM$
 * $Comment: Added Metuia and Plastic3D Look and Feel$
 */


package org.sourcejammer.client.gui;

import java.awt.Frame;
import java.awt.Rectangle;
import java.awt.Window;
import java.util.Properties;

import javax.swing.JOptionPane;

import org.sourcejammer.client.DisplayTextLibrary;
import org.sourcejammer.client.HistoryTypeMapper;
import org.sourcejammer.client.SourceJammerClient;
import org.sourcejammer.client.gui.action.ActionCentral;
import org.sourcejammer.client.gui.action.Actions;
import org.sourcejammer.client.gui.action.SkinLFAction;
import org.sourcejammer.client.gui.conf.UserPrefs;
import org.sourcejammer.util.AppConfig;

/**
 * Title:   $FileName: SJGuiClient.java$
 * @author $AuthorName: Timo Haberkern$
 * @version $VerNum: 7$
 * $KeyWordsOff: $<br><br>
 * 
 * 
 * Provides main method for launching SJ Gui client application.
 */
public class SJGuiClient implements Actions {

  private static SJPrimaryWindow moSJ = null;

  public SJGuiClient() {
  }

  public static void main(String[] args){

    try {

      String sURL = null;
      String sConfPath = null;

      // ejm -check if old sURL param is there

      if (args.length > 1) {
        sURL = args[0];
        sConfPath = args[1];
      }
      else {
        sConfPath = args[0];
      }


      AppConfig.getInstance(sConfPath);
      SourceJammerClient client = SourceJammerClient.getInstance(sConfPath);
      try{
        DisplayTextLibrary.initializeInstance(client.getDisplayTextPropertiesFileName());
      }
      catch (Throwable thr){
        thr.printStackTrace();
        Frame owner = new Frame();
        Window temp = new Window(owner);
        String[] message = {"SourceJammer is having trouble with the display ",
                            "text file. Either the file cannot be found or it ",
                            "is improperly formatted.", " ",
                            "Please check the file and restart SourceJammer ",
                            "when the problem is resolved."};
        JOptionPane.showMessageDialog(temp, message, "Error in display text file", JOptionPane.ERROR_MESSAGE);
        System.exit(0);
      }

      try{
        HistoryTypeMapper.initializeInstance();
      }
      catch (Throwable thr){
        thr.printStackTrace();
        Frame owner = new Frame();
        Window temp = new Window(owner);
        String[] message = {"SourceJammer is having trouble with the history type ",
                            "mapper file (filehist.props). Either the file cannot ",
                            "be found or it is improperly formatted.", " ",
                            "Please check the file and restart SourceJammer ",
                            "when the problem is resolved."};
        JOptionPane.showMessageDialog(temp, message, "Error in hisory type mapper file", JOptionPane.ERROR_MESSAGE);
        System.exit(0);
      }

      //Initialize process thread by calling ProcessCentral.
      org.sourcejammer.client.gui.process.ProcessCentral.getInstance();

      CommandCentral oCentral = CommandCentral.getInstance();
     //oCentral.setArchiveName(sArchive);

      // ejm -if sURL is not there then don't set it
      if(sURL != null)
        oCentral.setServerURL(sURL);

      moSJ = new SJPrimaryWindow();

      String sInitialLAF = SourceJammerClient.getInstance().getInitialLookAndFeel();
      
      sInitialLAF = UserPrefs.getInstance().getString(UserPrefs.LOOK_AND_FEEL, sInitialLAF);
      
      if (sInitialLAF.equals(AppConfig.LookAndFeel.WINDOWS)){
        ActionCentral.getInstance().fireActionThisThread(act_WINDOWS_LOOK_AND_FEEL);
      }
      else if (sInitialLAF.equals(AppConfig.LookAndFeel.MOTIF)){
        //MOTIF no longer supported.
        ActionCentral.getInstance().fireActionThisThread(act_METAL_LOOK_AND_FEEL);
      }
      else if (sInitialLAF.equals(AppConfig.LookAndFeel.KUNSTOFF)){
        ActionCentral.getInstance().fireActionThisThread(act_K_LOOK_AND_FEEL);
      }
      else if (sInitialLAF.equals(AppConfig.LookAndFeel.METAL)){
        ActionCentral.getInstance().fireActionThisThread(act_METAL_LOOK_AND_FEEL);
      }
      else if (sInitialLAF.equals(AppConfig.LookAndFeel.PLASTIC)) {
        ActionCentral.getInstance().fireActionThisThread(Actions.act_PLASTIC_LOOK_AND_FEEL);
      }
      else if (sInitialLAF.equals(AppConfig.LookAndFeel.METOUIA)) {
        ActionCentral.getInstance().fireActionThisThread(Actions.act_METOUIA_LOOK_AND_FEEL);
      }
      else{
        String skin = UserPrefs.getInstance().getString(UserPrefs.SKIN_LF_THEME, "Skin LF");
        SkinLFAction act = (SkinLFAction)ActionCentral.getInstance().getAction(Actions.act_SKIN_LF);
        act.setThemeFile(new java.io.File(skin));
        ActionCentral.getInstance().fireActionThisThread(Actions.act_SKIN_LF);
      }

      UserPrefs prefs = UserPrefs.getInstance();

      //Get proxy settings.
      Properties sysProps = System.getProperties();
      boolean proxyEnabled = prefs.getBoolean(UserPrefs.PROXY_ENABLED, false);
      if (proxyEnabled){
        sysProps.setProperty(UserPrefs.SYS_PROXY_ENABLED, "true");
      }
      else{
        sysProps.setProperty(UserPrefs.SYS_PROXY_ENABLED, "false");
      }
      
      String notThere = "No it's not there.";
      String host = prefs.getString(UserPrefs.PROXY_HOST, notThere);
      if (host != notThere){
        sysProps.setProperty(UserPrefs.SYS_PROXY_HOST, host);
      }
      String port = prefs.getString(UserPrefs.PROXY_PORT, notThere);
      if (port != notThere){
        sysProps.setProperty(UserPrefs.SYS_PROXY_PORT, port);
      }
      String user = prefs.getString(UserPrefs.PROXY_USER, notThere);
      if (user != notThere){
        sysProps.setProperty(UserPrefs.SYS_PROXY_USER, user);
      }

      //Window bounds.
      Rectangle bounds = prefs.getStartupWindowBounds();

      //moSJ.getProjectTree().setModel(GuiUtil.createTreeModel(ndRoot));
      boolean maximized = UserPrefs.getInstance().getBoolean(UserPrefs.WINDOW_MAX, false);
      GJApp.launch(moSJ, "SourceJammer!", bounds, maximized);

      while (! oCentral.isAppWindowRendered()){}

      System.out.println("Firing connect action.");
      ActionCentral.getInstance().fireAction(act_CONNECT_LIST_ARCHIVES);


    }
    catch(Exception ex){
      //Let's display the message if we can and kill the splash screen.
      Frame owner = new Frame();
      Window temp = new Window(owner);
      String[] message = {ex.getMessage()};
      JOptionPane.showMessageDialog(temp, message, "Error in starting SJ client", JOptionPane.ERROR_MESSAGE);

      if (StartGUI.splash != null){
        StartGUI.splash.window.dispose();
      }

      ex.printStackTrace();
      System.exit(0);
    }

  }

  private void setProxySettings(){
    Properties sysProps = System.getProperties();
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.