jgraph in action(三)

 
 
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());
 
 
工具类
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值