Merge origin/master
Conflicts: src/wuerfelthreads/Start.java src/wuerfelthreads/view/WuerfelView.form src/wuerfelthreads/view/WuerfelView.java
This commit is contained in:
parent
7dd6e6905e
commit
a87fa346f3
@ -11,6 +11,7 @@ import javax.swing.WindowConstants;
|
|||||||
import mvcgrafik.controller.GrafikController;
|
import mvcgrafik.controller.GrafikController;
|
||||||
import mvcgrafik.model.GrafikModel;
|
import mvcgrafik.model.GrafikModel;
|
||||||
import mvcgrafik.view.GrafikView;
|
import mvcgrafik.view.GrafikView;
|
||||||
|
//import mvcgrafik.ohmLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder Class
|
* Builder Class
|
||||||
|
@ -7,9 +7,15 @@
|
|||||||
package mvcgrafik.controller;
|
package mvcgrafik.controller;
|
||||||
|
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
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.IOException;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import mvcgrafik.model.Figure;
|
||||||
import mvcgrafik.model.GrafikModel;
|
import mvcgrafik.model.GrafikModel;
|
||||||
import mvcgrafik.view.GrafikView;
|
import mvcgrafik.view.GrafikView;
|
||||||
|
|
||||||
@ -17,10 +23,12 @@ import mvcgrafik.view.GrafikView;
|
|||||||
*
|
*
|
||||||
* @author le
|
* @author le
|
||||||
*/
|
*/
|
||||||
public class GrafikController implements MouseMotionListener, MouseListener
|
public class GrafikController implements MouseMotionListener, MouseListener, KeyListener
|
||||||
{
|
{
|
||||||
private GrafikView view;
|
private GrafikView view;
|
||||||
private GrafikModel model;
|
private GrafikModel model;
|
||||||
|
private Figure figure;
|
||||||
|
private Point p_old;
|
||||||
|
|
||||||
public GrafikController(GrafikView view, GrafikModel model)
|
public GrafikController(GrafikView view, GrafikModel model)
|
||||||
{
|
{
|
||||||
@ -38,8 +46,11 @@ public class GrafikController implements MouseMotionListener, MouseListener
|
|||||||
public void mouseDragged(MouseEvent evt)
|
public void mouseDragged(MouseEvent evt)
|
||||||
{
|
{
|
||||||
Point p = evt.getPoint();
|
Point p = evt.getPoint();
|
||||||
view.drawPoint(p);
|
if(p_old != null){
|
||||||
model.addPoint(p);
|
view.drawLine(p, p_old);
|
||||||
|
}
|
||||||
|
p_old = p;
|
||||||
|
figure.addPoint(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -50,6 +61,9 @@ public class GrafikController implements MouseMotionListener, MouseListener
|
|||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e)
|
public void mouseClicked(MouseEvent e)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
figure = model.addFigure();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -60,6 +74,7 @@ public class GrafikController implements MouseMotionListener, MouseListener
|
|||||||
@Override
|
@Override
|
||||||
public void mouseReleased(MouseEvent evt)
|
public void mouseReleased(MouseEvent evt)
|
||||||
{
|
{
|
||||||
|
p_old = null;
|
||||||
if (evt.getButton() == MouseEvent.BUTTON3)
|
if (evt.getButton() == MouseEvent.BUTTON3)
|
||||||
{
|
{
|
||||||
view.doPrint();
|
view.doPrint();
|
||||||
@ -75,4 +90,45 @@ public class GrafikController implements MouseMotionListener, MouseListener
|
|||||||
public void mouseExited(MouseEvent e)
|
public void mouseExited(MouseEvent e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyTyped(KeyEvent e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyPressed(KeyEvent e)
|
||||||
|
{
|
||||||
|
if(e.getKeyCode() == KeyEvent.VK_S)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
model.speichereDatei("TEST");
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
Logger.getLogger(GrafikController.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(e.getKeyCode() == KeyEvent.VK_O)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
model.ladeDatei("TEST");
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
Logger.getLogger(GrafikController.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
catch (ClassNotFoundException ex)
|
||||||
|
{
|
||||||
|
Logger.getLogger(GrafikController.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyReleased(KeyEvent e)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
36
src/mvcgrafik/model/Figure.java
Normal file
36
src/mvcgrafik/model/Figure.java
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -25,34 +25,35 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class GrafikModel
|
public class GrafikModel
|
||||||
{
|
{
|
||||||
private ArrayList<Point> punkte;
|
private ArrayList<Figure> figures;
|
||||||
|
|
||||||
public GrafikModel()
|
public GrafikModel()
|
||||||
{
|
{
|
||||||
punkte = new ArrayList<>();
|
figures = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPoint(Point p)
|
public Figure addFigure()
|
||||||
{
|
{
|
||||||
punkte.add(p);
|
figures.add(new Figure());
|
||||||
|
return figures.get(figures.size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Point> getPunkte()
|
public List<Figure> getFigures()
|
||||||
{
|
{
|
||||||
return Collections.unmodifiableList(punkte);
|
return Collections.unmodifiableList(figures);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void speicherePunkte(String dateiname) throws FileNotFoundException, IOException
|
public void speichereDatei(String dateiname) throws FileNotFoundException, IOException
|
||||||
{
|
{
|
||||||
FileOutputStream fos = new FileOutputStream(dateiname);
|
FileOutputStream fos = new FileOutputStream(dateiname);
|
||||||
BufferedOutputStream buffout = new BufferedOutputStream(fos);
|
BufferedOutputStream buffout = new BufferedOutputStream(fos);
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(buffout);
|
ObjectOutputStream oos = new ObjectOutputStream(buffout);
|
||||||
oos.writeObject(punkte);
|
oos.writeObject(figures);
|
||||||
oos.flush();
|
oos.flush();
|
||||||
oos.close();
|
oos.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ladePunkte(String dateiname) throws FileNotFoundException, IOException, ClassNotFoundException
|
public void ladeDatei(String dateiname) throws FileNotFoundException, IOException, ClassNotFoundException
|
||||||
{
|
{
|
||||||
FileInputStream fis = new FileInputStream(dateiname);
|
FileInputStream fis = new FileInputStream(dateiname);
|
||||||
BufferedInputStream buffin = new BufferedInputStream(fis);
|
BufferedInputStream buffin = new BufferedInputStream(fis);
|
||||||
@ -66,7 +67,7 @@ public class GrafikModel
|
|||||||
// {
|
// {
|
||||||
// Fehler ....
|
// Fehler ....
|
||||||
// }
|
// }
|
||||||
punkte = (ArrayList<Point>) ois.readObject();
|
figures = (ArrayList<Figure>) ois.readObject();
|
||||||
ois.close();
|
ois.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import java.awt.Dimension;
|
|||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
import java.awt.geom.Line2D;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.awt.print.PageFormat;
|
import java.awt.print.PageFormat;
|
||||||
import java.awt.print.Printable;
|
import java.awt.print.Printable;
|
||||||
@ -32,6 +33,7 @@ public class GrafikView extends JComponent implements Printable
|
|||||||
private final static Logger lg = Logger.getLogger("mvcGrafik");
|
private final static Logger lg = Logger.getLogger("mvcGrafik");
|
||||||
private Rectangle2D.Float pixel;
|
private Rectangle2D.Float pixel;
|
||||||
private GrafikModel model;
|
private GrafikModel model;
|
||||||
|
private Point old_punkt = null;
|
||||||
|
|
||||||
public GrafikView()
|
public GrafikView()
|
||||||
{
|
{
|
||||||
@ -44,11 +46,12 @@ public class GrafikView extends JComponent implements Printable
|
|||||||
this.model = model;
|
this.model = model;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawPoint(Point p)
|
public void drawLine(Point p, Point p_old)
|
||||||
{
|
{
|
||||||
Graphics2D g2 = (Graphics2D) this.getGraphics();
|
Graphics2D g2 = (Graphics2D) this.getGraphics();
|
||||||
pixel.setFrame(p, EINS);
|
Line2D.Double line = new Line2D.Double(p.getX(),p.getY(),p_old.getX(),p_old.getY());
|
||||||
g2.draw(pixel);
|
// pixel.setFrame(p, EINS);
|
||||||
|
g2.draw(line);
|
||||||
g2.dispose(); // VERY, VERY WICHTIG
|
g2.dispose(); // VERY, VERY WICHTIG
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,11 +66,17 @@ public class GrafikView extends JComponent implements Printable
|
|||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
Graphics2D g2 = (Graphics2D) g;
|
Graphics2D g2 = (Graphics2D) g;
|
||||||
|
|
||||||
for (Point p : model.getPunkte())
|
model.getFigures().forEach(figure -> {
|
||||||
{
|
figure.getPunkte().forEach(punkt -> {
|
||||||
pixel.setFrame(p, EINS);
|
pixel.setFrame(punkt, EINS);
|
||||||
g2.draw(pixel);
|
// g2.draw(pixel);
|
||||||
}
|
if(old_punkt != null)
|
||||||
|
{
|
||||||
|
drawLine(punkt, old_punkt);
|
||||||
|
}
|
||||||
|
old_punkt = punkt;
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doPrint()
|
public void doPrint()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user