/* * ModelC.java * * Version: * $Id: ModelC.java,v 1.14 2007-10-07 19:14:29 wpg4665 Exp $ * * Revisions: * $Log: ModelC.java,v $ * Revision 1.14 2007-10-07 19:14:29 wpg4665 * *** empty log message *** * * Revision 1.13 2007-10-07 19:10:31 wpg4665 * added isSame method to determine if the file has been modified * * Revision 1.11 2007-10-06 15:49:31 wpg4665 * made it so command line loading problems of a calendar file is handled here * * Revision 1.10 2007-10-06 00:34:16 wpg4665 * *** empty log message *** * * Revision 1.9 2007-10-05 21:36:33 ser6507 * Added functionality to the add, edit and delete methods * * Revision 1.8 2007-10-05 19:33:31 mdi9985 * fixed misc problems - now builds * * Revision 1.7 2007-10-03 15:39:44 wpg4665 * deafult naming loop works now, is implemented * * Revision 1.6 2007-10-02 20:49:41 wpg4665 * Modified as needed by viewC and added some more functionality * * Revision 1.5 2007-09-28 17:27:51 wpg4665 * Changed comment syntax * * Revision 1.4 2007-09-28 17:09:07 wpg4665 * Finalized comments. May need more methods later * */ package controller; import model.*; /** * ModelC.java controls all of the functionality * that deals with the Model package * * @author Will Gordon */ public class ModelC { private ApptMap myApptMap; //The ApptMap that is current being seen and used private String currentOpenFile; //The name of the file that is currently being written to and read from /** * An empty constructor * Starts the calendar with a new ApptMap */ public ModelC(){ myApptMap = new ApptMap(); //checks to see if the file name is already there for ( int i = 1; currentOpenFile == null; i++ ) { if ( IO.readApptMap( "Calendar" + i + ".cal") == null ) { currentOpenFile = "Calendar" + i + ".cal"; } } } /** * A constructor that looks for the specified fileName * It opens the specified file * * @param fileName : the name of the file that holds the desired apptMap */ public ModelC( String fileName ){ if ( null != IO.readApptMap( fileName ) ) { myApptMap = IO.readApptMap( fileName ); currentOpenFile = fileName; } else { System.err.println( "Error: Command line read Calendar file cannot be found" ); System.exit( 1 ); } } /** * Saves the ApptMap with specified fileName * * @param fileName : the name of the file to save the apptMap in * * @return true if properly saved */ public boolean save( String fileName ){ boolean isSaved = IO.writeApptMap( myApptMap, fileName ); currentOpenFile = fileName; return isSaved; } /** * saves the current ApptMap to its previously defined fileName * * @return true if saved properly */ public boolean save(){ boolean isSaved = IO.writeApptMap( myApptMap, currentOpenFile ); return isSaved; } /** * opens the apptMap at the fileName * * @param fileName : saves the name of the fileName as a default */ public void open( String fileName ){ currentOpenFile = fileName; myApptMap = IO.readApptMap( fileName ); } public String getCurrentOpenFile(){ return currentOpenFile; } public void addAppt( Appt a) { //myApptMap.addAppt(a); } public void editAppt( Appt old, Appt edited ) { //deleteAppt(old, false); //addAppt(edited); } public void deleteAppt(Appt a, boolean deleteLinked) { //myApptMap.deleteAppt(Appt.getKey(a), a.getName()); } public boolean isSame() { return IO.readApptMap( currentOpenFile ).getNumMods() == myApptMap.getNumMods(); } }