|
|
|
|
|
|
|
|
import java.awt.print.PrinterException; |
|
|
import java.awt.print.PrinterException; |
|
|
import java.awt.print.PrinterJob; |
|
|
import java.awt.print.PrinterJob; |
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
import java.util.logging.Logger; |
|
|
import javax.print.attribute.HashPrintRequestAttributeSet; |
|
|
import javax.print.attribute.HashPrintRequestAttributeSet; |
|
|
import javax.print.attribute.standard.DialogTypeSelection; |
|
|
import javax.print.attribute.standard.DialogTypeSelection; |
|
|
import javax.swing.JComponent; |
|
|
import javax.swing.JComponent; |
|
|
import javax.swing.JOptionPane; |
|
|
import javax.swing.JOptionPane; |
|
|
import mvcgrafik.model.GrafikModel; |
|
|
import mvcgrafik.model.GrafikModel; |
|
|
|
|
|
import mvcgrafik.util.OhmLogger; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
|
|
|
|
|
|
*/ |
|
|
*/ |
|
|
public class GrafikView extends JComponent implements Printable |
|
|
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 static Dimension EINS = new Dimension(1, 1); // Dimension ist eine Klasse die width udn height hält |
|
|
private Rectangle2D.Float pixel; |
|
|
private Rectangle2D.Float pixel; |
|
|
private Line2D.Float line; |
|
|
private Line2D.Float line; |
|
|
|
|
|
|
|
|
public GrafikView() |
|
|
public GrafikView() |
|
|
{ |
|
|
{ |
|
|
pixel = new Rectangle2D.Float(); |
|
|
pixel = new Rectangle2D.Float(); |
|
|
|
|
|
line = new Line2D.Float(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void setModel(GrafikModel model) |
|
|
public void setModel(GrafikModel model) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 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) |
|
|
public void drawPoint(Point p) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
Graphics2D g2 = (Graphics2D)this.getGraphics(); // gefährlich! |
|
|
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!!!!!!! |
|
|
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) |
|
|
public void paintComponent(Graphics g) |
|
|
{ |
|
|
{ |
|
|
if (model == null) return; |
|
|
if (model == null) return; |
|
|
|
|
|
|
|
|
Graphics2D g2 = (Graphics2D)g; |
|
|
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); |
|
|
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() |
|
|
public void doPrint() |
|
|
{ |
|
|
{ |