From 7ea1da3ebde52a8889ed1bc668a2f5727a3f42cf Mon Sep 17 00:00:00 2001 From: schuhmannje82308 Date: Tue, 5 Dec 2023 09:15:57 +0100 Subject: [PATCH] Print implementiert --- src/mvcgrafik/Start.java | 2 +- .../controller/CommandController.java | 22 +++-- .../controller/commands/PrintCommand.java | 57 ++++++++++++ src/mvcgrafik/view/GrafikFrame.form | 11 +++ src/mvcgrafik/view/GrafikFrame.java | 81 +++++++++++------- src/mvcgrafik/view/Print24.gif | Bin 0 -> 491 bytes 6 files changed, 132 insertions(+), 41 deletions(-) create mode 100644 src/mvcgrafik/controller/commands/PrintCommand.java create mode 100644 src/mvcgrafik/view/Print24.gif diff --git a/src/mvcgrafik/Start.java b/src/mvcgrafik/Start.java index f12e437..f40cbe7 100644 --- a/src/mvcgrafik/Start.java +++ b/src/mvcgrafik/Start.java @@ -26,7 +26,7 @@ public class Start GrafikView view = frm.getgZeichenflaeche(); view.setModel(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_commands.registerEvents(); controller_commands.registerCommands(); diff --git a/src/mvcgrafik/controller/CommandController.java b/src/mvcgrafik/controller/CommandController.java index 2f06b4a..c6ab253 100644 --- a/src/mvcgrafik/controller/CommandController.java +++ b/src/mvcgrafik/controller/CommandController.java @@ -10,9 +10,11 @@ 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; /** * @@ -20,12 +22,14 @@ import mvcgrafik.view.GrafikFrame; */ public class CommandController implements ActionListener { - private GrafikFrame view; + private GrafikFrame frame; + private GrafikView view; private GrafikModel model; private CommandInvoker invoker; - public CommandController(GrafikFrame view, GrafikModel model) + public CommandController(GrafikFrame frame,GrafikView view, GrafikModel model) { + this.frame = frame; this.view = view; this.model = model; this.invoker = new CommandInvoker(); @@ -33,14 +37,18 @@ public class CommandController implements ActionListener public void registerEvents() { - view.getBtnFileOpen().addActionListener(this); - view.getBtnFileSave().addActionListener(this); + frame.getBtnFileOpen().addActionListener(this); + frame.getBtnFileSave().addActionListener(this); + frame.getBtnPrint().addActionListener(this); + } public void registerCommands() { - invoker.addCommand(view.getBtnFileOpen(), new OpenCommand(view, model)); - invoker.addCommand(view.getBtnFileSave(), new SaveCommand(view,model)); + invoker.addCommand(frame.getBtnFileOpen(), new OpenCommand(frame, 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) { Component key = (Component)e.getSource(); invoker.executeCommand(key); - if(key == view.getBtnFileOpen()){ + if(key == frame.getBtnFileOpen()){ invoker.deleteStack(); } } diff --git a/src/mvcgrafik/controller/commands/PrintCommand.java b/src/mvcgrafik/controller/commands/PrintCommand.java new file mode 100644 index 0000000..a76ffa2 --- /dev/null +++ b/src/mvcgrafik/controller/commands/PrintCommand.java @@ -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; + } + +} diff --git a/src/mvcgrafik/view/GrafikFrame.form b/src/mvcgrafik/view/GrafikFrame.form index f2cd990..87c960a 100644 --- a/src/mvcgrafik/view/GrafikFrame.form +++ b/src/mvcgrafik/view/GrafikFrame.form @@ -72,6 +72,17 @@ + + + + + + + + + + + diff --git a/src/mvcgrafik/view/GrafikFrame.java b/src/mvcgrafik/view/GrafikFrame.java index ae256b9..f0b194b 100644 --- a/src/mvcgrafik/view/GrafikFrame.java +++ b/src/mvcgrafik/view/GrafikFrame.java @@ -56,39 +56,46 @@ public class GrafikFrame extends javax.swing.JFrame * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() - { + // //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(); + 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(); + btnPrint = new javax.swing.JButton(); - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - getContentPane().add(gZeichenflaeche, java.awt.BorderLayout.CENTER); + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + 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.setToolTipText("Open File"); - btnFileOpen.setFocusable(false); - btnFileOpen.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - btnFileOpen.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); - jToolBar1.add(btnFileOpen); + 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); - 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); + 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); - 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)); - setLocationRelativeTo(null); - }// //GEN-END:initComponents + getContentPane().add(jToolBar1, java.awt.BorderLayout.PAGE_START); + + setSize(new java.awt.Dimension(540, 412)); + setLocationRelativeTo(null); + }// //GEN-END:initComponents /** * @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 - 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 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 javax.swing.JToolBar jToolBar1; + // End of variables declaration//GEN-END:variables + + /** + * @return the btnPrint + */ + public javax.swing.JButton getBtnPrint() { + return btnPrint; + } } diff --git a/src/mvcgrafik/view/Print24.gif b/src/mvcgrafik/view/Print24.gif new file mode 100644 index 0000000000000000000000000000000000000000..e6b4fb177c737f574e63baa93bf34f85ce95a0f9 GIT binary patch literal 491 zcmZ?wbhEHblwgoxxcZ;rKL{{92ZCon^bAPc0fF1MZ{N9n>;Ekvy7~Y5wZB)d{JwnY z$Hj}^&z<{n_ROaY?1=9`-~ZQ2L|8#ZpZwqe7D zb?dIIS#xRistYStoL#!~%;LqT7A!cvV8Mb}vkuOjxqs%&nZ{=rfZ)J^10V_v6o0ZX zGBDUM=zw@2KRK{%b(mM+p(EA5NA|&&stlp?mr|G8XcgaBQ)azVYO4C3m)CB3GQ_Er zp3Pgo_T3Mu1=HS7haFDz>Db zVbav;OW4dNPwJ~!y=H9-!-kC^^VfJK)#&mxZK>Gi!{5-bc`JjFfPaImxT*Ro7q51I zS<#-Pb6y*7-nvXuz**G#N{_}Uv zFQ_caOwTA$FfuSOP)Mp&2rkW2@Xbsv$}g@gE=kQT)=}`xOV(3x%*jy*0x2w32udwZ eEh