`

JHotDraw的IO问题

阅读更多

您好!请教一个问题:jhotdraw7.6中samples中draw实例中有个file菜单中有个“open”的功能,可以根据xml文件生成图形,请问这个功能的代码在哪儿?谢谢

 

 

你好,我用的是7.5的版本,我想应该是一样的。

实现机制:
draw的存储接口是DOMStorable,负责drawing的IO操作;所有继承或实现该接口的子类都必须实现了read和write方法,即实现具体类的读入和写出责任。AbstractAttributedFigure和Drawing都继承该接口。

读取文件的顺序为:

  1. openAction读入文件,调用DrawView的read方法读取该文件;
  2. DrawView中维护多个inputFormat,每个inputFormat负责读取特定的Figure;当调用read方法时,DrawView尝试让所有的inputFormat读取该文件,但只要有一个inputFormat读取成功就停止。
至于DrawView装载了多少InputFromat,可以参考org.jhotdraw.samples.draw.DrawView.createDrawing():

 

 

 

 protected Drawing createDrawing() {
        Drawing drawing = new QuadTreeDrawing();
        DOMStorableInputOutputFormat ioFormat =
                new DOMStorableInputOutputFormat(new DrawFigureFactory());
        
        drawing.addInputFormat(ioFormat);
        ImageFigure prototype = new ImageFigure();
        drawing.addInputFormat(new ImageInputFormat(prototype));
        drawing.addInputFormat(new TextInputFormat(new TextFigure()));
        TextAreaFigure taf = new TextAreaFigure();
        taf.setBounds(new Point2D.Double(10,10), new Point2D.Double(60,40));
        drawing.addInputFormat(new TextInputFormat(taf));
        
        drawing.addOutputFormat(ioFormat);
        drawing.addOutputFormat(new ImageOutputFormat());
        return drawing;
    }
 


参考org.jhotdraw.draw.LineConnectionFigure对write()和read()的实现:
 

//org.jhotdraw.draw.LineConnectionFigure.read
public void read(DOMInput in) throws IOException {
        readAttributes(in);
        readLiner(in);

        // Note: Points must be read after Liner, because Liner influences
        // the location of the points.
        readPoints(in);
    }

//org.jhotdraw.draw.AbstractAttributedFigure.readAttributes
 protected void readAttributes(DOMInput in) throws IOException {
        if (in.getElementCount("a") > 0) {
            in.openElement("a");
            for (int i=in.getElementCount() - 1; i >= 0; i-- ) {
                in.openElement(i);
                String name = in.getTagName();
                Object value = in.readObject();
                AttributeKey key = getAttributeKey(name);
                if (key != null && key.isAssignable(value)) {
                    if (forbiddenAttributes == null
                            || ! forbiddenAttributes.contains(key)) {
                        set(key, value);
                    }
                }
                in.closeElement();
            }
            in.closeElement();
        }
    }




 protected void readLiner(DOMInput in) throws IOException {
        if (in.getElementCount("liner") > 0) {
            in.openElement("liner");
            liner = (Liner) in.readObject();
            in.closeElement();
        } else {
            liner = null;
        }

    }


//org.jhotdraw.draw.LineConnectionFigure.readPoints
 protected void readPoints(DOMInput in) throws IOException {
        super.readPoints(in);
        in.openElement("startConnector");
        setStartConnector((Connector) in.readObject());
        in.closeElement();
        in.openElement("endConnector");
        setEndConnector((Connector) in.readObject());
        in.closeElement();
    }
 

读入机制参见:
org.jhotdraw.app.action.file.OpenFileAction#openViewFromURI() line 105
org.jhotdraw.samples.draw.DrawView#read()
org.jhotdraw.xml.DOMFactory

 


分享到:
评论
5 楼 sxpyrgz 2011-10-20  
c.zhiwu 写道
sxpyrgz 写道
哥门儿你在玩JHOTDRAW吗?


我也在整,不过过程中还有不少的问题
4 楼 c.zhiwu 2011-10-13  
sxpyrgz 写道
哥门儿你在玩JHOTDRAW吗?

3 楼 sxpyrgz 2011-10-12  
哥门儿你在玩JHOTDRAW吗?
2 楼 c.zhiwu 2011-05-11  
是在实现Figure的具体类中实现IO的,如果要修改,可以参考Figure的子类。
1 楼 hust_axu 2011-05-06  
您好,请教一个问题。我想讲他自动生成的xml代码
<drawing>
- <figures>
- <start-state id="0" x="40" y="49" w="60" h="40" name="开始">
- <a>
- <fontFace>
  <font id="1" name="宋体" style="0" size="20" />
  </fontFace>
- <fontSize>
  <double id="2">20.0</double>
  </fontSize>
  </a>
  <transition name="到拟稿" to="拟稿" />
  </start-state>
- <task-node id="3" x="42" y="148" w="60" h="40" name="拟稿">
- <a>
- <text>
  <string id="4">拟稿</string>
  </text>
- <fontFace>
  <font ref="1" />
  </fontFace>
- <fontSize>
  <double ref="2" />
  </fontSize>
  </a>
  <transition name="到审批" to="审批" />
- <task name="拟稿">
  <description>draft</description>
  <assignment class="test.assignment.DraftAssignment" />
- <controller>
  <variable access="read,write" name="documentId" />
  </controller>
  </task>
  </task-node>
- <task-node id="5" x="40" y="238" w="60" h="40" name="审批">
- <a>
- <text>
  <string id="6">审批</string>
  </text>
- <fontFace>
  <font ref="1" />
  </fontFace>
- <fontSize>
  <double ref="2" />
  </fontSize>
  </a>
  <transition name="到判断" to="判断" />
- <task name="审批">
  <description>examine</description>
  <assignment class="test.assignment.ExamineAssignment" />
- <controller>
  <variable access="read,write" name="documentId" />
  </controller>
  </task>
  </task-node>
- <task-node id="7" x="40" y="346" w="60" h="40" name="成文">
- <a>
- <text>
  <string id="8">成文</string>
  </text>
- <fontFace>
  <font ref="1" />
  </fontFace>
- <fontSize>
  <double ref="2" />
  </fontSize>
  </a>
  <transition name="到传阅" to="传阅" />
- <task name="成文">
  <description>write</description>
  <assignment class="test.assignment.WriteAssignment" />
- <controller>
  <variable access="read,write" name="documentId" />
  </controller>
  </task>
  </task-node>
- <task-node id="9" x="187" y="344" w="60" h="40" name="传阅">
- <a>
- <text>
  <string id="a">传阅</string>
  </text>
- <fontFace>
  <font ref="1" />
  </fontFace>
- <fontSize>
  <double ref="2" />
  </fontSize>
  </a>
  <transition name="到归档" to="归档" />
- <task name="传阅">
  <description>read</description>
  <assignment class="test.assignment.ReadAssignment" />
- <controller>
  <variable access="read,write" name="documentId" />
  </controller>
  </task>
  </task-node>
- <decision id="b" x="179" y="232" w="60" h="40" name="判断">
- <a>
- <fillColor>
  <color id="c" rgba="#ffffff00" />
  </fillColor>
- <fontFace>
  <font ref="1" />
  </fontFace>
- <fontSize>
  <double ref="2" />
  </fontSize>
  </a>
  <transition name="同意" to="成文" />
  <transition name="不同意" to="拟稿" />
  <handler class="test.handler.TestDecisionHandler" />
  </decision>
- <end-state id="d" x="462" y="337" w="60" h="40" name="结束">
- <a>
- <fillColor>
  <color id="e" rgba="#ffff0000" />
  </fillColor>
- <fontFace>
  <font ref="1" />
  </fontFace>
- <fontSize>
  <double ref="2" />
  </fontSize>
  </a>
  </end-state>
- <task-node id="f" x="313" y="343" w="60" h="40" name="归档">
- <a>
- <text>
  <string id="10">归档</string>
  </text>
- <fontFace>
  <font ref="1" />
  </fontFace>
- <fontSize>
  <double ref="2" />
  </fontSize>
  </a>
  <transition name="到结束" to="结束" />
- <task name="归档">
  <description>file</description>
  <assignment class="test.assignment.FileAssignment" />
- <controller>
  <variable access="read,write" name="documentId" />
  </controller>
  </task>
  </task-node>
- <transition id="11">
- <points>
  <p colinear="true" x="70.41414141414141" y="89.5" c1x="0" c1y="0" c2x="0" c2y="0" />
  <p colinear="true" x="71.58585858585859" y="147.5" c1x="0" c1y="0" c2x="0" c2y="0" />
  </points>
- <startConnector>
- <rConnector id="12">
- <Owner>
  <start-state ref="0" />
  </Owner>
  </rConnector>
  </startConnector>
- <endConnector>
- <rConnector id="13">
- <Owner>
  <task-node ref="3" />
  </Owner>
  </rConnector>
  </endConnector>
- <a>
- <strokeColor>
  <color id="14" rgba="#ff000000" />
  </strokeColor>
- <strokeWidth>
  <double id="15">1.0</double>
  </strokeWidth>
  </a>
  </transition>
- <transition id="16">
- <points>
  <p colinear="true" x="71.54444444444445" y="188.5" c1x="0" c1y="0" c2x="0" c2y="0" />
  <p colinear="true" x="70.45555555555555" y="237.5" c1x="0" c1y="0" c2x="0" c2y="0" />
  </points>
- <startConnector>
- <rConnector id="17">
- <Owner>
  <task-node ref="3" />
  </Owner>
  </rConnector>
  </startConnector>
- <endConnector>
- <rConnector id="18">
- <Owner>
  <task-node ref="5" />
  </Owner>
  </rConnector>
  </endConnector>
- <a>
- <strokeColor>
  <color ref="14" />
  </strokeColor>
- <strokeWidth>
  <double ref="15" />
  </strokeWidth>
  </a>
  </transition>
- <transition id="19">
- <points>
  <p colinear="true" x="100.5" y="256.68345323741005" c1x="0" c1y="0" c2x="0" c2y="0" />
  <p colinear="true" x="178.5" y="253.31654676258992" c1x="0" c1y="0" c2x="0" c2y="0" />
  </points>
- <startConnector>
- <rConnector id="1a">
- <Owner>
  <task-node ref="5" />
  </Owner>
  </rConnector>
  </startConnector>
- <endConnector>
- <rConnector id="1b">
- <Owner>
  <decision ref="b" />
  </Owner>
  </rConnector>
  </endConnector>
- <a>
- <strokeColor>
  <color ref="14" />
  </strokeColor>
- <strokeWidth>
  <double ref="15" />
  </strokeWidth>
  </a>
  </transition>
- <transition id="1c">
- <points>
  <p colinear="true" x="178.5" y="233.2992700729927" c1x="0" c1y="0" c2x="0" c2y="0" />
  <p colinear="true" x="102.5" y="186.7007299270073" c1x="0" c1y="0" c2x="0" c2y="0" />
  </points>
- <startConnector>
- <rConnector id="1d">
- <Owner>
  <decision ref="b" />
  </Owner>
  </rConnector>
  </startConnector>
- <endConnector>
- <rConnector id="1e">
- <Owner>
  <task-node ref="3" />
  </Owner>
  </rConnector>
  </endConnector>
- <a>
- <strokeColor>
  <color ref="14" />
  </strokeColor>
- <strokeWidth>
  <double ref="15" />
  </strokeWidth>
  </a>
  </transition>
- <transition id="1f">
- <points>
  <p colinear="true" x="184.00438596491227" y="272.5" c1x="0" c1y="0" c2x="0" c2y="0" />
  <p colinear="true" x="94.99561403508773" y="345.5" c1x="0" c1y="0" c2x="0" c2y="0" />
  </points>
- <startConnector>
- <rConnector id="20">
- <Owner>
  <decision ref="b" />
  </Owner>
  </rConnector>
  </startConnector>
- <endConnector>
- <rConnector id="21">
- <Owner>
  <task-node ref="7" />
  </Owner>
  </rConnector>
  </endConnector>
- <a>
- <strokeColor>
  <color ref="14" />
  </strokeColor>
- <strokeWidth>
  <double ref="15" />
  </strokeWidth>
  </a>
  </transition>
- <transition id="22">
- <points>
  <p colinear="true" x="100.5" y="365.5850340136054" c1x="0" c1y="0" c2x="0" c2y="0" />
  <p colinear="true" x="186.5" y="364.4149659863946" c1x="0" c1y="0" c2x="0" c2y="0" />
  </points>
- <startConnector>
- <rConnector id="23">
- <Owner>
  <task-node ref="7" />
  </Owner>
  </rConnector>
  </startConnector>
- <endConnector>
- <rConnector id="24">
- <Owner>
  <task-node ref="9" />
  </Owner>
  </rConnector>
  </endConnector>
- <a>
- <strokeColor>
  <color ref="14" />
  </strokeColor>
- <strokeWidth>
  <double ref="15" />
  </strokeWidth>
  </a>
  </transition>
- <transition id="25">
- <points>
  <p colinear="true" x="247.5" y="363.7579365079365" c1x="0" c1y="0" c2x="0" c2y="0" />
  <p colinear="true" x="312.5" y="363.2420634920635" c1x="0" c1y="0" c2x="0" c2y="0" />
  </points>
- <startConnector>
- <rConnector id="26">
- <Owner>
  <task-node ref="9" />
  </Owner>
  </rConnector>
  </startConnector>
- <endConnector>
- <rConnector id="27">
- <Owner>
  <task-node ref="f" />
  </Owner>
  </rConnector>
  </endConnector>
- <a>
- <strokeColor>
  <color ref="14" />
  </strokeColor>
- <strokeWidth>
  <double ref="15" />
  </strokeWidth>
  </a>
  </transition>
- <transition id="28">
- <points>
  <p colinear="true" x="373.5" y="361.7718120805369" c1x="0" c1y="0" c2x="0" c2y="0" />
  <p colinear="true" x="461.5" y="358.2281879194631" c1x="0" c1y="0" c2x="0" c2y="0" />
  </points>
- <startConnector>
- <rConnector id="29">
- <Owner>
  <task-node ref="f" />
  </Owner>
  </rConnector>
  </startConnector>
- <endConnector>
- <rConnector id="2a">
- <Owner>
  <end-state ref="d" />
  </Owner>
  </rConnector>
  </endConnector>
- <a>
- <strokeColor>
  <color ref="14" />
  </strokeColor>
- <strokeWidth>
  <double ref="15" />
  </strokeWidth>
  </a>
  </transition>
  </figures>
  </drawing>

修改成文一下形式的xml文件
  <?xml version="1.0" encoding="UTF-8" ?>
- <process-definition xmlns="" name="document">
- <start-state name="开始">
  <transition to="拟稿" />
  </start-state>
- <task-node name="拟稿">
- <task name="拟稿">
  <description>draft</description>
  <assignment class="test.assignment.DraftAssignment" />
- <controller>
  <variable access="read,write" name="documentId" />
  </controller>
  </task>
  <transition to="审批" />
  </task-node>
- <task-node name="归档">
- <task name="归档">
  <description>file</description>
  <assignment class="test.assignment.FileAssignment" />
- <controller>
  <variable access="read,write" name="documentId" />
  </controller>
  </task>
  <transition to="结束" />
  </task-node>
- <task-node name="传阅">
- <task name="传阅">
  <description>read</description>
  <assignment class="test.assignment.ReadAssignment" />
- <controller>
  <variable access="read,write" name="documentId" />
  </controller>
  </task>
  <transition to="归档" />
  </task-node>
- <task-node name="成文">
- <task name="成文">
  <description>write</description>
  <assignment class="test.assignment.WriteAssignment" />
- <controller>
  <variable access="read,write" name="documentId" />
  </controller>
  </task>
  <transition to="传阅" />
  </task-node>
- <task-node name="审批">
- <task name="审批">
  <description>examine</description>
  <assignment class="test.assignment.ExamineAssignment" />
- <controller>
  <variable access="read,write" name="documentId" />
  </controller>
  </task>
  <transition to="判断" />
  </task-node>
- <decision name="判断">
  <handler class="test.handler.TestDecisionHandler" />
  <transition to="成文" name="同意" />
  <transition to="拟稿" name="不同意" />
  </decision>
  <end-state name="结束" />
  </process-definition>

请问需要修改哪些文件啊?

相关推荐

    JAVA上百实例源码以及开源项目

     Java二进制IO类与文件复制操作实例,好像是一本书的例子,源代码有的是独立运行的,与同目录下的其它代码文件互不联系,这些代码面向初级、中级Java程序员。 Java访问权限控制源代码 1个目标文件 摘要:Java源码,...

    JAVA上百实例源码以及开源项目源代码

     Java二进制IO类与文件复制操作实例,好像是一本书的例子,源代码有的是独立运行的,与同目录下的其它代码文件互不联系,这些代码面向初级、中级Java程序员。 Java访问权限控制源代码 1个目标文件 摘要:Java源码,...

    java开源包1

    Tomcat Native 这个项目可以让 Tomcat 使用 Apache 的 apr 包来处理包括文件和网络IO操作,以提升性能。 预输入搜索 Cleo Cleo 是一个灵活的软件库用于处理一些预输入和自动完成的搜索功能,该项目是 LinkedIn 公司...

    java开源包11

    Tomcat Native 这个项目可以让 Tomcat 使用 Apache 的 apr 包来处理包括文件和网络IO操作,以提升性能。 预输入搜索 Cleo Cleo 是一个灵活的软件库用于处理一些预输入和自动完成的搜索功能,该项目是 LinkedIn 公司...

    java开源包2

    Tomcat Native 这个项目可以让 Tomcat 使用 Apache 的 apr 包来处理包括文件和网络IO操作,以提升性能。 预输入搜索 Cleo Cleo 是一个灵活的软件库用于处理一些预输入和自动完成的搜索功能,该项目是 LinkedIn 公司...

    java开源包3

    Tomcat Native 这个项目可以让 Tomcat 使用 Apache 的 apr 包来处理包括文件和网络IO操作,以提升性能。 预输入搜索 Cleo Cleo 是一个灵活的软件库用于处理一些预输入和自动完成的搜索功能,该项目是 LinkedIn 公司...

    java开源包6

    Tomcat Native 这个项目可以让 Tomcat 使用 Apache 的 apr 包来处理包括文件和网络IO操作,以提升性能。 预输入搜索 Cleo Cleo 是一个灵活的软件库用于处理一些预输入和自动完成的搜索功能,该项目是 LinkedIn 公司...

    java开源包5

    Tomcat Native 这个项目可以让 Tomcat 使用 Apache 的 apr 包来处理包括文件和网络IO操作,以提升性能。 预输入搜索 Cleo Cleo 是一个灵活的软件库用于处理一些预输入和自动完成的搜索功能,该项目是 LinkedIn 公司...

    java开源包10

    Tomcat Native 这个项目可以让 Tomcat 使用 Apache 的 apr 包来处理包括文件和网络IO操作,以提升性能。 预输入搜索 Cleo Cleo 是一个灵活的软件库用于处理一些预输入和自动完成的搜索功能,该项目是 LinkedIn 公司...

    java开源包4

    Tomcat Native 这个项目可以让 Tomcat 使用 Apache 的 apr 包来处理包括文件和网络IO操作,以提升性能。 预输入搜索 Cleo Cleo 是一个灵活的软件库用于处理一些预输入和自动完成的搜索功能,该项目是 LinkedIn 公司...

    java开源包8

    Tomcat Native 这个项目可以让 Tomcat 使用 Apache 的 apr 包来处理包括文件和网络IO操作,以提升性能。 预输入搜索 Cleo Cleo 是一个灵活的软件库用于处理一些预输入和自动完成的搜索功能,该项目是 LinkedIn 公司...

    java开源包7

    Tomcat Native 这个项目可以让 Tomcat 使用 Apache 的 apr 包来处理包括文件和网络IO操作,以提升性能。 预输入搜索 Cleo Cleo 是一个灵活的软件库用于处理一些预输入和自动完成的搜索功能,该项目是 LinkedIn 公司...

    java开源包9

    Tomcat Native 这个项目可以让 Tomcat 使用 Apache 的 apr 包来处理包括文件和网络IO操作,以提升性能。 预输入搜索 Cleo Cleo 是一个灵活的软件库用于处理一些预输入和自动完成的搜索功能,该项目是 LinkedIn 公司...

    java开源包101

    Tomcat Native 这个项目可以让 Tomcat 使用 Apache 的 apr 包来处理包括文件和网络IO操作,以提升性能。 预输入搜索 Cleo Cleo 是一个灵活的软件库用于处理一些预输入和自动完成的搜索功能,该项目是 LinkedIn 公司...

    Java资源包01

    Tomcat Native 这个项目可以让 Tomcat 使用 Apache 的 apr 包来处理包括文件和网络IO操作,以提升性能。 预输入搜索 Cleo Cleo 是一个灵活的软件库用于处理一些预输入和自动完成的搜索功能,该项目是 LinkedIn 公司...

Global site tag (gtag.js) - Google Analytics