Compare commits
3
Commits
b3d25ed538
..
Jens
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
21f8bb449a | ||
|
|
6bdad9c08a | ||
|
|
e9941da388 |
No files matched your search
@@ -1 +1,2 @@
|
|||||||
/build/
|
/build/
|
||||||
|
/dist/
|
||||||
@@ -50,9 +50,5 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
|
|||||||
public void mouseReleased(MouseEvent evt)
|
public void mouseReleased(MouseEvent evt)
|
||||||
{
|
{
|
||||||
model.endShape();
|
model.endShape();
|
||||||
// if (evt.getButton() == MouseEvent.BUTTON3)
|
|
||||||
// {
|
|
||||||
// view.doPrint();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import java.util.prefs.Preferences;
|
import java.util.prefs.Preferences;
|
||||||
|
import mvcgrafik.util.OhmLogger;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author le
|
* @author le
|
||||||
*/
|
*/
|
||||||
public class GrafikModel
|
public class GrafikModel
|
||||||
{
|
{
|
||||||
private ArrayList<Point> punkte;
|
private Figur aktuelleFigur;
|
||||||
private ArrayList<ArrayList> figuren;
|
private ArrayList<Figur> figuren;
|
||||||
private Preferences pref;
|
private Preferences pref;
|
||||||
|
private static Logger lg = OhmLogger.getLogger();
|
||||||
|
|
||||||
public GrafikModel()
|
public GrafikModel()
|
||||||
{
|
{
|
||||||
punkte = new ArrayList<>();
|
aktuelleFigur = new Figur();
|
||||||
figuren = new ArrayList<>();
|
figuren = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPoint(Point p)
|
public void addPoint(Point p)
|
||||||
{
|
{
|
||||||
punkte.add(p);
|
aktuelleFigur.addPoint(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Point> getPunkte()
|
public List<Point> getPunkte()
|
||||||
{
|
{
|
||||||
return Collections.unmodifiableList(punkte);
|
return aktuelleFigur.getPunkte();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ArrayList> getFiguren(){
|
public List<Figur> getFiguren(){
|
||||||
return Collections.unmodifiableList(figuren);
|
return Collections.unmodifiableList(figuren);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,8 +93,8 @@ public class GrafikModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void endShape() {
|
public void endShape() {
|
||||||
figuren.add(new ArrayList<Point>(punkte));
|
figuren.add(aktuelleFigur);
|
||||||
punkte.clear();
|
aktuelleFigur = new Figur();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -114,6 +116,6 @@ public class GrafikModel
|
|||||||
{
|
{
|
||||||
pref.put(lastDirectory, lastAdress);
|
pref.put(lastDirectory, lastAdress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -38,6 +38,9 @@ public class GrafikView extends JComponent implements Printable
|
|||||||
private Line2D.Float line;
|
private Line2D.Float line;
|
||||||
private GrafikModel model;
|
private GrafikModel model;
|
||||||
|
|
||||||
|
private Point from = null;
|
||||||
|
private Point to = null;
|
||||||
|
|
||||||
public GrafikView()
|
public GrafikView()
|
||||||
{
|
{
|
||||||
pixel = new Rectangle2D.Float();
|
pixel = new Rectangle2D.Float();
|
||||||
@@ -70,6 +73,7 @@ public class GrafikView extends JComponent implements Printable
|
|||||||
* Jedes mal wenn die Maus los gelassen wird, wird dder aktuelle Pfad gespeichert
|
* Jedes mal wenn die Maus los gelassen wird, wird dder aktuelle Pfad gespeichert
|
||||||
* @param g
|
* @param g
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void paintComponent(Graphics g)
|
public void paintComponent(Graphics g)
|
||||||
{
|
{
|
||||||
if (model == null) return;
|
if (model == null) return;
|
||||||
@@ -79,21 +83,22 @@ public class GrafikView extends JComponent implements Printable
|
|||||||
|
|
||||||
model.getFiguren().forEach(figuren->
|
model.getFiguren().forEach(figuren->
|
||||||
{
|
{
|
||||||
drawPath(figuren,g2);
|
drawPath(figuren.getPunkte(),g2);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawPath(List<Point> path, Graphics2D g2){
|
public void drawPath(List<Point> path, Graphics2D g2){
|
||||||
|
from = path.getFirst();
|
||||||
|
to = null;
|
||||||
|
|
||||||
for(int i=0; i < path.size()-1; i++)
|
path.forEach(point->
|
||||||
{
|
{
|
||||||
Point from = path.get(i);
|
to = point;
|
||||||
Point to = path.get(i+1);
|
line.setLine(from,to);
|
||||||
|
g2.draw(line);
|
||||||
|
from = to;
|
||||||
|
|
||||||
line.setLine(from,to);
|
});
|
||||||
g2.draw(line);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user