You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GrafikModel.java 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package mvcgrafik.model;
  7. import java.awt.Point;
  8. import java.io.BufferedInputStream;
  9. import java.io.BufferedOutputStream;
  10. import java.io.FileInputStream;
  11. import java.io.FileNotFoundException;
  12. import java.io.FileOutputStream;
  13. import java.io.IOException;
  14. import java.io.ObjectInputStream;
  15. import java.io.ObjectOutputStream;
  16. import java.util.ArrayList;
  17. import java.util.Collections;
  18. import java.util.List;
  19. /**
  20. *
  21. * @author le
  22. */
  23. public class GrafikModel
  24. {
  25. private ArrayList<Figure> figures;
  26. public GrafikModel()
  27. {
  28. figures = new ArrayList<>();
  29. }
  30. public Figure addFigure()
  31. {
  32. figures.add(new Figure());
  33. return figures.get(figures.size() - 1);
  34. }
  35. public List<Figure> getFigures()
  36. {
  37. return Collections.unmodifiableList(figures);
  38. }
  39. public void speichereDatei(String dateiname) throws FileNotFoundException, IOException
  40. {
  41. FileOutputStream fos = new FileOutputStream(dateiname);
  42. BufferedOutputStream buffout = new BufferedOutputStream(fos);
  43. ObjectOutputStream oos = new ObjectOutputStream(buffout);
  44. oos.writeObject(figures);
  45. oos.flush();
  46. oos.close();
  47. }
  48. public void ladeDatei(String dateiname) throws FileNotFoundException, IOException, ClassNotFoundException
  49. {
  50. FileInputStream fis = new FileInputStream(dateiname);
  51. BufferedInputStream buffin = new BufferedInputStream(fis);
  52. ObjectInputStream ois = new ObjectInputStream(buffin);
  53. Object obj = ois.readObject();
  54. // if (obj instanceof ArrayList)
  55. // {
  56. // punkte = (ArrayList<Point>) obj;
  57. // }
  58. // else
  59. // {
  60. // Fehler ....
  61. // }
  62. figures = (ArrayList<Figure>) ois.readObject();
  63. ois.close();
  64. }
  65. }