Package application

Source Code of application.Application

package application;

import java.awt.Color;
import java.util.Locale;
import java.util.ResourceBundle;

import javax.swing.UIManager;
import javax.swing.plaf.ColorUIResource;

import views.Gui;

import manager.Settings;

public class Application {

  private static Gui app = null;
  public static Settings settings = null;
  public static ResourceBundle messages;

  //--------------------------------------------------------------------
  // Main
  public static void main(String[] args) {
    String language;
       
        //try to open the settings file
    Application.settings = new Settings();

    if(Application.settings.loadFromFile("settings.xml"))
      language = Application.settings.getLanguage();
    // unable to open the config file
    else {
      Application.settings = null;
      language = new String("en");
    }

        // Create local environment
        Locale currentLocale = new Locale(language);
        Application.messages = ResourceBundle.getBundle("languages/MessagesBundle", currentLocale);
       
        // Changes look for interface and tooltips
        try {
          UIManager.put("ToolTip.foreground", new ColorUIResource(Color.black));
            UIManager.put("ToolTip.background", new ColorUIResource(new Color(184, 207, 229)));
            if(Application.settings != null) {//check if the setting file is opened
              if(Application.settings.getLookAndFeel() != "")
                UIManager.setLookAndFeel(Application.settings.getLookAndFeel());
              else
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            }           
      } catch (Exception evt) { System.out.println(evt); };
     
     
    Application.app = new Gui();
    Application.app.setVisible(true);
  }

  /**
   * exit will exit the application by using the System command
   */
  public static void exit() {
    if(Application.app != null)
      Application.app.setVisible(false);
    System.exit(0);
  }

  /**
   * Restart is used to restart the gui part of GTLRegEx to perform
   * changes made b the user in the control panel (skin/language).
   */
  public static void restart() {
   
    // Get the current models
    String regEx = Application.app.getModel().getRegularExpression();
    String text = Application.app.getModel().getText();
   
    // Try to make the gabage collector react
    Application.app.setVisible(false);
    Application.app = null;
    Application.messages = null;
    System.gc();
   
    // Load the changed settings
    Application.settings = new Settings();
    Application.settings.loadFromFile("settings.xml");
   
        // Create local environment
        Locale currentLocale = new Locale(Application.settings.getLanguage());
        Application.messages = ResourceBundle.getBundle("languages/MessagesBundle", currentLocale);
       
        // Changes look for interface and tooltips
        try {
          UIManager.put("ToolTip.foreground", new ColorUIResource(Color.black));
            UIManager.put("ToolTip.background", new ColorUIResource(new Color(184, 207, 229)));
            if(Application.settings != null) {//check if the setting file is opened
              if(Application.settings.getLookAndFeel() != "")
                UIManager.setLookAndFeel(Application.settings.getLookAndFeel());
              else
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            }           
      } catch (Exception evt) { System.out.println(evt); };
     
      // Restart gui and put both the regex and the text back
    Application.app = new Gui();
    Application.app.getModel().setRegEx(regEx);
    Application.app.getModel().setText(text);
    Application.app.setVisible(true);

  }

}
TOP

Related Classes of application.Application

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.