Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 247:bf7c96516dd0 Implementation_of_communication
fix createOmnigraffle method & add document for command line
author | tatsuki |
---|---|
date | Tue, 05 Jul 2016 06:59:03 +0900 |
parents | 4b4e3f25ca1b |
children | c0f49708d9aa |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/commandline/commandline.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/omnigraffle/App.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/omnigraffle/CreateXmlDocument.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/omnigraffle/InsertNodePositionData.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/omnigraffle/OmniGraffleCreater.java |
diffstat | 5 files changed, 569 insertions(+), 522 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/commandline/commandline.java Tue Jul 05 01:56:11 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/commandline/commandline.java Tue Jul 05 06:59:03 2016 +0900 @@ -8,6 +8,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.DefaultNodePath; import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.DefaultTreeEditor; import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.omnigraffle.OmniGraffleCreater; import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; @@ -16,16 +17,54 @@ import jp.ac.u_ryukyu.ie.cr.jungle.util.Error; import jp.ac.u_ryukyu.ie.cr.jungle.xml.reader.XmlReader; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerException; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.net.URISyntaxException; import java.nio.ByteBuffer; import java.util.Iterator; import java.util.LinkedList; -/** - * 就活でjungleを見せるために作ったもの - * それ以降アップデートする予定はない +/* + * コマンドラインの簡単な使い方 + * エラー処理とかはまだ書いてない + * 本当にプロトタイプ + * + * + * 木の一覧 + * trees + * + * データのimport + * treeName.import(path/to/xml) + * + * データのexport + * treeName.export() + * treeのデータをomnigraffle形式で出力する + * + * + * データのfind + * treeName.find() + * で全てのデータを表示 + * + * treeName.find(条件) + * で条件に一致するNodeの取得 + * 例 treeName.find(name = kanagawa) + * + * treeName.find(条件, {表示するkey}) + * 条件に一致するNodeの表示するkeyを表示する + * + * treeName.find(, {表示するkey}) + * でも OK + * treeName.find(検索するkey 例 id) 絞込はまだ treeNameは:revisionで過去のTreeにアクセス可能 find(条件,{表示するkey}) + * + * Nodeの追加 + * treeName.insert(<path>,key:value,key:value………) + * + * attribute等のupdate + * treeName.insertAttribute(path,key:value, ………) treeName path <Path> keys key values attribute + * */ public class commandline { @@ -67,7 +106,7 @@ System.out.println("---------------------------------------------------------------------"); } - private void parse(String sql) { + private void parse(String sql) throws ParserConfigurationException, TransformerException, IOException, URISyntaxException { String[] split = sql.replace(" ", "").split("\\."); Iterator<String> iterator = new Iterator<String>() { private int count = 0; @@ -97,15 +136,15 @@ if (cmd[1] != null) { switch (cmd[0]) { - case "find": //検索 treeName.find(検索するkey 例 id) 絞込はまだ treeNameは:revisionで過去のTreeにアクセス可能 find(条件,{表示するkey}) + case "find": String condition = cmd[1].replace(")", ""); // )を取り除く find(treeName, condition, iterator); break; - case "insert"://Nodeの追加 treeName.insert(<path>,key:value,key:value………) + case "insert": String value = cmd[1].replace(")", ""); // )を取り除く insert(treeName, value, iterator); break; - case "insertAttribute"://attribute等のupdate treeName.insertAttribute(path,key:value, ………) treeName path <Path> keys key values attribute + case "insertAttribute": value = cmd[1].replace(")", ""); // )を取り除く update(treeName, value, iterator); break; @@ -113,10 +152,19 @@ String url = cmd[1].replace(")", ""); // )を取り除く dataImport(treeName, url); //xmlをimportする treename.import(url) break; + case "export"://木をOmniGraffle形式にExportする + dataExport(treeName); + break; } } } + private void dataExport(String treeName) throws URISyntaxException, ParserConfigurationException, TransformerException, IOException { + JungleTree tree = jungle.getTreeByName(treeName); + OmniGraffleCreater omnigraffleCreater = new OmniGraffleCreater(treeName,tree); + omnigraffleCreater.createJungleTreeClassDiagram(); + } + private void dataImport(String treeName, String url) { if (treeName.equals("") || url.equals("")) { System.out.println("faild");
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/omnigraffle/App.java Tue Jul 05 01:56:11 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/omnigraffle/App.java Tue Jul 05 06:59:03 2016 +0900 @@ -31,8 +31,8 @@ return ; } - CreateXmlDocument creater = new CreateXmlDocument(args[0], tree); - creater.createJungleTreeClassDiagramGraphics(); + OmniGraffleCreater creater = new OmniGraffleCreater(args[0], tree); + creater.createJungleTreeClassDiagram(); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/omnigraffle/CreateXmlDocument.java Tue Jul 05 01:56:11 2016 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,503 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.jungle.store.omnigraffle; - - -import jp.ac.u_ryukyu.ie.cr.jungle.JungleTree; -import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNodeAttributes; -import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNodeChildren; -import jp.ac.u_ryukyu.ie.cr.jungle.util.Pair; -import org.w3c.dom.DOMImplementation; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentType; -import org.w3c.dom.Element; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; -import java.io.*; -import java.net.URISyntaxException; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.TreeMap; - - -public class CreateXmlDocument { - - private String file_name; - private Document document; - private String PUBLIC_ID = "-//Apple//DTD PLIST 1.0//EN"; - private String SYSTEM_ID = "http://www.apple.com/DTDs/PropertyList-1.0.dtd"; - private JungleTree tree; - private String FONT_SIZE = "14"; - - - CreateXmlDocument(String file_name, JungleTree tree) throws ParserConfigurationException, IOException, URISyntaxException, TransformerException { - this.file_name = file_name; - this.tree = tree; - - DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - assert documentBuilder != null; - - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - - DOMImplementation domImpl = builder.getDOMImplementation(); - - DocumentType docType = domImpl.createDocumentType("plist", PUBLIC_ID, SYSTEM_ID); - document = domImpl.createDocument("", "plist", docType); - } - - void createJungleTreeClassDiagramGraphics() throws IOException, TransformerException { - - createXMLHead(); - createJungleTreeGraphics(); - createXMLTail(); - write(); - } - - private void createXMLHead() throws IOException {//jungleとは関係ない部分をここで記述する - Element plist = document.getDocumentElement(); - plist.setAttribute("version", "1.0"); - - Element dict = createElement("dict"); - plist.appendChild(dict); - - dict.appendChild(createElement("key", "ActiveLayerIndex")); - dict.appendChild(createElement("integer", "0")); - dict.appendChild(createElement("key", "ApplicationVersion")); - - Element array = createElement("array"); - dict.appendChild(array); - - array.appendChild(createElement("string", "com.omnigroup.OmniGraffle")); - array.appendChild(createElement("string", "139.16.0.171715")); - - dict.appendChild(createElement("key", "AutoAdjust")); - dict.appendChild(createElement("true")); - dict.appendChild(createElement("key", "BackgroundGraphic")); - - - Element dictChild = createElement("dict"); - dict.appendChild(dictChild); - dictChild.appendChild(createElement("key", "Bounds")); - dictChild.appendChild(createElement("string", "{{0, 0}, {0,0}}"));//キャンパスサイズ 図形とかに応じて勝手に変更されるから0でいい? 複数個集まった時のやつ? {558.99997329711914, 783} - dictChild.appendChild(createElement("key", "Class")); - dictChild.appendChild(createElement("string", "SolidGraphic")); - dictChild.appendChild(createElement("key", "ID")); - dictChild.appendChild(createElement("integer", "0")); - dictChild.appendChild(createElement("key", "Style")); - - Element dictShadow = createElement("dict"); - dictChild.appendChild(dictShadow); - - dictShadow.appendChild(createElement("key", "shadow")); - - Element dictShadowDraws = createElement("dict"); - dictShadow.appendChild(dictShadowDraws); - dictShadowDraws.appendChild(createElement("key", "Draws")); - dictShadowDraws.appendChild(createElement("string", "NO")); - - dictShadow.appendChild(createElement("key", "stroke")); - - Element dictStrokeDraws = createElement("dict"); - dictShadow.appendChild(dictStrokeDraws); - dictStrokeDraws.appendChild(createElement("key", "Draws")); - dictStrokeDraws.appendChild(createElement("string", "NO")); - - dict.appendChild(createElement("key", "BaseZoom")); - dict.appendChild(createElement("integer", "0")); - dict.appendChild(createElement("key", "CanvasOrigin")); - dict.appendChild(createElement("string", "{0, 0}")); - dict.appendChild(createElement("key", "ColumnAlign")); - dict.appendChild(createElement("integer", "1")); - dict.appendChild(createElement("key", "ColumnSpacing")); - dict.appendChild(createElement("real", "36")); - dict.appendChild(createElement("key", "Creator")); - dict.appendChild(createElement("string", "sister_clown")); //作成者の名前 - dict.appendChild(createElement("key", "DisplayScale")); - dict.appendChild(createElement("string", "1.000 cm = 1.000 cm")); - dict.appendChild(createElement("key", "GraphDocumentVersion")); - dict.appendChild(createElement("integer", "8")); - dict.appendChild(createElement("key", "GraphicsList")); - - - } - - - private void createJungleTreeGraphics() throws UnsupportedEncodingException { - - TreeMap<TreeNode, NodePoint> treeMap = new InsertNodePositionData(tree).InsertPositionData(); - Element plist = document.getDocumentElement(); - Element dict = (Element) plist.getLastChild(); - - Element graphicsArray = createElement("array"); - dict.appendChild(graphicsArray); - - int graphicsId = 1; - for (TreeNode node : treeMap.keySet()) { - Pair<Element, Integer> squarePair = createSquare(node, treeMap, graphicsId); - graphicsId = squarePair.right(); - graphicsArray.appendChild(squarePair.left()); - - Pair<LinkedList<Element>, Integer> linePair = createLine(node, treeMap, graphicsId); - graphicsId = linePair.right(); - - for (Element lineDict : linePair.left()) { - graphicsArray.appendChild(lineDict); - } - } - - - } - - private Pair<LinkedList<Element>, Integer> createLine(TreeNode node, TreeMap<TreeNode, NodePoint> treeMap, int graphicsId) { - TreeNodeChildren children = node.getChildren(); - NodePoint currentNodePoint = treeMap.get(node); - int startLineX = currentNodePoint.getX() + (currentNodePoint.getWidth() / 2); - int startLineY = currentNodePoint.getY() + (currentNodePoint.getHeight()); - LinkedList<Element> lineGraphicsList = new LinkedList<>(); - - for (TreeNode child : children) { - NodePoint childNodePoint = treeMap.get(child); - int endLineX = childNodePoint.getX() + (childNodePoint.getWidth() / 2); - int endLineY = childNodePoint.getY(); - - Element graphicsDict = createElement("dict"); - graphicsDict.appendChild(createElement("key", "Class")); - graphicsDict.appendChild(createElement("string", "LineGraphic")); - graphicsDict.appendChild(createElement("key", "ID")); - graphicsDict.appendChild(createElement("integer", String.valueOf(graphicsId))); - graphicsDict.appendChild(createElement("key", "Points")); - - Element pointArray = createElement("array"); - graphicsDict.appendChild(pointArray); - String startLine = "{" + startLineX + "," + startLineY + "}" ; - pointArray.appendChild(createElement("string", startLine)); - String endLine = "{" + endLineX + "," + endLineY + "}" ; - pointArray.appendChild(createElement("string", endLine)); - - graphicsDict.appendChild(createElement("key", "Style")); - - Element styleDict = createElement("dict"); - graphicsDict.appendChild(styleDict); - styleDict.appendChild(createElement("key", "stroke")); - - Element strokeDict = createElement("dict"); - styleDict.appendChild(strokeDict); - strokeDict.appendChild(createElement("key","HeadArrow")); - strokeDict.appendChild(createElement("string","0")); - strokeDict.appendChild(createElement("key","Join")); - strokeDict.appendChild(createElement("integer","0")); - strokeDict.appendChild(createElement("key","Legacy")); - strokeDict.appendChild(createElement("true")); - strokeDict.appendChild(createElement("key","TailArrow")); - strokeDict.appendChild(createElement("string","0")); - lineGraphicsList.add(graphicsDict); - graphicsId++; - } - return new Pair<>(lineGraphicsList,graphicsId); - } - - private Pair<Element, Integer> createSquare(TreeNode node, TreeMap<TreeNode, NodePoint> treeMap, int graphicsId) throws UnsupportedEncodingException { - - NodePoint np = treeMap.get(node); - Element graphicsDict = createElement("dict"); - graphicsDict.appendChild(createElement("key", "Bounds")); - - int x = np.getX(); - int y = np.getY(); - int height = np.getHeight(); - int width = np.getWidth(); - String squareCoordinate = "{{" + x + "," + y + "},{" + width + "," + height + "}}"; - graphicsDict.appendChild(createElement("string", squareCoordinate)); - graphicsDict.appendChild(createElement("key", "Class")); - graphicsDict.appendChild(createElement("string", "ShapedGraphic")); - graphicsDict.appendChild(createElement("key", "FontInfo")); - - Element fontDict = createElement("dict"); - graphicsDict.appendChild(fontDict); - fontDict.appendChild(createElement("key", "Font")); - fontDict.appendChild(createElement("string", "HiraKakuProN-W3")); //fontの指定 下の方でもいろいろやってるからあれかも? - fontDict.appendChild(createElement("key", "Size")); - fontDict.appendChild(createElement("real", FONT_SIZE)); - - graphicsDict.appendChild(createElement("key", "ID")); - graphicsDict.appendChild(createElement("integer", String.valueOf(graphicsId))); - graphicsDict.appendChild(createElement("key", "Magnets")); - - Element magnetArray = createElement("array"); - graphicsDict.appendChild(magnetArray); - magnetArray.appendChild(createElement("string", "{0, 1}")); - magnetArray.appendChild(createElement("string", "{0, -1}")); - magnetArray.appendChild(createElement("string", "{1, 0}")); - magnetArray.appendChild(createElement("string", "{-1, 0}")); - - graphicsDict.appendChild(createElement("key", "Shape")); - graphicsDict.appendChild(createElement("string", "Rectangle")); - graphicsDict.appendChild(createElement("key", "Style")); - - Element styleDict = createElement("dict"); - graphicsDict.appendChild(styleDict); - styleDict.appendChild(createElement("key", "shadow")); - - Element shadowDict = createElement("dict"); - styleDict.appendChild(shadowDict); - shadowDict.appendChild(createElement("key", "Draws")); - shadowDict.appendChild(createElement("string", "NO")); - - graphicsDict.appendChild(createElement("key", "Text")); - Element textDict = createElement("dict"); - graphicsDict.appendChild(textDict); - textDict.appendChild(createElement("key", "Text")); - String text = getText(node); - textDict.appendChild(createElement("string", text)); - textDict.appendChild(createElement("key", "VerticalPad")); - textDict.appendChild(createElement("integer", "0")); - return new Pair<>(graphicsDict, graphicsId + 1); - } - - private String getText(TreeNode node) throws UnsupportedEncodingException { - TreeNodeAttributes nodeAttribute = node.getAttributes(); - - Iterator<String> keys = nodeAttribute.getKeys(); - String nodeValue = ""; - while (keys.hasNext()) { - String key = keys.next(); - String value = nodeAttribute.getString(key); - nodeValue += convertSjis(key); - nodeValue += (" " + convertSjis(":") + " "); - nodeValue += convertSjis(value); - nodeValue += "\\\n"; - } - - return "{\\rtf1\\ansi\\ansicpg932\\cocoartf1343\\cocoasubrtf140\n" + - "\\cocoascreenfonts1{\\fonttbl\\f0\\fnil\\fcharset128 HiraKakuProN-W3;}\n" + - "{\\colortbl;\\red255\\green255\\blue255;}\n" + - "\\pard\\tx560\\tx1120\\tx1680\\tx2240\\tx2800\\tx3360\\tx3920\\tx4480\\tx5040\\tx5600\\tx6160\\tx6720\\pardirnatural\\qc\n" + - "\n" + "\\f0\\fs24" + " \\cf0 " + nodeValue + "}"; - } - - private String convertSjis(String str) throws UnsupportedEncodingException { - String text = ""; - byte[] bytes = str.getBytes("SJIS"); - for (int count = 0; count < bytes.length; count++) { - String sjisByteCode1 = Integer.toHexString(bytes[count] & 0xFF); - - text = text + "\\'" + sjisByteCode1; - } - return text; - } - - private void createXMLTail() { - Element plist = document.getDocumentElement(); - Element dict = (Element) plist.getLastChild(); - dict.appendChild(createElement("key", "GridInfo"));//ここもまだ使いそう? - dict.appendChild(createElement("dict")); - - dict.appendChild(createElement("key", "GuidesLocked")); - dict.appendChild(createElement("string", "NO")); - dict.appendChild(createElement("key", "GuidesVisible")); - dict.appendChild(createElement("string", "YES")); - dict.appendChild(createElement("key", "HPages")); - dict.appendChild(createElement("integer", "1")); - dict.appendChild(createElement("key", "ImageCounter")); - dict.appendChild(createElement("integer", "1")); - dict.appendChild(createElement("key", "KeepToScale")); - dict.appendChild(createElement("false")); - dict.appendChild(createElement("key", "Layers")); - - Element layerArray = createElement("array"); - dict.appendChild(layerArray); - - Element layerDict = createElement("dict"); - layerArray.appendChild(layerDict); - - layerDict.appendChild(createElement("key", "Lock")); - layerDict.appendChild(createElement("string", "NO")); - layerDict.appendChild(createElement("key", "Name")); - layerDict.appendChild(createElement("string", "レイヤー 1")); - layerDict.appendChild(createElement("key", "Print")); - layerDict.appendChild(createElement("string", "YES")); - layerDict.appendChild(createElement("key", "View")); - layerDict.appendChild(createElement("string", "YES")); - - dict.appendChild(createElement("key", "LayoutInfo")); - - Element layoutInfoDict = createElement("dict"); - dict.appendChild(layoutInfoDict); - - layoutInfoDict.appendChild(createElement("key", "Animate")); - layoutInfoDict.appendChild(createElement("string", "NO")); - layoutInfoDict.appendChild(createElement("key", "circoMinDist")); - layoutInfoDict.appendChild(createElement("real", "18")); - layoutInfoDict.appendChild(createElement("key", "circoSeparation")); - layoutInfoDict.appendChild(createElement("real", "0.0")); - layoutInfoDict.appendChild(createElement("key", "layoutEngine")); - layoutInfoDict.appendChild(createElement("string", "dot")); - layoutInfoDict.appendChild(createElement("key", "neatoSeparation")); - layoutInfoDict.appendChild(createElement("real", "0.0")); - layoutInfoDict.appendChild(createElement("key", "twopiSeparation")); - layoutInfoDict.appendChild(createElement("real", "0.0")); - - dict.appendChild(createElement("key", "LinksVisible")); - dict.appendChild(createElement("string", "NO")); - dict.appendChild(createElement("key", "MagnetsVisible")); - dict.appendChild(createElement("string", "NO")); - dict.appendChild(createElement("key", "MasterSheets")); - - Element mastersheetArray = createElement("array"); - dict.appendChild(mastersheetArray); - - dict.appendChild(createElement("key", "Modifier")); - dict.appendChild(createElement("string", "sister_clown")); - dict.appendChild(createElement("key", "NotesVisible")); - dict.appendChild(createElement("string", "NO")); - dict.appendChild(createElement("key", "Orientation")); - dict.appendChild(createElement("string", "2")); - dict.appendChild(createElement("key", "OriginVisible")); - dict.appendChild(createElement("string", "NO")); - dict.appendChild(createElement("key", "PageBreaks")); - dict.appendChild(createElement("string", "YES")); - dict.appendChild(createElement("key", "PrintInfo")); - - Element printInfoDict = createElement("dict"); - dict.appendChild(printInfoDict); - printInfoDict.appendChild(createElement("key", "NSBottomMargin")); - - Element NSBottomMarginArray = createElement("array"); - printInfoDict.appendChild(NSBottomMarginArray); - NSBottomMarginArray.appendChild(createElement("string", "float")); - NSBottomMarginArray.appendChild(createElement("string", "41")); - - printInfoDict.appendChild(createElement("key", "NSHorizonalPagination")); - Element NSHorizonalPaginationArray = createElement("array"); - printInfoDict.appendChild(NSHorizonalPaginationArray); - - NSHorizonalPaginationArray.appendChild(createElement("string", "coded")); - NSHorizonalPaginationArray.appendChild(createElement("string", "BAtzdHJlYW10eXBlZIHoA4QBQISEhAhOU051bWJlcgCEhAdOU1ZhbHVlAISECE5TT2JqZWN0AIWEASqEhAFxlwCG")); - - printInfoDict.appendChild(createElement("key", "NSLeftMargin")); - Element NSLeftMarginArray = createElement("array"); - printInfoDict.appendChild(NSLeftMarginArray); - NSLeftMarginArray.appendChild(createElement("string", "float")); - NSLeftMarginArray.appendChild(createElement("string", "18")); - - printInfoDict.appendChild(createElement("key", "NSPaperSize")); - Element NSPaperNameArray = createElement("array"); - printInfoDict.appendChild(NSPaperNameArray); - NSPaperNameArray.appendChild(createElement("string", "size"));//キャンパスサイズっぽい - NSPaperNameArray.appendChild(createElement("string", "{1000,1000}")); - - printInfoDict.appendChild(createElement("key", "NSPrintReverseOrientation")); - Element NSPrintReverseOrientationArray = createElement("array"); - printInfoDict.appendChild(NSPrintReverseOrientationArray); - NSPrintReverseOrientationArray.appendChild(createElement("string", "int")); - NSPrintReverseOrientationArray.appendChild(createElement("string", "0")); - - printInfoDict.appendChild(createElement("key", "NSRightMargin")); - Element NSRightMarginArray = createElement("array"); - printInfoDict.appendChild(NSRightMarginArray); - NSRightMarginArray.appendChild(createElement("string", "float")); - NSRightMarginArray.appendChild(createElement("string", "18")); - - printInfoDict.appendChild(createElement("key", "NSTopMargin")); - Element NSTopMarginArray = createElement("array"); - printInfoDict.appendChild(NSTopMarginArray); - NSTopMarginArray.appendChild(createElement("string", "float")); - NSTopMarginArray.appendChild(createElement("string", "18")); - - dict.appendChild(createElement("key", "PrintOnePage")); - dict.appendChild(createElement("false")); - dict.appendChild(createElement("key", "ReadOnly")); - dict.appendChild(createElement("string", "NO")); - dict.appendChild(createElement("key", "RowAlign")); - dict.appendChild(createElement("integer", "1")); - dict.appendChild(createElement("key", "RowSpacing")); - dict.appendChild(createElement("real", "36")); - dict.appendChild(createElement("key", "SheetTitle")); - dict.appendChild(createElement("string", "キャンバス 1")); - dict.appendChild(createElement("key", "SmartAlignmentGuidesActive")); - dict.appendChild(createElement("string", "YES")); - dict.appendChild(createElement("key", "SmartDistanceGuidesActive")); - dict.appendChild(createElement("string", "YES")); - dict.appendChild(createElement("key", "UniqueID")); - dict.appendChild(createElement("integer", "1")); - dict.appendChild(createElement("key", "UseEntirePage")); - dict.appendChild(createElement("false")); - dict.appendChild(createElement("key", "VPages")); - dict.appendChild(createElement("integer", "1")); - dict.appendChild(createElement("key", "WindowInfo")); - - Element WindowInfoDict = createElement("dict"); - dict.appendChild(WindowInfoDict); - WindowInfoDict.appendChild(createElement("key", "CurrentSheet")); - WindowInfoDict.appendChild(createElement("integer", "0")); - WindowInfoDict.appendChild(createElement("key", "ExpandedCanvases")); - WindowInfoDict.appendChild(createElement("array")); - WindowInfoDict.appendChild(createElement("key", "Frame")); - WindowInfoDict.appendChild(createElement("string", "{{513, 0}, {1122, 1154}}")); //後で変える必要があるかも? - WindowInfoDict.appendChild(createElement("key", "ListView")); - WindowInfoDict.appendChild(createElement("true")); - WindowInfoDict.appendChild(createElement("key", "OutlineWidth")); - WindowInfoDict.appendChild(createElement("integer", "142")); - WindowInfoDict.appendChild(createElement("key", "RightSidebar")); - WindowInfoDict.appendChild(createElement("false")); - WindowInfoDict.appendChild(createElement("key", "ShowRuler")); - WindowInfoDict.appendChild(createElement("true")); - WindowInfoDict.appendChild(createElement("key", "Sidebar")); - WindowInfoDict.appendChild(createElement("true")); - WindowInfoDict.appendChild(createElement("key", "SidebarWidth")); - WindowInfoDict.appendChild(createElement("integer", "120")); - WindowInfoDict.appendChild(createElement("key", "VisibleRegion")); - WindowInfoDict.appendChild(createElement("string", "{{-708, -620}, {1974, 2024}}")); //変える以下略 - WindowInfoDict.appendChild(createElement("key", "Zoom")); - WindowInfoDict.appendChild(createElement("real", "1")); - WindowInfoDict.appendChild(createElement("key", "ZoomValues")); - - Element ZoomValuesArray = createElement("array"); - WindowInfoDict.appendChild(ZoomValuesArray); - - Element ZoomValuesArrayChild = createElement("array"); - ZoomValuesArray.appendChild(ZoomValuesArrayChild); - ZoomValuesArrayChild.appendChild(createElement("string", "キャンバス 1")); - ZoomValuesArrayChild.appendChild(createElement("real", "1")); - ZoomValuesArrayChild.appendChild(createElement("real", "1")); - - - } - - private Element createElement(String key) { - return document.createElement(key); - } - - private Element createElement(String key, String value) { - Element element = document.createElement(key); - element.appendChild(document.createTextNode(value)); - return element; - } - - private boolean write() throws TransformerException, FileNotFoundException { - TransformerFactory transFactory = TransformerFactory.newInstance(); - Transformer transformer = transFactory.newTransformer(); - transformer.setOutputProperty(OutputKeys.INDENT, "yes"); - transformer.setOutputProperty(OutputKeys.METHOD, "xml"); - transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, SYSTEM_ID); - transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, PUBLIC_ID); - transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "8"); - - DOMSource source = new DOMSource(document); - File file = new File("omnigraffle/" + file_name + ".graffle"); - FileOutputStream os = new FileOutputStream(file); - StreamResult result = new StreamResult(os); - transformer.transform(source, result); - System.out.println("put " + file_name); - return true; - } - -}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/omnigraffle/InsertNodePositionData.java Tue Jul 05 01:56:11 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/omnigraffle/InsertNodePositionData.java Tue Jul 05 06:59:03 2016 +0900 @@ -102,16 +102,6 @@ if (num > nodeList.size()) num = 0; } - - for (TreeNode node : treeMap.keySet()) { - NodePoint point = treeMap.get(node); - System.out.println("----------------------------"); - System.out.println(node.getAttributes().getString("element")); - System.out.println(node.getAttributes().getString("name")); - System.out.println("Y = " + point.getY()); - System.out.println("X = " + point.getX()); - System.out.println("----------------------------"); - } return treeMap; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/omnigraffle/OmniGraffleCreater.java Tue Jul 05 06:59:03 2016 +0900 @@ -0,0 +1,512 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.store.omnigraffle; + + +import jp.ac.u_ryukyu.ie.cr.jungle.JungleTree; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNodeAttributes; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNodeChildren; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Pair; +import org.w3c.dom.DOMImplementation; +import org.w3c.dom.Document; +import org.w3c.dom.DocumentType; +import org.w3c.dom.Element; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import java.io.*; +import java.net.URISyntaxException; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.TreeMap; + + +public class OmniGraffleCreater { + + private String file_name; + private Document document; + private String PUBLIC_ID = "-//Apple//DTD PLIST 1.0//EN"; + private String SYSTEM_ID = "http://www.apple.com/DTDs/PropertyList-1.0.dtd"; + private JungleTree tree; + private String FONT_SIZE = "14"; + private int CanvasSize_X = 100; + private int CanvasSize_Y = 100; + + public OmniGraffleCreater(String file_name, JungleTree tree) throws ParserConfigurationException, IOException, URISyntaxException, TransformerException { + this.file_name = file_name; + this.tree = tree; + + DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + assert documentBuilder != null; + + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + + DOMImplementation domImpl = builder.getDOMImplementation(); + + DocumentType docType = domImpl.createDocumentType("plist", PUBLIC_ID, SYSTEM_ID); + document = domImpl.createDocument("", "plist", docType); + } + + public void createJungleTreeClassDiagram() throws IOException, TransformerException { + + createXMLHead(); + createJungleTreeGraphics(); + createXMLTail(); + write(); + } + + private void createXMLHead() throws IOException {//jungleとは関係ない部分をここで記述する + Element plist = document.getDocumentElement(); + plist.setAttribute("version", "1.0"); + + Element dict = createElement("dict"); + plist.appendChild(dict); + + dict.appendChild(createElement("key", "ActiveLayerIndex")); + dict.appendChild(createElement("integer", "0")); + dict.appendChild(createElement("key", "ApplicationVersion")); + + Element array = createElement("array"); + dict.appendChild(array); + + array.appendChild(createElement("string", "com.omnigroup.OmniGraffle")); + array.appendChild(createElement("string", "139.16.0.171715")); + + dict.appendChild(createElement("key", "AutoAdjust")); + dict.appendChild(createElement("true")); + dict.appendChild(createElement("key", "BackgroundGraphic")); + + + Element dictChild = createElement("dict"); + dict.appendChild(dictChild); + dictChild.appendChild(createElement("key", "Bounds")); + dictChild.appendChild(createElement("string", "{{0, 0}, {0,0}}"));//キャンパスサイズ 図形とかに応じて勝手に変更されるから0でいい? 複数個集まった時のやつ? {558.99997329711914, 783} + dictChild.appendChild(createElement("key", "Class")); + dictChild.appendChild(createElement("string", "SolidGraphic")); + dictChild.appendChild(createElement("key", "ID")); + dictChild.appendChild(createElement("integer", "0")); + dictChild.appendChild(createElement("key", "Style")); + + Element dictShadow = createElement("dict"); + dictChild.appendChild(dictShadow); + + dictShadow.appendChild(createElement("key", "shadow")); + + Element dictShadowDraws = createElement("dict"); + dictShadow.appendChild(dictShadowDraws); + dictShadowDraws.appendChild(createElement("key", "Draws")); + dictShadowDraws.appendChild(createElement("string", "NO")); + + dictShadow.appendChild(createElement("key", "stroke")); + + Element dictStrokeDraws = createElement("dict"); + dictShadow.appendChild(dictStrokeDraws); + dictStrokeDraws.appendChild(createElement("key", "Draws")); + dictStrokeDraws.appendChild(createElement("string", "NO")); + + dict.appendChild(createElement("key", "BaseZoom")); + dict.appendChild(createElement("integer", "0")); + dict.appendChild(createElement("key", "CanvasOrigin")); + dict.appendChild(createElement("string", "{0, 0}")); + dict.appendChild(createElement("key", "ColumnAlign")); + dict.appendChild(createElement("integer", "1")); + dict.appendChild(createElement("key", "ColumnSpacing")); + dict.appendChild(createElement("real", "36")); + dict.appendChild(createElement("key", "Creator")); + dict.appendChild(createElement("string", "Jungle")); //作成者の名前 + dict.appendChild(createElement("key", "DisplayScale")); + dict.appendChild(createElement("string", "1.000 cm = 1.000 cm")); + dict.appendChild(createElement("key", "GraphDocumentVersion")); + dict.appendChild(createElement("integer", "8")); + dict.appendChild(createElement("key", "GraphicsList")); + + + } + + + private void createJungleTreeGraphics() throws UnsupportedEncodingException { + + TreeMap<TreeNode, NodePoint> treeMap = new InsertNodePositionData(tree).InsertPositionData(); + Element plist = document.getDocumentElement(); + Element dict = (Element) plist.getLastChild(); + + Element graphicsArray = createElement("array"); + dict.appendChild(graphicsArray); + + int graphicsId = 1; + for (TreeNode node : treeMap.keySet()) { + Pair<Element, Integer> squarePair = createSquare(node, treeMap, graphicsId); + graphicsId = squarePair.right(); + graphicsArray.appendChild(squarePair.left()); + + Pair<LinkedList<Element>, Integer> linePair = createLine(node, treeMap, graphicsId); + graphicsId = linePair.right(); + + for (Element lineDict : linePair.left()) { + graphicsArray.appendChild(lineDict); + } + } + + + } + + private Pair<LinkedList<Element>, Integer> createLine(TreeNode node, TreeMap<TreeNode, NodePoint> treeMap, int graphicsId) { + TreeNodeChildren children = node.getChildren(); + NodePoint currentNodePoint = treeMap.get(node); + int startLineX = currentNodePoint.getX() + (currentNodePoint.getWidth() / 2); + int startLineY = currentNodePoint.getY() + (currentNodePoint.getHeight()); + LinkedList<Element> lineGraphicsList = new LinkedList<>(); + + for (TreeNode child : children) { + NodePoint childNodePoint = treeMap.get(child); + int endLineX = childNodePoint.getX() + (childNodePoint.getWidth() / 2); + int endLineY = childNodePoint.getY(); + + Element graphicsDict = createElement("dict"); + graphicsDict.appendChild(createElement("key", "Class")); + graphicsDict.appendChild(createElement("string", "LineGraphic")); + graphicsDict.appendChild(createElement("key", "ID")); + graphicsDict.appendChild(createElement("integer", String.valueOf(graphicsId))); + graphicsDict.appendChild(createElement("key", "Points")); + + Element pointArray = createElement("array"); + graphicsDict.appendChild(pointArray); + String startLine = "{" + startLineX + "," + startLineY + "}" ; + pointArray.appendChild(createElement("string", startLine)); + String endLine = "{" + endLineX + "," + endLineY + "}" ; + pointArray.appendChild(createElement("string", endLine)); + + graphicsDict.appendChild(createElement("key", "Style")); + + Element styleDict = createElement("dict"); + graphicsDict.appendChild(styleDict); + styleDict.appendChild(createElement("key", "stroke")); + + Element strokeDict = createElement("dict"); + styleDict.appendChild(strokeDict); + strokeDict.appendChild(createElement("key","HeadArrow")); + strokeDict.appendChild(createElement("string","0")); + strokeDict.appendChild(createElement("key","Join")); + strokeDict.appendChild(createElement("integer","0")); + strokeDict.appendChild(createElement("key","Legacy")); + strokeDict.appendChild(createElement("true")); + strokeDict.appendChild(createElement("key","TailArrow")); + strokeDict.appendChild(createElement("string","0")); + lineGraphicsList.add(graphicsDict); + graphicsId++; + } + return new Pair<>(lineGraphicsList,graphicsId); + } + + private Pair<Element, Integer> createSquare(TreeNode node, TreeMap<TreeNode, NodePoint> treeMap, int graphicsId) throws UnsupportedEncodingException { + + NodePoint np = treeMap.get(node); + Element graphicsDict = createElement("dict"); + graphicsDict.appendChild(createElement("key", "Bounds")); + + int x = np.getX(); + int y = np.getY(); + + //キャンパスサイズを設定する、一番大きいX,Yの値を探す + if (x > CanvasSize_X) + CanvasSize_X = x; + if (x > CanvasSize_Y) + CanvasSize_Y = y; + + int height = np.getHeight(); + int width = np.getWidth(); + String squareCoordinate = "{{" + x + "," + y + "},{" + width + "," + height + "}}"; + graphicsDict.appendChild(createElement("string", squareCoordinate)); + graphicsDict.appendChild(createElement("key", "Class")); + graphicsDict.appendChild(createElement("string", "ShapedGraphic")); + graphicsDict.appendChild(createElement("key", "FontInfo")); + + Element fontDict = createElement("dict"); + graphicsDict.appendChild(fontDict); + fontDict.appendChild(createElement("key", "Font")); + fontDict.appendChild(createElement("string", "HiraKakuProN-W3")); //fontの指定 下の方でもいろいろやってるからあれかも? + fontDict.appendChild(createElement("key", "Size")); + fontDict.appendChild(createElement("real", FONT_SIZE)); + + graphicsDict.appendChild(createElement("key", "ID")); + graphicsDict.appendChild(createElement("integer", String.valueOf(graphicsId))); + graphicsDict.appendChild(createElement("key", "Magnets")); + + Element magnetArray = createElement("array"); + graphicsDict.appendChild(magnetArray); + magnetArray.appendChild(createElement("string", "{0, 1}")); + magnetArray.appendChild(createElement("string", "{0, -1}")); + magnetArray.appendChild(createElement("string", "{1, 0}")); + magnetArray.appendChild(createElement("string", "{-1, 0}")); + + graphicsDict.appendChild(createElement("key", "Shape")); + graphicsDict.appendChild(createElement("string", "Rectangle")); + graphicsDict.appendChild(createElement("key", "Style")); + + Element styleDict = createElement("dict"); + graphicsDict.appendChild(styleDict); + styleDict.appendChild(createElement("key", "shadow")); + + Element shadowDict = createElement("dict"); + styleDict.appendChild(shadowDict); + shadowDict.appendChild(createElement("key", "Draws")); + shadowDict.appendChild(createElement("string", "NO")); + + graphicsDict.appendChild(createElement("key", "Text")); + Element textDict = createElement("dict"); + graphicsDict.appendChild(textDict); + textDict.appendChild(createElement("key", "Text")); + String text = getText(node); + textDict.appendChild(createElement("string", text)); + textDict.appendChild(createElement("key", "VerticalPad")); + textDict.appendChild(createElement("integer", "0")); + return new Pair<>(graphicsDict, graphicsId + 1); + } + + private String getText(TreeNode node) throws UnsupportedEncodingException { + TreeNodeAttributes nodeAttribute = node.getAttributes(); + + Iterator<String> keys = nodeAttribute.getKeys(); + String nodeValue = ""; + while (keys.hasNext()) { + String key = keys.next(); + String value = nodeAttribute.getString(key); + nodeValue += convertSjis(key); + nodeValue += (" " + convertSjis(":") + " "); + nodeValue += convertSjis(value); + nodeValue += "\\\n"; + } + + return "{\\rtf1\\ansi\\ansicpg932\\cocoartf1343\\cocoasubrtf140\n" + + "\\cocoascreenfonts1{\\fonttbl\\f0\\fnil\\fcharset128 HiraKakuProN-W3;}\n" + + "{\\colortbl;\\red255\\green255\\blue255;}\n" + + "\\pard\\tx560\\tx1120\\tx1680\\tx2240\\tx2800\\tx3360\\tx3920\\tx4480\\tx5040\\tx5600\\tx6160\\tx6720\\pardirnatural\\qc\n" + + "\n" + "\\f0\\fs24" + " \\cf0 " + nodeValue + "}"; + } + + private String convertSjis(String str) throws UnsupportedEncodingException { + String text = ""; + byte[] bytes = str.getBytes("SJIS"); + for (int count = 0; count < bytes.length; count++) { + String sjisByteCode1 = Integer.toHexString(bytes[count] & 0xFF); + + text = text + "\\'" + sjisByteCode1; + } + return text; + } + + private void createXMLTail() { + Element plist = document.getDocumentElement(); + Element dict = (Element) plist.getLastChild(); + dict.appendChild(createElement("key", "GridInfo"));//ここもまだ使いそう? + dict.appendChild(createElement("dict")); + + dict.appendChild(createElement("key", "GuidesLocked")); + dict.appendChild(createElement("string", "NO")); + dict.appendChild(createElement("key", "GuidesVisible")); + dict.appendChild(createElement("string", "YES")); + dict.appendChild(createElement("key", "HPages")); + dict.appendChild(createElement("integer", "1")); + dict.appendChild(createElement("key", "ImageCounter")); + dict.appendChild(createElement("integer", "1")); + dict.appendChild(createElement("key", "KeepToScale")); + dict.appendChild(createElement("false")); + dict.appendChild(createElement("key", "Layers")); + + Element layerArray = createElement("array"); + dict.appendChild(layerArray); + + Element layerDict = createElement("dict"); + layerArray.appendChild(layerDict); + + layerDict.appendChild(createElement("key", "Lock")); + layerDict.appendChild(createElement("string", "NO")); + layerDict.appendChild(createElement("key", "Name")); + layerDict.appendChild(createElement("string", "レイヤー 1")); + layerDict.appendChild(createElement("key", "Print")); + layerDict.appendChild(createElement("string", "YES")); + layerDict.appendChild(createElement("key", "View")); + layerDict.appendChild(createElement("string", "YES")); + + dict.appendChild(createElement("key", "LayoutInfo")); + + Element layoutInfoDict = createElement("dict"); + dict.appendChild(layoutInfoDict); + + layoutInfoDict.appendChild(createElement("key", "Animate")); + layoutInfoDict.appendChild(createElement("string", "NO")); + layoutInfoDict.appendChild(createElement("key", "circoMinDist")); + layoutInfoDict.appendChild(createElement("real", "18")); + layoutInfoDict.appendChild(createElement("key", "circoSeparation")); + layoutInfoDict.appendChild(createElement("real", "0.0")); + layoutInfoDict.appendChild(createElement("key", "layoutEngine")); + layoutInfoDict.appendChild(createElement("string", "dot")); + layoutInfoDict.appendChild(createElement("key", "neatoSeparation")); + layoutInfoDict.appendChild(createElement("real", "0.0")); + layoutInfoDict.appendChild(createElement("key", "twopiSeparation")); + layoutInfoDict.appendChild(createElement("real", "0.0")); + + dict.appendChild(createElement("key", "LinksVisible")); + dict.appendChild(createElement("string", "NO")); + dict.appendChild(createElement("key", "MagnetsVisible")); + dict.appendChild(createElement("string", "NO")); + dict.appendChild(createElement("key", "MasterSheets")); + + Element mastersheetArray = createElement("array"); + dict.appendChild(mastersheetArray); + + dict.appendChild(createElement("key", "Modifier")); + dict.appendChild(createElement("string", "Jungle")); + dict.appendChild(createElement("key", "NotesVisible")); + dict.appendChild(createElement("string", "NO")); + dict.appendChild(createElement("key", "Orientation")); + dict.appendChild(createElement("string", "2")); + dict.appendChild(createElement("key", "OriginVisible")); + dict.appendChild(createElement("string", "NO")); + dict.appendChild(createElement("key", "PageBreaks")); + dict.appendChild(createElement("string", "YES")); + dict.appendChild(createElement("key", "PrintInfo")); + + Element printInfoDict = createElement("dict"); + dict.appendChild(printInfoDict); + printInfoDict.appendChild(createElement("key", "NSBottomMargin")); + + Element NSBottomMarginArray = createElement("array"); + printInfoDict.appendChild(NSBottomMarginArray); + NSBottomMarginArray.appendChild(createElement("string", "float")); + NSBottomMarginArray.appendChild(createElement("string", "41")); + + printInfoDict.appendChild(createElement("key", "NSHorizonalPagination")); + Element NSHorizonalPaginationArray = createElement("array"); + printInfoDict.appendChild(NSHorizonalPaginationArray); + + NSHorizonalPaginationArray.appendChild(createElement("string", "coded")); + NSHorizonalPaginationArray.appendChild(createElement("string", "BAtzdHJlYW10eXBlZIHoA4QBQISEhAhOU051bWJlcgCEhAdOU1ZhbHVlAISECE5TT2JqZWN0AIWEASqEhAFxlwCG")); + + printInfoDict.appendChild(createElement("key", "NSLeftMargin")); + Element NSLeftMarginArray = createElement("array"); + printInfoDict.appendChild(NSLeftMarginArray); + NSLeftMarginArray.appendChild(createElement("string", "float")); + NSLeftMarginArray.appendChild(createElement("string", "18")); + + printInfoDict.appendChild(createElement("key", "NSPaperSize")); + Element NSPaperNameArray = createElement("array"); + printInfoDict.appendChild(NSPaperNameArray); + NSPaperNameArray.appendChild(createElement("string", "size"));//キャンパスサイズっぽい + String canvasSize = "{" + (CanvasSize_Y + 200) + "," + (CanvasSize_X + 200) + "}"; + NSPaperNameArray.appendChild(createElement("string", canvasSize)); + + printInfoDict.appendChild(createElement("key", "NSPrintReverseOrientation")); + Element NSPrintReverseOrientationArray = createElement("array"); + printInfoDict.appendChild(NSPrintReverseOrientationArray); + NSPrintReverseOrientationArray.appendChild(createElement("string", "int")); + NSPrintReverseOrientationArray.appendChild(createElement("string", "0")); + + printInfoDict.appendChild(createElement("key", "NSRightMargin")); + Element NSRightMarginArray = createElement("array"); + printInfoDict.appendChild(NSRightMarginArray); + NSRightMarginArray.appendChild(createElement("string", "float")); + NSRightMarginArray.appendChild(createElement("string", "18")); + + printInfoDict.appendChild(createElement("key", "NSTopMargin")); + Element NSTopMarginArray = createElement("array"); + printInfoDict.appendChild(NSTopMarginArray); + NSTopMarginArray.appendChild(createElement("string", "float")); + NSTopMarginArray.appendChild(createElement("string", "18")); + + dict.appendChild(createElement("key", "PrintOnePage")); + dict.appendChild(createElement("false")); + dict.appendChild(createElement("key", "ReadOnly")); + dict.appendChild(createElement("string", "NO")); + dict.appendChild(createElement("key", "RowAlign")); + dict.appendChild(createElement("integer", "1")); + dict.appendChild(createElement("key", "RowSpacing")); + dict.appendChild(createElement("real", "36")); + dict.appendChild(createElement("key", "SheetTitle")); + dict.appendChild(createElement("string", "キャンバス 1")); + dict.appendChild(createElement("key", "SmartAlignmentGuidesActive")); + dict.appendChild(createElement("string", "YES")); + dict.appendChild(createElement("key", "SmartDistanceGuidesActive")); + dict.appendChild(createElement("string", "YES")); + dict.appendChild(createElement("key", "UniqueID")); + dict.appendChild(createElement("integer", "1")); + dict.appendChild(createElement("key", "UseEntirePage")); + dict.appendChild(createElement("false")); + dict.appendChild(createElement("key", "VPages")); + dict.appendChild(createElement("integer", "1")); + dict.appendChild(createElement("key", "WindowInfo")); + + Element WindowInfoDict = createElement("dict"); + dict.appendChild(WindowInfoDict); + WindowInfoDict.appendChild(createElement("key", "CurrentSheet")); + WindowInfoDict.appendChild(createElement("integer", "0")); + WindowInfoDict.appendChild(createElement("key", "ExpandedCanvases")); + WindowInfoDict.appendChild(createElement("array")); + WindowInfoDict.appendChild(createElement("key", "Frame")); + WindowInfoDict.appendChild(createElement("string", "{{513, 0}, {1122, 1154}}")); //後で変える必要があるかも? + WindowInfoDict.appendChild(createElement("key", "ListView")); + WindowInfoDict.appendChild(createElement("true")); + WindowInfoDict.appendChild(createElement("key", "OutlineWidth")); + WindowInfoDict.appendChild(createElement("integer", "142")); + WindowInfoDict.appendChild(createElement("key", "RightSidebar")); + WindowInfoDict.appendChild(createElement("false")); + WindowInfoDict.appendChild(createElement("key", "ShowRuler")); + WindowInfoDict.appendChild(createElement("true")); + WindowInfoDict.appendChild(createElement("key", "Sidebar")); + WindowInfoDict.appendChild(createElement("true")); + WindowInfoDict.appendChild(createElement("key", "SidebarWidth")); + WindowInfoDict.appendChild(createElement("integer", "120")); + WindowInfoDict.appendChild(createElement("key", "VisibleRegion")); + WindowInfoDict.appendChild(createElement("string", "{{-708, -620}, {1974, 2024}}")); //変える以下略 + WindowInfoDict.appendChild(createElement("key", "Zoom")); + WindowInfoDict.appendChild(createElement("real", "1")); + WindowInfoDict.appendChild(createElement("key", "ZoomValues")); + + Element ZoomValuesArray = createElement("array"); + WindowInfoDict.appendChild(ZoomValuesArray); + + Element ZoomValuesArrayChild = createElement("array"); + ZoomValuesArray.appendChild(ZoomValuesArrayChild); + ZoomValuesArrayChild.appendChild(createElement("string", "キャンバス 1")); + ZoomValuesArrayChild.appendChild(createElement("real", "1")); + ZoomValuesArrayChild.appendChild(createElement("real", "1")); + + + } + + private Element createElement(String key) { + return document.createElement(key); + } + + private Element createElement(String key, String value) { + Element element = document.createElement(key); + element.appendChild(document.createTextNode(value)); + return element; + } + + private boolean write() throws TransformerException, FileNotFoundException { + TransformerFactory transFactory = TransformerFactory.newInstance(); + Transformer transformer = transFactory.newTransformer(); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + transformer.setOutputProperty(OutputKeys.METHOD, "xml"); + transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, SYSTEM_ID); + transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, PUBLIC_ID); + transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "2"); + + DOMSource source = new DOMSource(document); + File file = new File("omnigraffle/" + file_name + ".graffle"); + FileOutputStream os = new FileOutputStream(file); + StreamResult result = new StreamResult(os); + transformer.transform(source, result); + System.out.println("put " + file_name); + return true; + } + +}