|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- /*
- * 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<Figure> figures;
-
- public GrafikModel()
- {
- figures = new ArrayList<>();
- }
-
- public Figure addFigure()
- {
- figures.add(new Figure());
- return figures.get(figures.size() - 1);
- }
-
- public List<Figure> 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<Point>) obj;
- // }
- // else
- // {
- // Fehler ....
- // }
- figures = (ArrayList<Figure>) ois.readObject();
- ois.close();
- }
-
- }
|