用JBuilder实现类似Visual Studio的宏扩展功能
2008-01-05 08:06:46 来源:WEB开发网对于Visual Studio的宏,大家应该很熟悉了,这是一篇关于JBuilder实现类似Visual Studio的宏扩展功能,我们就通过对一段代码是否注释掉作为简单例子。大家可以实现自己的一些扩展,算是抛玉引砖了。
支持环境: Jbuilder 4.0 - JBuilder 7.0
使用JBuilder编译时需要在 PRoject ---> Project Properties ---> Required Libaries中加上Jbuilder下的 Open Tool SDK,编译成功后将生成的class打包成一个javaCommentSwitch.jar文件,其中包含这样一个文件META-INF\Manifest.mf,该文件内容如下:
Manifest-Version: 1.0
OpenTools-UI: JavaCommentSwitch
不需要什么具体的讲解,代码如下:
/*===============================================
文件一: IDEActions.java
===============================================*/
/**
*
Title: JBuilder IDE Toolbox
*
Description: http://www.vchelp.net/itbookreview/view_user.asp?user_name=Ghost
*
Copyright: Copyright (c) 2002 Ghost Studio. All Rights Reserved.
*
Company: Ghost Studio
* @author 阿鬼 [mornlee@21cn.com]
* @version 1.0
*/
import com.borland.primetime.actions.ActionGroup;
import com.borland.primetime.editor.EditorContextActionProvider;
import com.borland.primetime.editor.EditorPane;
import javax.swing.Action;
public class IDEActions
{
private static final String STRING_ActionGroupName = "JBuilder IDE Toolbox"; // ActiveGroup's Name
public static final EditorContextActionProvider CONTEXTMENU_ActionProvider = new EditorContextActionProvider()
{
public Action getContextAction(EditorPane target)
{
ActionGroup actionGroup = new ActionGroup();
ActionGroup actionSubGroup = new ActionGroup(STRING_ActionGroupName);
actionSubGroup.add(JavaCommentSwitch.ACTION_GenerateJavaCommentSwitch);
// 此处可以增加更多的功能
// ......
actionGroup.add(actionSubGroup);
return actionGroup;
}
public int getPriority()
{
return 0;
}
};
public IDEActions()
{
}
static class ction
implements EditorContextActionProvider
{
public Action getContextAction(EditorPane target)
{
ActionGroup actionGroup = new ActionGroup();
ActionGroup actionSubGroup = new ActionGroup(STRING_ActionGroupName);
actionSubGroup.add(JavaCommentSwitch.ACTION_GenerateJavaCommentSwitch);
actionGroup.add(actionSubGroup);
return actionGroup;
}
public int getPriority()
{
return 0;
}
ction()
{
}
}
}
/*===============================================
文件二: JavaCommentSwitch.java
===============================================*/
/**
*
Title: JBuilder IDE Toolbox
*
Description: http://www.vchelp.net/itbookreview/view_user.asp?user_name=ghost
*
更多精彩
赞助商链接