Whisht Wind


« 十一月 2009
星期日星期一星期二星期三星期四星期五星期六
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
     
       
今天

Subscribe

Add to My YahooSubscribe in RojoSubscribe in NewsGator OnlineThis blog's XML feed
Subscribe with BloglinesAdd to Google

Search this blog

Blog Roll

Downloads

Other Links

Popular Tags

addons android archive autoloading autopager china chinese cisco dhcp dict earthquake firefox flock fonts foxbeans hgweb j2me java javame jstardict jstardictm language mercurial milax moon mozilla mtu nb-xul netbeans openoffice opensolaris pack palette recommended solaris stardict tar.gz tar.gz2 vpn vpnclient windows wine xul zip 嫦娥 郑萍如 面板

Weblog menu

Feeds

Recent Entries

Today's referrers

今日点击: 336

Locations of visitors to this page

20080316 星期日 2008年03月16日

Netbeans 开发之 添加自定义面板到现有编辑器

为了给我自己的 Netbeans插件 Foxbeans 添加功能,所以我最近研究了一下NetBeans插件的开发。这里会记录一些我的发现,以便其他人可以参考。作为第一篇,我先谢谢如何添加自定义面板。先说说如何给现有文件编辑器添加面板。这里我的例子是html编辑器,完整源代码在这里,效果如下,拖到网页上就添加一个 :):


大 的大致工作思路是用一个XML (下面说的smile.xml)文件定义面板中的一个项。这包含它的名称,描述,图标,以及实现它的类名。layer.xml中引用这个文件,把它加入一 个所谓的folder中,每个编辑器可以使用一到多个这种folder中的项。html编辑器使用的是HTMLPalette (JSP使用JSPPalette). 你可以将你的项加入到它的folder中。如果你做过Firefox插件的话,你会看到他们使用的是相同的思路。在Firefox中,这叫 overlay,也就是覆盖。实际上也不是覆盖,而是添加。一些动态语言里有这种类似的语法。你可以向一个已经在其他地方定义的类里添加新的属性和方法。 扯远了。:)

大致的步骤如下:
1. 新建一个NetBeans模块:


2. 新建一个XML文件,方法是在菜单里选新建->XML->XML文档,内容如下:

<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : smile.xml
    Created on : 2008年3月16日, 上午11:03
    Author     : wind
    Description:
        Purpose of the document follows.
-->

<!DOCTYPE editor_palette_item PUBLIC "-//NetBeans//Editor Palette Item 1.0//EN" "http://www.netbeans.org/dtds/editor-palette-item-1_0.dtd">
<editor_palette_item version="1.0">
    <class name="com.teesoft.palettedemo1.smile" />

    <icon16 urlvalue="com/teesoft/palettedemo1/smile16.png" />
    <icon32 urlvalue="com/teesoft/palettedemo1/smile32.png" />
    <description localizing-bundle="com.teesoft.palettedemo1.Bundle"
               display-name-key="NAME_smile"
               tooltip-key="HINT_smile" />
</editor_palette_item>

3. 新建一个smile.java
内容如下:

package com.teesoft.palettedemo1;

import javax.swing.text.BadLocationException;
import javax.swing.text.JTextComponent;
import org.openide.text.ActiveEditorDrop;
import org.openide.util.Exceptions;

/**
 *
 * @author wind
 */
public class smile implements ActiveEditorDrop {

    public boolean handleTransfer(JTextComponent jTextComponent) {
        try {
            JTextComponentUtils.insert(":)", jTextComponent);
        } catch (BadLocationException ex) {
            Exceptions.printStackTrace(ex);
        }
        return true;
    }
}
4. 下载 JTextComponectUtils.java. 这个是基于NetBeans中HTMLPaletteUtilities.java 。
5. layer.xml的内容改为下面的内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd">
<filesystem>
    <folder name="HTMLPalette">
        <folder name="Emotions">
            <attr name="SystemFileSystem.localizingBundle" stringvalue="com.teesoft.palettedemo1.Bundle"/>
            <attr name="originalFile" stringvalue="Emotions"/>           
            <file name="smile.xml" url="nbresloc:/com/teesoft/palettedemo1/smile.xml"/>
        </folder>
    </folder>
</filesystem>
6. Bundle.properties内容如下:
OpenIDE-Module-Name=PaletteDemo1
NAME_smile=smile
HINT_smile=smile
Emotions=Emotions

7. 在项目上点右键,属性中选库,将添加如下四个库(如果你不加,项目就没法编译,你可以将找不到的库的名字复制下来,点下图中添加按钮,粘贴类名,它会自动找到你需要的库):








Technorati Tags: , , ,

My Tags:

( 2008年03月16日, 12:20:08 下午 CST ) [Listen] Permalink 评论 [1]

Share and enjoy:  Bookmark it with Blinklist Submit to Bloglines Bookmark it with Blogmarks Track with co.mments Bookmark it with Del.icio.us Submit it to Digg Submit it to Fark Bookmark it with Furl Bookmark it with Ma.gnolia Bookmark it with Maple Bookmark it at NewsVine Bookmark it at reddit.com Bookmark it at Simpy.com Bookmark it with Spurl Submit it to slashdot Track with TailRank See who links to it via Technorati Bookmark it with wists

评论:

nice

发表于 wow gold 在 2008年11月03日, 09:06 上午 CST #

发表一条评论:
  • HTML语法: 禁用