Compare commits
2 Commits
b3d25ed538
...
6bdad9c08a
Author | SHA1 | Date | |
---|---|---|---|
![]() |
6bdad9c08a | ||
![]() |
e9941da388 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
/build/
|
||||
/dist/
|
||||
|
39
src/mvcgrafik/model/Figur.java
Normal file
39
src/mvcgrafik/model/Figur.java
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
|
||||
package mvcgrafik.model;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ahren
|
||||
*/
|
||||
public class Figur implements Serializable
|
||||
{
|
||||
private ArrayList<Point> punkte;
|
||||
|
||||
public Figur(){
|
||||
punkte = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addPoint(Point p){
|
||||
punkte.add(p);
|
||||
}
|
||||
|
||||
public List<Point> getPunkte()
|
||||
{
|
||||
return Collections.unmodifiableList(punkte);
|
||||
}
|
||||
|
||||
public void clear(){
|
||||
punkte.clear();
|
||||
}
|
||||
|
||||
}
|
@ -17,35 +17,37 @@ import java.io.ObjectOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import mvcgrafik.util.OhmLogger;
|
||||
/**
|
||||
*
|
||||
* @author le
|
||||
*/
|
||||
public class GrafikModel
|
||||
{
|
||||
private ArrayList<Point> punkte;
|
||||
private ArrayList<ArrayList> figuren;
|
||||
private Figur aktuelleFigur;
|
||||
private ArrayList<Figur> figuren;
|
||||
private Preferences pref;
|
||||
private static Logger lg = OhmLogger.getLogger();
|
||||
|
||||
public GrafikModel()
|
||||
{
|
||||
punkte = new ArrayList<>();
|
||||
aktuelleFigur = new Figur();
|
||||
figuren = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addPoint(Point p)
|
||||
{
|
||||
punkte.add(p);
|
||||
aktuelleFigur.addPoint(p);
|
||||
}
|
||||
|
||||
public List<Point> getPunkte()
|
||||
{
|
||||
return Collections.unmodifiableList(punkte);
|
||||
return aktuelleFigur.getPunkte();
|
||||
}
|
||||
|
||||
public List<ArrayList> getFiguren(){
|
||||
public List<Figur> getFiguren(){
|
||||
return Collections.unmodifiableList(figuren);
|
||||
}
|
||||
|
||||
@ -91,8 +93,8 @@ public class GrafikModel
|
||||
}
|
||||
|
||||
public void endShape() {
|
||||
figuren.add(new ArrayList<Point>(punkte));
|
||||
punkte.clear();
|
||||
figuren.add(aktuelleFigur);
|
||||
aktuelleFigur = new Figur();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -114,6 +116,6 @@ public class GrafikModel
|
||||
{
|
||||
pref.put(lastDirectory, lastAdress);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -70,6 +70,7 @@ public class GrafikView extends JComponent implements Printable
|
||||
* Jedes mal wenn die Maus los gelassen wird, wird dder aktuelle Pfad gespeichert
|
||||
* @param g
|
||||
*/
|
||||
@Override
|
||||
public void paintComponent(Graphics g)
|
||||
{
|
||||
if (model == null) return;
|
||||
@ -79,9 +80,8 @@ public class GrafikView extends JComponent implements Printable
|
||||
|
||||
model.getFiguren().forEach(figuren->
|
||||
{
|
||||
drawPath(figuren,g2);
|
||||
drawPath(figuren.getPunkte(),g2);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void drawPath(List<Point> path, Graphics2D g2){
|
||||
|
Loading…
x
Reference in New Issue
Block a user