laatste versie
This commit is contained in:
+17
-1
@@ -2,24 +2,35 @@ package Applicatie;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import Objects.DrawObject;
|
||||
|
||||
public class Action
|
||||
{
|
||||
|
||||
private Point2D position;
|
||||
private int starttime;
|
||||
private int duration;
|
||||
private DrawObject target;
|
||||
private Waypoint waypoint;
|
||||
|
||||
public Action(Point2D position, int starttime, int duration)
|
||||
public Action(Point2D position, int starttime, int duration, DrawObject tar, Waypoint waypoint)
|
||||
{
|
||||
this.position = position;
|
||||
this.starttime = starttime;
|
||||
this.duration = duration;
|
||||
this.target = tar;
|
||||
this.waypoint = waypoint;
|
||||
}
|
||||
|
||||
public Point2D getPosition()
|
||||
{
|
||||
return position;
|
||||
}
|
||||
|
||||
public DrawObject getTargetObject()
|
||||
{
|
||||
return target;
|
||||
}
|
||||
|
||||
public int getStartTime()
|
||||
{
|
||||
@@ -35,4 +46,9 @@ public class Action
|
||||
{
|
||||
return duration;
|
||||
}
|
||||
|
||||
public Waypoint getWaypoint(){
|
||||
return waypoint;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,10 +26,11 @@ public class ControlPanel extends JPanel
|
||||
super();
|
||||
BoxLayout box = new BoxLayout(this, BoxLayout.X_AXIS);
|
||||
setLayout(box);
|
||||
|
||||
setPreferredSize(new Dimension(0,50));
|
||||
setBorder(BorderFactory.createLineBorder(new Color(180, 180, 180)));
|
||||
setBackground(new Color(220, 220, 220));
|
||||
|
||||
setFocusable(false);
|
||||
|
||||
JPanel simulatorPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
simulatorPanel.setPreferredSize(new Dimension(350,50));
|
||||
@@ -41,6 +42,7 @@ public class ControlPanel extends JPanel
|
||||
simulatorPanel.add(simulatorLabel);
|
||||
|
||||
JButton playButton = new JButton("Play");
|
||||
playButton.setFocusable(false);
|
||||
playButton.setFont(new Font("Segoe UI", Font.PLAIN, 20));
|
||||
playButton.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e)
|
||||
@@ -51,6 +53,7 @@ public class ControlPanel extends JPanel
|
||||
simulatorPanel.add(playButton);
|
||||
|
||||
JButton pauseButton = new JButton("Pause");
|
||||
pauseButton.setFocusable(false);
|
||||
pauseButton.setFont(new Font("Segoe UI", Font.PLAIN, 20));
|
||||
pauseButton.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e)
|
||||
@@ -61,6 +64,7 @@ public class ControlPanel extends JPanel
|
||||
simulatorPanel.add(pauseButton);
|
||||
|
||||
JButton stopButton = new JButton("Stop");
|
||||
stopButton.setFocusable(false);
|
||||
stopButton.setFont(new Font("Segoe UI", Font.PLAIN, 20));
|
||||
stopButton.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e)
|
||||
@@ -83,6 +87,7 @@ public class ControlPanel extends JPanel
|
||||
timePanel.add(timeLabel);
|
||||
|
||||
JButton dateButton = new JButton("Pick Date");
|
||||
dateButton.setFocusable(false);
|
||||
dateButton.setFont(new Font("Segoe UI", Font.PLAIN, 20));
|
||||
dateButton.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e)
|
||||
@@ -105,11 +110,12 @@ public class ControlPanel extends JPanel
|
||||
peoplePanel.add(peopleLabel);
|
||||
|
||||
JButton peopleButton = new JButton("Set People");
|
||||
peopleButton.setFocusable(false);
|
||||
peopleButton.setFont(new Font("Segoe UI", Font.PLAIN, 20));
|
||||
peopleButton.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
p.addVisitors(1);
|
||||
p.addVisitors();
|
||||
}
|
||||
});
|
||||
peoplePanel.add(peopleButton);
|
||||
|
||||
+13
-13
@@ -28,7 +28,7 @@ public class MenuBar extends JMenuBar
|
||||
});
|
||||
file.add(item);
|
||||
|
||||
JMenuItem agenda = new JMenuItem("Open Planner");
|
||||
JMenuItem agenda = new JMenuItem("Open Agenda");
|
||||
agenda.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
@@ -38,17 +38,7 @@ public class MenuBar extends JMenuBar
|
||||
});
|
||||
file.add(agenda);
|
||||
|
||||
item = new JMenuItem("Load agenda");
|
||||
item.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
w.getPanel().agenda.loadAgenda();
|
||||
}
|
||||
});
|
||||
file.add(item);
|
||||
|
||||
item = new JMenuItem("Load terrain");
|
||||
item = new JMenuItem("Open");
|
||||
item.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
@@ -58,7 +48,7 @@ public class MenuBar extends JMenuBar
|
||||
});
|
||||
file.add(item);
|
||||
|
||||
item = new JMenuItem("Save terrain");
|
||||
item = new JMenuItem("Save");
|
||||
item.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
@@ -70,6 +60,16 @@ public class MenuBar extends JMenuBar
|
||||
|
||||
file.addSeparator();
|
||||
|
||||
item = new JMenuItem("Load agenda");
|
||||
item.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
w.getPanel().agenda.loadAgenda();
|
||||
}
|
||||
});
|
||||
file.add(item);
|
||||
|
||||
item = new JMenuItem("Agenda");
|
||||
item.addActionListener(new ActionListener()
|
||||
{
|
||||
|
||||
@@ -23,7 +23,7 @@ import javax.swing.JTextField;
|
||||
@SuppressWarnings("serial")
|
||||
public class NewWorldPanel extends JFrame {
|
||||
|
||||
BufferedImage grass,sand,selectedImage;
|
||||
BufferedImage grass,sand,grass2, sand2,stone, selectedImage;
|
||||
|
||||
public NewWorldPanel(Panel topPanel) {
|
||||
super("New World");
|
||||
@@ -32,13 +32,16 @@ public class NewWorldPanel extends JFrame {
|
||||
|
||||
try {
|
||||
grass = ImageIO.read(new File("images/grassIcon.jpg"));
|
||||
sand = ImageIO.read(new File("images/sand.jpg"));
|
||||
sand = ImageIO.read(new File("images/sandIcon.jpg"));
|
||||
grass2 = ImageIO.read(new File("images/grassIcon2.png"));
|
||||
sand2 = ImageIO.read(new File("images/sandIcon2.jpg"));
|
||||
stone = ImageIO.read(new File("images/stoneIcon.jpg"));
|
||||
selectedImage = grass;
|
||||
}
|
||||
catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String[] terrains = {"Grass", "Sand"};
|
||||
String[] terrains = {"Grass", "Grass 2","Sand", "Sand 2", "Stone"};
|
||||
JPanel mainPanel = new JPanel(new BorderLayout());
|
||||
JButton button;
|
||||
JLabel label;
|
||||
@@ -88,8 +91,17 @@ public class NewWorldPanel extends JFrame {
|
||||
selectedImage = grass;
|
||||
break;
|
||||
case 1:
|
||||
selectedImage = grass2;
|
||||
break;
|
||||
case 2:
|
||||
selectedImage = sand;
|
||||
break;
|
||||
case 3:
|
||||
selectedImage = sand2;
|
||||
break;
|
||||
case 4:
|
||||
selectedImage = stone;
|
||||
break;
|
||||
}
|
||||
imageLabel.setIcon(new ImageIcon(selectedImage));
|
||||
}
|
||||
|
||||
+91
-46
@@ -32,10 +32,10 @@ import Agenda.AgendaStage;
|
||||
import Listeners.Mouse;
|
||||
import Listeners.MouseMotion;
|
||||
import Listeners.MouseWheel;
|
||||
import Listeners.WindowFocusListener;
|
||||
import Objects.DrawObject;
|
||||
import Objects.Entrance;
|
||||
import Objects.Food;
|
||||
import Objects.OldPath;
|
||||
import Objects.Path;
|
||||
import Objects.Stage;
|
||||
import Objects.Toilet;
|
||||
@@ -45,7 +45,7 @@ import Objects.Wall;
|
||||
public class Panel extends JPanel implements ActionListener
|
||||
{
|
||||
|
||||
BufferedImage grass, sand;
|
||||
BufferedImage grass, grass2, sand, sand2, stone;
|
||||
BufferedImage background;
|
||||
BufferedImage podiumImage, toiletImage, entranceImage, pathImage, wallImage, foodImage, waypointImage;
|
||||
|
||||
@@ -61,8 +61,8 @@ public class Panel extends JPanel implements ActionListener
|
||||
private DrawObject selectedObject;
|
||||
private String clickedOption = "drag";
|
||||
private Path currentPath;
|
||||
private int width = 1920;
|
||||
private int height = 1080;
|
||||
private static int width = 1920;
|
||||
private static int height = 1080;
|
||||
|
||||
Point2D cameraPoint = new Point2D.Double(getWidth() / 2, getHeight() / 2);
|
||||
float cameraScale = 1;
|
||||
@@ -73,7 +73,7 @@ public class Panel extends JPanel implements ActionListener
|
||||
Point lastMousePosition = new Point(0, 0);
|
||||
Point2D selectionPosition = new Point(0, 0);
|
||||
Images images = new Images();
|
||||
javax.swing.Timer t;
|
||||
Timer t;
|
||||
|
||||
SimpleDateFormat formatter;
|
||||
GregorianCalendar date;
|
||||
@@ -108,13 +108,16 @@ public class Panel extends JPanel implements ActionListener
|
||||
try
|
||||
{
|
||||
grass = ImageIO.read(new File("images/grass.jpg"));
|
||||
grass2 = ImageIO.read(new File("images/grass2.png"));
|
||||
sand = ImageIO.read(new File("images/sand.jpg"));
|
||||
sand2 = ImageIO.read(new File("images/sand2.jpg"));
|
||||
stone = ImageIO.read(new File("images/stone.jpg"));
|
||||
podiumImage = ImageIO.read(new File("images/stageIcon.png"));
|
||||
toiletImage = ImageIO.read(new File("images/wcIcon.png"));
|
||||
entranceImage = ImageIO.read(new File("images/entranceIcon.png"));
|
||||
wallImage = ImageIO.read(new File("images/wallIcon.png"));
|
||||
foodImage = ImageIO.read(new File("images/foodIcon.png"));
|
||||
waypointImage = ImageIO.read(new File("images/waypoint.png"));
|
||||
waypointImage = ImageIO.read(new File("images/waypointIcon.png"));
|
||||
background = grass;
|
||||
}
|
||||
catch (IOException e)
|
||||
@@ -143,6 +146,8 @@ public class Panel extends JPanel implements ActionListener
|
||||
addMouseMotionListener(new MouseMotion(this));
|
||||
|
||||
addMouseWheelListener(new MouseWheel(this));
|
||||
|
||||
addFocusListener(new WindowFocusListener(this));
|
||||
t = new Timer(1000 / 10, this);
|
||||
}
|
||||
|
||||
@@ -162,23 +167,26 @@ public class Panel extends JPanel implements ActionListener
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
ArrayList<AgendaStage> stages = agenda.getStages();
|
||||
Object[] s = new Object[stages.size()];
|
||||
AgendaStage stage = null;
|
||||
if (stages.size() != 0) {
|
||||
for (int i = 0; i < stages.size(); i++) {
|
||||
s[i] = stages.get(i);
|
||||
}
|
||||
ArrayList<AgendaStage> stages = agenda.getStages();
|
||||
Object[] s = new Object[stages.size()];
|
||||
AgendaStage stage = null;
|
||||
if (stages.size() != 0)
|
||||
{
|
||||
for (int i = 0; i < stages.size(); i++)
|
||||
{
|
||||
s[i] = stages.get(i);
|
||||
}
|
||||
|
||||
stage = (AgendaStage) JOptionPane.showInputDialog(null,
|
||||
"Select the right Stage", "Select Stage",
|
||||
JOptionPane.PLAIN_MESSAGE, null, s, "stage");
|
||||
}
|
||||
if (stage != null){
|
||||
return new Stage(null, stage);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
stage = (AgendaStage) JOptionPane.showInputDialog(null, "Select the right Stage", "Select Stage", JOptionPane.PLAIN_MESSAGE, null, s, "stage");
|
||||
}
|
||||
if (stage != null)
|
||||
{
|
||||
return new Stage(null, stage);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
case 1:
|
||||
return new Toilet(null);
|
||||
case 2:
|
||||
@@ -187,7 +195,7 @@ public class Panel extends JPanel implements ActionListener
|
||||
return new Wall(null);
|
||||
case 4:
|
||||
return new Food(null);
|
||||
case 6:
|
||||
case 5:
|
||||
return new Waypoint(null);
|
||||
default:
|
||||
return null;
|
||||
@@ -203,37 +211,47 @@ public class Panel extends JPanel implements ActionListener
|
||||
{
|
||||
waypoints.add(w);
|
||||
}
|
||||
|
||||
public Waypoint getWaypoint(int i)
|
||||
{
|
||||
for(Waypoint w : waypoints)
|
||||
{
|
||||
if(w.getSelf() == i)
|
||||
{
|
||||
return w;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ArrayList<Waypoint> getWaypoints()
|
||||
{
|
||||
return waypoints;
|
||||
}
|
||||
|
||||
public int getNextTarget()
|
||||
{
|
||||
int last = 0;
|
||||
for (Waypoint w : waypoints)
|
||||
{
|
||||
System.out.println(waypoints);
|
||||
if (w.getSelf() > last)
|
||||
{
|
||||
last = w.getSelf();
|
||||
}
|
||||
}
|
||||
System.out.println(last);
|
||||
return last;
|
||||
}
|
||||
|
||||
public void addVisitors()
|
||||
{
|
||||
visitors.add(new Visitor("visitor", new Point(100, 300), agenda, objects, date));
|
||||
ArrayList<DrawObject> entrances = new ArrayList<>();
|
||||
for(DrawObject object : objects) {
|
||||
if(object instanceof Entrance) {
|
||||
entrances.add(object);
|
||||
}
|
||||
}
|
||||
if(!entrances.isEmpty()) {
|
||||
DrawObject entrance = entrances.get((int) Math.floor(Math.random()*entrances.size()));
|
||||
Point point = new Point((int)entrance.getPosition().getX(),(int)entrance.getPosition().getY());
|
||||
visitors.add(new Visitor("visitor",point, agenda, objects, waypoints, date));
|
||||
}
|
||||
else {
|
||||
JOptionPane.showMessageDialog(this, "You don't have an entrance");
|
||||
}
|
||||
}
|
||||
|
||||
public void addVisitors(int count)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
visitors.add(new Visitor("visitor", new Point(100, 300), agenda, objects, date));
|
||||
addVisitors();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,7 +259,7 @@ public class Panel extends JPanel implements ActionListener
|
||||
{
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
g2.setClip(new Rectangle2D.Double(0, 0, getWidth(), 300));
|
||||
g2.setClip(new Rectangle2D.Double(0, 0, getWidth(), 150));
|
||||
Stroke old = g2.getStroke();
|
||||
g2.setStroke(new BasicStroke(10));
|
||||
g2.drawLine(0, 150, getWidth(), 150);
|
||||
@@ -501,6 +519,9 @@ public class Panel extends JPanel implements ActionListener
|
||||
*/
|
||||
public void startPath()
|
||||
{
|
||||
pp.clearSelected();
|
||||
setSelectedObject(null);
|
||||
clearObjectSelection();
|
||||
setClickedOption("Path");
|
||||
currentPath = new Path();
|
||||
paths.add(currentPath);
|
||||
@@ -542,13 +563,27 @@ public class Panel extends JPanel implements ActionListener
|
||||
{
|
||||
if (path.containsPoint(point))
|
||||
{
|
||||
|
||||
setcurrentPath(path);
|
||||
setClickedOption("Path");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Path getClickedPath(Point2D point)
|
||||
{
|
||||
for (Path path : paths)
|
||||
{
|
||||
if (path.containsPoint(point))
|
||||
{
|
||||
return path;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a path from the list.
|
||||
@@ -581,13 +616,13 @@ public class Panel extends JPanel implements ActionListener
|
||||
{
|
||||
this.agenda = agenda;
|
||||
}
|
||||
|
||||
public int getFieldWidth()
|
||||
|
||||
public static int getFieldWidth()
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getFieldHeight()
|
||||
|
||||
public static int getFieldHeight()
|
||||
{
|
||||
return height;
|
||||
}
|
||||
@@ -607,7 +642,7 @@ public class Panel extends JPanel implements ActionListener
|
||||
|
||||
for (Visitor v : visitors)
|
||||
{
|
||||
v.update(objects, currentTime, visitors, paths);
|
||||
v.update(objects, currentTime, visitors, paths, this);
|
||||
}
|
||||
repaint();
|
||||
|
||||
@@ -641,8 +676,18 @@ public class Panel extends JPanel implements ActionListener
|
||||
background = grass;
|
||||
break;
|
||||
case 1:
|
||||
background = grass2;
|
||||
break;
|
||||
case 2:
|
||||
background = sand;
|
||||
break;
|
||||
case 3:
|
||||
background = sand2;
|
||||
break;
|
||||
case 4:
|
||||
background = stone;
|
||||
break;
|
||||
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package Applicatie;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import Objects.Path;
|
||||
|
||||
public class PathPopup extends JFrame
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
public PathPopup(Path p, Panel panel)
|
||||
{
|
||||
super("Artist editscreen!");
|
||||
setDefaultCloseOperation(HIDE_ON_CLOSE);
|
||||
JPanel content = new JPanel(new BorderLayout());
|
||||
JPanel south = new JPanel(new FlowLayout());
|
||||
JPanel center = new JPanel(new GridLayout(5, 2));
|
||||
content.add(south, BorderLayout.SOUTH);
|
||||
content.add(center, BorderLayout.CENTER);
|
||||
|
||||
JPanel panel1 = new JPanel();
|
||||
JLabel name = new JLabel("Path");
|
||||
panel1.add(name);
|
||||
center.add(panel1);
|
||||
|
||||
JTextField tf = new JTextField(5);
|
||||
center.add(tf);
|
||||
|
||||
JButton edit = new JButton("Done");
|
||||
edit.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
p.addWaypoint(Integer.valueOf(tf.getText()), panel);
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
south.add(edit);
|
||||
|
||||
setContentPane(content);
|
||||
setVisible(true);
|
||||
setSize(500, 320);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -56,6 +56,7 @@ public class PropertiesPanel extends JPanel
|
||||
setPreferredSize(new Dimension(200, 0));
|
||||
setBorder(BorderFactory.createLineBorder(new Color(180, 180, 180)));
|
||||
setBackground(new Color(220, 220, 220));
|
||||
setFocusable(false);
|
||||
|
||||
// NAME "PROPERTIES"
|
||||
JPanel propPanel = new JPanel();
|
||||
@@ -97,6 +98,7 @@ public class PropertiesPanel extends JPanel
|
||||
// BUTTONS ROW 1
|
||||
JPanel row1ButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
JButton deleteButton = new JButton("Delete");
|
||||
deleteButton.setFocusable(false);
|
||||
deleteButton.setFont(new Font("Segoe UI", Font.PLAIN, 20));
|
||||
deleteButton.addActionListener(new ActionListener()
|
||||
{
|
||||
@@ -111,6 +113,7 @@ public class PropertiesPanel extends JPanel
|
||||
}
|
||||
});
|
||||
JButton areaButton = new JButton("Area");
|
||||
areaButton.setFocusable(false);
|
||||
areaButton.setFont(new Font("Segoe UI", Font.PLAIN, 20));
|
||||
areaButton.addActionListener(new ActionListener()
|
||||
{
|
||||
@@ -330,7 +333,8 @@ public class PropertiesPanel extends JPanel
|
||||
{
|
||||
locationXField.setBackground(Color.WHITE);
|
||||
double xpos = Double.parseDouble(locationXField.getText());
|
||||
selectedObject.setPosition(new Point2D.Double(xpos, selectedObject.getPosition().getY()));
|
||||
selectedObject.setPosition(new Point2D.Double(xpos, selectedObject.getPosition().getY()), true);
|
||||
update();
|
||||
p.update();
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
@@ -369,8 +373,8 @@ public class PropertiesPanel extends JPanel
|
||||
{
|
||||
locationYField.setBackground(Color.WHITE);
|
||||
double ypos = Double.parseDouble(locationYField.getText());
|
||||
selectedObject.setPosition(new Point2D.Double(selectedObject.getPosition().getX(), ypos));
|
||||
;
|
||||
selectedObject.setPosition(new Point2D.Double(selectedObject.getPosition().getX(), ypos), true);
|
||||
update();
|
||||
p.update();
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
|
||||
@@ -23,7 +23,7 @@ public class SaveLoad {
|
||||
fileChooser.setFileFilter(new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File pathname) {
|
||||
if(pathname.isFile() && pathname.getName().endsWith(".ter"))
|
||||
if(pathname.isFile() && pathname.getName().endsWith(".agn"))
|
||||
{
|
||||
return true;
|
||||
}else if(pathname.isDirectory()){return true;}else{return false;}
|
||||
@@ -31,7 +31,7 @@ public class SaveLoad {
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return ".ter";
|
||||
return ".agn";
|
||||
}
|
||||
|
||||
});
|
||||
@@ -41,9 +41,9 @@ public class SaveLoad {
|
||||
if(userSelection == JFileChooser.APPROVE_OPTION)
|
||||
{
|
||||
File file = fileChooser.getSelectedFile();
|
||||
if(!file.getName().endsWith(".ter"))
|
||||
if(!file.getName().endsWith(".agn"))
|
||||
{
|
||||
file = new File(file.getAbsolutePath() + ".ter");
|
||||
file = new File(file.getAbsolutePath() + ".agn");
|
||||
}
|
||||
|
||||
if(file.exists())
|
||||
@@ -82,7 +82,7 @@ public class SaveLoad {
|
||||
fileChooser.setFileFilter(new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File pathname) {
|
||||
if(pathname.isFile() && pathname.getName().endsWith(".ter"))
|
||||
if(pathname.isFile() && pathname.getName().endsWith(".agn"))
|
||||
{
|
||||
return true;
|
||||
}else if(pathname.isDirectory()){return true;}else{return false;}
|
||||
@@ -90,7 +90,7 @@ public class SaveLoad {
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return ".ter";
|
||||
return ".agn";
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
+220
-81
@@ -2,7 +2,6 @@ package Applicatie;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.AffineTransform;
|
||||
@@ -16,10 +15,12 @@ import java.util.Map;
|
||||
import Agenda.Agenda;
|
||||
import Agenda.Event;
|
||||
import Objects.DrawObject;
|
||||
import Objects.Entrance;
|
||||
import Objects.Path;
|
||||
import Objects.Stage;
|
||||
|
||||
public class Visitor {
|
||||
public class Visitor
|
||||
{
|
||||
|
||||
Point2D position;
|
||||
double rotation;
|
||||
@@ -29,35 +30,38 @@ public class Visitor {
|
||||
ArrayList<Action> actions;
|
||||
Agenda agenda;
|
||||
ArrayList<DrawObject> objects;
|
||||
ArrayList<Waypoint> waypoints;
|
||||
GregorianCalendar date;
|
||||
char target;
|
||||
int target;
|
||||
int finalTarget;
|
||||
|
||||
public Visitor(String filename, Point2D position, Agenda agenda,
|
||||
ArrayList<DrawObject> objects, GregorianCalendar date) {
|
||||
public Visitor(String filename, Point2D position, Agenda agenda, ArrayList<DrawObject> objects, ArrayList<Waypoint> waypoints, GregorianCalendar date)
|
||||
{
|
||||
this.position = position;
|
||||
this.filename = filename;
|
||||
this.rotation = 0;
|
||||
this.date = date;
|
||||
this.speed = 1 + Math.random() * 4;
|
||||
this.waypoints = waypoints;
|
||||
this.date = date;
|
||||
scale = 1;
|
||||
actions = new ArrayList<Action>();
|
||||
this.agenda = agenda;
|
||||
this.objects = objects;
|
||||
fillActions();
|
||||
target = 'z';
|
||||
|
||||
for (Action a : actions){
|
||||
System.out.println(a.getStartTime());
|
||||
}
|
||||
System.out.println(actions.size());
|
||||
target = 1;
|
||||
finalTarget = 4;
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g2) {
|
||||
public void draw(Graphics2D g2)
|
||||
{
|
||||
AffineTransform tx = getTransform();
|
||||
Image image = Images.getImage(filename);
|
||||
g2.drawImage(image, tx, null);
|
||||
}
|
||||
|
||||
private AffineTransform getTransform() {
|
||||
private AffineTransform getTransform()
|
||||
{
|
||||
Image image = Images.getImage(filename);
|
||||
AffineTransform tx = new AffineTransform();
|
||||
tx.scale(scale, scale);
|
||||
@@ -66,48 +70,151 @@ public class Visitor {
|
||||
return tx;
|
||||
}
|
||||
|
||||
public void update(ArrayList<DrawObject> objects, int currentTime,
|
||||
ArrayList<Visitor> visitors, ArrayList<Path> paths) {
|
||||
Point2D target = new Point(500, 500);
|
||||
for (Action a : actions) {
|
||||
if (currentTime >= a.getStartTime()
|
||||
&& currentTime < a.getStoptime()) {
|
||||
target = a.getPosition();
|
||||
public DrawObject getEntrance()
|
||||
{
|
||||
for (DrawObject o : objects)
|
||||
{
|
||||
if (o instanceof Entrance)
|
||||
{
|
||||
return o;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void update(ArrayList<DrawObject> objects, int currentTime, ArrayList<Visitor> visitors, ArrayList<Path> paths, Panel panel)
|
||||
{
|
||||
DrawObject target = getEntrance();
|
||||
for (Action a : actions)
|
||||
{
|
||||
if (currentTime >= a.getStartTime() && currentTime < a.getStoptime())
|
||||
{
|
||||
target = a.getTargetObject();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
moveToTarget(target, objects, visitors, paths);
|
||||
// moveToTarget(target, objects, visitors, paths);
|
||||
move(target, panel);
|
||||
}
|
||||
|
||||
public void moveToTarget(Point2D target, ArrayList<DrawObject> objects,
|
||||
ArrayList<Visitor> visitors, ArrayList<Path> paths) {
|
||||
Point2D tar = target;
|
||||
public void move(DrawObject tar, Panel panel)
|
||||
{
|
||||
Point2D targetPoint = panel.getWaypoint(target).getPosition();
|
||||
|
||||
double newRot = Math.atan2(targetPoint.getY() - position.getY(), targetPoint.getX() - position.getX());
|
||||
|
||||
int difx = (int) (targetPoint.getX() - position.getX());
|
||||
int dify = (int) (targetPoint.getY() - position.getY());
|
||||
int distance = (int) Math.sqrt((difx * difx) + (dify * dify));
|
||||
|
||||
if (rotation > newRot && distance > 10)
|
||||
{
|
||||
rotation -= 0.15;
|
||||
}
|
||||
else if (rotation < newRot && distance > 10)
|
||||
{
|
||||
rotation += 0.15;
|
||||
}
|
||||
|
||||
Point2D oldPosition = position;
|
||||
|
||||
// face direction
|
||||
float directionX = (float) Math.cos(rotation);
|
||||
float directionY = (float) Math.sin(rotation);
|
||||
|
||||
if (distance > 10)
|
||||
{
|
||||
position = new Point2D.Double((position.getX() + directionX * speed), (position.getY() + directionY * speed));
|
||||
}
|
||||
|
||||
boolean possible = true;
|
||||
for (DrawObject object : objects)
|
||||
{
|
||||
if (object instanceof Entrance || object instanceof Waypoint)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (hasCollisionDO(object))
|
||||
{
|
||||
possible = false;
|
||||
}
|
||||
}
|
||||
if (possible == false)
|
||||
{
|
||||
position = oldPosition;
|
||||
rotation += 0.2;
|
||||
}
|
||||
if (checkIfOnWaypoint(panel))
|
||||
{
|
||||
// for(int i : panel.getWaypoint(target).getOptions())
|
||||
// {
|
||||
// if(i == finalTarget)
|
||||
// {
|
||||
// target = finalTarget;
|
||||
// }
|
||||
// }
|
||||
// ArrayList<int[]> options = new ArrayList<int[]>();
|
||||
HashMap<Integer, int[]> options = new HashMap<Integer, int[]>();
|
||||
for (Waypoint w : panel.getWaypoints())
|
||||
{
|
||||
options.put(w.getSelf(), w.getOptions());
|
||||
}
|
||||
for(Map.Entry<Integer, int[]> e : options.entrySet())
|
||||
{
|
||||
System.out.println(e.getKey());
|
||||
System.out.println("=====================");
|
||||
for(int i : e.getValue())
|
||||
{
|
||||
System.out.println(i);
|
||||
}
|
||||
System.out.println("----------");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean checkIfOnWaypoint(Panel panel)
|
||||
{
|
||||
if (panel.getWaypoint(target).contains(position))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void moveToTarget(DrawObject target, ArrayList<DrawObject> objects, ArrayList<Visitor> visitors, ArrayList<Path> paths)
|
||||
{
|
||||
Point2D tar = target.getPosition();
|
||||
boolean hasPathBelow = false;
|
||||
for (Path p : paths) {
|
||||
if (p.containsPoint(position)) {
|
||||
for (Path p : paths)
|
||||
{
|
||||
if (p.containsPoint(position))
|
||||
{
|
||||
hasPathBelow = true;
|
||||
break;
|
||||
}
|
||||
Shape containsShape = p.containsPointShape(position);
|
||||
if (containsShape != null) {
|
||||
tar = new Point2D.Double(
|
||||
containsShape.getBounds().getCenterX(), containsShape
|
||||
.getBounds().getCenterY());
|
||||
if (containsShape != null)
|
||||
{
|
||||
tar = new Point2D.Double(containsShape.getBounds().getCenterX(), containsShape.getBounds().getCenterY());
|
||||
}
|
||||
}
|
||||
|
||||
if (hasPathBelow) {
|
||||
double newRot = Math.atan2(tar.getY() - position.getY(), tar.getX()
|
||||
- position.getX());
|
||||
if (hasPathBelow)
|
||||
{
|
||||
double newRot = Math.atan2(tar.getY() - position.getY(), tar.getX() - position.getX());
|
||||
|
||||
int difx = (int) (tar.getX() - position.getX());
|
||||
int dify = (int) (tar.getY() - position.getY());
|
||||
int distance = (int) Math.sqrt((difx * difx) + (dify * dify));
|
||||
|
||||
if (rotation > newRot && distance > 10) {
|
||||
if (rotation > newRot && distance > 10)
|
||||
{
|
||||
rotation -= 0.15;
|
||||
} else if (rotation < newRot && distance > 10) {
|
||||
}
|
||||
else if (rotation < newRot && distance > 10)
|
||||
{
|
||||
rotation += 0.15;
|
||||
}
|
||||
|
||||
@@ -117,30 +224,39 @@ public class Visitor {
|
||||
float directionX = (float) Math.cos(rotation);
|
||||
float directionY = (float) Math.sin(rotation);
|
||||
|
||||
if (distance > 10) {
|
||||
position = new Point2D.Double((position.getX() + directionX
|
||||
* speed), (position.getY() + directionY * speed));
|
||||
if (distance > 10)
|
||||
{
|
||||
position = new Point2D.Double((position.getX() + directionX * speed), (position.getY() + directionY * speed));
|
||||
}
|
||||
|
||||
boolean possible = true;
|
||||
for (DrawObject object : objects) {
|
||||
if (hasCollisionDO(object)) {
|
||||
for (DrawObject object : objects)
|
||||
{
|
||||
if (hasCollisionDO(object))
|
||||
{
|
||||
possible = false;
|
||||
}
|
||||
}
|
||||
for (Visitor object : visitors) {
|
||||
if (hasCollision(object) && object != this) {
|
||||
for (Visitor object : visitors)
|
||||
{
|
||||
if (hasCollision(object) && object != this)
|
||||
{
|
||||
possible = false;
|
||||
}
|
||||
}
|
||||
if (possible == false) {
|
||||
if (possible == false)
|
||||
{
|
||||
position = oldPosition;
|
||||
rotation += 0.2;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
HashMap<Double, Shape> values = new HashMap<Double, Shape>();
|
||||
for (Path p : paths) {
|
||||
for (Shape s : p.getPath()) {
|
||||
for (Path p : paths)
|
||||
{
|
||||
for (Shape s : p.getPath())
|
||||
{
|
||||
Rectangle b = s.getBounds();
|
||||
double maxx = b.getMaxX();
|
||||
double minx = b.getMinX();
|
||||
@@ -154,14 +270,16 @@ public class Visitor {
|
||||
points[3] = new Point2D.Double(maxx, maxy);
|
||||
|
||||
Double lastdistance = null;
|
||||
for (Point2D.Double point : points) {
|
||||
double distance = Point2D.distance(point.getX(),
|
||||
point.getY(), position.getX(), position.getY());
|
||||
if (lastdistance == null) {
|
||||
for (Point2D.Double point : points)
|
||||
{
|
||||
double distance = Point2D.distance(point.getX(), point.getY(), position.getX(), position.getY());
|
||||
if (lastdistance == null)
|
||||
{
|
||||
lastdistance = distance;
|
||||
continue;
|
||||
}
|
||||
if (distance < lastdistance) {
|
||||
if (distance < lastdistance)
|
||||
{
|
||||
lastdistance = distance;
|
||||
}
|
||||
}
|
||||
@@ -171,31 +289,35 @@ public class Visitor {
|
||||
}
|
||||
Double lastdistance = null;
|
||||
Shape lastShape = null;
|
||||
for (Map.Entry<Double, Shape> e : values.entrySet()) {
|
||||
for (Map.Entry<Double, Shape> e : values.entrySet())
|
||||
{
|
||||
double distance = e.getKey();
|
||||
if (lastdistance == null) {
|
||||
if (lastdistance == null)
|
||||
{
|
||||
lastdistance = distance;
|
||||
continue;
|
||||
}
|
||||
if (distance < lastdistance) {
|
||||
if (distance < lastdistance)
|
||||
{
|
||||
lastdistance = distance;
|
||||
}
|
||||
}
|
||||
lastShape = values.get(lastdistance);
|
||||
|
||||
Point2D.Double target2 = new Point2D.Double(lastShape.getBounds()
|
||||
.getCenterX(), lastShape.getBounds().getCenterY());
|
||||
Point2D.Double target2 = new Point2D.Double(lastShape.getBounds().getCenterX(), lastShape.getBounds().getCenterY());
|
||||
|
||||
double newRot = Math.atan2(target2.getY() - position.getY(),
|
||||
target2.getX() - position.getX());
|
||||
double newRot = Math.atan2(target2.getY() - position.getY(), target2.getX() - position.getX());
|
||||
|
||||
int difx = (int) (target2.getX() - position.getX());
|
||||
int dify = (int) (target2.getY() - position.getY());
|
||||
int distance = (int) Math.sqrt((difx * difx) + (dify * dify));
|
||||
|
||||
if (rotation > newRot && distance > 10) {
|
||||
if (rotation > newRot && distance > 10)
|
||||
{
|
||||
rotation -= 0.15;
|
||||
} else if (rotation < newRot && distance > 10) {
|
||||
}
|
||||
else if (rotation < newRot && distance > 10)
|
||||
{
|
||||
rotation += 0.15;
|
||||
}
|
||||
|
||||
@@ -205,23 +327,28 @@ public class Visitor {
|
||||
float directionX = (float) Math.cos(rotation);
|
||||
float directionY = (float) Math.sin(rotation);
|
||||
|
||||
if (distance > 10) {
|
||||
position = new Point2D.Double((position.getX() + directionX
|
||||
* speed), (position.getY() + directionY * speed));
|
||||
if (distance > 10)
|
||||
{
|
||||
position = new Point2D.Double((position.getX() + directionX * speed), (position.getY() + directionY * speed));
|
||||
}
|
||||
|
||||
boolean possible = true;
|
||||
for (DrawObject object : objects) {
|
||||
if (hasCollisionDO(object)) {
|
||||
for (DrawObject object : objects)
|
||||
{
|
||||
if (hasCollisionDO(object))
|
||||
{
|
||||
possible = false;
|
||||
}
|
||||
}
|
||||
for (Visitor object : visitors) {
|
||||
if (hasCollision(object) && object != this) {
|
||||
for (Visitor object : visitors)
|
||||
{
|
||||
if (hasCollision(object) && object != this)
|
||||
{
|
||||
possible = false;
|
||||
}
|
||||
}
|
||||
if (possible == false) {
|
||||
if (possible == false)
|
||||
{
|
||||
position = oldPosition;
|
||||
rotation += 0.2;
|
||||
}
|
||||
@@ -237,9 +364,10 @@ public class Visitor {
|
||||
int random = (int) Math.floor(Math.random() * 21);
|
||||
if (random < 40) {
|
||||
Point2D position = null;
|
||||
DrawObject targetStage = null;
|
||||
ArrayList<Event> posEvents = new ArrayList<Event>();
|
||||
for (Event e : agenda.getEvents()) {
|
||||
if (startTime >= e.getStart() && startTime < e.getStop() && date.DAY_OF_MONTH == e.getStartDate().DAY_OF_MONTH) {
|
||||
if (startTime >= e.getStart() && startTime < e.getStop()) {
|
||||
posEvents.add(e);
|
||||
}
|
||||
}
|
||||
@@ -261,6 +389,7 @@ public class Visitor {
|
||||
if (s.getStage().getName()
|
||||
.equals(evs.getStage().getName())) {
|
||||
position = s.getPosition();
|
||||
targetStage = d;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -269,12 +398,14 @@ public class Visitor {
|
||||
|
||||
int randomtime = (int) (40 + (Math.random() * (60 - 40)));
|
||||
if (position != null) {
|
||||
actions.add(new Action(position, startTime, randomtime));
|
||||
Waypoint w = getClosedWaypoint(position);
|
||||
actions.add(new Action(position, startTime, randomtime, targetStage, w));
|
||||
}
|
||||
startTime = startTime + randomtime;
|
||||
|
||||
} else if (random >= 40 && random < 45) {
|
||||
Point2D position = null;
|
||||
DrawObject targetStage = null;
|
||||
ArrayList<DrawObject> foodPlaces = new ArrayList<DrawObject>();
|
||||
for (DrawObject d : objects) {
|
||||
if (d.getFileName().equals("food")) {
|
||||
@@ -285,13 +416,16 @@ public class Visitor {
|
||||
if (foodPlaces.size() != 0){
|
||||
int r = (int) Math.floor(Math.random() * foodPlaces.size());
|
||||
position = foodPlaces.get(r).getPosition();
|
||||
actions.add(new Action(position, startTime, 35));
|
||||
targetStage = foodPlaces.get(r);
|
||||
Waypoint w = getClosedWaypoint(position);
|
||||
actions.add(new Action(position, startTime, 35, targetStage, w));
|
||||
startTime = startTime + 20;
|
||||
}
|
||||
startTime = startTime + 35;
|
||||
|
||||
} else if (random > 45) {
|
||||
Point2D position = null;
|
||||
DrawObject targetStage = null;
|
||||
ArrayList<DrawObject> toilets = new ArrayList<DrawObject>();
|
||||
for (DrawObject d : objects) {
|
||||
if (d.getFileName().equals("wc")) {
|
||||
@@ -301,7 +435,9 @@ public class Visitor {
|
||||
if (toilets.size() != 0){
|
||||
int r = (int) Math.floor(Math.random() * toilets.size());
|
||||
position = toilets.get(r).getPosition();
|
||||
actions.add(new Action(position, startTime, 35));
|
||||
targetStage = toilets.get(r);
|
||||
Waypoint w = getClosedWaypoint(position);
|
||||
actions.add(new Action(position, startTime, 35, targetStage, w));
|
||||
startTime = startTime + 20;
|
||||
}
|
||||
startTime = startTime + 35;
|
||||
@@ -309,15 +445,19 @@ public class Visitor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int convertMinutesToHours(int startTime) {
|
||||
int time = 0;
|
||||
int hours = startTime / 60;
|
||||
int minutes = startTime % 60;
|
||||
time = (hours * 100) + minutes;
|
||||
return time;
|
||||
|
||||
public Waypoint getClosedWaypoint(Point2D point){
|
||||
Waypoint waypoint = null;
|
||||
int distance = 10000;
|
||||
for(Waypoint w : waypoints){
|
||||
if (w.getPosition().distance(point) < distance){
|
||||
waypoint = w;
|
||||
distance = (int) w.getPosition().distance(point);
|
||||
}
|
||||
}
|
||||
return waypoint;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasCollisionDO(DrawObject object) {
|
||||
Image image = Images.getImage(filename);
|
||||
Image image2 = Images.getImage(object.getFileName());
|
||||
@@ -373,5 +513,4 @@ public class Visitor {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,6 +36,7 @@ public class Waypoint extends DrawObject
|
||||
|
||||
public void setSelf(int self)
|
||||
{
|
||||
System.out.println(self);
|
||||
this.self = self;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
package Applicatie;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import Objects.DrawObject;
|
||||
|
||||
public class WaypointPopup extends JFrame {
|
||||
|
||||
private static final long serialVersionUID = 1;
|
||||
private JLabel title;
|
||||
|
||||
public WaypointPopup(DrawObject w, Panel panel)
|
||||
{
|
||||
super("Edit WayPoint");
|
||||
Waypoint wp = (Waypoint) w;
|
||||
setDefaultCloseOperation(HIDE_ON_CLOSE);
|
||||
JPanel content = new JPanel(new BorderLayout());
|
||||
JPanel north = new JPanel();
|
||||
if(wp.getSelf() == 0)
|
||||
{
|
||||
title = new JLabel("Edit WayPoint");
|
||||
}
|
||||
else
|
||||
{
|
||||
title = new JLabel("Edit WayPoint " + wp.getSelf());
|
||||
}
|
||||
title.setFont(new Font("Dialog", Font.BOLD, 24));
|
||||
north.add(title);
|
||||
content.add(north, BorderLayout.NORTH);
|
||||
JPanel center = new JPanel(new FlowLayout());
|
||||
JPanel row1 = new JPanel();
|
||||
row1.setLayout(new BoxLayout(row1, BoxLayout.Y_AXIS));
|
||||
JPanel row2 = new JPanel();
|
||||
row2.setLayout(new BoxLayout(row2, BoxLayout.Y_AXIS));
|
||||
JPanel south = new JPanel();
|
||||
content.add(south, BorderLayout.SOUTH);
|
||||
content.add(center, BorderLayout.CENTER);
|
||||
center.add(row1);
|
||||
center.add(row2);
|
||||
|
||||
JPanel empty = new JPanel();
|
||||
empty.add(Box.createRigidArea(new Dimension(0, 20)));
|
||||
row2.add(empty);
|
||||
|
||||
JPanel panel1 = new JPanel();
|
||||
JLabel name = new JLabel("Waypoint");
|
||||
name.setFont(new Font("Dialog", Font.PLAIN, 20));
|
||||
panel1.add(name);
|
||||
row1.add(panel1);
|
||||
|
||||
JTextField tf = new JTextField(10);
|
||||
row2.add(tf);
|
||||
|
||||
JPanel panel2 = new JPanel();
|
||||
JLabel options = new JLabel("Options");
|
||||
options.setFont(new Font("Dialog", Font.PLAIN, 20));
|
||||
panel2.add(options);
|
||||
row1.add(panel2);
|
||||
|
||||
JPanel empty2 = new JPanel();
|
||||
empty2.add(Box.createRigidArea(new Dimension(0, 5)));
|
||||
row2.add(empty2);
|
||||
|
||||
JTextField tx = new JTextField(8);
|
||||
row2.add(tx);
|
||||
|
||||
JPanel help = new JPanel();
|
||||
JLabel example = new JLabel("example: '1-2-3'");
|
||||
example.setFont(new Font("Dialog", Font.PLAIN, 12));
|
||||
help.add(example);
|
||||
row2.add(help);
|
||||
|
||||
JButton edit = new JButton("Done");
|
||||
edit.addActionListener(new ActionListener()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
wp.setSelf(Integer.valueOf(tf.getText()));
|
||||
panel.addWaypoint(wp);
|
||||
dispose();
|
||||
String options[] = tx.getText().split("-");
|
||||
int ioptions[] = new int[options.length];
|
||||
for(int i = 0; i < options.length; i++)
|
||||
{
|
||||
ioptions[i] = Integer.valueOf(options[i]);
|
||||
}
|
||||
wp.setOptions(ioptions);
|
||||
|
||||
}
|
||||
});
|
||||
south.add(edit);
|
||||
|
||||
setContentPane(content);
|
||||
setVisible(true);
|
||||
setSize(300,250);
|
||||
}
|
||||
|
||||
}
|
||||
+32
-4
@@ -27,23 +27,51 @@ public class Keyboard implements KeyListener {
|
||||
}
|
||||
else if(e.getKeyCode() == e.VK_LEFT) {
|
||||
if(panel.getSelectedObject() != null)
|
||||
panel.getSelectedObject().setPosition(new Point2D.Double(panel.getSelectedObject().getPosition().getX()-5,panel.getSelectedObject().getPosition().getY()));
|
||||
panel.getSelectedObject().setPosition(new Point2D.Double(panel.getSelectedObject().getPosition().getX()-5,panel.getSelectedObject().getPosition().getY()), true);
|
||||
panel.checkCollision();
|
||||
panel.getPP().update();
|
||||
}
|
||||
else if(e.getKeyCode() == e.VK_RIGHT) {
|
||||
if(panel.getSelectedObject() != null)
|
||||
panel.getSelectedObject().setPosition(new Point2D.Double(panel.getSelectedObject().getPosition().getX()+5,panel.getSelectedObject().getPosition().getY()));
|
||||
panel.getSelectedObject().setPosition(new Point2D.Double(panel.getSelectedObject().getPosition().getX()+5,panel.getSelectedObject().getPosition().getY()), true);
|
||||
panel.checkCollision();
|
||||
panel.getPP().update();
|
||||
}
|
||||
else if(e.getKeyCode() == e.VK_UP) {
|
||||
if(panel.getSelectedObject() != null)
|
||||
panel.getSelectedObject().setPosition(new Point2D.Double(panel.getSelectedObject().getPosition().getX(),panel.getSelectedObject().getPosition().getY()-5));
|
||||
panel.getSelectedObject().setPosition(new Point2D.Double(panel.getSelectedObject().getPosition().getX(),panel.getSelectedObject().getPosition().getY()-5), true);
|
||||
panel.checkCollision();
|
||||
panel.getPP().update();
|
||||
}
|
||||
else if(e.getKeyCode() == e.VK_DOWN) {
|
||||
if(panel.getSelectedObject() != null)
|
||||
panel.getSelectedObject().setPosition(new Point2D.Double(panel.getSelectedObject().getPosition().getX(),panel.getSelectedObject().getPosition().getY()+5));
|
||||
panel.getSelectedObject().setPosition(new Point2D.Double(panel.getSelectedObject().getPosition().getX(),panel.getSelectedObject().getPosition().getY()+5), true);
|
||||
panel.checkCollision();
|
||||
panel.getPP().update();
|
||||
}
|
||||
else if(e.getKeyCode() == e.VK_ADD) {
|
||||
if(panel.getSelectedObject() != null)
|
||||
panel.getSelectedObject().setScale(panel.getSelectedObject().getScale()+0.2);
|
||||
panel.checkCollision();
|
||||
panel.getPP().update();
|
||||
}
|
||||
else if(e.getKeyCode() == e.VK_SUBTRACT) {
|
||||
if(panel.getSelectedObject() != null)
|
||||
panel.getSelectedObject().setScale(Math.max(panel.getSelectedObject().getScale()-0.2, 0.2));
|
||||
panel.checkCollision();
|
||||
panel.getPP().update();
|
||||
}
|
||||
else if(e.getKeyCode() == e.VK_COMMA) {
|
||||
if(panel.getSelectedObject() != null)
|
||||
panel.getSelectedObject().setRotation((panel.getSelectedObject().getRotation()-5)%360);
|
||||
panel.checkCollision();
|
||||
panel.getPP().update();
|
||||
}
|
||||
else if(e.getKeyCode() == e.VK_PERIOD) {
|
||||
if(panel.getSelectedObject() != null)
|
||||
panel.getSelectedObject().setRotation((panel.getSelectedObject().getRotation()+5)%360);
|
||||
panel.checkCollision();
|
||||
panel.getPP().update();
|
||||
}
|
||||
else if(e.getKeyCode() == e.VK_ENTER) {
|
||||
if(panel.getClickedOption().equals("Path")) {
|
||||
|
||||
+45
-42
@@ -7,8 +7,13 @@ import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import Applicatie.Panel;
|
||||
import Applicatie.PathPopup;
|
||||
|
||||
import Applicatie.Waypoint;
|
||||
import Applicatie.WaypointPopup;
|
||||
import Objects.DrawObject;
|
||||
import Objects.Path;
|
||||
import Objects.Entrance;
|
||||
@@ -30,6 +35,7 @@ public class Mouse extends MouseAdapter
|
||||
Point2D clickPoint = panel.getClickPoint(e.getPoint());
|
||||
panel.setLastClickPosition(clickPoint);
|
||||
panel.setLastMousePosition(e.getPoint());
|
||||
|
||||
if (!panel.getClickedOption().equals("Path"))
|
||||
{
|
||||
if (e.getY() < 150)
|
||||
@@ -41,15 +47,16 @@ public class Mouse extends MouseAdapter
|
||||
if (e.getX() >= panel.getScrollfactor() && e.getX() < last + image.getWidth() + panel.getScrollfactor())
|
||||
{
|
||||
DrawObject tempDrawObj = panel.createNewDrawObject(i);
|
||||
if (tempDrawObj != null){
|
||||
tempDrawObj.setPosition(clickPoint);
|
||||
if (!panel.getObjects().isEmpty())
|
||||
panel.clearObjectSelection();
|
||||
panel.setDragObject(tempDrawObj);
|
||||
panel.getDragObject().setSelected(true);
|
||||
panel.getPP().setSelected(tempDrawObj);
|
||||
panel.setSelectedObject(tempDrawObj);
|
||||
selectedObject = tempDrawObj;
|
||||
if (tempDrawObj != null)
|
||||
{
|
||||
tempDrawObj.setPosition(clickPoint);
|
||||
if (!panel.getObjects().isEmpty())
|
||||
panel.clearObjectSelection();
|
||||
panel.setDragObject(tempDrawObj);
|
||||
panel.getDragObject().setSelected(true);
|
||||
panel.getPP().setSelected(tempDrawObj);
|
||||
panel.setSelectedObject(tempDrawObj);
|
||||
selectedObject = tempDrawObj;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -67,6 +74,14 @@ public class Mouse extends MouseAdapter
|
||||
{
|
||||
if (o.contains(clickPoint))
|
||||
{
|
||||
if (SwingUtilities.isRightMouseButton(e))
|
||||
{
|
||||
if (o instanceof Waypoint)
|
||||
{
|
||||
new WaypointPopup(o, panel);
|
||||
|
||||
}
|
||||
}
|
||||
if (o == selectedObject)
|
||||
{
|
||||
boolean upperLeft = o.containsCorner(clickPoint, 0);
|
||||
@@ -110,7 +125,19 @@ public class Mouse extends MouseAdapter
|
||||
|
||||
}
|
||||
}
|
||||
panel.checkPath(clickPoint);
|
||||
Path clickedPath = panel.getClickedPath(clickPoint);
|
||||
if (clickedPath != null)
|
||||
{
|
||||
if (SwingUtilities.isRightMouseButton(e))
|
||||
{
|
||||
new PathPopup(clickedPath, panel);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
panel.checkPath(clickPoint);
|
||||
}
|
||||
|
||||
}
|
||||
if (panel.getDragObject() == null && selectedObject != null)
|
||||
{
|
||||
@@ -122,45 +149,21 @@ public class Mouse extends MouseAdapter
|
||||
}
|
||||
else
|
||||
{ // Making path.
|
||||
|
||||
panel.getCurrentPath().addPoint(new Point2D.Double(clickPoint.getX(), clickPoint.getY()));
|
||||
|
||||
}
|
||||
panel.repaint();
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent e)
|
||||
{
|
||||
if(panel.getDragObject() != null) {
|
||||
if(panel.getDragObject().getRectangleColor() != Color.RED) {
|
||||
if(panel.getDragObject() instanceof Entrance)
|
||||
{
|
||||
Rectangle2D rect = panel.getDragObject().getRectangle();
|
||||
double xl = (panel.getFieldWidth()/2) + rect.getMinX();
|
||||
double xr = panel.getFieldWidth() - xl+rect.getWidth();
|
||||
double yt = (panel.getFieldHeight()/2) + rect.getMinY();
|
||||
double yb = panel.getFieldHeight() - yt+rect.getHeight();
|
||||
if(xl < xr && xl < yt && xl < yb)
|
||||
{
|
||||
panel.getDragObject().setPosition(new Point2D.Double(-panel.getFieldWidth()/2, rect.getMinY()));
|
||||
}
|
||||
else if(xr < xl && xr < yt && xr < yb)
|
||||
{
|
||||
panel.getDragObject().setPosition(new Point2D.Double(panel.getFieldWidth()/2 - rect.getWidth(), rect.getMinY()));
|
||||
}
|
||||
else if(yt < xl && yt < xr && yt < yb)
|
||||
{
|
||||
panel.getDragObject().setPosition(new Point2D.Double(rect.getMinX(), -panel.getFieldHeight()/2));
|
||||
}
|
||||
else if(yb < xl && yb < yt && yb < xr)
|
||||
{
|
||||
panel.getDragObject().setPosition(new Point2D.Double(rect.getMinX(), panel.getFieldHeight()/2 - rect.getHeight()));
|
||||
}
|
||||
else
|
||||
{
|
||||
panel.getDragObject().setPosition(new Point2D.Double(-panel.getFieldWidth()/2, -panel.getFieldHeight()/2));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (panel.getDragObject() != null)
|
||||
{
|
||||
if (panel.getDragObject().getRectangleColor() != Color.RED)
|
||||
{
|
||||
panel.getDragObject().setPosition(panel.getDragObject().getPosition(), true);
|
||||
panel.getPP().update();
|
||||
panel.setDragObject(null);
|
||||
panel.setClickedOption("drag");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package Listeners;
|
||||
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
|
||||
import Applicatie.Panel;
|
||||
|
||||
public class WindowFocusListener implements FocusListener
|
||||
{
|
||||
Panel p;
|
||||
|
||||
public WindowFocusListener(Panel p)
|
||||
{
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void focusGained(FocusEvent e){}
|
||||
|
||||
@Override
|
||||
public void focusLost(FocusEvent e)
|
||||
{
|
||||
p.requestFocus();
|
||||
}
|
||||
}
|
||||
@@ -234,6 +234,10 @@ public abstract class DrawObject implements Serializable
|
||||
{
|
||||
this.position = position;
|
||||
}
|
||||
public void setPosition(Point2D position, boolean b)
|
||||
{
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public double getRotation()
|
||||
{
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package Objects;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import Applicatie.Panel;
|
||||
|
||||
public class Entrance extends DrawObject
|
||||
{
|
||||
@@ -15,5 +18,35 @@ public class Entrance extends DrawObject
|
||||
{
|
||||
return "Entrance";
|
||||
}
|
||||
|
||||
public void setPosition(Point2D position, boolean b)
|
||||
{
|
||||
//this.position = position;
|
||||
Rectangle2D rect = getRectangle();
|
||||
double xl = (Panel.getFieldWidth()/2) + rect.getMinX();
|
||||
double xr = Panel.getFieldWidth() - (Panel.getFieldWidth()/2 + rect.getMaxX());
|
||||
double yt = (Panel.getFieldHeight()/2) + rect.getMinY();
|
||||
double yb = Panel.getFieldHeight() - (Panel.getFieldHeight()/2 + rect.getMaxY());
|
||||
if(xl < xr && xl < yt && xl < yb)
|
||||
{
|
||||
this.position = new Point2D.Double(-Panel.getFieldWidth()/2, position.getY());
|
||||
}
|
||||
else if(xr < xl && xr < yt && xr < yb)
|
||||
{
|
||||
this.position = new Point2D.Double(Panel.getFieldWidth()/2 - rect.getWidth(), position.getY());
|
||||
}
|
||||
else if(yt < xl && yt < xr && yt < yb)
|
||||
{
|
||||
this.position = new Point2D.Double(position.getX(), -Panel.getFieldHeight()/2);
|
||||
}
|
||||
else if(yb < xl && yb < yt && yb < xr)
|
||||
{
|
||||
this.position = new Point2D.Double(position.getX(), Panel.getFieldHeight()/2 - rect.getHeight());
|
||||
}
|
||||
else
|
||||
{
|
||||
this.position = new Point2D.Double(-Panel.getFieldWidth()/2, -Panel.getFieldHeight()/2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+25
-4
@@ -14,6 +14,9 @@ import java.util.ArrayList;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import Applicatie.Panel;
|
||||
import Applicatie.Waypoint;
|
||||
|
||||
/**
|
||||
* Create's a path.
|
||||
*
|
||||
@@ -27,6 +30,7 @@ public class Path
|
||||
private ArrayList<Shape> lines;
|
||||
private Point2D tempPoint;
|
||||
private BufferedImage pathBackground;
|
||||
private ArrayList<Waypoint> waypoints;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -35,6 +39,7 @@ public class Path
|
||||
{
|
||||
points = new ArrayList<>();
|
||||
lines = new ArrayList<>();
|
||||
waypoints = new ArrayList<Waypoint>();
|
||||
try
|
||||
{
|
||||
pathBackground = ImageIO.read(new File("images/newPath.png"));
|
||||
@@ -91,7 +96,7 @@ public class Path
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if one of the lines contains the given point.
|
||||
*
|
||||
@@ -110,12 +115,13 @@ public class Path
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean intersectsRect(Rectangle2D rect)
|
||||
{
|
||||
for(Shape line : getPath())
|
||||
for (Shape line : getPath())
|
||||
{
|
||||
if(line.intersects(rect))
|
||||
if (line.intersects(rect))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -140,8 +146,23 @@ public class Path
|
||||
lines.add(stroke.createStrokedShape(line));
|
||||
}
|
||||
return lines;
|
||||
|
||||
}
|
||||
|
||||
public void addWaypoint(int i, Panel panel)
|
||||
{
|
||||
for (Waypoint w : panel.getWaypoints())
|
||||
{
|
||||
if (w.getSelf() == i)
|
||||
{
|
||||
waypoints.add(w);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a point to the path.
|
||||
*
|
||||
|
||||
+15
-10
@@ -1,28 +1,33 @@
|
||||
package Objects;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import Agenda.Agenda;
|
||||
import Agenda.AgendaStage;
|
||||
|
||||
public class Stage extends DrawObject {
|
||||
public class Stage extends DrawObject
|
||||
{
|
||||
AgendaStage stage;
|
||||
|
||||
public Stage(Point2D position, AgendaStage stage) {
|
||||
|
||||
public Stage(Point2D position, AgendaStage st)
|
||||
{
|
||||
super("stage", position);
|
||||
this.stage = stage;
|
||||
stage = st;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
public String getName()
|
||||
{
|
||||
return "Stage";
|
||||
}
|
||||
|
||||
public AgendaStage getStage() {
|
||||
public AgendaStage getStage()
|
||||
{
|
||||
return stage;
|
||||
}
|
||||
|
||||
public void setStage(AgendaStage stage)
|
||||
{
|
||||
this.stage = stage;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user