ok
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;
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package Agenda;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Stage implements Serializable {
|
||||
public class AgendaStage implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
|
||||
public Stage(String name, String description)
|
||||
public AgendaStage(String name, String description)
|
||||
{
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ package Agenda;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
@@ -19,13 +19,13 @@ 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));
|
||||
@@ -74,11 +74,11 @@ 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);
|
||||
|
||||
@@ -109,7 +109,7 @@ public class ControlPanel extends JPanel
|
||||
peopleButton.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
p.addVisitors(300);
|
||||
p.addVisitors(1);
|
||||
}
|
||||
});
|
||||
peoplePanel.add(peopleButton);
|
||||
@@ -128,4 +128,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)
|
||||
|
||||
+83
-32
@@ -6,6 +6,7 @@ import java.awt.event.ActionListener;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
public class MenuBar extends JMenuBar
|
||||
{
|
||||
@@ -17,17 +18,17 @@ public class MenuBar extends JMenuBar
|
||||
|
||||
JMenu file = new JMenu("File");
|
||||
|
||||
JMenuItem exit = new JMenuItem("Exit");
|
||||
exit.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
w.setVisible(false);
|
||||
w.dispose();
|
||||
JMenuItem item = new JMenuItem("New");
|
||||
item.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
NewWorldPanel world = new NewWorldPanel(w.getPanel());
|
||||
}
|
||||
});
|
||||
file.add(item);
|
||||
|
||||
JMenuItem agenda = new JMenuItem("Open Agenda");
|
||||
JMenuItem agenda = new JMenuItem("Open Planner");
|
||||
agenda.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
@@ -35,41 +36,91 @@ public class MenuBar extends JMenuBar
|
||||
new Agenda.Window();
|
||||
}
|
||||
});
|
||||
|
||||
JMenuItem save = new JMenuItem("Save terrain");
|
||||
save.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
SaveLoad.save(w.getPanel());
|
||||
file.add(agenda);
|
||||
|
||||
item = new JMenuItem("Load agenda");
|
||||
item.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
w.getPanel().agenda.loadAgenda();
|
||||
}
|
||||
});
|
||||
|
||||
JMenuItem load = new JMenuItem("Load terrain");
|
||||
load.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
file.add(item);
|
||||
|
||||
item = new JMenuItem("Load terrain");
|
||||
item.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
SaveLoad.load(w.getPanel());
|
||||
}
|
||||
});
|
||||
|
||||
JMenuItem loadagenda = new JMenuItem("Load agenda");
|
||||
loadagenda.addActionListener(new ActionListener()
|
||||
file.add(item);
|
||||
|
||||
item = new JMenuItem("Save terrain");
|
||||
item.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
SaveLoad.save(w.getPanel());
|
||||
}
|
||||
});
|
||||
file.add(item);
|
||||
|
||||
file.addSeparator();
|
||||
|
||||
item = new JMenuItem("Agenda");
|
||||
item.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
w.getPanel().getAgenda().loadAgenda();
|
||||
w.getPanel().addVisitors();
|
||||
new Agenda.Window();
|
||||
}
|
||||
});
|
||||
file.add(item);
|
||||
|
||||
file.addSeparator();
|
||||
|
||||
item = new JMenuItem("Exit");
|
||||
item.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
w.setVisible(false);
|
||||
w.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
file.add(agenda);
|
||||
file.add(loadagenda);
|
||||
file.add(load);
|
||||
file.add(save);
|
||||
file.add(exit);
|
||||
|
||||
file.add(item);
|
||||
add(file);
|
||||
|
||||
file = new JMenu("Path");
|
||||
|
||||
item = new JMenuItem("New Path");
|
||||
item.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
w.getPanel().startPath();
|
||||
}
|
||||
});
|
||||
|
||||
file.add(item);
|
||||
add(file);
|
||||
|
||||
file = new JMenu("Help");
|
||||
|
||||
item = new JMenuItem("About");
|
||||
item.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JOptionPane.showMessageDialog(w.getFrames()[0],"Festivalplanner\nMade by: Wesley de Hek, Kenneth van Ewijk, Remco Sannen, Yorick Rommers & Guus van Dongen ");
|
||||
}
|
||||
});
|
||||
file.add(item);
|
||||
add(file);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package Applicatie;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class NewWorldPanel extends JFrame {
|
||||
|
||||
BufferedImage grass,sand,selectedImage;
|
||||
|
||||
public NewWorldPanel(Panel topPanel) {
|
||||
super("New World");
|
||||
setDefaultCloseOperation(HIDE_ON_CLOSE);
|
||||
setResizable(false);
|
||||
|
||||
try {
|
||||
grass = ImageIO.read(new File("images/grassIcon.jpg"));
|
||||
sand = ImageIO.read(new File("images/sand.jpg"));
|
||||
selectedImage = grass;
|
||||
}
|
||||
catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String[] terrains = {"Grass", "Sand"};
|
||||
JPanel mainPanel = new JPanel(new BorderLayout());
|
||||
JButton button;
|
||||
JLabel label;
|
||||
JTextField heightTextField;
|
||||
JTextField widthTextField;
|
||||
JComboBox terrainBox;
|
||||
JLabel imageLabel;
|
||||
|
||||
//Top:
|
||||
JPanel panel = new JPanel();
|
||||
BoxLayout box = new BoxLayout(panel, BoxLayout.Y_AXIS);
|
||||
panel.setLayout(box);
|
||||
panel.add(Box.createRigidArea(new Dimension(0,10)));
|
||||
JPanel linePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
label = new JLabel(" Enter your preferences: ");
|
||||
linePanel.add(label);
|
||||
panel.add(linePanel);
|
||||
panel.add(Box.createRigidArea(new Dimension(0,10)));
|
||||
//Width:
|
||||
linePanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
label = new JLabel("Width: ");
|
||||
widthTextField = new JTextField("1920");
|
||||
widthTextField.setPreferredSize(new Dimension(100,20));
|
||||
linePanel.add(label);
|
||||
linePanel.add(widthTextField);
|
||||
panel.add(linePanel);
|
||||
//Height:
|
||||
linePanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
label = new JLabel("Height: ");
|
||||
heightTextField = new JTextField("1080");
|
||||
heightTextField.setPreferredSize(new Dimension(100,20));
|
||||
linePanel.add(label);
|
||||
linePanel.add(heightTextField);
|
||||
panel.add(linePanel);
|
||||
//Terrain:
|
||||
linePanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
label = new JLabel("Terrain: ");
|
||||
terrainBox = new JComboBox(terrains);
|
||||
terrainBox.setPreferredSize(new Dimension(100,20));
|
||||
imageLabel = new JLabel(new ImageIcon(selectedImage));
|
||||
terrainBox.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
switch(terrainBox.getSelectedIndex()) {
|
||||
case 0:
|
||||
selectedImage = grass;
|
||||
break;
|
||||
case 1:
|
||||
selectedImage = sand;
|
||||
break;
|
||||
}
|
||||
imageLabel.setIcon(new ImageIcon(selectedImage));
|
||||
}
|
||||
});
|
||||
linePanel.add(label);
|
||||
linePanel.add(terrainBox);
|
||||
panel.add(linePanel);
|
||||
//Image:
|
||||
linePanel = new JPanel();
|
||||
linePanel.add(imageLabel);
|
||||
panel.add(linePanel);
|
||||
|
||||
mainPanel.add(panel,BorderLayout.NORTH);
|
||||
//Bottom:
|
||||
panel = new JPanel();
|
||||
//Cancel:
|
||||
button = new JButton("Cancel");
|
||||
button.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
NewWorldPanel.this.dispose();
|
||||
}
|
||||
});
|
||||
panel.add(button);
|
||||
|
||||
button = new JButton("Apply");
|
||||
button.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
topPanel.newWorld(Integer.parseInt(widthTextField.getText()),Integer.parseInt(heightTextField.getText()),terrainBox.getSelectedIndex());
|
||||
NewWorldPanel.this.dispose();
|
||||
}
|
||||
});
|
||||
panel.add(button);
|
||||
|
||||
mainPanel.add(panel,BorderLayout.SOUTH);
|
||||
add(mainPanel);
|
||||
|
||||
//Finishing off
|
||||
pack();
|
||||
setSize(290,330);
|
||||
setLocationRelativeTo(null);
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
||||
+136
-38
@@ -17,14 +17,18 @@ 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;
|
||||
@@ -38,28 +42,32 @@ import Objects.Toilet;
|
||||
import Objects.Wall;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class Panel extends JPanel implements ActionListener
|
||||
public class Panel extends JPanel implements ActionListener
|
||||
{
|
||||
|
||||
BufferedImage grass, sand;
|
||||
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;
|
||||
|
||||
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);
|
||||
@@ -67,8 +75,12 @@ public class Panel extends JPanel implements ActionListener
|
||||
Images images = new Images();
|
||||
javax.swing.Timer t;
|
||||
|
||||
SimpleDateFormat formatter;
|
||||
GregorianCalendar date;
|
||||
|
||||
int currentTime = 540;
|
||||
int tick = 0;
|
||||
|
||||
// how to nieuwe dingen aan het panel toe te voegen:
|
||||
// maak bufferedimage global aan, voeg er een image aan toe, en voeg de
|
||||
// image aan panelInfo toe en het object aan panelTypes.
|
||||
@@ -85,19 +97,25 @@ 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
|
||||
{
|
||||
background = ImageIO.read(new File("images/grass.jpg"));
|
||||
grass = ImageIO.read(new File("images/grass.jpg"));
|
||||
sand = ImageIO.read(new File("images/sand.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/waypoint.png"));
|
||||
background = grass;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
@@ -106,10 +124,10 @@ 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();
|
||||
|
||||
panelInfox = 0;
|
||||
@@ -125,11 +143,9 @@ public class Panel extends JPanel implements ActionListener
|
||||
addMouseMotionListener(new MouseMotion(this));
|
||||
|
||||
addMouseWheelListener(new MouseWheel(this));
|
||||
t = new Timer(1000/100, this);
|
||||
t = new Timer(1000 / 10, this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int getPanelInfoLength()
|
||||
{
|
||||
int panelInfoLength = 0;
|
||||
@@ -146,17 +162,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 6:
|
||||
return new Waypoint(null);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@@ -167,14 +199,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 int getNextTarget()
|
||||
{
|
||||
int last = 0;
|
||||
for (Waypoint w : waypoints)
|
||||
{
|
||||
System.out.println(waypoints);
|
||||
if (w.getSelf() > last)
|
||||
{
|
||||
last = w.getSelf();
|
||||
}
|
||||
}
|
||||
System.out.println(last);
|
||||
return last;
|
||||
}
|
||||
|
||||
public void addVisitors()
|
||||
{
|
||||
visitors.add(new Visitor("visitor", new Point(100, 300), agenda, objects));
|
||||
}
|
||||
|
||||
|
||||
public void addVisitors(int count)
|
||||
{
|
||||
for(int i = 0 ; i < count ; i++)
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
visitors.add(new Visitor("visitor", new Point(100, 300), agenda, objects));
|
||||
}
|
||||
@@ -202,7 +259,8 @@ public class Panel extends JPanel implements ActionListener
|
||||
|
||||
TexturePaint p = new TexturePaint(background, new Rectangle2D.Double(0, 0, 100, 100));
|
||||
g2.setPaint(p);
|
||||
g2.fill(new Rectangle2D.Double(-1920, -1080, 3840, 2160));
|
||||
|
||||
g2.fill(new Rectangle2D.Double(-width / 2, -height / 2, width, height));
|
||||
|
||||
BasicStroke stroke = new BasicStroke(10);
|
||||
g2.setStroke(stroke);
|
||||
@@ -215,11 +273,12 @@ public class Panel extends JPanel implements ActionListener
|
||||
{
|
||||
o.draw(g2);
|
||||
}
|
||||
|
||||
for (Visitor v : visitors){
|
||||
|
||||
for (Visitor v : visitors)
|
||||
{
|
||||
v.draw(g2);
|
||||
}
|
||||
|
||||
|
||||
g2.setTransform(oldTransform);
|
||||
if (currentPath != null)
|
||||
{ // Display text while in path making modes.
|
||||
@@ -522,30 +581,69 @@ public class Panel extends JPanel implements ActionListener
|
||||
{
|
||||
this.agenda = agenda;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tick++;
|
||||
if ( tick >= 10 && visitors.size() > 0){
|
||||
tick = 0;
|
||||
currentTime++;
|
||||
System.out.println(currentTime);
|
||||
}
|
||||
|
||||
for (Visitor v: visitors){
|
||||
v.update(objects, currentTime, visitors);
|
||||
}
|
||||
repaint();
|
||||
|
||||
|
||||
public int getFieldWidth()
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getFieldHeight()
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
public javax.swing.Timer getT()
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
tick++;
|
||||
if (tick >= 10 && visitors.size() > 0)
|
||||
{
|
||||
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, paths);
|
||||
}
|
||||
repaint();
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public void newWorld(int width, int height, int terrainIndex)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
paths.clear();
|
||||
objects.clear();
|
||||
cameraScale = 1;
|
||||
switch (terrainIndex)
|
||||
{
|
||||
case 0:
|
||||
background = grass;
|
||||
break;
|
||||
case 1:
|
||||
background = sand;
|
||||
break;
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,19 +23,17 @@ import javax.swing.JTextField;
|
||||
import Objects.DrawObject;
|
||||
import Objects.Path;
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class PropertiesPanel extends JPanel
|
||||
{
|
||||
|
||||
DrawObject selectedObject = null;
|
||||
Path selectedPath = null;
|
||||
|
||||
|
||||
Panel p = null;
|
||||
|
||||
Dimension spacerDimension = new Dimension(200, 10);
|
||||
|
||||
|
||||
JLabel nameLabel;
|
||||
JPanel areaPanel;
|
||||
Component rigidArea;
|
||||
@@ -88,10 +86,11 @@ public class PropertiesPanel extends JPanel
|
||||
buttonPanel.setMaximumSize(new Dimension(200, 40));
|
||||
buttonPanel.add(buttonLabel);
|
||||
add(buttonPanel);
|
||||
|
||||
//AREA PANEL: AVAILABLE FOR ACTIONLISTENER
|
||||
|
||||
// AREA PANEL: AVAILABLE FOR ACTIONLISTENER
|
||||
areaPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
areaPanel.setVisible(false);
|
||||
|
||||
rigidArea = Box.createRigidArea(spacerDimension);
|
||||
rigidArea.setVisible(false);
|
||||
|
||||
@@ -103,9 +102,10 @@ public class PropertiesPanel extends JPanel
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
if(selectedObject != null)
|
||||
if (selectedObject != null)
|
||||
p.removeObject(selectedObject);
|
||||
else if(selectedPath != null) {
|
||||
else if (selectedPath != null)
|
||||
{
|
||||
p.removePath(selectedPath);
|
||||
}
|
||||
}
|
||||
@@ -118,6 +118,7 @@ public class PropertiesPanel extends JPanel
|
||||
{
|
||||
areaPanel.setVisible(!areaPanel.isVisible());
|
||||
rigidArea.setVisible(!rigidArea.isVisible());
|
||||
|
||||
}
|
||||
});
|
||||
row1ButtonPanel.setPreferredSize(new Dimension(200, 50));
|
||||
@@ -125,30 +126,33 @@ public class PropertiesPanel extends JPanel
|
||||
row1ButtonPanel.add(deleteButton);
|
||||
row1ButtonPanel.add(areaButton);
|
||||
add(row1ButtonPanel);
|
||||
|
||||
|
||||
add(rigidArea);
|
||||
|
||||
//AREA PANEL
|
||||
|
||||
// AREA PANEL
|
||||
JLabel areaLabel = new JLabel("Area size");
|
||||
areaLabel.setFont(new Font("Segoe UI", Font.ITALIC, 20));
|
||||
areaPanel.setPreferredSize(new Dimension(200, 180));
|
||||
areaPanel.setMaximumSize(new Dimension(200, 180));
|
||||
areaPanel.setPreferredSize(new Dimension(200, 150));
|
||||
areaPanel.setMaximumSize(new Dimension(200, 250));
|
||||
areaPanel.add(areaLabel);
|
||||
add(areaPanel);
|
||||
{
|
||||
JPanel areaTopPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
areaTopPanel.setPreferredSize(new Dimension(200, 30));
|
||||
areaTopPanel.setPreferredSize(new Dimension(200, 50));
|
||||
areaPanel.add(areaTopPanel);
|
||||
|
||||
JLabel areaTopLabel = new JLabel("Top ");
|
||||
JLabel areaTopLabel = new JLabel("Top");
|
||||
areaTopPanel.add(areaTopLabel);
|
||||
areaTopField = new JTextField();
|
||||
areaTopField.setPreferredSize(new Dimension(120, 25));
|
||||
areaTopField.setPreferredSize(new Dimension(140, 25));
|
||||
|
||||
{
|
||||
areaTopField.addKeyListener(new KeyListener()
|
||||
{
|
||||
|
||||
public void keyTyped(KeyEvent e){}
|
||||
public void keyTyped(KeyEvent e)
|
||||
{
|
||||
}
|
||||
|
||||
public void keyReleased(KeyEvent e)
|
||||
{
|
||||
@@ -158,20 +162,24 @@ public class PropertiesPanel extends JPanel
|
||||
int top = Integer.parseInt(areaTopField.getText());
|
||||
selectedObject.setAreaTop(top);
|
||||
p.update();
|
||||
} catch (NumberFormatException nfe)
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
areaTopField.setBackground(Color.RED);
|
||||
}
|
||||
}
|
||||
|
||||
public void keyPressed(KeyEvent e){}
|
||||
public void keyPressed(KeyEvent e)
|
||||
{
|
||||
}
|
||||
});
|
||||
}
|
||||
areaTopPanel.add(areaTopField);
|
||||
}
|
||||
{
|
||||
JPanel areaBottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
areaBottomPanel.setPreferredSize(new Dimension(200, 30));
|
||||
areaBottomPanel.setPreferredSize(new Dimension(200, 50));
|
||||
|
||||
areaPanel.add(areaBottomPanel);
|
||||
|
||||
JLabel areaBottomLabel = new JLabel("Bottom");
|
||||
@@ -182,7 +190,9 @@ public class PropertiesPanel extends JPanel
|
||||
areaBottomField.addKeyListener(new KeyListener()
|
||||
{
|
||||
|
||||
public void keyTyped(KeyEvent e){}
|
||||
public void keyTyped(KeyEvent e)
|
||||
{
|
||||
}
|
||||
|
||||
public void keyReleased(KeyEvent e)
|
||||
{
|
||||
@@ -192,31 +202,36 @@ public class PropertiesPanel extends JPanel
|
||||
int bottom = Integer.parseInt(areaBottomField.getText());
|
||||
selectedObject.setAreaBottom(bottom);
|
||||
p.update();
|
||||
} catch (NumberFormatException nfe)
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
areaBottomField.setBackground(Color.RED);
|
||||
}
|
||||
}
|
||||
|
||||
public void keyPressed(KeyEvent e){}
|
||||
public void keyPressed(KeyEvent e)
|
||||
{
|
||||
}
|
||||
});
|
||||
}
|
||||
areaBottomPanel.add(areaBottomField);
|
||||
}
|
||||
{
|
||||
JPanel areaLeftPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
areaLeftPanel.setPreferredSize(new Dimension(200, 30));
|
||||
areaLeftPanel.setPreferredSize(new Dimension(200, 50));
|
||||
areaPanel.add(areaLeftPanel);
|
||||
|
||||
JLabel areaLeftLabel = new JLabel("Left ");
|
||||
JLabel areaLeftLabel = new JLabel("Left");
|
||||
areaLeftPanel.add(areaLeftLabel);
|
||||
areaLeftField = new JTextField();
|
||||
areaLeftField.setPreferredSize(new Dimension(120, 25));
|
||||
areaLeftField.setPreferredSize(new Dimension(138, 25));
|
||||
{
|
||||
areaLeftField.addKeyListener(new KeyListener()
|
||||
{
|
||||
|
||||
public void keyTyped(KeyEvent e){}
|
||||
public void keyTyped(KeyEvent e)
|
||||
{
|
||||
}
|
||||
|
||||
public void keyReleased(KeyEvent e)
|
||||
{
|
||||
@@ -226,31 +241,37 @@ public class PropertiesPanel extends JPanel
|
||||
int left = Integer.parseInt(areaLeftField.getText());
|
||||
selectedObject.setAreaLeft(left);
|
||||
p.update();
|
||||
} catch (NumberFormatException nfe)
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
areaLeftField.setBackground(Color.RED);
|
||||
}
|
||||
}
|
||||
|
||||
public void keyPressed(KeyEvent e){}
|
||||
public void keyPressed(KeyEvent e)
|
||||
{
|
||||
}
|
||||
});
|
||||
}
|
||||
areaLeftPanel.add(areaLeftField);
|
||||
}
|
||||
{
|
||||
JPanel areaRightPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
areaRightPanel.setPreferredSize(new Dimension(200, 30));
|
||||
|
||||
areaRightPanel.setPreferredSize(new Dimension(200, 50));
|
||||
areaPanel.add(areaRightPanel);
|
||||
|
||||
JLabel areaRightLabel = new JLabel("Right ");
|
||||
JLabel areaRightLabel = new JLabel("Right");
|
||||
areaRightPanel.add(areaRightLabel);
|
||||
areaRightField = new JTextField();
|
||||
areaRightField.setPreferredSize(new Dimension(120, 25));
|
||||
areaRightField.setPreferredSize(new Dimension(130, 25));
|
||||
{
|
||||
areaRightField.addKeyListener(new KeyListener()
|
||||
{
|
||||
|
||||
public void keyTyped(KeyEvent e){}
|
||||
public void keyTyped(KeyEvent e)
|
||||
{
|
||||
}
|
||||
|
||||
public void keyReleased(KeyEvent e)
|
||||
{
|
||||
@@ -260,13 +281,16 @@ public class PropertiesPanel extends JPanel
|
||||
int right = Integer.parseInt(areaRightField.getText());
|
||||
selectedObject.setAreaRight(right);
|
||||
p.update();
|
||||
} catch (NumberFormatException nfe)
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
areaRightField.setBackground(Color.RED);
|
||||
}
|
||||
}
|
||||
|
||||
public void keyPressed(KeyEvent e){}
|
||||
public void keyPressed(KeyEvent e)
|
||||
{
|
||||
}
|
||||
});
|
||||
}
|
||||
areaRightPanel.add(areaRightField);
|
||||
@@ -308,7 +332,8 @@ public class PropertiesPanel extends JPanel
|
||||
double xpos = Double.parseDouble(locationXField.getText());
|
||||
selectedObject.setPosition(new Point2D.Double(xpos, selectedObject.getPosition().getY()));
|
||||
p.update();
|
||||
} catch (NumberFormatException nfe)
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
locationXField.setBackground(Color.RED);
|
||||
}
|
||||
@@ -347,7 +372,8 @@ public class PropertiesPanel extends JPanel
|
||||
selectedObject.setPosition(new Point2D.Double(selectedObject.getPosition().getX(), ypos));
|
||||
;
|
||||
p.update();
|
||||
} catch (NumberFormatException nfe)
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
|
||||
locationYField.setBackground(Color.RED);
|
||||
@@ -394,9 +420,16 @@ 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)
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
scaleField.setBackground(Color.RED);
|
||||
}
|
||||
@@ -444,7 +477,8 @@ public class PropertiesPanel extends JPanel
|
||||
rotationField.setText(rotation + "");
|
||||
selectedObject.setRotation(rotation);
|
||||
p.update();
|
||||
} catch (NumberFormatException nfe)
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
rotationField.setBackground(Color.RED);
|
||||
}
|
||||
@@ -491,8 +525,8 @@ public class PropertiesPanel extends JPanel
|
||||
|
||||
public void update()
|
||||
{
|
||||
if(selectedObject != null)
|
||||
fillFields();
|
||||
if (selectedObject != null)
|
||||
fillFields();
|
||||
}
|
||||
|
||||
private void enableComponents(Container container, boolean enable)
|
||||
@@ -532,18 +566,18 @@ public class PropertiesPanel extends JPanel
|
||||
|
||||
private void fillFields()
|
||||
{
|
||||
|
||||
nameLabel.setText(selectedObject.getName());
|
||||
|
||||
locationXField.setText(Math.round(selectedObject.getPosition().getX()) + "");
|
||||
locationYField.setText(Math.round(selectedObject.getPosition().getY()) + "");
|
||||
scaleField.setText((double) Math.round(selectedObject.getScale() * 10) / 10 + "");
|
||||
rotationField.setText(Math.round(selectedObject.getRotation() % 360) + "");
|
||||
|
||||
areaTopField.setText(selectedObject.getAreaTop() + "");
|
||||
areaBottomField.setText(selectedObject.getAreaBottom() + "");
|
||||
areaLeftField.setText(selectedObject.getAreaLeft() + "");
|
||||
areaRightField.setText(selectedObject.getAreaRight() + "");
|
||||
nameLabel.setText(selectedObject.getName());
|
||||
|
||||
locationXField.setText(Math.round(selectedObject.getPosition().getX()) + "");
|
||||
locationYField.setText(Math.round(selectedObject.getPosition().getY()) + "");
|
||||
scaleField.setText((double) Math.round(selectedObject.getScale() * 10) / 10 + "");
|
||||
rotationField.setText(Math.round(selectedObject.getRotation() % 360) + "");
|
||||
|
||||
areaTopField.setText(selectedObject.getAreaTop() + "");
|
||||
areaBottomField.setText(selectedObject.getAreaBottom() + "");
|
||||
areaLeftField.setText(selectedObject.getAreaLeft() + "");
|
||||
areaRightField.setText(selectedObject.getAreaRight() + "");
|
||||
|
||||
}
|
||||
|
||||
@@ -551,14 +585,16 @@ public class PropertiesPanel extends JPanel
|
||||
{
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
public void setSelectedPath(Path path) {
|
||||
|
||||
public void setSelectedPath(Path path)
|
||||
{
|
||||
selectedObject = null;
|
||||
selectedPath = path;
|
||||
fillPathFields();
|
||||
}
|
||||
|
||||
private void fillPathFields() {
|
||||
|
||||
private void fillPathFields()
|
||||
{
|
||||
nameLabel.setText("Path");
|
||||
enableComponents(this, true);
|
||||
locationXField.setEnabled(false);
|
||||
|
||||
+216
-62
@@ -3,13 +3,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.Area;
|
||||
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.Path;
|
||||
|
||||
public class Visitor
|
||||
{
|
||||
@@ -22,6 +28,7 @@ public class Visitor
|
||||
ArrayList<Action> actions;
|
||||
Agenda agenda;
|
||||
ArrayList<DrawObject> objects;
|
||||
char target;
|
||||
|
||||
public Visitor(String filename, Point2D position, Agenda agenda, ArrayList<DrawObject> objects)
|
||||
{
|
||||
@@ -34,6 +41,7 @@ public class Visitor
|
||||
this.agenda = agenda;
|
||||
this.objects = objects;
|
||||
fillActions();
|
||||
target = 'z';
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g2)
|
||||
@@ -49,12 +57,11 @@ 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 void update(ArrayList<DrawObject> objects, int currentTime, ArrayList<Visitor> visitors, ArrayList<Path> paths)
|
||||
{
|
||||
Point2D target = new Point(500, 500);
|
||||
for (Action a : actions)
|
||||
@@ -65,57 +72,179 @@ public class Visitor
|
||||
}
|
||||
|
||||
}
|
||||
moveToTarget(target, objects, visitors);
|
||||
|
||||
moveToTarget(target, objects, visitors, paths);
|
||||
}
|
||||
|
||||
public void moveToTarget(Point2D target, ArrayList<DrawObject> objects, ArrayList<Visitor> visitors)
|
||||
public void moveToTarget(Point2D 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;
|
||||
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 (hitTestVisitor(object) && object != this)
|
||||
// {
|
||||
// possible = false;
|
||||
// }
|
||||
// }
|
||||
if (possible == false)
|
||||
|
||||
if (hasPathBelow)
|
||||
{
|
||||
position = oldPosition;
|
||||
rotation += 0.2;
|
||||
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)
|
||||
{
|
||||
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 (hasCollisionDO(object))
|
||||
{
|
||||
possible = false;
|
||||
}
|
||||
}
|
||||
for (Visitor object : visitors)
|
||||
{
|
||||
if (hasCollision(object) && object != this)
|
||||
{
|
||||
possible = false;
|
||||
}
|
||||
}
|
||||
if (possible == false)
|
||||
{
|
||||
position = oldPosition;
|
||||
rotation += 0.2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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));
|
||||
|
||||
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 (hasCollisionDO(object))
|
||||
{
|
||||
possible = false;
|
||||
}
|
||||
}
|
||||
for (Visitor object : visitors)
|
||||
{
|
||||
if (hasCollision(object) && object != this)
|
||||
{
|
||||
possible = false;
|
||||
}
|
||||
}
|
||||
if (possible == false)
|
||||
{
|
||||
position = oldPosition;
|
||||
rotation += 0.2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,27 +326,52 @@ public class Visitor
|
||||
time = (hours * 100) + minutes;
|
||||
return time;
|
||||
}
|
||||
|
||||
public int getEndX()
|
||||
{
|
||||
|
||||
public boolean hasCollisionDO(DrawObject object){
|
||||
Image image = Images.getImage(filename);
|
||||
return (int) (position.getX() + image.getWidth(null));
|
||||
Image image2 = Images.getImage(object.getFileName());
|
||||
Rectangle recta = new Rectangle((int)position.getX(),(int)position.getY(), image.getWidth(null), image.getHeight(null));
|
||||
Rectangle rectb = new Rectangle((int)object.getPosition().getX(),(int)object.getPosition().getY(), image2.getWidth(null), image2.getHeight(null));
|
||||
|
||||
Area a = new Area(recta);
|
||||
Area b = new Area(rectb);
|
||||
|
||||
AffineTransform transA = new AffineTransform();
|
||||
transA.rotate(rotation, position.getX(), position.getY());
|
||||
|
||||
AffineTransform transB = new AffineTransform();
|
||||
transB.rotate(Math.toRadians(object.getRotation()), object.getPosition().getX(), object.getPosition().getY());
|
||||
|
||||
Area aa = a.createTransformedArea(transA);
|
||||
Area bb = b.createTransformedArea(transB);
|
||||
|
||||
if(bb.intersects(aa.getBounds2D())){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getEndY()
|
||||
{
|
||||
public boolean hasCollision(Visitor v){
|
||||
Image image = Images.getImage(filename);
|
||||
return (int) (position.getY() + image.getHeight(null));
|
||||
Rectangle a = new Rectangle((int)position.getX(),(int)position.getY(), image.getWidth(null), image.getHeight(null));
|
||||
Rectangle b = new Rectangle((int)v.position.getX(),(int)v.position.getY(), image.getWidth(null), image.getHeight(null));
|
||||
|
||||
Area aa = new Area(a);
|
||||
Area bb = new Area(b);
|
||||
|
||||
AffineTransform af = new AffineTransform();
|
||||
af.rotate(rotation, position.getX(), position.getY());
|
||||
|
||||
AffineTransform bf = new AffineTransform();
|
||||
bf.rotate(v.rotation, v.position.getX(), v.position.getY());
|
||||
|
||||
Area ra = aa.createTransformedArea(af);
|
||||
Area rb = bb.createTransformedArea(bf);
|
||||
|
||||
if(ra.intersects(rb.getBounds2D())){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hitTest(DrawObject to2)
|
||||
{
|
||||
return (getEndX() >= to2.getPosition().getX() && getEndY() >= to2.getPosition().getY() && to2.getEndX() >= position.getX() && to2.getEndY() >= position.getY());
|
||||
|
||||
}
|
||||
|
||||
// public boolean hitTestVisitor(Visitor v)
|
||||
// {
|
||||
// return (getEndX() >= v.position.getX() && getEndY() >= v.position.getY() && v.getEndX() >= position.getX() && v.getEndY() >= position.getY());
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
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)
|
||||
{
|
||||
this.self = self;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -5,7 +5,9 @@ import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import Applicatie.NewWorldPanel;
|
||||
import Applicatie.Panel;
|
||||
import Applicatie.SaveLoad;
|
||||
|
||||
public class Keyboard implements KeyListener {
|
||||
|
||||
@@ -54,6 +56,15 @@ public class Keyboard implements KeyListener {
|
||||
else if(e.getKeyCode() == e.VK_P) {
|
||||
panel.startPath();
|
||||
}
|
||||
else if(e.getKeyCode() == e.VK_N) {
|
||||
NewWorldPanel world = new NewWorldPanel(panel);
|
||||
}
|
||||
else if(e.getKeyCode() == e.VK_S) {
|
||||
SaveLoad.save(panel);
|
||||
}
|
||||
else if(e.getKeyCode() == e.VK_O) {
|
||||
SaveLoad.load(panel);
|
||||
}
|
||||
panel.repaint();
|
||||
}
|
||||
|
||||
|
||||
+45
-8
@@ -4,11 +4,14 @@ 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 Applicatie.Panel;
|
||||
import Applicatie.Waypoint;
|
||||
import Objects.DrawObject;
|
||||
import Objects.Stage;
|
||||
import Objects.Path;
|
||||
import Objects.Entrance;
|
||||
|
||||
public class Mouse extends MouseAdapter
|
||||
{
|
||||
@@ -27,7 +30,8 @@ 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 +41,16 @@ public class Mouse extends MouseAdapter
|
||||
if (e.getX() >= panel.getScrollfactor() && e.getX() < last + image.getWidth() + panel.getScrollfactor())
|
||||
{
|
||||
DrawObject tempDrawObj = panel.createNewDrawObject(i);
|
||||
if (tempDrawObj != null){
|
||||
tempDrawObj.setPosition(clickPoint);
|
||||
if(!panel.getObjects().isEmpty())
|
||||
if (!panel.getObjects().isEmpty())
|
||||
panel.clearObjectSelection();
|
||||
panel.setDragObject(tempDrawObj);
|
||||
panel.getDragObject().setSelected(true);
|
||||
panel.getPP().setSelected(tempDrawObj);
|
||||
panel.setSelectedObject(tempDrawObj);
|
||||
selectedObject = tempDrawObj;
|
||||
}
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
@@ -101,7 +107,7 @@ public class Mouse extends MouseAdapter
|
||||
panel.getPP().setSelected(o);
|
||||
panel.setSelectedObject(o);
|
||||
panel.setSelectionPosition(panel.getDragObject().getPosition());
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
panel.checkPath(clickPoint);
|
||||
@@ -114,21 +120,52 @@ 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() instanceof Entrance)
|
||||
{
|
||||
Rectangle2D rect = panel.getDragObject().getRectangle();
|
||||
double xl = (panel.getFieldWidth()/2) + rect.getMinX();
|
||||
double xr = panel.getFieldWidth() - xl+rect.getWidth();
|
||||
double yt = (panel.getFieldHeight()/2) + rect.getMinY();
|
||||
double yb = panel.getFieldHeight() - yt+rect.getHeight();
|
||||
if(xl < xr && xl < yt && xl < yb)
|
||||
{
|
||||
panel.getDragObject().setPosition(new Point2D.Double(-panel.getFieldWidth()/2, rect.getMinY()));
|
||||
}
|
||||
else if(xr < xl && xr < yt && xr < yb)
|
||||
{
|
||||
panel.getDragObject().setPosition(new Point2D.Double(panel.getFieldWidth()/2 - rect.getWidth(), rect.getMinY()));
|
||||
}
|
||||
else if(yt < xl && yt < xr && yt < yb)
|
||||
{
|
||||
panel.getDragObject().setPosition(new Point2D.Double(rect.getMinX(), -panel.getFieldHeight()/2));
|
||||
}
|
||||
else if(yb < xl && yb < yt && yb < xr)
|
||||
{
|
||||
panel.getDragObject().setPosition(new Point2D.Double(rect.getMinX(), panel.getFieldHeight()/2 - rect.getHeight()));
|
||||
}
|
||||
else
|
||||
{
|
||||
panel.getDragObject().setPosition(new Point2D.Double(-panel.getFieldWidth()/2, -panel.getFieldHeight()/2));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
panel.setDragObject(null);
|
||||
panel.setClickedOption("drag");
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
panel.getDragObject().setPosition(panel.getSelectionPosition());
|
||||
panel.getDragObject().setRectangleColor(Color.BLACK);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.awt.event.MouseWheelListener;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import Applicatie.Panel;
|
||||
import Objects.DrawObject;
|
||||
|
||||
public class MouseWheel implements MouseWheelListener
|
||||
{
|
||||
|
||||
@@ -104,7 +104,6 @@ public abstract class DrawObject implements Serializable
|
||||
AffineTransform tx = new AffineTransform();
|
||||
tx.scale(scale, scale);
|
||||
tx.translate(position.getX(), position.getY());
|
||||
System.out.println(position.getX());
|
||||
tx.rotate(Math.toRadians(rotation), (width + areaLeft + areaRight) / 2, (height + areaTop + areaBottom) / 2);
|
||||
return tx;
|
||||
}
|
||||
|
||||
+99
-40
@@ -16,103 +16,162 @@ import javax.imageio.ImageIO;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Path() {
|
||||
public Path()
|
||||
{
|
||||
points = new ArrayList<>();
|
||||
lines = new ArrayList<>();
|
||||
try {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
-6
@@ -1,18 +1,28 @@
|
||||
package Objects;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Stage extends DrawObject
|
||||
{
|
||||
public Stage(Point2D position)
|
||||
{
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import Agenda.Agenda;
|
||||
import Agenda.AgendaStage;
|
||||
|
||||
public class Stage extends DrawObject {
|
||||
AgendaStage stage;
|
||||
|
||||
public Stage(Point2D position, AgendaStage stage) {
|
||||
super("stage", position);
|
||||
this.stage = stage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
public String getName() {
|
||||
return "Stage";
|
||||
}
|
||||
|
||||
public AgendaStage getStage() {
|
||||
return stage;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user