f@0
|
1 /*
|
f@0
|
2 accessPD - An accessible PD patches editor
|
f@0
|
3
|
f@0
|
4 Copyright (C) 2014 Fiore Martin
|
f@0
|
5
|
f@0
|
6 This program is free software: you can redistribute it and/or modify
|
f@0
|
7 it under the terms of the GNU General Public License as published by
|
f@0
|
8 the Free Software Foundation, either version 3 of the License, or
|
f@0
|
9 (at your option) any later version.
|
f@0
|
10
|
f@0
|
11 This program is distributed in the hope that it will be useful,
|
f@0
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
f@0
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
f@0
|
14 GNU General Public License for more details.
|
f@0
|
15
|
f@0
|
16 You should have received a copy of the GNU General Public License
|
f@0
|
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
f@0
|
18 */
|
f@1
|
19 package uk.ac.qmul.eecs.ccmi.pdsupport;
|
f@1
|
20
|
f@1
|
21 import java.io.IOException;
|
f@1
|
22 import java.io.InputStream;
|
f@1
|
23 import java.io.OutputStream;
|
f@1
|
24 import java.io.OutputStreamWriter;
|
f@1
|
25 import java.io.PrintWriter;
|
f@1
|
26 import java.nio.charset.Charset;
|
f@1
|
27
|
f@1
|
28 import uk.ac.qmul.eecs.ccmi.gui.Diagram;
|
f@1
|
29 import uk.ac.qmul.eecs.ccmi.gui.Edge;
|
f@1
|
30 import uk.ac.qmul.eecs.ccmi.gui.Node;
|
f@1
|
31
|
f@0
|
32 public class PdPersistenceManager {
|
f@0
|
33 private static PdPersistenceManager singleton;
|
f@0
|
34 public final static String PD_EXTENSION = ".pd";
|
f@0
|
35
|
f@0
|
36 public static PdPersistenceManager getInstance(){
|
f@0
|
37 if(singleton == null){
|
f@0
|
38 singleton = new PdPersistenceManager();
|
f@0
|
39 }
|
f@0
|
40
|
f@0
|
41 return singleton;
|
f@0
|
42 }
|
f@0
|
43
|
f@0
|
44 public void encodeDiagramInstance(Diagram diagram, String newName, OutputStream out){
|
f@0
|
45 OutputStreamWriter writer = new OutputStreamWriter(out, Charset.forName("US-ASCII"));
|
f@0
|
46
|
f@0
|
47 PrintWriter printWriter = new PrintWriter(writer);
|
f@0
|
48
|
f@0
|
49 printWriter.print("#N canvas 0 0 550 400 10;\r\n");
|
f@0
|
50
|
f@0
|
51
|
f@0
|
52 int index = 0;
|
f@0
|
53 for(Node n : diagram.getCollectionModel().getNodes()){
|
f@0
|
54 PdObject pdObj = (PdObject)n;
|
f@0
|
55
|
f@0
|
56 pdObj.setOrderNumber(index++);
|
f@0
|
57 printWriter.print(pdObj.toPdFile()+";\r\n");
|
f@0
|
58 }
|
f@0
|
59
|
f@0
|
60 for(Edge e : diagram.getCollectionModel().getEdges()){
|
f@0
|
61 PdConnection pdCon = (PdConnection)e;
|
f@0
|
62 printWriter.print(pdCon.toPdFile()+";\r\n");
|
f@0
|
63 }
|
f@0
|
64
|
f@0
|
65 printWriter.close();
|
f@0
|
66 }
|
f@0
|
67
|
f@0
|
68 public Diagram decodeDiagramInstance(InputStream in) throws IOException {
|
f@0
|
69 return null;
|
f@0
|
70 }
|
f@0
|
71
|
f@0
|
72 public void encodeDiagramInstance(Diagram diagram, OutputStream out) throws IOException{
|
f@0
|
73 encodeDiagramInstance(diagram, diagram.getName(),out);
|
f@0
|
74 }
|
f@0
|
75
|
f@0
|
76
|
f@0
|
77
|
f@0
|
78 }
|