|
|
@@ -16,11 +16,14 @@ import java.awt.print.Printable; |
|
|
|
import java.awt.print.PrinterException; |
|
|
|
import java.awt.print.PrinterJob; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.logging.Logger; |
|
|
|
import javax.print.attribute.HashPrintRequestAttributeSet; |
|
|
|
import javax.print.attribute.standard.DialogTypeSelection; |
|
|
|
import javax.swing.JComponent; |
|
|
|
import javax.swing.JOptionPane; |
|
|
|
import mvcgrafik.model.GrafikModel; |
|
|
|
import mvcgrafik.util.OhmLogger; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
@@ -29,6 +32,7 @@ import mvcgrafik.model.GrafikModel; |
|
|
|
*/ |
|
|
|
public class GrafikView extends JComponent implements Printable |
|
|
|
{ |
|
|
|
private static Logger lg = OhmLogger.getLogger(); |
|
|
|
private static Dimension EINS = new Dimension(1, 1); // Dimension ist eine Klasse die width udn height hält |
|
|
|
private Rectangle2D.Float pixel; |
|
|
|
private Line2D.Float line; |
|
|
@@ -37,6 +41,7 @@ public class GrafikView extends JComponent implements Printable |
|
|
|
public GrafikView() |
|
|
|
{ |
|
|
|
pixel = new Rectangle2D.Float(); |
|
|
|
line = new Line2D.Float(); |
|
|
|
} |
|
|
|
|
|
|
|
public void setModel(GrafikModel model) |
|
|
@@ -46,47 +51,25 @@ 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 drawPoint(Point p) |
|
|
|
{ |
|
|
|
|
|
|
|
Graphics2D g2 = (Graphics2D)this.getGraphics(); // gefährlich! |
|
|
|
paintComponent(g2); |
|
|
|
// pixel.setFrame(p, EINS); |
|
|
|
// g2.draw(pixel); |
|
|
|
|
|
|
|
drawPath(model.getPunkte(),g2); |
|
|
|
|
|
|
|
//Um die aktuelle Figur zu zeichnen |
|
|
|
int pathSize = model.getPunkte().size(); |
|
|
|
|
|
|
|
for(int i=0; i < pathSize-1; i++) |
|
|
|
{ |
|
|
|
Point from = model.getPunkte().get(i); |
|
|
|
Point to = model.getPunkte().get(i+1); |
|
|
|
|
|
|
|
line = new Line2D.Float(from.x,from.y,to.x,to.y) {}; |
|
|
|
g2.draw(line); |
|
|
|
} |
|
|
|
|
|
|
|
//Um die fertigen Figuren zu zeichnen |
|
|
|
model.getFiguren().forEach(figure-> |
|
|
|
{ |
|
|
|
ArrayList<Point> currentPath = new ArrayList<>(figure); |
|
|
|
int figurePath = currentPath.size(); |
|
|
|
|
|
|
|
for(int i=0; i < figurePath-1; i++) |
|
|
|
{ |
|
|
|
Point from = currentPath.get(i); |
|
|
|
Point to = model.getPunkte().get(i+1); |
|
|
|
|
|
|
|
line = new Line2D.Float(from.x,from.y,to.x,to.y) {}; |
|
|
|
g2.draw(line); |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
g2.dispose(); //SEEEEHHHHRRRR WICHTIG!!!!!!! |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Hier werden alle Pfade aus dem model neu gezeichnet |
|
|
|
* Jedes mal wenn die Maus los gelassen wird, wird dder aktuelle Pfad gespeichert |
|
|
|
* @param g |
|
|
|
*/ |
|
|
|
public void paintComponent(Graphics g) |
|
|
|
{ |
|
|
|
if (model == null) return; |
|
|
@@ -94,62 +77,25 @@ public class GrafikView extends JComponent implements Printable |
|
|
|
Graphics2D g2 = (Graphics2D)g; |
|
|
|
|
|
|
|
|
|
|
|
// int pathSize = model.getPunkte().size(); |
|
|
|
// |
|
|
|
// for(int i=0; i < pathSize-1; i++) |
|
|
|
// { |
|
|
|
// Point from = model.getPunkte().get(i); |
|
|
|
// Point to = model.getPunkte().get(i+1); |
|
|
|
// |
|
|
|
// line = new Line2D.Float(from.x,from.y,to.x,to.y) {}; |
|
|
|
// g2.draw(line); |
|
|
|
// } |
|
|
|
|
|
|
|
model.getFiguren().forEach(figure-> |
|
|
|
model.getFiguren().forEach(figuren-> |
|
|
|
{ |
|
|
|
ArrayList<Point> currentPath = new ArrayList<>(figure); |
|
|
|
int figurePath = currentPath.size(); |
|
|
|
drawPath(figuren,g2); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public void drawPath(List<Point> path, Graphics2D g2){ |
|
|
|
|
|
|
|
for(int i=0; i < figurePath-1; i++) |
|
|
|
for(int i=0; i < path.size()-1; i++) |
|
|
|
{ |
|
|
|
Point from = currentPath.get(i); |
|
|
|
Point to = model.getPunkte().get(i+1); |
|
|
|
Point from = path.get(i); |
|
|
|
Point to = path.get(i+1); |
|
|
|
|
|
|
|
line = new Line2D.Float(from.x,from.y,to.x,to.y) {}; |
|
|
|
line.setLine(from,to); |
|
|
|
g2.draw(line); |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// model.getPunkte().forEach(p -> |
|
|
|
// { |
|
|
|
// pixel.setFrame(p, EINS); |
|
|
|
// g2.draw(pixel); |
|
|
|
// }); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// public void drawPath(ArrayList<Point> path){ |
|
|
|
// Graphics2D g2 = (Graphics2D)this.getGraphics(); |
|
|
|
// |
|
|
|
// int pathSize = path.size(); |
|
|
|
// |
|
|
|
// for(int i=0; i < pathSize-1; i++) |
|
|
|
// { |
|
|
|
// Point from = model.getPunkte().get(i); |
|
|
|
// Point to = model.getPunkte().get(i+1); |
|
|
|
// |
|
|
|
// line = new Line2D.Float(from.x,from.y,to.x,to.y) {}; |
|
|
|
// g2.draw(line); |
|
|
|
// } |
|
|
|
// |
|
|
|
// g2.dispose(); |
|
|
|
// |
|
|
|
// } |
|
|
|
|
|
|
|
public void doPrint() |
|
|
|
{ |
|
|
|
HashPrintRequestAttributeSet printSet = |