Ich hab überall wo der Frame eingebunden werden muss die sachen auskommentiert und ToDos eingefügtmaster
@@ -29,13 +29,14 @@ public class CommandController implements ActionListener{ | |||
public void registerEvents(){ | |||
view.getBtnConnect().addActionListener(this); | |||
view.getTfNachricht().addActionListener(this); | |||
//ToDo: muss auf gFrame referenzieren | |||
//view.getTfNachricht().addActionListener(this); | |||
} | |||
public void registerCommands(){ | |||
CommandSend commandSend = new CommandSend(view); | |||
invoker.addCommand(view.getBtnConnect(), new CommandConnect(view, commandSend)); | |||
invoker.addCommand(view.getTfNachricht(), commandSend); | |||
//invoker.addCommand(view.getTfNachricht(), commandSend); | |||
} | |||
/** |
@@ -34,17 +34,21 @@ public class CommandSend implements CommandInterface | |||
public CommandSend(ChatView view) | |||
{ | |||
this.view = view; | |||
this.eingabeFeld = view.getTfNachricht(); | |||
//ToDo: Hier muss auch der gFrame referenziert werden | |||
//this.eingabeFeld = view.getTfNachricht(); | |||
transmitterInterface = null; | |||
} | |||
@Override | |||
public void execute() | |||
{ | |||
if(transmitterInterface != null && !eingabeFeld.getText().isEmpty()){ | |||
transmitterInterface.send(eingabeFeld.getText()); | |||
eingabeFeld.setText(""); | |||
} | |||
//ToDo in dieser methode muss die Figur serialisiert werden und zum | |||
//übermitteln bereitgestellt werden | |||
// if(transmitterInterface != null && !eingabeFeld.getText().isEmpty()){ | |||
// transmitterInterface.send(eingabeFeld.getText()); | |||
// eingabeFeld.setText(""); | |||
// } | |||
} | |||
@@ -29,8 +29,10 @@ public class ReceiveAdapter implements Subscriber<Nachricht> { | |||
@Override | |||
public void onNext(Nachricht item) { | |||
view.getTxtChat().append(item.getNachricht()); | |||
//ToDo: hier muss der gFrame aufgerufen werden | |||
// evtl muss die Figur aber zuerst serialisiert werden | |||
//view.getTxtChat().append(item.getNachricht()); | |||
this.subscription.request(1); | |||
} | |||
@@ -107,45 +107,25 @@ | |||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/> | |||
<SubComponents> | |||
<Component class="javax.swing.JTextField" name="tfNachricht"> | |||
<Properties> | |||
<Property name="toolTipText" type="java.lang.String" value=""/> | |||
</Properties> | |||
<Events> | |||
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="tfNachrichtMouseClicked"/> | |||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="tfNachrichtActionPerformed"/> | |||
</Events> | |||
<Constraints> | |||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription"> | |||
<BorderConstraints direction="Last"/> | |||
</Constraint> | |||
</Constraints> | |||
</Component> | |||
<Container class="javax.swing.JScrollPane" name="jScrollPane2"> | |||
<Properties> | |||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor"> | |||
<Dimension value="[238, 150]"/> | |||
</Property> | |||
</Properties> | |||
<AuxValues> | |||
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> | |||
</AuxValues> | |||
<Container class="javax.swing.JPanel" name="jPanel2"> | |||
<Constraints> | |||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription"> | |||
<BorderConstraints direction="Center"/> | |||
</Constraint> | |||
</Constraints> | |||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> | |||
<SubComponents> | |||
<Component class="javax.swing.JTextArea" name="txtChat"> | |||
<Properties> | |||
<Property name="columns" type="int" value="20"/> | |||
<Property name="rows" type="int" value="5"/> | |||
<Property name="text" type="java.lang.String" value="Chat:"/> | |||
</Properties> | |||
</Component> | |||
</SubComponents> | |||
<Layout> | |||
<DimensionLayout dim="0"> | |||
<Group type="103" groupAlignment="0" attributes="0"> | |||
<EmptySpace min="0" pref="400" max="32767" attributes="0"/> | |||
</Group> | |||
</DimensionLayout> | |||
<DimensionLayout dim="1"> | |||
<Group type="103" groupAlignment="0" attributes="0"> | |||
<EmptySpace min="0" pref="300" max="32767" attributes="0"/> | |||
</Group> | |||
</DimensionLayout> | |||
</Layout> | |||
</Container> | |||
</SubComponents> | |||
</Form> |
@@ -35,9 +35,7 @@ public class ChatView extends javax.swing.JFrame | |||
jPanel1 = new javax.swing.JPanel(); | |||
BtnConnect = new javax.swing.JButton(); | |||
BtnGrpMode = new javax.swing.ButtonGroup(); | |||
tfNachricht = new javax.swing.JTextField(); | |||
jScrollPane2 = new javax.swing.JScrollPane(); | |||
txtChat = new javax.swing.JTextArea(); | |||
jPanel2 = new javax.swing.JPanel(); | |||
dialogChooseMode.setMinimumSize(new java.awt.Dimension(278, 208)); | |||
dialogChooseMode.getContentPane().setLayout(new java.awt.GridLayout(0, 1)); | |||
@@ -97,27 +95,18 @@ public class ChatView extends javax.swing.JFrame | |||
} | |||
}); | |||
tfNachricht.setToolTipText(""); | |||
tfNachricht.addMouseListener(new java.awt.event.MouseAdapter() { | |||
public void mouseClicked(java.awt.event.MouseEvent evt) { | |||
tfNachrichtMouseClicked(evt); | |||
} | |||
}); | |||
tfNachricht.addActionListener(new java.awt.event.ActionListener() { | |||
public void actionPerformed(java.awt.event.ActionEvent evt) { | |||
tfNachrichtActionPerformed(evt); | |||
} | |||
}); | |||
getContentPane().add(tfNachricht, java.awt.BorderLayout.PAGE_END); | |||
jScrollPane2.setPreferredSize(new java.awt.Dimension(238, 150)); | |||
txtChat.setColumns(20); | |||
txtChat.setRows(5); | |||
txtChat.setText("Chat:"); | |||
jScrollPane2.setViewportView(txtChat); | |||
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); | |||
jPanel2.setLayout(jPanel2Layout); | |||
jPanel2Layout.setHorizontalGroup( | |||
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |||
.addGap(0, 400, Short.MAX_VALUE) | |||
); | |||
jPanel2Layout.setVerticalGroup( | |||
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |||
.addGap(0, 300, Short.MAX_VALUE) | |||
); | |||
getContentPane().add(jScrollPane2, java.awt.BorderLayout.CENTER); | |||
getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER); | |||
pack(); | |||
}// </editor-fold>//GEN-END:initComponents | |||
@@ -132,21 +121,11 @@ public class ChatView extends javax.swing.JFrame | |||
// TODO add your handling code here: | |||
}//GEN-LAST:event_BtnServerActionPerformed | |||
private void tfNachrichtActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_tfNachrichtActionPerformed | |||
{//GEN-HEADEREND:event_tfNachrichtActionPerformed | |||
// TODO add your handling code here: | |||
}//GEN-LAST:event_tfNachrichtActionPerformed | |||
private void formWindowOpened(java.awt.event.WindowEvent evt)//GEN-FIRST:event_formWindowOpened | |||
{//GEN-HEADEREND:event_formWindowOpened | |||
dialogChooseMode.show(); | |||
}//GEN-LAST:event_formWindowOpened | |||
private void tfNachrichtMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_tfNachrichtMouseClicked | |||
{//GEN-HEADEREND:event_tfNachrichtMouseClicked | |||
}//GEN-LAST:event_tfNachrichtMouseClicked | |||
private void BtnConnectActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_BtnConnectActionPerformed | |||
{//GEN-HEADEREND:event_BtnConnectActionPerformed | |||
// TODO add your handling code here: | |||
@@ -208,10 +187,8 @@ public class ChatView extends javax.swing.JFrame | |||
private javax.swing.JRadioButton BtnServer; | |||
private javax.swing.JDialog dialogChooseMode; | |||
private javax.swing.JPanel jPanel1; | |||
private javax.swing.JScrollPane jScrollPane2; | |||
private javax.swing.JPanel jPanel2; | |||
private javax.swing.JLabel lblMode; | |||
private javax.swing.JTextField tfNachricht; | |||
private javax.swing.JTextArea txtChat; | |||
// End of variables declaration//GEN-END:variables | |||
/** | |||
@@ -254,19 +231,19 @@ public class ChatView extends javax.swing.JFrame | |||
return dialogChooseMode; | |||
} | |||
/** | |||
* @return the tfNachricht | |||
*/ | |||
public javax.swing.JTextField getTfNachricht() | |||
{ | |||
return tfNachricht; | |||
} | |||
/** | |||
* @return the txtChat | |||
*/ | |||
public javax.swing.JTextArea getTxtChat() | |||
{ | |||
return txtChat; | |||
} | |||
// /** | |||
// * @return the tfNachricht | |||
// */ | |||
// public javax.swing.JTextField getTfNachricht() | |||
// { | |||
// return tfNachricht; | |||
// } | |||
// | |||
// /** | |||
// * @return the txtChat | |||
// */ | |||
// public javax.swing.JTextArea getTxtChat() | |||
// { | |||
// return txtChat; | |||
// } | |||
} |
@@ -0,0 +1,89 @@ | |||
<?xml version="1.0" encoding="UTF-8" ?> | |||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> | |||
<NonVisualComponents> | |||
<Component class="javax.swing.JFileChooser" name="FcFileChooser"> | |||
</Component> | |||
</NonVisualComponents> | |||
<Properties> | |||
<Property name="defaultCloseOperation" type="int" value="3"/> | |||
</Properties> | |||
<SyntheticProperties> | |||
<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"/> | |||
<SyntheticProperty name="generateCenter" type="boolean" value="true"/> | |||
</SyntheticProperties> | |||
<AuxValues> | |||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> | |||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> | |||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> | |||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> | |||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> | |||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/> | |||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> | |||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> | |||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> | |||
</AuxValues> | |||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/> | |||
<SubComponents> | |||
<Container class="mvcgrafik.view.GrafikView" name="gZeichenflaeche"> | |||
<Constraints> | |||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription"> | |||
<BorderConstraints direction="Center"/> | |||
</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> | |||
<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> | |||
</SubComponents> | |||
</Form> |
@@ -0,0 +1,165 @@ | |||
/* | |||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license | |||
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template | |||
*/ | |||
package ChatProgramm.view; | |||
/** | |||
* | |||
* @author le | |||
*/ | |||
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 | |||
*/ | |||
public mvcgrafik.view.GrafikView getgZeichenflaeche() | |||
{ | |||
return gZeichenflaeche; | |||
} | |||
/** | |||
* Creates new form GrafikFrame | |||
*/ | |||
public GrafikFrame() | |||
{ | |||
initComponents(); | |||
} | |||
/** | |||
* This method is called from within the constructor to initialize the form. | |||
* WARNING: Do NOT modify this code. The content of this method is always | |||
* regenerated by the Form Editor. | |||
*/ | |||
@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(); | |||
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 | |||
*/ | |||
public static void main(String args[]) | |||
{ | |||
/* Set the Nimbus look and feel */ | |||
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> | |||
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. | |||
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html | |||
*/ | |||
try | |||
{ | |||
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) | |||
{ | |||
if ("Nimbus".equals(info.getName())) | |||
{ | |||
javax.swing.UIManager.setLookAndFeel(info.getClassName()); | |||
break; | |||
} | |||
} | |||
} | |||
catch (ClassNotFoundException ex) | |||
{ | |||
java.util.logging.Logger.getLogger(GrafikFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||
} | |||
catch (InstantiationException ex) | |||
{ | |||
java.util.logging.Logger.getLogger(GrafikFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||
} | |||
catch (IllegalAccessException ex) | |||
{ | |||
java.util.logging.Logger.getLogger(GrafikFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||
} | |||
catch (javax.swing.UnsupportedLookAndFeelException ex) | |||
{ | |||
java.util.logging.Logger.getLogger(GrafikFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||
} | |||
//</editor-fold> | |||
//</editor-fold> | |||
/* Create and display the form */ | |||
java.awt.EventQueue.invokeLater(new Runnable() | |||
{ | |||
public void run() | |||
{ | |||
new GrafikFrame().setVisible(true); | |||
} | |||
}); | |||
} | |||
// 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; | |||
} | |||
} |
@@ -0,0 +1,143 @@ | |||
/* | |||
* 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 ChatProgramm.view; | |||
import java.awt.Dimension; | |||
import java.awt.Graphics; | |||
import java.awt.Graphics2D; | |||
import java.awt.Point; | |||
import java.awt.geom.Rectangle2D; | |||
import java.awt.geom.Line2D; | |||
import java.awt.print.PageFormat; | |||
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 ChatProgramm.model.GrafikModel; | |||
import ChatProgramm.util.OhmLogger; | |||
/** | |||
* | |||
* @author le | |||
*/ | |||
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; | |||
private GrafikModel model; | |||
private Point from = null; | |||
private Point to = null; | |||
public GrafikView() | |||
{ | |||
pixel = new Rectangle2D.Float(); | |||
line = new Line2D.Float(); | |||
} | |||
public void setModel(GrafikModel model) | |||
{ | |||
this.model = model; | |||
} | |||
/** | |||
* 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! | |||
drawPath(model.getPunkte(),g2); | |||
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) | |||
{ | |||
if (model == null) return; | |||
super.paintComponent(g); | |||
Graphics2D g2 = (Graphics2D)g; | |||
model.getFiguren().forEach(figuren-> | |||
{ | |||
drawPath(figuren.getPunkte(),g2); | |||
}); | |||
} | |||
public void drawPath(List<Point> path, Graphics2D g2){ | |||
from = path.getFirst(); | |||
to = null; | |||
path.forEach(point-> | |||
{ | |||
to = point; | |||
line.setLine(from,to); | |||
g2.draw(line); | |||
from = to; | |||
}); | |||
} | |||
public void doPrint() | |||
{ | |||
HashPrintRequestAttributeSet printSet = | |||
new HashPrintRequestAttributeSet(); | |||
printSet.add(DialogTypeSelection.NATIVE); | |||
PrinterJob pj = PrinterJob.getPrinterJob(); | |||
pj.setPrintable(this); | |||
//Dialog | |||
if (pj.printDialog(printSet)) | |||
{ | |||
try | |||
{ | |||
pj.print(printSet); | |||
} | |||
catch (Exception ex) | |||
{ | |||
JOptionPane.showMessageDialog(this, ex.toString()); | |||
} | |||
} | |||
} | |||
@Override | |||
public int print(Graphics gp, PageFormat pf, int pageIndex) throws PrinterException | |||
{ | |||
Graphics2D g2p = (Graphics2D)gp; | |||
if (pageIndex == 0) | |||
{ | |||
g2p.translate(pf.getImageableX(), pf.getImageableY()); | |||
g2p.scale(pf.getImageableWidth() / this.getWidth(), | |||
pf.getImageableHeight() / this.getHeight()); | |||
super.print(g2p); | |||
return Printable.PAGE_EXISTS; | |||
} | |||
else | |||
{ | |||
return Printable.NO_SUCH_PAGE; // wichtig sonst Papiervernichtung | |||
} | |||
} | |||
} |