Saven werkt van guus

This commit is contained in:
Yorick
2015-04-07 13:12:02 +02:00
parent 5a9c3f259a
commit ea7ecfcd56
17 changed files with 1163 additions and 98 deletions
+92 -40
View File
@@ -21,6 +21,7 @@ import java.util.Iterator;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import Agenda.Agenda;
import Listeners.Mouse;
import Listeners.MouseMotion;
import Listeners.MouseWheel;
@@ -44,6 +45,7 @@ public class Panel extends JPanel
private ArrayList<BufferedImage> panelInfo = new ArrayList<BufferedImage>();
// private ArrayList<Object> panelTypes = new ArrayList<Object>();
ArrayList<Visitor> visitors = new ArrayList<>();
ArrayList<DrawObject> objects = new ArrayList<>();
ArrayList<Path> paths = new ArrayList<>();
@@ -54,24 +56,25 @@ public class Panel extends JPanel
Point2D cameraPoint = new Point2D.Double(getWidth() / 2, getHeight() / 2);
float cameraScale = 1;
PropertiesPanel pp;
Agenda agenda;
Point2D lastClickPosition = new Point(0, 0);
Point lastMousePosition = new Point(0, 0);
Point2D selectionPosition = new Point(0,0);
Point2D selectionPosition = new Point(0, 0);
Images images = new Images();
// how to nieuwe dingen aan het panel toe te voegen:
// maak bufferedimage global aan, voeg er een image aan toe, en voeg de
// image aan panelInfo toe en het object aan panelTypes.
// en maak een case statement die een new Object returnt in
// createNewDrawObject.
public Point2D getSelectionPosition() {
public Point2D getSelectionPosition()
{
return selectionPosition;
}
public void setSelectionPosition(Point2D selectionPosition) {
public void setSelectionPosition(Point2D selectionPosition)
{
this.selectionPosition = selectionPosition;
}
@@ -88,7 +91,8 @@ public class Panel extends JPanel
pathImage = ImageIO.read(new File("images/pathIcon.png"));
wallImage = ImageIO.read(new File("images/wallIcon.png"));
foodImage = ImageIO.read(new File("images/foodIcon.png"));
} catch (IOException e)
}
catch (IOException e)
{
e.printStackTrace();
}
@@ -98,6 +102,8 @@ public class Panel extends JPanel
panelInfo.add(pathImage);
panelInfo.add(wallImage);
panelInfo.add(foodImage);
agenda = new Agenda();
panelInfox = 0;
panelInfoy = 0;
@@ -152,6 +158,11 @@ public class Panel extends JPanel
objects.add(dragObject);
}
public void addVisitors()
{
visitors.add(new Visitor("visitor", new Point(100, 300), agenda, objects));
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
@@ -178,8 +189,9 @@ public class Panel extends JPanel
BasicStroke stroke = new BasicStroke(10);
g2.setStroke(stroke);
for(Path path : paths) {
for (Path path : paths)
{
path.draw(g2);
}
for (DrawObject o : objects)
@@ -187,14 +199,15 @@ public class Panel extends JPanel
o.draw(g2);
}
g2.setTransform(oldTransform);
if(currentPath != null) { //Display text while in path making modes.
if (currentPath != null)
{ // Display text while in path making modes.
g2.setColor(Color.WHITE);
g2.setFont(new Font("Verdana",Font.ITALIC,25));
g2.drawString("Press enter to finish the path.",20,185);
g2.setFont(new Font("Verdana", Font.ITALIC, 25));
g2.drawString("Press enter to finish the path.", 20, 185);
}
g2.setClip(null);
}
public AffineTransform getCamera()
@@ -210,7 +223,8 @@ public class Panel extends JPanel
try
{
return getCamera().inverseTransform(point, null);
} catch (NoninvertibleTransformException e1)
}
catch (NoninvertibleTransformException e1)
{
e1.printStackTrace();
}
@@ -272,6 +286,11 @@ public class Panel extends JPanel
this.lastClickPosition = lastClickPosition;
}
public void clearObjects()
{
objects.clear();
}
public Point getLastMousePosition()
{
return lastMousePosition;
@@ -354,7 +373,9 @@ public class Panel extends JPanel
/**
* Remove a DrawObject from the list.
* @param o - the DrawObject you want to remove from the list.
*
* @param o
* - the DrawObject you want to remove from the list.
*/
public void removeObject(DrawObject o)
{
@@ -370,61 +391,77 @@ public class Panel extends JPanel
repaint();
}
}
public void clearObjectSelection() {
for(DrawObject o : objects) {
public void clearObjectSelection()
{
for (DrawObject o : objects)
{
o.setSelected(false);
}
}
public void checkCollision() {
public void checkCollision()
{
boolean collision = false;
for(DrawObject o : getObjects()) {
if(getSelectedObject().collision(o) && o != getSelectedObject()) {
for (DrawObject o : getObjects())
{
if (getSelectedObject().collision(o) && o != getSelectedObject())
{
collision = true;
getSelectedObject().setRectangleColor(Color.RED);
break;
}
if(!collision)
if (!collision)
getSelectedObject().setRectangleColor(Color.BLACK);
}
}
/**
* Begin making a new path.
*/
public void startPath() {
public void startPath()
{
setClickedOption("Path");
currentPath = new Path();
paths.add(currentPath);
pp.setSelectedPath(currentPath);
}
/**
* Get the current selected Path.
*
* @return - the selected Path.
*/
public Path getCurrentPath() {
public Path getCurrentPath()
{
return currentPath;
}
/**
* Set the selected Path object.
* @param path - the selected Path object.
*
* @param path
* - the selected Path object.
*/
public void setcurrentPath(Path path) {
public void setcurrentPath(Path path)
{
currentPath = path;
pp.setSelectedPath(currentPath);
}
/**
* Checks if the point is contained in one of the path's.
* @param point - The point to check for.
*
* @param point
* - The point to check for.
* @return if the point is contained in one of the path's.
*/
public boolean checkPath(Point2D point) {
for(Path path : paths) {
if(path.containsPoint(point)) {
public boolean checkPath(Point2D point)
{
for (Path path : paths)
{
if (path.containsPoint(point))
{
setcurrentPath(path);
setClickedOption("Path");
return true;
@@ -432,15 +469,20 @@ public class Panel extends JPanel
}
return false;
}
/**
* Remove a path from the list.
* @param path - the path you want to remove from the list.
*
* @param path
* - the path you want to remove from the list.
*/
public void removePath(Path path) {
public void removePath(Path path)
{
Iterator<Path> it = paths.iterator();
while(it.hasNext()) {
if(it.next().equals(path)) {
while (it.hasNext())
{
if (it.next().equals(path))
{
pp.clearSelected();
setClickedOption("drag");
currentPath = null;
@@ -449,4 +491,14 @@ public class Panel extends JPanel
repaint();
}
}
public Agenda getAgenda()
{
return agenda;
}
public void setAgenda(Agenda agenda)
{
this.agenda = agenda;
}
}