jgraph in action(三)
来源:互联网 发布:c语言 宏 编辑:程序博客网 时间:2024/06/06 06:52
JGraph document Model
library是预定义的cell。
示例:
int number = model.getChildCount(file) + 1;
JGraphpadDiagram newDiagram = new JGraphpadDiagram(
getString("Diagram") + number);
model.addChild(newDiagram, (JGraphpadFile) file);
model.removeNodeFromParent(mutableTreeNode);
All JGraphpadFile and JGraphpadLibrary objects are roots, and
all JGraphpadDiagram objects are direct children of JGraphpadFile objects.
The root contains one or more files (documents or libraries), and the documents contain one or more diagrams.
factory methods定制之Main Window
[1] 主窗口结构如下:
JGraphpadPane.FactoryMethod创建主窗口,
负责整个JFrame实例的创建(包括menubar, toolbar, toolbox, statusbar and main area)
main area包括:left,content,bottom三部分。
Left和bottom由各自的factory methods创建,返回JTabbedPane.
示例:创建toolbox,以Node为参数创建:
Node toolboxConfig = JGraphEditorSettings.getNodeByName(
configuration.getChildNodes(), NODENAME_TOOLBOX);
JGraphEditorToolbox toolbox = editor.getFactory()
.createToolbox(toolboxConfig);
configuration对象代表xml格式的ui描述中的最外层结点(例如下面的xml),
getNodeByName获取名为toolbox的结点。
<ui>
<toolbox>
<item key="selectTool"/>
<separator/>
<item key="createDashPatternCombo"/>
</toolbox>
</ui>
menubar和toolbar也是类似:
Node menuBarConfig = JGraphEditorSettings.getNodeByName(
configuration.getChildNodes(), NODENAME_MENUBAR);
frame.setJMenuBar((JMenuBar) editor.getFactory().createMenuBar(
menuBarConfig));
[...]
Node toolbarConfiguration = JGraphEditorSettings.getNodeByName(
configuration.getChildNodes(), NODENAME_TOOLBAR);
JToolBar toolbar = editor.getFactory().createToolBar(
toolbarConfiguration);
注意下面,没有以Node做参数而是直接创建:
Component statusBar = editor.getFactory().executeMethod(
JGraphpadStatusBar.FactoryMethod.NAME);
frame.getContentPane().add(statusBar, BorderLayout.SOUTH);
JGraphpadPane.DocumentTracker这个内部类是在document model和pane之间的中间者,在model变化的时候,更新pane。
[2] 主窗口的组件
窗口的main area是JGraphPane,分为3部分,
left和bottom是由factory method创建,而content(JDeskTopPane)部分在constructor中创建。
Component leftTab = editor.getFactory().executeMethod(
LeftTabFactoryMethod.NAME);
Component bottomTab = editor.getFactory().executeMethod(
BottomTabFactoryMethod.NAME);
三部分的位置信息注册到settings对象,供显示和退出保存。
Content被注册了一个鼠标监听器:
desktopPane.addMouseListener(new JGraphpadMouseAdapter(editor,
NODENAME_DESKTOPPOPUPMENU));
这个监听器根据配置文件处理右键弹出窗口问题。
JGraphpadPane另外有些method,其用途是
供DocumentTracker调用,以同步model的各种变化。
在其中有个configureDiagramPane hook which is called when a new diagram pane is created for a diagram
[3] left tab
left是一个JSplitPane:
factory.executeMethod(JGraphEditorNavigator.FactoryMethod.NAME);
factory.executeMethod(JGraphpadLibraryPane.FactoryMethod.NAME);
JSplitPane navigatorSplit = editor.getFactory().createSplitPane(
navigator, libraryPane, JSplitPane.VERTICAL_SPLIT);
editor.getSettings().putObject(KEY_NAVIGATORSPLIT, navigatorSplit);
为了记住JSplitPane的当前位置信息,添加shut down hook
editor.getSettings().addShutdownHook(
new JGraphEditorSettings.ShutdownHook() {
public void shutdown() {
editor.getSettings().storeSplitPane(
JGraphpad.NAME_USERSETTINGS,
KEY_NAVIGATORSPLIT);
}
});
[4] bottom tab
bottom是一个JTabbedPane,如下:
JTabbedPane tabPane = editor.getFactory().createTabbedPane(
JTabbedPane.TOP);
Component console = editor.getFactory().executeMethod(
JGraphpadConsole.FactoryMethod.NAME);
if (console != null)
tabPane.addTab(JGraphEditorResources.getString("Errors"),
editor.getFactory().createScrollPane(console));
factory methods定制之Library Pane
The library pane is inserted into the main area of the JGraphpadPane and displays the entries in the library.
The library supports drag and drop and copy, paste, cut and delete, and has a reference to the library
in the document model.
待续。。。
factory methods定制之Window Menu
创建并注册到settings
JMenu menu = new JGraphpadWindowMenu();
editor.getSettings().putObject(KEY_WINDOWMENU, menu);
JGraphpadWindowMenu由静态和动态entities两部分,后者是保存在List。
当内部的frame(多窗口程序)变化时(remove或add),后者会相应变化。
factory methods定制之Open Recent Menu
由JGraphpadOpenRecentMenu实现,也是动态的,
通过读取保存在一个property对象中的List
tmp = props.getProperty(KEY_RECENTFILES + i++);
更新“最近的文档”的记录:
editor.getSettings().pushListEntryProperty(
NAME_USERSETTINGS, KEY_RECENTFILES, filename,
MAX_RECENTFILES);
factory methods定制之Status bar
JGraphpadStatusBar是JPanel的扩展,
在constructor中用工厂方法创建,并且注册所有关心的listeners,即
焦点的传递,和模型的事件,当前graph的鼠标移动事件,
factory methods定制之console
com.jgraph.pad.factory.JGraphpadConsole继承JTextArea,
连接到out或err系统流。
factory methods定制之combo boxes
除去framework提供的combo box外,pad提供了关于颜色和shape的combo box。
factory methods定制之custom tools
framework只对tools支持名字和isAlwaysActive属性。而继承的
JGraphpadVertexTool和JGraphpadEdgeTool支持更多,并且后者用从前缀继承。
两者都使用了prototype。
The vertex tool is used to insert cells with bounds,
the edge tool is used to insert cells with points
添加tool,使用
createVertexTool
createEdgeTool
下面以一个tree作为user object为例:
JTree tree = new JTree();
tree.setRootVisible(false);
kit.addTool(createVertexTool("treeTool", tree,
JGraphpadVertexRenderer.SHAPE_RECTANGLE, null));
边框会在插入时刻被添加。
kit.addTool(createEdgeTool("orthogonalEdgeTool",
"", GraphConstants.ROUTING_SIMPLE));
最后,添加到配置文件
# treeTool
treeTool.tooltip=Tree
treeTool.icon=/com/jgraph/pad/images/tree.gif
和ui的xml
<toolbox>
[...]
<item key="treeTool"/>
</toolbox>
factory methods定制之Dialogs
内置对话框:
文件对话框:
使用如下:
JGraphpadDialogs.getSharedInstance().editorFileDialog(
getActiveFrame(), getString("OpenJGraphpadFile"),
null, true, ".csv",lastDirectory)
文件对话框会以上次目录为当前目录。
上面的参数true指明对话框类型:open
字体对话框:
about对话框:
授权对话框:
JGraphpadAuthenticator继承java.net. Authenticator
用来获取基于网络的授权。
不直接使用,而是作为默认的对话框,以参数形式传递给Authenticator
Authenticator.setDefault(new JGraphpadAuthenticator());
工具类
- jgraph in action(三)
- jgraph in action(二)
- jgraph in action(四)
- JGraph in action(一)
- AJAX IN ACTION 学习笔记(三)
- Solr In Action 中文版 第一章(三)
- Spring In Action<三>
- JGraph
- JAVA 8 In Action 读书笔记 (三) : Collect In Stream
- 试译《Ajax in Action》第四部分(三)
- 学习Machine Leaning In Action(三):朴素贝叶斯
- Ejb in action(三)——Session Bean
- maven in action(三)hello world maven
- 《Spring in action》——学习总结(三)
- Spring In Action(三):基于注解的AOP
- spring in action笔记(三)——配置bean
- jgraph note(5-17)
- Eclipse插件开发(JGraph)
- 嵌入式系统关键技术分析与开发应用[163 BLOG]
- [转]C#编码好习惯
- 河北省地税Oracle数据库同步复制采集大集中及异地容灾应用
- 结合struts和hibernate谈J2EE架构的数据表示
- [转]C#纯数学方法递归实现货币数字转换中文
- jgraph in action(三)
- 用VC+OpenGL绘制NURBS曲面
- 长江证券集中交易系统本地查询及异地容灾备份系统建设
- petshop4.0 详解之八(PetShop表示层设计)
- SQLServer的分页SQL
- petshop4.0 详解之六(PetShop表示层设计)
- IBM的三种异地容灾备份方案
- 7月13号---一个 值得纪念的 日子
- ajax学习之1---Dom