Sparkplugin开发人员指南汉化版free文档格式.docx

上传人:b****5 文档编号:18211120 上传时间:2022-12-14 格式:DOCX 页数:27 大小:96.26KB
下载 相关 举报
Sparkplugin开发人员指南汉化版free文档格式.docx_第1页
第1页 / 共27页
Sparkplugin开发人员指南汉化版free文档格式.docx_第2页
第2页 / 共27页
Sparkplugin开发人员指南汉化版free文档格式.docx_第3页
第3页 / 共27页
Sparkplugin开发人员指南汉化版free文档格式.docx_第4页
第4页 / 共27页
Sparkplugin开发人员指南汉化版free文档格式.docx_第5页
第5页 / 共27页
点击查看更多>>
下载资源
资源描述

Sparkplugin开发人员指南汉化版free文档格式.docx

《Sparkplugin开发人员指南汉化版free文档格式.docx》由会员分享,可在线阅读,更多相关《Sparkplugin开发人员指南汉化版free文档格式.docx(27页珍藏版)》请在冰豆网上搜索。

Sparkplugin开发人员指南汉化版free文档格式.docx

⏹ChatManager—负责处理大多数聊天Chat监听器和过滤器的注册,以及聊天室的创建和检索。

它也可以用来检索ChatFrame用户界面。

⏹SessionManager--包含有关当前会话信息,如连接到服务器,连接的错误和个人存在(presence)变动的通知处理。

⏹SoundManager--用于播放声音。

✧事件处理(EventHandlers):

Spark包含了大量的监听和处理程序,以便把更多插件可以嵌入到Sparkclient。

比较常见的监听和处理程序有:

⏹ChatRoomListener(和ChatRoomListenerAdapter)-允许的插件监听聊天室被打开,关闭和启动。

通常你会使用这个自定义的个人聊天室。

⏹MessageListener--消息接收或发送监听器

⏹ContactGroupListener--联络组变动监听器。

⏹ContactListListener--联系人列表变动监听器。

⏹FileTransferListener--拦截文件传输监听器。

⏹ContextMenuListener--右键弹出菜单(上下文菜单)监听器,允许添加、删除动作或添加删除菜单项。

⏹PresenceListener–人员状态变化监听器。

⏹ContactItemHandler–ContactItem在线状态变化控制监听。

✧组件(Components):

Spark包含了需要在你开发插件时使用的Swing组件,较为常用的有:

⏹MainWindow--该框架包含联系人列表。

您可以使用MainWindow添加新的标签,菜单项或焦点控件。

⏹ChatRoom–聊天室基础的抽象类。

它的实现是ChatRoomImpl和GroupChatRoom。

⏹ChatArea–为TranscriptWindow和ChatInputEditor的基本聊天视图控件。

⏹ContactList–Spark的联系人列表界面控件

⏹ChatRoomButton–聊天室的外观按钮,用于适应聊天室的主题。

Plugin的结构

Plugins是JAR的压缩文件,插件的文件结构如下:

PluginStructure(压缩包机构)

myplugin.jar!

/

|-plugin.xml<

-Plugin定义文件

|-libs/<

-运行插件(Plugin)所用到的类.

plugin.xml文件中指定的主要Plugin类。

样例文件如下所示:

plugin.xml样例

<

?

xmlversion="

1.0"

encoding="

UTF-8"

>

<

!

--GooglePluginStructure-->

plugin>

name>

GoogleDesktopPlugin<

/name>

class>

com.examples.plugins.GooglePlugin<

/class>

author>

DerekDeMoro<

/author>

version>

1.0<

/version>

description>

EnablesuserstofindfilesandemailsrelatingtousersusingGoogleDesktoptechnology.<

/description>

email>

ddman@<

/email>

minSparkVersion>

2.0.6<

/minSparkVersion>

/plugin>

Plugin的安装

你只需要将要安装的插件JAR拖放到你的Spark客户端安装插件目录中。

目录机构

Spark/

|-plugins/<

-将你的SparkPlug插件放到这里。

|-lib/<

-运行你的插件需要的类和类库。

|-resources/<

-资源文件夹,包括其他支持文档和类库.

|-docs/<

-你自己的开发插件的帮助手册和的JavaDoc.

你的插件类必须实现从Spark客户端API插件接口。

该插件接口是用于初始化和关闭插件的方法。

开始编写Sparkplugs

为了建立自己的SparkPlugs,你需要将工程属性中的所有项目设置到ClassPath中,将Sparkplug.zip或Sparplug.tar.gz解压缩,你将看到以下内容:

Sparkplugs/

|-build/<

-使用ANT让你轻松的构建你的插件。

|-images/<

-文档使用的图像文件夹。

|-plugin_development_guide.html/<

-完整的开发指南(本文档)。

|-api/<

-Sparkplug包含的Javadoc文档。

|-spark/<

-spark构建结构,你需要设置Classpath。

|-bin<

-启动文件startup.bat,用于测试Spark。

|-lib<

-包含所有Spark运行需要的包。

|-logs<

-所有的日志存储。

|-plugins<

-所有的插件(plugins)部署到这里。

|-resources<

-包含用于运行在具体操作系统上的本机库。

要设置一个Spark项目,运行在你的IDE,您将需要以下几件事:

✧编译Spark,需要1.4以上版本的JRE;

✧将Sparkplugs/spark/lib和Sparkplugs/spark/lib/windows文件夹添加到Classpath;

✧添加资源目录(Sparkplugins/spark/resource)到本地Classpath中;

✧MainClass-org.jivesoftware.Spark;

✧VM参数--Dplugin=path_to_your_plugin.xml文件,这使您的插件可以运行在IDE以外的环境中;

✧就这些。

我们提供了可以轻松的构建、部署你的插件到你的的Spark测试环境中。

在使用时

BuildingaSparkplug

ToeasilybuildaSparkplug,wehaveaddedasimpleANTscripttocreateadeployedplug.Tocreate,dothefollowing:

1)Copyyourjavasourcefilestothesrcdirectory.

2)Placeanydependencies(besidesSpark)intothelibdirectory.

3)Updatetheplugin.xmlfiletorepresentyourplugin.

4)Gotothebuilddirectory,andtypeantjartobuildyourpluginor

....type"

antrun"

tobuildanddeployyourplugindirectlytoSparkand

haveSparkstartuptotestyourpluginrightaway.

Yournewpluginwillbecalledmyplugin.jar.

Ifyouwishtodeployyourpluginlater,justcopyyournewmyplugin.jartothepluginsdirectoryofyourSparkplugdistrokit.

Enjoy!

Spark是如何做的呢?

所有代码示例可以在examples.jar文件找到。

✧如何创建一个简单的插件

✧如何将我自己的标签到Spark工作空间

✧如何添加一个上下文菜单监听到联系人列表

✧如何添加ContextMenu监听到一个聊天室

✧如何添加菜单到Spark

✧如何添加一个按钮到聊天室

✧如何添加自己喜欢的Spark搜索,比如用户搜索或谷歌搜索在Firefox

✧怎么能拦截文件传输请求

✧如何发送一个文件给其他用户

✧如何控制用户界面和事件的ContactItem处理

✧Spark发生变化时,怎么能通知用户更改时

✧如何添加消息筛选器

✧如何创建一个人对人的聊天室

✧如何创建一个公共会议室

✧如何添加自己的首选项

✧当有新消息是如果进行消息提示

如何创建一个简单的插件

1.实现Plugin

Plugin样例

packageorg.jivesoftware.spark.examples;

importorg.jivesoftware.spark.plugin.Plugin;

/**

*ImplementstheSparkPluginframeworktodisplaythedifferentpossibilitiesusing

*Spark.

*/

publicclassExamplePluginimplementsPlugin{

/**

*CalledafterSparkisloadedtoinitializethenewplugin.

publicvoidinitialize(){

System.out.println("

WelcomeToSpark"

);

}

*CalledwhenSparkisshuttingdowntoallowforpersistenceofinformation

*orreleasingofresources.

publicvoidshutdown(){

*ReturntrueiftheSparkcanshutdownonusersrequest.

*@returntrueifSparkcanshutdownonusersrequest.

publicbooleancanShutDown(){

returntrue;

*Iscalledwhenauserexplicitlyaskedtouninstallthisplugin.

*Thepluginownerisresponsibletocleanupanyresourcesand

*removeanycomponentsinstallinSpark.

publicvoiduninstall(){

//Removeallresourcesbelongingtothisplugin.

}

如何将我自己的标签到Spark工作空间

1.实现Plugin;

2.取得Spark用户界面:

Workspace;

3.取得WorkspacePane,这是Spark的Tab面板;

4.添加您自己的Tab

添加Tab到Spark

publicclassExamplePluginimplementsPlugin{..

*AddsatabtoSpark

privatevoidaddTabToSpark(){

//GetWorkspaceUIfromSparkManager

Workspaceworkspace=SparkManager.getWorkspace();

//RetrievetheTabbedPanefromtheWorkspaceUI.

JTabbedPanetabbedPane=workspace.getWorkspacePane();

//AddownTab.

tabbedPane.addTab("

MyPlugin"

newJButton("

Hello"

));

}.

如何在联系人列表中添加一个上下文菜单监听者

2.在Spark的Workspace中取得ContactList

3.添加ContactListListener

添加ContextMenu监听到ContactList

privatevoidaddContactListListener(){

//RetrievetheContactListfromtheWorkspace

ContactListcontactList=workspace.getContactList();

//CreateanactiontoaddtotheContextMenu

finalActionsayHelloAction=newAbstractAction(){

publicvoidactionPerformed(ActionEventactionEvent){

JOptionPane.showMessageDialog(SparkManager.getMainWindow(),"

WelcometoSpark"

};

sayHelloAction.putValue(Action.NAME,"

SayHelloToMe"

contactList.addContextMenuListener(newContextMenuListener(){

publicvoidpoppingUp(Objectobject,JPopupMenupopup){

if(objectinstanceofContactItem){

popup.add(sayHelloAction);

//在菜单上加个Action

publicvoidpoppingDown(JPopupMenupopup){

publicbooleanhandleDefaultAction(MouseEvente){

returnfalse;

});

如何在一个聊天室ChatRom中添加上下文菜单监听

2.添加ChatRoomListener到ChatManager

3.从ChatRoom获取TranscriptWindow或ChatInputEditor

4.添加ContactMenuListener到ChatArea

添加ChatRoomListener到ChatManager,TranscriptWindoworChatInputEditor

privatevoidaddContactListenerToChatRoom(){

//RetrieveaChatManagerfromSparkManager

ChatManagerchatManager=SparkManager.getChatManager();

finalContextMenuListenerlistener=newContextMenuListener(){

finalTranscriptWindowchatWindow=(TranscriptWindow)object;

ActionclearAction=newAbstractAction(){

try{

chatWindow.insert("

Myowntext:

)"

catch(BadLocationExceptione){

e.printStackTrace();

clearAction.putValue(Action.NAME,"

Insertmyowntext"

popup.add(clearAction);

//AddaChatRoomListenertotheChatManagertoallowfornotifications

//whenaroomisbeingopened.Note:

IwilluseaChatRoomListenerAdapterforbrevity.

chatManager.addChatRoomListener(newChatRoomListenerAdapter(){

publicvoidchatRoomOpened(ChatRoomroom){

room.getTranscriptWindow().addContextMenuListener(listener);

publicvoidchatRoomLeft(ChatRoomroom){

room.getTranscriptWindow().removeContextMenuListener(listener);

如何添加菜单到Spark

2.从SparkManager取得MainWindow

3.创建一个菜单或是添加一个菜单项到现有的菜单中

添加菜单到Spark

*AddsanewmenuandchildmenuitemtoSpark.

privatevoidaddMenuToSpark(){

//RetrievetheMainWindowUIfromSpark.

finalMainWindowmainWindow=SparkManager.getMainWindow();

//CreatenewMenu

JMenumyPluginMenu=newJMenu("

MyPluginMenu"

//CreateActiontotestMenuinstall.

ActionshowMessage=newAbstractAction(){

JOptionPane.showMessageDialog(mainWindow,"

Yeah,Itworks."

//Givethemenuitemaname.

showMessage.putValue(Action.NAME,"

Checkifitworks"

//AddtoMenu

myPluginMenu.add(showMessage);

//AddMenuToSpark

mainWindow.getJMenuBar().add(myPluginMenu);

如何添加一个按钮到聊天室

2.添加ChatRoomListener到ChatManager

3.当房间打开时,添加ChatRoomButton到ChatRoom的ToolBar上

新增一个按钮到ChatRoomButton

*AddsabuttontoeachChatRoomthatisopened.

privatevoidaddChatRoomButton(){

//RetrieveChatManagerfromtheSparkManager

//CreateanewChatRoomButton.

finalChatRoomButto

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 考试认证 > 从业资格考试

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1