Compare commits
No commits in common. "d164ff82518f4fee8a6dd66a1cd7fc35f75f10e1" and "a222d2a48f78527fbff2927f68c4c0d8cb915a6e" have entirely different histories.
d164ff8251
...
a222d2a48f
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
|
/nbproject/private/
|
||||||
/build/
|
/build/
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
log.level=INFO
|
|
||||||
|
|
||||||
log.directory=../Aufgabe7_bandit
|
|
||||||
log.filename=ohmLog
|
|
||||||
|
|
||||||
# Beispiel f\u00fcr verschiedene Level f\u00fcr unterschiedliche Pakete
|
|
||||||
# log.level.bandit.Zahlengenerator=FINE
|
|
||||||
# log.level.bandit.Model.Wuerfel=WARNING
|
|
@ -56,7 +56,7 @@ public class OpenCommand implements CommandInterface
|
|||||||
{
|
{
|
||||||
Logger.getLogger(OpenCommand.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(OpenCommand.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
view.getgZeichenflaeche().repaint();
|
model.deleteArrays();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ public class GrafikModel
|
|||||||
BufferedOutputStream bos = new BufferedOutputStream(fos);
|
BufferedOutputStream bos = new BufferedOutputStream(fos);
|
||||||
//Serialisierung
|
//Serialisierung
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(bos);
|
ObjectOutputStream oos = new ObjectOutputStream(bos);
|
||||||
oos.writeObject(figuren);
|
oos.writeObject(punkte);
|
||||||
oos.flush(); // Puffer
|
oos.flush(); // Puffer
|
||||||
oos.close();
|
oos.close();
|
||||||
}
|
}
|
||||||
@ -85,13 +85,13 @@ public class GrafikModel
|
|||||||
//eleganter
|
//eleganter
|
||||||
if (daten instanceof ArrayList liste)
|
if (daten instanceof ArrayList liste)
|
||||||
{
|
{
|
||||||
figuren = liste;
|
punkte = liste;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void endShape() {
|
public void endShape() {
|
||||||
figuren.add(new ArrayList<Point>(punkte));
|
figuren.add(punkte);
|
||||||
punkte.clear();
|
punkte.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,5 +115,10 @@ public class GrafikModel
|
|||||||
pref.put(lastDirectory, lastAdress);
|
pref.put(lastDirectory, lastAdress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteArrays()
|
||||||
|
{
|
||||||
|
figuren.clear();
|
||||||
|
punkte.clear();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,111 +0,0 @@
|
|||||||
package mvcgrafik.util;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.Set;
|
|
||||||
//import java.util.Properties;
|
|
||||||
import java.util.logging.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Klasse zur eigens konfigurierten Log-Ausgabe in der Console
|
|
||||||
* @author ahrens
|
|
||||||
*/
|
|
||||||
public class OhmLogger
|
|
||||||
{
|
|
||||||
private static final String LOGGER_NAME = "OhmLogger";
|
|
||||||
private static Logger lg = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* privater Konstrukter -> Singleton
|
|
||||||
*/
|
|
||||||
private OhmLogger()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Public Method zum Erstellen des Loggers und zum Aufruf der Methode
|
|
||||||
* zum Initialisieren
|
|
||||||
* @return Referenz auf Logger
|
|
||||||
*/
|
|
||||||
public static Logger getLogger()
|
|
||||||
{
|
|
||||||
if (lg == null)
|
|
||||||
{
|
|
||||||
lg = Logger.getLogger(LOGGER_NAME);
|
|
||||||
initLogger();
|
|
||||||
}
|
|
||||||
return lg;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Methode zum Initialisieren, Suchen der Konfigurationsdatei, Anlegen eines
|
|
||||||
* neuen Console Handlers, Löschen der bisherigen Standard Handler und
|
|
||||||
* Einfügen des eigenen Handler, Setzen des Levels, je nach Properties
|
|
||||||
*/
|
|
||||||
private static void initLogger()
|
|
||||||
{
|
|
||||||
try (InputStream configFile = OhmLogger.class.getClassLoader().getResourceAsStream("config.properties")) {
|
|
||||||
if (configFile != null) {
|
|
||||||
Properties properties = new Properties();
|
|
||||||
properties.load(configFile);
|
|
||||||
java.util.logging.Level classLogLevel = java.util.logging.Level.parse(properties.getProperty("log.level"));
|
|
||||||
|
|
||||||
|
|
||||||
ConsoleHandler ch = new ConsoleHandler();
|
|
||||||
ch.setFormatter(new OhmFormatter());
|
|
||||||
lg.setUseParentHandlers(false);
|
|
||||||
lg.getHandlers();
|
|
||||||
lg.addHandler(ch);
|
|
||||||
|
|
||||||
|
|
||||||
lg.setLevel(classLogLevel);
|
|
||||||
|
|
||||||
String logDirectory = properties.getProperty("log.directory");
|
|
||||||
String logFileName = properties.getProperty("log.filename");
|
|
||||||
|
|
||||||
FileHandler fileHandler = new FileHandler(logDirectory + "/" + logFileName, true);
|
|
||||||
fileHandler.setFormatter(new OhmFormatter());
|
|
||||||
lg.addHandler(fileHandler);
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
System.err.println("Unable to find config.properties file. OhmLogger will use default settings.");
|
|
||||||
}
|
|
||||||
} catch (IOException | SecurityException e) {
|
|
||||||
System.err.println("Error configuring OhmLogger: " + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Klasse zum Setzen des Formates des Auszugebenden Log-Strings
|
|
||||||
* @author ahren
|
|
||||||
*/
|
|
||||||
class OhmFormatter extends Formatter
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public String format(LogRecord record)
|
|
||||||
{
|
|
||||||
String logline = "| ";
|
|
||||||
|
|
||||||
LocalDateTime ldt = LocalDateTime.now();
|
|
||||||
logline += ldt.toString();
|
|
||||||
logline += " | " + record.getLevel();
|
|
||||||
logline += " | " + record.getSourceClassName();
|
|
||||||
logline += " | " + record.getMessage();
|
|
||||||
logline += " |\n";
|
|
||||||
|
|
||||||
return logline;
|
|
||||||
}
|
|
||||||
}
|
|
@ -16,14 +16,11 @@ import java.awt.print.Printable;
|
|||||||
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;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,7 +29,6 @@ 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;
|
||||||
@ -41,7 +37,6 @@ public class GrafikView extends JComponent implements Printable
|
|||||||
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)
|
||||||
@ -51,25 +46,47 @@ 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)
|
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;
|
||||||
@ -77,25 +94,61 @@ public class GrafikView extends JComponent implements Printable
|
|||||||
Graphics2D g2 = (Graphics2D)g;
|
Graphics2D g2 = (Graphics2D)g;
|
||||||
|
|
||||||
|
|
||||||
model.getFiguren().forEach(figuren->
|
// int pathSize = model.getPunkte().size();
|
||||||
{
|
//
|
||||||
drawPath(figuren,g2);
|
// for(int i=0; i < pathSize-1; i++)
|
||||||
});
|
// {
|
||||||
|
// Point from = model.getPunkte().get(i);
|
||||||
}
|
// Point to = model.getPunkte().get(i+1);
|
||||||
|
//
|
||||||
public void drawPath(List<Point> path, Graphics2D g2){
|
// line = new Line2D.Float(from.x,from.y,to.x,to.y) {};
|
||||||
|
// g2.draw(line);
|
||||||
|
// }
|
||||||
|
|
||||||
for(int i=0; i < path.size()-1; i++)
|
model.getFiguren().forEach(figure->
|
||||||
{
|
{
|
||||||
Point from = path.get(i);
|
ArrayList<Point> currentPath = new ArrayList<>(figure);
|
||||||
Point to = path.get(i+1);
|
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.setLine(from,to);
|
line = new Line2D.Float(from.x,from.y,to.x,to.y) {};
|
||||||
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()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user