gamesplugin.java

来自「mywork是rcp开发的很好的例子」· Java 代码 · 共 115 行

JAVA
115
字号
/************************************************************
 *
 * Copyright (c) 2003 Chemi. All rights reserved.
 * 
 * This program and the accompanying materials
 * are made available under the terms of the MIT License
 * which accompanies this distribution, and is available at
 * http://www.opensource.org/licenses/mit-license.html
 *
 ************************************************************/

package es.org.chemi.games;

import java.util.MissingResourceException;
import java.util.ResourceBundle;

import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

import es.org.chemi.games.util.Constants;
import es.org.chemi.games.util.ResourceManager;

/**
 * The main plugin class to be used in the desktop.
 */
public class GamesPlugin extends AbstractUIPlugin 
{
	//The shared instance.
	private static GamesPlugin plugin;
	//Resource bundle.
	private ResourceBundle resourceBundle;
	//Resource manager.
	private static ResourceManager resourceManager = null;
		
	/**
	 * The constructor.
	 */
	public GamesPlugin() 
	{
		super();
		plugin = this;
	}

	/**
	 * Returns the shared instance.
	 */
	public static GamesPlugin getDefault() 
	{
		return plugin;
	}

	/**
	 * Returns the string from the plugin's resource bundle,
	 * or 'key' if not found.
	 */
	public static String getResourceString(String key) 
	{
		ResourceBundle bundle= GamesPlugin.getDefault().getResourceBundle();
		try 
		{
			return bundle.getString(key);
		}
		catch (MissingResourceException e) 
		{
			return key;
		}
	}

	/**
	 * Returns the plugin's resource bundle,
	 */
	public ResourceBundle getResourceBundle() 
	{
		return resourceBundle;
	}
	
	public static ResourceManager getResourceManager()
	{
		if(resourceManager == null)
			resourceManager = new ResourceManager(Constants.PLUGIN_ID);
		return resourceManager;
	}
	
	public void start(BundleContext context) throws Exception
	{
	    super.start(context);
	    
		resourceManager = new ResourceManager(Constants.PLUGIN_ID);
		
		GamesPlugin.trace(this.getClass().getName(),"Loading " + this.getBundle().getSymbolicName() + " plug-in (version: " + this.getBundle().getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION) + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		
		try 
		{
			resourceBundle= ResourceBundle.getBundle("es.org.chemi.games.GamesPluginResources"); //$NON-NLS-1$
		}
		catch (MissingResourceException x) 
		{
			resourceBundle = null;
		}
	}

	public void stop(BundleContext context) throws Exception
	{
		super.stop(context);
		GamesPlugin.trace(this.getClass().getName(),"Unloading " + this.getBundle().getSymbolicName() + " plug-in (version: " + this.getBundle().getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION) + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		resourceManager.dispose();
	}
	
	public static void trace(String className, String message)
	{
//		if(GamesPlugin.getDefault().isDebugging())
//			if(Platform.getDebugOption("es.org.chemi.games/debug/filter").equals("*") || className.indexOf(Platform.getDebugOption("es.org.chemi.games/debug/filter").substring(0,Platform.getDebugOption("es.org.chemi.games/debug/filter").length()-1)) != -1) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
//					System.out.println("[Common - " + className + "] " + Calendar.getInstance().getTime() + " - " + message); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?