Compare commits
2
Commits
a222d2a48f
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d4374d13fd | ||
|
|
9d07714513 |
No files matched your search
@@ -1,2 +1 @@
|
||||
/nbproject/private/
|
||||
/build/
|
||||
@@ -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
|
||||
@@ -7,7 +7,6 @@ package mvcgrafik;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.UIManager;
|
||||
import mvcgrafik.controller.CommandController;
|
||||
import mvcgrafik.controller.GrafikController;
|
||||
import mvcgrafik.model.GrafikModel;
|
||||
import mvcgrafik.view.GrafikFrame;
|
||||
@@ -26,10 +25,7 @@ public class Start
|
||||
GrafikView view = frm.getgZeichenflaeche();
|
||||
view.setModel(model);
|
||||
GrafikController controller = new GrafikController(view, model);
|
||||
CommandController controller_commands = new CommandController(frm, model);
|
||||
controller.registerEvents();
|
||||
controller_commands.registerEvents();
|
||||
controller_commands.registerCommands();
|
||||
frm.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* 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.Component;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import mvcgrafik.controller.commands.CommandInvoker;
|
||||
import mvcgrafik.controller.commands.OpenCommand;
|
||||
import mvcgrafik.controller.commands.SaveCommand;
|
||||
import mvcgrafik.model.GrafikModel;
|
||||
import mvcgrafik.view.GrafikFrame;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ahren
|
||||
*/
|
||||
public class CommandController implements ActionListener
|
||||
{
|
||||
private GrafikFrame view;
|
||||
private GrafikModel model;
|
||||
private CommandInvoker invoker;
|
||||
|
||||
public CommandController(GrafikFrame view, GrafikModel model)
|
||||
{
|
||||
this.view = view;
|
||||
this.model = model;
|
||||
this.invoker = new CommandInvoker();
|
||||
}
|
||||
|
||||
public void registerEvents()
|
||||
{
|
||||
view.getBtnFileOpen().addActionListener(this);
|
||||
view.getBtnFileSave().addActionListener(this);
|
||||
}
|
||||
|
||||
public void registerCommands()
|
||||
{
|
||||
invoker.addCommand(view.getBtnFileOpen(), new OpenCommand(view, model));
|
||||
invoker.addCommand(view.getBtnFileSave(), new SaveCommand(view,model));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ausführen des jeweiligen Kommandos
|
||||
* @param e Referenz auf das Event
|
||||
*/
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Component key = (Component)e.getSource();
|
||||
invoker.executeCommand(key);
|
||||
if(key == view.getBtnFileOpen()){
|
||||
invoker.deleteStack();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
|
||||
*/
|
||||
package mvcgrafik.controller.commands;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ahren
|
||||
*/
|
||||
public interface CommandInterface
|
||||
{
|
||||
public void execute();
|
||||
public void undo();
|
||||
public void redo();
|
||||
public boolean isUndoable();
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* 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.awt.Component;
|
||||
import java.util.HashMap;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* Dient zur Realisierung des Polymorphismus
|
||||
* für das COmmand-Design-Pattern
|
||||
* Die Commands werden in einer HashMap gespeichert
|
||||
* @author ahren
|
||||
* @see CommandInterface
|
||||
*/
|
||||
public class CommandInvoker {
|
||||
|
||||
private HashMap<Component, CommandInterface> commands;
|
||||
private Stack <CommandInterface> undoStack;
|
||||
|
||||
public CommandInvoker(){
|
||||
commands = new HashMap<>();
|
||||
undoStack = new Stack();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fügt ein Kommando zur Kommando-"Datenbank" = HashMap hinzu
|
||||
* @param key Quelle des Events
|
||||
* @param value Referenz auf das zugehörige Kommando-Objekt
|
||||
*/
|
||||
public void addCommand(Component key, CommandInterface value){
|
||||
commands.put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Führt Kommando der Eventquelle "key" aus und legt die Referenz
|
||||
* des Kommando in den Undo-Stack
|
||||
* @param key Referenz auf die Eventquelle
|
||||
*/
|
||||
public void executeCommand(Component key){
|
||||
CommandInterface command = commands.get(key);
|
||||
command.execute();
|
||||
if (command.isUndoable())
|
||||
{
|
||||
undoStack.push(command);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Falls der Stack Elemente enthält, wird das oberste Element geholt
|
||||
* und die Methode "undo" des Commands aufgerufen
|
||||
*/
|
||||
public void undoCommand()
|
||||
{
|
||||
if (!undoStack.isEmpty())
|
||||
{
|
||||
undoStack.pop().undo();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Löscht bei Öffnen einer neuen Datei den Stack
|
||||
*/
|
||||
public void deleteStack()
|
||||
{
|
||||
while(!undoStack.isEmpty())
|
||||
undoStack.pop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ahren
|
||||
*/
|
||||
public class OpenCommand implements CommandInterface
|
||||
{
|
||||
private GrafikFrame view;
|
||||
private GrafikModel model;
|
||||
|
||||
public OpenCommand(GrafikFrame view, GrafikModel model)
|
||||
{
|
||||
this.view = view;
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
JFileChooser fc = view.getFcFileChooser();
|
||||
String lastDirectory = model.getPref();
|
||||
if (lastDirectory != null) {
|
||||
fc.setCurrentDirectory(new File(lastDirectory));
|
||||
}
|
||||
int choice = fc.showOpenDialog(view);
|
||||
if (choice == JFileChooser.APPROVE_OPTION)
|
||||
{
|
||||
File selectedFile = fc.getSelectedFile();
|
||||
String filename = selectedFile.getAbsolutePath();
|
||||
model.putPref("lastDirectory", selectedFile.getParent());
|
||||
|
||||
try
|
||||
{
|
||||
model.lesePunkte(filename);
|
||||
}
|
||||
catch (FileNotFoundException ex)
|
||||
{
|
||||
Logger.getLogger(OpenCommand.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
catch (ClassNotFoundException | IOException ex)
|
||||
{
|
||||
Logger.getLogger(OpenCommand.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
model.deleteArrays();
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ahren
|
||||
*/
|
||||
public class SaveCommand implements CommandInterface
|
||||
{
|
||||
private GrafikFrame view;
|
||||
private GrafikModel model;
|
||||
|
||||
public SaveCommand(GrafikFrame 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() {
|
||||
JFileChooser fc = view.getFcFileChooser();
|
||||
String lastDirectory = model.getPref();
|
||||
if (lastDirectory != null) {
|
||||
fc.setCurrentDirectory(new File(lastDirectory));
|
||||
}
|
||||
int choice = fc.showSaveDialog(view);
|
||||
if (choice == JFileChooser.APPROVE_OPTION)
|
||||
{
|
||||
File selectedFile = fc.getSelectedFile();
|
||||
String filename = selectedFile.getAbsolutePath();
|
||||
model.putPref("lastDirectory", selectedFile.getParent());
|
||||
|
||||
try
|
||||
{
|
||||
model.speicherePunkte(filename);
|
||||
}
|
||||
catch (FileNotFoundException ex)
|
||||
{
|
||||
Logger.getLogger(SaveCommand.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
Logger.getLogger(SaveCommand.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,7 +17,6 @@ import java.io.ObjectOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -27,7 +26,6 @@ public class GrafikModel
|
||||
{
|
||||
private ArrayList<Point> punkte;
|
||||
private ArrayList<ArrayList> figuren;
|
||||
private Preferences pref;
|
||||
|
||||
public GrafikModel()
|
||||
{
|
||||
@@ -91,34 +89,10 @@ public class GrafikModel
|
||||
}
|
||||
|
||||
public void endShape() {
|
||||
figuren.add(punkte);
|
||||
figuren.add(new ArrayList<Point>(punkte));
|
||||
punkte.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Bestimmt die Adresse des zuletzt besuchten Ordners
|
||||
* @return letzter Ordner
|
||||
*/
|
||||
public String getPref()
|
||||
{
|
||||
pref = Preferences.userNodeForPackage(getClass());
|
||||
return pref.get("lastDirectory", null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt die Preferenz zu dem zuletzt besuchten Ordner
|
||||
* @param lastDirectory Bezeichner "lastDirectory"
|
||||
* @param lastAdress Adresse des zuletzt besuchten Ordners
|
||||
*/
|
||||
public void putPref(String lastDirectory, String 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;
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,50 @@
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||
<NonVisualComponents>
|
||||
<Component class="javax.swing.JFileChooser" name="FcFileChooser">
|
||||
</Component>
|
||||
<Menu class="javax.swing.JMenuBar" name="jMenuBar1">
|
||||
<SubComponents>
|
||||
<Menu class="javax.swing.JMenu" name="jMenu1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="File"/>
|
||||
</Properties>
|
||||
<SubComponents>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="miSave">
|
||||
<Properties>
|
||||
<Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor">
|
||||
<KeyStroke key="Ctrl+S"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="Speichern"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="miSaveActionPerformed"/>
|
||||
</Events>
|
||||
</MenuItem>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="miOpen">
|
||||
<Properties>
|
||||
<Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor">
|
||||
<KeyStroke key="Ctrl+O"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="Öffnen"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="miOpenActionPerformed"/>
|
||||
</Events>
|
||||
</MenuItem>
|
||||
</SubComponents>
|
||||
</Menu>
|
||||
<Menu class="javax.swing.JMenu" name="jMenu2">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Edit"/>
|
||||
</Properties>
|
||||
</Menu>
|
||||
</SubComponents>
|
||||
</Menu>
|
||||
</NonVisualComponents>
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="menuBar" type="java.lang.String" value="jMenuBar1"/>
|
||||
<SyntheticProperty name="formSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,-100,0,0,2,28"/>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="0"/>
|
||||
<SyntheticProperty name="generateSize" type="boolean" value="true"/>
|
||||
@@ -35,44 +72,7 @@
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
|
||||
<Property name="useNullLayout" type="boolean" value="true"/>
|
||||
</Layout>
|
||||
</Container>
|
||||
<Container class="javax.swing.JToolBar" name="jToolBar1">
|
||||
<Properties>
|
||||
<Property name="rollover" type="boolean" value="true"/>
|
||||
</Properties>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||
<BorderConstraints direction="First"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JButton" name="btnFileOpen">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/mvcgrafik/view/Open24.gif"/>
|
||||
</Property>
|
||||
<Property name="toolTipText" type="java.lang.String" value="Open File"/>
|
||||
<Property name="focusable" type="boolean" value="false"/>
|
||||
<Property name="horizontalTextPosition" type="int" value="0"/>
|
||||
<Property name="verticalTextPosition" type="int" value="3"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="btnFileSave">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/mvcgrafik/view/Save24.gif"/>
|
||||
</Property>
|
||||
<Property name="toolTipText" type="java.lang.String" value="Safe File"/>
|
||||
<Property name="horizontalTextPosition" type="int" value="0"/>
|
||||
<Property name="verticalTextPosition" type="int" value="3"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
@@ -10,30 +10,6 @@ package mvcgrafik.view;
|
||||
*/
|
||||
public class GrafikFrame extends javax.swing.JFrame
|
||||
{
|
||||
|
||||
/**
|
||||
* @return the FcFileChooser
|
||||
*/
|
||||
public javax.swing.JFileChooser getFcFileChooser()
|
||||
{
|
||||
return FcFileChooser;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the btnFileOpen
|
||||
*/
|
||||
public javax.swing.JButton getBtnFileOpen()
|
||||
{
|
||||
return btnFileOpen;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the btnFileSave
|
||||
*/
|
||||
public javax.swing.JButton getBtnFileSave()
|
||||
{
|
||||
return btnFileSave;
|
||||
}
|
||||
/**
|
||||
* @return the gZeichenflaeche
|
||||
*/
|
||||
@@ -56,39 +32,59 @@ public class GrafikFrame extends javax.swing.JFrame
|
||||
* regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents()
|
||||
{
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
FcFileChooser = new javax.swing.JFileChooser();
|
||||
gZeichenflaeche = new mvcgrafik.view.GrafikView();
|
||||
jToolBar1 = new javax.swing.JToolBar();
|
||||
btnFileOpen = new javax.swing.JButton();
|
||||
btnFileSave = new javax.swing.JButton();
|
||||
gZeichenflaeche = new mvcgrafik.view.GrafikView();
|
||||
jMenuBar1 = new javax.swing.JMenuBar();
|
||||
jMenu1 = new javax.swing.JMenu();
|
||||
miSave = new javax.swing.JMenuItem();
|
||||
miOpen = new javax.swing.JMenuItem();
|
||||
jMenu2 = new javax.swing.JMenu();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||
getContentPane().add(gZeichenflaeche, java.awt.BorderLayout.CENTER);
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||
|
||||
jToolBar1.setRollover(true);
|
||||
gZeichenflaeche.setLayout(new java.awt.BorderLayout());
|
||||
getContentPane().add(gZeichenflaeche, java.awt.BorderLayout.CENTER);
|
||||
|
||||
btnFileOpen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mvcgrafik/view/Open24.gif"))); // NOI18N
|
||||
btnFileOpen.setToolTipText("Open File");
|
||||
btnFileOpen.setFocusable(false);
|
||||
btnFileOpen.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
|
||||
btnFileOpen.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
|
||||
jToolBar1.add(btnFileOpen);
|
||||
jMenu1.setText("File");
|
||||
|
||||
btnFileSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mvcgrafik/view/Save24.gif"))); // NOI18N
|
||||
btnFileSave.setToolTipText("Safe File");
|
||||
btnFileSave.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
|
||||
btnFileSave.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
|
||||
jToolBar1.add(btnFileSave);
|
||||
miSave.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_DOWN_MASK));
|
||||
miSave.setText("Speichern");
|
||||
miSave.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
miSaveActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jMenu1.add(miSave);
|
||||
|
||||
getContentPane().add(jToolBar1, java.awt.BorderLayout.PAGE_START);
|
||||
miOpen.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_DOWN_MASK));
|
||||
miOpen.setText("Öffnen");
|
||||
miOpen.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
miOpenActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jMenu1.add(miOpen);
|
||||
|
||||
setSize(new java.awt.Dimension(540, 412));
|
||||
setLocationRelativeTo(null);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
jMenuBar1.add(jMenu1);
|
||||
|
||||
jMenu2.setText("Edit");
|
||||
jMenuBar1.add(jMenu2);
|
||||
|
||||
setJMenuBar(jMenuBar1);
|
||||
|
||||
setSize(new java.awt.Dimension(540, 412));
|
||||
setLocationRelativeTo(null);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void miSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSaveActionPerformed
|
||||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_miSaveActionPerformed
|
||||
|
||||
private void miOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miOpenActionPerformed
|
||||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_miOpenActionPerformed
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
@@ -139,11 +135,26 @@ public class GrafikFrame extends javax.swing.JFrame
|
||||
});
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JFileChooser FcFileChooser;
|
||||
private javax.swing.JButton btnFileOpen;
|
||||
private javax.swing.JButton btnFileSave;
|
||||
private mvcgrafik.view.GrafikView gZeichenflaeche;
|
||||
private javax.swing.JToolBar jToolBar1;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private mvcgrafik.view.GrafikView gZeichenflaeche;
|
||||
private javax.swing.JMenu jMenu1;
|
||||
private javax.swing.JMenu jMenu2;
|
||||
private javax.swing.JMenuBar jMenuBar1;
|
||||
private javax.swing.JMenuItem miOpen;
|
||||
private javax.swing.JMenuItem miSave;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
/**
|
||||
* @return the miOpen
|
||||
*/
|
||||
public javax.swing.JMenuItem getMiOpen() {
|
||||
return miOpen;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the miSave
|
||||
*/
|
||||
public javax.swing.JMenuItem getMiSave() {
|
||||
return miSave;
|
||||
}
|
||||
}
|
||||
@@ -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,61 +77,24 @@ 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();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
drawPath(figuren,g2);
|
||||
});
|
||||
|
||||
|
||||
|
||||
// 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 drawPath(List<Point> path, Graphics2D g2){
|
||||
|
||||
for(int i=0; i < path.size()-1; i++)
|
||||
{
|
||||
Point from = path.get(i);
|
||||
Point to = path.get(i+1);
|
||||
|
||||
line.setLine(from,to);
|
||||
g2.draw(line);
|
||||
}
|
||||
}
|
||||
|
||||
public void doPrint()
|
||||
{
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 462 B |
Binary file not shown.
|
Before Width: | Height: | Size: 266 B |
Reference in new issue
Block a user