Package giggler.ui.plugin

Source Code of giggler.ui.plugin.UiPlugin

package giggler.ui.plugin;

import giggler.Configuration;
import giggler.Management;
import giggler.Plugin;
import giggler.PluginApi;
import giggler.ui.Fonts;
import giggler.ui.Settings;
import giggler.ui.impl.Frontend;


public class UiPlugin implements Plugin, Plugin.Composer, Plugin.Consumer, Plugin.Contributor
{
  public static final String PLUGIN = "giggler-ui";
 
    private static final String PLATFORM_PLUGIN = "giggler";

    private UIDefaults defaults = new UIDefaults();
    private Frontend frontend = null;

  private Configuration configuration = null;
  private Management management = null;
 
 
  public UiPlugin() {
  }
 
  public float getVersion() {
    return 1.0f;
  }

  public String getName() {
    return PLUGIN;
  }

    public void init() {

    }
   
    public boolean start() {

      frontend = new Frontend();
        frontend.setConfiguration(configuration);
        frontend.setManagement(management);

        return (frontend != null);
    }

  public boolean shutdown() {
     
    return true;
  }

  @SuppressWarnings("unchecked")
  public <T extends PluginApi> T getAccess(Class<T> pluginApi) {

      if (pluginApi == Settings.class)
          return (T) new UISettings();

      if (pluginApi == Fonts.class)
          return (T) new UIFonts();

      return null;
  }

  // COMPOSER ------------------------------------------------------------------------------------------------
 
    public boolean available(Plugin plugin) {

        if (PLATFORM_PLUGIN.equalsIgnoreCase(plugin.getName())) {
           
            configuration = plugin.getAccess(Configuration.class);
            configuration.setDefaults(defaults);
           
            UIEnvironment.setup(configuration);
           
            management = plugin.getAccess(Management.class);
           
            return true;
        }
       
        return false;
    }

    public void retired(Plugin plugin) {
     
        if (PLATFORM_PLUGIN.equalsIgnoreCase(plugin.getName())) {
         
          configuration = null;
        }
    }
   
    public String[] getDependencies() {

        return new String[] { PLATFORM_PLUGIN };
    }
   
    // CONSUMER ------------------------------------------------------------------------------------------------

  public boolean accept(Plugin plugin) {
   
//    if (PLATFORM_PLUGIN.equalsIgnoreCase(plugin.getName())) {
//     
//      Configuration configuration = plugin.getAccess(Configuration.class);
//      configuration.setDefaults(defaults);
//     
//      Environment.setup(configuration);
//     
//      frontend.setConfiguration(configuration);
//    }
   
      return frontend.available(plugin);
  }

  public void release(Plugin plugin) {
     
    if (frontend != null)
      frontend.retired(plugin);
  }

    // CONTRIBUTOR ------------------------------------------------------------------------------------------------

    public String[] getConsumers() {

        return new String[] { PLUGIN };
    }
}
TOP

Related Classes of giggler.ui.plugin.UiPlugin

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.