Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70b1dba047 | ||
|
|
80a934ebb3 | ||
|
|
b94c913472 | ||
|
|
e985dbe537 | ||
|
|
0a2c7ed67c | ||
|
|
5aaf23e346 | ||
|
|
558cf0ea5c |
@@ -0,0 +1,113 @@
|
|||||||
|
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(EXIT_ON_CLOSE);
|
||||||
|
JPanel content = new JPanel(new BorderLayout());
|
||||||
|
JPanel south = new JPanel(new FlowLayout());
|
||||||
|
JPanel center = new JPanel(new GridLayout(4,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: ");
|
||||||
|
panel5.add(image);
|
||||||
|
center.add(panel5);
|
||||||
|
|
||||||
|
JPanel panel6 = new JPanel();
|
||||||
|
JTextField imageTF = new JTextField("", 15);
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
boolean alreadyExists = false;
|
||||||
|
for (Artist artist : agenda.artists)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
agenda.addArtist(a);
|
||||||
|
JOptionPane.showMessageDialog(null, "Artist added!");
|
||||||
|
setVisible(false);
|
||||||
|
dispose();
|
||||||
|
} else {
|
||||||
|
JOptionPane.showMessageDialog(null, "Choose a different artist name!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
setContentPane(content);
|
||||||
|
setVisible(true);
|
||||||
|
setSize(500,320);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,289 @@
|
|||||||
|
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.JComboBox;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
|
|
||||||
|
public class AddEventPanel extends JFrame{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1;
|
||||||
|
|
||||||
|
public AddEventPanel(Agenda agenda)
|
||||||
|
{
|
||||||
|
super("Event addscreen!");
|
||||||
|
setDefaultCloseOperation(EXIT_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("",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);
|
||||||
|
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);
|
||||||
|
panel4.add(minute);
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
panel4.add(day);
|
||||||
|
|
||||||
|
String[] months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
|
||||||
|
JComboBox<String> month = new JComboBox<String>(months);
|
||||||
|
panel4.add(month);
|
||||||
|
|
||||||
|
|
||||||
|
Integer[] years = { 2015,2016,2017};
|
||||||
|
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);
|
||||||
|
JPanel panel6 = new JPanel();
|
||||||
|
panel6.add(hourE);
|
||||||
|
center.add(panel6);
|
||||||
|
|
||||||
|
JComboBox<Integer> minuteE = new JComboBox<Integer>(minutes);
|
||||||
|
panel6.add(minuteE);
|
||||||
|
|
||||||
|
|
||||||
|
JComboBox<Integer> dayE = new JComboBox<Integer>(days);
|
||||||
|
panel6.add(dayE);
|
||||||
|
|
||||||
|
JComboBox<String> monthE = new JComboBox<String>(months);
|
||||||
|
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.artists.size()];
|
||||||
|
|
||||||
|
for ( int idx = 0; idx < agenda.artists.size(); idx ++)
|
||||||
|
{
|
||||||
|
artists[idx] = agenda.artists.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.stages.size()];
|
||||||
|
|
||||||
|
for ( int idx = 0; idx < agenda.stages.size(); idx ++)
|
||||||
|
{
|
||||||
|
artists[idx] = agenda.stages.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();
|
||||||
|
String monthS = (String) month.getSelectedItem();
|
||||||
|
int yearS = year.getSelectedIndex();
|
||||||
|
|
||||||
|
int hourEnd = hourE.getSelectedIndex();
|
||||||
|
int minuteEnd = minuteE.getSelectedIndex();
|
||||||
|
int dayEnd = dayE.getSelectedIndex();
|
||||||
|
String monthEnd = (String) monthE.getSelectedItem();
|
||||||
|
int yearEnd = yearE.getSelectedIndex();
|
||||||
|
|
||||||
|
String artistName = (String)artist.getSelectedItem();
|
||||||
|
|
||||||
|
Artist artist = null;
|
||||||
|
|
||||||
|
for(Artist a : agenda.artists)
|
||||||
|
{
|
||||||
|
if (a.getName().equals(artistName))
|
||||||
|
{
|
||||||
|
artist = a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String stageName = (String)stage2.getSelectedItem();
|
||||||
|
|
||||||
|
Stage stage = null;
|
||||||
|
|
||||||
|
for(Stage s : agenda.stages)
|
||||||
|
{
|
||||||
|
if (s.getName().equals(stageName))
|
||||||
|
{
|
||||||
|
stage = s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String description = descriptionTF.getText();
|
||||||
|
|
||||||
|
int popularity = ep.getSelectedIndex();
|
||||||
|
|
||||||
|
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!");
|
||||||
|
} 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
setContentPane(content);
|
||||||
|
setVisible(true);
|
||||||
|
setSize(640,320);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int monthToInt(String month)
|
||||||
|
{
|
||||||
|
int number = 0;
|
||||||
|
switch (month)
|
||||||
|
{
|
||||||
|
case "January": number = 0; break;
|
||||||
|
case "February": number = 1; break;
|
||||||
|
case "March": number = 2; break;
|
||||||
|
case "April": number = 3; break;
|
||||||
|
case "May": number = 4; break;
|
||||||
|
case "June":number = 5; break;
|
||||||
|
case "July": number = 6; break;
|
||||||
|
case "August": number = 7; break;
|
||||||
|
case "September":number = 8; break;
|
||||||
|
case "October": number = 9; break;
|
||||||
|
case "November": number = 10; break;
|
||||||
|
case "December": number = 11; 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,92 @@
|
|||||||
|
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!");
|
||||||
|
agenda.addStage(new Stage("mainstage", "niks"));
|
||||||
|
setDefaultCloseOperation(EXIT_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 (Stage stage : agenda.stages)
|
||||||
|
{
|
||||||
|
if (stage.getName().equals(name))
|
||||||
|
{
|
||||||
|
alreadyExists = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (name.isEmpty()){
|
||||||
|
JOptionPane.showMessageDialog(null, "Fill in a correct name!");
|
||||||
|
}
|
||||||
|
else if ( alreadyExists == false )
|
||||||
|
{
|
||||||
|
Stage s = new Stage(name,description);
|
||||||
|
agenda.addStage(s);
|
||||||
|
JOptionPane.showMessageDialog(null, "Stage added!");
|
||||||
|
setVisible(false);
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
JOptionPane.showMessageDialog(null, "Choose a different stage name!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
setContentPane(content);
|
||||||
|
setVisible(true);
|
||||||
|
setSize(400,180);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -8,6 +8,10 @@ import java.io.ObjectOutputStream;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.filechooser.FileFilter;
|
||||||
|
|
||||||
public class Agenda implements Serializable {
|
public class Agenda implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1;
|
private static final long serialVersionUID = 1;
|
||||||
@@ -22,7 +26,7 @@ public class Agenda implements Serializable {
|
|||||||
artists = new ArrayList<Artist>();
|
artists = new ArrayList<Artist>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addStage(Stage stage) {
|
public void addStage(Stage stage){
|
||||||
stages.add(stage);
|
stages.add(stage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,34 +38,93 @@ public class Agenda implements Serializable {
|
|||||||
artists.add(artist);
|
artists.add(artist);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fillArtists() {
|
public void saveAgenda()
|
||||||
FileInputStream fis = null;
|
{
|
||||||
ObjectInputStream ois = null;
|
JFileChooser fileChooser = new JFileChooser();
|
||||||
|
|
||||||
try {
|
fileChooser.setFileFilter(new FileFilter() {
|
||||||
fis = new FileInputStream("artists.dat");
|
@Override
|
||||||
ois = new ObjectInputStream(fis);
|
public boolean accept(File pathname) {
|
||||||
|
if(pathname.isFile() && pathname.getName().endsWith(".dat"))
|
||||||
Object object;
|
{
|
||||||
object = ois.readObject();
|
return true;
|
||||||
try {
|
}else if(pathname.isDirectory()){return true;}else{return false;}
|
||||||
while (object != null) {
|
|
||||||
artists.add((Artist) object);
|
|
||||||
object = ois.readObject();
|
|
||||||
}
|
}
|
||||||
} catch (EOFException e) {
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return ".dat";
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
fileChooser.setDialogTitle("Choose save location");
|
||||||
|
int userSelection = fileChooser.showSaveDialog(null);
|
||||||
|
|
||||||
|
if(userSelection == JFileChooser.APPROVE_OPTION)
|
||||||
|
{
|
||||||
|
File file = fileChooser.getSelectedFile();
|
||||||
|
if(!file.getName().endsWith(".dat"))
|
||||||
|
{
|
||||||
|
file = new File(file.getAbsolutePath() + ".dat");
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fillEvents() {
|
public void loadAgenda()
|
||||||
|
{
|
||||||
|
JFileChooser fileChooser = new JFileChooser();
|
||||||
|
fileChooser.setFileFilter(new FileFilter() {
|
||||||
|
@Override
|
||||||
|
public boolean accept(File pathname) {
|
||||||
|
if(pathname.isFile() && pathname.getName().endsWith(".dat"))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}else if(pathname.isDirectory()){return true;}else{return false;}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return ".dat";
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
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
|
||||||
|
{
|
||||||
|
fillAgenda(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillAgenda(File file) {
|
||||||
FileInputStream fis = null;
|
FileInputStream fis = null;
|
||||||
ObjectInputStream ois = null;
|
ObjectInputStream ois = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fis = new FileInputStream("events.dat");
|
|
||||||
|
fis = new FileInputStream(file);
|
||||||
ois = new ObjectInputStream(fis);
|
ois = new ObjectInputStream(fis);
|
||||||
|
|
||||||
Object object;
|
Object object;
|
||||||
@@ -79,53 +142,45 @@ public class Agenda implements Serializable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fillStages() {
|
public void fillArtists()
|
||||||
FileInputStream fis = null;
|
{
|
||||||
ObjectInputStream ois = null;
|
for (Event e : events)
|
||||||
|
{
|
||||||
try {
|
boolean exists = false;
|
||||||
fis = new FileInputStream("stages.dat");
|
String name = e.getArtist().getName();
|
||||||
ois = new ObjectInputStream(fis);
|
for (Artist a : artists)
|
||||||
|
{
|
||||||
Object object;
|
if ( a.getName().equals(name) ) {
|
||||||
object = ois.readObject();
|
exists = true;
|
||||||
try {
|
|
||||||
while (object != null) {
|
|
||||||
stages.add((Stage) object);
|
|
||||||
object = ois.readObject();
|
|
||||||
}
|
}
|
||||||
} catch (EOFException e) {
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
if ( exists == false) {
|
||||||
e.printStackTrace();
|
addArtist(e.getArtist());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveStages() {
|
public void fillStages()
|
||||||
|
{
|
||||||
try {
|
for (Event e : events)
|
||||||
File file = new File("stages.dat");
|
{
|
||||||
if (!file.exists()){
|
boolean exists = false;
|
||||||
file.createNewFile();
|
String name = e.getStage().getName();
|
||||||
|
for (Stage s : stages)
|
||||||
|
{
|
||||||
|
if ( s.getName().equals(name) ) {
|
||||||
|
exists = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
FileOutputStream fos = new FileOutputStream(file);
|
if ( exists == false) {
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
addStage(e.getStage());
|
||||||
for (Stage stage : stages) {
|
|
||||||
oos.writeObject(stage);
|
|
||||||
}
|
}
|
||||||
oos.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveEvents() {
|
public void saveAgenda(File file) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File file = new File("events.dat");
|
|
||||||
if (!file.exists()){
|
|
||||||
file.createNewFile();
|
|
||||||
}
|
|
||||||
FileOutputStream fos = new FileOutputStream(file);
|
FileOutputStream fos = new FileOutputStream(file);
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||||
for (Event event : events) {
|
for (Event event : events) {
|
||||||
@@ -137,52 +192,23 @@ public class Agenda implements Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveArtists() {
|
public void clearAgenda()
|
||||||
|
{
|
||||||
try {
|
events.clear();
|
||||||
File file = new File("artists.dat");
|
|
||||||
if (!file.exists()){
|
|
||||||
file.createNewFile();
|
|
||||||
}
|
|
||||||
FileOutputStream fos = new FileOutputStream(file);
|
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
|
||||||
for (Artist artist : artists) {
|
|
||||||
oos.writeObject(artist);
|
|
||||||
}
|
|
||||||
oos.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addEvents()
|
public void fillAllLists()
|
||||||
{
|
{
|
||||||
int ID = 0;
|
loadAgenda();
|
||||||
for (Stage stage : stages)
|
|
||||||
{
|
|
||||||
ID = stage.getID();
|
|
||||||
for (Event event : events)
|
|
||||||
{
|
|
||||||
if ( ID == event.getID())
|
|
||||||
{
|
|
||||||
stage.addEvent(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saveAll()
|
|
||||||
{
|
|
||||||
saveArtists();
|
|
||||||
saveEvents();
|
|
||||||
saveStages();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void fillAll()
|
|
||||||
{
|
|
||||||
fillArtists();
|
|
||||||
fillEvents();
|
|
||||||
fillStages();
|
fillStages();
|
||||||
addEvents();
|
fillArtists();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
Agenda a = new Agenda();
|
||||||
|
a.fillAllLists();
|
||||||
|
|
||||||
|
System.out.println(a.events.get(0).getEventName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ public class Artist implements Serializable{
|
|||||||
|
|
||||||
if ( !image.equals("null")) {
|
if ( !image.equals("null")) {
|
||||||
this.image = new ImageIcon(image);
|
this.image = new ImageIcon(image);
|
||||||
} else {
|
|
||||||
this.image = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,25 +7,43 @@ public class Event implements Serializable {
|
|||||||
|
|
||||||
private static final long serialVersionUID = 1;
|
private static final long serialVersionUID = 1;
|
||||||
|
|
||||||
|
private String eventName;
|
||||||
private GregorianCalendar startDate;
|
private GregorianCalendar startDate;
|
||||||
private GregorianCalendar endDate;
|
private GregorianCalendar endDate;
|
||||||
private Artist artist;
|
private Artist artist;
|
||||||
|
private Stage stage;
|
||||||
private String description;
|
private String description;
|
||||||
private int expectedPopularity;
|
private int expectedPopularity;
|
||||||
private int ID;
|
|
||||||
|
|
||||||
public Event(int startYear, int startMonth, int startDay, int startHour,
|
public Event(String eventName, int startYear, int startMonth, int startDay,
|
||||||
int startMinute, int endYear, int endMonth, int endDay,
|
int startHour, int startMinute, int endYear, int endMonth,
|
||||||
int endHour, int endMinute, Artist artist, String description,
|
int endDay, int endHour, int endMinute, Artist artist, Stage stage,
|
||||||
int expectedPopularity, int ID) {
|
String description, int expectedPopularity) {
|
||||||
startDate = new GregorianCalendar(startYear, startMonth - 1, startDay,
|
this.eventName = eventName;
|
||||||
startHour, startMinute);
|
this.startDate = new GregorianCalendar(startYear, startMonth - 1,
|
||||||
endDate = new GregorianCalendar(endYear, endMonth - 1, endDay, endHour,
|
startDay, startHour, startMinute);
|
||||||
endMinute);
|
this.endDate = new GregorianCalendar(endYear, endMonth - 1, endDay,
|
||||||
|
endHour, endMinute);
|
||||||
|
this.stage = stage;
|
||||||
this.artist = artist;
|
this.artist = artist;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.expectedPopularity = expectedPopularity;
|
this.expectedPopularity = expectedPopularity;
|
||||||
this.ID = ID;
|
}
|
||||||
|
|
||||||
|
public Event(String eventName, GregorianCalendar startDate,
|
||||||
|
GregorianCalendar endDate, Artist artist, Stage 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 String getEventName() {
|
||||||
|
return this.eventName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GregorianCalendar getStartDate() {
|
public GregorianCalendar getStartDate() {
|
||||||
@@ -44,25 +62,37 @@ public class Event implements Serializable {
|
|||||||
return this.description;
|
return this.description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getID() {
|
public Stage getStage() {
|
||||||
return this.ID;
|
return this.stage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getExpectedPopularity() {
|
public int getExpectedPopularity() {
|
||||||
return this.expectedPopularity;
|
return this.expectedPopularity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setEventName(String name) {
|
||||||
|
this.eventName = name;
|
||||||
|
}
|
||||||
|
|
||||||
public void setStartDate(int startYear, int startMonth, int startDay,
|
public void setStartDate(int startYear, int startMonth, int startDay,
|
||||||
int startHour, int startMinute) {
|
int startHour, int startMinute) {
|
||||||
startDate.set(startYear, startMonth - 1, startDay, startHour,
|
startDate.set(startYear, startMonth - 1, startDay, startHour,
|
||||||
startMinute);
|
startMinute);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setStartDate(GregorianCalendar startDate) {
|
||||||
|
this.startDate = startDate;
|
||||||
|
}
|
||||||
|
|
||||||
public void setEndDate(int endYear, int endMonth, int endDay, int endHour,
|
public void setEndDate(int endYear, int endMonth, int endDay, int endHour,
|
||||||
int endMinute) {
|
int endMinute) {
|
||||||
endDate.set(endYear, endMonth - 1, endDay, endHour, endMinute);
|
endDate.set(endYear, endMonth - 1, endDay, endHour, endMinute);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setEndDate(GregorianCalendar endDate) {
|
||||||
|
this.endDate = endDate;
|
||||||
|
}
|
||||||
|
|
||||||
public void setArtist(Artist artist) {
|
public void setArtist(Artist artist) {
|
||||||
this.artist.setName(artist.getName());
|
this.artist.setName(artist.getName());
|
||||||
this.artist.setGenre(artist.getGenre());
|
this.artist.setGenre(artist.getGenre());
|
||||||
@@ -78,8 +108,8 @@ public class Event implements Serializable {
|
|||||||
this.expectedPopularity = popularity;
|
this.expectedPopularity = popularity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setID(int ID) {
|
public void setStage(Stage stage) {
|
||||||
this.ID = ID;
|
this.stage = stage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|||||||
@@ -1,25 +1,21 @@
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
|
|
||||||
public class Stage implements Serializable {
|
public class Stage implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1;
|
private static final long serialVersionUID = 1;
|
||||||
|
|
||||||
private ArrayList<Event> events;
|
private String name;
|
||||||
private String description;
|
private String description;
|
||||||
private int ID;
|
|
||||||
|
|
||||||
public Stage(String description, int ID )
|
public Stage(String name, String description)
|
||||||
{
|
{
|
||||||
this.events = new ArrayList<Event>();
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.ID = ID;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Event getEvent(int number)
|
public String getName()
|
||||||
{
|
{
|
||||||
return events.get(number);
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription()
|
public String getDescription()
|
||||||
@@ -27,23 +23,13 @@ public class Stage implements Serializable {
|
|||||||
return this.description;
|
return this.description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getID()
|
|
||||||
{
|
|
||||||
return this.ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDescription(String description)
|
public void setDescription(String description)
|
||||||
{
|
{
|
||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setID(int ID)
|
public void setName(String name)
|
||||||
{
|
{
|
||||||
this.ID = ID;
|
this.name = name;
|
||||||
}
|
|
||||||
|
|
||||||
public void addEvent(Event event)
|
|
||||||
{
|
|
||||||
events.add(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user