免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1213 | 回复: 0
打印 上一主题 下一主题

JGraph学习三 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-03-13 14:52 |只看该作者 |倒序浏览

现在来看一看addSampleData(model)。
public static void addSampleData(GraphModel model) {
       ConnectionSet cs = new ConnectionSet();
       Map attributes = new Hashtable();
       // Styles For Implement/Extend/Aggregation
       //设置implementStyle
AttributeMap implementStyle = new AttributeMap();
       GraphConstants.setLineBegin(implementStyle,
              GraphConstants.ARROW_TECHNICAL);
       GraphConstants.setBeginSize(implementStyle, 10);
       GraphConstants.setDashPattern(implementStyle, new float[] { 3, 3 });
       if (GraphConstants.DEFAULTFONT != null) {
           GraphConstants.setFont(implementStyle, GraphConstants.DEFAULTFONT
                  .deriveFont(10));
       }
       //设置extendStyle
       AttributeMap extendStyle = new AttributeMap();
       GraphConstants
              .setLineBegin(extendStyle, GraphConstants.ARROW_TECHNICAL);
       GraphConstants.setBeginFill(extendStyle, true);
       GraphConstants.setBeginSize(extendStyle, 10);
       if (GraphConstants.DEFAULTFONT != null) {
           GraphConstants.setFont(extendStyle, GraphConstants.DEFAULTFONT
                  .deriveFont(10));
       }
       //设置aggregateStyle
       AttributeMap aggregateStyle = new AttributeMap();
       GraphConstants.setLineBegin(aggregateStyle,
              GraphConstants.ARROW_DIAMOND);
       GraphConstants.setBeginFill(aggregateStyle, true);
       GraphConstants.setBeginSize(aggregateStyle, 6);
       GraphConstants.setLineEnd(aggregateStyle, GraphConstants.ARROW_SIMPLE);
       GraphConstants.setEndSize(aggregateStyle, 8);
       GraphConstants.setLabelPosition(aggregateStyle, new Point2D.Double(500,
              0));
       if (GraphConstants.DEFAULTFONT != null) {
           GraphConstants.setFont(aggregateStyle, GraphConstants.DEFAULTFONT
                  .deriveFont(10));
       }
       //
       // The Swing MVC Pattern
       //
       // Model Column
       //创建标签为GraphModel的节点,并设置属性
       DefaultGraphCell gm = new DefaultGraphCell("GraphModel");
       attributes.put(gm,
              createBounds(new AttributeMap(), 20, 100, Color.blue));
       gm.addPort(null,"GraphModel/Center");
       //创建标签为DefaultGraphModel的节点,并设置属性
       DefaultGraphCell dgm = new DefaultGraphCell("DefaultGraphModel");
       attributes.put(dgm, createBounds(new AttributeMap(), 20, 180,
              Color.blue));
       dgm.addPort(null, "DefaultGraphModel/Center");
       //创建关系为implements的边,并设置属性
       DefaultEdge dgmImplementsGm = new DefaultEdge("implements");
       cs.connect(dgmImplementsGm, gm.getChildAt(0), dgm.getChildAt(0));
       attributes.put(dgmImplementsGm, implementStyle);
       //将gm,dgm和dgmImplementsGm归为一组
       DefaultGraphCell modelGroup = new DefaultGraphCell("ModelGroup");
        modelGroup.add(gm);
       modelGroup.add(dgm);
       modelGroup.add(dgmImplementsGm);

       // JComponent Column
       DefaultGraphCell jc = new DefaultGraphCell("JComponent");
       attributes.put(jc, createBounds(new AttributeMap(), 180, 20,
              Color.green));
       jc.addPort(null, "JComponent/Center");
       //Jgraph
       DefaultGraphCell jg = new DefaultGraphCell("JGraph");
       attributes.put(jg, createBounds(new AttributeMap(), 180, 100,
              Color.green));
       jg.addPort(null, "JGraph/Center");
       DefaultEdge jgExtendsJc = new DefaultEdge("extends");
       cs.connect(jgExtendsJc, jc.getChildAt(0), jg.getChildAt(0));
       attributes.put(jgExtendsJc, extendStyle);
       // UI Column
       DefaultGraphCell cu = new DefaultGraphCell("ComponentUI");
       attributes
              .put(cu, createBounds(new AttributeMap(), 340, 20, Color.red));
       cu.addPort(null, "ComponentUI/Center");
       //GraphUI
       DefaultGraphCell gu = new DefaultGraphCell("GraphUI");
       attributes.put(gu,
              createBounds(new AttributeMap(), 340, 100, Color.red));
       gu.addPort(null, "GraphUI/Center");
        // BasicGraphUI
       DefaultGraphCell dgu = new DefaultGraphCell("BasicGraphUI");
       attributes.put(dgu, createBounds(new AttributeMap(), 340, 180,
              Color.red));
       dgu.addPort(null, "BasicGraphUI/Center");

       DefaultEdge guExtendsCu = new DefaultEdge("extends");
       cs.connect(guExtendsCu, cu.getChildAt(0), gu.getChildAt(0));
       attributes.put(guExtendsCu, extendStyle);

       DefaultEdge dguImplementsDu = new DefaultEdge("implements");
       cs.connect(dguImplementsDu, gu.getChildAt(0), dgu.getChildAt(0));
       attributes.put(dguImplementsDu, implementStyle);

       DefaultGraphCell uiGroup = new DefaultGraphCell("UIGroup");
       uiGroup.add(cu);
       uiGroup.add(gu);
       uiGroup.add(dgu);
       uiGroup.add(dguImplementsDu);
       uiGroup.add(guExtendsCu);
       // Aggregations
       DefaultEdge jgAggregatesGm = new DefaultEdge("model");
       cs.connect(jgAggregatesGm, jg.getChildAt(0), gm.getChildAt(0));
       attributes.put(jgAggregatesGm, aggregateStyle);
       DefaultEdge jcAggregatesCu = new DefaultEdge("ui");
       cs.connect(jcAggregatesCu, jc.getChildAt(0), cu.getChildAt(0));
       attributes.put(jcAggregatesCu, aggregateStyle);
       // Insert Cells into model
       Object[] cells = new Object[] { jgAggregatesGm, jcAggregatesCu,
              modelGroup, jc, jg, jgExtendsJc, uiGroup };
       //将加入的元素添加到GraphModel中
       model.insert(cells, attributes, cs, null, null);
    }
这个函数实现的基本功能是创建一些网络元素,包括创建节点和边,并将这些元素归组,最后将这些元素添加到GraphModel中。这是一个基本的创建Jgraph程序的过程。


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/33011/showart_257844.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP