f@0: /* f@0: accessPD - An accessible PD patches editor f@0: f@0: Copyright (C) 2014 Fiore Martin f@0: f@0: This program is free software: you can redistribute it and/or modify f@0: it under the terms of the GNU General Public License as published by f@0: the Free Software Foundation, either version 3 of the License, or f@0: (at your option) any later version. f@0: f@0: This program is distributed in the hope that it will be useful, f@0: but WITHOUT ANY WARRANTY; without even the implied warranty of f@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the f@0: GNU General Public License for more details. f@0: f@0: You should have received a copy of the GNU General Public License f@0: along with this program. If not, see . f@0: */ f@1: package uk.ac.qmul.eecs.ccmi.pdsupport; f@1: f@1: import java.io.IOException; f@1: import java.io.InputStream; f@1: import java.io.OutputStream; f@1: import java.io.OutputStreamWriter; f@1: import java.io.PrintWriter; f@1: import java.nio.charset.Charset; f@1: f@1: import uk.ac.qmul.eecs.ccmi.gui.Diagram; f@1: import uk.ac.qmul.eecs.ccmi.gui.Edge; f@1: import uk.ac.qmul.eecs.ccmi.gui.Node; f@1: f@0: public class PdPersistenceManager { f@0: private static PdPersistenceManager singleton; f@0: public final static String PD_EXTENSION = ".pd"; f@0: f@0: public static PdPersistenceManager getInstance(){ f@0: if(singleton == null){ f@0: singleton = new PdPersistenceManager(); f@0: } f@0: f@0: return singleton; f@0: } f@0: f@0: public void encodeDiagramInstance(Diagram diagram, String newName, OutputStream out){ f@0: OutputStreamWriter writer = new OutputStreamWriter(out, Charset.forName("US-ASCII")); f@0: f@0: PrintWriter printWriter = new PrintWriter(writer); f@0: f@0: printWriter.print("#N canvas 0 0 550 400 10;\r\n"); f@0: f@0: f@0: int index = 0; f@0: for(Node n : diagram.getCollectionModel().getNodes()){ f@0: PdObject pdObj = (PdObject)n; f@0: f@0: pdObj.setOrderNumber(index++); f@0: printWriter.print(pdObj.toPdFile()+";\r\n"); f@0: } f@0: f@0: for(Edge e : diagram.getCollectionModel().getEdges()){ f@0: PdConnection pdCon = (PdConnection)e; f@0: printWriter.print(pdCon.toPdFile()+";\r\n"); f@0: } f@0: f@0: printWriter.close(); f@0: } f@0: f@0: public Diagram decodeDiagramInstance(InputStream in) throws IOException { f@0: return null; f@0: } f@0: f@0: public void encodeDiagramInstance(Diagram diagram, OutputStream out) throws IOException{ f@0: encodeDiagramInstance(diagram, diagram.getName(),out); f@0: } f@0: f@0: f@0: f@0: }