8 Commits
Author SHA1 Message Date
schuhmannje82308 21f8bb449a ForEach zum path zeichnen 2023-12-05 17:41:15 +01:00
ahren 6bdad9c08a nach clean uuuuuup 2023-12-05 12:57:34 +01:00
ahren e9941da388 Bevor Cleanup 2023-12-05 12:56:25 +01:00
schuhmannje82308 b3d25ed538 Abgabe 2023-12-05 11:56:02 +01:00
schuhmannje82308 7ea1da3ebd Print implementiert 2023-12-05 09:15:57 +01:00
ahren d164ff8251 Öffnen und Speichern check 2023-12-04 17:58:15 +01:00
ahren a222d2a48f erste Implementierung, klappt aber noch nicht, liegt aber glaub ich am model
und der Funktion lese Punkte, speichere Punkte
2023-12-04 13:23:32 +01:00
ahren fc00ba58d8 new branch 2023-12-04 12:41:26 +01:00
17 changed files with 576 additions and 121 deletions
+1
View File
@@ -1 +1,2 @@
/build/ /build/
/dist/
+4
View File
@@ -7,6 +7,7 @@ package mvcgrafik;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.UIManager; import javax.swing.UIManager;
import mvcgrafik.controller.CommandController;
import mvcgrafik.controller.GrafikController; import mvcgrafik.controller.GrafikController;
import mvcgrafik.model.GrafikModel; import mvcgrafik.model.GrafikModel;
import mvcgrafik.view.GrafikFrame; import mvcgrafik.view.GrafikFrame;
@@ -25,7 +26,10 @@ 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,view, model);
controller.registerEvents(); controller.registerEvents();
controller_commands.registerEvents();
controller_commands.registerCommands();
frm.setVisible(true); frm.setVisible(true);
} }
@@ -0,0 +1,66 @@
/*
* 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.PrintCommand;
import mvcgrafik.controller.commands.SaveCommand;
import mvcgrafik.model.GrafikModel;
import mvcgrafik.view.GrafikFrame;
import mvcgrafik.view.GrafikView;
/**
*
* @author ahren
*/
public class CommandController implements ActionListener
{
private GrafikFrame frame;
private GrafikView view;
private GrafikModel model;
private CommandInvoker invoker;
public CommandController(GrafikFrame frame,GrafikView view, GrafikModel model)
{
this.frame = frame;
this.view = view;
this.model = model;
this.invoker = new CommandInvoker();
}
public void registerEvents()
{
frame.getBtnFileOpen().addActionListener(this);
frame.getBtnFileSave().addActionListener(this);
frame.getBtnPrint().addActionListener(this);
}
public void registerCommands()
{
invoker.addCommand(frame.getBtnFileOpen(), new OpenCommand(frame, model));
invoker.addCommand(frame.getBtnFileSave(), new SaveCommand(frame,model));
invoker.addCommand(frame.getBtnPrint(), new PrintCommand(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 == frame.getBtnFileOpen()){
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();
}
} }
} }
@@ -0,0 +1,17 @@
/*
* 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();
}
@@ -0,0 +1,73 @@
/*
* 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();
}
}
@@ -0,0 +1,78 @@
/*
* 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);
}
view.getgZeichenflaeche().repaint();
}
}
@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,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,80 @@
/*
* 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;
}
}
+39
View File
@@ -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();
}
}
+35 -12
View File
@@ -17,33 +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 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 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);
} }
@@ -62,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();
} }
@@ -83,16 +87,35 @@ 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(new ArrayList<Point>(punkte)); figuren.add(aktuelleFigur);
punkte.clear(); aktuelleFigur = new Figur();
} }
/**
* 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);
}
} }
+51 -40
View File
@@ -2,50 +2,13 @@
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> <Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<NonVisualComponents> <NonVisualComponents>
<Menu class="javax.swing.JMenuBar" name="jMenuBar1"> <Component class="javax.swing.JFileChooser" name="FcFileChooser">
<SubComponents> </Component>
<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="&#xd6;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> </NonVisualComponents>
<Properties> <Properties>
<Property name="defaultCloseOperation" type="int" value="3"/> <Property name="defaultCloseOperation" type="int" value="3"/>
</Properties> </Properties>
<SyntheticProperties> <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="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="formSizePolicy" type="int" value="0"/>
<SyntheticProperty name="generateSize" type="boolean" value="true"/> <SyntheticProperty name="generateSize" type="boolean" value="true"/>
@@ -72,7 +35,55 @@
</Constraint> </Constraint>
</Constraints> </Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/> <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>
<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>
</Container> </Container>
</SubComponents> </SubComponents>
</Form> </Form>
+56 -52
View File
@@ -10,6 +10,30 @@ package mvcgrafik.view;
*/ */
public class GrafikFrame extends javax.swing.JFrame 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 * @return the gZeichenflaeche
*/ */
@@ -35,57 +59,44 @@ public class GrafikFrame extends javax.swing.JFrame
// <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();
gZeichenflaeche = new mvcgrafik.view.GrafikView(); gZeichenflaeche = new mvcgrafik.view.GrafikView();
jMenuBar1 = new javax.swing.JMenuBar(); jToolBar1 = new javax.swing.JToolBar();
jMenu1 = new javax.swing.JMenu(); btnFileOpen = new javax.swing.JButton();
miSave = new javax.swing.JMenuItem(); btnFileSave = new javax.swing.JButton();
miOpen = new javax.swing.JMenuItem(); btnPrint = new javax.swing.JButton();
jMenu2 = new javax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
gZeichenflaeche.setLayout(new java.awt.BorderLayout());
getContentPane().add(gZeichenflaeche, java.awt.BorderLayout.CENTER); getContentPane().add(gZeichenflaeche, java.awt.BorderLayout.CENTER);
jMenu1.setText("File"); jToolBar1.setRollover(true);
miSave.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_DOWN_MASK)); btnFileOpen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mvcgrafik/view/Open24.gif"))); // NOI18N
miSave.setText("Speichern"); btnFileOpen.setToolTipText("Open File");
miSave.addActionListener(new java.awt.event.ActionListener() { btnFileOpen.setFocusable(false);
public void actionPerformed(java.awt.event.ActionEvent evt) { btnFileOpen.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
miSaveActionPerformed(evt); btnFileOpen.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
} jToolBar1.add(btnFileOpen);
});
jMenu1.add(miSave);
miOpen.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_DOWN_MASK)); btnFileSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mvcgrafik/view/Save24.gif"))); // NOI18N
miOpen.setText("Öffnen"); btnFileSave.setToolTipText("Safe File");
miOpen.addActionListener(new java.awt.event.ActionListener() { btnFileSave.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
public void actionPerformed(java.awt.event.ActionEvent evt) { btnFileSave.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
miOpenActionPerformed(evt); jToolBar1.add(btnFileSave);
}
});
jMenu1.add(miOpen);
jMenuBar1.add(jMenu1); 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);
jMenu2.setText("Edit"); getContentPane().add(jToolBar1, java.awt.BorderLayout.PAGE_START);
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
setSize(new java.awt.Dimension(540, 412)); setSize(new java.awt.Dimension(540, 412));
setLocationRelativeTo(null); setLocationRelativeTo(null);
}// </editor-fold>//GEN-END:initComponents }// </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 * @param args the command line arguments
*/ */
@@ -136,25 +147,18 @@ 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.JButton btnFileOpen;
private javax.swing.JButton btnFileSave;
private javax.swing.JButton btnPrint;
private mvcgrafik.view.GrafikView gZeichenflaeche; private mvcgrafik.view.GrafikView gZeichenflaeche;
private javax.swing.JMenu jMenu1; private javax.swing.JToolBar jToolBar1;
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 // End of variables declaration//GEN-END:variables
/** /**
* @return the miOpen * @return the btnPrint
*/ */
public javax.swing.JMenuItem getMiOpen() { public javax.swing.JButton getBtnPrint() {
return miOpen; return btnPrint;
}
/**
* @return the miSave
*/
public javax.swing.JMenuItem getMiSave() {
return miSave;
} }
} }
+13 -7
View File
@@ -38,6 +38,9 @@ public class GrafikView extends JComponent implements Printable
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();
@@ -70,6 +73,7 @@ public class GrafikView extends JComponent implements Printable
* Jedes mal wenn die Maus los gelassen wird, wird dder aktuelle Pfad gespeichert * Jedes mal wenn die Maus los gelassen wird, wird dder aktuelle Pfad gespeichert
* @param g * @param g
*/ */
@Override
public void paintComponent(Graphics g) public void paintComponent(Graphics g)
{ {
if (model == null) return; if (model == null) return;
@@ -79,22 +83,24 @@ public class GrafikView extends JComponent implements Printable
model.getFiguren().forEach(figuren-> model.getFiguren().forEach(figuren->
{ {
drawPath(figuren,g2); drawPath(figuren.getPunkte(),g2);
}); });
} }
public void drawPath(List<Point> path, Graphics2D g2){ public void drawPath(List<Point> path, Graphics2D g2){
from = path.getFirst();
to = null;
for(int i=0; i < path.size()-1; i++) path.forEach(point->
{ {
Point from = path.get(i); to = point;
Point to = path.get(i+1);
line.setLine(from,to); line.setLine(from,to);
g2.draw(line); g2.draw(line);
from = to;
});
} }
}
public void doPrint() public void doPrint()
{ {
Binary file not shown.

After

Width:  |  Height:  |  Size: 462 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 491 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 B