jgraph in action(四)

本文详细介绍了 JGraphpad 的定制过程和技术细节,包括工具类的使用、UserObject 的实现方式、ToolTipManager 的配置、Cloning 和 Editing 的处理、Transactions 的支持、Rendering 的原理等。此外还探讨了 In-place editing、Drag and drop、Popupmenu 的实现方法以及 Folding 等高级特性。

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

 
工具类
JGraphpadFileFilte
rJGraphpadFocusManager
JGraphpadMorphingManager
 
JGraphpadImageEncoder
JGraphpadImageIcon
JGraphpadShadowBorder
JGraphpadMouseAdapter
 
定制JGraph
JGraphpad基于JGraph做了如下的定制:
User objects and graph model to implement properties
Cell view renderer for rich text, heavweights and shapes
In-place editing of rich text and heavyweights
Edge views to support moveable ports
Transfer handler to implement drag and drop
Marquee handler for event intercepting
 
User Object
com.jgraph.pad.graph.JGraphpadBusinessObject实现user object
用一个Map类型的properties保存用户数据,
用String类型的value属性供render使用。
 
 
根据getTooltip方法在graph中创建tips
为了显示tip,提供一个特殊的JGraph类,该类唯一的功能是基于上面的getTooltip方法创建tips。
该类重写getToolTipText
该方法找到鼠标所指的cell,然后调用
getToolTipForCell(Object)创建tips,创建tips的时候会用user object
getTooltip做参数。
 
在JGraphpad类的configureGraph方法中注册tooltip manager
ToolTipManager.sharedInstance().registerComponent(graph);
 
Cloning
 
Editing
valueForCellChanged
getValue
 
Transactions:
JGraphpadGraphModel为了支持com.jgraph.pad.graph.JGraphpadBusinessObject扩展了
handleAttributes方法
 
Rendering
JGraphpadVertexRenderer提供了一个通用render,它可以render
JGraphpadVertexView所有可能的配置(rendering various shapes, gradient background, image scaling, rich text and redirecting to heavyweight value)。
JGraphpadVertexRenderer继承
VertexRenderer, VertexRenderer继承
JLable
 
通用render
优点
the reduced redundancy and complexity of the required cell type hierarchy and factory implementation
缺点
it requires special handling of fixed ports
when the shape is changed and makes the default renderer code considerably more complex
 
shape:
如果shape是rectangle,那么JLable可以负责绘制,
当shape不是retangle的时候,需要代码负责绘制(背景和border
 
heavyweight:
heavyweight本身是一个component,因此重写getRendererComponent
return new JComponent() {
public void paint(Graphics g) {
valueComponent.setSize(getSize());
if (graph.getEditingCell() != view.getCell())
valueComponent.paint(g);
}
};
The valueComponent is the actual heavyweight. The code is only invoked if the valueComponent is not null and creates a wrapper component around the heavyweight to avoid changes of its properties. The valueComponent variable is set in the installAttributes method or cleared in the resetAttributes method if installAttributes is not called, as controlled by the groupOpaque attribute defined by the core library
 
Rich text
render rich text的方法:
混合使用text component和通用render的方式。
 
In-place editing
 
in-place editingrender一样,按stringrich textheavyweight分类。
String:默认editor
其他:
if (obj.isRichText())
return editor;
else if (obj.isComponent())
return redirector;
 
鉴于heavyweight是一个component,因此用一个componenteditor,由下面的方法完成:
getCellEditorComponent method of the JGraphpadVertexView.RedirectorEditor class,最后由
getCellEditorValue返回edit结果。
 
rich text使用text paneedit,该text pane
getCellEditorComponent中配置。Edit结果由
getCellEditorValue返回
 
moveable port
drag and drop
鼠标事件
JGraph的控制流由basic marquee handler.中的鼠标handler定义。
 
Swing中的action listener chaining有些问题:
对已经注册的listener,不能通过注册新的listener而block对事件的处理。
因此,JGraph使用marquee handler来控制事件处理。
 
 
Popup menu
弹出菜单是鼠标右键事件的第一个处理,然后marquee handler接管控制,处理之后的其他响应。
 
Folding
the process of expanding and collapsing group cells, ie. showing or hiding
their children.
 
其他特性
edge groups
 
connecting edges
 
 
Edge promoting:
the process of painting edges along the parent group boundaries when
children are hidden
 
grouping by mouse
 
plugins
Internationalization
Browser Integration
Bean Shell
Codecs
EPS (Postscript)
JGX (JGraphpad 5.x)
L2FProd (UI Components)
Automatic Layout
PDF Export
SVG Export
Embedded Webserver
 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值