Package net.sf.tomcatmanager

Source Code of net.sf.tomcatmanager.TomcatManagerGui

package net.sf.tomcatmanager;

import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.SwingUtilities;

import com.apple.eawt.Application;
import com.apple.eawt.ApplicationAdapter;
import com.apple.eawt.ApplicationEvent;

/**
* Tomcat Manager is minimalistic application that allows you to monitor and
* modify whether the local Tomcat is running.
*
* This class is the GUI program entry point. It creates and links the
* model-view-controller for the Tomcat Manager.
*
* @author Martin Edling Andersson, Leonard van Driel
*/
public class TomcatManagerGui {

  private static transient Logger logger = Logger.getLogger(TomcatManagerGui.class.toString());

  public final static Level DEFAULT_LOG_LEVEL = Level.INFO;

  // model-view-controller
  private Controller controller;
  private Model model;
  private MainView mainView;
  private PreferencesView preferencesView;
  private LogView logView;
  private ViewHelper viewHelper;

  public void init() {
    logger.setLevel(TomcatManagerGui.DEFAULT_LOG_LEVEL);

    // setup model-view-controller
    model = new Model();
    mainView = new MainView();
    preferencesView = new PreferencesView();
    logView = new LogView();
    viewHelper = new ViewHelper();
    controller = new Controller();

    // Macify it.
    addMacOSXEventHandling();

    // link model-view-controller
    controller.setModel(model);
    controller.setMainView(mainView);
    controller.setPreferencesView(preferencesView);
    controller.setLogView(logView);
    controller.setViewHelper(viewHelper);
    model.setController(controller);
    mainView.setController(controller);
    preferencesView.setController(controller);
    logView.setController(controller);
    viewHelper.setController(controller);

    viewHelper.postInit();
    model.postInit();
    mainView.postInit();
    logView.postInit();
    preferencesView.postInit();
    controller.postInit();

    controller.startServerStatusLoop();
  }

  /**
   * Creates an Application Listener for Apple/Application Events so that they
   * can be caught and handled.
   */
  private void addMacOSXEventHandling() {

    Application.getApplication().addApplicationListener(new ApplicationAdapter() {
      @Override
      public void handleQuit(ApplicationEvent event) {
        controller.tryQuit();
      }

      @Override
      public void handlePreferences(ApplicationEvent event) {
        ViewHelper.placeWindowHIGCompliant(preferencesView);
        preferencesView.loadFromModel();
        preferencesView.setVisible(true);
      }

      @Override
      public void handleAbout(ApplicationEvent event) {
        ViewHelper.showAbout();
        event.setHandled(true);
      }
    });

    System.setProperty("apple.laf.useScreenMenuBar", Boolean.toString(true));
    System.setProperty("com.apple.mrj.application.apple.menu.about.name", About.NAME);
    System.setProperty("apple.awt.showGrowBox", Boolean.toString(true));
    System.setProperty("apple.awt.textantialiasing", Boolean.toString(true));
    System.setProperty("apple.awt.brushMetalLook", Boolean.toString(false));

    Application.getApplication().setDefaultMenuBar(viewHelper.createMenuBar());
    Application.getApplication().addAboutMenuItem();
    Application.getApplication().setEnabledAboutMenu(true);
    Application.getApplication().addPreferencesMenuItem();
    Application.getApplication().setEnabledPreferencesMenu(true);
  }

  public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        new TomcatManagerGui().init();
      }
    });
  }
}
TOP

Related Classes of net.sf.tomcatmanager.TomcatManagerGui

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.