Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
911714f9b5 | ||
|
|
254167ba15 | ||
|
|
b8a7d9c02d | ||
|
|
69c05da3fd | ||
|
|
c2cb07cf3e | ||
|
|
90ca17e28a | ||
|
|
c29ccec789 | ||
|
|
0535d98427 | ||
|
|
a2110d3e58 | ||
|
|
d8efbc8616 | ||
|
|
b9d42cd4eb | ||
|
|
ca90d98d9a | ||
|
|
a3479fc37a | ||
|
|
2f53d1353f | ||
|
|
87bf6d9295 | ||
|
|
a89feaaaab | ||
|
|
df02d793eb | ||
|
|
a00ccbe085 | ||
|
|
835d126d80 | ||
|
|
dd7893375e |
@@ -0,0 +1,128 @@
|
|||||||
|
package Agenda;
|
||||||
|
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.JOptionPane;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
|
|
||||||
|
public class AddArtistPanel extends JFrame{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1;
|
||||||
|
|
||||||
|
public AddArtistPanel(Agenda agenda)
|
||||||
|
{
|
||||||
|
super("Artist addscreen!");
|
||||||
|
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("Artist name: ");
|
||||||
|
panel1.add(name);
|
||||||
|
center.add(panel1);
|
||||||
|
|
||||||
|
JPanel panel2 = new JPanel();
|
||||||
|
JTextField nameTF = new JTextField("",15);
|
||||||
|
panel2.add(nameTF);
|
||||||
|
center.add(panel2);
|
||||||
|
|
||||||
|
JLabel genre = new JLabel("Genre: ");
|
||||||
|
JPanel panel3 = new JPanel();
|
||||||
|
panel3.add(genre);
|
||||||
|
center.add(panel3);
|
||||||
|
|
||||||
|
JTextField genreTF = new JTextField("",15);
|
||||||
|
JPanel panel4 = new JPanel();
|
||||||
|
panel4.add(genreTF);
|
||||||
|
center.add(panel4);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
JPanel panel7 = new JPanel();
|
||||||
|
JLabel description = new JLabel("Description: ");
|
||||||
|
panel7.add(description);
|
||||||
|
center.add(panel7);
|
||||||
|
|
||||||
|
JPanel panel8 = new JPanel();
|
||||||
|
JTextField descriptionTF = new JTextField("", 15);
|
||||||
|
panel8.add(descriptionTF);
|
||||||
|
center.add(panel8);
|
||||||
|
|
||||||
|
JPanel panel9 = new JPanel();
|
||||||
|
JLabel background = new JLabel("Background: ");
|
||||||
|
panel9.add(background);
|
||||||
|
center.add(panel9);
|
||||||
|
|
||||||
|
JPanel panel10 = new JPanel();
|
||||||
|
JTextField backgroundTF = new JTextField("", 15);
|
||||||
|
panel10.add(backgroundTF);
|
||||||
|
center.add(panel10);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
JButton add = new JButton("Add artist!");
|
||||||
|
south.add(add);
|
||||||
|
|
||||||
|
add.addActionListener(new ActionListener()
|
||||||
|
{
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
String name = nameTF.getText();
|
||||||
|
String genre = genreTF.getText();
|
||||||
|
String image = imageTF.getText();
|
||||||
|
String description = descriptionTF.getText();
|
||||||
|
String background = backgroundTF.getText();
|
||||||
|
|
||||||
|
boolean alreadyExists = false;
|
||||||
|
for (Artist artist : agenda.getArtists())
|
||||||
|
{
|
||||||
|
if (artist.getName().equals(name))
|
||||||
|
{
|
||||||
|
alreadyExists = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (name.isEmpty() == true){
|
||||||
|
JOptionPane.showMessageDialog(null, "Fill in a correct name!");
|
||||||
|
}
|
||||||
|
else if (alreadyExists == false)
|
||||||
|
{
|
||||||
|
Artist a = new Artist(name,genre,image,description, background);
|
||||||
|
agenda.addArtist(a);
|
||||||
|
JOptionPane.showMessageDialog(null, "Artist added!");
|
||||||
|
setVisible(false);
|
||||||
|
dispose();
|
||||||
|
Window.updatePanel();
|
||||||
|
} else {
|
||||||
|
JOptionPane.showMessageDialog(null, "Choose a different artist name!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
setContentPane(content);
|
||||||
|
setVisible(true);
|
||||||
|
setSize(500,320);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,308 @@
|
|||||||
|
package Agenda;
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.FlowLayout;
|
||||||
|
import java.awt.GridLayout;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JSeparator;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
|
|
||||||
|
public class AddEventPanel extends JFrame{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1;
|
||||||
|
|
||||||
|
public AddEventPanel(Agenda agenda)
|
||||||
|
{
|
||||||
|
super("Event addscreen!");
|
||||||
|
setDefaultCloseOperation(HIDE_ON_CLOSE);
|
||||||
|
JPanel content = new JPanel(new BorderLayout());
|
||||||
|
JPanel south = new JPanel(new FlowLayout());
|
||||||
|
JPanel center = new JPanel(new GridLayout(7,2));
|
||||||
|
content.add(south, BorderLayout.SOUTH);
|
||||||
|
content.add(center, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
GregorianCalendar today = new GregorianCalendar();
|
||||||
|
|
||||||
|
JPanel panel1 = new JPanel();
|
||||||
|
JLabel name = new JLabel("Event name: ");
|
||||||
|
panel1.add(name);
|
||||||
|
center.add(panel1);
|
||||||
|
|
||||||
|
JPanel panel2 = new JPanel();
|
||||||
|
JTextField nameTF = new JTextField("",15);
|
||||||
|
panel2.add(nameTF);
|
||||||
|
center.add(panel2);
|
||||||
|
|
||||||
|
JLabel starttime = new JLabel("Starttime: ");
|
||||||
|
JPanel panel3 = new JPanel();
|
||||||
|
panel3.add(starttime);
|
||||||
|
center.add(panel3);
|
||||||
|
|
||||||
|
Integer[] hours = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 };
|
||||||
|
JComboBox<Integer> hour = new JComboBox<Integer>(hours);
|
||||||
|
hour.setSelectedIndex(today.get(GregorianCalendar.HOUR_OF_DAY));
|
||||||
|
JPanel panel4 = new JPanel();
|
||||||
|
panel4.add(hour);
|
||||||
|
center.add(panel4);
|
||||||
|
|
||||||
|
Integer[] minutes = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59};
|
||||||
|
JComboBox<Integer> minute = new JComboBox<Integer>(minutes);
|
||||||
|
minute.setSelectedIndex(today.get(GregorianCalendar.MINUTE));
|
||||||
|
panel4.add(minute);
|
||||||
|
panel4.add(new JSeparator(SwingConstants.VERTICAL));
|
||||||
|
panel4.add(new JSeparator(SwingConstants.VERTICAL));
|
||||||
|
|
||||||
|
|
||||||
|
Integer[] days = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};
|
||||||
|
JComboBox<Integer> day = new JComboBox<Integer>(days);
|
||||||
|
day.setSelectedIndex(today.get(GregorianCalendar.DAY_OF_MONTH) - 1);
|
||||||
|
panel4.add(day);
|
||||||
|
|
||||||
|
String[] months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
|
||||||
|
JComboBox<String> month = new JComboBox<String>(months);
|
||||||
|
month.setSelectedIndex(today.get(GregorianCalendar.MONTH));
|
||||||
|
panel4.add(month);
|
||||||
|
|
||||||
|
|
||||||
|
Integer[] years = { 2015,2016,2017,2018};
|
||||||
|
JComboBox<Integer> year = new JComboBox<Integer>(years);
|
||||||
|
panel4.add(year);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
JPanel panel5 = new JPanel();
|
||||||
|
JLabel endtime = new JLabel("Endtime: ");
|
||||||
|
panel5.add(endtime);
|
||||||
|
center.add(panel5);
|
||||||
|
|
||||||
|
JComboBox<Integer> hourE = new JComboBox<Integer>(hours);
|
||||||
|
hourE.setSelectedIndex(today.get(GregorianCalendar.HOUR_OF_DAY));
|
||||||
|
JPanel panel6 = new JPanel();
|
||||||
|
panel6.add(hourE);
|
||||||
|
center.add(panel6);
|
||||||
|
|
||||||
|
JComboBox<Integer> minuteE = new JComboBox<Integer>(minutes);
|
||||||
|
minuteE.setSelectedIndex(today.get(GregorianCalendar.MINUTE+1));
|
||||||
|
panel6.add(minuteE);
|
||||||
|
panel6.add(new JSeparator(SwingConstants.VERTICAL));
|
||||||
|
panel6.add(new JSeparator(SwingConstants.VERTICAL));
|
||||||
|
|
||||||
|
|
||||||
|
JComboBox<Integer> dayE = new JComboBox<Integer>(days);
|
||||||
|
dayE.setSelectedIndex(today.get(GregorianCalendar.DAY_OF_MONTH) - 1);
|
||||||
|
panel6.add(dayE);
|
||||||
|
|
||||||
|
JComboBox<String> monthE = new JComboBox<String>(months);
|
||||||
|
monthE.setSelectedIndex(today.get(GregorianCalendar.MONTH));
|
||||||
|
panel6.add(monthE);
|
||||||
|
|
||||||
|
|
||||||
|
JComboBox<Integer> yearE = new JComboBox<Integer>(years);
|
||||||
|
panel6.add(yearE);
|
||||||
|
|
||||||
|
|
||||||
|
JPanel panel7 = new JPanel();
|
||||||
|
JLabel artist2 = new JLabel("Artist: ");
|
||||||
|
panel7.add(artist2);
|
||||||
|
center.add(panel7);
|
||||||
|
|
||||||
|
JPanel panel8 = new JPanel();
|
||||||
|
String[] artists = new String[agenda.getArtists().size()];
|
||||||
|
|
||||||
|
for ( int idx = 0; idx < agenda.getArtists().size(); idx ++)
|
||||||
|
{
|
||||||
|
artists[idx] = agenda.getArtists().get(idx).getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
JComboBox<String> artist = new JComboBox<String>(artists);
|
||||||
|
panel8.add(artist);
|
||||||
|
center.add(panel8);
|
||||||
|
|
||||||
|
JPanel panel9 = new JPanel();
|
||||||
|
JLabel stage = new JLabel("Stage: ");
|
||||||
|
panel9.add(stage);
|
||||||
|
center.add(panel9);
|
||||||
|
|
||||||
|
JPanel panel10 = new JPanel();
|
||||||
|
String[] stages = new String[agenda.getStages().size()];
|
||||||
|
|
||||||
|
for ( int idx = 0; idx < agenda.getStages().size(); idx ++)
|
||||||
|
{
|
||||||
|
stages[idx] = agenda.getStages().get(idx).getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
JComboBox<String> stage2 = new JComboBox<String>(stages);
|
||||||
|
panel10.add(stage2);
|
||||||
|
center.add(panel10);
|
||||||
|
|
||||||
|
JPanel panel11 = new JPanel();
|
||||||
|
JLabel description = new JLabel("Description: ");
|
||||||
|
panel11.add(description);
|
||||||
|
center.add(panel11);
|
||||||
|
|
||||||
|
JPanel panel12 = new JPanel();
|
||||||
|
JTextField descriptionTF = new JTextField("",15);
|
||||||
|
panel12.add(descriptionTF);
|
||||||
|
center.add(panel12);
|
||||||
|
|
||||||
|
JPanel panel13 = new JPanel();
|
||||||
|
JLabel expectedPopularity = new JLabel("Expected Popularity: ");
|
||||||
|
panel13.add(expectedPopularity);
|
||||||
|
center.add(panel13);
|
||||||
|
|
||||||
|
JPanel panel14 = new JPanel();
|
||||||
|
Integer[] eps= { 1,2,3,4,5,6,7,8,9,10};
|
||||||
|
JComboBox<Integer> ep = new JComboBox<Integer>(eps);
|
||||||
|
panel14.add(ep);
|
||||||
|
center.add(panel14);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
JButton add = new JButton("Add event!");
|
||||||
|
south.add(add);
|
||||||
|
|
||||||
|
add.addActionListener(new ActionListener()
|
||||||
|
{
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
boolean everythingCorrect = true;
|
||||||
|
String name = nameTF.getText();
|
||||||
|
|
||||||
|
int hourS = hour.getSelectedIndex();
|
||||||
|
int minuteS = minute.getSelectedIndex();
|
||||||
|
int dayS = day.getSelectedIndex() + 1;
|
||||||
|
String monthS = (String) month.getSelectedItem();
|
||||||
|
int yearS = year.getSelectedIndex() + 2015;
|
||||||
|
|
||||||
|
int hourEnd = hourE.getSelectedIndex();
|
||||||
|
int minuteEnd = minuteE.getSelectedIndex();
|
||||||
|
int dayEnd = dayE.getSelectedIndex() + 1;
|
||||||
|
String monthEnd = (String) monthE.getSelectedItem();
|
||||||
|
int yearEnd = yearE.getSelectedIndex() + 2015;
|
||||||
|
|
||||||
|
String artistName = (String)artist.getSelectedItem();
|
||||||
|
|
||||||
|
Artist artist = null;
|
||||||
|
|
||||||
|
for(Artist a : agenda.getArtists())
|
||||||
|
{
|
||||||
|
if (a.getName().equals(artistName))
|
||||||
|
{
|
||||||
|
artist = a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String stageName = (String)stage2.getSelectedItem();
|
||||||
|
|
||||||
|
AgendaStage stage = null;
|
||||||
|
|
||||||
|
for(AgendaStage s : agenda.getStages())
|
||||||
|
{
|
||||||
|
if (s.getName().equals(stageName))
|
||||||
|
{
|
||||||
|
stage = s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String description = descriptionTF.getText();
|
||||||
|
|
||||||
|
int popularity = ep.getSelectedIndex() + 1;
|
||||||
|
|
||||||
|
if (dayS > monthDays(monthS)){
|
||||||
|
everythingCorrect = false;
|
||||||
|
JOptionPane.showMessageDialog(null, "Invalid Date!");
|
||||||
|
}
|
||||||
|
else if (yearS > yearEnd || monthToInt(monthS) > monthToInt(monthEnd) || dayS > dayEnd || hourS > hourEnd || minuteS > minuteEnd){
|
||||||
|
everythingCorrect = false;
|
||||||
|
JOptionPane.showMessageDialog(null, "End time is earlier then start time!");
|
||||||
|
}
|
||||||
|
else if (dayS != dayEnd || monthS.equals(monthEnd) == false || yearS != yearEnd){
|
||||||
|
everythingCorrect = false;
|
||||||
|
JOptionPane.showMessageDialog(null, "Event is too long! It can't be longer than a single day.");
|
||||||
|
} else if (name.isEmpty()){
|
||||||
|
everythingCorrect = false;
|
||||||
|
JOptionPane.showMessageDialog(null, "Fill in a correct name!");
|
||||||
|
} else if (stage == null){
|
||||||
|
everythingCorrect = false;
|
||||||
|
JOptionPane.showMessageDialog(null, "Missing a stage!");
|
||||||
|
} else if (artist == null){
|
||||||
|
JOptionPane.showMessageDialog(null, "Missing a artist!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (everythingCorrect == true)
|
||||||
|
{
|
||||||
|
Event event = new Event(name,yearS,monthToInt(monthS),dayS,hourS,minuteS,yearEnd,monthToInt(monthEnd),dayEnd,hourEnd, minuteEnd, artist, stage,description, popularity);
|
||||||
|
agenda.addEvent(event);
|
||||||
|
everythingCorrect = false;
|
||||||
|
JOptionPane.showMessageDialog(null, "Event added!");
|
||||||
|
setVisible(false);
|
||||||
|
dispose();
|
||||||
|
Window.updatePanel();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
setContentPane(content);
|
||||||
|
setVisible(true);
|
||||||
|
setSize(700,320);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int monthToInt(String month)
|
||||||
|
{
|
||||||
|
int number = 0;
|
||||||
|
switch (month)
|
||||||
|
{
|
||||||
|
case "January": number = 1; break;
|
||||||
|
case "February": number = 2; break;
|
||||||
|
case "March": number = 3; break;
|
||||||
|
case "April": number = 4; break;
|
||||||
|
case "May": number = 5; break;
|
||||||
|
case "June":number = 6; break;
|
||||||
|
case "July": number = 7; break;
|
||||||
|
case "August": number = 8; break;
|
||||||
|
case "September":number = 9; break;
|
||||||
|
case "October": number = 10; break;
|
||||||
|
case "November": number = 11; break;
|
||||||
|
case "December": number = 12; break;
|
||||||
|
}
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int monthDays(String month)
|
||||||
|
{
|
||||||
|
int number = 0;
|
||||||
|
switch (month)
|
||||||
|
{
|
||||||
|
case "January": number = 31; break;
|
||||||
|
case "February": number = 28; break;
|
||||||
|
case "March": number = 31; break;
|
||||||
|
case "April": number = 30; break;
|
||||||
|
case "May": number = 31; break;
|
||||||
|
case "June":number = 30; break;
|
||||||
|
case "July": number = 31; break;
|
||||||
|
case "August": number = 31; break;
|
||||||
|
case "September":number = 30; break;
|
||||||
|
case "October": number = 31; break;
|
||||||
|
case "November": number = 30; break;
|
||||||
|
case "December": number = 31; break;
|
||||||
|
}
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
package Agenda;
|
||||||
|
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.JOptionPane;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
|
|
||||||
|
public class AddStagePanel extends JFrame{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1;
|
||||||
|
|
||||||
|
public AddStagePanel(Agenda agenda)
|
||||||
|
{
|
||||||
|
super("Stage addscreen!");
|
||||||
|
setDefaultCloseOperation(HIDE_ON_CLOSE);
|
||||||
|
JPanel content = new JPanel(new BorderLayout());
|
||||||
|
JPanel south = new JPanel(new FlowLayout());
|
||||||
|
JPanel center = new JPanel(new GridLayout(2,2));
|
||||||
|
content.add(south, BorderLayout.SOUTH);
|
||||||
|
content.add(center, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
JPanel panel1 = new JPanel();
|
||||||
|
JLabel name = new JLabel("Stage name: ");
|
||||||
|
panel1.add(name);
|
||||||
|
center.add(panel1);
|
||||||
|
|
||||||
|
JPanel panel2 = new JPanel();
|
||||||
|
JTextField nameTF = new JTextField("",15);
|
||||||
|
panel2.add(nameTF);
|
||||||
|
center.add(panel2);
|
||||||
|
|
||||||
|
JLabel description = new JLabel("Stage Description: ");
|
||||||
|
JPanel panel3 = new JPanel();
|
||||||
|
panel3.add(description);
|
||||||
|
center.add(panel3);
|
||||||
|
|
||||||
|
JTextField descriptionTF = new JTextField("",15);
|
||||||
|
JPanel panel4 = new JPanel();
|
||||||
|
panel4.add(descriptionTF);
|
||||||
|
center.add(panel4);
|
||||||
|
|
||||||
|
|
||||||
|
JButton add = new JButton("Add stage!");
|
||||||
|
south.add(add);
|
||||||
|
|
||||||
|
add.addActionListener(new ActionListener()
|
||||||
|
{
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
String name = nameTF.getText();
|
||||||
|
String description = descriptionTF.getText();
|
||||||
|
|
||||||
|
boolean alreadyExists = false;
|
||||||
|
for (AgendaStage stage : agenda.getStages())
|
||||||
|
{
|
||||||
|
if (stage.getName().equals(name))
|
||||||
|
{
|
||||||
|
alreadyExists = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (name.isEmpty()){
|
||||||
|
JOptionPane.showMessageDialog(null, "Fill in a correct name!");
|
||||||
|
}
|
||||||
|
else if ( alreadyExists == false )
|
||||||
|
{
|
||||||
|
AgendaStage s = new AgendaStage(name,description);
|
||||||
|
agenda.addStage(s);
|
||||||
|
JOptionPane.showMessageDialog(null, "Stage added!");
|
||||||
|
setVisible(false);
|
||||||
|
dispose();
|
||||||
|
Window.updatePanel();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
JOptionPane.showMessageDialog(null, "Choose a different stage name!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
setContentPane(content);
|
||||||
|
setVisible(true);
|
||||||
|
setSize(400,180);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,220 @@
|
|||||||
|
package Agenda;
|
||||||
|
import java.io.EOFException;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.filechooser.FileFilter;
|
||||||
|
|
||||||
|
public class Agenda implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1;
|
||||||
|
|
||||||
|
private ArrayList<AgendaStage> stages;
|
||||||
|
private ArrayList<Event> events;
|
||||||
|
private ArrayList<Artist> artists;
|
||||||
|
|
||||||
|
public Agenda() {
|
||||||
|
stages = new ArrayList<AgendaStage>();
|
||||||
|
events = new ArrayList<Event>();
|
||||||
|
artists = new ArrayList<Artist>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addStage(AgendaStage stage){
|
||||||
|
stages.add(stage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addEvent(Event event) {
|
||||||
|
events.add(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addArtist(Artist artist) {
|
||||||
|
artists.add(artist);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Event> getEvents()
|
||||||
|
{
|
||||||
|
return events;
|
||||||
|
}
|
||||||
|
public ArrayList<Artist> getArtists()
|
||||||
|
{
|
||||||
|
return artists;
|
||||||
|
}
|
||||||
|
public ArrayList<AgendaStage> getStages()
|
||||||
|
{
|
||||||
|
return stages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveAgenda()
|
||||||
|
{
|
||||||
|
JFileChooser fileChooser = new JFileChooser();
|
||||||
|
|
||||||
|
fileChooser.setFileFilter(new FileFilter() {
|
||||||
|
@Override
|
||||||
|
public boolean accept(File pathname) {
|
||||||
|
if(pathname.isFile() && pathname.getName().endsWith(".agn"))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}else if(pathname.isDirectory()){return true;}else{return false;}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return ".agn";
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
fileChooser.setDialogTitle("Choose save location");
|
||||||
|
int userSelection = fileChooser.showSaveDialog(null);
|
||||||
|
|
||||||
|
if(userSelection == JFileChooser.APPROVE_OPTION)
|
||||||
|
{
|
||||||
|
File file = fileChooser.getSelectedFile();
|
||||||
|
if(!file.getName().endsWith(".agn"))
|
||||||
|
{
|
||||||
|
file = new File(file.getAbsolutePath() + ".agn");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
if(JOptionPane.showConfirmDialog(null, "Are you sure you want to overwrite: " + file.getName(), "Overwrite", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION)
|
||||||
|
{
|
||||||
|
saveAgenda(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
saveAgenda(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadAgenda()
|
||||||
|
{
|
||||||
|
JFileChooser fileChooser = new JFileChooser();
|
||||||
|
fileChooser.setFileFilter(new FileFilter() {
|
||||||
|
@Override
|
||||||
|
public boolean accept(File pathname) {
|
||||||
|
if(pathname.isFile() && pathname.getName().endsWith(".agn"))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}else if(pathname.isDirectory()){return true;}else{return false;}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return ".agn";
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
fileChooser.setDialogTitle("Choose file");
|
||||||
|
int userSelection = fileChooser.showOpenDialog(null);
|
||||||
|
|
||||||
|
if(userSelection == JFileChooser.APPROVE_OPTION)
|
||||||
|
{
|
||||||
|
File file = fileChooser.getSelectedFile();
|
||||||
|
if(!file.exists())
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(null, "This file does not exist: " + file.getName());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
clearAgenda();
|
||||||
|
fillAgenda(file);
|
||||||
|
JOptionPane.showMessageDialog(null, "Loaded succesfully");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillAgenda(File file) {
|
||||||
|
FileInputStream fis = null;
|
||||||
|
ObjectInputStream ois = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
fis = new FileInputStream(file);
|
||||||
|
ois = new ObjectInputStream(fis);
|
||||||
|
|
||||||
|
Object object;
|
||||||
|
object = ois.readObject();
|
||||||
|
Agenda a = (Agenda) object;
|
||||||
|
events = a.getEvents();
|
||||||
|
stages = a.getStages();
|
||||||
|
artists = a.getArtists();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillArtists()
|
||||||
|
{
|
||||||
|
for (Event e : events)
|
||||||
|
{
|
||||||
|
boolean exists = false;
|
||||||
|
String name = e.getArtist().getName();
|
||||||
|
for (Artist a : artists)
|
||||||
|
{
|
||||||
|
if ( a.getName().equals(name) ) {
|
||||||
|
exists = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( exists == false) {
|
||||||
|
addArtist(e.getArtist());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillStages()
|
||||||
|
{
|
||||||
|
for (Event e : events)
|
||||||
|
{
|
||||||
|
boolean exists = false;
|
||||||
|
String name = e.getStage().getName();
|
||||||
|
for (AgendaStage s : stages)
|
||||||
|
{
|
||||||
|
if ( s.getName().equals(name) ) {
|
||||||
|
exists = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( exists == false) {
|
||||||
|
addStage(e.getStage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveAgenda(File file) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
FileOutputStream fos = new FileOutputStream(file);
|
||||||
|
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||||
|
oos.writeObject(this);
|
||||||
|
oos.close();
|
||||||
|
JOptionPane.showMessageDialog(null, "Saved succesfully");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearAgenda()
|
||||||
|
{
|
||||||
|
events.clear();
|
||||||
|
stages.clear();
|
||||||
|
artists.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillAllLists()
|
||||||
|
{
|
||||||
|
loadAgenda();
|
||||||
|
fillStages();
|
||||||
|
fillArtists();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package Agenda;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
|
||||||
|
|
||||||
|
public class Artist implements Serializable{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private String genre;
|
||||||
|
private ImageIcon image;
|
||||||
|
private String description;
|
||||||
|
private String background;
|
||||||
|
|
||||||
|
public Artist(String name, String genre, String image, String description, String background)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
this.genre = genre;
|
||||||
|
this.description = description;
|
||||||
|
this.background = background;
|
||||||
|
|
||||||
|
if ( !image.equals("null")) {
|
||||||
|
this.image = new ImageIcon(image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGenre()
|
||||||
|
{
|
||||||
|
return this.genre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageIcon getImage()
|
||||||
|
{
|
||||||
|
return this.image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription()
|
||||||
|
{
|
||||||
|
return this.description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBackground()
|
||||||
|
{
|
||||||
|
return this.background;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGenre(String genre)
|
||||||
|
{
|
||||||
|
this.genre = genre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImageIconString(String image)
|
||||||
|
{
|
||||||
|
this.image = new ImageIcon(image);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImageIcon(ImageIcon image)
|
||||||
|
{
|
||||||
|
this.image = image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description)
|
||||||
|
{
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBackground(String background)
|
||||||
|
{
|
||||||
|
this.background = background;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package Agenda;
|
||||||
|
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
import javax.swing.Box;
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JSeparator;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
|
public class ArtistPanel extends JPanel{
|
||||||
|
|
||||||
|
public ArtistPanel(Event event, Agenda a, TabbedPane tab)
|
||||||
|
{
|
||||||
|
super(new BorderLayout());
|
||||||
|
JLabel name = new JLabel(event.getArtist().getName());
|
||||||
|
JButton edit = new JButton("Edit Info");
|
||||||
|
edit.addActionListener(new ActionListener(){
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e)
|
||||||
|
{
|
||||||
|
EditArtistPanel editter = new EditArtistPanel(a, event.getArtist(), tab);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
name.setFont(new Font("Dialog", Font.BOLD, 20));
|
||||||
|
JLabel description = new JLabel("<html>" + " <b> Genre: </b> " + event.getArtist().getGenre() + "<br> <br> <b> Beschrijving </b> <br> <br>" + event.getArtist().getDescription() + " <br> <br> <b> achtergrondinfo </b> <br> <br>" + event.getArtist().getBackground() + "</html>");
|
||||||
|
description.setFont(new Font("Dialog", Font.PLAIN, 12));
|
||||||
|
JPanel panel = new JPanel();
|
||||||
|
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
|
||||||
|
JPanel panel2 = new JPanel();
|
||||||
|
panel2.setLayout(new BoxLayout(panel2, BoxLayout.LINE_AXIS));
|
||||||
|
panel2.setAlignmentX(LEFT_ALIGNMENT);
|
||||||
|
JLabel photo = new JLabel(event.getArtist().getImage());
|
||||||
|
panel2.add(name);
|
||||||
|
panel2.add(Box.createRigidArea(new Dimension(10,0)));
|
||||||
|
panel2.add(edit);
|
||||||
|
panel.add(panel2);
|
||||||
|
panel.add(new JSeparator(SwingConstants.HORIZONTAL));
|
||||||
|
add(photo, BorderLayout.EAST);
|
||||||
|
add(description, BorderLayout.CENTER);
|
||||||
|
add(panel, BorderLayout.NORTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package Agenda;
|
||||||
|
import javax.swing.AbstractListModel;
|
||||||
|
|
||||||
|
|
||||||
|
public class ContentList extends AbstractListModel {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 9110016552017561529L;
|
||||||
|
|
||||||
|
Object[] data;
|
||||||
|
|
||||||
|
public ContentList(Object[] data)
|
||||||
|
{
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getElementAt(int arg0) {
|
||||||
|
return data[arg0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSize() {
|
||||||
|
return data.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package Agenda;
|
||||||
|
import javax.swing.table.AbstractTableModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is used to make a temporary abstracttableModel with selected data so later it can be passed to the JTable so it refreshes.
|
||||||
|
* @author Wesley
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
public class ContentTable extends AbstractTableModel {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private Object[][] data;
|
||||||
|
private String[] columnNames;
|
||||||
|
|
||||||
|
|
||||||
|
public ContentTable(Object[][] data,String[] columnNames) {
|
||||||
|
this.data = data;
|
||||||
|
this.columnNames = columnNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getColumnCount() {
|
||||||
|
return columnNames.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRowCount() {
|
||||||
|
return data.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||||
|
return data[rowIndex][columnIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getColumnName(int col) {
|
||||||
|
return columnNames[col];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
package Agenda;
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.FlowLayout;
|
||||||
|
import java.awt.GridLayout;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
|
public class EditArtistPanel extends JFrame {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1;
|
||||||
|
|
||||||
|
public EditArtistPanel(Agenda agenda, Artist art, TabbedPane tab)
|
||||||
|
{
|
||||||
|
super("Artist editscreen!");
|
||||||
|
setDefaultCloseOperation(HIDE_ON_CLOSE);
|
||||||
|
JPanel content = new JPanel(new BorderLayout());
|
||||||
|
JPanel south = new JPanel(new FlowLayout());
|
||||||
|
JPanel center = new JPanel(new GridLayout(5,2));
|
||||||
|
content.add(south, BorderLayout.SOUTH);
|
||||||
|
content.add(center, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
JPanel panel1 = new JPanel();
|
||||||
|
JLabel name = new JLabel("Artist name: ");
|
||||||
|
panel1.add(name);
|
||||||
|
center.add(panel1);
|
||||||
|
|
||||||
|
JPanel panel2 = new JPanel();
|
||||||
|
JTextField nameTF = new JTextField(art.getName(),15);
|
||||||
|
panel2.add(nameTF);
|
||||||
|
center.add(panel2);
|
||||||
|
|
||||||
|
JLabel genre = new JLabel("Genre: ");
|
||||||
|
JPanel panel3 = new JPanel();
|
||||||
|
panel3.add(genre);
|
||||||
|
center.add(panel3);
|
||||||
|
|
||||||
|
JTextField genreTF = new JTextField(art.getGenre(),15);
|
||||||
|
JPanel panel4 = new JPanel();
|
||||||
|
panel4.add(genreTF);
|
||||||
|
center.add(panel4);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
JPanel panel7 = new JPanel();
|
||||||
|
JLabel description = new JLabel("Description: ");
|
||||||
|
panel7.add(description);
|
||||||
|
center.add(panel7);
|
||||||
|
|
||||||
|
JPanel panel8 = new JPanel();
|
||||||
|
JTextField descriptionTF = new JTextField(art.getDescription(), 15);
|
||||||
|
panel8.add(descriptionTF);
|
||||||
|
center.add(panel8);
|
||||||
|
|
||||||
|
JPanel panel9 = new JPanel();
|
||||||
|
JLabel background = new JLabel("Background: ");
|
||||||
|
panel9.add(background);
|
||||||
|
center.add(panel9);
|
||||||
|
|
||||||
|
JPanel panel10 = new JPanel();
|
||||||
|
JTextField backgroundTF = new JTextField(art.getBackground(), 15);
|
||||||
|
panel10.add(backgroundTF);
|
||||||
|
center.add(panel10);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
JButton edit = new JButton("Edit artist!");
|
||||||
|
south.add(edit);
|
||||||
|
|
||||||
|
edit.addActionListener(new ActionListener()
|
||||||
|
{
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
String name = nameTF.getText();
|
||||||
|
String genre = genreTF.getText();
|
||||||
|
String image = imageTF.getText();
|
||||||
|
String description = descriptionTF.getText();
|
||||||
|
String background = backgroundTF.getText();
|
||||||
|
|
||||||
|
boolean alreadyExists = false;
|
||||||
|
for (Artist artist : agenda.getArtists())
|
||||||
|
{
|
||||||
|
if (artist.getName().equals(name) && !artist.equals(art))
|
||||||
|
{
|
||||||
|
alreadyExists = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (name.isEmpty() == true){
|
||||||
|
JOptionPane.showMessageDialog(null, "Fill in a correct name!");
|
||||||
|
}
|
||||||
|
else if (alreadyExists == false)
|
||||||
|
{
|
||||||
|
art.setName(name);
|
||||||
|
art.setGenre(genre);
|
||||||
|
art.setImageIconString(image);
|
||||||
|
art.setDescription(description);
|
||||||
|
art.setBackground(background);
|
||||||
|
JOptionPane.showMessageDialog(null, "Artist edited!");
|
||||||
|
setVisible(false);
|
||||||
|
dispose();
|
||||||
|
Window.updatePanel();
|
||||||
|
if(tab != null)
|
||||||
|
{
|
||||||
|
tab.setVisible(false);
|
||||||
|
tab.dispose();
|
||||||
|
Event eventartist = null;
|
||||||
|
for(Event event: agenda.getEvents())
|
||||||
|
{
|
||||||
|
if (event.getArtist().getName().equals(name))
|
||||||
|
{
|
||||||
|
eventartist = event;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TabbedPane panel = new TabbedPane(agenda, eventartist, false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
JOptionPane.showMessageDialog(null, "Choose a different artist name!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JButton remove = new JButton("Remove artist!");
|
||||||
|
for(Event e : agenda.getEvents())
|
||||||
|
{
|
||||||
|
if(e.getArtist().equals(art))
|
||||||
|
{
|
||||||
|
remove.setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
south.add(remove);
|
||||||
|
|
||||||
|
remove.addActionListener(new ActionListener()
|
||||||
|
{
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
||||||
|
if(JOptionPane.showConfirmDialog(null, "Are you sure you want to remove this artist?", "Remove Artist", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION)
|
||||||
|
{
|
||||||
|
Iterator<Artist> it = agenda.getArtists().iterator();
|
||||||
|
while(it.hasNext())
|
||||||
|
{
|
||||||
|
Artist a = it.next();
|
||||||
|
if(a.equals(art))
|
||||||
|
{
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JOptionPane.showMessageDialog(null, "Artist removed!");
|
||||||
|
setVisible(false);
|
||||||
|
dispose();
|
||||||
|
Window.updatePanel();
|
||||||
|
if(tab != null)
|
||||||
|
{
|
||||||
|
tab.setVisible(false);
|
||||||
|
tab.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
setContentPane(content);
|
||||||
|
setVisible(true);
|
||||||
|
setSize(500,320);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,376 @@
|
|||||||
|
package Agenda;
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.FlowLayout;
|
||||||
|
import java.awt.GridLayout;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JSeparator;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
|
|
||||||
|
public class EditEventPanel extends JFrame{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1;
|
||||||
|
|
||||||
|
public EditEventPanel(Agenda agenda, Event e, TabbedPane tab)
|
||||||
|
{
|
||||||
|
super("Event editscreen!");
|
||||||
|
setDefaultCloseOperation(HIDE_ON_CLOSE);
|
||||||
|
JPanel content = new JPanel(new BorderLayout());
|
||||||
|
JPanel south = new JPanel(new FlowLayout());
|
||||||
|
JPanel center = new JPanel(new GridLayout(7,2));
|
||||||
|
content.add(south, BorderLayout.SOUTH);
|
||||||
|
content.add(center, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
|
||||||
|
JPanel panel1 = new JPanel();
|
||||||
|
JLabel name = new JLabel("Event name: ");
|
||||||
|
panel1.add(name);
|
||||||
|
center.add(panel1);
|
||||||
|
|
||||||
|
JPanel panel2 = new JPanel();
|
||||||
|
JTextField nameTF = new JTextField(e.getEventName(),15);
|
||||||
|
panel2.add(nameTF);
|
||||||
|
center.add(panel2);
|
||||||
|
|
||||||
|
JLabel starttime = new JLabel("Starttime: ");
|
||||||
|
JPanel panel3 = new JPanel();
|
||||||
|
panel3.add(starttime);
|
||||||
|
center.add(panel3);
|
||||||
|
|
||||||
|
Integer[] hours = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 };
|
||||||
|
JComboBox<Integer> hour = new JComboBox<Integer>(hours);
|
||||||
|
hour.setSelectedIndex(e.getStartDate().get(GregorianCalendar.HOUR_OF_DAY));
|
||||||
|
JPanel panel4 = new JPanel();
|
||||||
|
panel4.add(hour);
|
||||||
|
center.add(panel4);
|
||||||
|
|
||||||
|
Integer[] minutes = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59};
|
||||||
|
JComboBox<Integer> minute = new JComboBox<Integer>(minutes);
|
||||||
|
minute.setSelectedIndex(e.getStartDate().get(GregorianCalendar.MINUTE));
|
||||||
|
panel4.add(minute);
|
||||||
|
panel4.add(new JSeparator(SwingConstants.VERTICAL));
|
||||||
|
panel4.add(new JSeparator(SwingConstants.VERTICAL));
|
||||||
|
|
||||||
|
|
||||||
|
Integer[] days = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};
|
||||||
|
JComboBox<Integer> day = new JComboBox<Integer>(days);
|
||||||
|
day.setSelectedIndex(e.getStartDate().get(GregorianCalendar.DAY_OF_MONTH) - 1);
|
||||||
|
panel4.add(day);
|
||||||
|
|
||||||
|
String[] months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
|
||||||
|
JComboBox<String> month = new JComboBox<String>(months);
|
||||||
|
month.setSelectedIndex(e.getStartDate().get(GregorianCalendar.MONTH));
|
||||||
|
panel4.add(month);
|
||||||
|
|
||||||
|
|
||||||
|
Integer[] years = { 2015,2016,2017,2018};
|
||||||
|
JComboBox<Integer> year = new JComboBox<Integer>(years);
|
||||||
|
year.setSelectedItem(e.getStartDate().get(GregorianCalendar.YEAR));
|
||||||
|
panel4.add(year);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
JPanel panel5 = new JPanel();
|
||||||
|
JLabel endtime = new JLabel("Endtime: ");
|
||||||
|
panel5.add(endtime);
|
||||||
|
center.add(panel5);
|
||||||
|
|
||||||
|
JComboBox<Integer> hourE = new JComboBox<Integer>(hours);
|
||||||
|
hourE.setSelectedIndex(e.getEndDate().get(GregorianCalendar.HOUR_OF_DAY));
|
||||||
|
JPanel panel6 = new JPanel();
|
||||||
|
panel6.add(hourE);
|
||||||
|
center.add(panel6);
|
||||||
|
|
||||||
|
JComboBox<Integer> minuteE = new JComboBox<Integer>(minutes);
|
||||||
|
minuteE.setSelectedIndex(e.getEndDate().get(GregorianCalendar.MINUTE));
|
||||||
|
panel6.add(minuteE);
|
||||||
|
panel6.add(new JSeparator(SwingConstants.VERTICAL));
|
||||||
|
panel6.add(new JSeparator(SwingConstants.VERTICAL));
|
||||||
|
|
||||||
|
|
||||||
|
JComboBox<Integer> dayE = new JComboBox<Integer>(days);
|
||||||
|
dayE.setSelectedIndex(e.getEndDate().get(GregorianCalendar.DAY_OF_MONTH) - 1);
|
||||||
|
panel6.add(dayE);
|
||||||
|
|
||||||
|
JComboBox<String> monthE = new JComboBox<String>(months);
|
||||||
|
monthE.setSelectedIndex(e.getEndDate().get(GregorianCalendar.MONTH));
|
||||||
|
panel6.add(monthE);
|
||||||
|
|
||||||
|
|
||||||
|
JComboBox<Integer> yearE = new JComboBox<Integer>(years);
|
||||||
|
yearE.setSelectedItem(e.getEndDate().get(GregorianCalendar.YEAR));
|
||||||
|
panel6.add(yearE);
|
||||||
|
|
||||||
|
|
||||||
|
JPanel panel7 = new JPanel();
|
||||||
|
JLabel artist2 = new JLabel("Artist: ");
|
||||||
|
panel7.add(artist2);
|
||||||
|
center.add(panel7);
|
||||||
|
|
||||||
|
JPanel panel8 = new JPanel();
|
||||||
|
String[] artists = new String[agenda.getArtists().size()];
|
||||||
|
int artistIndex = 0;
|
||||||
|
|
||||||
|
for ( int idx = 0; idx < agenda.getArtists().size(); idx ++)
|
||||||
|
{
|
||||||
|
artists[idx] = agenda.getArtists().get(idx).getName();
|
||||||
|
if(agenda.getArtists().get(idx).equals(e.getArtist()))
|
||||||
|
{
|
||||||
|
artistIndex = idx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JComboBox<String> artist = new JComboBox<String>(artists);
|
||||||
|
artist.setSelectedIndex(artistIndex);
|
||||||
|
panel8.add(artist);
|
||||||
|
center.add(panel8);
|
||||||
|
|
||||||
|
JPanel panel9 = new JPanel();
|
||||||
|
JLabel stage = new JLabel("Stage: ");
|
||||||
|
panel9.add(stage);
|
||||||
|
center.add(panel9);
|
||||||
|
|
||||||
|
JPanel panel10 = new JPanel();
|
||||||
|
String[] stages = new String[agenda.getStages().size()];
|
||||||
|
|
||||||
|
int stageIndex = 0;
|
||||||
|
|
||||||
|
for ( int idx = 0; idx < agenda.getStages().size(); idx ++)
|
||||||
|
{
|
||||||
|
stages[idx] = agenda.getStages().get(idx).getName();
|
||||||
|
if(agenda.getStages().get(idx).equals(e.getStage()))
|
||||||
|
{
|
||||||
|
stageIndex = idx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JComboBox<String> stage2 = new JComboBox<String>(stages);
|
||||||
|
stage2.setSelectedIndex(stageIndex);
|
||||||
|
panel10.add(stage2);
|
||||||
|
center.add(panel10);
|
||||||
|
|
||||||
|
JPanel panel11 = new JPanel();
|
||||||
|
JLabel description = new JLabel("Description: ");
|
||||||
|
panel11.add(description);
|
||||||
|
center.add(panel11);
|
||||||
|
|
||||||
|
JPanel panel12 = new JPanel();
|
||||||
|
JTextField descriptionTF = new JTextField(e.getDescription(),15);
|
||||||
|
panel12.add(descriptionTF);
|
||||||
|
center.add(panel12);
|
||||||
|
|
||||||
|
JPanel panel13 = new JPanel();
|
||||||
|
JLabel expectedPopularity = new JLabel("Expected Popularity: ");
|
||||||
|
panel13.add(expectedPopularity);
|
||||||
|
center.add(panel13);
|
||||||
|
|
||||||
|
JPanel panel14 = new JPanel();
|
||||||
|
Integer[] eps= { 1,2,3,4,5,6,7,8,9,10};
|
||||||
|
JComboBox<Integer> ep = new JComboBox<Integer>(eps);
|
||||||
|
ep.setSelectedIndex(e.getExpectedPopularity() - 1);
|
||||||
|
panel14.add(ep);
|
||||||
|
center.add(panel14);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
JButton add = new JButton("Edit event!");
|
||||||
|
south.add(add);
|
||||||
|
|
||||||
|
add.addActionListener(new ActionListener()
|
||||||
|
{
|
||||||
|
public void actionPerformed(ActionEvent f) {
|
||||||
|
boolean everythingCorrect = true;
|
||||||
|
String name = nameTF.getText();
|
||||||
|
|
||||||
|
int hourS = hour.getSelectedIndex();
|
||||||
|
int minuteS = minute.getSelectedIndex();
|
||||||
|
int dayS = day.getSelectedIndex() + 1;
|
||||||
|
String monthS = (String) month.getSelectedItem();
|
||||||
|
int yearS = year.getSelectedIndex() + 2015;
|
||||||
|
|
||||||
|
int hourEnd = hourE.getSelectedIndex();
|
||||||
|
int minuteEnd = minuteE.getSelectedIndex();
|
||||||
|
int dayEnd = dayE.getSelectedIndex() + 1;
|
||||||
|
String monthEnd = (String) monthE.getSelectedItem();
|
||||||
|
int yearEnd = yearE.getSelectedIndex() + 2015;
|
||||||
|
|
||||||
|
String artistName = (String)artist.getSelectedItem();
|
||||||
|
|
||||||
|
Artist artist = null;
|
||||||
|
|
||||||
|
for(Artist a : agenda.getArtists())
|
||||||
|
{
|
||||||
|
if (a.getName().equals(artistName))
|
||||||
|
{
|
||||||
|
artist = a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String stageName = (String)stage2.getSelectedItem();
|
||||||
|
|
||||||
|
AgendaStage stage = null;
|
||||||
|
|
||||||
|
for(AgendaStage s : agenda.getStages())
|
||||||
|
{
|
||||||
|
if (s.getName().equals(stageName))
|
||||||
|
{
|
||||||
|
stage = s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String description = descriptionTF.getText();
|
||||||
|
|
||||||
|
int popularity = ep.getSelectedIndex() + 1;
|
||||||
|
|
||||||
|
if (dayS > monthDays(monthS)){
|
||||||
|
everythingCorrect = false;
|
||||||
|
JOptionPane.showMessageDialog(null, "Invalid Date!");
|
||||||
|
}
|
||||||
|
else if (yearS > yearEnd || monthToInt(monthS) > monthToInt(monthEnd) || dayS > dayEnd || hourS > hourEnd || minuteS > minuteEnd){
|
||||||
|
everythingCorrect = false;
|
||||||
|
JOptionPane.showMessageDialog(null, "End time is earlier then start time!");
|
||||||
|
}
|
||||||
|
else if (dayS != dayEnd || monthS.equals(monthEnd) == false || yearS != yearEnd){
|
||||||
|
everythingCorrect = false;
|
||||||
|
JOptionPane.showMessageDialog(null, "Event is too long! It can't be longer than a single day.");
|
||||||
|
} else if (name.isEmpty()){
|
||||||
|
everythingCorrect = false;
|
||||||
|
JOptionPane.showMessageDialog(null, "Fill in a correct name!");
|
||||||
|
} else if (stage == null){
|
||||||
|
everythingCorrect = false;
|
||||||
|
JOptionPane.showMessageDialog(null, "Missing a stage!");
|
||||||
|
} else if (artist == null){
|
||||||
|
JOptionPane.showMessageDialog(null, "Missing a artist!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (everythingCorrect == true)
|
||||||
|
{
|
||||||
|
e.setEventName(name);
|
||||||
|
e.setDescription(description);
|
||||||
|
e.setExpectedPopularity(popularity);
|
||||||
|
e.setArtist(artist);
|
||||||
|
e.setStage(stage);
|
||||||
|
e.setStartDate(yearS, monthToInt(monthS), dayS, hourS, minuteS);
|
||||||
|
e.setEndDate(yearEnd, monthToInt(monthEnd), dayEnd, hourEnd, minuteEnd);
|
||||||
|
|
||||||
|
everythingCorrect = false;
|
||||||
|
JOptionPane.showMessageDialog(null, "Event edited!");
|
||||||
|
setVisible(false);
|
||||||
|
dispose();
|
||||||
|
Window.updatePanel();
|
||||||
|
if(tab != null)
|
||||||
|
{
|
||||||
|
tab.setVisible(false);
|
||||||
|
tab.dispose();
|
||||||
|
Event eventartist = null;
|
||||||
|
for(Event event: agenda.getEvents())
|
||||||
|
{
|
||||||
|
if (event.getEventName().equals(name))
|
||||||
|
{
|
||||||
|
eventartist = event;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TabbedPane panel = new TabbedPane(agenda, eventartist, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JButton remove = new JButton("Remove event!");
|
||||||
|
south.add(remove);
|
||||||
|
|
||||||
|
remove.addActionListener(new ActionListener()
|
||||||
|
{
|
||||||
|
public void actionPerformed(ActionEvent f) {
|
||||||
|
|
||||||
|
if(JOptionPane.showConfirmDialog(null, "Are you sure you want to remove this event?", "Remove Event", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION)
|
||||||
|
{
|
||||||
|
Iterator<Event> it = agenda.getEvents().iterator();
|
||||||
|
while(it.hasNext())
|
||||||
|
{
|
||||||
|
Event ev = it.next();
|
||||||
|
if(ev.equals(e))
|
||||||
|
{
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JOptionPane.showMessageDialog(null, "Event removed!");
|
||||||
|
setVisible(false);
|
||||||
|
dispose();
|
||||||
|
Window.updatePanel();
|
||||||
|
if(tab != null)
|
||||||
|
{
|
||||||
|
tab.setVisible(false);
|
||||||
|
tab.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
setContentPane(content);
|
||||||
|
setVisible(true);
|
||||||
|
setSize(700,320);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int monthToInt(String month)
|
||||||
|
{
|
||||||
|
int number = 0;
|
||||||
|
switch (month)
|
||||||
|
{
|
||||||
|
case "January": number = 1; break;
|
||||||
|
case "February": number = 2; break;
|
||||||
|
case "March": number = 3; break;
|
||||||
|
case "April": number = 4; break;
|
||||||
|
case "May": number = 5; break;
|
||||||
|
case "June":number = 6; break;
|
||||||
|
case "July": number = 7; break;
|
||||||
|
case "August": number = 8; break;
|
||||||
|
case "September":number = 9; break;
|
||||||
|
case "October": number = 10; break;
|
||||||
|
case "November": number = 11; break;
|
||||||
|
case "December": number = 12; break;
|
||||||
|
}
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int monthDays(String month)
|
||||||
|
{
|
||||||
|
int number = 0;
|
||||||
|
switch (month)
|
||||||
|
{
|
||||||
|
case "January": number = 31; break;
|
||||||
|
case "February": number = 28; break;
|
||||||
|
case "March": number = 31; break;
|
||||||
|
case "April": number = 30; break;
|
||||||
|
case "May": number = 31; break;
|
||||||
|
case "June":number = 30; break;
|
||||||
|
case "July": number = 31; break;
|
||||||
|
case "August": number = 31; break;
|
||||||
|
case "September":number = 30; break;
|
||||||
|
case "October": number = 31; break;
|
||||||
|
case "November": number = 30; break;
|
||||||
|
case "December": number = 31; break;
|
||||||
|
}
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
package Agenda;
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.FlowLayout;
|
||||||
|
import java.awt.GridLayout;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
|
|
||||||
|
public class EditStagePanel extends JFrame{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1;
|
||||||
|
|
||||||
|
public EditStagePanel(Agenda agenda, AgendaStage sta)
|
||||||
|
{
|
||||||
|
super("Stage editscreen!");
|
||||||
|
setDefaultCloseOperation(HIDE_ON_CLOSE);
|
||||||
|
JPanel content = new JPanel(new BorderLayout());
|
||||||
|
JPanel south = new JPanel(new FlowLayout());
|
||||||
|
JPanel center = new JPanel(new GridLayout(2,2));
|
||||||
|
content.add(south, BorderLayout.SOUTH);
|
||||||
|
content.add(center, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
JPanel panel1 = new JPanel();
|
||||||
|
JLabel name = new JLabel("Stage name: ");
|
||||||
|
panel1.add(name);
|
||||||
|
center.add(panel1);
|
||||||
|
|
||||||
|
JPanel panel2 = new JPanel();
|
||||||
|
JTextField nameTF = new JTextField(sta.getName(),15);
|
||||||
|
panel2.add(nameTF);
|
||||||
|
center.add(panel2);
|
||||||
|
|
||||||
|
JLabel description = new JLabel("Stage Description: ");
|
||||||
|
JPanel panel3 = new JPanel();
|
||||||
|
panel3.add(description);
|
||||||
|
center.add(panel3);
|
||||||
|
|
||||||
|
JTextField descriptionTF = new JTextField(sta.getDescription(),15);
|
||||||
|
JPanel panel4 = new JPanel();
|
||||||
|
panel4.add(descriptionTF);
|
||||||
|
center.add(panel4);
|
||||||
|
|
||||||
|
|
||||||
|
JButton add = new JButton("Edit stage!");
|
||||||
|
south.add(add);
|
||||||
|
|
||||||
|
add.addActionListener(new ActionListener()
|
||||||
|
{
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
String name = nameTF.getText();
|
||||||
|
String description = descriptionTF.getText();
|
||||||
|
|
||||||
|
boolean alreadyExists = false;
|
||||||
|
for (AgendaStage stage : agenda.getStages())
|
||||||
|
{
|
||||||
|
if (stage.getName().equals(name) && !stage.equals(sta))
|
||||||
|
{
|
||||||
|
alreadyExists = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (name.isEmpty()){
|
||||||
|
JOptionPane.showMessageDialog(null, "Fill in a correct name!");
|
||||||
|
}
|
||||||
|
else if ( alreadyExists == false )
|
||||||
|
{
|
||||||
|
sta.setName(name);
|
||||||
|
sta.setDescription(description);
|
||||||
|
JOptionPane.showMessageDialog(null, "Stage edited!");
|
||||||
|
setVisible(false);
|
||||||
|
dispose();
|
||||||
|
Window.updatePanel();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
JOptionPane.showMessageDialog(null, "Choose a different stage name!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JButton remove = new JButton("Remove stage!");
|
||||||
|
for(Event e : agenda.getEvents())
|
||||||
|
{
|
||||||
|
if(e.getStage().equals(sta))
|
||||||
|
{
|
||||||
|
remove.setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
south.add(remove);
|
||||||
|
|
||||||
|
remove.addActionListener(new ActionListener()
|
||||||
|
{
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
||||||
|
if(JOptionPane.showConfirmDialog(null, "Are you sure you want to remove this stage?", "Remove Stage", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION)
|
||||||
|
{
|
||||||
|
Iterator<AgendaStage> it = agenda.getStages().iterator();
|
||||||
|
while(it.hasNext())
|
||||||
|
{
|
||||||
|
AgendaStage s = it.next();
|
||||||
|
if(s.equals(sta))
|
||||||
|
{
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JOptionPane.showMessageDialog(null, "Stage removed!");
|
||||||
|
setVisible(false);
|
||||||
|
dispose();
|
||||||
|
Window.updatePanel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
setContentPane(content);
|
||||||
|
setVisible(true);
|
||||||
|
setSize(400,180);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,211 @@
|
|||||||
|
package Agenda;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
|
||||||
|
public class Event implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1;
|
||||||
|
|
||||||
|
private String eventName;
|
||||||
|
private GregorianCalendar startDate;
|
||||||
|
private GregorianCalendar endDate;
|
||||||
|
private int startHour;
|
||||||
|
private int startMinute;
|
||||||
|
private int stopHour;
|
||||||
|
private int stopMinute;
|
||||||
|
private Artist artist;
|
||||||
|
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, AgendaStage stage,
|
||||||
|
String description, int expectedPopularity) {
|
||||||
|
this.eventName = eventName;
|
||||||
|
this.startDate = new GregorianCalendar(startYear, startMonth - 1,
|
||||||
|
startDay, startHour, startMinute);
|
||||||
|
this.endDate = new GregorianCalendar(endYear, endMonth - 1, endDay,
|
||||||
|
endHour, endMinute);
|
||||||
|
this.startHour = startHour;
|
||||||
|
this.startMinute = startMinute;
|
||||||
|
this.stopHour = endHour;
|
||||||
|
this.stopMinute = endMinute;
|
||||||
|
this.stage = stage;
|
||||||
|
this.artist = artist;
|
||||||
|
this.description = description;
|
||||||
|
this.expectedPopularity = expectedPopularity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Event(String eventName, GregorianCalendar startDate,
|
||||||
|
GregorianCalendar endDate, Artist artist, AgendaStage stage,
|
||||||
|
String description, int expectedPopularity) {
|
||||||
|
this.eventName = eventName;
|
||||||
|
this.startDate = startDate;
|
||||||
|
this.endDate = endDate;
|
||||||
|
this.artist = artist;
|
||||||
|
this.stage = stage;
|
||||||
|
this.description = description;
|
||||||
|
this.expectedPopularity = expectedPopularity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStart(){
|
||||||
|
return (startHour * 100) + startMinute;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStop(){
|
||||||
|
return (stopHour * 100) + stopMinute;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStopHour(){
|
||||||
|
return this.stopHour;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEventName() {
|
||||||
|
return this.eventName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GregorianCalendar getStartDate() {
|
||||||
|
return this.startDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GregorianCalendar getEndDate() {
|
||||||
|
return this.endDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Artist getArtist() {
|
||||||
|
return this.artist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return this.description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AgendaStage getStage() {
|
||||||
|
return this.stage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getExpectedPopularity() {
|
||||||
|
return this.expectedPopularity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEventName(String name) {
|
||||||
|
this.eventName = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartDate(int startYear, int startMonth, int startDay,
|
||||||
|
int startHour, int startMinute) {
|
||||||
|
startDate.set(startYear, startMonth - 1, startDay, startHour,
|
||||||
|
startMinute);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartDate(GregorianCalendar startDate) {
|
||||||
|
this.startDate = startDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndDate(int endYear, int endMonth, int endDay, int endHour,
|
||||||
|
int endMinute) {
|
||||||
|
endDate.set(endYear, endMonth - 1, endDay, endHour, endMinute);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndDate(GregorianCalendar endDate) {
|
||||||
|
this.endDate = endDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setArtist(Artist artist) {
|
||||||
|
this.artist.setName(artist.getName());
|
||||||
|
this.artist.setGenre(artist.getGenre());
|
||||||
|
this.artist.setImageIcon(artist.getImage());
|
||||||
|
this.artist.setDescription(artist.getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExpectedPopularity(int popularity) {
|
||||||
|
this.expectedPopularity = popularity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStage(AgendaStage stage) {
|
||||||
|
this.stage = stage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLength()
|
||||||
|
{
|
||||||
|
return getEndTime() - getStartTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStartTime()
|
||||||
|
{
|
||||||
|
DateFormat format = new SimpleDateFormat("kkmm");
|
||||||
|
format.setLenient(false);
|
||||||
|
// System.out.println(format.format(startDate.getTime()));
|
||||||
|
|
||||||
|
// System.out.println(date.get(Calendar.HOUR_OF_DAY));
|
||||||
|
int time = Integer.valueOf(format.format(startDate.getTime()));
|
||||||
|
int hours = time/100;
|
||||||
|
int minutes = time%100;
|
||||||
|
int finaltime;
|
||||||
|
if(minutes != 0)
|
||||||
|
{
|
||||||
|
finaltime = hours*60 + minutes;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
finaltime = hours*60;
|
||||||
|
}
|
||||||
|
return finaltime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEndTime()
|
||||||
|
{
|
||||||
|
DateFormat format = new SimpleDateFormat("kkmm");
|
||||||
|
format.setLenient(false);
|
||||||
|
// System.out.println(format.format(endDate.getTime()));
|
||||||
|
int time = Integer.valueOf(format.format(endDate.getTime()));
|
||||||
|
int hours = time/100;
|
||||||
|
int minutes = time%100;
|
||||||
|
int finaltime;
|
||||||
|
if(minutes != 0)
|
||||||
|
{
|
||||||
|
finaltime = hours*60 + minutes;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
finaltime = hours*60;
|
||||||
|
}
|
||||||
|
|
||||||
|
return finaltime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartTime(int hours, int minutes)
|
||||||
|
{
|
||||||
|
// System.out.println("Start:" + hours + ":" + minutes);
|
||||||
|
startDate.set(Calendar.HOUR_OF_DAY, hours);
|
||||||
|
startDate.set(Calendar.MINUTE, minutes);
|
||||||
|
// System.out.println(startDate.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndTime(int hours, int minutes)
|
||||||
|
{
|
||||||
|
// System.out.println("End:" + hours + ":" + minutes);
|
||||||
|
endDate.set(Calendar.HOUR_OF_DAY, hours);
|
||||||
|
endDate.set(Calendar.MINUTE, minutes);
|
||||||
|
// System.out.println(endDate.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
DateFormat format = new SimpleDateFormat("dd-MM-yyyy");
|
||||||
|
format.setLenient(false);
|
||||||
|
|
||||||
|
return artist.getName() + " plays from "
|
||||||
|
+ format.format(startDate.getTime()) + " to "
|
||||||
|
+ format.format(endDate.getTime()) + ".";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package Agenda;
|
||||||
|
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
|
import javax.swing.Box;
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JSeparator;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
|
public class EventPanel extends JPanel{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 504733981352439417L;
|
||||||
|
|
||||||
|
public EventPanel(Event event, Agenda a, TabbedPane tab)
|
||||||
|
{
|
||||||
|
super(new BorderLayout());
|
||||||
|
SimpleDateFormat dateformatter = new SimpleDateFormat("dd-MM-yyyy");
|
||||||
|
SimpleDateFormat timeformatter = new SimpleDateFormat("HH:mm");
|
||||||
|
JPanel box1 = new JPanel();
|
||||||
|
box1.setLayout(new BoxLayout(box1, BoxLayout.PAGE_AXIS));
|
||||||
|
JPanel box2 = new JPanel();
|
||||||
|
box2.setLayout(new BoxLayout(box2, BoxLayout.LINE_AXIS));
|
||||||
|
JPanel box3 = new JPanel();
|
||||||
|
box3.setLayout(new BoxLayout(box3, BoxLayout.PAGE_AXIS));
|
||||||
|
JPanel row = new JPanel();
|
||||||
|
row.setLayout(new BoxLayout(row, BoxLayout.LINE_AXIS));
|
||||||
|
JPanel panel = new JPanel();
|
||||||
|
JButton edit = new JButton("Edit Info");
|
||||||
|
edit.addActionListener(new ActionListener(){
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e)
|
||||||
|
{
|
||||||
|
EditEventPanel edit = new EditEventPanel(a, event, tab);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
|
||||||
|
JLabel title = new JLabel(event.getEventName());
|
||||||
|
JLabel date = new JLabel("<html>" + dateformatter.format(event.getEndDate().getTime()) + "</html>");
|
||||||
|
JLabel data = new JLabel("<html> " + event.getStage().getName() + "<br> <br>" + event.getArtist().getName() + "<br> <br>" + event.getExpectedPopularity() + "<br> <br>" + timeformatter.format(event.getStartDate().getTime()) + " - " + timeformatter.format(event.getEndDate().getTime()) + "<br> <br> </html>");
|
||||||
|
JLabel text = new JLabel("<html> Podium: <br> <br> Artiest: <br> <br> Populariteit: <br> <br> Tijd: <br> <br> </html>");
|
||||||
|
box2.setAlignmentX(LEFT_ALIGNMENT);
|
||||||
|
date.setFont(new Font("Dialog", Font.BOLD, 15));
|
||||||
|
row.setAlignmentX(LEFT_ALIGNMENT);
|
||||||
|
date.setAlignmentX(RIGHT_ALIGNMENT);
|
||||||
|
title.setFont(new Font("Dialog", Font.BOLD, 20));
|
||||||
|
text.setFont(new Font("Dialog", Font.BOLD, 15));
|
||||||
|
data.setFont(new Font("Dialog", Font.PLAIN, 15));
|
||||||
|
JLabel description = new JLabel("<html> <b> Beschrijving </b> <br> <br>" + event.getDescription() + "</html>");
|
||||||
|
description.setFont(new Font("Dialog", Font.PLAIN, 12));
|
||||||
|
row.add(title);
|
||||||
|
row.add(Box.createRigidArea(new Dimension(10,0)));
|
||||||
|
row.add(edit);
|
||||||
|
row.add(Box.createRigidArea(new Dimension(30,0)));
|
||||||
|
row.add(date);
|
||||||
|
box1.add(row);
|
||||||
|
box1.add(new JSeparator(SwingConstants.HORIZONTAL));
|
||||||
|
box2.add(text);
|
||||||
|
box2.add(data);
|
||||||
|
box3.add(new JSeparator(SwingConstants.HORIZONTAL));
|
||||||
|
box3.add(description);
|
||||||
|
panel.add(box1);
|
||||||
|
panel.add(box2);
|
||||||
|
panel.add(box3);
|
||||||
|
add(panel, BorderLayout.CENTER);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
package Agenda;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
|
||||||
|
import javax.swing.JMenu;
|
||||||
|
import javax.swing.JMenuBar;
|
||||||
|
import javax.swing.JMenuItem;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.KeyStroke;
|
||||||
|
|
||||||
|
|
||||||
|
public class MenuBar extends JMenuBar {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -2095136277753179215L;
|
||||||
|
|
||||||
|
|
||||||
|
public MenuBar(Window w)
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* FILE
|
||||||
|
*/
|
||||||
|
JMenu file = new JMenu("File");
|
||||||
|
|
||||||
|
JMenuItem newEvent = new JMenuItem("New Event");
|
||||||
|
newEvent.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
|
||||||
|
newEvent.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
new AddEventPanel(w.getAgenda());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JMenuItem newArtist = new JMenuItem("New Artist");
|
||||||
|
newArtist.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
new AddArtistPanel(w.getAgenda());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JMenuItem newStage = new JMenuItem("New Stage");
|
||||||
|
newStage.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
new AddStagePanel(w.getAgenda());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JMenuItem newAgenda = new JMenuItem("New Agenda");
|
||||||
|
newAgenda.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
||||||
|
if(JOptionPane.showConfirmDialog(null, "Are you sure you want to create a new agenda?", "New Agenda", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION)
|
||||||
|
{
|
||||||
|
Agenda ag = w.getAgenda();
|
||||||
|
ag.clearAgenda();
|
||||||
|
Window.updatePanel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JMenuItem open = new JMenuItem("Open");
|
||||||
|
open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
|
||||||
|
open.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
w.getAgenda().loadAgenda();
|
||||||
|
Window.updatePanel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JMenuItem save = new JMenuItem("Save");
|
||||||
|
save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
|
||||||
|
save.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
w.getAgenda().saveAgenda();
|
||||||
|
Window.updatePanel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JMenuItem exit = new JMenuItem("Exit");
|
||||||
|
exit.addActionListener(new ActionListener() {
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
w.setVisible(false);
|
||||||
|
w.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
file.add(newEvent);
|
||||||
|
file.add(newArtist);
|
||||||
|
file.add(newStage);
|
||||||
|
file.addSeparator();
|
||||||
|
file.add(newAgenda);
|
||||||
|
file.addSeparator();
|
||||||
|
file.add(open);
|
||||||
|
file.add(save);
|
||||||
|
file.addSeparator();
|
||||||
|
file.add(exit);
|
||||||
|
add(file);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* VIEW
|
||||||
|
*/
|
||||||
|
|
||||||
|
JMenu view = new JMenu("View");
|
||||||
|
|
||||||
|
JMenuItem timeline = new JMenuItem("Timeline");
|
||||||
|
timeline.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
Window.changePanel("timeline");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JMenuItem table = new JMenuItem("Table");
|
||||||
|
table.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
Window.changePanel("table");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JMenuItem art_sta = new JMenuItem("Artists and Stages");
|
||||||
|
art_sta.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
Window.changePanel("art_sta");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
view.add(timeline);
|
||||||
|
view.add(table);
|
||||||
|
view.add(art_sta);
|
||||||
|
add(view);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package Agenda;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public interface Panel{
|
||||||
|
public void update(ArrayList<Event> event);
|
||||||
|
}
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
package Agenda;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import javax.swing.AbstractListModel;
|
||||||
|
import javax.swing.JList;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.ListSelectionModel;
|
||||||
|
import javax.swing.event.ListSelectionEvent;
|
||||||
|
import javax.swing.event.ListSelectionListener;
|
||||||
|
|
||||||
|
public class PanelArtSta extends JPanel implements Panel{
|
||||||
|
|
||||||
|
private Agenda a;
|
||||||
|
JList artists;
|
||||||
|
JList stages;
|
||||||
|
Object[] dataArtist;
|
||||||
|
Object[] dataStage;
|
||||||
|
Window w;
|
||||||
|
|
||||||
|
public PanelArtSta(Window w)
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
a = w.getAgenda();
|
||||||
|
this.w = w;
|
||||||
|
|
||||||
|
artists = new JList();
|
||||||
|
artists.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
|
||||||
|
artists.setLayoutOrientation(JList.VERTICAL_WRAP);
|
||||||
|
artists.setVisibleRowCount(-1);
|
||||||
|
artists.addListSelectionListener(new ListSelectionListener() {
|
||||||
|
@Override
|
||||||
|
public void valueChanged(ListSelectionEvent e) {
|
||||||
|
if (e.getValueIsAdjusting() == false) {
|
||||||
|
|
||||||
|
if (artists.getSelectedIndex() == -1) {
|
||||||
|
} else {
|
||||||
|
new EditArtistPanel(w.getAgenda(), a.getArtists().get(artists.getSelectedIndex()), null);
|
||||||
|
artists.clearSelection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
JScrollPane artistScroller = new JScrollPane(artists);
|
||||||
|
artistScroller.setPreferredSize(new Dimension(250, 80));
|
||||||
|
|
||||||
|
stages = new JList();
|
||||||
|
stages.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
|
||||||
|
stages.setLayoutOrientation(JList.VERTICAL_WRAP);
|
||||||
|
stages.setVisibleRowCount(-1);
|
||||||
|
stages.addListSelectionListener(new ListSelectionListener() {
|
||||||
|
@Override
|
||||||
|
public void valueChanged(ListSelectionEvent e) {
|
||||||
|
if (e.getValueIsAdjusting() == false) {
|
||||||
|
|
||||||
|
if (stages.getSelectedIndex() == -1) {
|
||||||
|
} else {
|
||||||
|
new EditStagePanel(w.getAgenda(), a.getStages().get(stages.getSelectedIndex()));
|
||||||
|
stages.clearSelection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
JScrollPane stageScroller = new JScrollPane(stages);
|
||||||
|
stageScroller.setPreferredSize(new Dimension(250, 80));
|
||||||
|
|
||||||
|
add(artistScroller);
|
||||||
|
add(stageScroller);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void compileData()
|
||||||
|
{
|
||||||
|
int artistsList = a.getArtists().size();
|
||||||
|
int stagesList = a.getStages().size();
|
||||||
|
|
||||||
|
if(artistsList > 0)
|
||||||
|
{
|
||||||
|
dataArtist = new Object[artistsList];
|
||||||
|
for(int i = 0; i < artistsList; i++)
|
||||||
|
{
|
||||||
|
dataArtist[i] = a.getArtists().get(i);
|
||||||
|
}
|
||||||
|
artists.setEnabled(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dataArtist = new Object[1];
|
||||||
|
dataArtist[0] = new Artist("Geen Artists", "Geen Artists", "null", "Geen Artists", "Geen Artists");
|
||||||
|
artists.setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(stagesList > 0)
|
||||||
|
{
|
||||||
|
dataStage = new Object[stagesList];
|
||||||
|
|
||||||
|
for(int i = 0; i < stagesList; i++)
|
||||||
|
{
|
||||||
|
dataStage[i] = a.getStages().get(i);
|
||||||
|
}
|
||||||
|
stages.setEnabled(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dataStage = new Object[1];
|
||||||
|
dataStage[0] = new AgendaStage("Geen Stages", "Geen Stages");
|
||||||
|
stages.setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
|
public void update(ArrayList<Event> event) {
|
||||||
|
a = w.getAgenda();
|
||||||
|
compileData();
|
||||||
|
AbstractListModel artistsList = new ContentList(dataArtist);
|
||||||
|
AbstractListModel stagesList = new ContentList(dataStage);
|
||||||
|
artists.setModel(artistsList);
|
||||||
|
stages.setModel(stagesList);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,225 @@
|
|||||||
|
package Agenda;
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.FlowLayout;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Image;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.JTable;
|
||||||
|
import javax.swing.table.AbstractTableModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a JTable in a ScrolPane.
|
||||||
|
* @author Wesley
|
||||||
|
* @version 1.3
|
||||||
|
*/
|
||||||
|
public class PanelTable extends JPanel implements Panel{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private JScrollPane scrollPane;
|
||||||
|
private Object[][] data;
|
||||||
|
private String[] columnNames = {"Stage",
|
||||||
|
"Event",
|
||||||
|
"Artist",
|
||||||
|
"Begin Time",
|
||||||
|
"End Time"};
|
||||||
|
private ArrayList<Event> events;
|
||||||
|
private ArrayList<Event> fullEvents;
|
||||||
|
private JTable table;
|
||||||
|
private JTable selectedCell;
|
||||||
|
private Agenda a;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor makes the table and adds it to a scrollPane.
|
||||||
|
* @param events
|
||||||
|
*/
|
||||||
|
public PanelTable(Agenda a) {
|
||||||
|
super.setLayout(new BorderLayout());
|
||||||
|
this.a = a;
|
||||||
|
table= new JTable();
|
||||||
|
table.setAutoCreateRowSorter(true);
|
||||||
|
table.setAutoResizeMode(table.AUTO_RESIZE_ALL_COLUMNS);
|
||||||
|
table.getTableHeader().setReorderingAllowed(false);
|
||||||
|
table.addMouseListener(new MouseAdapter() {
|
||||||
|
public void mouseClicked(MouseEvent e) { if(e.getClickCount() > 1 ) cellClicked(e); else selectedCell = (JTable) e.getSource(); }
|
||||||
|
});
|
||||||
|
scrollPane = new JScrollPane(table,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||||
|
add(scrollPane,BorderLayout.SOUTH);
|
||||||
|
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
|
JButton button;
|
||||||
|
button = new JButton("Filter");
|
||||||
|
button.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) { filter(); }
|
||||||
|
});
|
||||||
|
buttonPanel.add(button);
|
||||||
|
button = new JButton(new ImageIcon("sprites/sprite0.png"));
|
||||||
|
button.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) { update(fullEvents, true); }
|
||||||
|
});
|
||||||
|
buttonPanel.add(button);
|
||||||
|
add(buttonPanel,BorderLayout.NORTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the size of the scrollPane, in which the table is placed to fill out its container panel (not sure if this is needed?)
|
||||||
|
*/
|
||||||
|
public void paintComponent(Graphics g) {
|
||||||
|
scrollPane.setPreferredSize(new Dimension(getWidth(),getHeight()-35));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the data from the events arrayList and makes a 2D-array of it.
|
||||||
|
* @param columnes
|
||||||
|
* @param rows
|
||||||
|
*/
|
||||||
|
public void compileData(int columnes, int rows) {
|
||||||
|
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm");
|
||||||
|
data = new Object[rows][columnes];
|
||||||
|
for(int x = 0; x < rows; x++) {
|
||||||
|
Object[] tempData = new Object[columnes];
|
||||||
|
tempData[0] = events.get(x).getStage().getName();
|
||||||
|
tempData[1] = events.get(x).getEventName();
|
||||||
|
tempData[2] = events.get(x).getArtist().getName();
|
||||||
|
tempData[3] = formatter.format(events.get(x).getStartDate().getTime());
|
||||||
|
tempData[4] = formatter.format(events.get(x).getEndDate().getTime());
|
||||||
|
data[x] = tempData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refreshes the content on the table with a fresh ArrayList of events, useful when things are removed and added and should be called every time you update the list.
|
||||||
|
* @param events
|
||||||
|
*/
|
||||||
|
public void update(ArrayList<Event> events)
|
||||||
|
{
|
||||||
|
update(events, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(ArrayList<Event> events, boolean newList) {
|
||||||
|
this.events = events;
|
||||||
|
if(newList)
|
||||||
|
this.fullEvents = events;
|
||||||
|
compileData(columnNames.length,events.size());
|
||||||
|
AbstractTableModel tableModel = new ContentTable(data,columnNames);
|
||||||
|
table.setModel(tableModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method for the action listener when a cell is clicked, opens dialog of the clicked cell.
|
||||||
|
* @param e
|
||||||
|
*/
|
||||||
|
private void cellClicked(MouseEvent e) {
|
||||||
|
JTable target = (JTable) e.getSource();
|
||||||
|
switch(target.getSelectedColumn()) {
|
||||||
|
case 0:
|
||||||
|
//A dialog for podia?
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
openEventDialog(target.getSelectedRow());
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
openArtistDialog(target.getSelectedRow());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens a dialog with information of the selected event.
|
||||||
|
* @param row
|
||||||
|
*/
|
||||||
|
private void openEventDialog(int row) {
|
||||||
|
Event event = events.get(row);
|
||||||
|
new TabbedPane(a, event, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens a dialog with information of the selected artist
|
||||||
|
* @param row
|
||||||
|
*/
|
||||||
|
private void openArtistDialog(int row) {
|
||||||
|
Event event = events.get(row);
|
||||||
|
new TabbedPane(a, event, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter method which filters on the currently selected cell.
|
||||||
|
* Needs to be under a button action, also a reset button is needed so list can be restored.
|
||||||
|
*/
|
||||||
|
public void filter() {
|
||||||
|
if(selectedCell != null) {
|
||||||
|
if(fullEvents.isEmpty()) {
|
||||||
|
fullEvents = events;
|
||||||
|
}
|
||||||
|
ArrayList<Event> filteredList = new ArrayList<>();
|
||||||
|
switch(selectedCell.getSelectedColumn()) {
|
||||||
|
case 0:
|
||||||
|
for(Event event : fullEvents) {
|
||||||
|
if(event.getStage().equals(events.get(selectedCell.getSelectedRow()).getStage())) {
|
||||||
|
filteredList.add(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
for(Event event : fullEvents) {
|
||||||
|
if(event.getEventName().equals(events.get(selectedCell.getSelectedRow()).getEventName())) {
|
||||||
|
filteredList.add(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
for(Event event : fullEvents) {
|
||||||
|
if(event.getArtist().equals(events.get(selectedCell.getSelectedRow()).getArtist())) {
|
||||||
|
filteredList.add(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
int selectedCellStartTime = events.get(selectedCell.getSelectedRow()).getStartDate().getTime().getHours()*100;
|
||||||
|
selectedCellStartTime += events.get(selectedCell.getSelectedRow()).getStartDate().getTime().getMinutes();
|
||||||
|
int selectedCellEndTime = events.get(selectedCell.getSelectedRow()).getEndDate().getTime().getHours()*100;
|
||||||
|
selectedCellEndTime += events.get(selectedCell.getSelectedRow()).getEndDate().getTime().getMinutes();
|
||||||
|
for(Event event : fullEvents) {
|
||||||
|
int time = event.getStartDate().getTime().getHours()*100;
|
||||||
|
time += event.getStartDate().getTime().getMinutes();
|
||||||
|
if(time >= selectedCellStartTime && time <= selectedCellEndTime) {
|
||||||
|
filteredList.add(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
selectedCellStartTime = events.get(selectedCell.getSelectedRow()).getStartDate().getTime().getHours()*100;
|
||||||
|
selectedCellStartTime += events.get(selectedCell.getSelectedRow()).getStartDate().getTime().getMinutes();
|
||||||
|
selectedCellEndTime = events.get(selectedCell.getSelectedRow()).getEndDate().getTime().getHours()*100;
|
||||||
|
selectedCellEndTime += events.get(selectedCell.getSelectedRow()).getEndDate().getTime().getMinutes();
|
||||||
|
for(Event event : fullEvents) {
|
||||||
|
int time = event.getEndDate().getTime().getHours()*100;
|
||||||
|
time += event.getEndDate().getTime().getMinutes();
|
||||||
|
if(time >= selectedCellStartTime && time <= selectedCellEndTime) {
|
||||||
|
filteredList.add(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
update(filteredList,false);
|
||||||
|
selectedCell = null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
JOptionPane.showMessageDialog(this, "Select a cell with the value u want to filter on","No cell selected",JOptionPane.WARNING_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
package Agenda;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.filechooser.FileFilter;
|
||||||
|
|
||||||
|
public class SaveLoad {
|
||||||
|
|
||||||
|
public static void saveFile(Object obj)
|
||||||
|
{
|
||||||
|
JFileChooser fileChooser = new JFileChooser();
|
||||||
|
|
||||||
|
fileChooser.setFileFilter(new FileFilter() {
|
||||||
|
@Override
|
||||||
|
public boolean accept(File pathname) {
|
||||||
|
if(pathname.isFile() && pathname.getName().endsWith(".agn"))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}else if(pathname.isDirectory()){return true;}else{return false;}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return "Agenda (.agn)";
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
fileChooser.setDialogTitle("Choose save location");
|
||||||
|
int userSelection = fileChooser.showSaveDialog(null);
|
||||||
|
|
||||||
|
if(userSelection == JFileChooser.APPROVE_OPTION)
|
||||||
|
{
|
||||||
|
File file = fileChooser.getSelectedFile();
|
||||||
|
if(!file.getName().endsWith(".agn"))
|
||||||
|
{
|
||||||
|
file = new File(file.getAbsolutePath() + ".agn");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
if(JOptionPane.showConfirmDialog(null, "Are you sure you want to overwrite: " + file.getName(), "Overwrite", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION)
|
||||||
|
{
|
||||||
|
save(obj, file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
save(obj, file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object loadFile()
|
||||||
|
{
|
||||||
|
JFileChooser fileChooser = new JFileChooser();
|
||||||
|
fileChooser.setFileFilter(new FileFilter() {
|
||||||
|
@Override
|
||||||
|
public boolean accept(File pathname) {
|
||||||
|
if(pathname.isFile() && pathname.getName().endsWith(".agn"))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}else if(pathname.isDirectory()){return true;}else{return false;}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return "Agenda (.agn)";
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
fileChooser.setDialogTitle("Choose file");
|
||||||
|
int userSelection = fileChooser.showOpenDialog(null);
|
||||||
|
|
||||||
|
if(userSelection == JFileChooser.APPROVE_OPTION)
|
||||||
|
{
|
||||||
|
File file = fileChooser.getSelectedFile();
|
||||||
|
if(!file.exists())
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(null, "This file does not exist: " + file.getName());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return load(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void save(Object obj, File file)
|
||||||
|
{
|
||||||
|
ObjectOutputStream oostr = null;
|
||||||
|
try {
|
||||||
|
oostr = new ObjectOutputStream(new FileOutputStream(file));
|
||||||
|
oostr.writeObject(obj);
|
||||||
|
oostr.flush();
|
||||||
|
oostr.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object load(File file)
|
||||||
|
{
|
||||||
|
ObjectInputStream oistr = null;
|
||||||
|
try {
|
||||||
|
oistr = new ObjectInputStream(new FileInputStream(file));
|
||||||
|
Object obj = oistr.readObject();
|
||||||
|
oistr.close();
|
||||||
|
return obj;
|
||||||
|
} catch (IOException | ClassNotFoundException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
package Agenda;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.LayoutManager;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
|
||||||
|
public class StagePanel extends JPanel
|
||||||
|
{
|
||||||
|
private BufferedImage image;
|
||||||
|
private int width, height, posX;
|
||||||
|
private double widthD, posXD;
|
||||||
|
private Event event;
|
||||||
|
public StagePanel(int width, int height, int posX, Event event, double widthD, double posXD)
|
||||||
|
{
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
this.posX = posX;
|
||||||
|
this.event = event;
|
||||||
|
this.widthD = widthD;
|
||||||
|
this.posXD = posXD;
|
||||||
|
image = new BufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB);
|
||||||
|
Graphics2D g2 = image.createGraphics();
|
||||||
|
g2.setColor(Color.blue);
|
||||||
|
g2.fillRect(0, 0, image.getWidth(), image.getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void paint(Graphics g)
|
||||||
|
{
|
||||||
|
super.paint(g);
|
||||||
|
((Graphics2D)g).drawImage(image, this.posX, 0, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StagePanel(LayoutManager arg0)
|
||||||
|
{
|
||||||
|
super(arg0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public StagePanel(boolean arg0)
|
||||||
|
{
|
||||||
|
super(arg0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(int posx, double posXD)
|
||||||
|
{
|
||||||
|
this.posX = posx;
|
||||||
|
this.posXD = posXD;
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public StagePanel(LayoutManager arg0, boolean arg1)
|
||||||
|
{
|
||||||
|
super(arg0, arg1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getPosX()
|
||||||
|
{
|
||||||
|
return this.posXD;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLength(int length, double widthD)
|
||||||
|
{
|
||||||
|
this.width = length;
|
||||||
|
this.widthD = widthD;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStageStartTime(int hours, int minutes)
|
||||||
|
{
|
||||||
|
event.setStartTime(hours, minutes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStageEndTime(int hours, int minutes)
|
||||||
|
{
|
||||||
|
event.setEndTime(hours, minutes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStageStartTime()
|
||||||
|
{
|
||||||
|
return event.getStartTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getImageWidth()
|
||||||
|
{
|
||||||
|
return this.widthD;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package Agenda;
|
||||||
|
|
||||||
|
//een jframe met info, heeft alleen een agenda object, event object (het desbetreffende event) en een boolean met daarin true of false (slaande op je wel of niet met het event wilt starten) nodig.
|
||||||
|
//Voorderest heeft dit niks nodig en is het een apart openend JFrame wat gewoon weer afgesloten kan worden.
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JTabbedPane;
|
||||||
|
|
||||||
|
public class TabbedPane extends JFrame{
|
||||||
|
|
||||||
|
public TabbedPane(Agenda a, Event event, boolean eventSelected)
|
||||||
|
{
|
||||||
|
super("info GUI");
|
||||||
|
JTabbedPane tab = new JTabbedPane();
|
||||||
|
tab.add("Event", new EventPanel(event, a, this));
|
||||||
|
tab.add("Artist", new ArtistPanel(event, a, this));
|
||||||
|
if(eventSelected)
|
||||||
|
{
|
||||||
|
tab.setSelectedIndex(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tab.setSelectedIndex(1);
|
||||||
|
}
|
||||||
|
setContentPane(tab);
|
||||||
|
setSize(480, 410);
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,456 @@
|
|||||||
|
package Agenda;
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Container;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.FlowLayout;
|
||||||
|
import java.awt.event.ComponentAdapter;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
|
import java.awt.event.ComponentListener;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseListener;
|
||||||
|
import java.awt.event.MouseMotionAdapter;
|
||||||
|
import java.awt.event.MouseMotionListener;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
|
||||||
|
import javax.swing.Box;
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings({ "serial" })
|
||||||
|
public class Timeline extends JPanel
|
||||||
|
{
|
||||||
|
private ArrayList<Event> events = new ArrayList<Event>();
|
||||||
|
private JPanel frame;
|
||||||
|
|
||||||
|
// Geef dit object je JFrame mee, en zet in je JFrame de volgende code:
|
||||||
|
// this.setContentPane(timeline.getTimeline());
|
||||||
|
// this.getRootPane().addComponentListener(new ComponentAdapter()
|
||||||
|
// {
|
||||||
|
// public void componentResized(ComponentEvent e) {
|
||||||
|
// timeline.refresh();
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
|
||||||
|
public Timeline(JPanel frame)
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
this.frame = frame;
|
||||||
|
|
||||||
|
genStages();
|
||||||
|
this.setSize(frame.getWidth(), frame.getHeight());
|
||||||
|
// refresh();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEvents(ArrayList<Event> events)
|
||||||
|
{
|
||||||
|
this.events = events;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refresh()
|
||||||
|
{
|
||||||
|
this.removeAll();
|
||||||
|
createMainPanel();
|
||||||
|
this.revalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public JPanel createMainPanel()
|
||||||
|
{
|
||||||
|
// this.setSize(frame.getWidth(), frame.getHeight());
|
||||||
|
JPanel mainPanel = new JPanel();
|
||||||
|
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
|
||||||
|
Container topContainer = createTopPanel();
|
||||||
|
Dimension dim = new Dimension(this.getWidth(), 60);
|
||||||
|
topContainer.setMaximumSize(dim);
|
||||||
|
mainPanel.add(topContainer);
|
||||||
|
|
||||||
|
Dimension centerDim = new Dimension(this.getWidth(), this.getHeight());
|
||||||
|
|
||||||
|
// Container centerContainer = createCenterPanel();
|
||||||
|
JPanel centerContainer = createCenterPanel();
|
||||||
|
centerContainer.setPreferredSize(centerDim);
|
||||||
|
|
||||||
|
centerContainer.setMaximumSize(centerDim);
|
||||||
|
// System.out.println(centerDim);
|
||||||
|
mainPanel.add(centerContainer);
|
||||||
|
this.add(mainPanel, BorderLayout.CENTER);
|
||||||
|
return mainPanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JPanel createCenterPanel()
|
||||||
|
{
|
||||||
|
|
||||||
|
JPanel centerPanel = new JPanel();
|
||||||
|
centerPanel.setBackground(Color.lightGray);
|
||||||
|
centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS));
|
||||||
|
centerPanel.add(Box.createRigidArea(new Dimension(0, 30)));
|
||||||
|
|
||||||
|
for(Event event : events)
|
||||||
|
{
|
||||||
|
StagePanel stagepanel = new StagePanel((int)calcLengthOfStage(event.getLength()), 30, (int)calcPositionOfStage(event.getStartTime()), event,calcLengthOfStage(event.getLength()),calcPositionOfStage(event.getStartTime()));
|
||||||
|
Container content = stagepanel;
|
||||||
|
content.setMaximumSize(new Dimension(this.getWidth(),30));
|
||||||
|
content.addMouseListener(new MouseListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent e) {
|
||||||
|
resizeTimeline(stagepanel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
content.addMouseMotionListener(new MouseMotionListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseMoved(MouseEvent e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseDragged(MouseEvent e) {
|
||||||
|
int value = (int)(e.getX() - stagepanel.getImageWidth() / 2);
|
||||||
|
double value2 = (e.getX() - stagepanel.getImageWidth() / 2);
|
||||||
|
// System.out.println("Value1: " + value);
|
||||||
|
// System.out.println("Value2: " + value2);
|
||||||
|
stagepanel.update(value, value2);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
centerPanel.add(content);
|
||||||
|
centerPanel.add(Box.createRigidArea(new Dimension(0,15)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// this.add(centerPanel, BorderLayout.CENTER);
|
||||||
|
return centerPanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resizeTimeline(StagePanel stagepanel)
|
||||||
|
{
|
||||||
|
// System.out.println(stagepanel.getStageStartTime());
|
||||||
|
// System.out.println(calcStartTimeOfStagePanel(stagepanel.getPosX()));
|
||||||
|
stagepanel.setStageStartTime(calcStartTimeOfStagePanelHours(stagepanel.getPosX()),calcStartTimeOfStagePanelMinutes(stagepanel.getPosX()));
|
||||||
|
stagepanel.setStageEndTime(calcEndTimeOfStagePanelHours(stagepanel.getPosX(), stagepanel.getImageWidth()),calcEndTimeOfStagePanelMinutes(stagepanel.getPosX(), stagepanel.getImageWidth()));
|
||||||
|
// stagepanel.setLength(calcLengthOfStagePanel(stagepanel.getImageWidth()));
|
||||||
|
// System.out.println("HOURS: " + calcEndTimeOfStagePanelHours(stagepanel.getPosX(), stagepanel.getImageWidth()));
|
||||||
|
// System.out.println("MINUTES: " + calcEndTimeOfStagePanelMinutes(stagepanel.getPosX(), stagepanel.getImageWidth()) );
|
||||||
|
// TimelinePanel tempPanel = (TimelinePanel) frame;
|
||||||
|
// tempPanel.refresh();
|
||||||
|
refresh();
|
||||||
|
// System.out.println(stagepanel.getPosX());
|
||||||
|
}
|
||||||
|
|
||||||
|
public double calcLengthOfStage(double length)
|
||||||
|
{
|
||||||
|
double lengthOfStage = 0;
|
||||||
|
int min = findMinMax(1);
|
||||||
|
int max = findMinMax(2);
|
||||||
|
|
||||||
|
double frameWidth = this.getWidth();
|
||||||
|
double minmax = max-min;
|
||||||
|
double pixelsPerLength = frameWidth / minmax;
|
||||||
|
lengthOfStage = pixelsPerLength * (double)length;
|
||||||
|
// System.out.println("LengthOfStage: " + lengthOfStage);
|
||||||
|
//
|
||||||
|
// System.out.println("MAX: " + max);
|
||||||
|
// System.out.println("MIN: " + min);
|
||||||
|
// System.out.println("LENGTH: " + length);
|
||||||
|
// System.out.println("FRAME: " + frameWidth);
|
||||||
|
// System.out.println("PixelsPerLEngth: " + pixelsPerLength);
|
||||||
|
|
||||||
|
return lengthOfStage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double calcLengthOfStagePanel(double length)
|
||||||
|
{
|
||||||
|
double lengthOfStagePanel = 0;
|
||||||
|
int min = findMinMax(1);
|
||||||
|
int max = findMinMax(2);
|
||||||
|
// System.out.println(length);
|
||||||
|
double frameWidth = this.getWidth();
|
||||||
|
double minmax = max-min;
|
||||||
|
double pixelsPerLength = frameWidth / minmax;
|
||||||
|
// System.out.println(pixelsPerLength);
|
||||||
|
lengthOfStagePanel = (double)length / pixelsPerLength;
|
||||||
|
// System.out.println(lengthOfStagePanel);
|
||||||
|
|
||||||
|
|
||||||
|
// System.out.println("LengthOfStagePane: " + (int)lengthOfStagePanel);
|
||||||
|
|
||||||
|
return lengthOfStagePanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double calcPositionOfStage(int startTime)
|
||||||
|
{
|
||||||
|
double posx;
|
||||||
|
int min = findMinMax(1);
|
||||||
|
int max = findMinMax(2);
|
||||||
|
double minmax = max-min;
|
||||||
|
posx = startTime - min;
|
||||||
|
posx = posx * this.getWidth() / minmax;
|
||||||
|
// System.out.println("Frame: " + this.getWidth());
|
||||||
|
// System.out.println("startTime: " + startTime);
|
||||||
|
// System.out.println("Max: " + max + " min: " + min);
|
||||||
|
// System.out.println("Posx: " + posx);
|
||||||
|
return posx;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int calcStartTimeOfStagePanelHours(double posx)
|
||||||
|
{
|
||||||
|
int min = findMinMax(1);
|
||||||
|
int max = findMinMax(2);
|
||||||
|
// System.out.println("MIN: " + min);
|
||||||
|
// System.out.println("max: " + max);
|
||||||
|
// double startTime = (posx / (this.getWidth() / (max - min )) ) + min;
|
||||||
|
//Omdat het anders onnodig afgerond wordt, alles apart in doubles.
|
||||||
|
double minmax = max-min;
|
||||||
|
double bottom = this.getWidth() / minmax;
|
||||||
|
double all = posx / bottom;
|
||||||
|
double startTime = all + min;
|
||||||
|
// System.out.println("STPH: " + this.getWidth());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return ((int)startTime / 60);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int calcStartTimeOfStagePanelMinutes(double posx)
|
||||||
|
{
|
||||||
|
int min = findMinMax(1);
|
||||||
|
int max = findMinMax(2);
|
||||||
|
// double startTime = (posx / (this.getWidth() / (max - min )) ) + min;
|
||||||
|
//Omdat het anders onnodig afgerond wordt, alles apart in doubles.
|
||||||
|
double minmax = max-min;
|
||||||
|
double bottom = this.getWidth() / minmax;
|
||||||
|
double all = posx / bottom;
|
||||||
|
double startTime = all + min;
|
||||||
|
// System.out.println("STPM: " + this.getWidth());
|
||||||
|
|
||||||
|
return ((int)startTime % 60);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int calcEndTimeOfStagePanelHours(double posx, double imageWidth)
|
||||||
|
{
|
||||||
|
int min = findMinMax(1);
|
||||||
|
int max = findMinMax(2);
|
||||||
|
//Omdat het anders onnodig afgerond wordt, alles apart in doubles.
|
||||||
|
double minmax = max-min;
|
||||||
|
double bottom = this.getWidth() / minmax;
|
||||||
|
double all = posx / bottom;
|
||||||
|
double endTime = all + min + calcLengthOfStagePanel(imageWidth);
|
||||||
|
// System.out.println("ETPH: " + this.getWidth());
|
||||||
|
return (int)endTime / 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int calcEndTimeOfStagePanelMinutes(double posx, double imageWidth)
|
||||||
|
{
|
||||||
|
int min = findMinMax(1);
|
||||||
|
int max = findMinMax(2);
|
||||||
|
//Omdat het anders onnodig afgerond wordt, alles apart in doubles.
|
||||||
|
double minmax = max-min;
|
||||||
|
double bottom = this.getWidth() / minmax;
|
||||||
|
double all = posx / bottom;
|
||||||
|
double endTime = all + min + calcLengthOfStagePanel(imageWidth);
|
||||||
|
// System.out.println("ETPM: " + this.getWidth());
|
||||||
|
return (int)endTime % 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int minutesToHours(int minutes)
|
||||||
|
{
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int intToTime(int time, String option)
|
||||||
|
{
|
||||||
|
if(option == "hours")
|
||||||
|
{
|
||||||
|
time = time % 24;
|
||||||
|
}
|
||||||
|
else if(option == "minutes")
|
||||||
|
{
|
||||||
|
time = time % 60;
|
||||||
|
}
|
||||||
|
// System.out.println(time);
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int toHours(int minutesTot)
|
||||||
|
{
|
||||||
|
int hours = minutesTot / 60;
|
||||||
|
int minutes = minutesTot % 60;
|
||||||
|
int finaltime;
|
||||||
|
|
||||||
|
finaltime = hours * 100 + minutes;
|
||||||
|
|
||||||
|
return finaltime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int findMinMax(int i)
|
||||||
|
{
|
||||||
|
// Event oldevent = new Event(0, 0, null, "Base", 0);
|
||||||
|
// ArrayList<Event> oldevents = new ArrayList<Event>();
|
||||||
|
// oldevents.add(oldevent);
|
||||||
|
// Steage oldstage = new Stage(oldevents,0,null, 0, 0);
|
||||||
|
ArrayList<Event> eventscopy = (ArrayList<Event>) events.clone();
|
||||||
|
|
||||||
|
Integer earliestStartTime = null;
|
||||||
|
Integer lastEndTime = null;
|
||||||
|
|
||||||
|
for(Event event : eventscopy)
|
||||||
|
{
|
||||||
|
if(i == 1)
|
||||||
|
{
|
||||||
|
if(earliestStartTime == null)
|
||||||
|
{
|
||||||
|
|
||||||
|
earliestStartTime = event.getStartTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(event.getStartTime() < earliestStartTime)
|
||||||
|
{
|
||||||
|
earliestStartTime = event.getStartTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if( i == 2)
|
||||||
|
{
|
||||||
|
if(lastEndTime == null)
|
||||||
|
{
|
||||||
|
lastEndTime = event.getEndTime();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(event.getEndTime() > lastEndTime)
|
||||||
|
{
|
||||||
|
lastEndTime = event.getEndTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(i == 1)
|
||||||
|
{
|
||||||
|
return earliestStartTime;
|
||||||
|
}
|
||||||
|
else if(i == 2)
|
||||||
|
{
|
||||||
|
return lastEndTime;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.out.println("Return -1");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private JPanel createTopPanel()
|
||||||
|
{
|
||||||
|
JPanel topPane = new JPanel();
|
||||||
|
topPane.setLayout(new BoxLayout(topPane, BoxLayout.Y_AXIS));
|
||||||
|
JPanel topPanel = new JPanel(new FlowLayout());
|
||||||
|
for(int i = 0; i <= this.getWidth() / 10; i++)
|
||||||
|
{
|
||||||
|
ImageIcon topImageIcon = new ImageIcon("src/sprites/block.png");
|
||||||
|
JLabel topImage = new JLabel(topImageIcon);
|
||||||
|
topPanel.add(topImage);
|
||||||
|
}
|
||||||
|
topPane.add(Box.createRigidArea(new Dimension(0,20)));
|
||||||
|
JPanel panel = new JPanel();
|
||||||
|
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
|
||||||
|
panel.add(Box.createRigidArea(new Dimension(50, 10)));
|
||||||
|
panel.add(new JLabel(Integer.toString(toHours(findMinMax(1)))));
|
||||||
|
panel.add(Box.createHorizontalGlue());
|
||||||
|
panel.add(new JLabel(Integer.toString(toHours(findMinMax(2)))));
|
||||||
|
panel.add(Box.createRigidArea(new Dimension(50, 10)));
|
||||||
|
topPane.add(panel);
|
||||||
|
topPane.add(topPanel);
|
||||||
|
// this.add(topPane, BorderLayout.NORTH);
|
||||||
|
return topPane;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JPanel createWestPanel()
|
||||||
|
{
|
||||||
|
this.setSize(frame.getWidth(), frame.getHeight());
|
||||||
|
JPanel westPanel = new JPanel();
|
||||||
|
westPanel.setLayout(new BoxLayout(westPanel, BoxLayout.Y_AXIS));
|
||||||
|
westPanel.add(Box.createRigidArea(new Dimension(0, 100)));
|
||||||
|
// for(int i = 0; i < events.size(); i++)
|
||||||
|
// {
|
||||||
|
// JLabel stageText = new JLabel("Stage: " + (i+1) + " ");
|
||||||
|
// westPanel.add(stageText);
|
||||||
|
// westPanel.add(Box.createRigidArea(new Dimension(0, 30 )));
|
||||||
|
// }
|
||||||
|
for(Event event : events)
|
||||||
|
{
|
||||||
|
JLabel stageText = new JLabel(event.getStage().getName() + ": " + " ");
|
||||||
|
|
||||||
|
westPanel.add(stageText);
|
||||||
|
westPanel.add(Box.createRigidArea(new Dimension(0, 30 )));
|
||||||
|
}
|
||||||
|
// this.add(westPanel, BorderLayout.WEST);
|
||||||
|
return westPanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void genStages()
|
||||||
|
{
|
||||||
|
// ImageIcon image = new ImageIcon();
|
||||||
|
// Artist artist2 = new Artist("Henk", "paul2", "kaas", image, 2);
|
||||||
|
// Artist artist1 = new Artist("Kaas", "Paul", "Lala", image, 1);
|
||||||
|
// Event event2 = new Event(1900, 2000, artist2, "hi2", 2);
|
||||||
|
// Event event1 = new Event(600, 1800, artist1, "hi", 1);
|
||||||
|
// ArrayList<Event> performances = new ArrayList<Event>();
|
||||||
|
// performances.add(event1);
|
||||||
|
// performances.add(event2);
|
||||||
|
// Stage stage1 = new Stage(performances, 100, null, 1800, 2100);
|
||||||
|
// events.add(stage1);
|
||||||
|
// Stage stage2 = new Stage(performances, 100, null, 1700, 1900);
|
||||||
|
// Stage stage3 = new Stage(performances, 100, null, 1600, 1800);
|
||||||
|
// Stage stage4 = new Stage(performances, 100, null, 1600, 2100);
|
||||||
|
// events.add(stage3);
|
||||||
|
// events.add(stage2);
|
||||||
|
//// stages.add(stage4);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createNull()
|
||||||
|
{
|
||||||
|
this.removeAll();
|
||||||
|
this.add(new JLabel("No events for this day"));
|
||||||
|
this.revalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public JPanel getTimeline()
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package Agenda;
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
|
||||||
|
public class TimelinePanel extends JPanel implements Panel {
|
||||||
|
|
||||||
|
private Timeline timeline;
|
||||||
|
// private WestPanel westPanel;
|
||||||
|
|
||||||
|
public TimelinePanel()
|
||||||
|
{
|
||||||
|
super(new BorderLayout());
|
||||||
|
|
||||||
|
this.setSize(600, 600);
|
||||||
|
this.setVisible(true);
|
||||||
|
timeline = new Timeline(this);
|
||||||
|
// westPanel = new WestPanel();
|
||||||
|
// this.add(timeline.createMainPanel(),BorderLayout.CENTER);
|
||||||
|
// this.add(new JButton());
|
||||||
|
// this.add(timeline.createWestPanel(), BorderLayout.WEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refresh()
|
||||||
|
{
|
||||||
|
this.removeAll();
|
||||||
|
timeline.refresh();
|
||||||
|
// westPanel.refresh();
|
||||||
|
this.add(timeline,BorderLayout.CENTER);
|
||||||
|
this.add(timeline.createWestPanel(), BorderLayout.WEST);
|
||||||
|
this.revalidate();
|
||||||
|
// timeline.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(ArrayList<Event> events)
|
||||||
|
{
|
||||||
|
timeline.setEvents(events);
|
||||||
|
// System.out.println(events.size());
|
||||||
|
// westPanel.setEvents(events);
|
||||||
|
// refresh();
|
||||||
|
// this.add(timeline.createMainPanel(),BorderLayout.CENTER);
|
||||||
|
// this.add(new JButton());
|
||||||
|
// this.add(timeline.createWestPanel(), BorderLayout.WEST);
|
||||||
|
|
||||||
|
//dit fixt het half
|
||||||
|
if(events.size() != 0)
|
||||||
|
{
|
||||||
|
this.removeAll();
|
||||||
|
timeline.refresh();
|
||||||
|
this.add(timeline.createWestPanel(),BorderLayout.WEST);
|
||||||
|
this.add(timeline, BorderLayout.CENTER);
|
||||||
|
this.revalidate();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.removeAll();
|
||||||
|
timeline.createNull();
|
||||||
|
this.add(timeline);
|
||||||
|
this.revalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public TimelinePanel getTimelinePanel()
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,237 @@
|
|||||||
|
package Agenda;
|
||||||
|
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Toolkit;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.ComponentAdapter;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
|
import java.awt.event.WindowAdapter;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JSeparator;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
|
import javax.swing.UIManager;
|
||||||
|
import javax.swing.UnsupportedLookAndFeelException;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.time.DateUtils;
|
||||||
|
|
||||||
|
public class Window extends JFrame {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 9023061329829975662L;
|
||||||
|
private static HashMap<String, Panel> panels = new HashMap<String, Panel>();
|
||||||
|
private static JPanel centerPanel;
|
||||||
|
private static GregorianCalendar date;
|
||||||
|
private static Agenda agenda;
|
||||||
|
private static String currentPanel = "table";
|
||||||
|
|
||||||
|
public Window()
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Initialize window
|
||||||
|
*/
|
||||||
|
super("Agenda");
|
||||||
|
agenda = new Agenda();
|
||||||
|
|
||||||
|
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||||
|
addWindowListener(new WindowAdapter() {
|
||||||
|
public void windowClosing(WindowEvent evt) {
|
||||||
|
onExit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
setSize(1200, 800);
|
||||||
|
|
||||||
|
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
|
||||||
|
setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2);
|
||||||
|
|
||||||
|
try {
|
||||||
|
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
|
||||||
|
} catch (ClassNotFoundException | InstantiationException
|
||||||
|
| IllegalAccessException | UnsupportedLookAndFeelException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
setJMenuBar(new MenuBar(this));
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create Panels
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Agenda Panels
|
||||||
|
Panel tablePanel = new PanelTable(agenda);
|
||||||
|
panels.put("table", tablePanel);
|
||||||
|
|
||||||
|
Panel art_staPanel = new PanelArtSta(this);
|
||||||
|
panels.put("art_sta", art_staPanel);
|
||||||
|
|
||||||
|
Panel timeline = new TimelinePanel();
|
||||||
|
panels.put("timeline", timeline);
|
||||||
|
|
||||||
|
//Main Panels
|
||||||
|
JPanel mainPanel = new JPanel(new BorderLayout());
|
||||||
|
centerPanel = new JPanel(new BorderLayout());
|
||||||
|
centerPanel.setBackground(Color.WHITE);
|
||||||
|
JPanel bottomPanel = new JPanel();
|
||||||
|
bottomPanel.setBackground(Color.DARK_GRAY);
|
||||||
|
|
||||||
|
date = new GregorianCalendar();
|
||||||
|
SimpleDateFormat formatter=new SimpleDateFormat("dd-MM-yyyy");
|
||||||
|
JLabel dateLabel = new JLabel(formatter.format(date.getTime()));
|
||||||
|
dateLabel.setForeground(Color.WHITE);
|
||||||
|
bottomPanel.add(dateLabel);
|
||||||
|
|
||||||
|
JButton backWeekButton = new JButton("<<");
|
||||||
|
backWeekButton.setToolTipText("Go one week back");
|
||||||
|
backWeekButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
date.set(GregorianCalendar.DAY_OF_MONTH, date.get(GregorianCalendar.DAY_OF_MONTH) - 7);
|
||||||
|
dateLabel.setText(formatter.format(date.getTime()));
|
||||||
|
updatePanel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
bottomPanel.add(new JSeparator(SwingConstants.VERTICAL));
|
||||||
|
bottomPanel.add(backWeekButton);
|
||||||
|
|
||||||
|
JButton backDayButton = new JButton("<");
|
||||||
|
backDayButton.setToolTipText("Go one day back");
|
||||||
|
backDayButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
date.set(GregorianCalendar.DAY_OF_MONTH, date.get(GregorianCalendar.DAY_OF_MONTH) - 1);
|
||||||
|
dateLabel.setText(formatter.format(date.getTime()));
|
||||||
|
updatePanel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
bottomPanel.add(new JSeparator(SwingConstants.VERTICAL));
|
||||||
|
bottomPanel.add(backDayButton);
|
||||||
|
|
||||||
|
JButton todayButton = new JButton("||");
|
||||||
|
todayButton.setToolTipText("Go to today");
|
||||||
|
todayButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
date = new GregorianCalendar();
|
||||||
|
dateLabel.setText(formatter.format(date.getTime()));
|
||||||
|
updatePanel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
bottomPanel.add(new JSeparator(SwingConstants.VERTICAL));
|
||||||
|
bottomPanel.add(todayButton);
|
||||||
|
|
||||||
|
JButton forwardDayButton = new JButton(">");
|
||||||
|
forwardDayButton.setToolTipText("Go one day forward");
|
||||||
|
forwardDayButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
date.set(GregorianCalendar.DAY_OF_MONTH, date.get(GregorianCalendar.DAY_OF_MONTH) + 1);
|
||||||
|
dateLabel.setText(formatter.format(date.getTime()));
|
||||||
|
updatePanel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
bottomPanel.add(new JSeparator(SwingConstants.VERTICAL));
|
||||||
|
bottomPanel.add(forwardDayButton);
|
||||||
|
|
||||||
|
JButton forwardWeekButton = new JButton(">>");
|
||||||
|
forwardWeekButton.setToolTipText("Go one week forward");
|
||||||
|
forwardWeekButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
date.set(GregorianCalendar.DAY_OF_MONTH, date.get(GregorianCalendar.DAY_OF_MONTH) + 7);
|
||||||
|
dateLabel.setText(formatter.format(date.getTime()));
|
||||||
|
updatePanel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
bottomPanel.add(new JSeparator(SwingConstants.VERTICAL));
|
||||||
|
bottomPanel.add(forwardWeekButton);
|
||||||
|
|
||||||
|
//Add panels
|
||||||
|
mainPanel.add(centerPanel, BorderLayout.CENTER);
|
||||||
|
mainPanel.add(bottomPanel, BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
setContentPane(mainPanel);
|
||||||
|
|
||||||
|
updatePanel();
|
||||||
|
|
||||||
|
//Show window
|
||||||
|
setVisible(true);
|
||||||
|
this.getRootPane().addComponentListener(new ComponentAdapter()
|
||||||
|
{
|
||||||
|
public void componentResized(ComponentEvent e) {
|
||||||
|
if(currentPanel == "timeline")
|
||||||
|
{
|
||||||
|
TimelinePanel tempTimeLine = (TimelinePanel) timeline;
|
||||||
|
tempTimeLine.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void changePanel(String panel)
|
||||||
|
{
|
||||||
|
currentPanel = panel;
|
||||||
|
updatePanel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updatePanel()
|
||||||
|
{
|
||||||
|
centerPanel.removeAll();
|
||||||
|
Panel p = panels.get(currentPanel);
|
||||||
|
p.update(getEvents());
|
||||||
|
JPanel p1 = (JPanel) p;
|
||||||
|
p1.setPreferredSize(centerPanel.getSize());
|
||||||
|
centerPanel.add(p1, BorderLayout.CENTER);
|
||||||
|
centerPanel.revalidate();
|
||||||
|
centerPanel.repaint();
|
||||||
|
p1.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onExit() {
|
||||||
|
if(JOptionPane.showConfirmDialog(null, "Are you sure you want to close this program?", "Close Agenda", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION)
|
||||||
|
{
|
||||||
|
setVisible(false);
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArrayList<Event> getEvents()
|
||||||
|
{
|
||||||
|
ArrayList<Event> events = new ArrayList<Event>();
|
||||||
|
for(Event e : agenda.getEvents())
|
||||||
|
{
|
||||||
|
if(DateUtils.isSameDay(e.getStartDate(), date) || DateUtils.isSameDay(e.getEndDate(), date))
|
||||||
|
{
|
||||||
|
events.add(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return events;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Agenda getAgenda()
|
||||||
|
{
|
||||||
|
return agenda;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAgenda(Agenda a)
|
||||||
|
{
|
||||||
|
agenda = a;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package Applicatie;
|
||||||
|
|
||||||
|
import java.awt.geom.Point2D;
|
||||||
|
|
||||||
|
import Objects.DrawObject;
|
||||||
|
|
||||||
|
public class Action
|
||||||
|
{
|
||||||
|
|
||||||
|
private Point2D position;
|
||||||
|
private int starttime;
|
||||||
|
private int duration;
|
||||||
|
private DrawObject target;
|
||||||
|
private Waypoint waypoint;
|
||||||
|
|
||||||
|
public Action(Point2D position, int starttime, int duration, DrawObject tar, Waypoint waypoint)
|
||||||
|
{
|
||||||
|
this.position = position;
|
||||||
|
this.starttime = starttime;
|
||||||
|
this.duration = duration;
|
||||||
|
this.target = tar;
|
||||||
|
this.waypoint = waypoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point2D getPosition()
|
||||||
|
{
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawObject getTargetObject()
|
||||||
|
{
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStartTime()
|
||||||
|
{
|
||||||
|
return starttime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStoptime()
|
||||||
|
{
|
||||||
|
return (starttime + duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDuration()
|
||||||
|
{
|
||||||
|
return duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Waypoint getWaypoint(){
|
||||||
|
return waypoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,152 @@
|
|||||||
|
package Applicatie;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.FlowLayout;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
|
import javax.swing.Box;
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
public class ControlPanel extends JPanel
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 6805244250902524351L;
|
||||||
|
|
||||||
|
private Panel p;
|
||||||
|
JLabel timeLabel;
|
||||||
|
|
||||||
|
public ControlPanel()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
BoxLayout box = new BoxLayout(this, BoxLayout.X_AXIS);
|
||||||
|
setLayout(box);
|
||||||
|
|
||||||
|
setPreferredSize(new Dimension(0,50));
|
||||||
|
setBorder(BorderFactory.createLineBorder(new Color(180, 180, 180)));
|
||||||
|
setBackground(new Color(220, 220, 220));
|
||||||
|
setFocusable(false);
|
||||||
|
|
||||||
|
JPanel simulatorPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
|
simulatorPanel.setPreferredSize(new Dimension(350,50));
|
||||||
|
simulatorPanel.setMaximumSize(new Dimension(350,50));
|
||||||
|
add(simulatorPanel);
|
||||||
|
{
|
||||||
|
JLabel simulatorLabel = new JLabel("Simulator: ");
|
||||||
|
simulatorLabel.setFont(new Font("Segoe UI", Font.ITALIC, 20));
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
p.getT().start();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
p.getT().stop();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
p.getT().stop();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
simulatorPanel.add(stopButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
add(Box.createRigidArea(new Dimension(10,50)));
|
||||||
|
|
||||||
|
JPanel timePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
|
timePanel.setPreferredSize(new Dimension(300,50));
|
||||||
|
timePanel.setMaximumSize(new Dimension(300,50));
|
||||||
|
add(timePanel);
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
///TODO implement
|
||||||
|
}
|
||||||
|
});
|
||||||
|
timePanel.add(dateButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
add(Box.createRigidArea(new Dimension(10,50)));
|
||||||
|
|
||||||
|
JPanel peoplePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
|
peoplePanel.setPreferredSize(new Dimension(285,50));
|
||||||
|
peoplePanel.setMaximumSize(new Dimension(285,50));
|
||||||
|
add(peoplePanel);
|
||||||
|
{
|
||||||
|
JLabel peopleLabel = new JLabel("0/0 People");
|
||||||
|
peopleLabel.setFont(new Font("Segoe UI", Font.PLAIN, 20));
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
peoplePanel.add(peopleButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
add(Box.createHorizontalGlue());
|
||||||
|
|
||||||
|
JPanel runningPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
|
runningPanel.setPreferredSize(new Dimension(195,50));
|
||||||
|
runningPanel.setMaximumSize(new Dimension(195,50));
|
||||||
|
add(runningPanel);
|
||||||
|
{
|
||||||
|
JLabel runningLabel = new JLabel("Simulation stopped");
|
||||||
|
runningLabel.setFont(new Font("Segoe UI", Font.PLAIN, 20));
|
||||||
|
runningPanel.add(runningLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPanel(Panel p)
|
||||||
|
{
|
||||||
|
this.p = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTime(String time)
|
||||||
|
{
|
||||||
|
timeLabel.setText(time);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPeople(int people)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
package Applicatie;
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import java.awt.Image;
|
|
||||||
import java.awt.Point;
|
|
||||||
import java.awt.Shape;
|
|
||||||
import java.awt.geom.AffineTransform;
|
|
||||||
import java.awt.geom.Point2D;
|
|
||||||
import java.awt.geom.Rectangle2D;
|
|
||||||
|
|
||||||
import javax.swing.ImageIcon;
|
|
||||||
|
|
||||||
|
|
||||||
public class DrawObject {
|
|
||||||
Point2D position;
|
|
||||||
double rotation;
|
|
||||||
double scale;
|
|
||||||
Image image;
|
|
||||||
protected boolean selected;
|
|
||||||
|
|
||||||
public DrawObject(String filename, Point2D position)
|
|
||||||
{
|
|
||||||
image = new ImageIcon(filename).getImage();
|
|
||||||
scale = 1;
|
|
||||||
rotation = 0;
|
|
||||||
this.position = position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void draw(Graphics2D g)
|
|
||||||
{
|
|
||||||
AffineTransform tx = getTransform();
|
|
||||||
g.drawImage(image, tx, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected AffineTransform getTransform() {
|
|
||||||
AffineTransform tx = new AffineTransform();
|
|
||||||
tx.scale(scale, scale);
|
|
||||||
tx.translate(position.getX(), position.getY());
|
|
||||||
tx.rotate(Math.toRadians(rotation), image.getWidth(null) / 2, image.getHeight(null) / 2);
|
|
||||||
return tx;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean contains(Point2D clickPoint) {
|
|
||||||
Shape shape = new Rectangle2D.Double(0,0,image.getWidth(null), image.getHeight(null));
|
|
||||||
return getTransform().createTransformedShape(shape).contains(clickPoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSelected(boolean b)
|
|
||||||
{
|
|
||||||
selected = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Point2D getPosition() {
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPosition(Point2D position) {
|
|
||||||
this.position = position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getRotation() {
|
|
||||||
return rotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRotation(double rotation) {
|
|
||||||
this.rotation = rotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getScale() {
|
|
||||||
return scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setScale(double scale) {
|
|
||||||
this.scale = scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Image getImage() {
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setImage(Image image) {
|
|
||||||
this.image = image;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSelected() {
|
|
||||||
return selected;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package Applicatie;
|
||||||
|
|
||||||
|
import java.awt.Image;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
|
||||||
|
public class Images
|
||||||
|
{
|
||||||
|
|
||||||
|
private static Map<String, Image> images;
|
||||||
|
|
||||||
|
public Images()
|
||||||
|
{
|
||||||
|
images = new HashMap<String, Image>();
|
||||||
|
|
||||||
|
images.put("entrance", loadImage("images/entrance.png"));
|
||||||
|
images.put("wc", loadImage("images/wc.png"));
|
||||||
|
images.put("path", loadImage("images/path.jpg"));
|
||||||
|
images.put("stage", loadImage("images/stage4.png"));
|
||||||
|
images.put("wall", loadImage("images/wall.png"));
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
return new ImageIcon(path).getImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Image getImage(String getter)
|
||||||
|
{
|
||||||
|
return images.get(getter);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
package Applicatie;
|
package Applicatie;
|
||||||
|
|
||||||
public class Main {
|
public class Main
|
||||||
|
{
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
new Window();
|
new Window();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
package Applicatie;
|
package Applicatie;
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
@@ -7,24 +8,119 @@ import javax.swing.JMenuBar;
|
|||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
|
public class MenuBar extends JMenuBar
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public class MenuBar extends JMenuBar {
|
|
||||||
|
|
||||||
public MenuBar(Window w)
|
public MenuBar(Window w)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
|
||||||
JMenu file = new JMenu("File");
|
JMenu file = new JMenu("File");
|
||||||
|
|
||||||
JMenuItem exit = new JMenuItem("Exit");
|
JMenuItem item = new JMenuItem("New");
|
||||||
exit.addActionListener(new ActionListener() {
|
item.addActionListener(new ActionListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
System.exit(0);
|
NewWorldPanel world = new NewWorldPanel(w.getPanel());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
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() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
SaveLoad.load(w.getPanel());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
file.add(item);
|
||||||
|
|
||||||
|
item = new JMenuItem("Save");
|
||||||
|
item.addActionListener(new ActionListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
SaveLoad.save(w.getPanel());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
file.add(item);
|
||||||
|
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
public void actionPerformed(ActionEvent e)
|
||||||
|
{
|
||||||
|
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(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(exit);
|
file.add(item);
|
||||||
|
|
||||||
add(file);
|
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,151 @@
|
|||||||
|
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,grass2, sand2,stone, 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/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", "Grass 2","Sand", "Sand 2", "Stone"};
|
||||||
|
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 = grass2;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
selectedImage = sand;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
selectedImage = sand2;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
selectedImage = stone;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,15 @@
|
|||||||
package Applicatie;
|
package Applicatie;
|
||||||
|
|
||||||
|
import java.awt.BasicStroke;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Font;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
import java.awt.Stroke;
|
||||||
import java.awt.TexturePaint;
|
import java.awt.TexturePaint;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
import java.awt.geom.NoninvertibleTransformException;
|
import java.awt.geom.NoninvertibleTransformException;
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
@@ -10,267 +17,678 @@ import java.awt.geom.Rectangle2D;
|
|||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.Timer;
|
||||||
|
|
||||||
|
import Agenda.Agenda;
|
||||||
|
import Agenda.AgendaStage;
|
||||||
import Listeners.Mouse;
|
import Listeners.Mouse;
|
||||||
import Listeners.MouseMotion;
|
import Listeners.MouseMotion;
|
||||||
import Listeners.MouseWheel;
|
import Listeners.MouseWheel;
|
||||||
|
import Listeners.WindowFocusListener;
|
||||||
|
import Objects.DrawObject;
|
||||||
import Objects.Entrance;
|
import Objects.Entrance;
|
||||||
|
import Objects.Food;
|
||||||
import Objects.Path;
|
import Objects.Path;
|
||||||
import Objects.Podium;
|
import Objects.Stage;
|
||||||
import Objects.Toilet;
|
import Objects.Toilet;
|
||||||
import Objects.Wall;
|
import Objects.Wall;
|
||||||
|
|
||||||
public class Panel extends JPanel {
|
@SuppressWarnings("serial")
|
||||||
|
public class Panel extends JPanel implements ActionListener
|
||||||
|
{
|
||||||
|
|
||||||
|
BufferedImage grass, grass2, sand, sand2, stone;
|
||||||
BufferedImage background;
|
BufferedImage background;
|
||||||
BufferedImage podiumImage, toiletImage, entranceImage, pathImage,wallImage;
|
BufferedImage podiumImage, toiletImage, entranceImage, pathImage, wallImage, foodImage, waypointImage;
|
||||||
|
|
||||||
private int panelInfox, panelInfoy,scrollfactor;
|
private int panelInfox, panelInfoy, scrollfactor;
|
||||||
|
|
||||||
private ArrayList<BufferedImage> panelInfo = new ArrayList<BufferedImage>();
|
private ArrayList<BufferedImage> panelInfo = new ArrayList<BufferedImage>();
|
||||||
// private ArrayList<Object> panelTypes = new ArrayList<Object>();
|
// private ArrayList<Object> panelTypes = new ArrayList<Object>();
|
||||||
|
ArrayList<Visitor> visitors = new ArrayList<>();
|
||||||
|
ArrayList<Waypoint> waypoints = new ArrayList<Waypoint>();
|
||||||
ArrayList<DrawObject> objects = new ArrayList<>();
|
ArrayList<DrawObject> objects = new ArrayList<>();
|
||||||
|
ArrayList<Path> paths = new ArrayList<>();
|
||||||
DrawObject dragObject = null;
|
DrawObject dragObject = null;
|
||||||
|
private DrawObject selectedObject;
|
||||||
Point2D cameraPoint = new Point2D.Double(getWidth()/2,getHeight()/2);
|
private String clickedOption = "drag";
|
||||||
|
private Path currentPath;
|
||||||
|
private static int width = 1920;
|
||||||
|
private static int height = 1080;
|
||||||
|
|
||||||
|
Point2D cameraPoint = new Point2D.Double(getWidth() / 2, getHeight() / 2);
|
||||||
float cameraScale = 1;
|
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();
|
||||||
|
Timer t;
|
||||||
|
|
||||||
|
SimpleDateFormat formatter;
|
||||||
Point2D lastClickPosition = new Point(0,0);
|
GregorianCalendar date;
|
||||||
Point lastMousePosition = new Point(0,0);
|
|
||||||
|
int currentTime = 540;
|
||||||
//how to nieuwe dingen aan het panel toe te voegen:
|
int tick = 0;
|
||||||
//maak bufferedimage global aan, voeg er een image aan toe, en voeg de image aan panelInfo toe en het object aan panelTypes.
|
|
||||||
//en maak een case statement die een new Object returnt in createNewDrawObject.
|
// how to nieuwe dingen aan het panel toe te voegen:
|
||||||
|
// maak bufferedimage global aan, voeg er een image aan toe, en voeg de
|
||||||
Panel()
|
// image aan panelInfo toe en het object aan panelTypes.
|
||||||
|
// en maak een case statement die een new Object returnt in
|
||||||
|
// createNewDrawObject.
|
||||||
|
|
||||||
|
public Point2D getSelectionPosition()
|
||||||
{
|
{
|
||||||
try {
|
return selectionPosition;
|
||||||
background = ImageIO.read(new File("images/grass.jpg"));
|
}
|
||||||
|
|
||||||
|
public void setSelectionPosition(Point2D selectionPosition)
|
||||||
|
{
|
||||||
|
this.selectionPosition = selectionPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
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"));
|
podiumImage = ImageIO.read(new File("images/stageIcon.png"));
|
||||||
toiletImage = ImageIO.read(new File("images/wcIcon.png"));
|
toiletImage = ImageIO.read(new File("images/wcIcon.png"));
|
||||||
entranceImage = ImageIO.read(new File("images/entranceIcon.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"));
|
wallImage = ImageIO.read(new File("images/wallIcon.png"));
|
||||||
} catch (IOException e) {
|
foodImage = ImageIO.read(new File("images/foodIcon.png"));
|
||||||
|
waypointImage = ImageIO.read(new File("images/waypointIcon.png"));
|
||||||
|
background = grass;
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
panelInfo.add(podiumImage);
|
panelInfo.add(podiumImage);
|
||||||
panelInfo.add(toiletImage);
|
panelInfo.add(toiletImage);
|
||||||
panelInfo.add(entranceImage);
|
panelInfo.add(entranceImage);
|
||||||
panelInfo.add(pathImage);
|
|
||||||
panelInfo.add(wallImage);
|
panelInfo.add(wallImage);
|
||||||
|
panelInfo.add(foodImage);
|
||||||
|
panelInfo.add(waypointImage);
|
||||||
|
|
||||||
|
agenda = new Agenda();
|
||||||
|
|
||||||
panelInfox = 0;
|
panelInfox = 0;
|
||||||
panelInfoy = 0;
|
panelInfoy = 0;
|
||||||
scrollfactor = 0;
|
scrollfactor = 0;
|
||||||
|
|
||||||
// objects.add(new Podium(new Point2D.Double(100, 100)));
|
// objects.add(new Podium(new Point2D.Double(100, 100)));
|
||||||
// objects.add(new Podium(new Point2D.Double(500, 100)));
|
// objects.add(new Podium(new Point2D.Double(500, 100)));
|
||||||
// objects.add(new Podium(new Point2D.Double(300, 400)));
|
// objects.add(new Podium(new Point2D.Double(300, 400)));
|
||||||
|
|
||||||
addMouseListener(new Mouse(this));
|
addMouseListener(new Mouse(this));
|
||||||
|
|
||||||
addMouseMotionListener(new MouseMotion(this));
|
addMouseMotionListener(new MouseMotion(this));
|
||||||
|
|
||||||
addMouseWheelListener(new MouseWheel(this));
|
addMouseWheelListener(new MouseWheel(this));
|
||||||
|
|
||||||
|
addFocusListener(new WindowFocusListener(this));
|
||||||
|
t = new Timer(1000 / 10, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPanelInfoLength()
|
public int getPanelInfoLength()
|
||||||
{
|
{
|
||||||
int panelInfoLength = 0;
|
int panelInfoLength = 0;
|
||||||
for(BufferedImage image : panelInfo)
|
for (BufferedImage image : panelInfo)
|
||||||
{
|
{
|
||||||
panelInfoLength += image.getWidth();
|
panelInfoLength += image.getWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
return panelInfoLength;
|
return panelInfoLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DrawObject createNewDrawObject(int index)
|
public DrawObject createNewDrawObject(int index)
|
||||||
{
|
{
|
||||||
switch(index)
|
switch (index)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
return new Podium(null);
|
ArrayList<AgendaStage> stages = agenda.getStages();
|
||||||
case 1:
|
Object[] s = new Object[stages.size()];
|
||||||
return new Toilet(null);
|
AgendaStage stage = null;
|
||||||
case 2:
|
if (stages.size() != 0)
|
||||||
return new Entrance(null);
|
{
|
||||||
case 3:
|
for (int i = 0; i < stages.size(); i++)
|
||||||
return new Path(null);
|
{
|
||||||
case 4:
|
s[i] = stages.get(i);
|
||||||
return new Wall(null);
|
}
|
||||||
default:
|
|
||||||
return null;
|
stage = (AgendaStage) JOptionPane.showInputDialog(null, "Select the right Stage", "Select Stage", JOptionPane.PLAIN_MESSAGE, null, s, "stage");
|
||||||
|
}
|
||||||
|
if (stage != null)
|
||||||
|
{
|
||||||
|
return new Stage(null, stage);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
case 1:
|
||||||
|
return new Toilet(null);
|
||||||
|
case 2:
|
||||||
|
return new Entrance(null);
|
||||||
|
case 3:
|
||||||
|
return new Wall(null);
|
||||||
|
case 4:
|
||||||
|
return new Food(null);
|
||||||
|
case 5:
|
||||||
|
return new Waypoint(null);
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(DrawObject dragObject)
|
public void add(DrawObject dragObject)
|
||||||
{
|
{
|
||||||
objects.add(dragObject);
|
objects.add(dragObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addWaypoint(Waypoint w)
|
||||||
|
{
|
||||||
|
waypoints.add(w);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Waypoint getWaypoint(int i)
|
||||||
|
{
|
||||||
|
for(Waypoint w : waypoints)
|
||||||
|
{
|
||||||
|
if(w.getSelf() == i)
|
||||||
|
{
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Waypoint> getWaypoints()
|
||||||
|
{
|
||||||
|
return waypoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addVisitors()
|
||||||
|
{
|
||||||
|
ArrayList<DrawObject> entrances = new ArrayList<>();
|
||||||
|
for(DrawObject object : objects) {
|
||||||
|
if(object instanceof Entrance) {
|
||||||
|
entrances.add(object);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!entrances.isEmpty()) {
|
||||||
|
DrawObject entrance = entrances.get((int) Math.floor(Math.random()*entrances.size()));
|
||||||
|
Point point = new Point((int)entrance.getPosition().getX(),(int)entrance.getPosition().getY());
|
||||||
|
visitors.add(new Visitor("visitor",point, agenda, objects, waypoints, date));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
JOptionPane.showMessageDialog(this, "You don't have an entrance");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addVisitors(int count)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
addVisitors();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void paintComponent(Graphics g)
|
public void paintComponent(Graphics g)
|
||||||
{
|
{
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
Graphics2D g2 = (Graphics2D)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.fill(new Ellipse2D.Double(0,0,300,300));
|
g2.setStroke(new BasicStroke(10));
|
||||||
|
g2.drawLine(0, 150, getWidth(), 150);
|
||||||
// g2.drawImage(podiumImage, 0, 0, null);
|
g2.setStroke(old);
|
||||||
for(BufferedImage image : panelInfo)
|
for (BufferedImage image : panelInfo)
|
||||||
{
|
{
|
||||||
g2.drawImage(image, panelInfox + scrollfactor, panelInfoy, null);
|
g2.drawImage(image, panelInfox + scrollfactor, panelInfoy, null);
|
||||||
panelInfox += image.getWidth();
|
panelInfox += image.getWidth();
|
||||||
}
|
}
|
||||||
panelInfox = 0;
|
panelInfox = 0;
|
||||||
|
|
||||||
g2.setClip(new Rectangle2D.Double(0,150, getWidth(), getHeight()));
|
g2.setClip(new Rectangle2D.Double(0, 150, getWidth(), getHeight()));
|
||||||
AffineTransform oldTransform = g2.getTransform();
|
AffineTransform oldTransform = g2.getTransform();
|
||||||
g2.setTransform(getCamera());
|
g2.setTransform(getCamera());
|
||||||
|
|
||||||
TexturePaint p = new TexturePaint(background, new Rectangle2D.Double(0, 0, 100, 100));
|
TexturePaint p = new TexturePaint(background, new Rectangle2D.Double(0, 0, 100, 100));
|
||||||
g2.setPaint(p);
|
g2.setPaint(p);
|
||||||
g2.fill(new Rectangle2D.Double(-1920,-1080,3840,2160));
|
|
||||||
|
g2.fill(new Rectangle2D.Double(-width / 2, -height / 2, width, height));
|
||||||
for(DrawObject o : objects){
|
|
||||||
|
BasicStroke stroke = new BasicStroke(10);
|
||||||
|
g2.setStroke(stroke);
|
||||||
|
|
||||||
|
for (Path path : paths)
|
||||||
|
{
|
||||||
|
path.draw(g2);
|
||||||
|
}
|
||||||
|
for (DrawObject o : objects)
|
||||||
|
{
|
||||||
o.draw(g2);
|
o.draw(g2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (Visitor v : visitors)
|
||||||
|
{
|
||||||
g2.setClip(null);
|
v.draw(g2);
|
||||||
|
}
|
||||||
|
|
||||||
g2.setTransform(oldTransform);
|
g2.setTransform(oldTransform);
|
||||||
|
if (currentPath != null)
|
||||||
|
{ // Display text while in path making modes.
|
||||||
|
g2.setColor(Color.WHITE);
|
||||||
|
g2.setFont(new Font("Verdana", Font.ITALIC, 25));
|
||||||
|
g2.drawString("Press enter to finish the path.", 20, 185);
|
||||||
|
}
|
||||||
|
g2.setClip(null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public AffineTransform getCamera() {
|
public AffineTransform getCamera()
|
||||||
|
{
|
||||||
AffineTransform tx = new AffineTransform();
|
AffineTransform tx = new AffineTransform();
|
||||||
tx.translate(-cameraPoint.getX() + getWidth()/2, -cameraPoint.getY() + getHeight()/2);
|
tx.translate(-cameraPoint.getX() + getWidth() / 2, -cameraPoint.getY() + getHeight() / 2);
|
||||||
tx.scale(cameraScale, cameraScale);
|
tx.scale(cameraScale, cameraScale);
|
||||||
|
|
||||||
return tx;
|
return tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Point2D getClickPoint(Point point) {
|
public Point2D getClickPoint(Point point)
|
||||||
try {
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
return getCamera().inverseTransform(point, null);
|
return getCamera().inverseTransform(point, null);
|
||||||
} catch (NoninvertibleTransformException e1) {
|
}
|
||||||
|
catch (NoninvertibleTransformException e1)
|
||||||
|
{
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setBackground(BufferedImage background)
|
||||||
|
{
|
||||||
public void setBackground(BufferedImage background) {
|
|
||||||
this.background = background;
|
this.background = background;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<DrawObject> getObjects()
|
||||||
|
{
|
||||||
public ArrayList<DrawObject> getObjects() {
|
|
||||||
return objects;
|
return objects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setObjects(ArrayList<DrawObject> objects)
|
||||||
public void setObjects(ArrayList<DrawObject> objects) {
|
{
|
||||||
this.objects = objects;
|
this.objects = objects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DrawObject getDragObject()
|
||||||
public DrawObject getDragObject() {
|
{
|
||||||
return dragObject;
|
return dragObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDragObject(DrawObject dragObject)
|
||||||
public void setDragObject(DrawObject dragObject) {
|
{
|
||||||
this.dragObject = dragObject;
|
this.dragObject = dragObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Point2D getCameraPoint()
|
||||||
public Point2D getCameraPoint() {
|
{
|
||||||
return cameraPoint;
|
return cameraPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCameraPoint(Point2D cameraPoint)
|
||||||
public void setCameraPoint(Point2D cameraPoint) {
|
{
|
||||||
this.cameraPoint = cameraPoint;
|
this.cameraPoint = cameraPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getCameraScale()
|
||||||
public float getCameraScale() {
|
{
|
||||||
return cameraScale;
|
return cameraScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCameraScale(float cameraScale)
|
||||||
public void setCameraScale(float cameraScale) {
|
{
|
||||||
this.cameraScale = cameraScale;
|
this.cameraScale = cameraScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Point2D getLastClickPosition()
|
||||||
public Point2D getLastClickPosition() {
|
{
|
||||||
return lastClickPosition;
|
return lastClickPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLastClickPosition(Point2D lastClickPosition)
|
||||||
public void setLastClickPosition(Point2D lastClickPosition) {
|
{
|
||||||
this.lastClickPosition = lastClickPosition;
|
this.lastClickPosition = lastClickPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearObjects()
|
||||||
|
{
|
||||||
|
objects.clear();
|
||||||
|
}
|
||||||
|
|
||||||
public Point getLastMousePosition() {
|
public Point getLastMousePosition()
|
||||||
|
{
|
||||||
return lastMousePosition;
|
return lastMousePosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLastMousePosition(Point lastMousePosition)
|
||||||
public void setLastMousePosition(Point lastMousePosition) {
|
{
|
||||||
this.lastMousePosition = lastMousePosition;
|
this.lastMousePosition = lastMousePosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BufferedImage getPodiumImage()
|
||||||
public BufferedImage getPodiumImage() {
|
{
|
||||||
return podiumImage;
|
return podiumImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPodiumImage(BufferedImage podiumImage)
|
||||||
public void setPodiumImage(BufferedImage podiumImage) {
|
{
|
||||||
this.podiumImage = podiumImage;
|
this.podiumImage = podiumImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<BufferedImage> getPanelInfo()
|
||||||
public ArrayList<BufferedImage> getPanelInfo() {
|
{
|
||||||
return panelInfo;
|
return panelInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPanelInfo(ArrayList<BufferedImage> panelInfo)
|
||||||
public void setPanelInfo(ArrayList<BufferedImage> panelInfo) {
|
{
|
||||||
this.panelInfo = panelInfo;
|
this.panelInfo = panelInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getScrollfactor()
|
||||||
public int getScrollfactor() {
|
{
|
||||||
return scrollfactor;
|
return scrollfactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setScrollfactor(int scrollfactor) {
|
public void setScrollfactor(int scrollfactor)
|
||||||
|
{
|
||||||
this.scrollfactor = scrollfactor;
|
this.scrollfactor = scrollfactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPanelInfox() {
|
public int getPanelInfox()
|
||||||
|
{
|
||||||
return panelInfox;
|
return panelInfox;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPanelInfox(int panelInfox) {
|
public void setPanelInfox(int panelInfox)
|
||||||
|
{
|
||||||
this.panelInfox = panelInfox;
|
this.panelInfox = panelInfox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public PropertiesPanel getPP()
|
||||||
|
{
|
||||||
|
return pp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update()
|
||||||
|
{
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawObject getSelectedObject()
|
||||||
|
{
|
||||||
|
return selectedObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelectedObject(DrawObject selectedObject)
|
||||||
|
{
|
||||||
|
this.selectedObject = selectedObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClickedOption()
|
||||||
|
{
|
||||||
|
return clickedOption;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClickedOption(String clickedOption)
|
||||||
|
{
|
||||||
|
this.clickedOption = clickedOption;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a DrawObject from the list.
|
||||||
|
*
|
||||||
|
* @param o
|
||||||
|
* - the DrawObject you want to remove from the list.
|
||||||
|
*/
|
||||||
|
public void removeObject(DrawObject o)
|
||||||
|
{
|
||||||
|
Iterator<DrawObject> itr = objects.iterator();
|
||||||
|
while (itr.hasNext())
|
||||||
|
{
|
||||||
|
DrawObject nextObject = (DrawObject) itr.next();
|
||||||
|
if (nextObject.equals(o))
|
||||||
|
{
|
||||||
|
pp.clearSelected();
|
||||||
|
itr.remove();
|
||||||
|
}
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearObjectSelection()
|
||||||
|
{
|
||||||
|
for (DrawObject o : objects)
|
||||||
|
{
|
||||||
|
o.setSelected(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkCollision()
|
||||||
|
{
|
||||||
|
boolean collision = false;
|
||||||
|
for (DrawObject o : getObjects())
|
||||||
|
{
|
||||||
|
if (getSelectedObject().collision(o) && o != getSelectedObject())
|
||||||
|
{
|
||||||
|
collision = true;
|
||||||
|
getSelectedObject().setRectangleColor(Color.RED);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!collision)
|
||||||
|
getSelectedObject().setRectangleColor(Color.BLACK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Begin making a new path.
|
||||||
|
*/
|
||||||
|
public void startPath()
|
||||||
|
{
|
||||||
|
pp.clearSelected();
|
||||||
|
setSelectedObject(null);
|
||||||
|
clearObjectSelection();
|
||||||
|
setClickedOption("Path");
|
||||||
|
currentPath = new Path();
|
||||||
|
paths.add(currentPath);
|
||||||
|
pp.setSelectedPath(currentPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current selected Path.
|
||||||
|
*
|
||||||
|
* @return - the selected Path.
|
||||||
|
*/
|
||||||
|
public Path getCurrentPath()
|
||||||
|
{
|
||||||
|
return currentPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the selected Path object.
|
||||||
|
*
|
||||||
|
* @param path
|
||||||
|
* - the selected Path object.
|
||||||
|
*/
|
||||||
|
public void setcurrentPath(Path path)
|
||||||
|
{
|
||||||
|
currentPath = path;
|
||||||
|
pp.setSelectedPath(currentPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the point is contained in one of the path's.
|
||||||
|
*
|
||||||
|
* @param point
|
||||||
|
* - The point to check for.
|
||||||
|
* @return if the point is contained in one of the path's.
|
||||||
|
*/
|
||||||
|
public boolean checkPath(Point2D point)
|
||||||
|
{
|
||||||
|
for (Path path : paths)
|
||||||
|
{
|
||||||
|
if (path.containsPoint(point))
|
||||||
|
{
|
||||||
|
|
||||||
|
setcurrentPath(path);
|
||||||
|
setClickedOption("Path");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Path getClickedPath(Point2D point)
|
||||||
|
{
|
||||||
|
for (Path path : paths)
|
||||||
|
{
|
||||||
|
if (path.containsPoint(point))
|
||||||
|
{
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a path from the list.
|
||||||
|
*
|
||||||
|
* @param path
|
||||||
|
* - the path you want to remove from the list.
|
||||||
|
*/
|
||||||
|
public void removePath(Path path)
|
||||||
|
{
|
||||||
|
Iterator<Path> it = paths.iterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
if (it.next().equals(path))
|
||||||
|
{
|
||||||
|
pp.clearSelected();
|
||||||
|
setClickedOption("drag");
|
||||||
|
currentPath = null;
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Agenda getAgenda()
|
||||||
|
{
|
||||||
|
return agenda;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAgenda(Agenda agenda)
|
||||||
|
{
|
||||||
|
this.agenda = agenda;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getFieldWidth()
|
||||||
|
{
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getFieldHeight()
|
||||||
|
{
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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, this);
|
||||||
|
}
|
||||||
|
repaint();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Timer getT()
|
||||||
|
{
|
||||||
|
return 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 = grass2;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
background = sand;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
background = sand2;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
background = stone;
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package Applicatie;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.FlowLayout;
|
||||||
|
import java.awt.GridLayout;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
|
import Objects.Path;
|
||||||
|
|
||||||
|
public class PathPopup extends JFrame
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1;
|
||||||
|
|
||||||
|
public PathPopup(Path p, Panel panel)
|
||||||
|
{
|
||||||
|
super("Artist editscreen!");
|
||||||
|
setDefaultCloseOperation(HIDE_ON_CLOSE);
|
||||||
|
JPanel content = new JPanel(new BorderLayout());
|
||||||
|
JPanel south = new JPanel(new FlowLayout());
|
||||||
|
JPanel center = new JPanel(new GridLayout(5, 2));
|
||||||
|
content.add(south, BorderLayout.SOUTH);
|
||||||
|
content.add(center, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
JPanel panel1 = new JPanel();
|
||||||
|
JLabel name = new JLabel("Path");
|
||||||
|
panel1.add(name);
|
||||||
|
center.add(panel1);
|
||||||
|
|
||||||
|
JTextField tf = new JTextField(5);
|
||||||
|
center.add(tf);
|
||||||
|
|
||||||
|
JButton edit = new JButton("Done");
|
||||||
|
edit.addActionListener(new ActionListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e)
|
||||||
|
{
|
||||||
|
p.addWaypoint(Integer.valueOf(tf.getText()), panel);
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
south.add(edit);
|
||||||
|
|
||||||
|
setContentPane(content);
|
||||||
|
setVisible(true);
|
||||||
|
setSize(500, 320);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,609 @@
|
|||||||
|
package Applicatie;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Container;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.FlowLayout;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.event.KeyListener;
|
||||||
|
import java.awt.geom.Point2D;
|
||||||
|
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
|
import javax.swing.Box;
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
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;
|
||||||
|
|
||||||
|
JTextField locationXField;
|
||||||
|
JTextField locationYField;
|
||||||
|
JTextField scaleField;
|
||||||
|
JTextField rotationField;
|
||||||
|
JTextField areaTopField;
|
||||||
|
JTextField areaBottomField;
|
||||||
|
JTextField areaLeftField;
|
||||||
|
JTextField areaRightField;
|
||||||
|
|
||||||
|
PropertiesPanel()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
BoxLayout box = new BoxLayout(this, BoxLayout.PAGE_AXIS);
|
||||||
|
setLayout(box);
|
||||||
|
|
||||||
|
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();
|
||||||
|
JLabel propLabel = new JLabel("Properties");
|
||||||
|
propLabel.setFont(new Font("Segoe UI", Font.BOLD, 30));
|
||||||
|
propPanel.setBackground(new Color(220, 220, 220));
|
||||||
|
propPanel.setMaximumSize(new Dimension(200, 60));
|
||||||
|
propPanel.add(propLabel);
|
||||||
|
add(propPanel);
|
||||||
|
|
||||||
|
// NAME
|
||||||
|
JPanel namePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
|
nameLabel = new JLabel("No Selection");
|
||||||
|
nameLabel.setFont(new Font("Segoe UI", Font.PLAIN, 20));
|
||||||
|
namePanel.setPreferredSize(new Dimension(200, 40));
|
||||||
|
namePanel.setMaximumSize(new Dimension(200, 40));
|
||||||
|
namePanel.add(nameLabel);
|
||||||
|
add(namePanel);
|
||||||
|
|
||||||
|
// SPACER
|
||||||
|
add(Box.createRigidArea(spacerDimension));
|
||||||
|
|
||||||
|
// BUTTONS
|
||||||
|
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
|
JLabel buttonLabel = new JLabel("Actions");
|
||||||
|
buttonLabel.setFont(new Font("Segoe UI", Font.ITALIC, 20));
|
||||||
|
buttonPanel.setPreferredSize(new Dimension(200, 40));
|
||||||
|
buttonPanel.setMaximumSize(new Dimension(200, 40));
|
||||||
|
buttonPanel.add(buttonLabel);
|
||||||
|
add(buttonPanel);
|
||||||
|
|
||||||
|
// AREA PANEL: AVAILABLE FOR ACTIONLISTENER
|
||||||
|
areaPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
|
areaPanel.setVisible(false);
|
||||||
|
|
||||||
|
rigidArea = Box.createRigidArea(spacerDimension);
|
||||||
|
rigidArea.setVisible(false);
|
||||||
|
|
||||||
|
// 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()
|
||||||
|
{
|
||||||
|
public void actionPerformed(ActionEvent e)
|
||||||
|
{
|
||||||
|
if (selectedObject != null)
|
||||||
|
p.removeObject(selectedObject);
|
||||||
|
else if (selectedPath != null)
|
||||||
|
{
|
||||||
|
p.removePath(selectedPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
JButton areaButton = new JButton("Area");
|
||||||
|
areaButton.setFocusable(false);
|
||||||
|
areaButton.setFont(new Font("Segoe UI", Font.PLAIN, 20));
|
||||||
|
areaButton.addActionListener(new ActionListener()
|
||||||
|
{
|
||||||
|
public void actionPerformed(ActionEvent e)
|
||||||
|
{
|
||||||
|
areaPanel.setVisible(!areaPanel.isVisible());
|
||||||
|
rigidArea.setVisible(!rigidArea.isVisible());
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
row1ButtonPanel.setPreferredSize(new Dimension(200, 50));
|
||||||
|
row1ButtonPanel.setMaximumSize(new Dimension(200, 50));
|
||||||
|
row1ButtonPanel.add(deleteButton);
|
||||||
|
row1ButtonPanel.add(areaButton);
|
||||||
|
add(row1ButtonPanel);
|
||||||
|
|
||||||
|
add(rigidArea);
|
||||||
|
|
||||||
|
// AREA PANEL
|
||||||
|
JLabel areaLabel = new JLabel("Area size");
|
||||||
|
areaLabel.setFont(new Font("Segoe UI", Font.ITALIC, 20));
|
||||||
|
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, 50));
|
||||||
|
areaPanel.add(areaTopPanel);
|
||||||
|
|
||||||
|
JLabel areaTopLabel = new JLabel("Top");
|
||||||
|
areaTopPanel.add(areaTopLabel);
|
||||||
|
areaTopField = new JTextField();
|
||||||
|
areaTopField.setPreferredSize(new Dimension(140, 25));
|
||||||
|
|
||||||
|
{
|
||||||
|
areaTopField.addKeyListener(new KeyListener()
|
||||||
|
{
|
||||||
|
|
||||||
|
public void keyTyped(KeyEvent e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyReleased(KeyEvent e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
areaTopField.setBackground(Color.WHITE);
|
||||||
|
int top = Integer.parseInt(areaTopField.getText());
|
||||||
|
selectedObject.setAreaTop(top);
|
||||||
|
p.update();
|
||||||
|
}
|
||||||
|
catch (NumberFormatException nfe)
|
||||||
|
{
|
||||||
|
areaTopField.setBackground(Color.RED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyPressed(KeyEvent e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
areaTopPanel.add(areaTopField);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
JPanel areaBottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
|
areaBottomPanel.setPreferredSize(new Dimension(200, 50));
|
||||||
|
|
||||||
|
areaPanel.add(areaBottomPanel);
|
||||||
|
|
||||||
|
JLabel areaBottomLabel = new JLabel("Bottom");
|
||||||
|
areaBottomPanel.add(areaBottomLabel);
|
||||||
|
areaBottomField = new JTextField();
|
||||||
|
areaBottomField.setPreferredSize(new Dimension(120, 25));
|
||||||
|
{
|
||||||
|
areaBottomField.addKeyListener(new KeyListener()
|
||||||
|
{
|
||||||
|
|
||||||
|
public void keyTyped(KeyEvent e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyReleased(KeyEvent e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
areaBottomField.setBackground(Color.WHITE);
|
||||||
|
int bottom = Integer.parseInt(areaBottomField.getText());
|
||||||
|
selectedObject.setAreaBottom(bottom);
|
||||||
|
p.update();
|
||||||
|
}
|
||||||
|
catch (NumberFormatException nfe)
|
||||||
|
{
|
||||||
|
areaBottomField.setBackground(Color.RED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyPressed(KeyEvent e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
areaBottomPanel.add(areaBottomField);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
JPanel areaLeftPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
|
areaLeftPanel.setPreferredSize(new Dimension(200, 50));
|
||||||
|
areaPanel.add(areaLeftPanel);
|
||||||
|
|
||||||
|
JLabel areaLeftLabel = new JLabel("Left");
|
||||||
|
areaLeftPanel.add(areaLeftLabel);
|
||||||
|
areaLeftField = new JTextField();
|
||||||
|
areaLeftField.setPreferredSize(new Dimension(138, 25));
|
||||||
|
{
|
||||||
|
areaLeftField.addKeyListener(new KeyListener()
|
||||||
|
{
|
||||||
|
|
||||||
|
public void keyTyped(KeyEvent e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyReleased(KeyEvent e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
areaLeftField.setBackground(Color.WHITE);
|
||||||
|
int left = Integer.parseInt(areaLeftField.getText());
|
||||||
|
selectedObject.setAreaLeft(left);
|
||||||
|
p.update();
|
||||||
|
}
|
||||||
|
catch (NumberFormatException nfe)
|
||||||
|
{
|
||||||
|
areaLeftField.setBackground(Color.RED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyPressed(KeyEvent e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
areaLeftPanel.add(areaLeftField);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
JPanel areaRightPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
|
|
||||||
|
areaRightPanel.setPreferredSize(new Dimension(200, 50));
|
||||||
|
areaPanel.add(areaRightPanel);
|
||||||
|
|
||||||
|
JLabel areaRightLabel = new JLabel("Right");
|
||||||
|
areaRightPanel.add(areaRightLabel);
|
||||||
|
areaRightField = new JTextField();
|
||||||
|
areaRightField.setPreferredSize(new Dimension(130, 25));
|
||||||
|
{
|
||||||
|
areaRightField.addKeyListener(new KeyListener()
|
||||||
|
{
|
||||||
|
|
||||||
|
public void keyTyped(KeyEvent e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyReleased(KeyEvent e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
areaRightField.setBackground(Color.WHITE);
|
||||||
|
int right = Integer.parseInt(areaRightField.getText());
|
||||||
|
selectedObject.setAreaRight(right);
|
||||||
|
p.update();
|
||||||
|
}
|
||||||
|
catch (NumberFormatException nfe)
|
||||||
|
{
|
||||||
|
areaRightField.setBackground(Color.RED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyPressed(KeyEvent e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
areaRightPanel.add(areaRightField);
|
||||||
|
}
|
||||||
|
|
||||||
|
// SPACER
|
||||||
|
add(Box.createRigidArea(spacerDimension));
|
||||||
|
|
||||||
|
// LOCATION
|
||||||
|
JPanel locationPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
|
JLabel locationLabel = new JLabel("Location");
|
||||||
|
locationLabel.setFont(new Font("Segoe UI", Font.ITALIC, 20));
|
||||||
|
locationPanel.setPreferredSize(new Dimension(200, 110));
|
||||||
|
locationPanel.setMaximumSize(new Dimension(200, 110));
|
||||||
|
locationPanel.add(locationLabel);
|
||||||
|
add(locationPanel);
|
||||||
|
{
|
||||||
|
JPanel locationXPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
|
locationXPanel.setPreferredSize(new Dimension(200, 30));
|
||||||
|
locationPanel.add(locationXPanel);
|
||||||
|
|
||||||
|
JLabel locationXLabel = new JLabel("X");
|
||||||
|
locationXPanel.add(locationXLabel);
|
||||||
|
locationXField = new JTextField();
|
||||||
|
locationXField.setPreferredSize(new Dimension(150, 25));
|
||||||
|
{
|
||||||
|
locationXField.addKeyListener(new KeyListener()
|
||||||
|
{
|
||||||
|
|
||||||
|
public void keyTyped(KeyEvent e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyReleased(KeyEvent e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
locationXField.setBackground(Color.WHITE);
|
||||||
|
double xpos = Double.parseDouble(locationXField.getText());
|
||||||
|
selectedObject.setPosition(new Point2D.Double(xpos, selectedObject.getPosition().getY()), true);
|
||||||
|
update();
|
||||||
|
p.update();
|
||||||
|
}
|
||||||
|
catch (NumberFormatException nfe)
|
||||||
|
{
|
||||||
|
locationXField.setBackground(Color.RED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyPressed(KeyEvent e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
locationXPanel.add(locationXField);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
JPanel locationYPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
|
locationYPanel.setPreferredSize(new Dimension(200, 30));
|
||||||
|
locationPanel.add(locationYPanel);
|
||||||
|
|
||||||
|
JLabel locationYLabel = new JLabel("Y");
|
||||||
|
locationYPanel.add(locationYLabel);
|
||||||
|
locationYField = new JTextField();
|
||||||
|
locationYField.setPreferredSize(new Dimension(150, 25));
|
||||||
|
{
|
||||||
|
locationYField.addKeyListener(new KeyListener()
|
||||||
|
{
|
||||||
|
|
||||||
|
public void keyTyped(KeyEvent e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyReleased(KeyEvent e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
locationYField.setBackground(Color.WHITE);
|
||||||
|
double ypos = Double.parseDouble(locationYField.getText());
|
||||||
|
selectedObject.setPosition(new Point2D.Double(selectedObject.getPosition().getX(), ypos), true);
|
||||||
|
update();
|
||||||
|
p.update();
|
||||||
|
}
|
||||||
|
catch (NumberFormatException nfe)
|
||||||
|
{
|
||||||
|
|
||||||
|
locationYField.setBackground(Color.RED);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyPressed(KeyEvent e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
locationYPanel.add(locationYField);
|
||||||
|
}
|
||||||
|
|
||||||
|
// SCALE
|
||||||
|
JPanel scalePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
|
JLabel scaleLabel = new JLabel("Scale");
|
||||||
|
scaleLabel.setFont(new Font("Segoe UI", Font.ITALIC, 20));
|
||||||
|
scalePanel.setPreferredSize(new Dimension(200, 70));
|
||||||
|
scalePanel.setMaximumSize(new Dimension(200, 70));
|
||||||
|
scalePanel.add(scaleLabel);
|
||||||
|
add(scalePanel);
|
||||||
|
{
|
||||||
|
JPanel scalePanel2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
|
scalePanel2.setPreferredSize(new Dimension(200, 30));
|
||||||
|
scalePanel.add(scalePanel2);
|
||||||
|
|
||||||
|
JLabel scale2Label = new JLabel(" ");
|
||||||
|
scalePanel2.add(scale2Label);
|
||||||
|
scaleField = new JTextField();
|
||||||
|
scaleField.setPreferredSize(new Dimension(150, 25));
|
||||||
|
{
|
||||||
|
scaleField.addKeyListener(new KeyListener()
|
||||||
|
{
|
||||||
|
|
||||||
|
public void keyTyped(KeyEvent e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyReleased(KeyEvent e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
scaleField.setBackground(Color.RED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyPressed(KeyEvent e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
scalePanel2.add(scaleField);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ROTATION
|
||||||
|
JPanel rotationPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
|
JLabel rotationLabel = new JLabel("Rotation");
|
||||||
|
rotationLabel.setFont(new Font("Segoe UI", Font.ITALIC, 20));
|
||||||
|
rotationPanel.setPreferredSize(new Dimension(200, 80));
|
||||||
|
rotationPanel.setMaximumSize(new Dimension(200, 80));
|
||||||
|
rotationPanel.add(rotationLabel);
|
||||||
|
add(rotationPanel);
|
||||||
|
{
|
||||||
|
JPanel rotationPanel2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
|
rotationPanel2.setPreferredSize(new Dimension(200, 30));
|
||||||
|
rotationPanel.add(rotationPanel2);
|
||||||
|
|
||||||
|
JLabel rotation2Label = new JLabel(" ");
|
||||||
|
rotationPanel2.add(rotation2Label);
|
||||||
|
rotationField = new JTextField();
|
||||||
|
rotationField.setPreferredSize(new Dimension(150, 25));
|
||||||
|
{
|
||||||
|
rotationField.addKeyListener(new KeyListener()
|
||||||
|
{
|
||||||
|
|
||||||
|
public void keyTyped(KeyEvent e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyReleased(KeyEvent e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
rotationField.setBackground(Color.WHITE);
|
||||||
|
int rotation = Integer.parseInt(rotationField.getText()) % 360;
|
||||||
|
rotationField.setText(rotation + "");
|
||||||
|
selectedObject.setRotation(rotation);
|
||||||
|
p.update();
|
||||||
|
}
|
||||||
|
catch (NumberFormatException nfe)
|
||||||
|
{
|
||||||
|
rotationField.setBackground(Color.RED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyPressed(KeyEvent e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
rotationPanel2.add(rotationField);
|
||||||
|
}
|
||||||
|
|
||||||
|
// SPACER
|
||||||
|
add(Box.createRigidArea(spacerDimension));
|
||||||
|
|
||||||
|
// AGENDA
|
||||||
|
JPanel agendaPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
|
JLabel agendaLabel = new JLabel("Agenda");
|
||||||
|
agendaLabel.setFont(new Font("Segoe UI", Font.ITALIC, 20));
|
||||||
|
agendaPanel.setPreferredSize(new Dimension(200, 100));
|
||||||
|
agendaPanel.setMaximumSize(new Dimension(200, 100));
|
||||||
|
agendaPanel.add(agendaLabel);
|
||||||
|
add(agendaPanel);
|
||||||
|
|
||||||
|
enableComponents(this, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelected(DrawObject drOb)
|
||||||
|
{
|
||||||
|
selectedObject = drOb;
|
||||||
|
selectedPath = null;
|
||||||
|
fillFields();
|
||||||
|
enableComponents(this, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearSelected()
|
||||||
|
{
|
||||||
|
enableComponents(this, false);
|
||||||
|
clearFields(this);
|
||||||
|
selectedObject = null;
|
||||||
|
selectedPath = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update()
|
||||||
|
{
|
||||||
|
if (selectedObject != null)
|
||||||
|
fillFields();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enableComponents(Container container, boolean enable)
|
||||||
|
{
|
||||||
|
Component[] components = container.getComponents();
|
||||||
|
for (Component component : components)
|
||||||
|
{
|
||||||
|
component.setEnabled(enable);
|
||||||
|
if (component instanceof Container)
|
||||||
|
{
|
||||||
|
enableComponents((Container) component, enable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearFields(Container container)
|
||||||
|
{
|
||||||
|
Component[] components = container.getComponents();
|
||||||
|
for (Component component : components)
|
||||||
|
{
|
||||||
|
if (component instanceof JTextField)
|
||||||
|
{
|
||||||
|
((JTextField) component).setText("");
|
||||||
|
((JTextField) component).setBackground(Color.WHITE);
|
||||||
|
|
||||||
|
}
|
||||||
|
if (component instanceof Container)
|
||||||
|
{
|
||||||
|
clearFields((Container) component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nameLabel.setText("No Selection");
|
||||||
|
areaPanel.setVisible(false);
|
||||||
|
rigidArea.setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
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() + "");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPanel(Panel p)
|
||||||
|
{
|
||||||
|
this.p = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelectedPath(Path path)
|
||||||
|
{
|
||||||
|
selectedObject = null;
|
||||||
|
selectedPath = path;
|
||||||
|
fillPathFields();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillPathFields()
|
||||||
|
{
|
||||||
|
nameLabel.setText("Path");
|
||||||
|
enableComponents(this, true);
|
||||||
|
locationXField.setEnabled(false);
|
||||||
|
locationYField.setEnabled(false);
|
||||||
|
scaleField.setEnabled(false);
|
||||||
|
rotationField.setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
package Applicatie;
|
||||||
|
import java.io.EOFException;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.filechooser.FileFilter;
|
||||||
|
|
||||||
|
import Objects.DrawObject;
|
||||||
|
|
||||||
|
public class SaveLoad {
|
||||||
|
|
||||||
|
|
||||||
|
public static void save(Panel panel)
|
||||||
|
{
|
||||||
|
JFileChooser fileChooser = new JFileChooser();
|
||||||
|
|
||||||
|
fileChooser.setFileFilter(new FileFilter() {
|
||||||
|
@Override
|
||||||
|
public boolean accept(File pathname) {
|
||||||
|
if(pathname.isFile() && pathname.getName().endsWith(".agn"))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}else if(pathname.isDirectory()){return true;}else{return false;}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return ".agn";
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
fileChooser.setDialogTitle("Choose save location");
|
||||||
|
int userSelection = fileChooser.showSaveDialog(null);
|
||||||
|
|
||||||
|
if(userSelection == JFileChooser.APPROVE_OPTION)
|
||||||
|
{
|
||||||
|
File file = fileChooser.getSelectedFile();
|
||||||
|
if(!file.getName().endsWith(".agn"))
|
||||||
|
{
|
||||||
|
file = new File(file.getAbsolutePath() + ".agn");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
if(JOptionPane.showConfirmDialog(null, "Are you sure you want to overwrite: " + file.getName(), "Overwrite", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION)
|
||||||
|
{
|
||||||
|
saveTerrain(file, panel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
saveTerrain(file, panel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void saveTerrain(File file, Panel panel) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
FileOutputStream fos = new FileOutputStream(file);
|
||||||
|
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||||
|
for (DrawObject object : panel.objects) {
|
||||||
|
oos.writeObject(object);
|
||||||
|
}
|
||||||
|
oos.close();
|
||||||
|
JOptionPane.showMessageDialog(null, "Saved succesfully");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void load(Panel panel)
|
||||||
|
{
|
||||||
|
JFileChooser fileChooser = new JFileChooser();
|
||||||
|
fileChooser.setFileFilter(new FileFilter() {
|
||||||
|
@Override
|
||||||
|
public boolean accept(File pathname) {
|
||||||
|
if(pathname.isFile() && pathname.getName().endsWith(".agn"))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}else if(pathname.isDirectory()){return true;}else{return false;}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return ".agn";
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
fileChooser.setDialogTitle("Choose file");
|
||||||
|
int userSelection = fileChooser.showOpenDialog(null);
|
||||||
|
|
||||||
|
if(userSelection == JFileChooser.APPROVE_OPTION)
|
||||||
|
{
|
||||||
|
File file = fileChooser.getSelectedFile();
|
||||||
|
if(!file.exists())
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(null, "This file does not exist: " + file.getName());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fillTerrain(file, panel);
|
||||||
|
JOptionPane.showMessageDialog(null, "Loaded succesfully");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void fillTerrain(File file, Panel panel) {
|
||||||
|
FileInputStream fis = null;
|
||||||
|
ObjectInputStream ois = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
fis = new FileInputStream(file);
|
||||||
|
ois = new ObjectInputStream(fis);
|
||||||
|
|
||||||
|
Object object;
|
||||||
|
object = ois.readObject();
|
||||||
|
try {
|
||||||
|
panel.clearObjects();
|
||||||
|
while (object != null) {
|
||||||
|
panel.objects.add((DrawObject) object);
|
||||||
|
object = ois.readObject();
|
||||||
|
}
|
||||||
|
} catch (EOFException e) {
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
panel.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,483 @@
|
|||||||
|
package Applicatie;
|
||||||
|
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Image;
|
||||||
|
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.GregorianCalendar;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import Agenda.Agenda;
|
||||||
|
import Agenda.Event;
|
||||||
|
import Objects.DrawObject;
|
||||||
|
import Objects.Entrance;
|
||||||
|
import Objects.Path;
|
||||||
|
import Objects.Stage;
|
||||||
|
|
||||||
|
public class Visitor {
|
||||||
|
|
||||||
|
Point2D position;
|
||||||
|
double rotation;
|
||||||
|
double scale;
|
||||||
|
double speed;
|
||||||
|
String filename;
|
||||||
|
ArrayList<Action> actions;
|
||||||
|
Agenda agenda;
|
||||||
|
ArrayList<DrawObject> objects;
|
||||||
|
ArrayList<Waypoint> waypoints;
|
||||||
|
GregorianCalendar date;
|
||||||
|
int target;
|
||||||
|
int finalTarget;
|
||||||
|
|
||||||
|
public Visitor(String filename, Point2D position, Agenda agenda,
|
||||||
|
ArrayList<DrawObject> objects, ArrayList<Waypoint> waypoints,
|
||||||
|
GregorianCalendar date) {
|
||||||
|
this.position = position;
|
||||||
|
this.filename = filename;
|
||||||
|
this.rotation = 0;
|
||||||
|
this.speed = 1 + Math.random() * 4;
|
||||||
|
this.waypoints = waypoints;
|
||||||
|
this.date = date;
|
||||||
|
scale = 1;
|
||||||
|
actions = new ArrayList<Action>();
|
||||||
|
this.agenda = agenda;
|
||||||
|
this.objects = objects;
|
||||||
|
fillActions();
|
||||||
|
System.out.println(actions.size());
|
||||||
|
for (Action a : actions){
|
||||||
|
System.out.println("" + a.getStartTime());
|
||||||
|
}
|
||||||
|
target = 1;
|
||||||
|
finalTarget = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw(Graphics2D g2) {
|
||||||
|
AffineTransform tx = getTransform();
|
||||||
|
Image image = Images.getImage(filename);
|
||||||
|
g2.drawImage(image, tx, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private AffineTransform getTransform() {
|
||||||
|
Image image = Images.getImage(filename);
|
||||||
|
AffineTransform tx = new AffineTransform();
|
||||||
|
tx.scale(scale, scale);
|
||||||
|
tx.translate(position.getX(), position.getY());
|
||||||
|
tx.rotate(rotation, image.getWidth(null) / 2, image.getHeight(null) / 2);
|
||||||
|
return tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawObject getEntrance() {
|
||||||
|
for (DrawObject o : objects) {
|
||||||
|
if (o instanceof Entrance) {
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(ArrayList<DrawObject> objects, int currentTime,
|
||||||
|
ArrayList<Visitor> visitors, ArrayList<Path> paths, Panel panel) {
|
||||||
|
DrawObject target = getEntrance();
|
||||||
|
for (Action a : actions) {
|
||||||
|
if (currentTime >= a.getStartTime()
|
||||||
|
&& currentTime < a.getStoptime()) {
|
||||||
|
finalTarget = a.getWaypoint().getSelf();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// moveToTarget(target, objects, visitors, paths);
|
||||||
|
move(target, panel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void move(DrawObject tar, Panel panel) {
|
||||||
|
Point2D targetPoint = panel.getWaypoint(target).getPosition();
|
||||||
|
|
||||||
|
double newRot = Math.atan2(targetPoint.getY() - position.getY(),
|
||||||
|
targetPoint.getX() - position.getX());
|
||||||
|
|
||||||
|
int difx = (int) (targetPoint.getX() - position.getX());
|
||||||
|
int dify = (int) (targetPoint.getY() - position.getY());
|
||||||
|
int distance = (int) Math.sqrt((difx * difx) + (dify * dify));
|
||||||
|
|
||||||
|
if (rotation > newRot && distance > 10) {
|
||||||
|
rotation -= 0.15;
|
||||||
|
} else if (rotation < newRot && distance > 10) {
|
||||||
|
rotation += 0.15;
|
||||||
|
}
|
||||||
|
|
||||||
|
Point2D oldPosition = position;
|
||||||
|
|
||||||
|
// face direction
|
||||||
|
float directionX = (float) Math.cos(rotation);
|
||||||
|
float directionY = (float) Math.sin(rotation);
|
||||||
|
|
||||||
|
if (distance > 10) {
|
||||||
|
position = new Point2D.Double(
|
||||||
|
(position.getX() + directionX * speed),
|
||||||
|
(position.getY() + directionY * speed));
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean possible = true;
|
||||||
|
for (DrawObject object : objects) {
|
||||||
|
if (object instanceof Entrance || object instanceof Waypoint) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (hasCollisionDO(object)) {
|
||||||
|
possible = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (possible == false) {
|
||||||
|
position = oldPosition;
|
||||||
|
rotation += 0.2;
|
||||||
|
}
|
||||||
|
if (checkIfOnWaypoint(panel)) {
|
||||||
|
// for(int i : panel.getWaypoint(target).getOptions())
|
||||||
|
// {
|
||||||
|
// if(i == finalTarget)
|
||||||
|
// {
|
||||||
|
// target = finalTarget;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// ArrayList<int[]> options = new ArrayList<int[]>();
|
||||||
|
HashMap<Integer, int[]> options = new HashMap<Integer, int[]>();
|
||||||
|
for (Waypoint w : panel.getWaypoints()) {
|
||||||
|
options.put(w.getSelf(), w.getOptions());
|
||||||
|
}
|
||||||
|
for (Map.Entry<Integer, int[]> e : options.entrySet()) {
|
||||||
|
System.out.println(e.getKey());
|
||||||
|
System.out.println("=====================");
|
||||||
|
for (int i : e.getValue()) {
|
||||||
|
System.out.println(i);
|
||||||
|
}
|
||||||
|
System.out.println("----------");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkIfOnWaypoint(Panel panel) {
|
||||||
|
if (panel.getWaypoint(target).contains(position)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void moveToTarget(DrawObject target, ArrayList<DrawObject> objects,
|
||||||
|
ArrayList<Visitor> visitors, ArrayList<Path> paths) {
|
||||||
|
Point2D tar = target.getPosition();
|
||||||
|
boolean hasPathBelow = false;
|
||||||
|
for (Path p : paths) {
|
||||||
|
if (p.containsPoint(position)) {
|
||||||
|
hasPathBelow = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Shape containsShape = p.containsPointShape(position);
|
||||||
|
if (containsShape != null) {
|
||||||
|
tar = new Point2D.Double(
|
||||||
|
containsShape.getBounds().getCenterX(), containsShape
|
||||||
|
.getBounds().getCenterY());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasPathBelow) {
|
||||||
|
double newRot = Math.atan2(tar.getY() - position.getY(), tar.getX()
|
||||||
|
- position.getX());
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void fillActions() {
|
||||||
|
int startTime = 540;
|
||||||
|
int stopTime = 1260;
|
||||||
|
|
||||||
|
while (startTime < stopTime) {
|
||||||
|
int random = (int) Math.floor(Math.random() * 51);
|
||||||
|
if (random < 30) {
|
||||||
|
Point2D position = null;
|
||||||
|
DrawObject targetStage = null;
|
||||||
|
ArrayList<Event> posEvents = new ArrayList<Event>();
|
||||||
|
for (Event e : agenda.getEvents()) {
|
||||||
|
if (startTime >= e.getStart() && startTime < e.getStop()) {
|
||||||
|
posEvents.add(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int totalPopularity = 0;
|
||||||
|
for (Event ev : posEvents){
|
||||||
|
totalPopularity += ev.getExpectedPopularity();
|
||||||
|
}
|
||||||
|
|
||||||
|
Random rand = new Random();
|
||||||
|
int n = rand.nextInt(totalPopularity) + 1;
|
||||||
|
int currentPop = 0;
|
||||||
|
if (posEvents != null){
|
||||||
|
for (Event evs : posEvents){
|
||||||
|
int before = currentPop;
|
||||||
|
currentPop = currentPop + evs.getExpectedPopularity();
|
||||||
|
if (before < n && currentPop >= n){
|
||||||
|
for (DrawObject d : objects) {
|
||||||
|
if (d.getFileName().equals("stage")) {
|
||||||
|
Stage s = (Stage) d;
|
||||||
|
if (s.getStage().getName()
|
||||||
|
.equals(evs.getStage().getName())) {
|
||||||
|
position = s.getPosition();
|
||||||
|
targetStage = d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int randomtime = (int) (40 + (Math.random() * (60 - 40)));
|
||||||
|
if (position != null) {
|
||||||
|
Waypoint w = getClosedWaypoint(position);
|
||||||
|
actions.add(new Action(position, startTime, randomtime,
|
||||||
|
targetStage, w));
|
||||||
|
}
|
||||||
|
startTime = startTime + randomtime;
|
||||||
|
|
||||||
|
} else if (random >= 30 && random < 40) {
|
||||||
|
Point2D position = null;
|
||||||
|
DrawObject targetStage = null;
|
||||||
|
ArrayList<DrawObject> foodPlaces = new ArrayList<DrawObject>();
|
||||||
|
for (DrawObject d : objects) {
|
||||||
|
if (d.getFileName().equals("food")) {
|
||||||
|
foodPlaces.add(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (foodPlaces.size() != 0) {
|
||||||
|
int r = (int) Math.floor(Math.random() * foodPlaces.size());
|
||||||
|
position = foodPlaces.get(r).getPosition();
|
||||||
|
targetStage = foodPlaces.get(r);
|
||||||
|
Waypoint w = getClosedWaypoint(position);
|
||||||
|
actions.add(new Action(position, startTime, 35,
|
||||||
|
targetStage, w));
|
||||||
|
startTime = startTime + 20;
|
||||||
|
}
|
||||||
|
startTime = startTime + 35;
|
||||||
|
|
||||||
|
} else if (random >= 40) {
|
||||||
|
Point2D position = null;
|
||||||
|
DrawObject targetStage = null;
|
||||||
|
ArrayList<DrawObject> toilets = new ArrayList<DrawObject>();
|
||||||
|
for (DrawObject d : objects) {
|
||||||
|
if (d.getFileName().equals("wc")) {
|
||||||
|
toilets.add(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (toilets.size() != 0) {
|
||||||
|
int r = (int) Math.floor(Math.random() * toilets.size());
|
||||||
|
position = toilets.get(r).getPosition();
|
||||||
|
targetStage = toilets.get(r);
|
||||||
|
Waypoint w = getClosedWaypoint(position);
|
||||||
|
actions.add(new Action(position, startTime, 35,
|
||||||
|
targetStage, w));
|
||||||
|
startTime = startTime + 20;
|
||||||
|
}
|
||||||
|
startTime = startTime + 35;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Waypoint getClosedWaypoint(Point2D point) {
|
||||||
|
Waypoint waypoint = null;
|
||||||
|
int distance = 10000;
|
||||||
|
for (Waypoint w : waypoints) {
|
||||||
|
if (w.getPosition().distance(point) < distance) {
|
||||||
|
waypoint = w;
|
||||||
|
distance = (int) w.getPosition().distance(point);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return waypoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasCollisionDO(DrawObject object) {
|
||||||
|
Image image = Images.getImage(filename);
|
||||||
|
Image image2 = Images.getImage(object.getFileName());
|
||||||
|
Rectangle recta = new Rectangle((int) position.getX(),
|
||||||
|
(int) position.getY(), image.getWidth(null),
|
||||||
|
image.getHeight(null));
|
||||||
|
Rectangle rectb = new Rectangle((int) object.getPosition().getX(),
|
||||||
|
(int) object.getPosition().getY(), image2.getWidth(null),
|
||||||
|
image2.getHeight(null));
|
||||||
|
|
||||||
|
Area a = new Area(recta);
|
||||||
|
Area b = new Area(rectb);
|
||||||
|
|
||||||
|
AffineTransform transA = new AffineTransform();
|
||||||
|
transA.rotate(rotation, position.getX(), position.getY());
|
||||||
|
|
||||||
|
AffineTransform transB = new AffineTransform();
|
||||||
|
transB.rotate(Math.toRadians(object.getRotation()), object
|
||||||
|
.getPosition().getX(), object.getPosition().getY());
|
||||||
|
|
||||||
|
Area aa = a.createTransformedArea(transA);
|
||||||
|
Area bb = b.createTransformedArea(transB);
|
||||||
|
|
||||||
|
if (bb.intersects(aa.getBounds2D())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasCollision(Visitor v) {
|
||||||
|
Image image = Images.getImage(filename);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,112 @@
|
|||||||
|
package Applicatie;
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.FlowLayout;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
import javax.swing.Box;
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
|
import Objects.DrawObject;
|
||||||
|
|
||||||
|
public class WaypointPopup extends JFrame {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1;
|
||||||
|
private JLabel title;
|
||||||
|
|
||||||
|
public WaypointPopup(DrawObject w, Panel panel)
|
||||||
|
{
|
||||||
|
super("Edit WayPoint");
|
||||||
|
Waypoint wp = (Waypoint) w;
|
||||||
|
setDefaultCloseOperation(HIDE_ON_CLOSE);
|
||||||
|
JPanel content = new JPanel(new BorderLayout());
|
||||||
|
JPanel north = new JPanel();
|
||||||
|
if(wp.getSelf() == 0)
|
||||||
|
{
|
||||||
|
title = new JLabel("Edit WayPoint");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
title = new JLabel("Edit WayPoint " + wp.getSelf());
|
||||||
|
}
|
||||||
|
title.setFont(new Font("Dialog", Font.BOLD, 24));
|
||||||
|
north.add(title);
|
||||||
|
content.add(north, BorderLayout.NORTH);
|
||||||
|
JPanel center = new JPanel(new FlowLayout());
|
||||||
|
JPanel row1 = new JPanel();
|
||||||
|
row1.setLayout(new BoxLayout(row1, BoxLayout.Y_AXIS));
|
||||||
|
JPanel row2 = new JPanel();
|
||||||
|
row2.setLayout(new BoxLayout(row2, BoxLayout.Y_AXIS));
|
||||||
|
JPanel south = new JPanel();
|
||||||
|
content.add(south, BorderLayout.SOUTH);
|
||||||
|
content.add(center, BorderLayout.CENTER);
|
||||||
|
center.add(row1);
|
||||||
|
center.add(row2);
|
||||||
|
|
||||||
|
JPanel empty = new JPanel();
|
||||||
|
empty.add(Box.createRigidArea(new Dimension(0, 20)));
|
||||||
|
row2.add(empty);
|
||||||
|
|
||||||
|
JPanel panel1 = new JPanel();
|
||||||
|
JLabel name = new JLabel("Waypoint");
|
||||||
|
name.setFont(new Font("Dialog", Font.PLAIN, 20));
|
||||||
|
panel1.add(name);
|
||||||
|
row1.add(panel1);
|
||||||
|
|
||||||
|
JTextField tf = new JTextField(10);
|
||||||
|
row2.add(tf);
|
||||||
|
|
||||||
|
JPanel panel2 = new JPanel();
|
||||||
|
JLabel options = new JLabel("Options");
|
||||||
|
options.setFont(new Font("Dialog", Font.PLAIN, 20));
|
||||||
|
panel2.add(options);
|
||||||
|
row1.add(panel2);
|
||||||
|
|
||||||
|
JPanel empty2 = new JPanel();
|
||||||
|
empty2.add(Box.createRigidArea(new Dimension(0, 5)));
|
||||||
|
row2.add(empty2);
|
||||||
|
|
||||||
|
JTextField tx = new JTextField(8);
|
||||||
|
row2.add(tx);
|
||||||
|
|
||||||
|
JPanel help = new JPanel();
|
||||||
|
JLabel example = new JLabel("example: '1-2-3'");
|
||||||
|
example.setFont(new Font("Dialog", Font.PLAIN, 12));
|
||||||
|
help.add(example);
|
||||||
|
row2.add(help);
|
||||||
|
|
||||||
|
JButton edit = new JButton("Done");
|
||||||
|
edit.addActionListener(new ActionListener()
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e)
|
||||||
|
{
|
||||||
|
wp.setSelf(Integer.valueOf(tf.getText()));
|
||||||
|
panel.addWaypoint(wp);
|
||||||
|
dispose();
|
||||||
|
String options[] = tx.getText().split("-");
|
||||||
|
int ioptions[] = new int[options.length];
|
||||||
|
for(int i = 0; i < options.length; i++)
|
||||||
|
{
|
||||||
|
ioptions[i] = Integer.valueOf(options[i]);
|
||||||
|
}
|
||||||
|
wp.setOptions(ioptions);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
south.add(edit);
|
||||||
|
|
||||||
|
setContentPane(content);
|
||||||
|
setVisible(true);
|
||||||
|
setSize(300,250);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,34 +1,50 @@
|
|||||||
package Applicatie;
|
package Applicatie;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
import Listeners.Keyboard;
|
||||||
|
|
||||||
public class Window extends JFrame {
|
public class Window extends JFrame
|
||||||
|
{
|
||||||
private static final long serialVersionUID = -1324363758675184283L;
|
private static final long serialVersionUID = -1324363758675184283L;
|
||||||
|
|
||||||
Window()
|
private Panel fp;
|
||||||
{
|
|
||||||
|
Window() {
|
||||||
super("Festival Plannner");
|
super("Festival Plannner");
|
||||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
setSize(500,600);
|
//setSize(500, 600);
|
||||||
setExtendedState( getExtendedState()|JFrame.MAXIMIZED_BOTH );
|
setMinimumSize(new Dimension(1160, 680));
|
||||||
|
setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH);
|
||||||
//CONTENT PANELS
|
|
||||||
|
// CONTENT PANELS
|
||||||
JPanel contentPanel = new JPanel(new BorderLayout());
|
JPanel contentPanel = new JPanel(new BorderLayout());
|
||||||
Panel fp = new Panel();
|
PropertiesPanel pp = new PropertiesPanel();
|
||||||
|
ControlPanel cp = new ControlPanel();
|
||||||
|
fp = new Panel(pp, cp);
|
||||||
|
contentPanel.add(fp, BorderLayout.CENTER);
|
||||||
|
contentPanel.add(cp, BorderLayout.SOUTH);
|
||||||
|
contentPanel.add(pp, BorderLayout.EAST);
|
||||||
contentPanel.add(fp, BorderLayout.CENTER);
|
contentPanel.add(fp, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
|
||||||
|
addKeyListener(new Keyboard(fp));
|
||||||
setContentPane(contentPanel);
|
setContentPane(contentPanel);
|
||||||
//END CONTENT PANELS
|
// END CONTENT PANELS
|
||||||
|
|
||||||
|
// MENUBAR
|
||||||
//MENUBAR
|
|
||||||
setJMenuBar(new MenuBar(this));
|
setJMenuBar(new MenuBar(this));
|
||||||
//END MENUBAR
|
// END MENUBAR
|
||||||
|
|
||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Panel getPanel() {
|
||||||
|
return fp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,119 @@
|
|||||||
|
package Listeners;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
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 {
|
||||||
|
|
||||||
|
private Panel panel;
|
||||||
|
|
||||||
|
public Keyboard(Panel panel) {
|
||||||
|
this.panel = panel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyPressed(KeyEvent e) {
|
||||||
|
if(e.getKeyCode() == e.VK_DELETE ) {
|
||||||
|
if(panel.getSelectedObject() != null)
|
||||||
|
panel.removeObject(panel.getSelectedObject());
|
||||||
|
else if(panel.getCurrentPath() != null)
|
||||||
|
panel.removePath(panel.getCurrentPath());
|
||||||
|
}
|
||||||
|
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()), 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()), 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), 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), 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")) {
|
||||||
|
panel.setClickedOption("drag");
|
||||||
|
panel.getCurrentPath().setTempPoint(null);
|
||||||
|
panel.setcurrentPath(null);
|
||||||
|
panel.getPP().clearSelected();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyReleased(KeyEvent e) {
|
||||||
|
//if(e.getKeyCode() == e.VK_LEFT) {
|
||||||
|
checkCollision();
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyTyped(KeyEvent e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkCollision() {
|
||||||
|
if(panel.getSelectedObject() != null) {
|
||||||
|
if(panel.getSelectedObject().getRectangleColor() != Color.BLACK) {
|
||||||
|
panel.getSelectedObject().setPosition(panel.getSelectionPosition());
|
||||||
|
panel.getSelectedObject().setRectangleColor(Color.BLACK);
|
||||||
|
}
|
||||||
|
panel.repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,64 +1,179 @@
|
|||||||
package Listeners;
|
package Listeners;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import Applicatie.DrawObject;
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
import Applicatie.Panel;
|
import Applicatie.Panel;
|
||||||
import Objects.Podium;
|
import Applicatie.PathPopup;
|
||||||
|
|
||||||
|
import Applicatie.Waypoint;
|
||||||
|
import Applicatie.WaypointPopup;
|
||||||
|
import Objects.DrawObject;
|
||||||
|
import Objects.Path;
|
||||||
|
import Objects.Entrance;
|
||||||
|
|
||||||
|
public class Mouse extends MouseAdapter
|
||||||
|
{
|
||||||
|
|
||||||
public class Mouse extends MouseAdapter {
|
|
||||||
|
|
||||||
private Panel panel;
|
private Panel panel;
|
||||||
|
private DrawObject selectedObject;
|
||||||
|
|
||||||
public Mouse(Panel panel)
|
public Mouse(Panel panel)
|
||||||
{
|
{
|
||||||
this.panel = panel;
|
this.panel = panel;
|
||||||
|
selectedObject = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e)
|
||||||
|
{
|
||||||
Point2D clickPoint = panel.getClickPoint(e.getPoint());
|
Point2D clickPoint = panel.getClickPoint(e.getPoint());
|
||||||
panel.setLastClickPosition(clickPoint);
|
panel.setLastClickPosition(clickPoint);
|
||||||
panel.setLastMousePosition(e.getPoint());
|
panel.setLastMousePosition(e.getPoint());
|
||||||
if(e.getY() < 150)
|
|
||||||
|
if (!panel.getClickedOption().equals("Path"))
|
||||||
{
|
{
|
||||||
// if(e.getX() < 51) //51 = width podium image
|
if (e.getY() < 150)
|
||||||
// panel.setDragObject(new Podium(clickPoint));
|
|
||||||
// else
|
|
||||||
// panel.setDragObject(new Toilet(clickPoint));
|
|
||||||
int i = 0;
|
|
||||||
int last = 0;
|
|
||||||
for(BufferedImage image : panel.getPanelInfo())
|
|
||||||
{
|
{
|
||||||
if(e.getX() >= panel.getScrollfactor() && e.getX() < last + image.getWidth() + panel.getScrollfactor())
|
int i = 0;
|
||||||
|
int last = 0;
|
||||||
|
for (BufferedImage image : panel.getPanelInfo())
|
||||||
{
|
{
|
||||||
DrawObject tempDrawObj = panel.createNewDrawObject(i);
|
if (e.getX() >= panel.getScrollfactor() && e.getX() < last + image.getWidth() + panel.getScrollfactor())
|
||||||
tempDrawObj.setPosition(clickPoint);
|
{
|
||||||
panel.setDragObject(tempDrawObj);
|
DrawObject tempDrawObj = panel.createNewDrawObject(i);
|
||||||
break;
|
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++;
|
||||||
|
last += image.getWidth();
|
||||||
|
}
|
||||||
|
if (panel.getDragObject() != null)
|
||||||
|
{
|
||||||
|
panel.add(panel.getDragObject());
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
last += image.getWidth();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if(panel.getDragObject() != null)
|
else
|
||||||
{
|
{
|
||||||
panel.add(panel.getDragObject());
|
for (DrawObject o : panel.getObjects())
|
||||||
|
{
|
||||||
|
if (o.contains(clickPoint))
|
||||||
|
{
|
||||||
|
if (SwingUtilities.isRightMouseButton(e))
|
||||||
|
{
|
||||||
|
if (o instanceof Waypoint)
|
||||||
|
{
|
||||||
|
new WaypointPopup(o, panel);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (o == selectedObject)
|
||||||
|
{
|
||||||
|
boolean upperLeft = o.containsCorner(clickPoint, 0);
|
||||||
|
boolean upperRight = o.containsCorner(clickPoint, 1);
|
||||||
|
boolean bottomLeft = o.containsCorner(clickPoint, 2);
|
||||||
|
boolean bottomRight = o.containsCorner(clickPoint, 3);
|
||||||
|
boolean rotate = o.containsCorner(clickPoint, 4);
|
||||||
|
if (upperLeft)
|
||||||
|
{
|
||||||
|
panel.setClickedOption("upperLeft");
|
||||||
|
}
|
||||||
|
else if (upperRight)
|
||||||
|
{
|
||||||
|
panel.setClickedOption("upperRight");
|
||||||
|
}
|
||||||
|
else if (bottomLeft)
|
||||||
|
{
|
||||||
|
panel.setClickedOption("bottomLeft");
|
||||||
|
}
|
||||||
|
else if (bottomRight)
|
||||||
|
{
|
||||||
|
panel.setClickedOption("bottomRight");
|
||||||
|
}
|
||||||
|
else if (rotate)
|
||||||
|
{
|
||||||
|
panel.setClickedOption("rotate");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
panel.setClickedOption("drag");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (selectedObject != null)
|
||||||
|
selectedObject.setSelected(false);
|
||||||
|
o.setSelected(true);
|
||||||
|
selectedObject = o;
|
||||||
|
panel.setDragObject(o);
|
||||||
|
panel.getPP().setSelected(o);
|
||||||
|
panel.setSelectedObject(o);
|
||||||
|
panel.setSelectionPosition(panel.getDragObject().getPosition());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Path clickedPath = panel.getClickedPath(clickPoint);
|
||||||
|
if (clickedPath != null)
|
||||||
|
{
|
||||||
|
if (SwingUtilities.isRightMouseButton(e))
|
||||||
|
{
|
||||||
|
new PathPopup(clickedPath, panel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
panel.checkPath(clickPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (panel.getDragObject() == null && selectedObject != null)
|
||||||
|
{
|
||||||
|
selectedObject.setSelected(false);
|
||||||
|
panel.setSelectedObject(null);
|
||||||
|
panel.getPP().clearSelected();
|
||||||
|
selectedObject = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{ // Making path.
|
||||||
for(DrawObject o : panel.getObjects())
|
|
||||||
if(o.contains(clickPoint))
|
panel.getCurrentPath().addPoint(new Point2D.Double(clickPoint.getX(), clickPoint.getY()));
|
||||||
panel.setDragObject(o);
|
|
||||||
}
|
}
|
||||||
|
panel.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mouseReleased(MouseEvent e) {
|
public void mouseReleased(MouseEvent e)
|
||||||
panel.setDragObject(null);
|
{
|
||||||
|
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
|
||||||
|
{
|
||||||
|
panel.getDragObject().setPosition(panel.getSelectionPosition());
|
||||||
|
panel.getDragObject().setRectangleColor(Color.BLACK);
|
||||||
|
}
|
||||||
|
panel.setSelectionPosition(panel.getSelectedObject().getPosition());
|
||||||
|
}
|
||||||
|
panel.repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
package Listeners;
|
package Listeners;
|
||||||
import Applicatie.Panel;
|
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseMotionAdapter;
|
import java.awt.event.MouseMotionAdapter;
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
|
|
||||||
import Applicatie.Panel;
|
import Applicatie.Panel;
|
||||||
|
import Objects.DrawObject;
|
||||||
|
|
||||||
public class MouseMotion extends MouseMotionAdapter {
|
public class MouseMotion extends MouseMotionAdapter
|
||||||
|
{
|
||||||
|
|
||||||
private Panel panel;
|
private Panel panel;
|
||||||
|
|
||||||
@@ -19,34 +18,98 @@ public class MouseMotion extends MouseMotionAdapter {
|
|||||||
this.panel = panel;
|
this.panel = panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mouseDragged(MouseEvent e) {
|
public void mouseDragged(MouseEvent e)
|
||||||
|
{
|
||||||
Point2D clickPoint = panel.getClickPoint(e.getPoint());
|
Point2D clickPoint = panel.getClickPoint(e.getPoint());
|
||||||
if(panel.getDragObject() != null)
|
if (panel.getDragObject() != null)
|
||||||
{
|
{
|
||||||
if(SwingUtilities.isLeftMouseButton(e)){
|
switch (panel.getClickedOption())
|
||||||
|
|
||||||
|
|
||||||
panel.getDragObject().setPosition(new Point2D.Double(
|
|
||||||
panel.getDragObject().getPosition().getX() - (panel.getLastClickPosition().getX() - clickPoint.getX()),
|
|
||||||
panel.getDragObject().getPosition().getY() - (panel.getLastClickPosition().getY() - clickPoint.getY())));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
case "drag":
|
||||||
double tempval = panel.getDragObject().getRotation() + (panel.getLastClickPosition().getX() - clickPoint.getX());
|
if (panel.getDragObject() != null)
|
||||||
panel.getDragObject().setRotation(tempval);
|
panel.getDragObject().setPosition(new Point2D.Double((panel.getDragObject().getPosition().getX()) - ((panel.getLastClickPosition().getX() - clickPoint.getX())) / panel.getDragObject().getScale(), (panel.getDragObject().getPosition().getY()) - (panel.getLastClickPosition().getY() - clickPoint.getY()) / panel.getDragObject().getScale()));
|
||||||
|
panel.checkCollision();
|
||||||
|
break;
|
||||||
|
case "upperLeft":
|
||||||
|
if (clickPoint.getX() < panel.getDragObject().getPosition().getX() && clickPoint.getY() < panel.getDragObject().getPosition().getY())
|
||||||
|
{
|
||||||
|
resizeBigger();
|
||||||
|
}
|
||||||
|
else if (clickPoint.getX() > panel.getDragObject().getPosition().getX() && clickPoint.getY() > panel.getDragObject().getPosition().getY())
|
||||||
|
{
|
||||||
|
resizeSmaller(clickPoint);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "upperRight":
|
||||||
|
if (clickPoint.getX() > panel.getDragObject().getRectangle().getX() + panel.getDragObject().getRectangle().getWidth() && clickPoint.getY() < panel.getDragObject().getRectangle().getY())
|
||||||
|
{
|
||||||
|
resizeBigger();
|
||||||
|
}
|
||||||
|
else if (clickPoint.getX() < panel.getDragObject().getRectangle().getX() + panel.getDragObject().getRectangle().getWidth() && clickPoint.getY() > panel.getDragObject().getRectangle().getY())
|
||||||
|
{
|
||||||
|
resizeSmaller(clickPoint);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "bottomLeft":
|
||||||
|
if (clickPoint.getX() < panel.getDragObject().getRectangle().getX() && clickPoint.getY() > panel.getDragObject().getRectangle().getY() + panel.getDragObject().getRectangle().getHeight())
|
||||||
|
{
|
||||||
|
resizeBigger();
|
||||||
|
}
|
||||||
|
else if (clickPoint.getX() > panel.getDragObject().getRectangle().getX() && clickPoint.getY() < panel.getDragObject().getRectangle().getY() + panel.getDragObject().getRectangle().getHeight())
|
||||||
|
{
|
||||||
|
resizeSmaller(clickPoint);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "bottomRight":
|
||||||
|
if (clickPoint.getX() > panel.getDragObject().getRectangle().getX() + panel.getDragObject().getRectangle().getWidth() && clickPoint.getY() > panel.getDragObject().getRectangle().getY() + panel.getDragObject().getRectangle().getHeight())
|
||||||
|
{
|
||||||
|
resizeBigger();
|
||||||
|
}
|
||||||
|
else if (clickPoint.getX() < panel.getDragObject().getRectangle().getX() + panel.getDragObject().getRectangle().getWidth() && clickPoint.getY() < panel.getDragObject().getRectangle().getY() + panel.getDragObject().getRectangle().getHeight())
|
||||||
|
{
|
||||||
|
resizeSmaller(clickPoint);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "rotate":
|
||||||
|
double tempval = panel.getDragObject().getRotation() - (panel.getLastClickPosition().getX() - clickPoint.getX());
|
||||||
|
panel.getDragObject().setRotation(tempval);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
panel.repaint();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
panel.setCameraPoint(new Point2D.Double(
|
panel.setCameraPoint(new Point2D.Double(panel.getCameraPoint().getX() + (panel.getLastMousePosition().getX() - e.getX()), panel.getCameraPoint().getY() + (panel.getLastMousePosition().getY() - e.getY())));
|
||||||
panel.getCameraPoint().getX() + (panel.getLastMousePosition().getX() - e.getX()),
|
|
||||||
panel.getCameraPoint().getY() + (panel.getLastMousePosition().getY() - e.getY())
|
|
||||||
));
|
|
||||||
panel.repaint();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
panel.repaint();
|
||||||
panel.setLastMousePosition(e.getPoint());
|
panel.setLastMousePosition(e.getPoint());
|
||||||
panel.setLastClickPosition(clickPoint);
|
panel.setLastClickPosition(clickPoint);
|
||||||
|
panel.getPP().update();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseMoved(MouseEvent e) {
|
||||||
|
if(panel.getClickedOption().equals("Path"))
|
||||||
|
panel.getCurrentPath().setTempPoint(panel.getClickPoint(e.getPoint()));
|
||||||
|
panel.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resizeBigger()
|
||||||
|
{
|
||||||
|
double scale = panel.getDragObject().getScale()*1 + 0.02;
|
||||||
|
panel.getDragObject().setScale(scale);
|
||||||
|
panel.getDragObject().setPosition(new Point2D.Double(panel.getDragObject().getPosition().getX() -2, panel.getDragObject().getPosition().getY() - 2));
|
||||||
|
panel.checkCollision();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resizeSmaller(Point2D clickPoint)
|
||||||
|
{
|
||||||
|
System.out.println(clickPoint.getX());
|
||||||
|
if (panel.getDragObject().getScale() > 0.2)
|
||||||
|
{
|
||||||
|
double scale = panel.getDragObject().getScale()*1 - 0.02;
|
||||||
|
panel.getDragObject().setScale(scale);
|
||||||
|
panel.getDragObject().setPosition(new Point2D.Double(panel.getDragObject().getPosition().getX() +2, panel.getDragObject().getPosition().getY() +2 ));
|
||||||
|
panel.checkCollision();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
package Listeners;
|
package Listeners;
|
||||||
|
|
||||||
|
import java.awt.Point;
|
||||||
import java.awt.event.MouseWheelEvent;
|
import java.awt.event.MouseWheelEvent;
|
||||||
import java.awt.event.MouseWheelListener;
|
import java.awt.event.MouseWheelListener;
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
|
|
||||||
import Applicatie.DrawObject;
|
|
||||||
import Applicatie.Panel;
|
import Applicatie.Panel;
|
||||||
|
import Objects.DrawObject;
|
||||||
|
|
||||||
public class MouseWheel implements MouseWheelListener {
|
public class MouseWheel implements MouseWheelListener
|
||||||
|
{
|
||||||
private Panel panel;
|
private Panel panel;
|
||||||
private int scrollfactor;
|
private int scrollfactor;
|
||||||
|
|
||||||
@@ -17,49 +19,44 @@ public class MouseWheel implements MouseWheelListener {
|
|||||||
scrollfactor = 20;
|
scrollfactor = 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mouseWheelMoved(MouseWheelEvent e) {
|
public void mouseWheelMoved(MouseWheelEvent e)
|
||||||
Point2D clickPoint = panel.getClickPoint(e.getPoint());
|
{
|
||||||
for(DrawObject o : panel.getObjects())
|
if (e.getY() < 150)
|
||||||
{
|
|
||||||
if(o.contains(clickPoint))
|
|
||||||
{
|
|
||||||
double scale = o.getScale()* 1 + (e.getPreciseWheelRotation()/10.0);
|
|
||||||
o.setScale(scale);
|
|
||||||
panel.repaint();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(e.getY() < 150)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
if(e.getPreciseWheelRotation() < 0)
|
if (e.getPreciseWheelRotation() < 0)
|
||||||
{
|
{
|
||||||
if(panel.getScrollfactor() + scrollfactor + panel.getPanelInfoLength() < panel.getWidth())
|
if (panel.getScrollfactor() + scrollfactor + panel.getPanelInfoLength() < panel.getWidth())
|
||||||
{
|
{
|
||||||
panel.setScrollfactor(panel.getScrollfactor() + scrollfactor);
|
panel.setScrollfactor(panel.getScrollfactor() + scrollfactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if(panel.getScrollfactor() - scrollfactor >= 0)
|
if (panel.getScrollfactor() - scrollfactor >= 0)
|
||||||
{
|
{
|
||||||
panel.setScrollfactor(panel.getScrollfactor() - scrollfactor);
|
panel.setScrollfactor(panel.getScrollfactor() - scrollfactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// cameraPoint
|
// cameraPoint
|
||||||
double cameraScale = panel.getCameraScale() * 1 - (e.getPreciseWheelRotation()/10);
|
double cameraScale = panel.getCameraScale() * 1 - (e.getPreciseWheelRotation() / 10);
|
||||||
panel.setCameraScale((float) cameraScale);
|
if (cameraScale >= 0.1 && cameraScale < 4)
|
||||||
|
{
|
||||||
|
panel.setCameraScale((float) cameraScale);
|
||||||
|
//panel.setCameraPoint(new Point2D.Double(e.getX()-(panel.getWidth()/2)-panel.getCameraPoint().getX(), e.getY()-(panel.getHeight()/2) - panel.getCameraPoint().getY()));
|
||||||
|
//panel.setCameraPoint( new Point2D.Double(
|
||||||
|
// -panel.getClickPoint(new Point(e.getX(), e.getY())).getX(),
|
||||||
|
// -panel.getClickPoint(new Point(e.getX(), e.getY())).getY()
|
||||||
|
// ));
|
||||||
|
//TODO FIX
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
panel.repaint();
|
panel.repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,350 @@
|
|||||||
|
package Objects;
|
||||||
|
|
||||||
|
import java.awt.BasicStroke;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Image;
|
||||||
|
import java.awt.Shape;
|
||||||
|
import java.awt.geom.AffineTransform;
|
||||||
|
import java.awt.geom.Ellipse2D;
|
||||||
|
import java.awt.geom.NoninvertibleTransformException;
|
||||||
|
import java.awt.geom.Point2D;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
|
||||||
|
import Applicatie.Images;
|
||||||
|
|
||||||
|
public abstract class DrawObject implements Serializable
|
||||||
|
{
|
||||||
|
Point2D position;
|
||||||
|
double rotation;
|
||||||
|
double scale;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
// private Image image;
|
||||||
|
protected boolean selected;
|
||||||
|
private String filename;
|
||||||
|
|
||||||
|
protected int areaTop;
|
||||||
|
protected int areaBottom;
|
||||||
|
protected int areaLeft;
|
||||||
|
protected int areaRight;
|
||||||
|
|
||||||
|
private Rectangle2D rektAngle;
|
||||||
|
private Rectangle2D upperLeftCorner;
|
||||||
|
private Rectangle2D upperRightCorner;
|
||||||
|
private Rectangle2D bottomLeftCorner;
|
||||||
|
private Rectangle2D bottomRightCorner;
|
||||||
|
private Ellipse2D rotateDot;
|
||||||
|
|
||||||
|
static final int UPPERLEFT = 0;
|
||||||
|
static final int UPPERRIGHT = 1;
|
||||||
|
static final int BOTTOMLEFT = 2;
|
||||||
|
static final int BOTTOMRIGHT = 3;
|
||||||
|
private Color rectangleColor;
|
||||||
|
|
||||||
|
public DrawObject(String filename, Point2D position)
|
||||||
|
{
|
||||||
|
// image = new ImageIcon(filename).getImage();
|
||||||
|
|
||||||
|
Image image = Images.getImage(filename);
|
||||||
|
width = image.getWidth(null);
|
||||||
|
height = image.getHeight(null);
|
||||||
|
this.filename = filename;
|
||||||
|
scale = 1;
|
||||||
|
rotation = 0;
|
||||||
|
this.position = position;
|
||||||
|
rectangleColor = Color.BLACK;
|
||||||
|
|
||||||
|
areaTop = 0;
|
||||||
|
areaBottom = 0;
|
||||||
|
areaLeft = 0;
|
||||||
|
areaRight = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract String getName();
|
||||||
|
|
||||||
|
public void draw(Graphics2D g)
|
||||||
|
{
|
||||||
|
AffineTransform tx = getTransform();
|
||||||
|
Image image = Images.getImage(filename);
|
||||||
|
g.drawImage(image, tx, null);
|
||||||
|
if (selected)
|
||||||
|
{
|
||||||
|
// g.rotate(Math.toRadians(rotation), width/2,
|
||||||
|
// height/2);
|
||||||
|
AffineTransform rotate = AffineTransform.getRotateInstance(Math.toRadians(rotation), position.getX() + image.getWidth(null) / 2, position.getY() + image.getHeight(null) / 2);
|
||||||
|
// g.transform(rotate);
|
||||||
|
g.setColor(rectangleColor);
|
||||||
|
g.setStroke(new BasicStroke(7));
|
||||||
|
rektAngle = new Rectangle2D.Double((int) position.getX() - areaLeft, (int) position.getY() - areaTop, width + areaLeft + areaRight, height + areaTop + areaBottom);
|
||||||
|
tx = getTransformRectangle();
|
||||||
|
rektAngle.setFrame(tx.createTransformedShape(rektAngle).getBounds());
|
||||||
|
g.draw(rektAngle);
|
||||||
|
g.setColor(Color.YELLOW);
|
||||||
|
upperLeftCorner = new Rectangle2D.Double(rektAngle.getX() - 7, rektAngle.getY() - 7, 15, 15);
|
||||||
|
upperRightCorner = new Rectangle2D.Double(rektAngle.getX() + rektAngle.getWidth() - 8, rektAngle.getY() - 7, 15, 15);
|
||||||
|
bottomLeftCorner = new Rectangle2D.Double(rektAngle.getX() - 7, rektAngle.getY() + rektAngle.getHeight() - 8, 15, 15);
|
||||||
|
bottomRightCorner = new Rectangle2D.Double(rektAngle.getX() + rektAngle.getWidth() - 8, rektAngle.getY() + rektAngle.getHeight() - 8, 15, 15);
|
||||||
|
g.fill(upperLeftCorner); // upperleft
|
||||||
|
g.fill(upperRightCorner); // upperright
|
||||||
|
g.fill(bottomLeftCorner); // bottomleft
|
||||||
|
g.fill(bottomRightCorner); // bottomright
|
||||||
|
g.setColor(Color.RED);
|
||||||
|
rotateDot = new Ellipse2D.Double((rektAngle.getX() + (rektAngle.getWidth() / 2)) - 8, rektAngle.getY() - 8, 15, 15);
|
||||||
|
g.fill(rotateDot);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected AffineTransform getTransform()
|
||||||
|
{
|
||||||
|
AffineTransform tx = new AffineTransform();
|
||||||
|
tx.scale(scale, scale);
|
||||||
|
tx.translate(position.getX(), position.getY());
|
||||||
|
tx.rotate(Math.toRadians(rotation), (width + areaLeft + areaRight) / 2, (height + areaTop + areaBottom) / 2);
|
||||||
|
return tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected AffineTransform getTransformSelection()
|
||||||
|
{
|
||||||
|
AffineTransform tx = new AffineTransform();
|
||||||
|
tx.scale(scale, scale);
|
||||||
|
tx.translate(position.getX(), position.getY());
|
||||||
|
return tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Special transformation for the selection rectangle, because the
|
||||||
|
* translation of the image one places the rectangle translated from the
|
||||||
|
* image.
|
||||||
|
*
|
||||||
|
* @return affineTransform
|
||||||
|
*/
|
||||||
|
private AffineTransform getTransformRectangle()
|
||||||
|
{
|
||||||
|
AffineTransform tx = new AffineTransform();
|
||||||
|
tx.scale(scale, scale);
|
||||||
|
return tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(Point2D clickPoint)
|
||||||
|
{
|
||||||
|
Shape shape;
|
||||||
|
if (rektAngle == null)
|
||||||
|
{
|
||||||
|
shape = new Rectangle2D.Double(0 - areaLeft, 0 - areaTop, width + areaLeft + areaRight, height + areaTop + areaBottom);
|
||||||
|
return getTransform().createTransformedShape(shape).contains(clickPoint);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shape = new Rectangle2D.Double(-9 - areaLeft, -9 - areaTop, width + 13 + areaLeft + areaRight, height + 13 + areaTop + areaBottom);
|
||||||
|
return getTransformSelection().createTransformedShape(shape).contains(clickPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point2D getObjectPoint(Point2D point)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return getTransform().inverseTransform(point, null);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (NoninvertibleTransformException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checking collision.
|
||||||
|
*
|
||||||
|
* @param object
|
||||||
|
* . the drawObject to check collision with.
|
||||||
|
* @return if there is a collision.
|
||||||
|
*/
|
||||||
|
public boolean collision(DrawObject object)
|
||||||
|
{
|
||||||
|
Shape ownShape = getRectangle();
|
||||||
|
Rectangle2D otherRectangle = object.getTransform().createTransformedShape(object.getImageRectangle()).getBounds2D();
|
||||||
|
if(ownShape != null && otherRectangle != null) {
|
||||||
|
if (ownShape.intersects(otherRectangle))
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method checks if the place thats clicked is inside one of the
|
||||||
|
* corners.
|
||||||
|
*
|
||||||
|
* @param point
|
||||||
|
* @param corner
|
||||||
|
* @return if the clicked point is inside one of the corners
|
||||||
|
*/
|
||||||
|
public boolean containsCorner(Point2D point, int corner)
|
||||||
|
{
|
||||||
|
Rectangle2D chosenCorner = null;
|
||||||
|
switch (corner)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
chosenCorner = upperLeftCorner;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
chosenCorner = upperRightCorner;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
chosenCorner = bottomLeftCorner;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
chosenCorner = bottomRightCorner;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
if (point.getX() > rotateDot.getX() && point.getX() < rotateDot.getX() + rotateDot.getWidth() && point.getY() > rotateDot.getY() && point.getY() < rotateDot.getY() + rotateDot.getHeight())
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (point.getX() > chosenCorner.getX() && point.getX() < chosenCorner.getX() + chosenCorner.getWidth() && point.getY() > chosenCorner.getY() && point.getY() < chosenCorner.getY() + chosenCorner.getHeight())
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelected(boolean b)
|
||||||
|
{
|
||||||
|
selected = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point2D getPosition()
|
||||||
|
{
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPosition(Point2D position)
|
||||||
|
{
|
||||||
|
this.position = position;
|
||||||
|
}
|
||||||
|
public void setPosition(Point2D position, boolean b)
|
||||||
|
{
|
||||||
|
this.position = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getRotation()
|
||||||
|
{
|
||||||
|
return rotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRotation(double rotation)
|
||||||
|
{
|
||||||
|
this.rotation = rotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getScale()
|
||||||
|
{
|
||||||
|
return scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScale(double scale)
|
||||||
|
{
|
||||||
|
this.scale = scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSelected()
|
||||||
|
{
|
||||||
|
return selected;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rectangle2D getRectangle()
|
||||||
|
{
|
||||||
|
return rektAngle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRectangle(Rectangle2D rectangle)
|
||||||
|
{
|
||||||
|
rektAngle = rectangle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color getRectangleColor()
|
||||||
|
{
|
||||||
|
return rectangleColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRectangleColor(Color rectangleColor)
|
||||||
|
{
|
||||||
|
this.rectangleColor = rectangleColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rectangle2D getImageRectangle()
|
||||||
|
{
|
||||||
|
Image image = Images.getImage(filename);
|
||||||
|
return new Rectangle2D.Double(0, 0, image.getWidth(null), image.getHeight(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAreaTop()
|
||||||
|
{
|
||||||
|
return areaTop;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAreaTop(int areaTop)
|
||||||
|
{
|
||||||
|
this.areaTop = areaTop;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAreaBottom()
|
||||||
|
{
|
||||||
|
return areaBottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAreaBottom(int areaBottom)
|
||||||
|
{
|
||||||
|
this.areaBottom = areaBottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAreaLeft()
|
||||||
|
{
|
||||||
|
return areaLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAreaLeft(int areaLeft)
|
||||||
|
{
|
||||||
|
this.areaLeft = areaLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAreaRight()
|
||||||
|
{
|
||||||
|
return areaRight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAreaRight(int areaRight)
|
||||||
|
{
|
||||||
|
this.areaRight = areaRight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEndX()
|
||||||
|
{
|
||||||
|
Image image = Images.getImage(filename);
|
||||||
|
return (int) (position.getX() + image.getWidth(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEndY()
|
||||||
|
{
|
||||||
|
Image image = Images.getImage(filename);
|
||||||
|
return (int) (position.getY() + image.getHeight(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileName()
|
||||||
|
{
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,13 +1,52 @@
|
|||||||
package Objects;
|
package Objects;
|
||||||
|
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
|
|
||||||
import Applicatie.DrawObject;
|
import Applicatie.Panel;
|
||||||
|
|
||||||
|
public class Entrance extends DrawObject
|
||||||
|
{
|
||||||
|
|
||||||
public class Entrance extends DrawObject {
|
public Entrance(Point2D position)
|
||||||
|
{
|
||||||
public Entrance(Point2D position) {
|
super("entrance", position);
|
||||||
super("images/entrance.png", position);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
@Override
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package Objects;
|
||||||
|
import java.awt.geom.Point2D;
|
||||||
|
|
||||||
|
|
||||||
|
public class Food extends DrawObject {
|
||||||
|
|
||||||
|
public Food(Point2D position) {
|
||||||
|
super("food", position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return "Food";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package Objects;
|
||||||
|
|
||||||
|
import java.awt.geom.Point2D;
|
||||||
|
|
||||||
|
public class OldPath extends DrawObject
|
||||||
|
{
|
||||||
|
|
||||||
|
public OldPath(Point2D position)
|
||||||
|
{
|
||||||
|
super("path", position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return "Path";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,13 +1,198 @@
|
|||||||
package Objects;
|
package Objects;
|
||||||
|
|
||||||
|
import java.awt.BasicStroke;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Shape;
|
||||||
|
import java.awt.TexturePaint;
|
||||||
|
import java.awt.geom.Line2D;
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import Applicatie.DrawObject;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
|
import Applicatie.Panel;
|
||||||
|
import Applicatie.Waypoint;
|
||||||
|
|
||||||
public class Path extends DrawObject {
|
/**
|
||||||
|
* Create's a path.
|
||||||
|
*
|
||||||
|
* @author Wesley de Hek
|
||||||
|
* @version 1.2
|
||||||
|
*/
|
||||||
|
public class Path
|
||||||
|
{
|
||||||
|
|
||||||
public Path(Point2D position) {
|
private ArrayList<Point2D> points;
|
||||||
super("images/path.jpg", position);
|
private ArrayList<Shape> lines;
|
||||||
|
private Point2D tempPoint;
|
||||||
|
private BufferedImage pathBackground;
|
||||||
|
private ArrayList<Waypoint> waypoints;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*/
|
||||||
|
public Path()
|
||||||
|
{
|
||||||
|
points = new ArrayList<>();
|
||||||
|
lines = new ArrayList<>();
|
||||||
|
waypoints = new ArrayList<Waypoint>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
pathBackground = ImageIO.read(new File("images/newPath.png"));
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* Draws the path.
|
||||||
|
*
|
||||||
|
* @param g2
|
||||||
|
* - the Graphics2D object.
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
Point2D point = points.get(i);
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
* @return if the path contains the 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()
|
||||||
|
{
|
||||||
|
lines.clear();
|
||||||
|
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);
|
||||||
|
lines.add(stroke.createStrokedShape(line));
|
||||||
|
}
|
||||||
|
return lines;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addWaypoint(int i, Panel panel)
|
||||||
|
{
|
||||||
|
for (Waypoint w : panel.getWaypoints())
|
||||||
|
{
|
||||||
|
if (w.getSelf() == i)
|
||||||
|
{
|
||||||
|
waypoints.add(w);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a point to the path.
|
||||||
|
*
|
||||||
|
* @param point
|
||||||
|
* - the point you want the path to pass.
|
||||||
|
*/
|
||||||
|
public void addPoint(Point2D point)
|
||||||
|
{
|
||||||
|
points.add(point);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all the path points.
|
||||||
|
*
|
||||||
|
* @return all the points of the path.
|
||||||
|
*/
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
public void setTempPoint(Point2D point)
|
||||||
|
{
|
||||||
|
tempPoint = point;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package Objects;
|
|
||||||
import java.awt.geom.Point2D;
|
|
||||||
|
|
||||||
import Applicatie.DrawObject;
|
|
||||||
|
|
||||||
|
|
||||||
public class Podium extends DrawObject {
|
|
||||||
|
|
||||||
public Podium(Point2D position) {
|
|
||||||
super("images/stage3.png", position);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package Objects;
|
||||||
|
|
||||||
|
import java.awt.geom.Point2D;
|
||||||
|
|
||||||
|
import Agenda.AgendaStage;
|
||||||
|
|
||||||
|
public class Stage extends DrawObject
|
||||||
|
{
|
||||||
|
AgendaStage stage;
|
||||||
|
|
||||||
|
public Stage(Point2D position, AgendaStage st)
|
||||||
|
{
|
||||||
|
super("stage", position);
|
||||||
|
stage = st;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return "Stage";
|
||||||
|
}
|
||||||
|
|
||||||
|
public AgendaStage getStage()
|
||||||
|
{
|
||||||
|
return stage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStage(AgendaStage stage)
|
||||||
|
{
|
||||||
|
this.stage = stage;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,13 +1,19 @@
|
|||||||
package Objects;
|
package Objects;
|
||||||
|
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
|
|
||||||
import Applicatie.DrawObject;
|
public class Toilet extends DrawObject
|
||||||
|
{
|
||||||
|
|
||||||
|
public Toilet(Point2D position)
|
||||||
|
{
|
||||||
|
super("wc", position);
|
||||||
|
}
|
||||||
|
|
||||||
public class Toilet extends DrawObject {
|
@Override
|
||||||
|
public String getName()
|
||||||
public Toilet(Point2D position) {
|
{
|
||||||
super("images/wc.png", position);
|
return "Toilet";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,19 @@
|
|||||||
package Objects;
|
package Objects;
|
||||||
|
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
|
|
||||||
import Applicatie.DrawObject;
|
public class Wall extends DrawObject
|
||||||
|
{
|
||||||
|
|
||||||
|
public Wall(Point2D position)
|
||||||
public class Wall extends DrawObject {
|
{
|
||||||
|
super("wall", position);
|
||||||
public Wall(Point2D position) {
|
|
||||||
super("images/wall.png", position);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
@Override
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return "Wall";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 972 B |
|
Before Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 494 KiB |
|
Before Width: | Height: | Size: 972 B |
|
Before Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 494 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 46 KiB |
|
Before Width: | Height: | Size: 8.7 KiB |
|
Before Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 737 B |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 7.8 KiB |
|
Before Width: | Height: | Size: 4.0 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 46 KiB |
|
Before Width: | Height: | Size: 8.7 KiB |
|
Before Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 737 B |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 7.8 KiB |
|
Before Width: | Height: | Size: 4.0 KiB |