diff --git a/Agenda.java b/Agenda.java deleted file mode 100644 index 34a9e88..0000000 --- a/Agenda.java +++ /dev/null @@ -1,211 +0,0 @@ -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 stages; - private ArrayList events; - private ArrayList artists; - - public Agenda() { - stages = new ArrayList(); - events = new ArrayList(); - artists = new ArrayList(); - } - - public void addStage(Stage stage){ - stages.add(stage); - } - - public void addEvent(Event event) { - events.add(event); - } - - public void addArtist(Artist artist) { - artists.add(artist); - } - - public ArrayList getEvents() - { - return events; - } - - 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 - { - fillAgenda(file); - } - } - } - - 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(); - try { - while (object != null) { - events.add((Event) object); - object = ois.readObject(); - } - } catch (EOFException e) { - } - } 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 (Stage 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); - for (Event event : events) { - oos.writeObject(event); - } - oos.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public void clearAgenda() - { - events.clear(); - } - - public void fillAllLists() - { - loadAgenda(); - fillStages(); - fillArtists(); - } -} diff --git a/ContentTable.java b/ContentTable.java deleted file mode 100644 index c80c1f9..0000000 --- a/ContentTable.java +++ /dev/null @@ -1,40 +0,0 @@ -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]; - } -} diff --git a/GUI.java b/GUI.java index 27e876d..df85891 100644 --- a/GUI.java +++ b/GUI.java @@ -1,7 +1,9 @@ +import java.awt.BorderLayout; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import javax.swing.JFrame; +import javax.swing.JPanel; public class GUI extends JFrame @@ -12,22 +14,32 @@ public class GUI extends JFrame { super("Gui"); this.setDefaultCloseOperation(EXIT_ON_CLOSE); + +// JPanel contentPane = new JPanel(new BorderLayout()); +// this.setContentPane(contentPane); +// this.setSize(600, 600); +// this.setVisible(true); +// System.out.println(contentPane.getWidth()); +// timeline = new Timeline(contentPane); +// contentPane.add(timeline,BorderLayout.CENTER); +// contentPane.add(timeline.createWestPanel(), BorderLayout.WEST); +// timeline.refresh(); + TimelinePanel panel = new TimelinePanel(); + this.setContentPane(panel); this.setSize(600, 600); - timeline = new Timeline(this); - - - this.setContentPane(timeline.getTimeline()); + this.setVisible(true); + this.getRootPane().addComponentListener(new ComponentAdapter() { public void componentResized(ComponentEvent e) { - timeline.refresh(); + panel.refresh(); } }); - this.setVisible(true); + } diff --git a/Main.java b/Main.java deleted file mode 100644 index 767d583..0000000 --- a/Main.java +++ /dev/null @@ -1,32 +0,0 @@ - - - -public class Main { - - public static void main(String[] args) { - //new Window(); - - Window w = new Window(); - Agenda agn = w.getAgenda(); - - Artist a1 = new Artist("Coldplay", "Alternative Rock", "null", "A band"); - Artist a2 = new Artist("Nirvana", "Alternative Rock", "null", "A band whose lead singer is dead"); - Artist a3 = new Artist("Eminem", "Rap", "null", "A very famous rapper"); - Stage s1 = new Stage("Rock Stage", "Stage for Rock and Alternative Rock concerts"); - Stage s2 = new Stage("Rap Stage", "Stage for Rap concerts"); - - Event e1 = new Event("Coldplay Live", 2015, 2, 24, 21, 00, 2015, 2, 24, 23, 00, a1, s1, "A concert from a very famous band", 2); - Event e2 = new Event("Coldplay Live", 2015, 2, 25, 20, 00, 2015, 2, 25, 22, 00, a1, s1, "A concert from a very famous band", 1); - Event e3 = new Event("Nirvana in memory", 2015, 2, 24, 16, 30, 2015, 2, 24, 20, 45, a2, s1, "A concert in memory of a once very famous band", 4); - Event e4 = new Event("Epic Rap Battles of History", 2015, 3, 3, 12, 30, 2015, 3, 12, 18, 45, a3, s2, "Rap battle with Eminem and ERP", 3); - - agn.addEvent(e1); - agn.addEvent(e2); - agn.addEvent(e3); - agn.addEvent(e4); - - agn.fillArtists(); - agn.fillStages(); - } - -} diff --git a/MenuBar.java b/MenuBar.java deleted file mode 100644 index e216d66..0000000 --- a/MenuBar.java +++ /dev/null @@ -1,89 +0,0 @@ -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.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) { - //TODO - } - }); - - 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(); - } - }); - - 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(); - } - }); - - JMenuItem exit = new JMenuItem("Exit"); - exit.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - System.exit(0); - } - }); - - file.add(newEvent); - 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.updatePanel("timeline"); - } - }); - - JMenuItem table = new JMenuItem("Table"); - table.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - Window.updatePanel("table"); - } - }); - - view.add(timeline); - view.add(table); - add(view); - } -} diff --git a/Panel.java b/Panel.java deleted file mode 100644 index c0b37d5..0000000 --- a/Panel.java +++ /dev/null @@ -1,5 +0,0 @@ -import java.util.ArrayList; - -public interface Panel{ - public void update(ArrayList event); -} diff --git a/PanelTable.java b/PanelTable.java deleted file mode 100644 index 63fc694..0000000 --- a/PanelTable.java +++ /dev/null @@ -1,206 +0,0 @@ -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.2 - */ -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 events; - private ArrayList fullEvents; - private JTable table; - private JTable selectedCell; - - /** - * Constructor makes the table and adds it to a scrollPane. - * @param events - */ - public PanelTable() { - super.setLayout(new BorderLayout()); - table= new JTable(); - table.setAutoCreateRowSorter(true); - table.setAutoResizeMode(table.AUTO_RESIZE_ALL_COLUMNS); - 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] = "Stage 1"; - 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 events) - { - update(events, true); - } - - public void update(ArrayList 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) { - JFrame frame = new JFrame(); - Event event = events.get(row); - //the dialog - frame.pack(); - frame.setSize(300, 200); - frame.setLocationRelativeTo(this); - frame.setVisible(true); - } - - /** - * Opens a dialog with information of the selected artist - * @param row - */ - private void openArtistDialog(int row) { - JFrame frame = new JFrame(); - Artist artist = events.get(row).getArtist(); - //the dialog - frame.pack(); - frame.setSize(300, 200); - frame.setLocationRelativeTo(this); - frame.setVisible(true); - } - - /** - * 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 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.equals(events.get(selectedCell.getSelectedRow()))) { - filteredList.add(event); - } - } - break; - case 2: - for(Event event : fullEvents) { - if(event.getArtist().equals(events.get(selectedCell.getSelectedRow()).getArtist())) { - 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); - } - } - -} diff --git a/SaveLoad.java b/SaveLoad.java deleted file mode 100644 index 6b27af0..0000000 --- a/SaveLoad.java +++ /dev/null @@ -1,123 +0,0 @@ - - -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; - } - } -} diff --git a/StagePanel.java b/StagePanel.java index e4e646d..f8a206e 100644 --- a/StagePanel.java +++ b/StagePanel.java @@ -62,6 +62,11 @@ public class StagePanel extends JPanel return this.posX; } + public void setLength(int length) + { + this.width = length; + } + public void setStageStartTime(int startTime) { stage.setStartTime(startTime); diff --git a/Timeline.java b/Timeline.java index fa9774b..d87f990 100644 --- a/Timeline.java +++ b/Timeline.java @@ -1,5 +1,6 @@ import java.awt.BorderLayout; import java.awt.Color; +import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; @@ -16,6 +17,7 @@ import java.util.ArrayList; 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; @@ -25,7 +27,7 @@ import javax.swing.JPanel; public class Timeline extends JPanel { private ArrayList stages = new ArrayList(); - private JFrame frame; + private JPanel frame; // Geef dit object je JFrame mee, en zet in je JFrame de volgende code: // this.setContentPane(timeline.getTimeline()); @@ -36,12 +38,14 @@ public class Timeline extends JPanel // } // }); - public Timeline(JFrame frame) + + public Timeline(JPanel frame) { - super(new BorderLayout()); + super(); this.frame = frame; genStages(); + this.setSize(frame.getWidth(), frame.getHeight()); refresh(); } @@ -49,7 +53,7 @@ public class Timeline extends JPanel public void refresh() { this.removeAll(); - createWestPanel(); +// createWestPanel(); createMainPanel(); this.revalidate(); } @@ -59,11 +63,18 @@ public class Timeline extends JPanel JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); Container topContainer = createTopPanel(); - Dimension dim = new Dimension(frame.getWidth(), 60); + Dimension dim = new Dimension(this.getWidth(), 60); topContainer.setMaximumSize(dim); mainPanel.add(topContainer); - Container centerContainer = createCenterPanel(); - centerContainer.setMaximumSize(new Dimension(frame.getWidth(), frame.getHeight())); + + Dimension centerDim = new Dimension(this.getWidth(), frame.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); } @@ -80,7 +91,7 @@ public class Timeline extends JPanel { StagePanel stagepanel = new StagePanel(calcLengthOfStage(stage.getLength()), 30, calcPositionOfStage(stage.getStartTime()), stage); Container content = stagepanel; - content.setMaximumSize(new Dimension(frame.getWidth() - 70,30)); + content.setMaximumSize(new Dimension(this.getWidth(),30)); content.addMouseListener(new MouseListener() { @Override @@ -136,6 +147,8 @@ public class Timeline extends JPanel // System.out.println(calcStartTimeOfStagePanel(stagepanel.getPosX())); stagepanel.setStageStartTime(calcStartTimeOfStagePanel(stagepanel.getPosX())); stagepanel.setStageEndTime(calcEndTimeOfStagePanel(stagepanel.getPosX(), stagepanel.getImageWidth())); +// stagepanel.setLength(calcLengthOfStagePanel(stagepanel.getImageWidth())); +// System.out.println(calcLengthOfStagePanel(stagepanel.getImageWidth())); refresh(); @@ -147,10 +160,10 @@ public class Timeline extends JPanel int min = findMinMax(1); int max = findMinMax(2); - double frameWidth = frame.getWidth(); + double frameWidth = this.getWidth(); double pixelsPerLength = frameWidth / (max - min); lengthOfStage = pixelsPerLength * (double)length; - +// System.out.println((int)lengthOfStage); return (int)lengthOfStage; } @@ -159,12 +172,12 @@ public class Timeline extends JPanel double lengthOfStagePanel = 0; int min = findMinMax(1); int max = findMinMax(2); - System.out.println(length); - double frameWidth = frame.getWidth(); +// System.out.println(length); + double frameWidth = this.getWidth(); double pixelsPerLength = frameWidth / (max - min); - System.out.println(pixelsPerLength); +// System.out.println(pixelsPerLength); lengthOfStagePanel = (double)length / pixelsPerLength; - System.out.println(lengthOfStagePanel); +// System.out.println(lengthOfStagePanel); return (int)lengthOfStagePanel; } @@ -175,8 +188,8 @@ public class Timeline extends JPanel int min = findMinMax(1); int max = findMinMax(2); posx = startTime - min; - posx = posx * frame.getWidth() / (max-min); -// System.out.println("Frame: " + frame.getWidth()); + posx = posx * this.getWidth() / (max-min); +// System.out.println("Frame: " + this.getWidth()); // System.out.println("startTime: " + startTime); // System.out.println("Max: " + max + " min: " + min); // System.out.println("Posx: " + posx); @@ -187,16 +200,16 @@ public class Timeline extends JPanel { int min = findMinMax(1); int max = findMinMax(2); -// double startTime = (posx / (frame.getWidth() / (max - min )) ) + min; +// double startTime = (posx / (this.getWidth() / (max - min )) ) + min; //Omdat het anders onnodig afgerond wordt, alles apart in doubles. double minmax = max-min; - double bottom = frame.getWidth() / minmax; + double bottom = this.getWidth() / minmax; double all = posx / bottom; double startTime = all + min; // System.out.println("starttime----------------"); -// System.out.println("Frame: " + frame.getWidth()); +// System.out.println("Frame: " + this.getWidth()); // System.out.println("startTime: " + startTime); // System.out.println("Max: " + max + " min: " + min); // System.out.println("Posx: " + posx); @@ -209,7 +222,7 @@ public class Timeline extends JPanel int max = findMinMax(2); //Omdat het anders onnodig afgerond wordt, alles apart in doubles. double minmax = max-min; - double bottom = frame.getWidth() / minmax; + double bottom = this.getWidth() / minmax; double all = posx / bottom; double endTime = all + min + calcLengthOfStagePanel(imageWidth); // System.out.println(calcLengthOfStagePanel(imageWidth)); @@ -274,10 +287,6 @@ public class Timeline extends JPanel System.out.println("Return -1"); return -1; } - - - - } private JPanel createTopPanel() @@ -285,7 +294,7 @@ public class Timeline extends JPanel JPanel topPane = new JPanel(); topPane.setLayout(new BoxLayout(topPane, BoxLayout.Y_AXIS)); JPanel topPanel = new JPanel(new FlowLayout()); - for(int i = 0; i <= frame.getWidth() / 10; i++) + for(int i = 0; i <= this.getWidth() / 10; i++) { ImageIcon topImageIcon = new ImageIcon("src/test2.png"); JLabel topImage = new JLabel(topImageIcon); @@ -294,18 +303,18 @@ public class Timeline extends JPanel 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(10, 10))); + panel.add(Box.createRigidArea(new Dimension(50, 10))); panel.add(new JLabel(Integer.toString(findMinMax(1)))); panel.add(Box.createHorizontalGlue()); panel.add(new JLabel(Integer.toString(findMinMax(2)))); - panel.add(Box.createRigidArea(new Dimension(10, 10))); + panel.add(Box.createRigidArea(new Dimension(50, 10))); topPane.add(panel); topPane.add(topPanel); // this.add(topPane, BorderLayout.NORTH); return topPane; } - private void createWestPanel() + public JPanel createWestPanel() { JPanel westPanel = new JPanel(); westPanel.setLayout(new BoxLayout(westPanel, BoxLayout.Y_AXIS)); @@ -316,7 +325,8 @@ public class Timeline extends JPanel westPanel.add(stageText); westPanel.add(Box.createRigidArea(new Dimension(0, 30 ))); } - this.add(westPanel, BorderLayout.WEST); +// this.add(westPanel, BorderLayout.WEST); + return westPanel; } private void genStages() diff --git a/TimelinePanel.java b/TimelinePanel.java new file mode 100644 index 0000000..48d829b --- /dev/null +++ b/TimelinePanel.java @@ -0,0 +1,26 @@ +import java.awt.BorderLayout; + +import javax.swing.JPanel; + + +public class TimelinePanel extends JPanel { + + private Timeline timeline; + + public TimelinePanel() + { + super(new BorderLayout()); + + this.setSize(600, 600); + this.setVisible(true); + timeline = new Timeline(this); + this.add(timeline,BorderLayout.CENTER); + this.add(timeline.createWestPanel(), BorderLayout.WEST); + } + + public void refresh() + { + timeline.refresh(); + } + +} diff --git a/Window.java b/Window.java deleted file mode 100644 index 2bc916a..0000000 --- a/Window.java +++ /dev/null @@ -1,213 +0,0 @@ - - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.Toolkit; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -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 panels = new HashMap(); - 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(); - panels.put("table", tablePanel); - - //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())); - changePanel(); - } - }); - 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())); - changePanel(); - } - }); - 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())); - changePanel(); - } - }); - 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())); - changePanel(); - } - }); - 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())); - changePanel(); - } - }); - bottomPanel.add(new JSeparator(SwingConstants.VERTICAL)); - bottomPanel.add(forwardWeekButton); - - //Add panels - mainPanel.add(centerPanel, BorderLayout.CENTER); - mainPanel.add(bottomPanel, BorderLayout.SOUTH); - - setContentPane(mainPanel); - - changePanel(); - - //Show window - setVisible(true); - } - - public static void updatePanel(String panel) - { - currentPanel = panel; - changePanel(); - } - - private static void changePanel() - { - if(centerPanel.getComponents().length > 0) - { - centerPanel.remove(0); - } - Panel p = panels.get(currentPanel); - p.update(getEvents()); - JPanel p1 = (JPanel) p; - p1.setPreferredSize(centerPanel.getSize()); - centerPanel.add(p1, BorderLayout.CENTER); - 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) - { - System.exit(0); - } - } - - public static ArrayList getEvents() - { - ArrayList events = new ArrayList(); - 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; - } - - -} diff --git a/commons-lang3-3.3.2.jar b/commons-lang3-3.3.2.jar deleted file mode 100644 index bb06979..0000000 Binary files a/commons-lang3-3.3.2.jar and /dev/null differ