/* * 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 mvcgrafik.model; import java.awt.Point; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; 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; /** * * @author le */ public class GrafikModel { private ArrayList
figures; public GrafikModel() { figures = new ArrayList<>(); } public Figure addFigure() { figures.add(new Figure()); return figures.get(figures.size() - 1); } public List
getFigures() { return Collections.unmodifiableList(figures); } public void speichereDatei(String dateiname) throws FileNotFoundException, IOException { FileOutputStream fos = new FileOutputStream(dateiname); BufferedOutputStream buffout = new BufferedOutputStream(fos); ObjectOutputStream oos = new ObjectOutputStream(buffout); oos.writeObject(figures); oos.flush(); oos.close(); } public void ladeDatei(String dateiname) throws FileNotFoundException, IOException, ClassNotFoundException { FileInputStream fis = new FileInputStream(dateiname); BufferedInputStream buffin = new BufferedInputStream(fis); ObjectInputStream ois = new ObjectInputStream(buffin); Object obj = ois.readObject(); // if (obj instanceof ArrayList) // { // punkte = (ArrayList) obj; // } // else // { // Fehler .... // } figures = (ArrayList
) ois.readObject(); ois.close(); } }