|
|
|
|
|
|
|
|
return Collections.unmodifiableList(figuren); |
|
|
return Collections.unmodifiableList(figuren); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Persistenz via Serialisierung |
|
|
|
|
|
* @param dateiname |
|
|
|
|
|
* @throws FileNotFoundException |
|
|
|
|
|
* @throws IOException |
|
|
|
|
|
*/ |
|
|
|
|
|
public void speicherePunkte(String dateiname) throws FileNotFoundException, IOException |
|
|
|
|
|
{ |
|
|
|
|
|
// an Preferences denken!! |
|
|
|
|
|
FileOutputStream fos = new FileOutputStream(dateiname); |
|
|
|
|
|
//wichtig Puffer -> Performance |
|
|
|
|
|
BufferedOutputStream bos = new BufferedOutputStream(fos); |
|
|
|
|
|
//Serialisierung |
|
|
|
|
|
ObjectOutputStream oos = new ObjectOutputStream(bos); |
|
|
|
|
|
oos.writeObject(figuren); |
|
|
|
|
|
oos.flush(); // Puffer |
|
|
|
|
|
oos.close(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void lesePunkte(String dateiname) throws FileNotFoundException, IOException, ClassNotFoundException |
|
|
|
|
|
{ |
|
|
|
|
|
// an Preferences denken!! |
|
|
|
|
|
FileInputStream fis = new FileInputStream(dateiname); |
|
|
|
|
|
//wichtig Puffer -> Performance |
|
|
|
|
|
BufferedInputStream bis = new BufferedInputStream(fis); |
|
|
|
|
|
//Serialisierung |
|
|
|
|
|
ObjectInputStream ois = new ObjectInputStream(bis); |
|
|
|
|
|
Object daten = ois.readObject(); // Achtung |
|
|
|
|
|
// if (daten instanceof ArrayList) |
|
|
|
|
|
// { |
|
|
|
|
|
// punkte = (ArrayList<Point>)daten; |
|
|
|
|
|
// } |
|
|
|
|
|
//eleganter |
|
|
|
|
|
if (daten instanceof ArrayList liste) |
|
|
|
|
|
{ |
|
|
|
|
|
figuren = liste; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void endShape() { |
|
|
public void endShape() { |
|
|
figuren.add(aktuelleFigur); |
|
|
figuren.add(aktuelleFigur); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void setFigur(Figur figur){ |
|
|
public void setFigur(Figur figur){ |
|
|
aktuelleFigur = figur; |
|
|
|
|
|
|
|
|
//aktuelleFigur = figur; |
|
|
figuren.add(figur); |
|
|
figuren.add(figur); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Bestimmt die Adresse des zuletzt besuchten Ordners |
|
|
|
|
|
* @return letzter Ordner |
|
|
|
|
|
*/ |
|
|
|
|
|
public String getPref() |
|
|
|
|
|
{ |
|
|
|
|
|
pref = Preferences.userNodeForPackage(getClass()); |
|
|
|
|
|
return pref.get("lastDirectory", null); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Setzt die Preferenz zu dem zuletzt besuchten Ordner |
|
|
|
|
|
* @param lastDirectory Bezeichner "lastDirectory" |
|
|
|
|
|
* @param lastAdress Adresse des zuletzt besuchten Ordners |
|
|
|
|
|
*/ |
|
|
|
|
|
public void putPref(String lastDirectory, String lastAdress) |
|
|
|
|
|
{ |
|
|
|
|
|
pref.put(lastDirectory, lastAdress); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|