Läuft muss nurnoch aufgeräumt werden
This commit is contained in:
parent
dc1f783e00
commit
0e71917727
@ -51,46 +51,7 @@ public class GrafikModel
|
||||
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() {
|
||||
figuren.add(aktuelleFigur);
|
||||
@ -98,29 +59,10 @@ public class GrafikModel
|
||||
}
|
||||
|
||||
public void setFigur(Figur figur){
|
||||
aktuelleFigur = figur;
|
||||
//aktuelleFigur = 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class ReceiveAdapter implements Subscriber<Figur> {
|
||||
|
||||
lg.info("Figur wurde dem Grafikmodel hinzugefügt");
|
||||
model.setFigur(item);
|
||||
gView.drawPoint();
|
||||
gView.drawFigur();
|
||||
// evtl muss die Figur aber zuerst serialisiert werden
|
||||
//view.getTxtChat().append(item.getNachricht());
|
||||
this.subscription.request(1);
|
||||
|
@ -58,13 +58,22 @@ public class GrafikView extends JComponent implements Printable
|
||||
* Zeichnet den aktuellen Pfad (solange die maus gedrückt gehalten wird)
|
||||
* @param p -> Der aktuelle punkt als x-y-Koordinate
|
||||
*/
|
||||
public void drawFigur()
|
||||
{
|
||||
Graphics2D g2 = (Graphics2D)this.getGraphics(); // gefährlich!
|
||||
|
||||
drawPath(model.getFiguren().getLast().getPunkte(),g2);
|
||||
|
||||
g2.dispose(); //SEEEEHHHHRRRR WICHTIG!!!!!!!
|
||||
}
|
||||
|
||||
public void drawPoint()
|
||||
{
|
||||
Graphics2D g2 = (Graphics2D)this.getGraphics(); // gefährlich!
|
||||
|
||||
drawPath(model.getPunkte(),g2);
|
||||
|
||||
g2.dispose(); //SEEEEHHHHRRRR WICHTIG!!!!!!!
|
||||
g2.dispose(); //SEEEEHHHHRRRR WICHTIG!!!!!!!
|
||||
}
|
||||
|
||||
|
||||
@ -87,7 +96,7 @@ public class GrafikView extends JComponent implements Printable
|
||||
});
|
||||
}
|
||||
|
||||
public void drawPath(List<Point> path, Graphics2D g2){
|
||||
public void drawPath(List<Point> path, Graphics2D g2){
|
||||
from = path.getFirst();
|
||||
to = null;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user