Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c11d4ad2f | ||
|
|
77dae9741e |
+4
-4
@@ -34,8 +34,8 @@ public class Event implements Serializable {
|
|||||||
endHour, endMinute);
|
endHour, endMinute);
|
||||||
this.startHour = startHour;
|
this.startHour = startHour;
|
||||||
this.startMinute = startMinute;
|
this.startMinute = startMinute;
|
||||||
this.stopHour = stopHour;
|
this.stopHour = endHour;
|
||||||
this.stopMinute = stopMinute;
|
this.stopMinute = endMinute;
|
||||||
this.stage = stage;
|
this.stage = stage;
|
||||||
this.artist = artist;
|
this.artist = artist;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
@@ -55,11 +55,11 @@ public class Event implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getStart(){
|
public int getStart(){
|
||||||
return (startHour * 100) + startMinute;
|
return (startHour * 60) + startMinute;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStop(){
|
public int getStop(){
|
||||||
return (stopHour * 100) + stopMinute;
|
return (stopHour * 60) + stopMinute;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStopHour(){
|
public int getStopHour(){
|
||||||
|
|||||||
@@ -11,13 +11,15 @@ public class Action
|
|||||||
private int starttime;
|
private int starttime;
|
||||||
private int duration;
|
private int duration;
|
||||||
private DrawObject target;
|
private DrawObject target;
|
||||||
|
private Waypoint waypoint;
|
||||||
|
|
||||||
public Action(Point2D position, int starttime, int duration, DrawObject tar)
|
public Action(Point2D position, int starttime, int duration, DrawObject tar, Waypoint waypoint)
|
||||||
{
|
{
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.starttime = starttime;
|
this.starttime = starttime;
|
||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
this.target = tar;
|
this.target = tar;
|
||||||
|
this.waypoint = waypoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Point2D getPosition()
|
public Point2D getPosition()
|
||||||
@@ -44,4 +46,8 @@ public class Action
|
|||||||
{
|
{
|
||||||
return duration;
|
return duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Waypoint getWaypoint(){
|
||||||
|
return waypoint;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
package Applicatie;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.event.KeyListener;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
|
public class AddPeoplePanel extends JFrame {
|
||||||
|
|
||||||
|
public AddPeoplePanel(Panel topPanel) {
|
||||||
|
super("Adding people");
|
||||||
|
setDefaultCloseOperation(HIDE_ON_CLOSE);
|
||||||
|
setResizable(false);
|
||||||
|
|
||||||
|
JPanel mainPanel = new JPanel(new BorderLayout());
|
||||||
|
JLabel label;
|
||||||
|
JButton button;
|
||||||
|
|
||||||
|
//Top:
|
||||||
|
JPanel panel = new JPanel();
|
||||||
|
label = new JLabel("Enter the amount of people you want to add: ");
|
||||||
|
panel.add(label);
|
||||||
|
mainPanel.add(panel,BorderLayout.NORTH);
|
||||||
|
//Center:
|
||||||
|
panel = new JPanel();
|
||||||
|
JTextField amountOfPeopleField = new JTextField("0");
|
||||||
|
amountOfPeopleField.setPreferredSize(new Dimension(100,20));
|
||||||
|
amountOfPeopleField.addKeyListener(new KeyListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyTyped(KeyEvent e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyReleased(KeyEvent e) {
|
||||||
|
try {
|
||||||
|
amountOfPeopleField.setBackground(Color.WHITE);
|
||||||
|
int amountOfPeople = Integer.parseInt(amountOfPeopleField.getText());
|
||||||
|
amountOfPeopleField.setText(amountOfPeople + "");
|
||||||
|
}
|
||||||
|
catch(NumberFormatException nf) {
|
||||||
|
amountOfPeopleField.setBackground(Color.RED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyPressed(KeyEvent e) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
label = new JLabel("people ");
|
||||||
|
panel.add(amountOfPeopleField);
|
||||||
|
panel.add(label);
|
||||||
|
mainPanel.add(panel,BorderLayout.CENTER);
|
||||||
|
//Bottom:
|
||||||
|
panel = new JPanel();
|
||||||
|
button = new JButton("Cancel");
|
||||||
|
button.addActionListener(new ActionListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
AddPeoplePanel.this.dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
panel.add(button);
|
||||||
|
button = new JButton("Apply");
|
||||||
|
button.addActionListener(new ActionListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if(amountOfPeopleField.getBackground() != Color.RED) {
|
||||||
|
topPanel.addVisitors(Integer.parseInt(amountOfPeopleField.getText()));
|
||||||
|
AddPeoplePanel.this.dispose();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
JOptionPane.showMessageDialog(topPanel, "Only numbers are accepted");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
panel.add(button);
|
||||||
|
mainPanel.add(panel,BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
add(mainPanel);
|
||||||
|
|
||||||
|
//Finishing off
|
||||||
|
pack();
|
||||||
|
setSize(290,150);
|
||||||
|
setLocationRelativeTo(null);
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,13 +19,16 @@ public class ControlPanel extends JPanel
|
|||||||
private static final long serialVersionUID = 6805244250902524351L;
|
private static final long serialVersionUID = 6805244250902524351L;
|
||||||
|
|
||||||
private Panel p;
|
private Panel p;
|
||||||
|
private int people;
|
||||||
JLabel timeLabel;
|
JLabel timeLabel;
|
||||||
|
JLabel peopleLabel;
|
||||||
|
|
||||||
public ControlPanel()
|
public ControlPanel()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
BoxLayout box = new BoxLayout(this, BoxLayout.X_AXIS);
|
BoxLayout box = new BoxLayout(this, BoxLayout.X_AXIS);
|
||||||
setLayout(box);
|
setLayout(box);
|
||||||
|
people = 0;
|
||||||
|
|
||||||
setPreferredSize(new Dimension(0,50));
|
setPreferredSize(new Dimension(0,50));
|
||||||
setBorder(BorderFactory.createLineBorder(new Color(180, 180, 180)));
|
setBorder(BorderFactory.createLineBorder(new Color(180, 180, 180)));
|
||||||
@@ -105,7 +108,7 @@ public class ControlPanel extends JPanel
|
|||||||
peoplePanel.setMaximumSize(new Dimension(285,50));
|
peoplePanel.setMaximumSize(new Dimension(285,50));
|
||||||
add(peoplePanel);
|
add(peoplePanel);
|
||||||
{
|
{
|
||||||
JLabel peopleLabel = new JLabel("0/0 People");
|
peopleLabel = new JLabel(people + " People");
|
||||||
peopleLabel.setFont(new Font("Segoe UI", Font.PLAIN, 20));
|
peopleLabel.setFont(new Font("Segoe UI", Font.PLAIN, 20));
|
||||||
peoplePanel.add(peopleLabel);
|
peoplePanel.add(peopleLabel);
|
||||||
|
|
||||||
@@ -115,7 +118,7 @@ public class ControlPanel extends JPanel
|
|||||||
peopleButton.addActionListener(new ActionListener(){
|
peopleButton.addActionListener(new ActionListener(){
|
||||||
public void actionPerformed(ActionEvent e)
|
public void actionPerformed(ActionEvent e)
|
||||||
{
|
{
|
||||||
p.addVisitors();
|
new AddPeoplePanel(p);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
peoplePanel.add(peopleButton);
|
peoplePanel.add(peopleButton);
|
||||||
@@ -147,6 +150,7 @@ public class ControlPanel extends JPanel
|
|||||||
|
|
||||||
public void setPeople(int people)
|
public void setPeople(int people)
|
||||||
{
|
{
|
||||||
|
this.people = people;
|
||||||
|
peopleLabel.setText(people + " People");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package Applicatie;
|
|||||||
|
|
||||||
public class Main
|
public class Main
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
new Window();
|
new Window();
|
||||||
|
|||||||
+76
-44
@@ -73,7 +73,7 @@ public class Panel extends JPanel implements ActionListener
|
|||||||
Point lastMousePosition = 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();
|
Images images = new Images();
|
||||||
javax.swing.Timer t;
|
Timer t;
|
||||||
|
|
||||||
SimpleDateFormat formatter;
|
SimpleDateFormat formatter;
|
||||||
GregorianCalendar date;
|
GregorianCalendar date;
|
||||||
@@ -146,9 +146,8 @@ public class Panel extends JPanel implements ActionListener
|
|||||||
addMouseMotionListener(new MouseMotion(this));
|
addMouseMotionListener(new MouseMotion(this));
|
||||||
|
|
||||||
addMouseWheelListener(new MouseWheel(this));
|
addMouseWheelListener(new MouseWheel(this));
|
||||||
|
|
||||||
addFocusListener(new WindowFocusListener(this));
|
addFocusListener(new WindowFocusListener(this));
|
||||||
|
|
||||||
t = new Timer(1000 / 10, this);
|
t = new Timer(1000 / 10, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,18 +170,21 @@ public class Panel extends JPanel implements ActionListener
|
|||||||
ArrayList<AgendaStage> stages = agenda.getStages();
|
ArrayList<AgendaStage> stages = agenda.getStages();
|
||||||
Object[] s = new Object[stages.size()];
|
Object[] s = new Object[stages.size()];
|
||||||
AgendaStage stage = null;
|
AgendaStage stage = null;
|
||||||
if (stages.size() != 0) {
|
if (stages.size() != 0)
|
||||||
for (int i = 0; i < stages.size(); i++) {
|
{
|
||||||
|
for (int i = 0; i < stages.size(); i++)
|
||||||
|
{
|
||||||
s[i] = stages.get(i);
|
s[i] = stages.get(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
stage = (AgendaStage) JOptionPane.showInputDialog(null,
|
stage = (AgendaStage) JOptionPane.showInputDialog(null, "Select the right Stage", "Select Stage", JOptionPane.PLAIN_MESSAGE, null, s, "stage");
|
||||||
"Select the right Stage", "Select Stage",
|
|
||||||
JOptionPane.PLAIN_MESSAGE, null, s, "stage");
|
|
||||||
}
|
}
|
||||||
if (stage != null){
|
if (stage != null)
|
||||||
|
{
|
||||||
return new Stage(null, stage);
|
return new Stage(null, stage);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
@@ -209,13 +211,34 @@ public class Panel extends JPanel implements ActionListener
|
|||||||
{
|
{
|
||||||
waypoints.add(w);
|
waypoints.add(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Waypoint getWaypoint(int i)
|
||||||
|
{
|
||||||
|
for(Waypoint w : waypoints)
|
||||||
|
{
|
||||||
|
if(w.getSelf() == i)
|
||||||
|
{
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public ArrayList<Waypoint> getWaypoints()
|
public ArrayList<Waypoint> getWaypoints()
|
||||||
{
|
{
|
||||||
return waypoints;
|
return waypoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addVisitors()
|
public void addVisitors(ArrayList<DrawObject> entrances)
|
||||||
|
{
|
||||||
|
|
||||||
|
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));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addVisitors(int count)
|
||||||
{
|
{
|
||||||
ArrayList<DrawObject> entrances = new ArrayList<>();
|
ArrayList<DrawObject> entrances = new ArrayList<>();
|
||||||
for(DrawObject object : objects) {
|
for(DrawObject object : objects) {
|
||||||
@@ -224,21 +247,14 @@ public class Panel extends JPanel implements ActionListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!entrances.isEmpty()) {
|
if(!entrances.isEmpty()) {
|
||||||
DrawObject entrance = entrances.get((int) Math.floor(Math.random()*entrances.size()));
|
for (int i = 0; i < count; i++)
|
||||||
Point point = new Point((int)entrance.getPosition().getX(),(int)entrance.getPosition().getY());
|
{
|
||||||
visitors.add(new Visitor("visitor",point, agenda, objects));
|
addVisitors(entrances);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
JOptionPane.showMessageDialog(this, "You don't have a entrance");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addVisitors(int count)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
addVisitors();
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
JOptionPane.showMessageDialog(this, "You don't have an entrance");
|
||||||
|
cp.setPeople(visitors.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paintComponent(Graphics g)
|
public void paintComponent(Graphics g)
|
||||||
@@ -549,13 +565,27 @@ public class Panel extends JPanel implements ActionListener
|
|||||||
{
|
{
|
||||||
if (path.containsPoint(point))
|
if (path.containsPoint(point))
|
||||||
{
|
{
|
||||||
|
|
||||||
setcurrentPath(path);
|
setcurrentPath(path);
|
||||||
setClickedOption("Path");
|
setClickedOption("Path");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
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.
|
* Remove a path from the list.
|
||||||
@@ -588,17 +618,17 @@ public class Panel extends JPanel implements ActionListener
|
|||||||
{
|
{
|
||||||
this.agenda = agenda;
|
this.agenda = agenda;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getFieldWidth()
|
public static int getFieldWidth()
|
||||||
{
|
{
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getFieldHeight()
|
public static int getFieldHeight()
|
||||||
{
|
{
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e)
|
public void actionPerformed(ActionEvent e)
|
||||||
{
|
{
|
||||||
@@ -614,7 +644,7 @@ public class Panel extends JPanel implements ActionListener
|
|||||||
|
|
||||||
for (Visitor v : visitors)
|
for (Visitor v : visitors)
|
||||||
{
|
{
|
||||||
v.update(objects, currentTime, visitors, paths);
|
v.update(objects, currentTime, visitors, paths, this);
|
||||||
}
|
}
|
||||||
repaint();
|
repaint();
|
||||||
|
|
||||||
@@ -641,24 +671,26 @@ public class Panel extends JPanel implements ActionListener
|
|||||||
this.height = height;
|
this.height = height;
|
||||||
paths.clear();
|
paths.clear();
|
||||||
objects.clear();
|
objects.clear();
|
||||||
|
visitors.clear();
|
||||||
cameraScale = 1;
|
cameraScale = 1;
|
||||||
switch (terrainIndex)
|
switch (terrainIndex)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
background = grass;
|
background = grass;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
background = grass2;
|
background = grass2;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
background = sand;
|
background = sand;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
background = sand2;
|
background = sand2;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
background = stone;
|
background = stone;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package Applicatie;
|
||||||
|
|
||||||
|
import java.awt.FlowLayout;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
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.Path;
|
||||||
|
|
||||||
|
public class PathPopup extends JFrame
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1;
|
||||||
|
|
||||||
|
public PathPopup(Path p, Panel panel)
|
||||||
|
{
|
||||||
|
super("");
|
||||||
|
setDefaultCloseOperation(HIDE_ON_CLOSE);
|
||||||
|
JPanel content = new JPanel();
|
||||||
|
content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
|
||||||
|
JPanel south = new JPanel(new FlowLayout());
|
||||||
|
JPanel center = new JPanel();
|
||||||
|
JPanel panel1 = new JPanel();
|
||||||
|
JLabel name = new JLabel("Add WayPoint");
|
||||||
|
name.setFont(new Font("Dialog", Font.BOLD, 20));
|
||||||
|
panel1.add(name);
|
||||||
|
content.add(panel1);
|
||||||
|
content.add(center);
|
||||||
|
content.add(south);
|
||||||
|
|
||||||
|
JTextField tf = new JTextField(10);
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JButton cancel = new JButton("Cancel");
|
||||||
|
cancel.addActionListener(new ActionListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e)
|
||||||
|
{
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
south.add(edit);
|
||||||
|
south.add(cancel);
|
||||||
|
|
||||||
|
setContentPane(content);
|
||||||
|
setVisible(true);
|
||||||
|
setSize(200, 150);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+223
-65
@@ -5,8 +5,10 @@ import java.awt.Image;
|
|||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.Shape;
|
import java.awt.Shape;
|
||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
|
import java.awt.geom.Area;
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -15,6 +17,7 @@ import Agenda.Event;
|
|||||||
import Objects.DrawObject;
|
import Objects.DrawObject;
|
||||||
import Objects.Entrance;
|
import Objects.Entrance;
|
||||||
import Objects.Path;
|
import Objects.Path;
|
||||||
|
import Objects.Stage;
|
||||||
|
|
||||||
public class Visitor
|
public class Visitor
|
||||||
{
|
{
|
||||||
@@ -27,21 +30,28 @@ public class Visitor
|
|||||||
ArrayList<Action> actions;
|
ArrayList<Action> actions;
|
||||||
Agenda agenda;
|
Agenda agenda;
|
||||||
ArrayList<DrawObject> objects;
|
ArrayList<DrawObject> objects;
|
||||||
int target;
|
|
||||||
|
|
||||||
public Visitor(String filename, Point2D position, Agenda agenda, ArrayList<DrawObject> objects)
|
ArrayList<Waypoint> waypoints;
|
||||||
|
GregorianCalendar date;
|
||||||
|
int target;
|
||||||
|
int finalTarget;
|
||||||
|
|
||||||
|
public Visitor(String filename, Point2D position, Agenda agenda, ArrayList<DrawObject> objects, ArrayList<Waypoint> waypoints, GregorianCalendar date)
|
||||||
|
|
||||||
{
|
{
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.filename = filename;
|
this.filename = filename;
|
||||||
this.rotation = 0;
|
this.rotation = 0;
|
||||||
this.speed = 1 + Math.random() * 4;
|
this.speed = 1 + Math.random() * 4;
|
||||||
|
this.waypoints = waypoints;
|
||||||
|
this.date = date;
|
||||||
scale = 1;
|
scale = 1;
|
||||||
actions = new ArrayList<Action>();
|
actions = new ArrayList<Action>();
|
||||||
this.agenda = agenda;
|
this.agenda = agenda;
|
||||||
this.objects = objects;
|
this.objects = objects;
|
||||||
fillActions();
|
fillActions();
|
||||||
System.out.println(actions.size());
|
target = 1;
|
||||||
target = 0;
|
finalTarget = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(Graphics2D g2)
|
public void draw(Graphics2D g2)
|
||||||
@@ -63,29 +73,119 @@ public class Visitor
|
|||||||
|
|
||||||
public DrawObject getEntrance()
|
public DrawObject getEntrance()
|
||||||
{
|
{
|
||||||
for(DrawObject o : objects)
|
for (DrawObject o : objects)
|
||||||
{
|
{
|
||||||
if(o instanceof Entrance)
|
if (o instanceof Entrance)
|
||||||
{
|
{
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(ArrayList<DrawObject> objects, int currentTime, ArrayList<Visitor> visitors, ArrayList<Path> paths)
|
public void update(ArrayList<DrawObject> objects, int currentTime, ArrayList<Visitor> visitors, ArrayList<Path> paths, Panel panel)
|
||||||
{
|
{
|
||||||
DrawObject target = getEntrance();
|
DrawObject target = getEntrance();
|
||||||
for (Action a : actions)
|
for (Action a : actions)
|
||||||
{
|
{
|
||||||
if (currentTime >= a.getStartTime() && currentTime < a.getStoptime())
|
if (currentTime >= a.getStartTime() && currentTime < a.getStoptime())
|
||||||
{
|
{
|
||||||
target = a.getTargetObject();
|
this.finalTarget = a.getWaypoint().getSelf();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
System.out.println(actions.size());
|
||||||
|
|
||||||
moveToTarget(target, objects, visitors, paths);
|
// moveToTarget(target, objects, visitors, paths);
|
||||||
|
move(target, panel);
|
||||||
|
}
|
||||||
|
|
||||||
|
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))
|
||||||
|
{
|
||||||
|
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())
|
||||||
|
{
|
||||||
|
for (int i : e.getValue())
|
||||||
|
{
|
||||||
|
if (finalTarget != target)
|
||||||
|
{
|
||||||
|
if (finalTarget == i && e.getKey() == target)
|
||||||
|
{
|
||||||
|
target = finalTarget;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (finalTarget == i)
|
||||||
|
{
|
||||||
|
target = e.getKey();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
public void moveToTarget(DrawObject target, ArrayList<DrawObject> objects, ArrayList<Visitor> visitors, ArrayList<Path> paths)
|
||||||
@@ -100,7 +200,7 @@ public class Visitor
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Shape containsShape = p.containsPointShape(position);
|
Shape containsShape = p.containsPointShape(position);
|
||||||
if(containsShape != null)
|
if (containsShape != null)
|
||||||
{
|
{
|
||||||
tar = new Point2D.Double(containsShape.getBounds().getCenterX(), containsShape.getBounds().getCenterY());
|
tar = new Point2D.Double(containsShape.getBounds().getCenterX(), containsShape.getBounds().getCenterY());
|
||||||
}
|
}
|
||||||
@@ -137,14 +237,15 @@ public class Visitor
|
|||||||
boolean possible = true;
|
boolean possible = true;
|
||||||
for (DrawObject object : objects)
|
for (DrawObject object : objects)
|
||||||
{
|
{
|
||||||
if (hitTest(object))
|
if (hasCollisionDO(object))
|
||||||
{
|
{
|
||||||
possible = false;
|
possible = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Visitor object : visitors)
|
for (Visitor object : visitors)
|
||||||
{
|
{
|
||||||
if (hitTestVisitor(object) && object != this)
|
|
||||||
|
if (hasCollision(object) && object != this)
|
||||||
{
|
{
|
||||||
possible = false;
|
possible = false;
|
||||||
}
|
}
|
||||||
@@ -208,27 +309,23 @@ public class Visitor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastShape = values.get(lastdistance);
|
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 difx = (int) (target2.getX() - position.getX());
|
||||||
int dify = (int) (target2.getY() - position.getY());
|
int dify = (int) (target2.getY() - position.getY());
|
||||||
int distance = (int) Math.sqrt((difx * difx) + (dify * dify));
|
int distance = (int) Math.sqrt((difx * difx) + (dify * dify));
|
||||||
|
|
||||||
System.out.println(rotation);
|
if (rotation > newRot && distance > 10)
|
||||||
System.out.println(newRot);
|
{
|
||||||
System.out.println("--------------");
|
rotation -= 0.15;
|
||||||
// if (rotation > newRot && distance > 10)
|
}
|
||||||
// {
|
else if (rotation < newRot && distance > 10)
|
||||||
// rotation -= 0.15;
|
{
|
||||||
// }
|
rotation += 0.15;
|
||||||
// else if (rotation < newRot && distance > 10)
|
}
|
||||||
// {
|
|
||||||
// rotation += 0.15;
|
|
||||||
// }
|
|
||||||
rotation = newRot;
|
|
||||||
|
|
||||||
Point2D oldPosition = position;
|
Point2D oldPosition = position;
|
||||||
|
|
||||||
@@ -244,14 +341,14 @@ public class Visitor
|
|||||||
boolean possible = true;
|
boolean possible = true;
|
||||||
for (DrawObject object : objects)
|
for (DrawObject object : objects)
|
||||||
{
|
{
|
||||||
if (hitTest(object))
|
if (hasCollisionDO(object))
|
||||||
{
|
{
|
||||||
possible = false;
|
possible = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Visitor object : visitors)
|
for (Visitor object : visitors)
|
||||||
{
|
{
|
||||||
if (hitTestVisitor(object) && object != this)
|
if (hasCollision(object) && object != this)
|
||||||
{
|
{
|
||||||
possible = false;
|
possible = false;
|
||||||
}
|
}
|
||||||
@@ -264,6 +361,7 @@ public class Visitor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("static-access")
|
||||||
public void fillActions()
|
public void fillActions()
|
||||||
{
|
{
|
||||||
int startTime = 540;
|
int startTime = 540;
|
||||||
@@ -272,65 +370,91 @@ public class Visitor
|
|||||||
while (startTime < stopTime)
|
while (startTime < stopTime)
|
||||||
{
|
{
|
||||||
int random = (int) Math.floor(Math.random() * 51);
|
int random = (int) Math.floor(Math.random() * 51);
|
||||||
if (random < 30)
|
if (random < 40)
|
||||||
{
|
{
|
||||||
Point2D position = null;
|
Point2D position = null;
|
||||||
DrawObject targetStage = null;
|
DrawObject targetStage = null;
|
||||||
|
ArrayList<Event> posEvents = new ArrayList<Event>();
|
||||||
for (Event e : agenda.getEvents())
|
for (Event e : agenda.getEvents())
|
||||||
{
|
{
|
||||||
if (convertMinutesToHours(startTime) > e.getStart() && convertMinutesToHours(startTime) < e.getStop())
|
if (startTime >= e.getStart() && startTime < e.getStop())
|
||||||
{
|
{
|
||||||
for (DrawObject d : objects)
|
posEvents.add(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (posEvents.size() != 0)
|
||||||
|
{
|
||||||
|
int r = (int) Math.floor(Math.random() * posEvents.size());
|
||||||
|
Event evs = posEvents.get(r);
|
||||||
|
for (DrawObject d : objects)
|
||||||
|
{
|
||||||
|
if (d.getFileName().equals("stage"))
|
||||||
{
|
{
|
||||||
if (d.getFileName().equals(e.getStage().getName()))
|
Stage s = (Stage) d;
|
||||||
|
if (s.getStage().getName().equals(evs.getStage().getName()))
|
||||||
{
|
{
|
||||||
position = d.getPosition();
|
position = s.getPosition();
|
||||||
targetStage = d;
|
targetStage = d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int randomtime = (int) (40 + (Math.random() * (60 - 40)));
|
int randomtime = (int) (40 + (Math.random() * (60 - 40)));
|
||||||
if (position != null)
|
if (position != null)
|
||||||
{
|
{
|
||||||
actions.add(new Action(position, startTime, randomtime, targetStage));
|
Waypoint w = getClosestWaypoint(position);
|
||||||
|
actions.add(new Action(position, startTime, randomtime, targetStage, w));
|
||||||
}
|
}
|
||||||
startTime = startTime + randomtime;
|
startTime = startTime + randomtime;
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (random >= 30 && random < 35)
|
else if (random >= 40 && random < 45)
|
||||||
{
|
{
|
||||||
Point2D position = null;
|
Point2D position = null;
|
||||||
DrawObject targetDraw = null;
|
DrawObject targetStage = null;
|
||||||
|
ArrayList<DrawObject> foodPlaces = new ArrayList<DrawObject>();
|
||||||
for (DrawObject d : objects)
|
for (DrawObject d : objects)
|
||||||
{
|
{
|
||||||
if (d.getFileName().equals("entrance"))
|
if (d.getFileName().equals("food"))
|
||||||
{
|
{
|
||||||
position = d.getPosition();
|
foodPlaces.add(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (position != null)
|
|
||||||
|
if (foodPlaces.size() != 0)
|
||||||
{
|
{
|
||||||
actions.add(new Action(position, startTime, 35, targetDraw));
|
int r = (int) Math.floor(Math.random() * foodPlaces.size());
|
||||||
startTime = startTime + 35;
|
position = foodPlaces.get(r).getPosition();
|
||||||
|
targetStage = foodPlaces.get(r);
|
||||||
|
Waypoint w = getClosestWaypoint(position);
|
||||||
|
actions.add(new Action(position, startTime, 35, targetStage, w));
|
||||||
|
startTime = startTime + 20;
|
||||||
}
|
}
|
||||||
startTime = startTime + 35;
|
startTime = startTime + 35;
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (random > 35)
|
else if (random > 45)
|
||||||
{
|
{
|
||||||
Point2D position = null;
|
Point2D position = null;
|
||||||
DrawObject targetDrawobj = null;
|
DrawObject targetStage = null;
|
||||||
|
ArrayList<DrawObject> toilets = new ArrayList<DrawObject>();
|
||||||
for (DrawObject d : objects)
|
for (DrawObject d : objects)
|
||||||
{
|
{
|
||||||
if (d.getFileName().equals("wc"))
|
if (d.getFileName().equals("wc"))
|
||||||
{
|
{
|
||||||
position = d.getPosition();
|
toilets.add(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (position != null)
|
if (toilets.size() != 0)
|
||||||
{
|
{
|
||||||
actions.add(new Action(position, startTime, 35, targetDrawobj));
|
int r = (int) Math.floor(Math.random() * toilets.size());
|
||||||
|
position = toilets.get(r).getPosition();
|
||||||
|
targetStage = toilets.get(r);
|
||||||
|
Waypoint w = getClosestWaypoint(position);
|
||||||
|
actions.add(new Action(position, startTime, 35, targetStage, w));
|
||||||
|
startTime = startTime + 20;
|
||||||
}
|
}
|
||||||
startTime = startTime + 35;
|
startTime = startTime + 35;
|
||||||
|
|
||||||
@@ -338,35 +462,69 @@ public class Visitor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int convertMinutesToHours(int startTime)
|
public Waypoint getClosestWaypoint(Point2D point)
|
||||||
{
|
{
|
||||||
int time = 0;
|
Waypoint waypoint = null;
|
||||||
int hours = startTime / 60;
|
int distance = 10000;
|
||||||
int minutes = startTime % 60;
|
for (Waypoint w : waypoints)
|
||||||
time = (hours * 100) + minutes;
|
{
|
||||||
return time;
|
if (w.getPosition().distance(point) < distance)
|
||||||
|
{
|
||||||
|
waypoint = w;
|
||||||
|
distance = (int) w.getPosition().distance(point);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return waypoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEndX()
|
public boolean hasCollisionDO(DrawObject object)
|
||||||
{
|
{
|
||||||
Image image = Images.getImage(filename);
|
Image image = Images.getImage(filename);
|
||||||
return (int) (position.getX() + image.getWidth(null));
|
Image image2 = Images.getImage(object.getFileName());
|
||||||
|
Rectangle recta = new Rectangle((int) position.getX(), (int) position.getY(), image.getWidth(null), image.getHeight(null));
|
||||||
|
Rectangle rectb = new Rectangle((int) object.getPosition().getX(), (int) object.getPosition().getY(), image2.getWidth(null), image2.getHeight(null));
|
||||||
|
|
||||||
|
Area a = new Area(recta);
|
||||||
|
Area b = new Area(rectb);
|
||||||
|
|
||||||
|
AffineTransform transA = new AffineTransform();
|
||||||
|
transA.rotate(rotation, position.getX(), position.getY());
|
||||||
|
|
||||||
|
AffineTransform transB = new AffineTransform();
|
||||||
|
transB.rotate(Math.toRadians(object.getRotation()), object.getPosition().getX(), object.getPosition().getY());
|
||||||
|
|
||||||
|
Area aa = a.createTransformedArea(transA);
|
||||||
|
Area bb = b.createTransformedArea(transB);
|
||||||
|
|
||||||
|
if (bb.intersects(aa.getBounds2D()))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEndY()
|
public boolean hasCollision(Visitor v)
|
||||||
{
|
{
|
||||||
Image image = Images.getImage(filename);
|
Image image = Images.getImage(filename);
|
||||||
return (int) (position.getY() + image.getHeight(null));
|
Rectangle a = new Rectangle((int) position.getX(), (int) position.getY(), image.getWidth(null), image.getHeight(null));
|
||||||
}
|
Rectangle b = new Rectangle((int) v.position.getX(), (int) v.position.getY(), image.getWidth(null), image.getHeight(null));
|
||||||
|
|
||||||
public boolean hitTest(DrawObject to2)
|
Area aa = new Area(a);
|
||||||
{
|
Area bb = new Area(b);
|
||||||
return (getEndX() >= to2.getPosition().getX() && getEndY() >= to2.getPosition().getY() && to2.getEndX() >= position.getX() && to2.getEndY() >= position.getY());
|
|
||||||
|
|
||||||
}
|
AffineTransform af = new AffineTransform();
|
||||||
|
af.rotate(rotation, position.getX(), position.getY());
|
||||||
|
|
||||||
public boolean hitTestVisitor(Visitor v)
|
AffineTransform bf = new AffineTransform();
|
||||||
{
|
bf.rotate(v.rotation, v.position.getX(), v.position.getY());
|
||||||
return (getEndX() >= v.position.getX() && getEndY() >= v.position.getY() && v.getEndX() >= position.getX() && v.getEndY() >= position.getY());
|
|
||||||
|
Area ra = aa.createTransformedArea(af);
|
||||||
|
Area rb = bb.createTransformedArea(bf);
|
||||||
|
|
||||||
|
if (ra.intersects(rb.getBounds2D()))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
package Applicatie;
|
package Applicatie;
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Dimension;
|
||||||
import java.awt.FlowLayout;
|
import java.awt.FlowLayout;
|
||||||
import java.awt.GridLayout;
|
import java.awt.Font;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
import javax.swing.Box;
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
@@ -16,25 +19,82 @@ import Objects.DrawObject;
|
|||||||
public class WaypointPopup extends JFrame {
|
public class WaypointPopup extends JFrame {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1;
|
private static final long serialVersionUID = 1;
|
||||||
|
private JLabel title;
|
||||||
|
|
||||||
public WaypointPopup(DrawObject w)
|
public WaypointPopup(DrawObject w, Panel panel)
|
||||||
{
|
{
|
||||||
super("Artist editscreen!");
|
super("Edit WayPoint");
|
||||||
Waypoint wp = (Waypoint) w;
|
Waypoint wp = (Waypoint) w;
|
||||||
setDefaultCloseOperation(HIDE_ON_CLOSE);
|
setDefaultCloseOperation(HIDE_ON_CLOSE);
|
||||||
JPanel content = new JPanel(new BorderLayout());
|
JPanel content = new JPanel(new BorderLayout());
|
||||||
JPanel south = new JPanel(new FlowLayout());
|
JPanel north = new JPanel();
|
||||||
JPanel center = new JPanel(new GridLayout(5,2));
|
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(south, BorderLayout.SOUTH);
|
||||||
content.add(center, BorderLayout.CENTER);
|
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();
|
JPanel panel1 = new JPanel();
|
||||||
JLabel name = new JLabel("Waypoint");
|
JLabel name = new JLabel("Waypoint");
|
||||||
|
name.setFont(new Font("Dialog", Font.PLAIN, 20));
|
||||||
panel1.add(name);
|
panel1.add(name);
|
||||||
center.add(panel1);
|
row1.add(panel1);
|
||||||
|
|
||||||
JTextField tf = new JTextField(5);
|
JTextField tf = new JTextField(wp.getSelf() + "", 10);
|
||||||
center.add(tf);
|
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);
|
||||||
|
|
||||||
|
String optionss = "";
|
||||||
|
if(wp.getOptions() != null)
|
||||||
|
{
|
||||||
|
if(wp.getOptions().length != 0)
|
||||||
|
{
|
||||||
|
int[] optionsa = wp.getOptions();
|
||||||
|
optionss += optionsa[0];
|
||||||
|
for(int i = 1; i < optionsa.length; i++)
|
||||||
|
{
|
||||||
|
optionss += "-" + optionsa[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JTextField tx = new JTextField("" + optionss, 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");
|
JButton edit = new JButton("Done");
|
||||||
edit.addActionListener(new ActionListener()
|
edit.addActionListener(new ActionListener()
|
||||||
@@ -44,14 +104,34 @@ public class WaypointPopup extends JFrame {
|
|||||||
public void actionPerformed(ActionEvent e)
|
public void actionPerformed(ActionEvent e)
|
||||||
{
|
{
|
||||||
wp.setSelf(Integer.valueOf(tf.getText()));
|
wp.setSelf(Integer.valueOf(tf.getText()));
|
||||||
|
panel.addWaypoint(wp);
|
||||||
dispose();
|
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);
|
south.add(edit);
|
||||||
|
|
||||||
|
JButton cancel = new JButton("Cancel");
|
||||||
|
cancel.addActionListener(new ActionListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e)
|
||||||
|
{
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
south.add(cancel);
|
||||||
|
|
||||||
setContentPane(content);
|
setContentPane(content);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
setSize(500,320);
|
setSize(300,250);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-4
@@ -4,7 +4,6 @@ import java.awt.Color;
|
|||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
import java.awt.geom.Rectangle2D;
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
@@ -14,7 +13,6 @@ import Applicatie.Waypoint;
|
|||||||
import Applicatie.WaypointPopup;
|
import Applicatie.WaypointPopup;
|
||||||
import Objects.DrawObject;
|
import Objects.DrawObject;
|
||||||
import Objects.Path;
|
import Objects.Path;
|
||||||
import Objects.Entrance;
|
|
||||||
|
|
||||||
public class Mouse extends MouseAdapter
|
public class Mouse extends MouseAdapter
|
||||||
{
|
{
|
||||||
@@ -76,7 +74,8 @@ public class Mouse extends MouseAdapter
|
|||||||
{
|
{
|
||||||
if (o instanceof Waypoint)
|
if (o instanceof Waypoint)
|
||||||
{
|
{
|
||||||
new WaypointPopup(o);
|
new WaypointPopup(o, panel);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (o == selectedObject)
|
if (o == selectedObject)
|
||||||
@@ -122,7 +121,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)
|
if (panel.getDragObject() == null && selectedObject != null)
|
||||||
{
|
{
|
||||||
@@ -134,7 +145,9 @@ public class Mouse extends MouseAdapter
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // Making path.
|
{ // Making path.
|
||||||
|
|
||||||
panel.getCurrentPath().addPoint(new Point2D.Double(clickPoint.getX(), clickPoint.getY()));
|
panel.getCurrentPath().addPoint(new Point2D.Double(clickPoint.getX(), clickPoint.getY()));
|
||||||
|
|
||||||
}
|
}
|
||||||
panel.repaint();
|
panel.repaint();
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-7
@@ -14,6 +14,7 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
|
import Applicatie.Panel;
|
||||||
import Applicatie.Waypoint;
|
import Applicatie.Waypoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -95,7 +96,7 @@ public class Path
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if one of the lines contains the given point.
|
* Check if one of the lines contains the given point.
|
||||||
*
|
*
|
||||||
@@ -114,12 +115,13 @@ public class Path
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean intersectsRect(Rectangle2D rect)
|
public boolean intersectsRect(Rectangle2D rect)
|
||||||
{
|
{
|
||||||
for(Shape line : getPath())
|
for (Shape line : getPath())
|
||||||
{
|
{
|
||||||
if(line.intersects(rect))
|
if (line.intersects(rect))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -144,13 +146,23 @@ public class Path
|
|||||||
lines.add(stroke.createStrokedShape(line));
|
lines.add(stroke.createStrokedShape(line));
|
||||||
}
|
}
|
||||||
return lines;
|
return lines;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addWaypoint(Waypoint w)
|
public void addWaypoint(int i, Panel panel)
|
||||||
{
|
{
|
||||||
waypoints.add(w);
|
for (Waypoint w : panel.getWaypoints())
|
||||||
|
{
|
||||||
|
if (w.getSelf() == i)
|
||||||
|
{
|
||||||
|
waypoints.add(w);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a point to the path.
|
* Add a point to the path.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user