/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package kommunikation.transmitter; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Observable; import java.util.logging.Logger; import kommunikation.logger.OhmLogger; /** * * @author le */ public class GrafikModel extends Observable { private ArrayList figuren; private ArrayList figurenFremd; private static final Logger lg = OhmLogger.getLogger(); public GrafikModel() { figuren = new ArrayList<>(); figurenFremd = new ArrayList<>(); } public void addFigurFremd(Figur f) { figurenFremd.add(f); lg.info("fremde Figur wurde hinzugefügt"); } public void addFigur(Figur f) { figuren.add(f); lg.info("Figur wurde hinzugefügt"); } public List getFigur() { return Collections.unmodifiableList(figuren); } public List getFigurFremd() { return Collections.unmodifiableList(figurenFremd); } public void speichereFiguren(File datei) throws FileNotFoundException, IOException { FileOutputStream fos = new FileOutputStream(datei); BufferedOutputStream bos = new BufferedOutputStream(fos); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(figuren); oos.flush(); oos.close(); } public void ladeFiguren(File dateiname) throws FileNotFoundException, IOException, ClassNotFoundException { FileInputStream fis = new FileInputStream(dateiname); BufferedInputStream buffin = new BufferedInputStream(fis); ObjectInputStream ois = new ObjectInputStream(buffin); figuren = (ArrayList) ois.readObject(); ois.close(); } }