spawn
hoi
This commit is contained in:
@@ -49,11 +49,13 @@ public class AddArtistPanel extends JFrame{
|
||||
|
||||
JPanel panel5 = new JPanel();
|
||||
JLabel image = new JLabel("Image: ");
|
||||
image.setVisible(false);
|
||||
panel5.add(image);
|
||||
center.add(panel5);
|
||||
|
||||
JPanel panel6 = new JPanel();
|
||||
JTextField imageTF = new JTextField("null", 15);
|
||||
imageTF.setVisible(false);
|
||||
panel6.add(imageTF);
|
||||
center.add(panel6);
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ public class AddEventPanel extends JFrame{
|
||||
center.add(panel6);
|
||||
|
||||
JComboBox<Integer> minuteE = new JComboBox<Integer>(minutes);
|
||||
minuteE.setSelectedIndex(today.get(GregorianCalendar.MINUTE));
|
||||
minuteE.setSelectedIndex(today.get(GregorianCalendar.MINUTE+1));
|
||||
panel6.add(minuteE);
|
||||
panel6.add(new JSeparator(SwingConstants.VERTICAL));
|
||||
panel6.add(new JSeparator(SwingConstants.VERTICAL));
|
||||
@@ -205,9 +205,9 @@ public class AddEventPanel extends JFrame{
|
||||
|
||||
String stageName = (String)stage2.getSelectedItem();
|
||||
|
||||
Stage stage = null;
|
||||
AgendaStage stage = null;
|
||||
|
||||
for(Stage s : agenda.getStages())
|
||||
for(AgendaStage s : agenda.getStages())
|
||||
{
|
||||
if (s.getName().equals(stageName))
|
||||
{
|
||||
|
||||
@@ -58,7 +58,7 @@ public class AddStagePanel extends JFrame{
|
||||
String description = descriptionTF.getText();
|
||||
|
||||
boolean alreadyExists = false;
|
||||
for (Stage stage : agenda.getStages())
|
||||
for (AgendaStage stage : agenda.getStages())
|
||||
{
|
||||
if (stage.getName().equals(name))
|
||||
{
|
||||
@@ -70,7 +70,7 @@ public class AddStagePanel extends JFrame{
|
||||
}
|
||||
else if ( alreadyExists == false )
|
||||
{
|
||||
Stage s = new Stage(name,description);
|
||||
AgendaStage s = new AgendaStage(name,description);
|
||||
agenda.addStage(s);
|
||||
JOptionPane.showMessageDialog(null, "Stage added!");
|
||||
setVisible(false);
|
||||
|
||||
+5
-5
@@ -17,17 +17,17 @@ public class Agenda implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
private ArrayList<Stage> stages;
|
||||
private ArrayList<AgendaStage> stages;
|
||||
private ArrayList<Event> events;
|
||||
private ArrayList<Artist> artists;
|
||||
|
||||
public Agenda() {
|
||||
stages = new ArrayList<Stage>();
|
||||
stages = new ArrayList<AgendaStage>();
|
||||
events = new ArrayList<Event>();
|
||||
artists = new ArrayList<Artist>();
|
||||
}
|
||||
|
||||
public void addStage(Stage stage){
|
||||
public void addStage(AgendaStage stage){
|
||||
stages.add(stage);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class Agenda implements Serializable {
|
||||
{
|
||||
return artists;
|
||||
}
|
||||
public ArrayList<Stage> getStages()
|
||||
public ArrayList<AgendaStage> getStages()
|
||||
{
|
||||
return stages;
|
||||
}
|
||||
@@ -179,7 +179,7 @@ public class Agenda implements Serializable {
|
||||
{
|
||||
boolean exists = false;
|
||||
String name = e.getStage().getName();
|
||||
for (Stage s : stages)
|
||||
for (AgendaStage s : stages)
|
||||
{
|
||||
if ( s.getName().equals(name) ) {
|
||||
exists = true;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package Agenda;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class AgendaStage implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
|
||||
public AgendaStage(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;
|
||||
}
|
||||
}
|
||||
@@ -49,11 +49,13 @@ public class EditArtistPanel extends JFrame {
|
||||
|
||||
JPanel panel5 = new JPanel();
|
||||
JLabel image = new JLabel("Image: ");
|
||||
image.setVisible(false);
|
||||
panel5.add(image);
|
||||
center.add(panel5);
|
||||
|
||||
JPanel panel6 = new JPanel();
|
||||
JTextField imageTF = new JTextField("null", 15);
|
||||
imageTF.setVisible(false);
|
||||
panel6.add(imageTF);
|
||||
center.add(panel6);
|
||||
|
||||
|
||||
@@ -221,9 +221,9 @@ public class EditEventPanel extends JFrame{
|
||||
|
||||
String stageName = (String)stage2.getSelectedItem();
|
||||
|
||||
Stage stage = null;
|
||||
AgendaStage stage = null;
|
||||
|
||||
for(Stage s : agenda.getStages())
|
||||
for(AgendaStage s : agenda.getStages())
|
||||
{
|
||||
if (s.getName().equals(stageName))
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@ public class EditStagePanel extends JFrame{
|
||||
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
public EditStagePanel(Agenda agenda, Stage sta)
|
||||
public EditStagePanel(Agenda agenda, AgendaStage sta)
|
||||
{
|
||||
super("Stage editscreen!");
|
||||
setDefaultCloseOperation(HIDE_ON_CLOSE);
|
||||
@@ -59,7 +59,7 @@ public class EditStagePanel extends JFrame{
|
||||
String description = descriptionTF.getText();
|
||||
|
||||
boolean alreadyExists = false;
|
||||
for (Stage stage : agenda.getStages())
|
||||
for (AgendaStage stage : agenda.getStages())
|
||||
{
|
||||
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)
|
||||
{
|
||||
Iterator<Stage> it = agenda.getStages().iterator();
|
||||
Iterator<AgendaStage> it = agenda.getStages().iterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
Stage s = it.next();
|
||||
AgendaStage s = it.next();
|
||||
if(s.equals(sta))
|
||||
{
|
||||
it.remove();
|
||||
|
||||
+5
-5
@@ -19,13 +19,13 @@ public class Event implements Serializable {
|
||||
private int stopHour;
|
||||
private int stopMinute;
|
||||
private Artist artist;
|
||||
private Stage stage;
|
||||
private AgendaStage stage;
|
||||
private String description;
|
||||
private int expectedPopularity;
|
||||
|
||||
public Event(String eventName, int startYear, int startMonth, int startDay,
|
||||
int startHour, int startMinute, int endYear, int endMonth,
|
||||
int endDay, int endHour, int endMinute, Artist artist, Stage stage,
|
||||
int endDay, int endHour, int endMinute, Artist artist, AgendaStage stage,
|
||||
String description, int expectedPopularity) {
|
||||
this.eventName = eventName;
|
||||
this.startDate = new GregorianCalendar(startYear, startMonth - 1,
|
||||
@@ -43,7 +43,7 @@ public class Event implements Serializable {
|
||||
}
|
||||
|
||||
public Event(String eventName, GregorianCalendar startDate,
|
||||
GregorianCalendar endDate, Artist artist, Stage stage,
|
||||
GregorianCalendar endDate, Artist artist, AgendaStage stage,
|
||||
String description, int expectedPopularity) {
|
||||
this.eventName = eventName;
|
||||
this.startDate = startDate;
|
||||
@@ -86,7 +86,7 @@ public class Event implements Serializable {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public Stage getStage() {
|
||||
public AgendaStage getStage() {
|
||||
return this.stage;
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ public class Event implements Serializable {
|
||||
this.expectedPopularity = popularity;
|
||||
}
|
||||
|
||||
public void setStage(Stage stage) {
|
||||
public void setStage(AgendaStage stage) {
|
||||
this.stage = stage;
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -82,7 +82,8 @@ public class MenuBar extends JMenuBar {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(JOptionPane.showConfirmDialog(null, "Are you sure you want to close this program?", "Close Agenda", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION)
|
||||
{
|
||||
System.exit(0);
|
||||
w.setVisible(false);
|
||||
w.dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -105,7 +105,7 @@ public class PanelArtSta extends JPanel implements Panel{
|
||||
else
|
||||
{
|
||||
dataStage = new Object[1];
|
||||
dataStage[0] = new Stage("Geen Stages", "Geen Stages");
|
||||
dataStage[0] = new AgendaStage("Geen Stages", "Geen Stages");
|
||||
stages.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
+10
-1
@@ -2,24 +2,33 @@ package Applicatie;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import Objects.DrawObject;
|
||||
|
||||
public class Action
|
||||
{
|
||||
|
||||
private Point2D position;
|
||||
private int starttime;
|
||||
private int duration;
|
||||
private DrawObject target;
|
||||
|
||||
public Action(Point2D position, int starttime, int duration)
|
||||
public Action(Point2D position, int starttime, int duration, DrawObject tar)
|
||||
{
|
||||
this.position = position;
|
||||
this.starttime = starttime;
|
||||
this.duration = duration;
|
||||
this.target = tar;
|
||||
}
|
||||
|
||||
public Point2D getPosition()
|
||||
{
|
||||
return position;
|
||||
}
|
||||
|
||||
public DrawObject getTargetObject()
|
||||
{
|
||||
return target;
|
||||
}
|
||||
|
||||
public int getStartTime()
|
||||
{
|
||||
|
||||
@@ -19,17 +19,18 @@ public class ControlPanel extends JPanel
|
||||
private static final long serialVersionUID = 6805244250902524351L;
|
||||
|
||||
private Panel p;
|
||||
JLabel timeLabel;
|
||||
|
||||
public ControlPanel(Panel p)
|
||||
public ControlPanel()
|
||||
{
|
||||
super();
|
||||
BoxLayout box = new BoxLayout(this, BoxLayout.X_AXIS);
|
||||
setLayout(box);
|
||||
this.p = p;
|
||||
|
||||
setPreferredSize(new Dimension(0,50));
|
||||
setBorder(BorderFactory.createLineBorder(new Color(180, 180, 180)));
|
||||
setBackground(new Color(220, 220, 220));
|
||||
|
||||
setFocusable(false);
|
||||
|
||||
JPanel simulatorPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
simulatorPanel.setPreferredSize(new Dimension(350,50));
|
||||
@@ -41,6 +42,7 @@ public class ControlPanel extends JPanel
|
||||
simulatorPanel.add(simulatorLabel);
|
||||
|
||||
JButton playButton = new JButton("Play");
|
||||
playButton.setFocusable(false);
|
||||
playButton.setFont(new Font("Segoe UI", Font.PLAIN, 20));
|
||||
playButton.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e)
|
||||
@@ -51,6 +53,7 @@ public class ControlPanel extends JPanel
|
||||
simulatorPanel.add(playButton);
|
||||
|
||||
JButton pauseButton = new JButton("Pause");
|
||||
pauseButton.setFocusable(false);
|
||||
pauseButton.setFont(new Font("Segoe UI", Font.PLAIN, 20));
|
||||
pauseButton.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e)
|
||||
@@ -61,6 +64,7 @@ public class ControlPanel extends JPanel
|
||||
simulatorPanel.add(pauseButton);
|
||||
|
||||
JButton stopButton = new JButton("Stop");
|
||||
stopButton.setFocusable(false);
|
||||
stopButton.setFont(new Font("Segoe UI", Font.PLAIN, 20));
|
||||
stopButton.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e)
|
||||
@@ -74,15 +78,16 @@ public class ControlPanel extends JPanel
|
||||
add(Box.createRigidArea(new Dimension(10,50)));
|
||||
|
||||
JPanel timePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
timePanel.setPreferredSize(new Dimension(280,50));
|
||||
timePanel.setMaximumSize(new Dimension(280,50));
|
||||
timePanel.setPreferredSize(new Dimension(300,50));
|
||||
timePanel.setMaximumSize(new Dimension(300,50));
|
||||
add(timePanel);
|
||||
{
|
||||
JLabel timeLabel = new JLabel("00:00 00-00-000");
|
||||
timeLabel = new JLabel("00:00 00-00-000");
|
||||
timeLabel.setFont(new Font("Segoe UI", Font.PLAIN, 20));
|
||||
timePanel.add(timeLabel);
|
||||
|
||||
JButton dateButton = new JButton("Pick Date");
|
||||
dateButton.setFocusable(false);
|
||||
dateButton.setFont(new Font("Segoe UI", Font.PLAIN, 20));
|
||||
dateButton.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e)
|
||||
@@ -105,11 +110,12 @@ public class ControlPanel extends JPanel
|
||||
peoplePanel.add(peopleLabel);
|
||||
|
||||
JButton peopleButton = new JButton("Set People");
|
||||
peopleButton.setFocusable(false);
|
||||
peopleButton.setFont(new Font("Segoe UI", Font.PLAIN, 20));
|
||||
peopleButton.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
p.addVisitors(1);
|
||||
p.addVisitors();
|
||||
}
|
||||
});
|
||||
peoplePanel.add(peopleButton);
|
||||
@@ -128,4 +134,19 @@ public class ControlPanel extends JPanel
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setPanel(Panel p)
|
||||
{
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
public void setTime(String time)
|
||||
{
|
||||
timeLabel.setText(time);
|
||||
}
|
||||
|
||||
public void setPeople(int people)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ public class Images
|
||||
images.put("stage1", loadImage("images/stage3.png"));
|
||||
images.put("visitor", loadImage("images/visitor.png"));
|
||||
images.put("food", loadImage("images/food.png"));
|
||||
images.put("waypoint", loadImage("images/waypoint.png"));
|
||||
}
|
||||
|
||||
public static Image loadImage(String path)
|
||||
|
||||
@@ -28,6 +28,16 @@ public class MenuBar extends JMenuBar
|
||||
});
|
||||
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.addActionListener(new ActionListener() {
|
||||
|
||||
@@ -50,6 +60,16 @@ public class MenuBar extends JMenuBar
|
||||
|
||||
file.addSeparator();
|
||||
|
||||
item = new JMenuItem("Load agenda");
|
||||
item.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
w.getPanel().agenda.loadAgenda();
|
||||
}
|
||||
});
|
||||
file.add(item);
|
||||
|
||||
item = new JMenuItem("Agenda");
|
||||
item.addActionListener(new ActionListener()
|
||||
{
|
||||
|
||||
@@ -23,7 +23,7 @@ import javax.swing.JTextField;
|
||||
@SuppressWarnings("serial")
|
||||
public class NewWorldPanel extends JFrame {
|
||||
|
||||
BufferedImage grass,sand,selectedImage;
|
||||
BufferedImage grass,sand,grass2, sand2,stone, selectedImage;
|
||||
|
||||
public NewWorldPanel(Panel topPanel) {
|
||||
super("New World");
|
||||
@@ -32,13 +32,16 @@ public class NewWorldPanel extends JFrame {
|
||||
|
||||
try {
|
||||
grass = ImageIO.read(new File("images/grassIcon.jpg"));
|
||||
sand = ImageIO.read(new File("images/sand.jpg"));
|
||||
sand = ImageIO.read(new File("images/sandIcon.jpg"));
|
||||
grass2 = ImageIO.read(new File("images/grassIcon2.png"));
|
||||
sand2 = ImageIO.read(new File("images/sandIcon2.jpg"));
|
||||
stone = ImageIO.read(new File("images/stoneIcon.jpg"));
|
||||
selectedImage = grass;
|
||||
}
|
||||
catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String[] terrains = {"Grass", "Sand"};
|
||||
String[] terrains = {"Grass", "Grass 2","Sand", "Sand 2", "Stone"};
|
||||
JPanel mainPanel = new JPanel(new BorderLayout());
|
||||
JButton button;
|
||||
JLabel label;
|
||||
@@ -88,8 +91,17 @@ public class NewWorldPanel extends JFrame {
|
||||
selectedImage = grass;
|
||||
break;
|
||||
case 1:
|
||||
selectedImage = grass2;
|
||||
break;
|
||||
case 2:
|
||||
selectedImage = sand;
|
||||
break;
|
||||
case 3:
|
||||
selectedImage = sand2;
|
||||
break;
|
||||
case 4:
|
||||
selectedImage = stone;
|
||||
break;
|
||||
}
|
||||
imageLabel.setIcon(new ImageIcon(selectedImage));
|
||||
}
|
||||
|
||||
+113
-27
@@ -17,21 +17,25 @@ import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.Timer;
|
||||
|
||||
import Agenda.Agenda;
|
||||
import Agenda.AgendaStage;
|
||||
import Listeners.Mouse;
|
||||
import Listeners.MouseMotion;
|
||||
import Listeners.MouseWheel;
|
||||
import Listeners.WindowFocusListener;
|
||||
import Objects.DrawObject;
|
||||
import Objects.Entrance;
|
||||
import Objects.Food;
|
||||
import Objects.OldPath;
|
||||
import Objects.Path;
|
||||
import Objects.Stage;
|
||||
import Objects.Toilet;
|
||||
@@ -41,34 +45,38 @@ import Objects.Wall;
|
||||
public class Panel extends JPanel implements ActionListener
|
||||
{
|
||||
|
||||
BufferedImage grass, sand;
|
||||
BufferedImage grass, grass2, sand, sand2, stone;
|
||||
BufferedImage background;
|
||||
BufferedImage podiumImage, toiletImage, entranceImage, pathImage, wallImage, foodImage;
|
||||
BufferedImage podiumImage, toiletImage, entranceImage, pathImage, wallImage, foodImage, waypointImage;
|
||||
|
||||
private int panelInfox, panelInfoy, scrollfactor;
|
||||
|
||||
private ArrayList<BufferedImage> panelInfo = new ArrayList<BufferedImage>();
|
||||
// private ArrayList<Object> panelTypes = new ArrayList<Object>();
|
||||
ArrayList<Visitor> visitors = new ArrayList<>();
|
||||
|
||||
ArrayList<Waypoint> waypoints = new ArrayList<Waypoint>();
|
||||
ArrayList<DrawObject> objects = new ArrayList<>();
|
||||
ArrayList<Path> paths = new ArrayList<>();
|
||||
DrawObject dragObject = null;
|
||||
private DrawObject selectedObject;
|
||||
private String clickedOption = "drag";
|
||||
private Path currentPath;
|
||||
private int width = 1920;
|
||||
private int height = 1080;
|
||||
private static int width = 1920;
|
||||
private static int height = 1080;
|
||||
|
||||
Point2D cameraPoint = new Point2D.Double(getWidth() / 2, getHeight() / 2);
|
||||
float cameraScale = 1;
|
||||
PropertiesPanel pp;
|
||||
ControlPanel cp;
|
||||
Agenda agenda;
|
||||
Point2D lastClickPosition = new Point(0, 0);
|
||||
Point lastMousePosition = new Point(0, 0);
|
||||
Point2D selectionPosition = new Point(0, 0);
|
||||
Images images = new Images();
|
||||
javax.swing.Timer t;
|
||||
|
||||
SimpleDateFormat formatter;
|
||||
GregorianCalendar date;
|
||||
|
||||
int currentTime = 540;
|
||||
int tick = 0;
|
||||
@@ -89,20 +97,27 @@ public class Panel extends JPanel implements ActionListener
|
||||
this.selectionPosition = selectionPosition;
|
||||
}
|
||||
|
||||
Panel(PropertiesPanel pp)
|
||||
Panel(PropertiesPanel pp, ControlPanel cp)
|
||||
{
|
||||
this.pp = pp;
|
||||
this.cp = cp;
|
||||
cp.setPanel(this);
|
||||
pp.setPanel(this);
|
||||
date = new GregorianCalendar();
|
||||
formatter = new SimpleDateFormat("H:s dd-MM-yyyy");
|
||||
try
|
||||
{
|
||||
grass = ImageIO.read(new File("images/grass.jpg"));
|
||||
grass2 = ImageIO.read(new File("images/grass2.png"));
|
||||
sand = ImageIO.read(new File("images/sand.jpg"));
|
||||
sand2 = ImageIO.read(new File("images/sand2.jpg"));
|
||||
stone = ImageIO.read(new File("images/stone.jpg"));
|
||||
podiumImage = ImageIO.read(new File("images/stageIcon.png"));
|
||||
toiletImage = ImageIO.read(new File("images/wcIcon.png"));
|
||||
entranceImage = ImageIO.read(new File("images/entranceIcon.png"));
|
||||
pathImage = ImageIO.read(new File("images/pathIcon.png"));
|
||||
wallImage = ImageIO.read(new File("images/wallIcon.png"));
|
||||
foodImage = ImageIO.read(new File("images/foodIcon.png"));
|
||||
waypointImage = ImageIO.read(new File("images/waypointIcon.png"));
|
||||
background = grass;
|
||||
}
|
||||
catch (IOException e)
|
||||
@@ -112,9 +127,9 @@ public class Panel extends JPanel implements ActionListener
|
||||
panelInfo.add(podiumImage);
|
||||
panelInfo.add(toiletImage);
|
||||
panelInfo.add(entranceImage);
|
||||
panelInfo.add(pathImage);
|
||||
panelInfo.add(wallImage);
|
||||
panelInfo.add(foodImage);
|
||||
panelInfo.add(waypointImage);
|
||||
|
||||
agenda = new Agenda();
|
||||
|
||||
@@ -131,7 +146,10 @@ public class Panel extends JPanel implements ActionListener
|
||||
addMouseMotionListener(new MouseMotion(this));
|
||||
|
||||
addMouseWheelListener(new MouseWheel(this));
|
||||
t = new Timer(1000 / 100, this);
|
||||
|
||||
addFocusListener(new WindowFocusListener(this));
|
||||
|
||||
t = new Timer(1000 / 10, this);
|
||||
}
|
||||
|
||||
public int getPanelInfoLength()
|
||||
@@ -150,17 +168,33 @@ public class Panel extends JPanel implements ActionListener
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return new Stage(null);
|
||||
ArrayList<AgendaStage> stages = agenda.getStages();
|
||||
Object[] s = new Object[stages.size()];
|
||||
AgendaStage stage = null;
|
||||
if (stages.size() != 0) {
|
||||
for (int i = 0; i < stages.size(); i++) {
|
||||
s[i] = stages.get(i);
|
||||
}
|
||||
|
||||
stage = (AgendaStage) JOptionPane.showInputDialog(null,
|
||||
"Select the right Stage", "Select Stage",
|
||||
JOptionPane.PLAIN_MESSAGE, null, s, "stage");
|
||||
}
|
||||
if (stage != null){
|
||||
return new Stage(null, stage);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
case 1:
|
||||
return new Toilet(null);
|
||||
case 2:
|
||||
return new Entrance(null);
|
||||
case 3:
|
||||
return new OldPath(null);
|
||||
case 4:
|
||||
return new Wall(null);
|
||||
case 5:
|
||||
case 4:
|
||||
return new Food(null);
|
||||
case 5:
|
||||
return new Waypoint(null);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@@ -171,16 +205,39 @@ public class Panel extends JPanel implements ActionListener
|
||||
objects.add(dragObject);
|
||||
}
|
||||
|
||||
public void addWaypoint(Waypoint w)
|
||||
{
|
||||
waypoints.add(w);
|
||||
}
|
||||
|
||||
public ArrayList<Waypoint> getWaypoints()
|
||||
{
|
||||
return waypoints;
|
||||
}
|
||||
|
||||
public void addVisitors()
|
||||
{
|
||||
visitors.add(new Visitor("visitor", new Point(100, 300), agenda, objects));
|
||||
ArrayList<DrawObject> entrances = new ArrayList<>();
|
||||
for(DrawObject object : objects) {
|
||||
if(object instanceof Entrance) {
|
||||
entrances.add(object);
|
||||
}
|
||||
}
|
||||
if(!entrances.isEmpty()) {
|
||||
DrawObject entrance = entrances.get((int) Math.floor(Math.random()*entrances.size()));
|
||||
Point point = new Point((int)entrance.getPosition().getX(),(int)entrance.getPosition().getY());
|
||||
visitors.add(new Visitor("visitor",point, agenda, objects));
|
||||
}
|
||||
else {
|
||||
JOptionPane.showMessageDialog(this, "You don't have a entrance");
|
||||
}
|
||||
}
|
||||
|
||||
public void addVisitors(int count)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
visitors.add(new Visitor("visitor", new Point(100, 300), agenda, objects));
|
||||
addVisitors();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,7 +245,7 @@ public class Panel extends JPanel implements ActionListener
|
||||
{
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
g2.setClip(new Rectangle2D.Double(0, 0, getWidth(), 300));
|
||||
g2.setClip(new Rectangle2D.Double(0, 0, getWidth(), 150));
|
||||
Stroke old = g2.getStroke();
|
||||
g2.setStroke(new BasicStroke(10));
|
||||
g2.drawLine(0, 150, getWidth(), 150);
|
||||
@@ -448,6 +505,9 @@ public class Panel extends JPanel implements ActionListener
|
||||
*/
|
||||
public void startPath()
|
||||
{
|
||||
pp.clearSelected();
|
||||
setSelectedObject(null);
|
||||
clearObjectSelection();
|
||||
setClickedOption("Path");
|
||||
currentPath = new Path();
|
||||
paths.add(currentPath);
|
||||
@@ -528,7 +588,17 @@ public class Panel extends JPanel implements ActionListener
|
||||
{
|
||||
this.agenda = agenda;
|
||||
}
|
||||
|
||||
|
||||
public static int getFieldWidth()
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
public static int getFieldHeight()
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
@@ -537,23 +607,30 @@ public class Panel extends JPanel implements ActionListener
|
||||
{
|
||||
tick = 0;
|
||||
currentTime++;
|
||||
date.setTimeInMillis(date.getTimeInMillis() + 1000);
|
||||
cp.setTime(formatter.format(date.getTime()));
|
||||
System.out.println(currentTime);
|
||||
}
|
||||
|
||||
for (Visitor v : visitors)
|
||||
{
|
||||
v.update(objects, currentTime, visitors);
|
||||
v.update(objects, currentTime, visitors, paths);
|
||||
}
|
||||
repaint();
|
||||
|
||||
}
|
||||
|
||||
public javax.swing.Timer getT()
|
||||
public Timer getT()
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
public void setT(javax.swing.Timer t)
|
||||
public ArrayList<Path> getPaths()
|
||||
{
|
||||
return paths;
|
||||
}
|
||||
|
||||
public void setT(Timer t)
|
||||
{
|
||||
this.t = t;
|
||||
}
|
||||
@@ -567,12 +644,21 @@ public class Panel extends JPanel implements ActionListener
|
||||
cameraScale = 1;
|
||||
switch (terrainIndex)
|
||||
{
|
||||
case 0:
|
||||
background = grass;
|
||||
break;
|
||||
case 1:
|
||||
background = sand;
|
||||
break;
|
||||
case 0:
|
||||
background = grass;
|
||||
break;
|
||||
case 1:
|
||||
background = grass2;
|
||||
break;
|
||||
case 2:
|
||||
background = sand;
|
||||
break;
|
||||
case 3:
|
||||
background = sand2;
|
||||
break;
|
||||
case 4:
|
||||
background = stone;
|
||||
break;
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ public class PropertiesPanel extends JPanel
|
||||
setPreferredSize(new Dimension(200, 0));
|
||||
setBorder(BorderFactory.createLineBorder(new Color(180, 180, 180)));
|
||||
setBackground(new Color(220, 220, 220));
|
||||
setFocusable(false);
|
||||
|
||||
// NAME "PROPERTIES"
|
||||
JPanel propPanel = new JPanel();
|
||||
@@ -97,6 +98,7 @@ public class PropertiesPanel extends JPanel
|
||||
// BUTTONS ROW 1
|
||||
JPanel row1ButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
JButton deleteButton = new JButton("Delete");
|
||||
deleteButton.setFocusable(false);
|
||||
deleteButton.setFont(new Font("Segoe UI", Font.PLAIN, 20));
|
||||
deleteButton.addActionListener(new ActionListener()
|
||||
{
|
||||
@@ -111,6 +113,7 @@ public class PropertiesPanel extends JPanel
|
||||
}
|
||||
});
|
||||
JButton areaButton = new JButton("Area");
|
||||
areaButton.setFocusable(false);
|
||||
areaButton.setFont(new Font("Segoe UI", Font.PLAIN, 20));
|
||||
areaButton.addActionListener(new ActionListener()
|
||||
{
|
||||
@@ -330,7 +333,8 @@ public class PropertiesPanel extends JPanel
|
||||
{
|
||||
locationXField.setBackground(Color.WHITE);
|
||||
double xpos = Double.parseDouble(locationXField.getText());
|
||||
selectedObject.setPosition(new Point2D.Double(xpos, selectedObject.getPosition().getY()));
|
||||
selectedObject.setPosition(new Point2D.Double(xpos, selectedObject.getPosition().getY()), true);
|
||||
update();
|
||||
p.update();
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
@@ -369,8 +373,8 @@ public class PropertiesPanel extends JPanel
|
||||
{
|
||||
locationYField.setBackground(Color.WHITE);
|
||||
double ypos = Double.parseDouble(locationYField.getText());
|
||||
selectedObject.setPosition(new Point2D.Double(selectedObject.getPosition().getX(), ypos));
|
||||
;
|
||||
selectedObject.setPosition(new Point2D.Double(selectedObject.getPosition().getX(), ypos), true);
|
||||
update();
|
||||
p.update();
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
@@ -420,7 +424,13 @@ public class PropertiesPanel extends JPanel
|
||||
{
|
||||
scaleField.setBackground(Color.WHITE);
|
||||
double scale = Double.parseDouble(scaleField.getText());
|
||||
if(scale<0 || (scale >0 && scale<0.2))
|
||||
{
|
||||
scale=0.2;
|
||||
scaleField.setText(scale+"");
|
||||
}
|
||||
selectedObject.setScale(scale);
|
||||
|
||||
p.update();
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
|
||||
+196
-47
@@ -2,14 +2,19 @@ package Applicatie;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import Agenda.Agenda;
|
||||
import Agenda.Event;
|
||||
import Objects.DrawObject;
|
||||
import Objects.Entrance;
|
||||
import Objects.Path;
|
||||
|
||||
public class Visitor
|
||||
{
|
||||
@@ -22,6 +27,7 @@ public class Visitor
|
||||
ArrayList<Action> actions;
|
||||
Agenda agenda;
|
||||
ArrayList<DrawObject> objects;
|
||||
int target;
|
||||
|
||||
public Visitor(String filename, Point2D position, Agenda agenda, ArrayList<DrawObject> objects)
|
||||
{
|
||||
@@ -34,6 +40,8 @@ public class Visitor
|
||||
this.agenda = agenda;
|
||||
this.objects = objects;
|
||||
fillActions();
|
||||
System.out.println(actions.size());
|
||||
target = 0;
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g2)
|
||||
@@ -49,73 +57,210 @@ public class Visitor
|
||||
AffineTransform tx = new AffineTransform();
|
||||
tx.scale(scale, scale);
|
||||
tx.translate(position.getX(), position.getY());
|
||||
// System.out.println(position.getX());
|
||||
tx.rotate(rotation, image.getWidth(null) / 2, image.getHeight(null) / 2);
|
||||
return tx;
|
||||
}
|
||||
|
||||
public void update(ArrayList<DrawObject> objects, int currentTime, ArrayList<Visitor> visitors)
|
||||
public DrawObject getEntrance()
|
||||
{
|
||||
Point2D target = new Point(500, 500);
|
||||
for(DrawObject o : objects)
|
||||
{
|
||||
if(o instanceof Entrance)
|
||||
{
|
||||
return o;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void update(ArrayList<DrawObject> objects, int currentTime, ArrayList<Visitor> visitors, ArrayList<Path> paths)
|
||||
{
|
||||
DrawObject target = getEntrance();
|
||||
for (Action a : actions)
|
||||
{
|
||||
if (currentTime >= a.getStartTime() && currentTime < a.getStoptime())
|
||||
{
|
||||
target = a.getPosition();
|
||||
target = a.getTargetObject();
|
||||
}
|
||||
|
||||
}
|
||||
moveToTarget(target, objects, visitors);
|
||||
|
||||
moveToTarget(target, objects, visitors, paths);
|
||||
}
|
||||
|
||||
public void moveToTarget(Point2D target, ArrayList<DrawObject> objects, ArrayList<Visitor> visitors)
|
||||
public void moveToTarget(DrawObject target, ArrayList<DrawObject> objects, ArrayList<Visitor> visitors, ArrayList<Path> paths)
|
||||
{
|
||||
|
||||
double newRot = Math.atan2(target.getY() - position.getY(), target.getX() - position.getX());
|
||||
|
||||
int difx = (int) (target.getX() - position.getX());
|
||||
int dify = (int) (target.getY() - position.getY());
|
||||
int distance = (int) Math.sqrt((difx * difx) + (dify * dify));
|
||||
|
||||
if (rotation > newRot && distance > 10)
|
||||
Point2D tar = target.getPosition();
|
||||
boolean hasPathBelow = false;
|
||||
for (Path p : paths)
|
||||
{
|
||||
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 (hitTest(object))
|
||||
if (p.containsPoint(position))
|
||||
{
|
||||
possible = false;
|
||||
hasPathBelow = true;
|
||||
break;
|
||||
}
|
||||
Shape containsShape = p.containsPointShape(position);
|
||||
if(containsShape != null)
|
||||
{
|
||||
tar = new Point2D.Double(containsShape.getBounds().getCenterX(), containsShape.getBounds().getCenterY());
|
||||
}
|
||||
}
|
||||
for (Visitor object : visitors)
|
||||
|
||||
if (hasPathBelow)
|
||||
{
|
||||
if (hitTestVisitor(object) && object != this)
|
||||
double newRot = Math.atan2(tar.getY() - position.getY(), tar.getX() - position.getX());
|
||||
|
||||
int difx = (int) (tar.getX() - position.getX());
|
||||
int dify = (int) (tar.getY() - position.getY());
|
||||
int distance = (int) Math.sqrt((difx * difx) + (dify * dify));
|
||||
|
||||
if (rotation > newRot && distance > 10)
|
||||
{
|
||||
possible = false;
|
||||
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 (hitTest(object))
|
||||
{
|
||||
possible = false;
|
||||
}
|
||||
}
|
||||
for (Visitor object : visitors)
|
||||
{
|
||||
if (hitTestVisitor(object) && object != this)
|
||||
{
|
||||
possible = false;
|
||||
}
|
||||
}
|
||||
if (possible == false)
|
||||
{
|
||||
position = oldPosition;
|
||||
rotation += 0.2;
|
||||
}
|
||||
}
|
||||
if (possible == false)
|
||||
else
|
||||
{
|
||||
position = oldPosition;
|
||||
rotation += 0.2;
|
||||
HashMap<Double, Shape> values = new HashMap<Double, Shape>();
|
||||
for (Path p : paths)
|
||||
{
|
||||
for (Shape s : p.getPath())
|
||||
{
|
||||
Rectangle b = s.getBounds();
|
||||
double maxx = b.getMaxX();
|
||||
double minx = b.getMinX();
|
||||
double maxy = b.getMaxY();
|
||||
double miny = b.getMinY();
|
||||
|
||||
Point2D.Double[] points = new Point2D.Double[4];
|
||||
points[0] = new Point2D.Double(minx, miny);
|
||||
points[1] = new Point2D.Double(minx, maxy);
|
||||
points[2] = new Point2D.Double(maxx, miny);
|
||||
points[3] = new Point2D.Double(maxx, maxy);
|
||||
|
||||
Double lastdistance = null;
|
||||
for (Point2D.Double point : points)
|
||||
{
|
||||
double distance = Point2D.distance(point.getX(), point.getY(), position.getX(), position.getY());
|
||||
if (lastdistance == null)
|
||||
{
|
||||
lastdistance = distance;
|
||||
continue;
|
||||
}
|
||||
if (distance < lastdistance)
|
||||
{
|
||||
lastdistance = distance;
|
||||
}
|
||||
}
|
||||
values.put(lastdistance, s);
|
||||
|
||||
}
|
||||
}
|
||||
Double lastdistance = null;
|
||||
Shape lastShape = null;
|
||||
for (Map.Entry<Double, Shape> e : values.entrySet())
|
||||
{
|
||||
double distance = e.getKey();
|
||||
if (lastdistance == null)
|
||||
{
|
||||
lastdistance = distance;
|
||||
continue;
|
||||
}
|
||||
if (distance < lastdistance)
|
||||
{
|
||||
lastdistance = distance;
|
||||
}
|
||||
}
|
||||
lastShape = values.get(lastdistance);
|
||||
|
||||
Point2D.Double target2 = new Point2D.Double(lastShape.getBounds().getCenterX(), lastShape.getBounds().getCenterY());
|
||||
|
||||
double newRot = Math.atan2(target2.getY() - position.getY(), target2.getX() - position.getX());
|
||||
|
||||
int difx = (int) (target2.getX() - position.getX());
|
||||
int dify = (int) (target2.getY() - position.getY());
|
||||
int distance = (int) Math.sqrt((difx * difx) + (dify * dify));
|
||||
|
||||
System.out.println(rotation);
|
||||
System.out.println(newRot);
|
||||
System.out.println("--------------");
|
||||
// if (rotation > newRot && distance > 10)
|
||||
// {
|
||||
// rotation -= 0.15;
|
||||
// }
|
||||
// else if (rotation < newRot && distance > 10)
|
||||
// {
|
||||
// rotation += 0.15;
|
||||
// }
|
||||
rotation = newRot;
|
||||
|
||||
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 (hitTest(object))
|
||||
{
|
||||
possible = false;
|
||||
}
|
||||
}
|
||||
for (Visitor object : visitors)
|
||||
{
|
||||
if (hitTestVisitor(object) && object != this)
|
||||
{
|
||||
possible = false;
|
||||
}
|
||||
}
|
||||
if (possible == false)
|
||||
{
|
||||
position = oldPosition;
|
||||
rotation += 0.2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,6 +275,7 @@ public class Visitor
|
||||
if (random < 30)
|
||||
{
|
||||
Point2D position = null;
|
||||
DrawObject targetStage = null;
|
||||
for (Event e : agenda.getEvents())
|
||||
{
|
||||
if (convertMinutesToHours(startTime) > e.getStart() && convertMinutesToHours(startTime) < e.getStop())
|
||||
@@ -139,6 +285,7 @@ public class Visitor
|
||||
if (d.getFileName().equals(e.getStage().getName()))
|
||||
{
|
||||
position = d.getPosition();
|
||||
targetStage = d;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -146,7 +293,7 @@ public class Visitor
|
||||
int randomtime = (int) (40 + (Math.random() * (60 - 40)));
|
||||
if (position != null)
|
||||
{
|
||||
actions.add(new Action(position, startTime, randomtime));
|
||||
actions.add(new Action(position, startTime, randomtime, targetStage));
|
||||
}
|
||||
startTime = startTime + randomtime;
|
||||
|
||||
@@ -154,6 +301,7 @@ public class Visitor
|
||||
else if (random >= 30 && random < 35)
|
||||
{
|
||||
Point2D position = null;
|
||||
DrawObject targetDraw = null;
|
||||
for (DrawObject d : objects)
|
||||
{
|
||||
if (d.getFileName().equals("entrance"))
|
||||
@@ -163,7 +311,7 @@ public class Visitor
|
||||
}
|
||||
if (position != null)
|
||||
{
|
||||
actions.add(new Action(position, startTime, 35));
|
||||
actions.add(new Action(position, startTime, 35, targetDraw));
|
||||
startTime = startTime + 35;
|
||||
}
|
||||
startTime = startTime + 35;
|
||||
@@ -172,6 +320,7 @@ public class Visitor
|
||||
else if (random > 35)
|
||||
{
|
||||
Point2D position = null;
|
||||
DrawObject targetDrawobj = null;
|
||||
for (DrawObject d : objects)
|
||||
{
|
||||
if (d.getFileName().equals("wc"))
|
||||
@@ -181,7 +330,7 @@ public class Visitor
|
||||
}
|
||||
if (position != null)
|
||||
{
|
||||
actions.add(new Action(position, startTime, 35));
|
||||
actions.add(new Action(position, startTime, 35, targetDrawobj));
|
||||
}
|
||||
startTime = startTime + 35;
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package Applicatie;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import Objects.DrawObject;
|
||||
|
||||
public class Waypoint extends DrawObject
|
||||
{
|
||||
private int[] options;
|
||||
private int self;
|
||||
public Waypoint(Point2D position)
|
||||
{
|
||||
super("waypoint", position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "Waypoint";
|
||||
}
|
||||
|
||||
public int[] getOptions()
|
||||
{
|
||||
return options;
|
||||
}
|
||||
|
||||
public void setOptions(int[] options)
|
||||
{
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
public int getSelf()
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
public void setSelf(int self)
|
||||
{
|
||||
System.out.println(self);
|
||||
this.self = self;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package Applicatie;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import Objects.DrawObject;
|
||||
|
||||
public class WaypointPopup extends JFrame {
|
||||
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
public WaypointPopup(DrawObject w)
|
||||
{
|
||||
super("Artist editscreen!");
|
||||
Waypoint wp = (Waypoint) w;
|
||||
setDefaultCloseOperation(HIDE_ON_CLOSE);
|
||||
JPanel content = new JPanel(new BorderLayout());
|
||||
JPanel south = new JPanel(new FlowLayout());
|
||||
JPanel center = new JPanel(new GridLayout(5,2));
|
||||
content.add(south, BorderLayout.SOUTH);
|
||||
content.add(center, BorderLayout.CENTER);
|
||||
|
||||
JPanel panel1 = new JPanel();
|
||||
JLabel name = new JLabel("Waypoint");
|
||||
panel1.add(name);
|
||||
center.add(panel1);
|
||||
|
||||
JTextField tf = new JTextField(5);
|
||||
center.add(tf);
|
||||
|
||||
JButton edit = new JButton("Done");
|
||||
edit.addActionListener(new ActionListener()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
wp.setSelf(Integer.valueOf(tf.getText()));
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
south.add(edit);
|
||||
|
||||
setContentPane(content);
|
||||
setVisible(true);
|
||||
setSize(500,320);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,9 +24,9 @@ public class Window extends JFrame
|
||||
// CONTENT PANELS
|
||||
JPanel contentPanel = new JPanel(new BorderLayout());
|
||||
PropertiesPanel pp = new PropertiesPanel();
|
||||
fp = new Panel(pp);
|
||||
ControlPanel cp = new ControlPanel();
|
||||
fp = new Panel(pp, cp);
|
||||
contentPanel.add(fp, BorderLayout.CENTER);
|
||||
ControlPanel cp = new ControlPanel(fp);
|
||||
contentPanel.add(cp, BorderLayout.SOUTH);
|
||||
contentPanel.add(pp, BorderLayout.EAST);
|
||||
contentPanel.add(fp, BorderLayout.CENTER);
|
||||
|
||||
+32
-4
@@ -27,23 +27,51 @@ public class Keyboard implements KeyListener {
|
||||
}
|
||||
else if(e.getKeyCode() == e.VK_LEFT) {
|
||||
if(panel.getSelectedObject() != null)
|
||||
panel.getSelectedObject().setPosition(new Point2D.Double(panel.getSelectedObject().getPosition().getX()-5,panel.getSelectedObject().getPosition().getY()));
|
||||
panel.getSelectedObject().setPosition(new Point2D.Double(panel.getSelectedObject().getPosition().getX()-5,panel.getSelectedObject().getPosition().getY()), true);
|
||||
panel.checkCollision();
|
||||
panel.getPP().update();
|
||||
}
|
||||
else if(e.getKeyCode() == e.VK_RIGHT) {
|
||||
if(panel.getSelectedObject() != null)
|
||||
panel.getSelectedObject().setPosition(new Point2D.Double(panel.getSelectedObject().getPosition().getX()+5,panel.getSelectedObject().getPosition().getY()));
|
||||
panel.getSelectedObject().setPosition(new Point2D.Double(panel.getSelectedObject().getPosition().getX()+5,panel.getSelectedObject().getPosition().getY()), true);
|
||||
panel.checkCollision();
|
||||
panel.getPP().update();
|
||||
}
|
||||
else if(e.getKeyCode() == e.VK_UP) {
|
||||
if(panel.getSelectedObject() != null)
|
||||
panel.getSelectedObject().setPosition(new Point2D.Double(panel.getSelectedObject().getPosition().getX(),panel.getSelectedObject().getPosition().getY()-5));
|
||||
panel.getSelectedObject().setPosition(new Point2D.Double(panel.getSelectedObject().getPosition().getX(),panel.getSelectedObject().getPosition().getY()-5), true);
|
||||
panel.checkCollision();
|
||||
panel.getPP().update();
|
||||
}
|
||||
else if(e.getKeyCode() == e.VK_DOWN) {
|
||||
if(panel.getSelectedObject() != null)
|
||||
panel.getSelectedObject().setPosition(new Point2D.Double(panel.getSelectedObject().getPosition().getX(),panel.getSelectedObject().getPosition().getY()+5));
|
||||
panel.getSelectedObject().setPosition(new Point2D.Double(panel.getSelectedObject().getPosition().getX(),panel.getSelectedObject().getPosition().getY()+5), true);
|
||||
panel.checkCollision();
|
||||
panel.getPP().update();
|
||||
}
|
||||
else if(e.getKeyCode() == e.VK_ADD) {
|
||||
if(panel.getSelectedObject() != null)
|
||||
panel.getSelectedObject().setScale(panel.getSelectedObject().getScale()+0.2);
|
||||
panel.checkCollision();
|
||||
panel.getPP().update();
|
||||
}
|
||||
else if(e.getKeyCode() == e.VK_SUBTRACT) {
|
||||
if(panel.getSelectedObject() != null)
|
||||
panel.getSelectedObject().setScale(Math.max(panel.getSelectedObject().getScale()-0.2, 0.2));
|
||||
panel.checkCollision();
|
||||
panel.getPP().update();
|
||||
}
|
||||
else if(e.getKeyCode() == e.VK_COMMA) {
|
||||
if(panel.getSelectedObject() != null)
|
||||
panel.getSelectedObject().setRotation((panel.getSelectedObject().getRotation()-5)%360);
|
||||
panel.checkCollision();
|
||||
panel.getPP().update();
|
||||
}
|
||||
else if(e.getKeyCode() == e.VK_PERIOD) {
|
||||
if(panel.getSelectedObject() != null)
|
||||
panel.getSelectedObject().setRotation((panel.getSelectedObject().getRotation()+5)%360);
|
||||
panel.checkCollision();
|
||||
panel.getPP().update();
|
||||
}
|
||||
else if(e.getKeyCode() == e.VK_ENTER) {
|
||||
if(panel.getClickedOption().equals("Path")) {
|
||||
|
||||
+40
-17
@@ -4,11 +4,17 @@ import java.awt.Color;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import Applicatie.Panel;
|
||||
import Applicatie.Waypoint;
|
||||
import Applicatie.WaypointPopup;
|
||||
import Objects.DrawObject;
|
||||
import Objects.Stage;
|
||||
import Objects.Path;
|
||||
import Objects.Entrance;
|
||||
|
||||
public class Mouse extends MouseAdapter
|
||||
{
|
||||
@@ -27,7 +33,9 @@ public class Mouse extends MouseAdapter
|
||||
Point2D clickPoint = panel.getClickPoint(e.getPoint());
|
||||
panel.setLastClickPosition(clickPoint);
|
||||
panel.setLastMousePosition(e.getPoint());
|
||||
if(!panel.getClickedOption().equals("Path")) {
|
||||
|
||||
if (!panel.getClickedOption().equals("Path"))
|
||||
{
|
||||
if (e.getY() < 150)
|
||||
{
|
||||
int i = 0;
|
||||
@@ -37,14 +45,17 @@ public class Mouse extends MouseAdapter
|
||||
if (e.getX() >= panel.getScrollfactor() && e.getX() < last + image.getWidth() + panel.getScrollfactor())
|
||||
{
|
||||
DrawObject tempDrawObj = panel.createNewDrawObject(i);
|
||||
tempDrawObj.setPosition(clickPoint);
|
||||
if(!panel.getObjects().isEmpty())
|
||||
panel.clearObjectSelection();
|
||||
panel.setDragObject(tempDrawObj);
|
||||
panel.getDragObject().setSelected(true);
|
||||
panel.getPP().setSelected(tempDrawObj);
|
||||
panel.setSelectedObject(tempDrawObj);
|
||||
selectedObject = tempDrawObj;
|
||||
if (tempDrawObj != null)
|
||||
{
|
||||
tempDrawObj.setPosition(clickPoint);
|
||||
if (!panel.getObjects().isEmpty())
|
||||
panel.clearObjectSelection();
|
||||
panel.setDragObject(tempDrawObj);
|
||||
panel.getDragObject().setSelected(true);
|
||||
panel.getPP().setSelected(tempDrawObj);
|
||||
panel.setSelectedObject(tempDrawObj);
|
||||
selectedObject = tempDrawObj;
|
||||
}
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
@@ -61,6 +72,13 @@ public class Mouse extends MouseAdapter
|
||||
{
|
||||
if (o.contains(clickPoint))
|
||||
{
|
||||
if (SwingUtilities.isRightMouseButton(e))
|
||||
{
|
||||
if (o instanceof Waypoint)
|
||||
{
|
||||
new WaypointPopup(o);
|
||||
}
|
||||
}
|
||||
if (o == selectedObject)
|
||||
{
|
||||
boolean upperLeft = o.containsCorner(clickPoint, 0);
|
||||
@@ -101,7 +119,7 @@ public class Mouse extends MouseAdapter
|
||||
panel.getPP().setSelected(o);
|
||||
panel.setSelectedObject(o);
|
||||
panel.setSelectionPosition(panel.getDragObject().getPosition());
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
panel.checkPath(clickPoint);
|
||||
@@ -114,21 +132,26 @@ public class Mouse extends MouseAdapter
|
||||
selectedObject = null;
|
||||
}
|
||||
}
|
||||
else { //Making path.
|
||||
panel.getCurrentPath().addPoint(new Point2D.Double(clickPoint.getX(),clickPoint.getY()));
|
||||
else
|
||||
{ // Making path.
|
||||
panel.getCurrentPath().addPoint(new Point2D.Double(clickPoint.getX(), clickPoint.getY()));
|
||||
}
|
||||
panel.repaint();
|
||||
}
|
||||
|
||||
|
||||
public void mouseReleased(MouseEvent e)
|
||||
{
|
||||
if(panel.getDragObject() != null) {
|
||||
if(panel.getDragObject().getRectangleColor() != Color.RED) {
|
||||
if (panel.getDragObject() != null)
|
||||
{
|
||||
if (panel.getDragObject().getRectangleColor() != Color.RED)
|
||||
{
|
||||
panel.getDragObject().setPosition(panel.getDragObject().getPosition(), true);
|
||||
panel.getPP().update();
|
||||
panel.setDragObject(null);
|
||||
panel.setClickedOption("drag");
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
panel.getDragObject().setPosition(panel.getSelectionPosition());
|
||||
panel.getDragObject().setRectangleColor(Color.BLACK);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package Listeners;
|
||||
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
|
||||
import Applicatie.Panel;
|
||||
|
||||
public class WindowFocusListener implements FocusListener
|
||||
{
|
||||
Panel p;
|
||||
|
||||
public WindowFocusListener(Panel p)
|
||||
{
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void focusGained(FocusEvent e){}
|
||||
|
||||
@Override
|
||||
public void focusLost(FocusEvent e)
|
||||
{
|
||||
p.requestFocus();
|
||||
}
|
||||
}
|
||||
@@ -234,6 +234,10 @@ public abstract class DrawObject implements Serializable
|
||||
{
|
||||
this.position = position;
|
||||
}
|
||||
public void setPosition(Point2D position, boolean b)
|
||||
{
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public double getRotation()
|
||||
{
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package Objects;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import Applicatie.Panel;
|
||||
|
||||
public class Entrance extends DrawObject
|
||||
{
|
||||
@@ -15,5 +18,35 @@ public class Entrance extends DrawObject
|
||||
{
|
||||
return "Entrance";
|
||||
}
|
||||
|
||||
public void setPosition(Point2D position, boolean b)
|
||||
{
|
||||
//this.position = position;
|
||||
Rectangle2D rect = getRectangle();
|
||||
double xl = (Panel.getFieldWidth()/2) + rect.getMinX();
|
||||
double xr = Panel.getFieldWidth() - (Panel.getFieldWidth()/2 + rect.getMaxX());
|
||||
double yt = (Panel.getFieldHeight()/2) + rect.getMinY();
|
||||
double yb = Panel.getFieldHeight() - (Panel.getFieldHeight()/2 + rect.getMaxY());
|
||||
if(xl < xr && xl < yt && xl < yb)
|
||||
{
|
||||
this.position = new Point2D.Double(-Panel.getFieldWidth()/2, position.getY());
|
||||
}
|
||||
else if(xr < xl && xr < yt && xr < yb)
|
||||
{
|
||||
this.position = new Point2D.Double(Panel.getFieldWidth()/2 - rect.getWidth(), position.getY());
|
||||
}
|
||||
else if(yt < xl && yt < xr && yt < yb)
|
||||
{
|
||||
this.position = new Point2D.Double(position.getX(), -Panel.getFieldHeight()/2);
|
||||
}
|
||||
else if(yb < xl && yb < yt && yb < xr)
|
||||
{
|
||||
this.position = new Point2D.Double(position.getX(), Panel.getFieldHeight()/2 - rect.getHeight());
|
||||
}
|
||||
else
|
||||
{
|
||||
this.position = new Point2D.Double(-Panel.getFieldWidth()/2, -Panel.getFieldHeight()/2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+107
-39
@@ -14,105 +14,173 @@ import java.util.ArrayList;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import Applicatie.Waypoint;
|
||||
|
||||
/**
|
||||
* Create's a path.
|
||||
*
|
||||
* @author Wesley de Hek
|
||||
* @version 1.2
|
||||
*/
|
||||
public class Path {
|
||||
|
||||
public class Path
|
||||
{
|
||||
|
||||
private ArrayList<Point2D> points;
|
||||
private ArrayList<Shape> lines;
|
||||
private Point2D tempPoint;
|
||||
private BufferedImage pathBackground;
|
||||
|
||||
private ArrayList<Waypoint> waypoints;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Path() {
|
||||
public Path()
|
||||
{
|
||||
points = new ArrayList<>();
|
||||
lines = new ArrayList<>();
|
||||
try {
|
||||
waypoints = new ArrayList<Waypoint>();
|
||||
try
|
||||
{
|
||||
pathBackground = ImageIO.read(new File("images/newPath.png"));
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draws the path.
|
||||
* @param g2 - the Graphics2D object.
|
||||
*
|
||||
* @param g2
|
||||
* - the Graphics2D object.
|
||||
*/
|
||||
public void draw(Graphics2D g2) {
|
||||
TexturePaint paint = new TexturePaint(pathBackground,new Rectangle2D.Double(0,0,128,128));
|
||||
public void draw(Graphics2D g2)
|
||||
{
|
||||
TexturePaint paint = new TexturePaint(pathBackground, new Rectangle2D.Double(0, 0, 128, 128));
|
||||
g2.setPaint(paint);
|
||||
g2.setStroke(new BasicStroke(30,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
|
||||
if(!points.isEmpty()) {
|
||||
for(int i = 1; i < points.size(); i++) {
|
||||
Point2D previousPoint = points.get(i-1);
|
||||
g2.setStroke(new BasicStroke(30, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
|
||||
if (!points.isEmpty())
|
||||
{
|
||||
for (int i = 1; i < points.size(); i++)
|
||||
{
|
||||
Point2D previousPoint = points.get(i - 1);
|
||||
Point2D point = points.get(i);
|
||||
g2.drawLine((int) previousPoint.getX(),(int) previousPoint.getY(),(int) point.getX(),(int) point.getY());
|
||||
g2.drawLine((int) previousPoint.getX(), (int) previousPoint.getY(), (int) point.getX(), (int) point.getY());
|
||||
}
|
||||
//Drawing line that follows the mouse:
|
||||
if(tempPoint != null) {
|
||||
Point2D lastPoint = points.get(points.size()-1);
|
||||
g2.drawLine((int) lastPoint.getX(),(int) lastPoint.getY(),(int) tempPoint.getX(),(int) tempPoint.getY());
|
||||
// Drawing line that follows the mouse:
|
||||
if (tempPoint != null)
|
||||
{
|
||||
Point2D lastPoint = points.get(points.size() - 1);
|
||||
g2.drawLine((int) lastPoint.getX(), (int) lastPoint.getY(), (int) tempPoint.getX(), (int) tempPoint.getY());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if one of the lines contains the given point and return the Shape.
|
||||
*
|
||||
* @param point
|
||||
* - The point of your object.
|
||||
* @return if the Shape contains the point.
|
||||
*/
|
||||
public Shape containsPointShape(Point2D point)
|
||||
{
|
||||
for (Shape line : getPath())
|
||||
{
|
||||
if (line.contains(point))
|
||||
{
|
||||
return line;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if one of the lines contains the given point.
|
||||
* @param point - the point you want to containment with.
|
||||
*
|
||||
* @param point
|
||||
* - the point you want to containment with.
|
||||
* @return if the path contains the point.
|
||||
*/
|
||||
public boolean containsPoint(Point2D point) {
|
||||
for(Shape line : getPath()) {
|
||||
if(line.contains(point)) {
|
||||
public boolean containsPoint(Point2D point)
|
||||
{
|
||||
for (Shape line : getPath())
|
||||
{
|
||||
if (line.contains(point))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean intersectsRect(Rectangle2D rect)
|
||||
{
|
||||
for(Shape line : getPath())
|
||||
{
|
||||
if(line.intersects(rect))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get array with line's from the points.
|
||||
*
|
||||
* @return a array with all the lines of the path.
|
||||
*/
|
||||
public ArrayList<Shape> getPath() {
|
||||
public ArrayList<Shape> getPath()
|
||||
{
|
||||
lines.clear();
|
||||
for(int i = 1; i < points.size(); i++) {
|
||||
Point2D previousPoint = points.get(i-1);
|
||||
for (int i = 1; i < points.size(); i++)
|
||||
{
|
||||
Point2D previousPoint = points.get(i - 1);
|
||||
Point2D point = points.get(i);
|
||||
Line2D line = new Line2D.Double((int) previousPoint.getX(),(int) previousPoint.getY(),(int) point.getX(),(int) point.getY());
|
||||
BasicStroke stroke = new BasicStroke(30,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND);
|
||||
Line2D line = new Line2D.Double((int) previousPoint.getX(), (int) previousPoint.getY(), (int) point.getX(), (int) point.getY());
|
||||
BasicStroke stroke = new BasicStroke(30, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
|
||||
lines.add(stroke.createStrokedShape(line));
|
||||
}
|
||||
return lines;
|
||||
return lines;
|
||||
}
|
||||
|
||||
public void addWaypoint(Waypoint w)
|
||||
{
|
||||
waypoints.add(w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a point to the path.
|
||||
* @param point - the point you want the path to pass.
|
||||
*
|
||||
* @param point
|
||||
* - the point you want the path to pass.
|
||||
*/
|
||||
public void addPoint(Point2D point) {
|
||||
public void addPoint(Point2D point)
|
||||
{
|
||||
points.add(point);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all the path points.
|
||||
*
|
||||
* @return all the points of the path.
|
||||
*/
|
||||
public ArrayList<Point2D> getPoints() {
|
||||
public ArrayList<Point2D> getPoints()
|
||||
{
|
||||
return points;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the temporary point, useful for following the mouse while drawing the path.
|
||||
* @param point - the point of the mouse.
|
||||
* Set the temporary point, useful for following the mouse while drawing the
|
||||
* path.
|
||||
*
|
||||
* @param point
|
||||
* - the point of the mouse.
|
||||
*/
|
||||
public void setTempPoint(Point2D point) {
|
||||
public void setTempPoint(Point2D point)
|
||||
{
|
||||
tempPoint = point;
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
-1
@@ -2,11 +2,16 @@ package Objects;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import Agenda.AgendaStage;
|
||||
|
||||
public class Stage extends DrawObject
|
||||
{
|
||||
public Stage(Point2D position)
|
||||
AgendaStage stage;
|
||||
|
||||
public Stage(Point2D position, AgendaStage st)
|
||||
{
|
||||
super("stage", position);
|
||||
stage = st;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -15,4 +20,14 @@ public class Stage extends DrawObject
|
||||
return "Stage";
|
||||
}
|
||||
|
||||
public AgendaStage getStage()
|
||||
{
|
||||
return stage;
|
||||
}
|
||||
|
||||
public void setStage(AgendaStage stage)
|
||||
{
|
||||
this.stage = stage;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user