<line x1="15" y1="114" x2="154" y2="114" style="fill:#1a1a1a; stroke:#1a1a1a; stroke-width:1"/><line x1="154" y1="35" x2="154" y2="113" style="fill:#1a1a1a; stroke:#1a1a1a; stroke-width:1"/><line x1="104" y1="15" x2="104" y2="53" style="fill:#1a1a1a; stroke:#1a1a1a; stroke-width:1"/><rect x="14" y="14" width="90" height="21" style="fill:#ffffff; stroke:#ffffff; stroke-width:1"/><rect x="14" y="14" width="89" height="20" style="fill:#ffffff; stroke:#000000; stroke-width:1"/><rect x="14" y="34" width="140" height="80" style="fill:#ffffff; stroke:#ffffff; stroke-width:1"/><rect x="14" y="34" width="139" height="79" style="fill:#ffffff; stroke:#000000; stroke-width:1"/></svg>
<?xml version="1.0" encoding="iso-8859-1"?> ... <svg width="800" height="600"> <circle cx="200" cy="200" r="100"/> </svg>
也可以嵌套在網頁中使用,如下:<embed width="320" height="240" type="image/svg-xml" id="svg"
pluginspage="http://www.adobe.com
/svg/viewer/install/" src="default.svg" > </embed>
一般說來,在繪制UML圖的時候,主體很少會用中文進行描述,但在注釋中就難免需要使用中文。SVG目前還不支持中文編碼,在碰到中文字符的時候,需要使用UTF-8編碼,這樣就可以有效避免不同的語言環境下的字符編碼問題。下面就繪制UML圖的過程中,SVG技術帶來的一些好處進行探討。 * 動態顯示注解信息對UML圖進行注解是有必要的。我們可以在UML圖下面寫上整段整段的注解,但這樣做似乎針對性不強,不輕易把事物講清楚?,F在好的方法是把事物按照組成部分細分,并針對性地進行說明。就如通用軟件的工具提示一樣,我們也可以利用SVG在UML圖上實現近似功能。 SVG把圖元看作一個個對象,并且提供DOM接口可直接訪問對象及其屬性,SVG亦提供了事件響應函數可獲取界面、鼠標以及一些自定義的事件消息。有了這些支持,再加上SVG的對象分組功能(<g>分組標簽)以及javaScipt或Java綁定,就可以順利地完成動態顯示注解信息的功能。 以前面的包代碼為例,來看一下如何利用JavaScipt動態顯示注解信息。 <script><![CDATA[function show_note(evt) {var SVGDoc = evt.getTarget().getOwnerDocument();var note = SVGDoc.getElementById("note");var style = note.getStyle();style.setProperty("visibility", "visible");}]]></script><g id="package" onclick="show_note(evt)">包模板代碼,此處省略</g><g id="note" x="100" y="100" style="visibility:hidden" desc="note info">注解代碼,此處省略</g>
<path d="M5,5 C5,45 45,45 45,5" style="stroke:red; fill:none; stroke-linecap:but; stroke-dash
array:5,3,2"/>
其中路徑中的M表示Moveto(移動到),C表示Curve(貝賽爾曲線控制)。虛線也可跟隨注解對象同時顯示或消隱。 * 以Highlight + Slide方式講解UML圖<script><![CDATA[function highlight(evt) {var object = evt.getTarget();var style = object.getStyle();style.setProperty("fill", "red");}function restore(evt) {var object = evt.getTarget();var style = object.getStyle();style.setProperty("fill", "#ffffff");}]]></script><rect x="14" y="14" width="90" height="21" style="fill:#ffffff;stroke:#ffffff;stroke-width:1"onmouSEOver=" highlight(evt) " onmouseout="restore(evt)"/></rect>
也可以這樣: <rect x="14" y="14" width="90" height="21" style="fill:#ffffff;stroke:#ffffff;stroke-wid th:1" /> <set attributeName="fill" from="#ffffff " to="red" begin=" mouseover" end=" mouseout"/> </rect>
幻燈片都是以Slide方式一頁一頁進行演示的,我們假如要講解一個軟件系統,或者說交付系統設計方案,也可以直接使用SVG來完成。在SVG中,結合<a>標簽或<set>標簽,和xlink:href 屬性一起可以建立一個鏈接,這個功能使得Slide方式得以實施。結合JavaScript函數setTimeout可實現自動Slide Show。 <svg><a xlink:href="http://…/slide_1.svg"/>…</a> </svg>
或<g id="object"> …</g><set id="object" xlink:href="http://…/slide_1.svg"/>
* 分層與圖分解<script><![CDATA[var kclick = false;function check(evt) {var SVGDoc = evt.getTarget().getOwnerDocument();var check_off = SVGDoc.getElementById("check_off");var check_on = SVGDoc.getElementById("check_on");var off_style = check_off.getStyle();var on_style = check_on.getStyle();if (kclick){off_style.setProperty("visibility", "visible");on_style.setProperty("visibility", "hidden");}else{off_style.setProperty("visibility", "hidden");on_style.setProperty("visibility", "visible");}kclick = !kclick;}]]></script><g id="check_off" onclick="check(evt)"><rect width="10" height="10" stroke-width="1" stroke="rgb(100,100,100)" fill="white"/></g><g id="check_on" visibility="hidden" onclick="check(evt)"><rect width="10" height="10" stroke-width="1" stroke="rgb(100,100,100)" fill="white"/><line x1="1" y1="1" x2="9" y2="9" stroke="black"/><line x1="1" y1="9" x2="9" y2="1" stroke="black"/></g><text x="20" y="10">Check Box 1</text>
function go() {getURL('/2004/2/data.1',fn);}function fn(obj) {alert(obj.content);setTimeout('go()',5000);}
當然了,后端服務器中數據源也可以是數據庫。SVG API提供了克隆或生成新元素插入現有DOM的方法,我們可以編寫Java程序訪問服務器中的數據庫,將元信息取出,生成新的SVG文件,或在現有SVG DOM中進行修改,反映出元信息的變化。下面的代碼是生成SVG文件的一個框架。 import org.apache.batik.dom.svg.SVGDOMImplementation;import org.w3c.dom.Document;import org.w3c.dom.Element;DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;Document doc = impl.createDocument(svgNS, "svg", null);// 得到SVG根元素Element svgRoot = doc.getDocumentElement();// 設置根元素的width和height屬性值svgRoot.setAttributeNS(null, "width", "400");svgRoot.setAttributeNS(null, "height", "450");// 訪問數據庫中的元信息,結合底層UML模板元件,生成新的SVG元素……// 把新元素連接在SVG根元素上svgRoot.appendChild(…);
其中,訪問數據庫部分內容被省略掉,在這里,要害是要結合UML模板元件,這樣就可快速準確地生成新的SVG組元素。 SVG還支持一些其它的功能,例如濾鏡、聲音等,也可以用來描述UML圖,在這里就不再多說了,有愛好的讀者可以翻閱相關書籍,這里僅僅是提出一些想法,實現時還需要不厭其煩地關注一些細節信息。 五、相關工具新聞熱點
疑難解答