Conflicts: src/wuerfelthreads/Start.java src/wuerfelthreads/view/WuerfelView.form src/wuerfelthreads/view/WuerfelView.javamaster
package mvcgrafik; | package mvcgrafik; | ||||
import javax.swing.JFrame; | import javax.swing.JFrame; | ||||
import javax.swing.JPanel; | |||||
import javax.swing.WindowConstants; | import javax.swing.WindowConstants; | ||||
import mvcgrafik.controller.BtnController; | |||||
import mvcgrafik.controller.GrafikController; | import mvcgrafik.controller.GrafikController; | ||||
import mvcgrafik.model.GrafikModel; | import mvcgrafik.model.GrafikModel; | ||||
import mvcgrafik.view.GrafikMenuView; | import mvcgrafik.view.GrafikMenuView; | ||||
GrafikMenuView view = new GrafikMenuView(); | GrafikMenuView view = new GrafikMenuView(); | ||||
GrafikModel model = new GrafikModel(); | GrafikModel model = new GrafikModel(); | ||||
view.getGrafikView1().setModel(model); | view.getGrafikView1().setModel(model); | ||||
// view.setModel(model); | |||||
GrafikController controller = new GrafikController(view, model); | |||||
GrafikController controller = new GrafikController(view.getGrafikView1(), model); | |||||
BtnController btncontroller = new BtnController(view, model); | |||||
controller.registerEvents(); | controller.registerEvents(); | ||||
btncontroller.registerEvents(); | |||||
view.setSize(800, 600); | view.setSize(800, 600); | ||||
view.setVisible(true); | view.setVisible(true); |
/* | |||||
* 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); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
package mvcgrafik.controller; | package mvcgrafik.controller; | ||||
import java.awt.Point; | import java.awt.Point; | ||||
import java.awt.event.ActionEvent; | |||||
import java.awt.event.ActionListener; | |||||
import java.awt.event.KeyEvent; | |||||
import java.awt.event.KeyListener; | |||||
import java.awt.event.MouseEvent; | import java.awt.event.MouseEvent; | ||||
import java.awt.event.MouseListener; | import java.awt.event.MouseListener; | ||||
import java.awt.event.MouseMotionListener; | import java.awt.event.MouseMotionListener; | ||||
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.logging.Logger; | ||||
import java.util.prefs.Preferences; | |||||
import javax.swing.JFileChooser; | |||||
import mvcgrafik.model.Figure; | import mvcgrafik.model.Figure; | ||||
import mvcgrafik.model.GrafikModel; | import mvcgrafik.model.GrafikModel; | ||||
import mvcgrafik.view.GrafikMenuView; | |||||
import mvcgrafik.logger.OhmLogger; | import mvcgrafik.logger.OhmLogger; | ||||
import mvcgrafik.view.GrafikView; | |||||
/** | /** | ||||
* | * | ||||
* @author le | * @author le | ||||
*/ | */ | ||||
public class GrafikController implements MouseMotionListener, MouseListener, ActionListener | |||||
public class GrafikController implements MouseMotionListener, MouseListener | |||||
{ | { | ||||
private GrafikMenuView view; | |||||
//private GrafikMenuView menuview; | |||||
private GrafikView view; | |||||
private GrafikModel model; | private GrafikModel model; | ||||
private Figure figure; | private Figure figure; | ||||
private Point p_old; | private Point p_old; | ||||
private static Logger lg = OhmLogger.getLogger(); | private static Logger lg = OhmLogger.getLogger(); | ||||
public GrafikController(GrafikMenuView view, GrafikModel model) | |||||
public GrafikController(GrafikView view, GrafikModel model) | |||||
{ | { | ||||
this.view = view; | this.view = view; | ||||
this.model = model; | this.model = model; | ||||
{ | { | ||||
view.addMouseMotionListener(this); | view.addMouseMotionListener(this); | ||||
view.addMouseListener(this); | view.addMouseListener(this); | ||||
view.getBtnOpen().addActionListener(this); | |||||
view.getBtnSafe().addActionListener(this); | |||||
} | } | ||||
@Override | @Override | ||||
Point p = evt.getPoint(); | Point p = evt.getPoint(); | ||||
if(p_old != null){ | if(p_old != null){ | ||||
// view.drawLine(p, p_old); | // view.drawLine(p, p_old); | ||||
view.getGrafikView1().drawLine(p, p_old); | |||||
view.drawLine(p, p_old); | |||||
} | } | ||||
p_old = p; | p_old = p; | ||||
figure.addPoint(p); | figure.addPoint(p); | ||||
if (evt.getButton() == MouseEvent.BUTTON3) | if (evt.getButton() == MouseEvent.BUTTON3) | ||||
{ | { | ||||
// view.doPrint(); | // view.doPrint(); | ||||
view.getGrafikView1().doPrint(); | |||||
view.doPrint(); | |||||
} | } | ||||
} | } | ||||
public void mouseExited(MouseEvent e) | public void mouseExited(MouseEvent e) | ||||
{ | { | ||||
} | } | ||||
@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); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | } | ||||
</NonVisualComponents> | </NonVisualComponents> | ||||
<Properties> | <Properties> | ||||
<Property name="defaultCloseOperation" type="int" value="3"/> | <Property name="defaultCloseOperation" type="int" value="3"/> | ||||
<Property name="title" type="java.lang.String" value="Zeichentool"/> | |||||
</Properties> | </Properties> | ||||
<SyntheticProperties> | <SyntheticProperties> | ||||
<SyntheticProperty name="menuBar" type="java.lang.String" value="jMenuBar1"/> | <SyntheticProperty name="menuBar" type="java.lang.String" value="jMenuBar1"/> | ||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> | <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> | ||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> | <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> | ||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> | <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> | </AuxValues> | ||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/> | <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/> |
public class GrafikMenuView extends javax.swing.JFrame | public class GrafikMenuView extends javax.swing.JFrame | ||||
{ | { | ||||
/** | |||||
* @return the jPanel1 | |||||
*/ | |||||
public javax.swing.JPanel getjPanel1() | |||||
{ | |||||
return jPanel1; | |||||
} | |||||
/** | /** | ||||
* Creates new form GrafikMenuView | * Creates new form GrafikMenuView | ||||
*/ | */ | ||||
jMenu2 = new javax.swing.JMenu(); | jMenu2 = new javax.swing.JMenu(); | ||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); | setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); | ||||
setTitle("Zeichentool"); | |||||
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); | javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); | ||||
jPanel1.setLayout(jPanel1Layout); | jPanel1.setLayout(jPanel1Layout); |
public class GrafikView extends JComponent implements Printable | public class GrafikView extends JComponent implements Printable | ||||
{ | { | ||||
private final static Dimension EINS = new Dimension(1, 1); | private final static Dimension EINS = new Dimension(1, 1); | ||||
private final static Logger lg = Logger.getLogger("mvcGrafik"); | |||||
private static Logger lg = OhmLogger.getLogger(); | |||||
private Rectangle2D.Float pixel; | private Rectangle2D.Float pixel; | ||||
private GrafikModel model; | private GrafikModel model; | ||||
private Point old_punkt = null; | private Point old_punkt = null; | ||||
{ | { | ||||
Graphics2D g2 = (Graphics2D) this.getGraphics(); | Graphics2D g2 = (Graphics2D) this.getGraphics(); | ||||
Line2D.Double line = new Line2D.Double(p.getX(),p.getY(),p_old.getX(),p_old.getY()); | Line2D.Double line = new Line2D.Double(p.getX(),p.getY(),p_old.getX(),p_old.getY()); | ||||
// pixel.setFrame(p, EINS); | |||||
g2.draw(line); | g2.draw(line); | ||||
g2.dispose(); // VERY, VERY WICHTIG | 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 | @Override | ||||
public void paintComponent(Graphics g) | public void paintComponent(Graphics g) | ||||
{ | { | ||||
model.getFigures().forEach(figure -> { | model.getFigures().forEach(figure -> { | ||||
old_punkt = null; | old_punkt = null; | ||||
figure.getPunkte().forEach(punkt -> { | figure.getPunkte().forEach(punkt -> { | ||||
// pixel.setFrame(punkt, EINS); | |||||
// g2.draw(pixel); | |||||
if(old_punkt != null) | if(old_punkt != null) | ||||
{ | { | ||||
drawLine(punkt, old_punkt); | |||||
drawLineG2(punkt, old_punkt, g2); | |||||
} | } | ||||
old_punkt = punkt; | old_punkt = punkt; | ||||
}); | }); | ||||
if (pageIndex == 1) | if (pageIndex == 1) | ||||
{ | { | ||||
g2p.translate(pf.getImageableX(), pf.getImageableY()); | g2p.translate(pf.getImageableX(), pf.getImageableY()); | ||||
g2p.scale(pf.getImageableWidth()/pf.getWidth(), | |||||
pf.getImageableHeight() / pf.getHeight()); | |||||
g2p.scale(pf.getImageableWidth()/this.getWidth(), | |||||
pf.getImageableHeight() / this.getHeight()); | |||||
super.print(g2p); | super.print(g2p); | ||||
return Printable.PAGE_EXISTS; | return Printable.PAGE_EXISTS; | ||||
} | } |