Compare commits
7
Commits
a222d2a48f
..
Jens
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
21f8bb449a | ||
|
|
6bdad9c08a | ||
|
|
e9941da388 | ||
|
|
b3d25ed538 | ||
|
|
7ea1da3ebd | ||
|
|
d164ff8251 | ||
|
|
9d07714513 |
No files matched your search
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
/nbproject/private/
|
|
||||||
/build/
|
/build/
|
||||||
|
/dist/
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
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
|
||||||
@@ -26,7 +26,7 @@ public class Start
|
|||||||
GrafikView view = frm.getgZeichenflaeche();
|
GrafikView view = frm.getgZeichenflaeche();
|
||||||
view.setModel(model);
|
view.setModel(model);
|
||||||
GrafikController controller = new GrafikController(view, model);
|
GrafikController controller = new GrafikController(view, model);
|
||||||
CommandController controller_commands = new CommandController(frm, model);
|
CommandController controller_commands = new CommandController(frm,view, model);
|
||||||
controller.registerEvents();
|
controller.registerEvents();
|
||||||
controller_commands.registerEvents();
|
controller_commands.registerEvents();
|
||||||
controller_commands.registerCommands();
|
controller_commands.registerCommands();
|
||||||
|
|||||||
@@ -10,9 +10,11 @@ import java.awt.event.ActionEvent;
|
|||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import mvcgrafik.controller.commands.CommandInvoker;
|
import mvcgrafik.controller.commands.CommandInvoker;
|
||||||
import mvcgrafik.controller.commands.OpenCommand;
|
import mvcgrafik.controller.commands.OpenCommand;
|
||||||
|
import mvcgrafik.controller.commands.PrintCommand;
|
||||||
import mvcgrafik.controller.commands.SaveCommand;
|
import mvcgrafik.controller.commands.SaveCommand;
|
||||||
import mvcgrafik.model.GrafikModel;
|
import mvcgrafik.model.GrafikModel;
|
||||||
import mvcgrafik.view.GrafikFrame;
|
import mvcgrafik.view.GrafikFrame;
|
||||||
|
import mvcgrafik.view.GrafikView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -20,12 +22,14 @@ import mvcgrafik.view.GrafikFrame;
|
|||||||
*/
|
*/
|
||||||
public class CommandController implements ActionListener
|
public class CommandController implements ActionListener
|
||||||
{
|
{
|
||||||
private GrafikFrame view;
|
private GrafikFrame frame;
|
||||||
|
private GrafikView view;
|
||||||
private GrafikModel model;
|
private GrafikModel model;
|
||||||
private CommandInvoker invoker;
|
private CommandInvoker invoker;
|
||||||
|
|
||||||
public CommandController(GrafikFrame view, GrafikModel model)
|
public CommandController(GrafikFrame frame,GrafikView view, GrafikModel model)
|
||||||
{
|
{
|
||||||
|
this.frame = frame;
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.model = model;
|
this.model = model;
|
||||||
this.invoker = new CommandInvoker();
|
this.invoker = new CommandInvoker();
|
||||||
@@ -33,14 +37,18 @@ public class CommandController implements ActionListener
|
|||||||
|
|
||||||
public void registerEvents()
|
public void registerEvents()
|
||||||
{
|
{
|
||||||
view.getBtnFileOpen().addActionListener(this);
|
frame.getBtnFileOpen().addActionListener(this);
|
||||||
view.getBtnFileSave().addActionListener(this);
|
frame.getBtnFileSave().addActionListener(this);
|
||||||
|
frame.getBtnPrint().addActionListener(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerCommands()
|
public void registerCommands()
|
||||||
{
|
{
|
||||||
invoker.addCommand(view.getBtnFileOpen(), new OpenCommand(view, model));
|
invoker.addCommand(frame.getBtnFileOpen(), new OpenCommand(frame, model));
|
||||||
invoker.addCommand(view.getBtnFileSave(), new SaveCommand(view,model));
|
invoker.addCommand(frame.getBtnFileSave(), new SaveCommand(frame,model));
|
||||||
|
invoker.addCommand(frame.getBtnPrint(), new PrintCommand(view,model));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,7 +59,7 @@ public class CommandController implements ActionListener
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
Component key = (Component)e.getSource();
|
Component key = (Component)e.getSource();
|
||||||
invoker.executeCommand(key);
|
invoker.executeCommand(key);
|
||||||
if(key == view.getBtnFileOpen()){
|
if(key == frame.getBtnFileOpen()){
|
||||||
invoker.deleteStack();
|
invoker.deleteStack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
model.deleteArrays();
|
view.getgZeichenflaeche().repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* 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.commands;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
|
import mvcgrafik.model.GrafikModel;
|
||||||
|
import mvcgrafik.view.GrafikFrame;
|
||||||
|
import mvcgrafik.view.GrafikView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author ahren
|
||||||
|
*/
|
||||||
|
public class PrintCommand implements CommandInterface
|
||||||
|
{
|
||||||
|
private GrafikView view;
|
||||||
|
private GrafikModel model;
|
||||||
|
|
||||||
|
public PrintCommand(GrafikView view, GrafikModel model){
|
||||||
|
this.view = view;
|
||||||
|
this.model = model;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aufrufen des File Choosers in zuletzt verwendeten Ordner, versuchen die
|
||||||
|
* Tabellendatei zu speichern
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
|
this.view.doPrint();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void undo() {
|
||||||
|
throw new UnsupportedOperationException("Not undoable."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void redo() {
|
||||||
|
throw new UnsupportedOperationException("Not redoable."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isUndoable() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +66,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(punkte);
|
oos.writeObject(figuren);
|
||||||
oos.flush(); // Puffer
|
oos.flush(); // Puffer
|
||||||
oos.close();
|
oos.close();
|
||||||
}
|
}
|
||||||
@@ -85,14 +87,14 @@ public class GrafikModel
|
|||||||
//eleganter
|
//eleganter
|
||||||
if (daten instanceof ArrayList liste)
|
if (daten instanceof ArrayList liste)
|
||||||
{
|
{
|
||||||
punkte = liste;
|
figuren = liste;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void endShape() {
|
public void endShape() {
|
||||||
figuren.add(punkte);
|
figuren.add(aktuelleFigur);
|
||||||
punkte.clear();
|
aktuelleFigur = new Figur();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -114,11 +116,6 @@ public class GrafikModel
|
|||||||
{
|
{
|
||||||
pref.put(lastDirectory, lastAdress);
|
pref.put(lastDirectory, lastAdress);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteArrays()
|
|
||||||
{
|
|
||||||
figuren.clear();
|
|
||||||
punkte.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -72,6 +72,17 @@
|
|||||||
<Property name="verticalTextPosition" type="int" value="3"/>
|
<Property name="verticalTextPosition" type="int" value="3"/>
|
||||||
</Properties>
|
</Properties>
|
||||||
</Component>
|
</Component>
|
||||||
|
<Component class="javax.swing.JButton" name="btnPrint">
|
||||||
|
<Properties>
|
||||||
|
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||||
|
<Image iconType="3" name="/mvcgrafik/view/Print24.gif"/>
|
||||||
|
</Property>
|
||||||
|
<Property name="toolTipText" type="java.lang.String" value="Print File"/>
|
||||||
|
<Property name="focusable" type="boolean" value="false"/>
|
||||||
|
<Property name="horizontalTextPosition" type="int" value="0"/>
|
||||||
|
<Property name="verticalTextPosition" type="int" value="3"/>
|
||||||
|
</Properties>
|
||||||
|
</Component>
|
||||||
</SubComponents>
|
</SubComponents>
|
||||||
</Container>
|
</Container>
|
||||||
</SubComponents>
|
</SubComponents>
|
||||||
|
|||||||
@@ -56,39 +56,46 @@ public class GrafikFrame extends javax.swing.JFrame
|
|||||||
* regenerated by the Form Editor.
|
* regenerated by the Form Editor.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||||
private void initComponents()
|
private void initComponents() {
|
||||||
{
|
|
||||||
|
|
||||||
FcFileChooser = new javax.swing.JFileChooser();
|
FcFileChooser = new javax.swing.JFileChooser();
|
||||||
gZeichenflaeche = new mvcgrafik.view.GrafikView();
|
gZeichenflaeche = new mvcgrafik.view.GrafikView();
|
||||||
jToolBar1 = new javax.swing.JToolBar();
|
jToolBar1 = new javax.swing.JToolBar();
|
||||||
btnFileOpen = new javax.swing.JButton();
|
btnFileOpen = new javax.swing.JButton();
|
||||||
btnFileSave = new javax.swing.JButton();
|
btnFileSave = new javax.swing.JButton();
|
||||||
|
btnPrint = new javax.swing.JButton();
|
||||||
|
|
||||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||||
getContentPane().add(gZeichenflaeche, java.awt.BorderLayout.CENTER);
|
getContentPane().add(gZeichenflaeche, java.awt.BorderLayout.CENTER);
|
||||||
|
|
||||||
jToolBar1.setRollover(true);
|
jToolBar1.setRollover(true);
|
||||||
|
|
||||||
btnFileOpen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mvcgrafik/view/Open24.gif"))); // NOI18N
|
btnFileOpen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mvcgrafik/view/Open24.gif"))); // NOI18N
|
||||||
btnFileOpen.setToolTipText("Open File");
|
btnFileOpen.setToolTipText("Open File");
|
||||||
btnFileOpen.setFocusable(false);
|
btnFileOpen.setFocusable(false);
|
||||||
btnFileOpen.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
|
btnFileOpen.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
|
||||||
btnFileOpen.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
|
btnFileOpen.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
|
||||||
jToolBar1.add(btnFileOpen);
|
jToolBar1.add(btnFileOpen);
|
||||||
|
|
||||||
btnFileSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mvcgrafik/view/Save24.gif"))); // NOI18N
|
btnFileSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mvcgrafik/view/Save24.gif"))); // NOI18N
|
||||||
btnFileSave.setToolTipText("Safe File");
|
btnFileSave.setToolTipText("Safe File");
|
||||||
btnFileSave.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
|
btnFileSave.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
|
||||||
btnFileSave.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
|
btnFileSave.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
|
||||||
jToolBar1.add(btnFileSave);
|
jToolBar1.add(btnFileSave);
|
||||||
|
|
||||||
getContentPane().add(jToolBar1, java.awt.BorderLayout.PAGE_START);
|
btnPrint.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mvcgrafik/view/Print24.gif"))); // NOI18N
|
||||||
|
btnPrint.setToolTipText("Print File");
|
||||||
|
btnPrint.setFocusable(false);
|
||||||
|
btnPrint.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
|
||||||
|
btnPrint.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
|
||||||
|
jToolBar1.add(btnPrint);
|
||||||
|
|
||||||
setSize(new java.awt.Dimension(540, 412));
|
getContentPane().add(jToolBar1, java.awt.BorderLayout.PAGE_START);
|
||||||
setLocationRelativeTo(null);
|
|
||||||
}// </editor-fold>//GEN-END:initComponents
|
setSize(new java.awt.Dimension(540, 412));
|
||||||
|
setLocationRelativeTo(null);
|
||||||
|
}// </editor-fold>//GEN-END:initComponents
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param args the command line arguments
|
* @param args the command line arguments
|
||||||
@@ -139,11 +146,19 @@ public class GrafikFrame extends javax.swing.JFrame
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
private javax.swing.JFileChooser FcFileChooser;
|
private javax.swing.JFileChooser FcFileChooser;
|
||||||
private javax.swing.JButton btnFileOpen;
|
private javax.swing.JButton btnFileOpen;
|
||||||
private javax.swing.JButton btnFileSave;
|
private javax.swing.JButton btnFileSave;
|
||||||
private mvcgrafik.view.GrafikView gZeichenflaeche;
|
private javax.swing.JButton btnPrint;
|
||||||
private javax.swing.JToolBar jToolBar1;
|
private mvcgrafik.view.GrafikView gZeichenflaeche;
|
||||||
// End of variables declaration//GEN-END:variables
|
private javax.swing.JToolBar jToolBar1;
|
||||||
|
// End of variables declaration//GEN-END:variables
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the btnPrint
|
||||||
|
*/
|
||||||
|
public javax.swing.JButton getBtnPrint() {
|
||||||
|
return btnPrint;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -16,11 +16,14 @@ 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;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,14 +32,19 @@ import mvcgrafik.model.GrafikModel;
|
|||||||
*/
|
*/
|
||||||
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;
|
||||||
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();
|
||||||
|
line = new Line2D.Float();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setModel(GrafikModel model)
|
public void setModel(GrafikModel model)
|
||||||
@@ -46,47 +54,26 @@ 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
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
public void paintComponent(Graphics g)
|
public void paintComponent(Graphics g)
|
||||||
{
|
{
|
||||||
if (model == null) return;
|
if (model == null) return;
|
||||||
@@ -94,61 +81,26 @@ public class GrafikView extends JComponent implements Printable
|
|||||||
Graphics2D g2 = (Graphics2D)g;
|
Graphics2D g2 = (Graphics2D)g;
|
||||||
|
|
||||||
|
|
||||||
// int pathSize = model.getPunkte().size();
|
model.getFiguren().forEach(figuren->
|
||||||
//
|
|
||||||
// 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<Point> currentPath = new ArrayList<>(figure);
|
drawPath(figuren.getPunkte(),g2);
|
||||||
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<Point> path){
|
public void drawPath(List<Point> path, Graphics2D g2){
|
||||||
// Graphics2D g2 = (Graphics2D)this.getGraphics();
|
from = path.getFirst();
|
||||||
//
|
to = null;
|
||||||
// int pathSize = path.size();
|
|
||||||
//
|
path.forEach(point->
|
||||||
// for(int i=0; i < pathSize-1; i++)
|
{
|
||||||
// {
|
to = point;
|
||||||
// Point from = model.getPunkte().get(i);
|
line.setLine(from,to);
|
||||||
// Point to = model.getPunkte().get(i+1);
|
g2.draw(line);
|
||||||
//
|
from = to;
|
||||||
// line = new Line2D.Float(from.x,from.y,to.x,to.y) {};
|
|
||||||
// g2.draw(line);
|
});
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// g2.dispose();
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
public void doPrint()
|
public void doPrint()
|
||||||
{
|
{
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 491 B |
Reference in new issue
Block a user