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.model.GrafikModel;
|
||||
import mvcgrafik.view.GrafikView;
|
||||
//import mvcgrafik.ohmLogger;
|
||||
|
||||
/**
|
||||
* Builder Class
|
||||
|
@ -7,9 +7,15 @@
|
||||
package mvcgrafik.controller;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
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.view.GrafikView;
|
||||
|
||||
@ -17,10 +23,12 @@ import mvcgrafik.view.GrafikView;
|
||||
*
|
||||
* @author le
|
||||
*/
|
||||
public class GrafikController implements MouseMotionListener, MouseListener
|
||||
public class GrafikController implements MouseMotionListener, MouseListener, KeyListener
|
||||
{
|
||||
private GrafikView view;
|
||||
private GrafikModel model;
|
||||
private Figure figure;
|
||||
private Point p_old;
|
||||
|
||||
public GrafikController(GrafikView view, GrafikModel model)
|
||||
{
|
||||
@ -38,8 +46,11 @@ public class GrafikController implements MouseMotionListener, MouseListener
|
||||
public void mouseDragged(MouseEvent evt)
|
||||
{
|
||||
Point p = evt.getPoint();
|
||||
view.drawPoint(p);
|
||||
model.addPoint(p);
|
||||
if(p_old != null){
|
||||
view.drawLine(p, p_old);
|
||||
}
|
||||
p_old = p;
|
||||
figure.addPoint(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -50,6 +61,9 @@ public class GrafikController implements MouseMotionListener, MouseListener
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e)
|
||||
{
|
||||
|
||||
figure = model.addFigure();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -60,6 +74,7 @@ public class GrafikController implements MouseMotionListener, MouseListener
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent evt)
|
||||
{
|
||||
p_old = null;
|
||||
if (evt.getButton() == MouseEvent.BUTTON3)
|
||||
{
|
||||
view.doPrint();
|
||||
@ -75,4 +90,45 @@ public class GrafikController implements MouseMotionListener, MouseListener
|
||||
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
|
||||
{
|
||||
private ArrayList<Point> punkte;
|
||||
private ArrayList<Figure> figures;
|
||||
|
||||
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);
|
||||
BufferedOutputStream buffout = new BufferedOutputStream(fos);
|
||||
ObjectOutputStream oos = new ObjectOutputStream(buffout);
|
||||
oos.writeObject(punkte);
|
||||
oos.writeObject(figures);
|
||||
oos.flush();
|
||||
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);
|
||||
BufferedInputStream buffin = new BufferedInputStream(fis);
|
||||
@ -66,7 +67,7 @@ public class GrafikModel
|
||||
// {
|
||||
// Fehler ....
|
||||
// }
|
||||
punkte = (ArrayList<Point>) ois.readObject();
|
||||
figures = (ArrayList<Figure>) ois.readObject();
|
||||
ois.close();
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ 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;
|
||||
@ -32,6 +33,7 @@ public class GrafikView extends JComponent implements Printable
|
||||
private final static Logger lg = Logger.getLogger("mvcGrafik");
|
||||
private Rectangle2D.Float pixel;
|
||||
private GrafikModel model;
|
||||
private Point old_punkt = null;
|
||||
|
||||
public GrafikView()
|
||||
{
|
||||
@ -44,11 +46,12 @@ public class GrafikView extends JComponent implements Printable
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public void drawPoint(Point p)
|
||||
public void drawLine(Point p, Point p_old)
|
||||
{
|
||||
Graphics2D g2 = (Graphics2D) this.getGraphics();
|
||||
pixel.setFrame(p, EINS);
|
||||
g2.draw(pixel);
|
||||
Line2D.Double line = new Line2D.Double(p.getX(),p.getY(),p_old.getX(),p_old.getY());
|
||||
// pixel.setFrame(p, EINS);
|
||||
g2.draw(line);
|
||||
g2.dispose(); // VERY, VERY WICHTIG
|
||||
}
|
||||
|
||||
@ -63,11 +66,17 @@ public class GrafikView extends JComponent implements Printable
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
|
||||
for (Point p : model.getPunkte())
|
||||
{
|
||||
pixel.setFrame(p, EINS);
|
||||
g2.draw(pixel);
|
||||
}
|
||||
model.getFigures().forEach(figure -> {
|
||||
figure.getPunkte().forEach(punkt -> {
|
||||
pixel.setFrame(punkt, EINS);
|
||||
// g2.draw(pixel);
|
||||
if(old_punkt != null)
|
||||
{
|
||||
drawLine(punkt, old_punkt);
|
||||
}
|
||||
old_punkt = punkt;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public void doPrint()
|
||||
|
Loading…
x
Reference in New Issue
Block a user