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(); |
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; | |||||
/** | /** | ||||
* | * | ||||
*/ | */ | ||||
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(); | ||||
public void registerEvents() | 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() | 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)); | |||||
} | } | ||||
/** | /** | ||||
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(); | ||||
} | } | ||||
} | } |
/* | |||||
* 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; | |||||
} | |||||
} |
<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> |
* regenerated by the Form Editor. | * regenerated by the Form Editor. | ||||
*/ | */ | ||||
@SuppressWarnings("unchecked") | @SuppressWarnings("unchecked") | ||||
// <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(); | |||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); | |||||
getContentPane().add(gZeichenflaeche, java.awt.BorderLayout.CENTER); | |||||
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); | |||||
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); | |||||
setSize(new java.awt.Dimension(540, 412)); | |||||
setLocationRelativeTo(null); | |||||
}// </editor-fold>//GEN-END: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(); | |||||
btnPrint = new javax.swing.JButton(); | |||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); | |||||
getContentPane().add(gZeichenflaeche, java.awt.BorderLayout.CENTER); | |||||
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); | |||||
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); | |||||
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); | |||||
getContentPane().add(jToolBar1, java.awt.BorderLayout.PAGE_START); | |||||
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 | ||||
}); | }); | ||||
} | } | ||||
// 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; | |||||
} | |||||
} | } |