Преглед на файлове

Updated io added once again.

Jeroen96 преди 10 години
родител
ревизия
ba564f17b8
променени са 9 файла, в които са добавени 174 реда и са изтрити 148 реда
  1. 2 1
      src/agenda/Act.java
  2. 2 1
      src/agenda/ActTime.java
  3. 2 1
      src/agenda/Agenda.java
  4. 3 1
      src/agenda/Artist.java
  5. 21 34
      src/agenda/Io.java
  6. 3 1
      src/agenda/Stage.java
  7. 3 1
      src/agenda/Time.java
  8. 9 0
      src/gui/frames/MainFrame.java
  9. 129 108
      src/gui/menubar/MenuBar.java

+ 2 - 1
src/agenda/Act.java

@@ -1,12 +1,13 @@
 package agenda;
 
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
 
 /**
  * Created by gjoosen on 06/02/15.
  */
-public class Act {
+public class Act implements Serializable  {
     
     private List<Artist> artists;
     private Stage stage;

+ 2 - 1
src/agenda/ActTime.java

@@ -1,12 +1,13 @@
 package agenda;
 
+import java.io.Serializable;
 import java.util.Calendar;
 import java.util.GregorianCalendar;
 
 /**
  * Created by gjoosen on 06/02/15.
  */
-public class ActTime {
+public class ActTime implements Serializable {
     
 	private GregorianCalendar beginTime, endTime;
     

+ 2 - 1
src/agenda/Agenda.java

@@ -1,12 +1,13 @@
 package agenda;
 
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
 
 /**
  * Created by gjoosen on 06/02/15.
  */
-public class Agenda {
+public class Agenda implements Serializable {
     
     private List<Stage> stages;
     private List<Artist> artists;

+ 3 - 1
src/agenda/Artist.java

@@ -1,9 +1,11 @@
 package agenda;
 
+import java.io.Serializable;
+
 /**
  * Created by gjoosen on 06/02/15.
  */
-public class Artist {
+public class Artist implements Serializable {
     
     private String name, genre;
     

+ 21 - 34
src/agenda/Io.java

@@ -10,69 +10,56 @@ import javax.swing.JFileChooser;
 
 
 public class Io {
-	
-	public static void main(String [] args) throws IOException{
-		Io io = new Io();
-	}
-	
-	public Io() throws IOException
-	{
-		writeIo();
-	}
-	
-	public void writeIo() throws IOException
+
+	public void writeIo(Agenda agenda) throws IOException
 	{
 		JFileChooser fileChooser = new JFileChooser();
 		if(fileChooser.showSaveDialog(null)
 				== fileChooser.APPROVE_OPTION) {
 			java.io.File file = fileChooser.getSelectedFile();
-		
-		ObjectOutputStream output = null;
-		try{
-			output = new ObjectOutputStream(new FileOutputStream(file));
-		}catch(IOException e){ 
-			System.out.println("Could not open file." + e);
-			System.exit(0);
-		}
-		try{
-			output.writeObject(new Agenda());
 
-			output.close();
-		}catch(IOException e){
-			System.out.println("Writing error.  " + e);
-			System.exit(0); 
-		}
+			ObjectOutputStream output = null;
+			try{
+				output = new ObjectOutputStream(new FileOutputStream(file));
+			}catch(IOException e){ 
+				System.out.println("Could not open file." + e);
+			}
+			try{
+				output.writeObject(agenda);
+				output.close();
+			}catch(IOException e){
+				System.out.println("Writing error.  " + e);
+			}
 		}
 
 	}
 
-	public void readIo() throws IOException
+	public static Agenda readIo() throws IOException
 	{
 		JFileChooser fileChooser = new JFileChooser();
 		if(fileChooser.showOpenDialog(null)
 				== fileChooser.APPROVE_OPTION) {
 			java.io.File file = fileChooser.getSelectedFile();
-			
+
 			ObjectInputStream input = null;
-			
+
 			try{
 				input = new ObjectInputStream(new FileInputStream(file));
 			}catch(IOException e){
 				System.out.println("There was a problem opening the file. " + e);
-				System.exit(0);
 
 			}
 			Agenda agenda = null;
 			try{
 				agenda = (Agenda)input.readObject();
 				input.close();
+				return agenda;
 			}catch(Exception e){
 				System.out.println("There was a issue reading this file: " + e);
-				System.exit(0);
 			}
-			System.out.println("agenda's stuff is : " + agenda.getActs());
-	}
-			
+		}
+		return null;
+
 	}
 }
 

+ 3 - 1
src/agenda/Stage.java

@@ -1,9 +1,11 @@
 package agenda;
 
+import java.io.Serializable;
+
 /**
  * Created by gjoosen on 06/02/15.
  */
-public class Stage {
+public class Stage implements Serializable {
     
     private String name;
     

+ 3 - 1
src/agenda/Time.java

@@ -1,9 +1,11 @@
 package agenda;
 
+import java.io.Serializable;
+
 /**
  * Created by gjoosen on 07/02/15.
  */
-public class Time {
+public class Time implements Serializable {
     
     private int hours, minutes;
     

+ 9 - 0
src/gui/frames/MainFrame.java

@@ -72,4 +72,13 @@ public class MainFrame extends JFrame{
         this.setContentPane(this.currentPanel);
         this.revalidate();
     }
+
+	public Agenda getAgenda() {
+		return agenda;
+	}
+
+	public void setAgenda(Agenda agenda) {
+		this.agenda = agenda;
+	}
+
 }

+ 129 - 108
src/gui/menubar/MenuBar.java

@@ -9,127 +9,148 @@ import java.awt.Window;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.KeyEvent;
+import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
 import javax.swing.*;
 
+import agenda.Agenda;
+import agenda.Io;
+
 @SuppressWarnings("serial")
 public class MenuBar extends JMenuBar{
 
-    private MainFrame mainFrame;
-    
+	private MainFrame mainFrame;
+
 	public MenuBar(MainFrame frame){
-        this.mainFrame = frame;
+		this.mainFrame = frame;
 		initialize();
 	}
-	
+
 	private void initialize(){
 		setLayout(new FlowLayout(80));
 		JMenu fileMenu = new JMenu("File");
-        JMenu editMenu = new JMenu("Edit");
-        JMenu viewMenu = new JMenu("View");
-        JMenu helpMenu = new JMenu("Help");
-        this.add(fileMenu);
-        this.add(editMenu);
-        this.add(viewMenu);
-        this.add(helpMenu);
-        
-        JMenuItem newAction = new JMenuItem("New");
-        JMenuItem openAction = new JMenuItem("Open");
-        JMenuItem exitAction = new JMenuItem("Exit");
-        JMenuItem cutAction = new JMenuItem("Cut");
-        JMenuItem copyAction = new JMenuItem("Copy");
-        JMenuItem pasteAction = new JMenuItem("Paste");
-        
-        //view 
-        JMenuItem editorView = new JMenuItem("Editor");
-        JMenuItem agendaView = new JMenuItem("Agenda");
-        JMenuItem simulatorView = new JMenuItem("Simulator");
-        JMenuItem tableView = new JMenuItem("Table");
-
-        newAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
-        openAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
-        exitAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
-        cutAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));
-        copyAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
-        pasteAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK));
-        
-        fileMenu.add(newAction);
-        newAction.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent arg0) {
-                System.out.println("You have clicked on the new action");
-            }
-        });
-        fileMenu.add(openAction);
-        openAction.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent arg0) {
-                System.out.println("You have clicked on the open action");
-            }
-        });
-        fileMenu.addSeparator();
-        fileMenu.add(exitAction);
-        exitAction.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent arg0) {
-                System.exit(0);
-            }
-        });
-        editMenu.add(cutAction);
-        cutAction.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent arg0) {
-                System.out.println("You have clicked on the cut action");
-            }
-        });
-        editMenu.add(copyAction);
-        copyAction.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent arg0) {
-                System.out.println("You have clicked on the copy action");
-            }
-        });
-        editMenu.add(pasteAction);
-        pasteAction.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent arg0) {
-                System.out.println("You have clicked on the paste action");
-            }
-        });
-        
-        //view
-        viewMenu.add(editorView);
-        editorView.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                System.out.println("Editor View");
-                mainFrame.changeView(MainFrame.Views.EDITOR);
-            }
-        });
-
-        viewMenu.add(simulatorView);
-        simulatorView.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                System.out.println("Simulator View");
-                mainFrame.changeView(MainFrame.Views.SIMULATOR);
-
-            }
-        });
-        
-        viewMenu.add(agendaView);
-        agendaView.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                System.out.println("Agenda View");
-                mainFrame.changeView(MainFrame.Views.AGENDA);
-
-            }
-        });
-
-        viewMenu.add(tableView);
-        tableView.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                mainFrame.changeView(MainFrame.Views.TABLE);
-            }
-        });
+		JMenu editMenu = new JMenu("Edit");
+		JMenu viewMenu = new JMenu("View");
+		JMenu helpMenu = new JMenu("Help");
+		this.add(fileMenu);
+		this.add(editMenu);
+		this.add(viewMenu);
+		this.add(helpMenu);
+
+		JMenuItem newAction = new JMenuItem("New");
+		JMenuItem openAction = new JMenuItem("Open");
+		JMenuItem exitAction = new JMenuItem("Exit");
+		JMenuItem cutAction = new JMenuItem("Cut");
+		JMenuItem copyAction = new JMenuItem("Copy");
+		JMenuItem pasteAction = new JMenuItem("Paste");
+		JMenuItem saveAction = new JMenuItem("Save");
+		//view 
+		JMenuItem editorView = new JMenuItem("Editor");
+		JMenuItem agendaView = new JMenuItem("Agenda");
+		JMenuItem simulatorView = new JMenuItem("Simulator");
+		JMenuItem tableView = new JMenuItem("Table");
+
+		newAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
+		openAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
+		exitAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
+		cutAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));
+		copyAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
+		pasteAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK));
+		saveAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,ActionEvent.CTRL_MASK));
+
+		fileMenu.add(newAction);
+		newAction.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent arg0) {
+				System.out.println("You have clicked on the new action");
+			}
+		});
+		fileMenu.add(openAction);
+		openAction.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent arg0) {
+				try {
+					Agenda agenda = Io.readIo();
+					mainFrame.setAgenda(agenda);
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+			}
+		});
+		fileMenu.add(openAction);
+		openAction.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent arg0) {
+				try {
+					Agenda agenda = Io.readIo();
+					mainFrame.setAgenda(agenda);
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+			}
+		});
+		fileMenu.addSeparator();
+		fileMenu.add(exitAction);
+		exitAction.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent arg0) {
+				System.exit(0);
+			}
+		});
+		editMenu.add(cutAction);
+		cutAction.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent arg0) {
+				System.out.println("You have clicked on the cut action");
+			}
+		});
+		editMenu.add(copyAction);
+		copyAction.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent arg0) {
+				System.out.println("You have clicked on the copy action");
+			}
+		});
+		editMenu.add(pasteAction);
+		pasteAction.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent arg0) {
+				System.out.println("You have clicked on the paste action");
+			}
+		});
+
+		//view
+		viewMenu.add(editorView);
+		editorView.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				System.out.println("Editor View");
+				mainFrame.changeView(MainFrame.Views.EDITOR);
+			}
+		});
+
+		viewMenu.add(simulatorView);
+		simulatorView.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				System.out.println("Simulator View");
+				mainFrame.changeView(MainFrame.Views.SIMULATOR);
+
+			}
+		});
+
+		viewMenu.add(agendaView);
+		agendaView.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				System.out.println("Agenda View");
+				mainFrame.changeView(MainFrame.Views.AGENDA);
+
+			}
+		});
+
+		viewMenu.add(tableView);
+		tableView.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				mainFrame.changeView(MainFrame.Views.TABLE);
+			}
+		});
 	}
-	
+
 }