|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
再说说缺点:首先java功能强大的背后是其复杂性,就拿web来说,当今流行的框架有很多,什么struts,spring,jQuery等等,而这无疑增加了java的复杂性。
关于VisualStudio的宏,人人应当很熟习了,这是一篇关于JBuilder完成相似VisualStudio的宏扩大功效,我们就经由过程对一段代码是不是正文失落作为复杂例子。人人能够完成本人的一些扩大,算是抛玉引砖了。
撑持情况:Jbuilder4.0-JBuilder7.0
利用JBuilder编译时必要在Project--->ProjectProperties--->RequiredLibaries中加上Jbuilder下的OpenToolSDK,编译乐成后将天生的class打包成一个JavaCommentSwitch.jar文件,个中包括如许一个文件META-INFManifest.mf,该文件内容以下:
Manifest-Version:1.0
OpenTools-UI:JavaCommentSwitch
不必要甚么具体的解说,代码以下:
/*===============================================
文件一:IDEActions.java
===============================================*/
/**
*
Title:JBuilderIDEToolbox
*
Description:http://www.vchelp.net/itbookreview/view_user.asp?user_name=ghost
*
Copyright:Copyright(c)2002GhostStudio.AllRightsReserved.
*
Company:GhostStudio
*@author阿鬼[mornlee@21cn.com]
*@version1.0
*/
importcom.borland.primetime.actions.ActionGroup;
importcom.borland.primetime.editor.EditorContextActionProvider;
importcom.borland.primetime.editor.EditorPane;
importjavax.swing.Action;
publicclassIDEActions
{
privatestaticfinalStringSTRING_ActionGroupName="JBuilderIDEToolbox";//ActiveGroupsName
publicstaticfinalEditorContextActionProviderCONTEXTMENU_ActionProvider=newEditorContextActionProvider()
{
publicActiongetContextAction(EditorPanetarget)
{
ActionGroupactionGroup=newActionGroup();
ActionGroupactionSubGroup=newActionGroup(STRING_ActionGroupName);
actionSubGroup.add(JavaCommentSwitch.ACTION_GenerateJavaCommentSwitch);
//此处能够增添更多的功效
//......
actionGroup.add(actionSubGroup);
returnactionGroup;
}
publicintgetPriority()
{
return0;
}
};
publicIDEActions()
{
}
staticclassction
implementsEditorContextActionProvider
{
publicActiongetContextAction(EditorPanetarget)
{
ActionGroupactionGroup=newActionGroup();
ActionGroupactionSubGroup=newActionGroup(STRING_ActionGroupName);
actionSubGroup.add(JavaCommentSwitch.ACTION_GenerateJavaCommentSwitch);
actionGroup.add(actionSubGroup);
returnactionGroup;
}
publicintgetPriority()
{
return0;
}
ction()
{
}
}
}
/*===============================================
文件二:JavaCommentSwitch.java
===============================================*/
/**
*
Title:JBuilderIDEToolbox
*
Description:http://www.vchelp.net/itbookreview/view_user.asp?user_name=ghost
*
Copyright:Copyright(c)2002GhostStudio.AllRightsReserved.
*
Company:GhostStudio
*@author阿鬼[mornlee@21cn.com]
*@version1.0
*/
importcom.borland.jbuilder.jot.*;
importcom.borland.jbuilder.node.JBProject;
importcom.borland.jbuilder.node.JavaFileNode;
importcom.borland.primetime.editor.*;
importcom.borland.primetime.ide.Browser;
importcom.borland.primetime.node.FileNode;
importcom.borland.primetime.node.Node;
importcom.borland.primetime.vfs.Url;
importjava.awt.event.ActionEvent;
importjava.beans.PropertyChangeEvent;
importjava.beans.PropertyChangeListener;
importjava.io.File;
importjava.io.PrintStream;
importjavax.swing.*;
importjavax.swing.text.JTextComponent;
importjavax.swing.text.Keymap;
publicclassJavaCommentSwitchextendsEditorAction
implementsPropertyChangeListener
{
privatestaticfinalStringversionString="0.1";
publicstaticEditorActionACTION_CreateJavaCommentSwitch=newJavaCommentSwitch("JavaCommentSwitch");
protectedstaticStringSTR_LONG_DESCRIPTION="Comment/Uncommentforselection.";//形态条显现
protectedstaticStringSTR_SHORT_DESCRIPTION="Comment/Uncommentforselection.";
publicstaticEditorActionACTION_GenerateJavaCommentSwitch=newJavaCommentSwitch("JavaCommentSwitch",true);
protectedstaticStringMENU_STR_LONG_DESCRIPTION="Comment/Uncommentforselection";
protectedstaticStringMENU_STR_SHORT_DESCRIPTION="Comment/Uncomment";
staticBrowserbrowser=null;
privateEditorPanetarget;
privateStringerrorMessageText;
privatebooleanisMenuAction;
publicJavaCommentSwitch(Stringname)
{
super(name);
target=null;
errorMessageText="";
isMenuAction=false;
}
publicJavaCommentSwitch(Stringname,booleanisMenuAction)
{
super(name);
target=null;
errorMessageText="";
this.isMenuAction=isMenuAction;
}
publicstaticvoidinitOpenTool(bytemajorVersion,byteminorVersion)
{
if(majorVersion<4)//撑持Jbuilder4.0以上
return;
EditorManager.registerContextActionProvider(IDEActions.CONTEXTMENU_ActionProvider);
ACTION_GenerateJavaCommentSwitch.putValue("LongDescription",MENU_STR_LONG_DESCRIPTION);
ACTION_GenerateJavaCommentSwitch.putValue("ShortDescription",MENU_STR_SHORT_DESCRIPTION);
EditorActions.addBindableEditorAction(ACTION_CreateJavaCommentSwitch);
ACTION_CreateJavaCommentSwitch.putValue("LongDescription",STR_LONG_DESCRIPTION);
ACTION_CreateJavaCommentSwitch.putValue("ShortDescription",STR_SHORT_DESCRIPTION);
Keymapkeymap=EditorManager.getKeymap();//撑持快速键ALT+F10
if(keymap!=null)
{
KeyStrokestroke[]=keymap.getKeyStrokesForAction(ACTION_CreateJavaCommentSwitch);
if(stroke==null)
keymap.addActionForKeyStroke(KeyStroke.getKeyStroke(java.awt.Event.F10,
java.awt.Event.ALT_MASK),ACTION_CreateJavaCommentSwitch);
}
EditorManager.addPropertyChangeListener((PropertyChangeListener)ACTION_CreateJavaCommentSwitch);
}
publicvoidactionPerformed(ActionEventevt)
{
target=getEditorTarget(evt);
NodetheNode=getNode();
if(theNode==null)
return;
JBProjectproj=(JBProject)theNode.getProject();
JotClasstheClass=getClass(theNode);
if(isMenuAction)
if(theClass!=null)
runJavaCommentSwitch();
else
JOptionPane.showMessageDialog(null,
"CurrentEditortargetisnotajavaclass.",
"Errorcreatingjavadoc",0);
}
/**
*@description
*
*@param
*@return
*@exception
*/
privatebooleanrunJavaCommentSwitch()
{
Stringselection=target.getSelectedText();
StringnewSelection="";
//往失落正文
if(selection.trim().startsWith("/*")&&selection.trim().endsWith("*/"))
{
StringBuffersb=newStringBuffer(selection);
newSelection=sb.substring(2,selection.length()-2);
}
//增加正文
else
{
newSelection=String.valueOf(String.valueOf((newStringBuffer("/*")).append(selection).append("*/")));
}
target.replaceSelection(newSelection);
returntrue;
}
publicvoidpropertyChange(PropertyChangeEventevt)
{
StringpropertyName=evt.getPropertyName();
if(propertyName.equals("keymap"))
{
Keymapkeymap=EditorManager.getKeymap();
if(keymap!=null)
{
KeyStrokestroke[]=keymap.getKeyStrokesForAction(ACTION_CreateJavaCommentSwitch);
if(stroke==null)
keymap.addActionForKeyStroke(KeyStroke.getKeyStroke(java.awt.Event.F10,
java.awt.Event.ALT_MASK),ACTION_CreateJavaCommentSwitch);
}
}
}
protectedNodegetNode()
{
Browserbrowser=Browser.getActiveBrowser();
Nodenode=browser.getActiveNode();
if((nodeinstanceofJavaFileNode)&&(node.getProject()instanceofJBProject))
returnnode;
else
returnnull;
}
protectedJotClassgetClass(Nodenode)
{
if((nodeinstanceofJavaFileNode)&&(node.getProject()instanceofJBProject))
{
JBProjectproject=(JBProject)node.getProject();
Stringfilename=((JavaFileNode)node).getUrl().getFile();
JotPackagespkg=project.getJotPackages();
Urlurl=newUrl(newFile(filename));
JotFilejfile=pkg.getFile(url);
JotClassjclasses[]=jfile.getClasses();
if(jclasses.length>1)
{
System.err.println("Morethanoneclassfoundinsourcefile");
errorMessageText="Morethanoneclassfoundinsourcefile";
returnnull;
}
if(jclasses.length==0)
{
System.err.println("Noclassesfoundinsourcefile");
errorMessageText="Noclassesfoundinsourcefile";
returnnull;
}else
{
returnjclasses[0];
}
}else
{
returnnull;
}
}
}
关于第二点:俺问问你,如果是企业级项目的话,诸如RMI,EJB,等一些关键技术,这些难道都不需要学么?如果光是使用jsp,servlet,javabean的话。 |
|