Nerbeans RCP

本文介绍了如何创建NetBeans平台应用程序项目,并强调了模块化的重要性。通过设置模块依赖,确保代码的组织和重用遵循严格的规则。NetBeans的Lookup类提供了一种松散耦合的方式,使得不同模块间可以通信。这种架构允许My Viewer和My Editor模块独立开发和发货,同时也允许其他模块提供不同的编辑器服务,只要它们遵循相同的API。这种方式类似于NetBeans IDE中对源文件的支持,如Java文件,允许添加新的工具并保持与其他组件的兼容性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

重点:

1.创建NetBeans Plaform Application项目

2.可以生成多个模块,设置依赖,降低耦合

NetBeans Platform Quick Start

选择文件| 新建项目,然后选择NetBeans模块。选择“ NetBeans平台应用程序”

右键单击“ WordEditorCore”模块,然后选择“新建” |“新建”。其他。在“模块开发”类别中,选择“窗口”:

本教程涵盖了两个重要的概念。

  1. 该应用程序包含四个模块。如果(1)第一个模块显式公开包,并且(2)第二个模块设置对第一个模块的依赖性,则一个模块的代码只能由另一个模块使用。这样,NetBeans平台有助于在严格的模块化体系结构中组织代码,从而确保不会随机重用代码,而仅在提供代码的模块之间设置了合同时才可重用。
  2. 其次,作为JDK 6 ServiceLoader方法的扩展,引入了Lookup类作为模块之间进行通信的机制。通过其接口加载实现。无需使用实现中的任何代码,“ WordEditorCore”模块就可以显示实现者提供的服务。以此方式向NetBeans平台应用程序提供了松散耦合。

NetBeans Selection Management Tutorial I-Using a TopComponent’s Lookup

So, What's the Point?

You might be wondering what the point of this exercise is—you've just shown that you can handle selection—big deal! The key to the importance of this is the way the code is split into three modules—the My Viewer module knows nothing about the My Editor module—either one can run by itself. They only share a common dependency on My API. That's important—it means two things: 1. My Viewer and My Editor can be developed and shipped independently, and 2. Any module that wants to provide a different sort of editor than My Editor can do so, and the viewer component will work perfectly with it, as long as the replacement editor offers an instance of Event from its Lookup.

To really picture the value of this, imagine Event were something much more complex; imagine that MyEditor is an image editor, and Event represents an image being edited. The thing that's powerful here is that you could replace MyEditor with, say, an SVG vector-based editor, and the viewer component (presumably showing attributes of the currently edited image) will work transparently with that new editor. It is this model of doing things that is the reason you can add new tools into the NetBeans IDE that work against Java files, and they will work in different versions of NetBeans, and that you can have an alternate editor (such as the form editor) for Java files and all the components and actions that work against Java files still work when the form editor is used.

This is very much the way NetBeans works with Java and other source files—in their case, the thing that is available from the editor's Lookup is a DataObject, and components like Navigator and the Property Sheet are simply watching what object is being made available by the focused TopComponent.

Another valuable thing about this approach is that often people are migrating existing applications to the NetBeans Platform. The object that is part of the data model, in that case, is probably existing, working code that should not be changed in order to integrate it into NetBeans. By keeping the data model's API in a separate module, the NetBeans integration can be kept separate from the core business logic.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值