NetBeans下OpenOffice二次开发

一、软件要求

JDK NetBeans OpenOffice OpenOffice_SDK

软件的配置参考OpenOffice官方帮助文档之Installation Guide

二、例子:Hello World

    1.Project Wizard :

    参考OpenOffcie.org->NetBeans->Intgration目录下的OpenOffice Add-On Project Type之Project Wizard

    Step4后可以根据需要修改Addon.xcu文件,修改方法OOo之恋(二)

2.添加一个新类XXXX,类名与工程名同名如TestAddOn(注意大小写),路径与CentralRegistrationClass.java同目录。文件内容参考TestAddOn.java文件。

    3.修改类XXXX的dispatch函数

     if ( aURL.Protocol.compareTo("org.openoffice.testaddon.testaddon:") == 0 )

     //其中org.openoffice.testaddon.testaddon:改为xcu文件中的OfficeMenuBar下的节点的

     //的oor:name属性

{

if ( aURL.Path.compareTo("Hello") == 0 )//Hello改为相应菜单对应的URL的值的:

//后面的字符串

{

// add your own code here

JOptionPane.showMessageDialog(null,"Hello World");

return;

}

else if(aURL.Path.compareTo("Test") == 0)//同上

{

JOptionPane.showMessageDialog(null,"Just Test");

return;

}

}

    4.修改类XXXX的queryDispatch函数:

    if ( aURL.Protocol.compareTo("org.openoffice.testaddon.testaddon:") == 0 )

    //其中org.openoffice.testaddon.testaddon:改为xcu文件中的OfficeMenuBar下的节点的

    //的oor:name属性

{

if ( aURL.Path.compareTo("Hello") == 0 )//Hello改为相应菜单对应的URL的值的:

//后面的字符串

return this;

else if(aURL.Path.compareTo("Test") == 0)//同上

return this;

}

return null;

TestAddOn.java

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

 

package org.openoffice.testaddon;

 

import com.sun.star.uno.UnoRuntime;

import com.sun.star.uno.XComponentContext;

import com.sun.star.lib.uno.helper.Factory;

import com.sun.star.lang.XSingleComponentFactory;

import com.sun.star.registry.XRegistryKey;

import com.sun.star.lib.uno.helper.WeakBase;

import javax.swing.*;

/**

*

* @author admin

*/

 

public final class TestAddOn extends WeakBase

implements com.sun.star.lang.XServiceInfo,

com.sun.star.frame.XDispatchProvider,

com.sun.star.lang.XInitialization,

com.sun.star.frame.XDispatch

{

private final XComponentContext m_xContext;

private com.sun.star.frame.XFrame m_xFrame;

private static final String m_implementationName = TestAddOn.class.getName();

private static final String[] m_serviceNames = {

"com.sun.star.frame.ProtocolHandler" };

public TestAddOn( XComponentContext context )

{

m_xContext = context;

};

public static XSingleComponentFactory __getComponentFactory( String sImplementationName ) {

XSingleComponentFactory xFactory = null;

if ( sImplementationName.equals( m_implementationName ) )

xFactory = Factory.createComponentFactory(TestAddOn.class, m_serviceNames);

return xFactory;

}

public static boolean __writeRegistryServiceInfo( XRegistryKey xRegistryKey ) {

return Factory.writeRegistryServiceInfo(m_implementationName,

m_serviceNames,

xRegistryKey);

}

// com.sun.star.lang.XServiceInfo:

public String getImplementationName() {

return m_implementationName;

}

public boolean supportsService( String sService ) {

int len = m_serviceNames.length;

for( int i=0; i < len; i++) {

if (sService.equals(m_serviceNames[i]))

return true;

}

return false;

}

public String[] getSupportedServiceNames() {

return m_serviceNames;

}

// com.sun.star.frame.XDispatchProvider:

public com.sun.star.frame.XDispatch queryDispatch( com.sun.star.util.URL aURL,

String sTargetFrameName,

int iSearchFlags )

{

if ( aURL.Protocol.compareTo("org.openoffice.testaddon.testaddon:") == 0 )

{

if ( aURL.Path.compareTo("Hello") == 0 )

return this;

else if(aURL.Path.compareTo("Test") == 0)

return this;

}

return null;

}

// com.sun.star.frame.XDispatchProvider:

public com.sun.star.frame.XDispatch[] queryDispatches(

com.sun.star.frame.DispatchDescriptor[] seqDescriptors )

{

int nCount = seqDescriptors.length;

com.sun.star.frame.XDispatch[] seqDispatcher =

new com.sun.star.frame.XDispatch[seqDescriptors.length];

for( int i=0; i < nCount; ++i )

{

seqDispatcher[i] = queryDispatch(seqDescriptors[i].FeatureURL,

seqDescriptors[i].FrameName,

seqDescriptors[i].SearchFlags );

}

return seqDispatcher;

}

// com.sun.star.lang.XInitialization:

public void initialize( Object[] object )

throws com.sun.star.uno.Exception

{

if ( object.length > 0 )

{

m_xFrame = (com.sun.star.frame.XFrame)UnoRuntime.queryInterface(

com.sun.star.frame.XFrame.class, object[0]);

}

}

// com.sun.star.frame.XDispatch:

public void dispatch( com.sun.star.util.URL aURL,

com.sun.star.beans.PropertyValue[] aArguments )

{

if ( aURL.Protocol.compareTo("org.openoffice.testaddon.testaddon:") == 0 )

{

if ( aURL.Path.compareTo("Hello") == 0 )

{

// add your own code here

JOptionPane.showMessageDialog(null,"Hello World");

return;

}

else if(aURL.Path.compareTo("Test") == 0)

{

JOptionPane.showMessageDialog(null,"Just Test");

return;

}

}

}

public void addStatusListener( com.sun.star.frame.XStatusListener xControl,

com.sun.star.util.URL aURL )

{

// add your own code here

}

public void removeStatusListener( com.sun.star.frame.XStatusListener xControl,

com.sun.star.util.URL aURL )

{

// add your own code here

}

 

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值