sokobanplugin.java
来自「mywork是rcp开发的很好的例子」· Java 代码 · 共 162 行
JAVA
162 行
/************************************************************
*
* 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.sokoban;
import java.net.URL;
import java.util.Calendar;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import es.org.chemi.games.sokoban.util.Constants;
import es.org.chemi.games.sokoban.util.LevelInformation;
import es.org.chemi.games.util.ResourceManager;
/**
* The main plugin class to be used in the desktop.
*/
public class SokobanPlugin extends AbstractUIPlugin
{
//The shared instance.
private static SokobanPlugin plugin;
//Resource bundle.
private ResourceBundle resourceBundle;
//Resource manager.
private static ResourceManager resourceManager = new ResourceManager(Constants.PLUGIN_ID);
/**
* The constructor.
*/
public SokobanPlugin()
{
super();
plugin = this;
}
/**
* Returns the shared instance.
*/
public static SokobanPlugin getDefault()
{
return plugin;
}
public static URL getResource(String path){
return plugin.getBundle().getEntry(path);
}
/**
* Returns the string from the plugin's resource bundle,
* or 'key' if not found.
*/
public static String getResourceString(String key)
{
ResourceBundle bundle= SokobanPlugin.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 void trace(String className, String message)
{
if(SokobanPlugin.getDefault().isDebugging())
if(Platform.getDebugOption("es.org.chemi.games.sokoban/debug/filter").equals("*") || className.indexOf(Platform.getDebugOption("es.org.chemi.games.sokoban/debug/filter").substring(0,Platform.getDebugOption("es.org.chemi.games.sokoban/debug/filter").length()-1)) != -1) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
System.out.println("[Sokoban - " + className + "] " + Calendar.getInstance().getTime() + " - " + message); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
public static ResourceManager getResourceManager()
{
return resourceManager;
}
public void start(BundleContext context) throws Exception
{
super.start(context);
SokobanPlugin.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.sokoban.SokobanPluginResources"); //$NON-NLS-1$
}
catch (MissingResourceException x)
{
resourceBundle = null;
}
// Store default values.
SokobanPlugin.trace(this.getClass().getName(),"Loading default preferences."); //$NON-NLS-1$
IPreferenceStore store = getDefault().getPreferenceStore();
// Store default mode.
store.setDefault("mode",Constants.MODE_ORIGINAL); //$NON-NLS-1$
// Store default level.
store.setDefault(Constants.LEVEL_ORIGINAL,1);
store.setDefault(Constants.LEVEL_EXTRA,1);
store.setDefault(Constants.LEVEL_OTHER,1);
// Strore default level information.
StringBuffer tmp = new StringBuffer();
for(int i=0; i<SokobanMessages.getInt("MainView.levelset.0.maxlevel"); i++)
{
tmp.append(new LevelInformation(i+1,false,"-",0,0,0).toString()); //$NON-NLS-1$
tmp.append("#"); //$NON-NLS-1$
}
store.setDefault(Constants.INFO_ORIGINAL,tmp.toString());
tmp = new StringBuffer();
for(int i=0; i<SokobanMessages.getInt("MainView.levelset.1.maxlevel"); i++)
{
tmp.append(new LevelInformation(i+1,false,"-",0,0,0).toString()); //$NON-NLS-1$
tmp.append("#"); //$NON-NLS-1$
}
store.setDefault(Constants.INFO_EXTRA,tmp.toString());
tmp = new StringBuffer();
for(int i=0; i<SokobanMessages.getInt("MainView.levelset.2.maxlevel"); i++)
{
tmp.append(new LevelInformation(i+1,false,"-",0,0,0).toString()); //$NON-NLS-1$
tmp.append("#"); //$NON-NLS-1$
}
store.setDefault(Constants.INFO_OTHER,tmp.toString());
// Store default sound mode.
store.setDefault(Constants.SOUND_MODE,true);
store.setDefault(Constants.SKIN_MODE,0);
store.setDefault(Constants.KEY_MODE,true);
store.setDefault(Constants.SKIN_TOTAL,2);
}
public void stop(BundleContext context) throws Exception
{
super.stop(context);
SokobanPlugin.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$
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?