Browse Source

Merge origin/master

Conflicts:
	src/wuerfelthreads/Start.java
	src/wuerfelthreads/view/WuerfelView.form
	src/wuerfelthreads/view/WuerfelView.java
master
BakeOrDie 4 years ago
parent
commit
a87fa346f3

+ 1
- 0
src/mvcgrafik/Start.java View File

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

+ 59
- 3
src/mvcgrafik/controller/GrafikController.java View File

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;


* *
* @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)
{ {
public void mouseDragged(MouseEvent evt) public void mouseDragged(MouseEvent evt)
{ {
Point p = evt.getPoint(); 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 @Override
@Override @Override
public void mouseClicked(MouseEvent e) public void mouseClicked(MouseEvent e)
{ {
figure = model.addFigure();
} }


@Override @Override
@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();
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
- 0
src/mvcgrafik/model/Figure.java View File

/*
* 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);
}
}

+ 11
- 10
src/mvcgrafik/model/GrafikModel.java View File

*/ */
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);
// { // {
// Fehler .... // Fehler ....
// } // }
punkte = (ArrayList<Point>) ois.readObject();
figures = (ArrayList<Figure>) ois.readObject();
ois.close(); ois.close();
} }

+ 17
- 8
src/mvcgrafik/view/GrafikView.java View File

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;
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()
{ {
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);
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 g2.dispose(); // VERY, VERY WICHTIG
} }


super.paintComponent(g); super.paintComponent(g);
Graphics2D g2 = (Graphics2D) 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() public void doPrint()

Loading…
Cancel
Save