From 72fb7d9782e780ea7704bc9e21990ac24826d4e2 Mon Sep 17 00:00:00 2001 From: schuhmannje82308 Date: Mon, 4 Dec 2023 11:33:35 +0100 Subject: [PATCH] Init --- build.xml | 73 + manifest.mf | 3 + nbproject/build-impl.xml | 1771 +++++++++++++++++ nbproject/genfiles.properties | 8 + nbproject/project.properties | 95 + nbproject/project.xml | 15 + src/mvcgrafik/Start.java | 47 + .../controller/GrafikController.java | 58 + src/mvcgrafik/model/GrafikModel.java | 98 + src/mvcgrafik/view/GrafikFrame.form | 39 + src/mvcgrafik/view/GrafikFrame.java | 100 + src/mvcgrafik/view/GrafikView.java | 191 ++ 12 files changed, 2498 insertions(+) create mode 100644 build.xml create mode 100644 manifest.mf create mode 100644 nbproject/build-impl.xml create mode 100644 nbproject/genfiles.properties create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml create mode 100644 src/mvcgrafik/Start.java create mode 100644 src/mvcgrafik/controller/GrafikController.java create mode 100644 src/mvcgrafik/model/GrafikModel.java create mode 100644 src/mvcgrafik/view/GrafikFrame.form create mode 100644 src/mvcgrafik/view/GrafikFrame.java create mode 100644 src/mvcgrafik/view/GrafikView.java diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..2d408ec --- /dev/null +++ b/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project Aufgabe9_mvcGrafik. + + + diff --git a/manifest.mf b/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..be61f9b --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1771 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..00dd84a --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=ed859e61 +build.xml.script.CRC32=b640427c +build.xml.stylesheet.CRC32=f85dc8f2@1.108.0.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=ed859e61 +nbproject/build-impl.xml.script.CRC32=d5540e9a +nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.108.0.48 diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..517c861 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,95 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.modulepath=\ + ${run.modulepath} +debug.test.classpath=\ + ${run.test.classpath} +debug.test.modulepath=\ + ${run.test.modulepath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/Aufgabe9_mvcGrafik.jar +dist.javadoc.dir=${dist.dir}/javadoc +dist.jlink.dir=${dist.dir}/jlink +dist.jlink.output=${dist.jlink.dir}/Aufgabe9_mvcGrafik +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.modulepath= +javac.processormodulepath= +javac.processorpath=\ + ${javac.classpath} +javac.source=17 +javac.target=17 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.modulepath=\ + ${javac.modulepath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.html5=false +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# The jlink additional root modules to resolve +jlink.additionalmodules= +# The jlink additional command line parameters +jlink.additionalparam= +jlink.launcher=true +jlink.launcher.name=Aufgabe9_mvcGrafik +main.class=mvcgrafik.Start +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.modulepath=\ + ${javac.modulepath} +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +run.test.modulepath=\ + ${javac.test.modulepath} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..61d1dd5 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + Aufgabe9_mvcGrafik + + + + + + + + + diff --git a/src/mvcgrafik/Start.java b/src/mvcgrafik/Start.java new file mode 100644 index 0000000..c44625e --- /dev/null +++ b/src/mvcgrafik/Start.java @@ -0,0 +1,47 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template + */ + +package mvcgrafik; + +import javax.swing.JOptionPane; +import javax.swing.UIManager; +import mvcgrafik.controller.GrafikController; +import mvcgrafik.model.GrafikModel; +import mvcgrafik.view.GrafikFrame; +import mvcgrafik.view.GrafikView; + +/** + * Builder Class + * @author le + */ +public class Start +{ + public Start() + { + GrafikModel model = new GrafikModel(); + GrafikFrame frm = new GrafikFrame(); + GrafikView view = frm.getgZeichenflaeche(); + view.setModel(model); + GrafikController controller = new GrafikController(view, model); + controller.registerEvents(); + frm.setVisible(true); + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) + { + try + { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } + catch (Exception ex) + { + JOptionPane.showMessageDialog(null, ex.toString()); + } + new Start(); + } +} diff --git a/src/mvcgrafik/controller/GrafikController.java b/src/mvcgrafik/controller/GrafikController.java new file mode 100644 index 0000000..d991160 --- /dev/null +++ b/src/mvcgrafik/controller/GrafikController.java @@ -0,0 +1,58 @@ +/* + * 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.controller; + +import java.awt.Point; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionListener; +import mvcgrafik.model.GrafikModel; +import mvcgrafik.view.GrafikView; + +/** + * + * @author le + */ +public class GrafikController extends MouseAdapter implements MouseMotionListener +{ + private GrafikView view; + private GrafikModel model; + + public GrafikController(GrafikView view, GrafikModel model) + { + this.view = view; + this.model = model; + } + + public void registerEvents() + { + view.addMouseMotionListener(this); + view.addMouseListener(this); + } + + @Override + public void mouseDragged(MouseEvent evt) + { + Point p = evt.getPoint(); + model.addPoint(p); + view.drawPoint(p); + } + + @Override + public void mouseMoved(MouseEvent e) + { + } + + @Override + public void mouseReleased(MouseEvent evt) + { + model.endShape(); + if (evt.getButton() == MouseEvent.BUTTON3) + { + view.doPrint(); + } + } +} diff --git a/src/mvcgrafik/model/GrafikModel.java b/src/mvcgrafik/model/GrafikModel.java new file mode 100644 index 0000000..371807c --- /dev/null +++ b/src/mvcgrafik/model/GrafikModel.java @@ -0,0 +1,98 @@ +/* + * 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.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * + * @author le + */ +public class GrafikModel +{ + private ArrayList punkte; + private ArrayList figuren; + + public GrafikModel() + { + punkte = new ArrayList<>(); + figuren = new ArrayList<>(); + } + + public void addPoint(Point p) + { + punkte.add(p); + } + + public List getPunkte() + { + return Collections.unmodifiableList(punkte); + } + + public List getFiguren(){ + 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(punkte); + 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)daten; +// } + //eleganter + if (daten instanceof ArrayList liste) + { + punkte = liste; + } + + } + + public void endShape() { + figuren.add(punkte); + punkte.clear(); + } + + + +} diff --git a/src/mvcgrafik/view/GrafikFrame.form b/src/mvcgrafik/view/GrafikFrame.form new file mode 100644 index 0000000..70c71e8 --- /dev/null +++ b/src/mvcgrafik/view/GrafikFrame.form @@ -0,0 +1,39 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mvcgrafik/view/GrafikFrame.java b/src/mvcgrafik/view/GrafikFrame.java new file mode 100644 index 0000000..e0c31a1 --- /dev/null +++ b/src/mvcgrafik/view/GrafikFrame.java @@ -0,0 +1,100 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template + */ +package mvcgrafik.view; + +/** + * + * @author le + */ +public class GrafikFrame extends javax.swing.JFrame +{ + /** + * @return the gZeichenflaeche + */ + public mvcgrafik.view.GrafikView getgZeichenflaeche() + { + return gZeichenflaeche; + } + + /** + * Creates new form GrafikFrame + */ + public GrafikFrame() + { + initComponents(); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() + { + + gZeichenflaeche = new mvcgrafik.view.GrafikView(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + getContentPane().add(gZeichenflaeche, java.awt.BorderLayout.CENTER); + + setSize(new java.awt.Dimension(540, 412)); + setLocationRelativeTo(null); + }// //GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) + { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try + { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) + { + if ("Nimbus".equals(info.getName())) + { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } + catch (ClassNotFoundException ex) + { + java.util.logging.Logger.getLogger(GrafikFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + catch (InstantiationException ex) + { + java.util.logging.Logger.getLogger(GrafikFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + catch (IllegalAccessException ex) + { + java.util.logging.Logger.getLogger(GrafikFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + catch (javax.swing.UnsupportedLookAndFeelException ex) + { + java.util.logging.Logger.getLogger(GrafikFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(new Runnable() + { + public void run() + { + new GrafikFrame().setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private mvcgrafik.view.GrafikView gZeichenflaeche; + // End of variables declaration//GEN-END:variables +} diff --git a/src/mvcgrafik/view/GrafikView.java b/src/mvcgrafik/view/GrafikView.java new file mode 100644 index 0000000..bcc31d4 --- /dev/null +++ b/src/mvcgrafik/view/GrafikView.java @@ -0,0 +1,191 @@ +/* + * 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.view; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.geom.Rectangle2D; +import java.awt.geom.Line2D; +import java.awt.print.PageFormat; +import java.awt.print.Printable; +import java.awt.print.PrinterException; +import java.awt.print.PrinterJob; +import java.util.ArrayList; +import javax.print.attribute.HashPrintRequestAttributeSet; +import javax.print.attribute.standard.DialogTypeSelection; +import javax.swing.JComponent; +import javax.swing.JOptionPane; +import mvcgrafik.model.GrafikModel; + + +/** + * + * @author le + */ +public class GrafikView extends JComponent implements Printable +{ + 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; + private GrafikModel model; + + public GrafikView() + { + pixel = new Rectangle2D.Float(); + } + + public void setModel(GrafikModel model) + { + this.model = model; + } + + + + public void drawPoint(Point p) + { + + Graphics2D g2 = (Graphics2D)this.getGraphics(); // gefährlich! + paintComponent(g2); +// pixel.setFrame(p, EINS); +// g2.draw(pixel); + + + //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 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!!!!!!! + } + + public void paintComponent(Graphics g) + { + if (model == null) return; + super.paintComponent(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-> + { + ArrayList 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); + } + + }); + + + +// model.getPunkte().forEach(p -> +// { +// pixel.setFrame(p, EINS); +// g2.draw(pixel); +// }); + + + } + +// public void drawPath(ArrayList 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 = + new HashPrintRequestAttributeSet(); + printSet.add(DialogTypeSelection.NATIVE); + PrinterJob pj = PrinterJob.getPrinterJob(); + pj.setPrintable(this); + //Dialog + if (pj.printDialog(printSet)) + { + try + { + pj.print(printSet); + } + catch (Exception ex) + { + JOptionPane.showMessageDialog(this, ex.toString()); + } + } + } + + @Override + public int print(Graphics gp, PageFormat pf, int pageIndex) throws PrinterException + { + Graphics2D g2p = (Graphics2D)gp; + if (pageIndex == 0) + { + g2p.translate(pf.getImageableX(), pf.getImageableY()); + g2p.scale(pf.getImageableWidth() / this.getWidth(), + pf.getImageableHeight() / this.getHeight()); + super.print(g2p); + return Printable.PAGE_EXISTS; + } + else + { + return Printable.NO_SUCH_PAGE; // wichtig sonst Papiervernichtung + } + } +}