Merge branch 'kenneth' of https://github.com/ProjectgroepA4/FestivalPlanner into kenneth
Conflicts: Applicatie/Panel.java Applicatie/Visitor.java Applicatie/WaypointPopup.java Listeners/Mouse.java
This commit is contained in:
@@ -205,9 +205,9 @@ public class AddEventPanel extends JFrame{
|
|||||||
|
|
||||||
String stageName = (String)stage2.getSelectedItem();
|
String stageName = (String)stage2.getSelectedItem();
|
||||||
|
|
||||||
AgendaStage stage = null;
|
Stage stage = null;
|
||||||
|
|
||||||
for(AgendaStage s : agenda.getStages())
|
for(Stage s : agenda.getStages())
|
||||||
{
|
{
|
||||||
if (s.getName().equals(stageName))
|
if (s.getName().equals(stageName))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public class AddStagePanel extends JFrame{
|
|||||||
String description = descriptionTF.getText();
|
String description = descriptionTF.getText();
|
||||||
|
|
||||||
boolean alreadyExists = false;
|
boolean alreadyExists = false;
|
||||||
for (AgendaStage stage : agenda.getStages())
|
for (Stage stage : agenda.getStages())
|
||||||
{
|
{
|
||||||
if (stage.getName().equals(name))
|
if (stage.getName().equals(name))
|
||||||
{
|
{
|
||||||
@@ -70,7 +70,7 @@ public class AddStagePanel extends JFrame{
|
|||||||
}
|
}
|
||||||
else if ( alreadyExists == false )
|
else if ( alreadyExists == false )
|
||||||
{
|
{
|
||||||
AgendaStage s = new AgendaStage(name,description);
|
Stage s = new Stage(name,description);
|
||||||
agenda.addStage(s);
|
agenda.addStage(s);
|
||||||
JOptionPane.showMessageDialog(null, "Stage added!");
|
JOptionPane.showMessageDialog(null, "Stage added!");
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
|
|||||||
+10
-6
@@ -17,17 +17,17 @@ public class Agenda implements Serializable {
|
|||||||
|
|
||||||
private static final long serialVersionUID = 1;
|
private static final long serialVersionUID = 1;
|
||||||
|
|
||||||
private ArrayList<AgendaStage> stages;
|
private ArrayList<Stage> stages;
|
||||||
private ArrayList<Event> events;
|
private ArrayList<Event> events;
|
||||||
private ArrayList<Artist> artists;
|
private ArrayList<Artist> artists;
|
||||||
|
|
||||||
public Agenda() {
|
public Agenda() {
|
||||||
stages = new ArrayList<AgendaStage>();
|
stages = new ArrayList<Stage>();
|
||||||
events = new ArrayList<Event>();
|
events = new ArrayList<Event>();
|
||||||
artists = new ArrayList<Artist>();
|
artists = new ArrayList<Artist>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addStage(AgendaStage stage){
|
public void addStage(Stage stage){
|
||||||
stages.add(stage);
|
stages.add(stage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,11 +47,12 @@ public class Agenda implements Serializable {
|
|||||||
{
|
{
|
||||||
return artists;
|
return artists;
|
||||||
}
|
}
|
||||||
public ArrayList<AgendaStage> getStages()
|
public ArrayList<Stage> getStages()
|
||||||
{
|
{
|
||||||
return stages;
|
return stages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
public void saveAgenda()
|
public void saveAgenda()
|
||||||
{
|
{
|
||||||
JFileChooser fileChooser = new JFileChooser();
|
JFileChooser fileChooser = new JFileChooser();
|
||||||
@@ -179,7 +180,7 @@ public class Agenda implements Serializable {
|
|||||||
{
|
{
|
||||||
boolean exists = false;
|
boolean exists = false;
|
||||||
String name = e.getStage().getName();
|
String name = e.getStage().getName();
|
||||||
for (AgendaStage s : stages)
|
for (Stage s : stages)
|
||||||
{
|
{
|
||||||
if ( s.getName().equals(name) ) {
|
if ( s.getName().equals(name) ) {
|
||||||
exists = true;
|
exists = true;
|
||||||
@@ -202,7 +203,8 @@ public class Agenda implements Serializable {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
public void clearAgenda()
|
public void clearAgenda()
|
||||||
{
|
{
|
||||||
@@ -211,10 +213,12 @@ public class Agenda implements Serializable {
|
|||||||
artists.clear();
|
artists.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
public void fillAllLists()
|
public void fillAllLists()
|
||||||
{
|
{
|
||||||
loadAgenda();
|
loadAgenda();
|
||||||
fillStages();
|
fillStages();
|
||||||
fillArtists();
|
fillArtists();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -221,9 +221,9 @@ public class EditEventPanel extends JFrame{
|
|||||||
|
|
||||||
String stageName = (String)stage2.getSelectedItem();
|
String stageName = (String)stage2.getSelectedItem();
|
||||||
|
|
||||||
AgendaStage stage = null;
|
Stage stage = null;
|
||||||
|
|
||||||
for(AgendaStage s : agenda.getStages())
|
for(Stage s : agenda.getStages())
|
||||||
{
|
{
|
||||||
if (s.getName().equals(stageName))
|
if (s.getName().equals(stageName))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class EditStagePanel extends JFrame{
|
|||||||
|
|
||||||
private static final long serialVersionUID = 1;
|
private static final long serialVersionUID = 1;
|
||||||
|
|
||||||
public EditStagePanel(Agenda agenda, AgendaStage sta)
|
public EditStagePanel(Agenda agenda, Stage sta)
|
||||||
{
|
{
|
||||||
super("Stage editscreen!");
|
super("Stage editscreen!");
|
||||||
setDefaultCloseOperation(HIDE_ON_CLOSE);
|
setDefaultCloseOperation(HIDE_ON_CLOSE);
|
||||||
@@ -59,7 +59,7 @@ public class EditStagePanel extends JFrame{
|
|||||||
String description = descriptionTF.getText();
|
String description = descriptionTF.getText();
|
||||||
|
|
||||||
boolean alreadyExists = false;
|
boolean alreadyExists = false;
|
||||||
for (AgendaStage stage : agenda.getStages())
|
for (Stage stage : agenda.getStages())
|
||||||
{
|
{
|
||||||
if (stage.getName().equals(name) && !stage.equals(sta))
|
if (stage.getName().equals(name) && !stage.equals(sta))
|
||||||
{
|
{
|
||||||
@@ -101,10 +101,10 @@ public class EditStagePanel extends JFrame{
|
|||||||
|
|
||||||
if(JOptionPane.showConfirmDialog(null, "Are you sure you want to remove this stage?", "Remove Stage", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION)
|
if(JOptionPane.showConfirmDialog(null, "Are you sure you want to remove this stage?", "Remove Stage", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION)
|
||||||
{
|
{
|
||||||
Iterator<AgendaStage> it = agenda.getStages().iterator();
|
Iterator<Stage> it = agenda.getStages().iterator();
|
||||||
while(it.hasNext())
|
while(it.hasNext())
|
||||||
{
|
{
|
||||||
AgendaStage s = it.next();
|
Stage s = it.next();
|
||||||
if(s.equals(sta))
|
if(s.equals(sta))
|
||||||
{
|
{
|
||||||
it.remove();
|
it.remove();
|
||||||
|
|||||||
+5
-5
@@ -19,13 +19,13 @@ public class Event implements Serializable {
|
|||||||
private int stopHour;
|
private int stopHour;
|
||||||
private int stopMinute;
|
private int stopMinute;
|
||||||
private Artist artist;
|
private Artist artist;
|
||||||
private AgendaStage stage;
|
private Stage stage;
|
||||||
private String description;
|
private String description;
|
||||||
private int expectedPopularity;
|
private int expectedPopularity;
|
||||||
|
|
||||||
public Event(String eventName, int startYear, int startMonth, int startDay,
|
public Event(String eventName, int startYear, int startMonth, int startDay,
|
||||||
int startHour, int startMinute, int endYear, int endMonth,
|
int startHour, int startMinute, int endYear, int endMonth,
|
||||||
int endDay, int endHour, int endMinute, Artist artist, AgendaStage stage,
|
int endDay, int endHour, int endMinute, Artist artist, Stage stage,
|
||||||
String description, int expectedPopularity) {
|
String description, int expectedPopularity) {
|
||||||
this.eventName = eventName;
|
this.eventName = eventName;
|
||||||
this.startDate = new GregorianCalendar(startYear, startMonth - 1,
|
this.startDate = new GregorianCalendar(startYear, startMonth - 1,
|
||||||
@@ -43,7 +43,7 @@ public class Event implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Event(String eventName, GregorianCalendar startDate,
|
public Event(String eventName, GregorianCalendar startDate,
|
||||||
GregorianCalendar endDate, Artist artist, AgendaStage stage,
|
GregorianCalendar endDate, Artist artist, Stage stage,
|
||||||
String description, int expectedPopularity) {
|
String description, int expectedPopularity) {
|
||||||
this.eventName = eventName;
|
this.eventName = eventName;
|
||||||
this.startDate = startDate;
|
this.startDate = startDate;
|
||||||
@@ -86,7 +86,7 @@ public class Event implements Serializable {
|
|||||||
return this.description;
|
return this.description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AgendaStage getStage() {
|
public Stage getStage() {
|
||||||
return this.stage;
|
return this.stage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@ public class Event implements Serializable {
|
|||||||
this.expectedPopularity = popularity;
|
this.expectedPopularity = popularity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStage(AgendaStage stage) {
|
public void setStage(Stage stage) {
|
||||||
this.stage = stage;
|
this.stage = stage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -63,7 +63,7 @@ public class MenuBar extends JMenuBar {
|
|||||||
open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
|
open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
|
||||||
open.addActionListener(new ActionListener() {
|
open.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
w.getAgenda().loadAgenda();
|
Applicatie.SaveLoad.load(w.getPanel());
|
||||||
Window.updatePanel();
|
Window.updatePanel();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -72,7 +72,7 @@ public class MenuBar extends JMenuBar {
|
|||||||
save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
|
save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
|
||||||
save.addActionListener(new ActionListener() {
|
save.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
w.getAgenda().saveAgenda();
|
Applicatie.SaveLoad.save(w.getPanel());
|
||||||
Window.updatePanel();
|
Window.updatePanel();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ public class PanelArtSta extends JPanel implements Panel{
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
dataStage = new Object[1];
|
dataStage = new Object[1];
|
||||||
dataStage[0] = new AgendaStage("Geen Stages", "Geen Stages");
|
dataStage[0] = new Stage("Geen Stages", "Geen Stages");
|
||||||
stages.setEnabled(false);
|
stages.setEnabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package Agenda;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class Stage implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
public Stage(String name, String description)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription()
|
||||||
|
{
|
||||||
|
return this.description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description)
|
||||||
|
{
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
-2
@@ -36,14 +36,16 @@ public class Window extends JFrame {
|
|||||||
private static GregorianCalendar date;
|
private static GregorianCalendar date;
|
||||||
private static Agenda agenda;
|
private static Agenda agenda;
|
||||||
private static String currentPanel = "table";
|
private static String currentPanel = "table";
|
||||||
|
private Applicatie.Panel ap;
|
||||||
|
|
||||||
public Window()
|
public Window(Applicatie.Panel ap)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Initialize window
|
* Initialize window
|
||||||
*/
|
*/
|
||||||
super("Agenda");
|
super("Agenda");
|
||||||
agenda = new Agenda();
|
this.ap = ap;
|
||||||
|
agenda = ap.getAgenda();
|
||||||
|
|
||||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||||
addWindowListener(new WindowAdapter() {
|
addWindowListener(new WindowAdapter() {
|
||||||
@@ -231,6 +233,12 @@ public class Window extends JFrame {
|
|||||||
public void setAgenda(Agenda a)
|
public void setAgenda(Agenda a)
|
||||||
{
|
{
|
||||||
agenda = a;
|
agenda = a;
|
||||||
|
ap.setAgenda(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Applicatie.Panel getPanel()
|
||||||
|
{
|
||||||
|
return ap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -115,7 +115,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();
|
p.addVisitors(1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
peoplePanel.add(peopleButton);
|
peoplePanel.add(peopleButton);
|
||||||
|
|||||||
+1
-21
@@ -28,16 +28,6 @@ public class MenuBar extends JMenuBar
|
|||||||
});
|
});
|
||||||
file.add(item);
|
file.add(item);
|
||||||
|
|
||||||
JMenuItem agenda = new JMenuItem("Open Agenda");
|
|
||||||
agenda.addActionListener(new ActionListener()
|
|
||||||
{
|
|
||||||
public void actionPerformed(ActionEvent e)
|
|
||||||
{
|
|
||||||
new Agenda.Window();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
file.add(agenda);
|
|
||||||
|
|
||||||
item = new JMenuItem("Open");
|
item = new JMenuItem("Open");
|
||||||
item.addActionListener(new ActionListener() {
|
item.addActionListener(new ActionListener() {
|
||||||
|
|
||||||
@@ -60,22 +50,12 @@ public class MenuBar extends JMenuBar
|
|||||||
|
|
||||||
file.addSeparator();
|
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 = new JMenuItem("Agenda");
|
||||||
item.addActionListener(new ActionListener()
|
item.addActionListener(new ActionListener()
|
||||||
{
|
{
|
||||||
public void actionPerformed(ActionEvent e)
|
public void actionPerformed(ActionEvent e)
|
||||||
{
|
{
|
||||||
new Agenda.Window();
|
new Agenda.Window(w.getPanel());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
file.add(item);
|
file.add(item);
|
||||||
|
|||||||
+26
-85
@@ -23,12 +23,10 @@ import java.util.GregorianCalendar;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.Timer;
|
import javax.swing.Timer;
|
||||||
|
|
||||||
import Agenda.Agenda;
|
import Agenda.Agenda;
|
||||||
import Agenda.AgendaStage;
|
|
||||||
import Listeners.Mouse;
|
import Listeners.Mouse;
|
||||||
import Listeners.MouseMotion;
|
import Listeners.MouseMotion;
|
||||||
import Listeners.MouseWheel;
|
import Listeners.MouseWheel;
|
||||||
@@ -73,7 +71,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();
|
||||||
Timer t;
|
javax.swing.Timer t;
|
||||||
|
|
||||||
SimpleDateFormat formatter;
|
SimpleDateFormat formatter;
|
||||||
GregorianCalendar date;
|
GregorianCalendar date;
|
||||||
@@ -146,8 +144,9 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,26 +166,7 @@ public class Panel extends JPanel implements ActionListener
|
|||||||
switch (index)
|
switch (index)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
ArrayList<AgendaStage> stages = agenda.getStages();
|
return new Stage(null);
|
||||||
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;
|
|
||||||
}
|
|
||||||
case 1:
|
case 1:
|
||||||
return new Toilet(null);
|
return new Toilet(null);
|
||||||
case 2:
|
case 2:
|
||||||
@@ -211,18 +191,6 @@ 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()
|
||||||
{
|
{
|
||||||
@@ -231,27 +199,14 @@ public class Panel extends JPanel implements ActionListener
|
|||||||
|
|
||||||
public void addVisitors()
|
public void addVisitors()
|
||||||
{
|
{
|
||||||
ArrayList<DrawObject> entrances = new ArrayList<>();
|
visitors.add(new Visitor("visitor", new Point(100, 300), agenda, objects));
|
||||||
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)
|
public void addVisitors(int count)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
addVisitors();
|
visitors.add(new Visitor("visitor", new Point(100, 300), agenda, objects));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -563,27 +518,13 @@ 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.
|
||||||
@@ -616,17 +557,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)
|
||||||
{
|
{
|
||||||
@@ -642,7 +583,7 @@ public class Panel extends JPanel implements ActionListener
|
|||||||
|
|
||||||
for (Visitor v : visitors)
|
for (Visitor v : visitors)
|
||||||
{
|
{
|
||||||
v.update(objects, currentTime, visitors, paths, this);
|
v.update(objects, currentTime, visitors, paths);
|
||||||
}
|
}
|
||||||
repaint();
|
repaint();
|
||||||
|
|
||||||
@@ -669,25 +610,25 @@ 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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import javax.swing.JFileChooser;
|
|||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.filechooser.FileFilter;
|
import javax.swing.filechooser.FileFilter;
|
||||||
|
|
||||||
|
import Agenda.Agenda;
|
||||||
import Objects.DrawObject;
|
import Objects.DrawObject;
|
||||||
|
|
||||||
public class SaveLoad {
|
public class SaveLoad {
|
||||||
@@ -66,6 +67,7 @@ public class SaveLoad {
|
|||||||
try {
|
try {
|
||||||
FileOutputStream fos = new FileOutputStream(file);
|
FileOutputStream fos = new FileOutputStream(file);
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||||
|
oos.writeObject(panel.getAgenda());
|
||||||
for (DrawObject object : panel.objects) {
|
for (DrawObject object : panel.objects) {
|
||||||
oos.writeObject(object);
|
oos.writeObject(object);
|
||||||
}
|
}
|
||||||
@@ -124,8 +126,10 @@ public class SaveLoad {
|
|||||||
ois = new ObjectInputStream(fis);
|
ois = new ObjectInputStream(fis);
|
||||||
|
|
||||||
Object object;
|
Object object;
|
||||||
object = ois.readObject();
|
Agenda a = (Agenda) ois.readObject();
|
||||||
|
panel.setAgenda(a);
|
||||||
try {
|
try {
|
||||||
|
object = ois.readObject();
|
||||||
panel.clearObjects();
|
panel.clearObjects();
|
||||||
while (object != null) {
|
while (object != null) {
|
||||||
panel.objects.add((DrawObject) object);
|
panel.objects.add((DrawObject) object);
|
||||||
|
|||||||
+64
-222
@@ -5,10 +5,8 @@ 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;
|
||||||
|
|
||||||
@@ -17,7 +15,6 @@ 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
|
||||||
{
|
{
|
||||||
@@ -30,28 +27,21 @@ public class Visitor
|
|||||||
ArrayList<Action> actions;
|
ArrayList<Action> actions;
|
||||||
Agenda agenda;
|
Agenda agenda;
|
||||||
ArrayList<DrawObject> objects;
|
ArrayList<DrawObject> objects;
|
||||||
|
|
||||||
ArrayList<Waypoint> waypoints;
|
|
||||||
GregorianCalendar date;
|
|
||||||
int target;
|
int target;
|
||||||
int finalTarget;
|
|
||||||
|
|
||||||
public Visitor(String filename, Point2D position, Agenda agenda, ArrayList<DrawObject> objects, ArrayList<Waypoint> waypoints, GregorianCalendar date)
|
|
||||||
|
|
||||||
|
public Visitor(String filename, Point2D position, Agenda agenda, ArrayList<DrawObject> objects)
|
||||||
{
|
{
|
||||||
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();
|
||||||
target = 1;
|
System.out.println(actions.size());
|
||||||
finalTarget = 0;
|
target = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(Graphics2D g2)
|
public void draw(Graphics2D g2)
|
||||||
@@ -73,119 +63,29 @@ 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, Panel panel)
|
public void update(ArrayList<DrawObject> objects, int currentTime, ArrayList<Visitor> visitors, ArrayList<Path> paths)
|
||||||
{
|
{
|
||||||
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())
|
||||||
{
|
{
|
||||||
this.finalTarget = a.getWaypoint().getSelf();
|
target = a.getTargetObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
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)
|
||||||
@@ -200,7 +100,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());
|
||||||
}
|
}
|
||||||
@@ -237,15 +137,14 @@ public class Visitor
|
|||||||
boolean possible = true;
|
boolean possible = true;
|
||||||
for (DrawObject object : objects)
|
for (DrawObject object : objects)
|
||||||
{
|
{
|
||||||
if (hasCollisionDO(object))
|
if (hitTest(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;
|
||||||
}
|
}
|
||||||
@@ -309,23 +208,27 @@ 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));
|
||||||
|
|
||||||
if (rotation > newRot && distance > 10)
|
System.out.println(rotation);
|
||||||
{
|
System.out.println(newRot);
|
||||||
rotation -= 0.15;
|
System.out.println("--------------");
|
||||||
}
|
// 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;
|
||||||
|
|
||||||
@@ -341,14 +244,14 @@ public class Visitor
|
|||||||
boolean possible = true;
|
boolean possible = true;
|
||||||
for (DrawObject object : objects)
|
for (DrawObject object : objects)
|
||||||
{
|
{
|
||||||
if (hasCollisionDO(object))
|
if (hitTest(object))
|
||||||
{
|
{
|
||||||
possible = false;
|
possible = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Visitor object : visitors)
|
for (Visitor object : visitors)
|
||||||
{
|
{
|
||||||
if (hasCollision(object) && object != this)
|
if (hitTestVisitor(object) && object != this)
|
||||||
{
|
{
|
||||||
possible = false;
|
possible = false;
|
||||||
}
|
}
|
||||||
@@ -361,7 +264,6 @@ public class Visitor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("static-access")
|
|
||||||
public void fillActions()
|
public void fillActions()
|
||||||
{
|
{
|
||||||
int startTime = 540;
|
int startTime = 540;
|
||||||
@@ -370,91 +272,65 @@ 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 < 40)
|
if (random < 30)
|
||||||
{
|
{
|
||||||
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 (startTime >= e.getStart() && startTime < e.getStop())
|
if (convertMinutesToHours(startTime) > e.getStart() && convertMinutesToHours(startTime) < e.getStop())
|
||||||
{
|
{
|
||||||
posEvents.add(e);
|
for (DrawObject d : objects)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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"))
|
|
||||||
{
|
{
|
||||||
Stage s = (Stage) d;
|
if (d.getFileName().equals(e.getStage().getName()))
|
||||||
if (s.getStage().getName().equals(evs.getStage().getName()))
|
|
||||||
{
|
{
|
||||||
position = s.getPosition();
|
position = d.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)
|
||||||
{
|
{
|
||||||
Waypoint w = getClosestWaypoint(position);
|
actions.add(new Action(position, startTime, randomtime, targetStage));
|
||||||
actions.add(new Action(position, startTime, randomtime, targetStage, w));
|
|
||||||
}
|
}
|
||||||
startTime = startTime + randomtime;
|
startTime = startTime + randomtime;
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (random >= 40 && random < 45)
|
else if (random >= 30 && random < 35)
|
||||||
{
|
{
|
||||||
Point2D position = null;
|
Point2D position = null;
|
||||||
DrawObject targetStage = null;
|
DrawObject targetDraw = null;
|
||||||
ArrayList<DrawObject> foodPlaces = new ArrayList<DrawObject>();
|
|
||||||
for (DrawObject d : objects)
|
for (DrawObject d : objects)
|
||||||
{
|
{
|
||||||
if (d.getFileName().equals("food"))
|
if (d.getFileName().equals("entrance"))
|
||||||
{
|
{
|
||||||
foodPlaces.add(d);
|
position = d.getPosition();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (position != null)
|
||||||
if (foodPlaces.size() != 0)
|
|
||||||
{
|
{
|
||||||
int r = (int) Math.floor(Math.random() * foodPlaces.size());
|
actions.add(new Action(position, startTime, 35, targetDraw));
|
||||||
position = foodPlaces.get(r).getPosition();
|
startTime = startTime + 35;
|
||||||
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 > 45)
|
else if (random > 35)
|
||||||
{
|
{
|
||||||
Point2D position = null;
|
Point2D position = null;
|
||||||
DrawObject targetStage = null;
|
DrawObject targetDrawobj = 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"))
|
||||||
{
|
{
|
||||||
toilets.add(d);
|
position = d.getPosition();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (toilets.size() != 0)
|
if (position != null)
|
||||||
{
|
{
|
||||||
int r = (int) Math.floor(Math.random() * toilets.size());
|
actions.add(new Action(position, startTime, 35, targetDrawobj));
|
||||||
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;
|
||||||
|
|
||||||
@@ -462,69 +338,35 @@ public class Visitor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Waypoint getClosestWaypoint(Point2D point)
|
public int convertMinutesToHours(int startTime)
|
||||||
{
|
{
|
||||||
Waypoint waypoint = null;
|
int time = 0;
|
||||||
int distance = 10000;
|
int hours = startTime / 60;
|
||||||
for (Waypoint w : waypoints)
|
int minutes = startTime % 60;
|
||||||
{
|
time = (hours * 100) + minutes;
|
||||||
if (w.getPosition().distance(point) < distance)
|
return time;
|
||||||
{
|
|
||||||
waypoint = w;
|
|
||||||
distance = (int) w.getPosition().distance(point);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return waypoint;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasCollisionDO(DrawObject object)
|
public int getEndX()
|
||||||
{
|
{
|
||||||
Image image = Images.getImage(filename);
|
Image image = Images.getImage(filename);
|
||||||
Image image2 = Images.getImage(object.getFileName());
|
return (int) (position.getX() + image.getWidth(null));
|
||||||
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 boolean hasCollision(Visitor v)
|
public int getEndY()
|
||||||
{
|
{
|
||||||
Image image = Images.getImage(filename);
|
Image image = Images.getImage(filename);
|
||||||
Rectangle a = new Rectangle((int) position.getX(), (int) position.getY(), image.getWidth(null), image.getHeight(null));
|
return (int) (position.getY() + image.getHeight(null));
|
||||||
Rectangle b = new Rectangle((int) v.position.getX(), (int) v.position.getY(), image.getWidth(null), image.getHeight(null));
|
}
|
||||||
|
|
||||||
Area aa = new Area(a);
|
public boolean hitTest(DrawObject to2)
|
||||||
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());
|
|
||||||
|
|
||||||
AffineTransform bf = new AffineTransform();
|
public boolean hitTestVisitor(Visitor v)
|
||||||
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,13 +1,10 @@
|
|||||||
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.Font;
|
import java.awt.GridLayout;
|
||||||
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;
|
||||||
@@ -19,82 +16,25 @@ 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, Panel panel)
|
public WaypointPopup(DrawObject w)
|
||||||
{
|
{
|
||||||
super("Edit WayPoint");
|
super("Artist editscreen!");
|
||||||
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 north = new JPanel();
|
JPanel south = new JPanel(new FlowLayout());
|
||||||
if(wp.getSelf() == 0)
|
JPanel center = new JPanel(new GridLayout(5,2));
|
||||||
{
|
|
||||||
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);
|
||||||
row1.add(panel1);
|
center.add(panel1);
|
||||||
|
|
||||||
JTextField tf = new JTextField(wp.getSelf() + "", 10);
|
JTextField tf = new JTextField(5);
|
||||||
row2.add(tf);
|
center.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()
|
||||||
@@ -104,34 +44,14 @@ 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(300,250);
|
setSize(500,320);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-36
@@ -10,8 +10,6 @@ import java.awt.image.BufferedImage;
|
|||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
import Applicatie.Panel;
|
import Applicatie.Panel;
|
||||||
import Applicatie.PathPopup;
|
|
||||||
|
|
||||||
import Applicatie.Waypoint;
|
import Applicatie.Waypoint;
|
||||||
import Applicatie.WaypointPopup;
|
import Applicatie.WaypointPopup;
|
||||||
import Objects.DrawObject;
|
import Objects.DrawObject;
|
||||||
@@ -47,17 +45,14 @@ public class Mouse extends MouseAdapter
|
|||||||
if (e.getX() >= panel.getScrollfactor() && e.getX() < last + image.getWidth() + panel.getScrollfactor())
|
if (e.getX() >= panel.getScrollfactor() && e.getX() < last + image.getWidth() + panel.getScrollfactor())
|
||||||
{
|
{
|
||||||
DrawObject tempDrawObj = panel.createNewDrawObject(i);
|
DrawObject tempDrawObj = panel.createNewDrawObject(i);
|
||||||
if (tempDrawObj != null)
|
tempDrawObj.setPosition(clickPoint);
|
||||||
{
|
if (!panel.getObjects().isEmpty())
|
||||||
tempDrawObj.setPosition(clickPoint);
|
panel.clearObjectSelection();
|
||||||
if (!panel.getObjects().isEmpty())
|
panel.setDragObject(tempDrawObj);
|
||||||
panel.clearObjectSelection();
|
panel.getDragObject().setSelected(true);
|
||||||
panel.setDragObject(tempDrawObj);
|
panel.getPP().setSelected(tempDrawObj);
|
||||||
panel.getDragObject().setSelected(true);
|
panel.setSelectedObject(tempDrawObj);
|
||||||
panel.getPP().setSelected(tempDrawObj);
|
selectedObject = tempDrawObj;
|
||||||
panel.setSelectedObject(tempDrawObj);
|
|
||||||
selectedObject = tempDrawObj;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
@@ -76,10 +71,8 @@ public class Mouse extends MouseAdapter
|
|||||||
{
|
{
|
||||||
if (SwingUtilities.isRightMouseButton(e))
|
if (SwingUtilities.isRightMouseButton(e))
|
||||||
{
|
{
|
||||||
if (o instanceof Waypoint)
|
if(o instanceof Waypoint){
|
||||||
{
|
new WaypointPopup(o);
|
||||||
new WaypointPopup(o, panel);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (o == selectedObject)
|
if (o == selectedObject)
|
||||||
@@ -125,19 +118,7 @@ public class Mouse extends MouseAdapter
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Path clickedPath = panel.getClickedPath(clickPoint);
|
panel.checkPath(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)
|
||||||
{
|
{
|
||||||
@@ -149,19 +130,15 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mouseReleased(MouseEvent e)
|
public void mouseReleased(MouseEvent e)
|
||||||
{
|
{
|
||||||
if (panel.getDragObject() != null)
|
if(panel.getDragObject() != null) {
|
||||||
{
|
if(panel.getDragObject().getRectangleColor() != Color.RED) {
|
||||||
if (panel.getDragObject().getRectangleColor() != Color.RED)
|
|
||||||
{
|
|
||||||
panel.getDragObject().setPosition(panel.getDragObject().getPosition(), true);
|
panel.getDragObject().setPosition(panel.getDragObject().getPosition(), true);
|
||||||
panel.getPP().update();
|
panel.getPP().update();
|
||||||
panel.setDragObject(null);
|
panel.setDragObject(null);
|
||||||
|
|||||||
+18
-1
@@ -15,6 +15,7 @@ import java.io.Serializable;
|
|||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
|
|
||||||
import Applicatie.Images;
|
import Applicatie.Images;
|
||||||
|
import Applicatie.Panel;
|
||||||
|
|
||||||
public abstract class DrawObject implements Serializable
|
public abstract class DrawObject implements Serializable
|
||||||
{
|
{
|
||||||
@@ -232,11 +233,27 @@ public abstract class DrawObject implements Serializable
|
|||||||
|
|
||||||
public void setPosition(Point2D position)
|
public void setPosition(Point2D position)
|
||||||
{
|
{
|
||||||
|
if(position.getX() < -Panel.getFieldWidth()/2)
|
||||||
|
{
|
||||||
|
position.setLocation(-Panel.getFieldWidth()/2, position.getY());
|
||||||
|
}
|
||||||
|
if(position.getY() < -Panel.getFieldHeight()/2)
|
||||||
|
{
|
||||||
|
position.setLocation(position.getX(), -Panel.getFieldHeight()/2);
|
||||||
|
}
|
||||||
|
if(position.getX() > Panel.getFieldWidth()/2 - width)
|
||||||
|
{
|
||||||
|
position.setLocation(Panel.getFieldWidth()/2-width, position.getY());
|
||||||
|
}
|
||||||
|
if(position.getY() > Panel.getFieldHeight()/2 - height)
|
||||||
|
{
|
||||||
|
position.setLocation(position.getX(), Panel.getFieldHeight()/2-height);
|
||||||
|
}
|
||||||
this.position = position;
|
this.position = position;
|
||||||
}
|
}
|
||||||
public void setPosition(Point2D position, boolean b)
|
public void setPosition(Point2D position, boolean b)
|
||||||
{
|
{
|
||||||
this.position = position;
|
setPosition(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getRotation()
|
public double getRotation()
|
||||||
|
|||||||
+7
-19
@@ -14,7 +14,6 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
import Applicatie.Panel;
|
|
||||||
import Applicatie.Waypoint;
|
import Applicatie.Waypoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -96,7 +95,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.
|
||||||
*
|
*
|
||||||
@@ -115,13 +114,12 @@ 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;
|
||||||
}
|
}
|
||||||
@@ -146,23 +144,13 @@ public class Path
|
|||||||
lines.add(stroke.createStrokedShape(line));
|
lines.add(stroke.createStrokedShape(line));
|
||||||
}
|
}
|
||||||
return lines;
|
return lines;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addWaypoint(int i, Panel panel)
|
public void addWaypoint(Waypoint w)
|
||||||
{
|
{
|
||||||
for (Waypoint w : panel.getWaypoints())
|
waypoints.add(w);
|
||||||
{
|
|
||||||
if (w.getSelf() == i)
|
|
||||||
{
|
|
||||||
waypoints.add(w);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a point to the path.
|
* Add a point to the path.
|
||||||
*
|
*
|
||||||
|
|||||||
+1
-16
@@ -2,16 +2,11 @@ package Objects;
|
|||||||
|
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
|
|
||||||
import Agenda.AgendaStage;
|
|
||||||
|
|
||||||
public class Stage extends DrawObject
|
public class Stage extends DrawObject
|
||||||
{
|
{
|
||||||
AgendaStage stage;
|
public Stage(Point2D position)
|
||||||
|
|
||||||
public Stage(Point2D position, AgendaStage st)
|
|
||||||
{
|
{
|
||||||
super("stage", position);
|
super("stage", position);
|
||||||
stage = st;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -20,14 +15,4 @@ public class Stage extends DrawObject
|
|||||||
return "Stage";
|
return "Stage";
|
||||||
}
|
}
|
||||||
|
|
||||||
public AgendaStage getStage()
|
|
||||||
{
|
|
||||||
return stage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStage(AgendaStage stage)
|
|
||||||
{
|
|
||||||
this.stage = stage;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 8.0 KiB |
Reference in New Issue
Block a user