@@ -0,0 +1,6 @@ | |||
/build/ | |||
/nbproject/private/ | |||
*.xml | |||
*.properties | |||
*.mf | |||
/dist/ |
@@ -0,0 +1,51 @@ | |||
/* | |||
* To change this license header, choose License Headers in Project Properties. | |||
* To change this template file, choose Tools | Templates | |||
* and open the template in the editor. | |||
*/ | |||
package mvcgrafik; | |||
import javax.swing.JFrame; | |||
import javax.swing.JPanel; | |||
import javax.swing.WindowConstants; | |||
import mvcgrafik.controller.BtnController; | |||
import mvcgrafik.controller.GrafikController; | |||
import mvcgrafik.model.GrafikModel; | |||
import mvcgrafik.view.GrafikMenuView; | |||
import mvcgrafik.view.GrafikView; | |||
//import mvcgrafik.ohmLogger; | |||
/** | |||
* Builder Class | |||
* @author le | |||
*/ | |||
public class Start | |||
{ | |||
public Start() | |||
{ | |||
JFrame frm = new JFrame(); | |||
frm.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); | |||
GrafikMenuView view = new GrafikMenuView(); | |||
GrafikModel model = new GrafikModel(); | |||
view.getGrafikView1().setModel(model); | |||
GrafikController controller = new GrafikController(view.getGrafikView1(), model); | |||
BtnController btncontroller = new BtnController(view, model); | |||
controller.registerEvents(); | |||
btncontroller.registerEvents(); | |||
view.setSize(800, 600); | |||
view.setVisible(true); | |||
} | |||
/** | |||
* @param args the command line arguments | |||
*/ | |||
public static void main(String[] args) | |||
{ | |||
new Start(); | |||
} | |||
} |
@@ -0,0 +1,109 @@ | |||
/* | |||
* To change this license header, choose License Headers in Project Properties. | |||
* To change this template file, choose Tools | Templates | |||
* and open the template in the editor. | |||
*/ | |||
package mvcgrafik.controller; | |||
import java.awt.Point; | |||
import java.awt.event.ActionEvent; | |||
import java.awt.event.ActionListener; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.io.UnsupportedEncodingException; | |||
import java.util.logging.Level; | |||
import java.util.logging.Logger; | |||
import java.util.prefs.Preferences; | |||
import javax.swing.JFileChooser; | |||
import mvcgrafik.model.Figure; | |||
import mvcgrafik.model.GrafikModel; | |||
import mvcgrafik.view.GrafikMenuView; | |||
import mvcgrafik.logger.OhmLogger; | |||
/** | |||
* | |||
* @author le | |||
*/ | |||
public class BtnController implements ActionListener | |||
{ | |||
private GrafikMenuView view; | |||
//private GrafikMenuView menuview; | |||
private GrafikModel model; | |||
private Figure figure; | |||
private Point p_old; | |||
private static Logger lg = OhmLogger.getLogger(); | |||
public BtnController(GrafikMenuView view, GrafikModel model) | |||
{ | |||
this.view = view; | |||
this.model = model; | |||
} | |||
public void registerEvents() | |||
{ | |||
view.getBtnOpen().addActionListener(this); | |||
view.getBtnSafe().addActionListener(this); | |||
} | |||
@Override | |||
public void actionPerformed(ActionEvent ae) | |||
{ | |||
if(ae.getSource() == view.getBtnSafe()) | |||
{ | |||
Preferences pref = Preferences.userNodeForPackage(this.getClass()); | |||
String path = pref.get("DEFAULT_PATH", ""); | |||
view.getjFileChooser1().setCurrentDirectory(new File(path)); | |||
int choice = view.getjFileChooser1().showSaveDialog(view); | |||
if (choice == JFileChooser.APPROVE_OPTION) | |||
{ | |||
File selectedFile = view.getjFileChooser1().getSelectedFile(); | |||
pref.put("DEFAULT_PATH", selectedFile.getAbsolutePath()); | |||
try | |||
{ | |||
//model.datenSpeichern(selectedFile); | |||
model.speichereDatei("TEST"); | |||
} | |||
catch (UnsupportedEncodingException ex) | |||
{ | |||
Logger.getLogger(GrafikController.class.getName()).log(Level.SEVERE, null, ex); | |||
} | |||
catch (IOException ex) | |||
{ | |||
Logger.getLogger(GrafikController.class.getName()).log(Level.SEVERE, null, ex); | |||
} | |||
} | |||
} | |||
if(ae.getSource() == view.getBtnOpen()) | |||
{ | |||
Preferences pref = Preferences.userNodeForPackage(this.getClass()); | |||
String path = pref.get("DEFAULT_PATH", ""); | |||
view.getjFileChooser1().setCurrentDirectory(new File(path)); | |||
int choice = view.getjFileChooser1().showOpenDialog(view); | |||
if (choice == JFileChooser.APPROVE_OPTION) | |||
{ | |||
File selectedFile = view.getjFileChooser1().getSelectedFile(); | |||
pref.put("DEFAULT_PATH", selectedFile.getAbsolutePath()); | |||
try | |||
{ | |||
//model.datenLesen(selectedFile); | |||
model.ladeDatei("TEST"); | |||
} | |||
catch (UnsupportedEncodingException ex) | |||
{ | |||
Logger.getLogger(GrafikController.class.getName()).log(Level.SEVERE, null, ex); | |||
} | |||
catch (IOException | ClassNotFoundException ex) | |||
{ | |||
Logger.getLogger(GrafikController.class.getName()).log(Level.SEVERE, null, ex); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
@@ -0,0 +1,103 @@ | |||
/* | |||
* To change this license header, choose License Headers in Project Properties. | |||
* To change this template file, choose Tools | Templates | |||
* and open the template in the editor. | |||
*/ | |||
package mvcgrafik.controller; | |||
import java.awt.Point; | |||
import java.awt.event.MouseEvent; | |||
import java.awt.event.MouseListener; | |||
import java.awt.event.MouseMotionListener; | |||
import java.util.logging.Logger; | |||
import mvcgrafik.model.Figure; | |||
import mvcgrafik.model.GrafikModel; | |||
import mvcgrafik.logger.OhmLogger; | |||
import mvcgrafik.view.GrafikView; | |||
/** | |||
* | |||
* @author le | |||
*/ | |||
public class GrafikController implements MouseMotionListener, MouseListener | |||
{ | |||
private GrafikView view; | |||
private GrafikModel model; | |||
private Figure figure; | |||
private Point p_old; | |||
private static Logger lg = OhmLogger.getLogger(); | |||
public GrafikController(GrafikView view, GrafikModel model) | |||
{ | |||
this.view = view; | |||
this.model = model; | |||
} | |||
public void registerEvents() | |||
{ | |||
view.addMouseMotionListener(this); | |||
view.addMouseListener(this); | |||
} | |||
@Override | |||
public void mouseDragged(MouseEvent evt) | |||
{ | |||
if(figure == null) | |||
{ | |||
lg.info("new Figure"); | |||
figure = model.addFigure(); | |||
} | |||
Point p = evt.getPoint(); | |||
if(p_old != null){ | |||
// view.drawLine(p, p_old); | |||
view.drawLine(p, p_old); | |||
} | |||
p_old = p; | |||
figure.addPoint(p); | |||
} | |||
@Override | |||
public void mouseMoved(MouseEvent e) | |||
{ | |||
} | |||
@Override | |||
public void mouseClicked(MouseEvent e) | |||
{ | |||
lg.info("clicked"); | |||
figure = model.addFigure(); | |||
} | |||
@Override | |||
public void mousePressed(MouseEvent e) | |||
{ | |||
} | |||
@Override | |||
public void mouseReleased(MouseEvent evt) | |||
{ | |||
p_old = null; | |||
figure = null; | |||
lg.info("Figure finished"); | |||
if (evt.getButton() == MouseEvent.BUTTON3) | |||
{ | |||
// view.doPrint(); | |||
view.doPrint(); | |||
} | |||
} | |||
@Override | |||
public void mouseEntered(MouseEvent e) | |||
{ | |||
} | |||
@Override | |||
public void mouseExited(MouseEvent e) | |||
{ | |||
} | |||
} | |||
@@ -0,0 +1,26 @@ | |||
/* | |||
* To change this license header, choose License Headers in Project Properties. | |||
* To change this template file, choose Tools | Templates | |||
* and open the template in the editor. | |||
*/ | |||
package mvcgrafik.logger; | |||
import java.util.Date; | |||
import java.util.logging.Formatter; | |||
import java.util.logging.LogRecord; | |||
/** | |||
* | |||
* @author chris | |||
*/ | |||
public class MyFormatter extends Formatter { | |||
@Override | |||
public String format(LogRecord lr) { | |||
String date = String.format("%1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS %1$Tp", new Date(lr.getMillis())); | |||
String s = ("| ")+lr.getMillis()+(" | ")+date+(" | ")+lr.getLevel().toString()+(" | ")+lr.getSourceClassName()+(" | ")+lr.getMessage()+(" | ")+"\n"; | |||
return s; | |||
} | |||
} |
@@ -0,0 +1,54 @@ | |||
/* | |||
* To change this license header, choose License Headers in Project Properties. | |||
* To change this template file, choose Tools | Templates | |||
* and open the template in the editor. | |||
*/ | |||
package mvcgrafik.logger; | |||
import mvcgrafik.logger.MyFormatter; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.util.logging.*; | |||
/** | |||
* | |||
* @author chris, hd | |||
*/ | |||
public class OhmLogger | |||
{ | |||
public OhmLogger() | |||
{ | |||
} | |||
private static Logger lg = null; | |||
public static Logger getLogger() | |||
{ | |||
if (lg == null) | |||
{ | |||
lg = Logger.getLogger("OhmLogger"); | |||
initLogger(); | |||
} | |||
return lg; | |||
} | |||
private static void initLogger() | |||
{ | |||
try{ | |||
String datei = System.getProperty("java.io.tmpdir") + File.separator + "log.txt"; | |||
FileHandler fh = new FileHandler(datei); | |||
ConsoleHandler ch = new ConsoleHandler(); | |||
lg.addHandler(fh); | |||
ch.setFormatter(new MyFormatter()); | |||
lg.setUseParentHandlers(false); | |||
lg.addHandler(ch); | |||
lg.setLevel(Level.ALL); | |||
} | |||
catch(IOException ioex) | |||
{ | |||
System.err.println(ioex); | |||
} | |||
} | |||
} |
@@ -0,0 +1,36 @@ | |||
/* | |||
* To change this license header, choose License Headers in Project Properties. | |||
* To change this template file, choose Tools | Templates | |||
* and open the template in the editor. | |||
*/ | |||
package mvcgrafik.model; | |||
import java.awt.Point; | |||
import java.util.ArrayList; | |||
import java.util.Collections; | |||
import java.util.List; | |||
/** | |||
* | |||
* @author chris, hd | |||
*/ | |||
public class Figure | |||
{ | |||
private ArrayList<Point> punkte; | |||
public Figure() | |||
{ | |||
punkte = new ArrayList<>(); | |||
} | |||
public void addPoint(Point p) | |||
{ | |||
punkte.add(p); | |||
} | |||
public List<Point> getPunkte() | |||
{ | |||
return Collections.unmodifiableList(punkte); | |||
} | |||
} |
@@ -0,0 +1,74 @@ | |||
/* | |||
* To change this license header, choose License Headers in Project Properties. | |||
* To change this template file, choose Tools | Templates | |||
* and open the template in the editor. | |||
*/ | |||
package mvcgrafik.model; | |||
import java.awt.Point; | |||
import java.io.BufferedInputStream; | |||
import java.io.BufferedOutputStream; | |||
import java.io.FileInputStream; | |||
import java.io.FileNotFoundException; | |||
import java.io.FileOutputStream; | |||
import java.io.IOException; | |||
import java.io.ObjectInputStream; | |||
import java.io.ObjectOutputStream; | |||
import java.util.ArrayList; | |||
import java.util.Collections; | |||
import java.util.List; | |||
/** | |||
* | |||
* @author le | |||
*/ | |||
public class GrafikModel | |||
{ | |||
private ArrayList<Figure> figures; | |||
public GrafikModel() | |||
{ | |||
figures = new ArrayList<>(); | |||
} | |||
public Figure addFigure() | |||
{ | |||
figures.add(new Figure()); | |||
return figures.get(figures.size() - 1); | |||
} | |||
public List<Figure> getFigures() | |||
{ | |||
return Collections.unmodifiableList(figures); | |||
} | |||
public void speichereDatei(String dateiname) throws FileNotFoundException, IOException | |||
{ | |||
FileOutputStream fos = new FileOutputStream(dateiname); | |||
BufferedOutputStream buffout = new BufferedOutputStream(fos); | |||
ObjectOutputStream oos = new ObjectOutputStream(buffout); | |||
oos.writeObject(figures); | |||
oos.flush(); | |||
oos.close(); | |||
} | |||
public void ladeDatei(String dateiname) throws FileNotFoundException, IOException, ClassNotFoundException | |||
{ | |||
FileInputStream fis = new FileInputStream(dateiname); | |||
BufferedInputStream buffin = new BufferedInputStream(fis); | |||
ObjectInputStream ois = new ObjectInputStream(buffin); | |||
Object obj = ois.readObject(); | |||
// if (obj instanceof ArrayList) | |||
// { | |||
// punkte = (ArrayList<Point>) obj; | |||
// } | |||
// else | |||
// { | |||
// Fehler .... | |||
// } | |||
figures = (ArrayList<Figure>) ois.readObject(); | |||
ois.close(); | |||
} | |||
} |
@@ -0,0 +1,93 @@ | |||
<?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="jFileChooser1"> | |||
</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="btnOpen"> | |||
<Properties> | |||
<Property name="text" type="java.lang.String" value="Open"/> | |||
</Properties> | |||
<Events> | |||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnOpenActionPerformed"/> | |||
</Events> | |||
</MenuItem> | |||
<MenuItem class="javax.swing.JMenuItem" name="btnSafe"> | |||
<Properties> | |||
<Property name="text" type="java.lang.String" value="Safe"/> | |||
</Properties> | |||
<Events> | |||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnSafeActionPerformed"/> | |||
</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"/> | |||
<Property name="title" type="java.lang.String" value="Zeichentool"/> | |||
</Properties> | |||
<SyntheticProperties> | |||
<SyntheticProperty name="menuBar" type="java.lang.String" value="jMenuBar1"/> | |||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/> | |||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/> | |||
</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"/> | |||
<AuxValue name="designerSize" 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,44,0,0,1,-112"/> | |||
</AuxValues> | |||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/> | |||
<SubComponents> | |||
<Container class="javax.swing.JPanel" name="jPanel1"> | |||
<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> | |||
<DimensionLayout dim="0"> | |||
<Group type="103" groupAlignment="0" attributes="0"> | |||
<Component id="grafikView1" alignment="0" pref="400" max="32767" attributes="0"/> | |||
</Group> | |||
</DimensionLayout> | |||
<DimensionLayout dim="1"> | |||
<Group type="103" groupAlignment="0" attributes="0"> | |||
<Component id="grafikView1" alignment="1" pref="279" max="32767" attributes="0"/> | |||
</Group> | |||
</DimensionLayout> | |||
</Layout> | |||
<SubComponents> | |||
<Container class="mvcgrafik.view.GrafikView" name="grafikView1"> | |||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout"> | |||
<Property name="useNullLayout" type="boolean" value="true"/> | |||
</Layout> | |||
</Container> | |||
</SubComponents> | |||
</Container> | |||
</SubComponents> | |||
</Form> |
@@ -0,0 +1,201 @@ | |||
/* | |||
* To change this license header, choose License Headers in Project Properties. | |||
* To change this template file, choose Tools | Templates | |||
* and open the template in the editor. | |||
*/ | |||
package mvcgrafik.view; | |||
/** | |||
* | |||
* @author hd | |||
*/ | |||
public class GrafikMenuView extends javax.swing.JFrame | |||
{ | |||
/** | |||
* @return the jPanel1 | |||
*/ | |||
public javax.swing.JPanel getjPanel1() | |||
{ | |||
return jPanel1; | |||
} | |||
/** | |||
* Creates new form GrafikMenuView | |||
*/ | |||
public GrafikMenuView() | |||
{ | |||
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() | |||
{ | |||
jFileChooser1 = new javax.swing.JFileChooser(); | |||
jPanel1 = new javax.swing.JPanel(); | |||
grafikView1 = new mvcgrafik.view.GrafikView(); | |||
jMenuBar1 = new javax.swing.JMenuBar(); | |||
jMenu1 = new javax.swing.JMenu(); | |||
btnOpen = new javax.swing.JMenuItem(); | |||
btnSafe = new javax.swing.JMenuItem(); | |||
jMenu2 = new javax.swing.JMenu(); | |||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); | |||
setTitle("Zeichentool"); | |||
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); | |||
jPanel1.setLayout(jPanel1Layout); | |||
jPanel1Layout.setHorizontalGroup( | |||
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |||
.addComponent(grafikView1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE) | |||
); | |||
jPanel1Layout.setVerticalGroup( | |||
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |||
.addComponent(grafikView1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE) | |||
); | |||
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER); | |||
jMenu1.setText("File"); | |||
btnOpen.setText("Open"); | |||
btnOpen.addActionListener(new java.awt.event.ActionListener() | |||
{ | |||
public void actionPerformed(java.awt.event.ActionEvent evt) | |||
{ | |||
btnOpenActionPerformed(evt); | |||
} | |||
}); | |||
jMenu1.add(btnOpen); | |||
btnSafe.setText("Safe"); | |||
btnSafe.addActionListener(new java.awt.event.ActionListener() | |||
{ | |||
public void actionPerformed(java.awt.event.ActionEvent evt) | |||
{ | |||
btnSafeActionPerformed(evt); | |||
} | |||
}); | |||
jMenu1.add(btnSafe); | |||
jMenuBar1.add(jMenu1); | |||
jMenu2.setText("Edit"); | |||
jMenuBar1.add(jMenu2); | |||
setJMenuBar(jMenuBar1); | |||
pack(); | |||
}// </editor-fold>//GEN-END:initComponents | |||
private void btnOpenActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnOpenActionPerformed | |||
{//GEN-HEADEREND:event_btnOpenActionPerformed | |||
// TODO add your handling code here: | |||
}//GEN-LAST:event_btnOpenActionPerformed | |||
private void btnSafeActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnSafeActionPerformed | |||
{//GEN-HEADEREND:event_btnSafeActionPerformed | |||
// TODO add your handling code here: | |||
}//GEN-LAST:event_btnSafeActionPerformed | |||
/** | |||
* @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(GrafikMenuView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||
} | |||
catch (InstantiationException ex) | |||
{ | |||
java.util.logging.Logger.getLogger(GrafikMenuView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||
} | |||
catch (IllegalAccessException ex) | |||
{ | |||
java.util.logging.Logger.getLogger(GrafikMenuView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||
} | |||
catch (javax.swing.UnsupportedLookAndFeelException ex) | |||
{ | |||
java.util.logging.Logger.getLogger(GrafikMenuView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||
} | |||
//</editor-fold> | |||
/* Create and display the form */ | |||
java.awt.EventQueue.invokeLater(new Runnable() | |||
{ | |||
public void run() | |||
{ | |||
new GrafikMenuView().setVisible(true); | |||
} | |||
}); | |||
} | |||
// Variables declaration - do not modify//GEN-BEGIN:variables | |||
private javax.swing.JMenuItem btnOpen; | |||
private javax.swing.JMenuItem btnSafe; | |||
private mvcgrafik.view.GrafikView grafikView1; | |||
private javax.swing.JFileChooser jFileChooser1; | |||
private javax.swing.JMenu jMenu1; | |||
private javax.swing.JMenu jMenu2; | |||
private javax.swing.JMenuBar jMenuBar1; | |||
private javax.swing.JPanel jPanel1; | |||
// End of variables declaration//GEN-END:variables | |||
/** | |||
* @return the grafikView1 | |||
*/ | |||
public mvcgrafik.view.GrafikView getGrafikView1() | |||
{ | |||
return grafikView1; | |||
} | |||
/** | |||
* @return the jFileChooser1 | |||
*/ | |||
public javax.swing.JFileChooser getjFileChooser1() | |||
{ | |||
return jFileChooser1; | |||
} | |||
/** | |||
* @return the btnOpen | |||
*/ | |||
public javax.swing.JMenuItem getBtnOpen() | |||
{ | |||
return btnOpen; | |||
} | |||
/** | |||
* @return the btnSafe | |||
*/ | |||
public javax.swing.JMenuItem getBtnSafe() | |||
{ | |||
return btnSafe; | |||
} | |||
} |
@@ -0,0 +1,127 @@ | |||
/* | |||
* To change this license header, choose License Headers in Project Properties. | |||
* To change this template file, choose Tools | Templates | |||
* and open the template in the editor. | |||
*/ | |||
package mvcgrafik.view; | |||
import java.awt.Color; | |||
import java.awt.Dimension; | |||
import java.awt.Graphics; | |||
import java.awt.Graphics2D; | |||
import java.awt.Point; | |||
import java.awt.geom.Line2D; | |||
import java.awt.geom.Rectangle2D; | |||
import java.awt.print.PageFormat; | |||
import java.awt.print.Printable; | |||
import java.awt.print.PrinterException; | |||
import java.awt.print.PrinterJob; | |||
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.logger.OhmLogger; | |||
/** | |||
* | |||
* @author hd, chris | |||
*/ | |||
public class GrafikView extends JComponent implements Printable | |||
{ | |||
private final static Dimension EINS = new Dimension(1, 1); | |||
private static Logger lg = OhmLogger.getLogger(); | |||
private Rectangle2D.Float pixel; | |||
private GrafikModel model; | |||
private Point old_punkt = null; | |||
public GrafikView() | |||
{ | |||
pixel = new Rectangle2D.Float(); | |||
this.setBackground(Color.WHITE); | |||
} | |||
public void setModel(GrafikModel model) | |||
{ | |||
this.model = model; | |||
} | |||
public void drawLine(Point p, Point p_old) | |||
{ | |||
Graphics2D g2 = (Graphics2D) this.getGraphics(); | |||
Line2D.Double line = new Line2D.Double(p.getX(),p.getY(),p_old.getX(),p_old.getY()); | |||
g2.draw(line); | |||
g2.dispose(); // VERY, VERY WICHTIG | |||
} | |||
public void drawLineG2(Point p, Point p_old, Graphics2D g2) | |||
{ | |||
Line2D.Double line = new Line2D.Double(p.getX(),p.getY(),p_old.getX(),p_old.getY()); | |||
g2.draw(line); | |||
} | |||
@Override | |||
public void paintComponent(Graphics g) | |||
{ | |||
lg.info("repaint"); | |||
if (model == null) | |||
{ | |||
lg.severe("keine Referenz auf Model vorhanden"); | |||
return; | |||
} | |||
super.paintComponent(g); | |||
Graphics2D g2 = (Graphics2D) g; | |||
model.getFigures().forEach(figure -> { | |||
old_punkt = null; | |||
figure.getPunkte().forEach(punkt -> { | |||
if(old_punkt != null) | |||
{ | |||
drawLineG2(punkt, old_punkt, g2); | |||
} | |||
old_punkt = punkt; | |||
}); | |||
}); | |||
} | |||
public void doPrint() | |||
{ | |||
HashPrintRequestAttributeSet printSet = | |||
new HashPrintRequestAttributeSet(); | |||
printSet.add(DialogTypeSelection.NATIVE); | |||
PrinterJob pj = PrinterJob.getPrinterJob(); | |||
pj.setPrintable(this); | |||
// Druckdialog | |||
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 == 1) | |||
{ | |||
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; | |||
} | |||
} | |||
} |