/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford Mount Allison University 2001 File: IniSettings.java Description: This class contains a list of the constants that are used throughout the GDCT program. These constants are stored in an initialization file to allow them to be easily updated and saved. */ //import statements import java.awt.Color; import java.awt.Frame; import java.awt.Font; public class IniSettings { //Copy of initialization file public static IniFile iFile = new IniFile(); //Name of initialization file private static String filename = "gdct.ini"; //Temporary frame used in the display of error messages private static String recent[] = new String[8]; private static boolean firstInstance = true; public IniSettings() //Default Constructor { if (firstInstance) { for (int i=0; i<8; i++) recent[i] = new String(); //If the iniFile exists... if (iFile.readIni(filename)) { //Get internal settings information readInternalSettings(); //Get category graphical settings information readCatGraphicalSettings(); //Get functor graphical settings information readFunGraphicalSettings(); //Get functor animation settings information readAnimationSettings(); //Get server settings information readServerSettings(); //Get recent files list readRecentFiles(); } else { //Display warning message that gdct.ini could not be found and program //defaults are being used for all rewriteInternalSettings(); rewriteCatGraphicalSettings(); rewriteFunGraphicalSettings(); rewriteAnimationSettings(); rewriteServerSettings(); rewriteRecentFiles(); /* //Write changed initialization settings to file if (!iFile.writeIni(filename)) { new MessageDialog(null, "Error", "Unable to open GDCT initialization file.", true); } */ } } firstInstance = false; } /* private String getItem(String name) //Reads the item specified and if it does not exist that section of //the intialization is corrupt and is rewrote { if (iFile.getItem(name) == null) { //Value not found in current section //of initialization file String currHeader = iFile.getHeader(); if (currHeader.equals("Internal Settings")) rewriteInternalSettings(); //else if (currHeader.equals("Category Graphical Settings")) //rewriteCatGraphicalSettings(); //else if (currHeader.equals("Functor Graphical Settings")) //rewriteFunGraphialSettings(); else if (currHeader.equals("Animation Settings")) rewriteAnimationSettings(); else if (currHeader.equals("Server Settings")) rewriteServerSettings(); //Write changed initialization file if (!iFile.writeIni(filename)) { //Display message error writing ini file } } else return (iFile.getItem(name)); } */ //------------------------------------------------------------------------------ //--------------------------- Internal Settings--------------------------------- //------------------------------------------------------------------------------ private static int maxloop = 10; //The Max Order of Endomorphisms is set to 50 by default private static int MAXWORD = 100; //MAXWORD is set to 50 by default private static int MAXARR = 1000; //MAXARR is set to 50 by default private static int RELLEN = 1000; //RELLEN is set to 30 by default; private static char separator = '*'; //seperator is the character that is used to seperate //arrow names in a path or relation private static int idCode = -2; //This value is the integer representation of an identity //arrow private static String currentVersion = "Version 3.0";//Current release version of GDCT public int getMaxLoop() //Get the endomorphism limit { return(maxloop); } public int getMAXWORD() //Get MAXWORD { return(MAXWORD); } public int getMAXARR() //Get the maximum number of arrows { return(MAXARR); } public int getRELLEN() //Get the length of the lhs and rhs of relations { return(RELLEN); } public char getSeparator() //Get the spearator character for paths of arrows { return(separator); } public int getIdentityCode() //Get the integer representation of the identity //arrow { return(idCode); } public String getCurrentVersion() //Return the current version information //for this release of GDCT { return(currentVersion); } public void setMaxLoop(int max) //Set the max order of endomorphism { //Change local maxloop maxloop = max; //Update file copy of maxloop //If internal settings exists in the initialization file if(!iFile.setHeader("Internal Settings")) rewriteInternalSettings(); iFile.addItem("endoLimit", Integer.toString(maxloop)); //Write changed initialization file if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(f, "Error", "Unable to write GDCT initialization file.", true); } } public void setMAXWORD(int max) //Set MAXWORD { //Change local MAXWORD MAXWORD = max; //Update file copy of MAXWORD //If internal settings exists in the initialization file if(!iFile.setHeader("Internal Settings")) rewriteInternalSettings(); iFile.addItem("maxObjects", Integer.toString(MAXWORD)); //Write changed initialization file if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(f, "Error", "Unable to write GDCT initialization file.", true); } } public void setMAXARR(int max) //Set the maximum number of arrows { //Change local maximum number of arrows MAXARR = max; //Update file copy of MAXARR //If internal settings exists in the initialization file if(!iFile.setHeader("Internal Settings")) rewriteInternalSettings(); iFile.addItem("maxArrows", Integer.toString(MAXARR)); //Write changed initialization file if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(f, "Error", "Unable to write GDCT initialization file.", true); } } public void setRELLEN(int max) //Set the length of the lhs and rhs of relations { //Change local length of relations RELLEN = max; //Update file copy of RELLEN //If internal settings exists in the initialization file if(iFile.setHeader("Internal Settings")) rewriteInternalSettings(); iFile.addItem("relationsLength", Integer.toString(RELLEN)); //Write changed initialization file if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(f, "Error", "Unable to write GDCT initialization file.", true); } } public void setSeparator(char newSep) //Set the separator character for paths of arrows { //Change local version of separator character separator = newSep; //NOTE: Separator not in initialization file } public void readInternalSettings() //Read the internal settings from the GDCT //initialization file { if (!iFile.setHeader("Internal Settings")) rewriteInternalSettings(); //Read Maxloop value try { maxloop = Integer.parseInt(iFile.getItem("endoLimit")); } catch(Exception e) { //Value for maxloop is not a valid integer } //Read MAXWORD value try { MAXWORD = Integer.parseInt(iFile.getItem("maxObjects")); } catch(Exception e) { //Value for MAXWORD is not a valid integer } //Read MAXARR value try { MAXARR = Integer.parseInt(iFile.getItem("maxArrows")); } catch(Exception e) { //Value for MAXWORD is not a valid integer } //NOTE: Maximum number of relations is currenty stured in //MAXWORD, thus it is equal to the maximum number of objects //Read RELLEN value try { RELLEN = Integer.parseInt(iFile.getItem("relationsLength")); } catch(Exception e) { //Value for RELLEN is not a valid integer } } public void rewriteInternalSettings() //Rewrite the internal settings section of the GDCT //initialization file { iFile.addHeader("Internal Settings"); //iFile.setHeader("Internal Settings"); iFile.addItem("endoLimit", Integer.toString(maxloop)); iFile.addItem("maxObjects", Integer.toString(MAXWORD)); iFile.addItem("maxArrows", Integer.toString(MAXARR)); iFile.addItem("maxRelations", Integer.toString(MAXWORD)); iFile.addItem("relationsLength", Integer.toString(RELLEN)); } //------------------------------------------------------------------------------ //-------------------------Category Graphical Settings-------------------------- //------------------------------------------------------------------------------ private static double catScale = 1; //Scale of category graphical display private static String catFontFace = "Helvetica"; //Font face of category graphical display private static int catFontSize = 10; //Font size of category graphical display private static boolean showCatControls = true; //Display Category Controls?? private static boolean showCatComments = true; //Display Category Comments?? public double getCatScale() //Return the scale of the graphical category display { return(catScale); } public Font getCatFont() //Return the current font specified in the //initialization file { Font f = new Font(catFontFace, Font.PLAIN, catFontSize); return(f); } public String getCatFontFace() //Return the font face of the category graphical display { return(catFontFace); } public int getCatFontSize() //Return the font size of the category graphical display { return(catFontSize); } public boolean checkCatComments() //Return if the comments should be displayed { return(showCatComments); } public boolean checkCatControls() //Return if the graphical display controls should be displayed { return(showCatControls); } public void setCatScale(double scale) //Set the category display scale { //Set the scale locally catScale = scale; //If the category graphical settings section of the initialization //file exists change the scale if (iFile.setHeader("Category Graphical Settings")) { iFile.addItem("scale", Double.toString(catScale)); } else rewriteCatGraphicalSettings(); if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(f, "Error", "Unable to write GDCT initialization file.", true); } } public void setCatFont(Font font) //Set the font face and size based on //the font passed in as a parameter { catFontFace = font.getName(); catFontSize = font.getSize(); //If the category graphical settings section of the initialization //file exists change the font information if (iFile.setHeader("Category Graphical Settings")) { iFile.addItem("fontFace", catFontFace); iFile.addItem("fontSize", Integer.toString(catFontSize)); } else rewriteCatGraphicalSettings(); if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(f, "Error", "Unable to write GDCT initialization file.", true); } } public void setCatFontFace(String font) //Set the category graphical display font face { //Change the font face locally catFontFace = font; //If the category graphical settings section of the initialization //file exists change the display of comments if (iFile.setHeader("Category Graphical Settings")) { iFile.addItem("fontFace", catFontFace); } else rewriteCatGraphicalSettings(); if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(f, "Error", "Unable to write GDCT initialization file.", true); } } public void setCatFontSize(int size) //Set the category graphical display font size { //Change the font size locally catFontSize = size; //If the category graphical settings section of the initialization //file exists change the font size if (iFile.setHeader("Category Graphical Settings")) { iFile.addItem("fontSize", Integer.toString(catFontSize)); } else rewriteCatGraphicalSettings(); if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(new Frame(), "Error", "Unable to write GDCT initialization file.", true); } } public void setCatComments(boolean display) //Change if the category comments should be displayed //or hidden { //Change display setting for comments locally showCatComments = display; //If the category graphical settings section of the initialization //file exists change the display of comments if (iFile.setHeader("Category Graphical Settings")) { if (showCatComments == false) iFile.addItem("showComments", "false"); else iFile.addItem("showComments", "true"); } else { //new MessageDialog(new Frame(), "Error", "Unable to read category graphical settings.", true); rewriteCatGraphicalSettings(); } if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(new Frame(), "Error", "Unable to write GDCT initialization file.", true); } } public void setCatControls(boolean display) //Change if the category graphical controls should be displayed //or hidden { //Change the display settings for the category graphical controls showCatControls = display; //If the category graphical settings section of the initialization //file exists change the display of controls if (iFile.setHeader("Category Graphical Settings")) { if (showCatControls == false) iFile.addItem("showControls", "false"); else iFile.addItem("showControls", "true"); } else { //new MessageDialog(new Frame(), "Error", "Unable to read category graphical settings.", true); rewriteCatGraphicalSettings(); } if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(new Frame(), "Error", "Unable to write GDCT initialization file.", true); } } public void readCatGraphicalSettings() //Read the category graphical settings from the //GDCT initialization file { if (iFile.setHeader("Category Graphical Settings")) { //Read Categoryt display scale value try { catScale = Double.valueOf(iFile.getItem("scale")).doubleValue(); } catch(Exception e) { //Value for maxloop is not a valid integer } //Read category font face catFontFace = iFile.getItem("fontFace"); //Read category font size try { catFontSize = Integer.parseInt(iFile.getItem("fontSize")); } catch(Exception e) { //Value for maxloop is not a valid integer } //Read if category comments should be displayed if ((iFile.getItem("showComments").toLowerCase()).equals("false")) showCatComments = false; else showCatComments = true; //Read if category controls should be displayed if ((iFile.getItem("showControls").toLowerCase()).equals("false")) showCatControls = false; else showCatControls = true; } else { rewriteCatGraphicalSettings(); } } public void rewriteCatGraphicalSettings() //Rewrite the category graphical settings section //of the GDCT initialization file { //Display message //Create Category Graphical Settings section iFile.addHeader("Category Graphical Settings"); iFile.setHeader("Category Graphical Settings"); //Add category scale iFile.addItem("scale", Double.toString(catScale)); //Add category font face iFile.addItem("fontFace", catFontFace); //Add category font size iFile.addItem("fontSize", Integer.toString(catFontSize)); //add if comments should be shown if (showCatComments == true) iFile.addItem("showComments", "true"); else iFile.addItem("showComments", "false"); //add if visual controls should be shown if (showCatControls == true) iFile.addItem("showControls", "true"); else iFile.addItem("showControls", "false"); } //------------------------------------------------------------------------------ //--------------------------Functor Graphical Settings-------------------------- //------------------------------------------------------------------------------ private static double catAScale = 1; //Scale of category A graphical display private static String catAFontFace = "Helvetica"; //Font face of category A graphical display private static int catAFontSize = 10; //Font size of category A graphical display private static double catBScale = 1; //Scale of category B graphical display private static String catBFontFace = "Helvetica"; //Font face of category B graphical display private static int catBFontSize = 10; //Font size of category B graphical display private static boolean showFunComments = true; //Display Functor Comments?? private static String funDisplayLayout = "ABVertical"; //Layout of category's display in functor private static boolean diagramDisplay = false; public double getCatAScale() //Return the scale of the graphical category A display { return(catAScale); } public Font getCatAFont() //Return the current font specified in the //initialization file { Font f = new Font(catAFontFace, Font.PLAIN, catAFontSize); return(f); } public String getCatAFontFace() //Return the font face of the category graphical display { return(catAFontFace); } public int getCatAFontSize() //Return the font size of the category graphical display { return(catAFontSize); } public double getCatBScale() //Return the scale of the graphical category B display { return(catBScale); } public Font getCatBFont() //Return the current font specified in the //initialization file { Font f = new Font(catBFontFace, Font.PLAIN, catBFontSize); return(f); } public String getCatBFontFace() //Return the font face of the category graphical display { return(catBFontFace); } public int getCatBFontSize() //Return the font size of the category graphical display { return(catBFontSize); } public boolean getDiagramDisplay() //Return whether the functor display is in diagram display mode { return(diagramDisplay); } public boolean checkFunComments() //Return if the comments should be displayed { return(showFunComments); } public String getFunDisplayLayout() //return the current functor display layout { return(funDisplayLayout); } public void setCatAScale(double scale) //Set the category A display scale { //Set the scale locally catAScale = scale; //If the functor graphical settings section of the initialization //file exists change the scale if (iFile.setHeader("Functor Graphical Settings")) { iFile.addItem("catAScale", Double.toString(catAScale)); } else rewriteFunGraphicalSettings(); if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(new Frame(), "Error", "Unable to write GDCT initialization file.", true); } } public void setCatAFont(Font font) //Set the font face and size based on //the font passed in as a parameter { catAFontFace = font.getName(); catAFontSize = font.getSize(); //If the functor graphical settings section of the initialization //file exists change the font information if (iFile.setHeader("Functor Graphical Settings")) { iFile.addItem("catAFontFace", catFontFace); iFile.addItem("catAFontSize", Integer.toString(catFontSize)); } else rewriteFunGraphicalSettings(); if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(new Frame(), "Error", "Unable to write GDCT initialization file.", true); } } public void setCatAFontFace(String font) //Set the category A graphical display font face { //Change the font face locally catAFontFace = font; //If thev functor graphical settings section of the initialization //file exists change the display of comments if (iFile.setHeader("Functor Graphical Settings")) { iFile.addItem("catAFontFace", catFontFace); } else rewriteFunGraphicalSettings(); if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(new Frame(), "Error", "Unable to write GDCT initialization file.", true); } } public void setCatAFontSize(int size) //Set the category A graphical display font size { //Change the font size locally catAFontSize = size; //If the functor graphical settings section of the initialization //file exists change the font size if (iFile.setHeader("Functor Graphical Settings")) { iFile.addItem("catAFontSize", Integer.toString(catFontSize)); } else rewriteFunGraphicalSettings(); if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(new Frame(), "Error", "Unable to write GDCT initialization file.", true); } } public void setCatBScale(double scale) //Set the category B display scale { //Set the scale locally catBScale = scale; //If the functor graphical settings section of the initialization //file exists change the scale if (iFile.setHeader("Functor Graphical Settings")) { iFile.addItem("catBScale", Double.toString(catAScale)); } else rewriteFunGraphicalSettings(); if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(new Frame(), "Error", "Unable to write GDCT initialization file.", true); } } public void setCatBFont(Font font) //Set the font face and size based on //the font passed in as a parameter { catBFontFace = font.getName(); catBFontSize = font.getSize(); //If the functor graphical settings section of the initialization //file exists change the font information if (iFile.setHeader("Functor Graphical Settings")) { iFile.addItem("catBFontFace", catFontFace); iFile.addItem("catBFontSize", Integer.toString(catFontSize)); } else rewriteFunGraphicalSettings(); if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(new Frame(), "Error", "Unable to write GDCT initialization file.", true); } } public void setCatBFontFace(String font) //Set the category B graphical display font face { //Change the font face locally catBFontFace = font; //If the functor graphical settings section of the initialization //file exists change the display of comments if (iFile.setHeader("Functor Graphical Settings")) { iFile.addItem("catBFontFace", catFontFace); } else rewriteFunGraphicalSettings(); if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(new Frame(), "Error", "Unable to write GDCT initialization file.", true); } } public void setCatBFontSize(int size) //Set the category B graphical display font size { //Change the font size locally catBFontSize = size; //If the functor graphical settings section of the initialization //file exists change the font size if (iFile.setHeader("Functor Graphical Settings")) { iFile.addItem("catBFontSize", Integer.toString(catFontSize)); } else rewriteFunGraphicalSettings(); if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(new Frame(), "Error", "Unable to write GDCT initialization file.", true); } } public void setFunComments(boolean display) //Change if the functor comments should be displayed //or hidden { //Change display setting for comments locally showFunComments = display; //If the functor graphical settings section of the initialization //file exists change the display of comments if (iFile.setHeader("Functor Graphical Settings")) { if (showFunComments == false) iFile.addItem("showComments", "false"); else iFile.addItem("showComments", "true"); } else { //new MessageDialog(new Frame(), "Error", "Unable to read functor graphical settings.", true); rewriteFunGraphicalSettings(); } if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(new Frame(), "Error", "Unable to write GDCT initialization file.", true); } } public void setFunDisplayLayout(String layout) //Set the Functor Display Layout to ABVertical, ABHorizontal, //AOnly, or BOnly { //Change display layout locally if (layout.equals("ABVertical") || layout.equals("ABHorizontal") || layout.equals("AOnly") || layout.equals("BOnly")) funDisplayLayout = layout; //If the functor graphical settings section of the initialization //file exists change the functor display layout if (iFile.setHeader("Functor Graphical Settings")) { if (layout.equals("ABVertical") || layout.equals("ABHorizontal") || layout.equals("AOnly") || layout.equals("BOnly")) iFile.addItem("displayLayout", funDisplayLayout); } else { //new MessageDialog(new Frame(), "Error", "Unable to read functor graphical settings.", true); rewriteFunGraphicalSettings(); } if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(new Frame(), "Error", "Unable to write GDCT initialization file.", true); } } public void setDiagramDisplay(boolean display) //Change if the functor comments should be displayed //or hidden { //Change display setting for comments locally diagramDisplay = display; //If the functor graphical settings section of the initialization //file exists change the display of comments if (iFile.setHeader("Functor Graphical Settings")) { if (diagramDisplay == false) iFile.addItem("diagramDisplay", "false"); else iFile.addItem("diagramDisplay", "true"); } else { //new MessageDialog(new Frame(), "Error", "Unable to read functor graphical settings.", true); rewriteFunGraphicalSettings(); } if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(new Frame(), "Error", "Unable to write GDCT initialization file.", true); } } public void readFunGraphicalSettings() //Read the functor graphical settings from the //GDCT initialization file { if (iFile.setHeader("Functor Graphical Settings")) { //Read category A's scale try { catAScale = Double.valueOf(iFile.getItem("catAscale")).doubleValue(); } catch(Exception e) { //Value for maxloop is not a valid integer } //Read category A font face catAFontFace = iFile.getItem("catAFontFace"); //Read category A font size try { catAFontSize = Integer.parseInt(iFile.getItem("catAFontSize")); } catch(Exception e) { //Value for maxloop is not a valid integer } //Read category B's scale try { catBScale = Double.valueOf(iFile.getItem("catBscale")).doubleValue(); } catch(Exception e) { //Value for maxloop is not a valid integer } //Read category B font face catBFontFace = iFile.getItem("catBFontFace"); //Read category B font size try { catBFontSize = Integer.parseInt(iFile.getItem("catBFontSize")); } catch(Exception e) { //Value for maxloop is not a valid integer } //Read if category comments should be displayed if ((iFile.getItem("showComments").toLowerCase()).equals("false")) showCatComments = false; else showCatComments = true; if ((iFile.getItem("diagramDisplay").toLowerCase()).equals("true")) diagramDisplay = true; else diagramDisplay = false; //Read Functor Display Layout } else { rewriteFunGraphicalSettings(); } } public void rewriteFunGraphicalSettings() //Rewrite the functor graphical settings section //of the GDCT initialization file { //Display message //Create Category Graphical Settings section iFile.addHeader("Functor Graphical Settings"); iFile.setHeader("Functor Graphical Settings"); //Add category A scale iFile.addItem("catAScale", Double.toString(catAScale)); //Add category A font face iFile.addItem("catAFontFace", catAFontFace); //Add category A font size iFile.addItem("catAFontSize", Integer.toString(catAFontSize)); //Add category B scale iFile.addItem("catBScale", Double.toString(catBScale)); //Add category B font face iFile.addItem("catBFontFace", catBFontFace); //Add category B font size iFile.addItem("catBFontSize", Integer.toString(catBFontSize)); //add if comments should be shown if (showFunComments == true) iFile.addItem("showComments", "true"); else iFile.addItem("showComments", "false"); if (diagramDisplay == true) iFile.addItem("diagramDisplay", "true"); else iFile.addItem("diagramDisplay", "false"); //add functor display layout iFile.addItem("displayLayout", funDisplayLayout); } //------------------------------------------------------------------------------ //------------------------Functor Animation Settings---------------------------- //------------------------------------------------------------------------------ private static int animationDelay = 2000; //animation delay time in ms private static Color AColor = Color.blue; //animated color of objects //and arrows in category A private static Color BColor = Color.blue; //animated color of objects //and arrows in category B public static int getAnimationDelay() //Return the current animation delay time in milliseconds { return(animationDelay); } public Color getAColor() //Return the current highlight color for Category A { return(AColor); } public Color getBColor() //Return the current highlight color for Category B { return(BColor); } public void setAnimationDelay(int delay) //Set the new animation delay for the animation //of functors between two finitely presented //categories { //Update local copy of animation delay animationDelay = delay; //Update file copy of animation delay //If functor animation settings exists in the initialization file if(iFile.setHeader("Functor Animation Settings")) { iFile.addItem("delayTime", Integer.toString(animationDelay)); } else { rewriteAnimationSettings(); } //Write change ini settings to file if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(new Frame(), "Error", "Unable to write GDCT initialization file.", true); } } public void setAColor(Color a) //Set the new color for the highlighting of object and //arrows in thhe functor animation of category A { //Update local copy of the color of Category A AColor = a; //Update file copy of the color of Category A //If functor animation settings exists in the initialization file if(iFile.setHeader("Functor Animation Settings")) { if (AColor.equals(Color.red)) iFile.addItem("catAColor", "red"); else if (AColor.equals(Color.blue)) iFile.addItem("catAColor", "blue"); else if (AColor.equals(Color.green)) iFile.addItem("catAColor", "green"); else if (AColor.equals(Color.yellow)) iFile.addItem("catAColor", "yellow"); else { //Message invalid color iFile.addItem("catAColor", "red"); } } else { rewriteAnimationSettings(); } //Write changed initialization settings to file if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(new Frame(), "Error", "Unable to write GDCT initialization file.", true); } } public void setBColor(Color b) //Set the new color for the highlighting of object and //arrows in thhe functor animation of category B { //Update local copy of the color of Category B BColor = b; //Update file copy of the color of Category B //If functor animation settings exists in the initialization file if(iFile.setHeader("Functor Animation Settings")) { if (BColor.equals(Color.red)) iFile.addItem("catBColor", "red"); else if (BColor.equals(Color.blue)) iFile.addItem("catBColor", "blue"); else if (BColor.equals(Color.green)) iFile.addItem("catBColor", "green"); else if (BColor.equals(Color.yellow)) iFile.addItem("catBColor", "yellow"); else { //Message invalid color iFile.addItem("catBColor", "red"); } } else { rewriteAnimationSettings(); } //Write changed initialization settings to file if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(new Frame(), "Error", "Unable to write GDCT initialization file.", true); } } public void readAnimationSettings() //Read the animation settings from the gdct //initialization file { if (iFile.setHeader("Functor Animation Settings")) { //Get animation delay from initialization file try { animationDelay = Integer.parseInt(iFile.getItem("delayTime")); } catch(Exception e) { //Value for Animation Delay is not a valid integer } //Get Category A highlight color from initialization file if ((iFile.getItem("catAColor").toLowerCase()).equals("red")) AColor = Color.red; else if ((iFile.getItem("catAColor").toLowerCase()).equals("blue")) AColor = Color.blue; else if ((iFile.getItem("catAColor").toLowerCase()).equals("green")) AColor = Color.green; else if ((iFile.getItem("catAColor").toLowerCase()).equals("yellow")) AColor = Color.yellow; else { ////new MessageDialog(f, "Error", "Desired color is invalid or not available in current version of GDCT", true); //Desired color is invalid or not available in current version of GDCT } //Get Category B highlight color from initialization file if (iFile.getItem("catBColor").toLowerCase().equals("red")) BColor = Color.red; if (iFile.getItem("catBColor").toLowerCase().equals("blue")) BColor = Color.blue; if (iFile.getItem("catBColor").toLowerCase().equals("green")) BColor = Color.green; if (iFile.getItem("catBColor").toLowerCase().equals("yellow")) BColor = Color.yellow; else { //Desired color is invalid or not available in current version of GDCT } } else { rewriteAnimationSettings(); } } public void rewriteAnimationSettings() //Rewrite the animation settings section of the GDCT //initialization file according to the default values //for animation delay and highlight colors for category //A and category B. { //Display message //Create Animation Settings section iFile.addHeader("Functor Animation Settings"); iFile.setHeader("Functor Animation Settings"); //Add delay time of animation iFile.addItem("delayTime", Integer.toString(animationDelay)); //Add highlight color for category A if (AColor.equals(Color.red)) iFile.addItem("catAColor", "red"); else if (AColor.equals(Color.blue)) iFile.addItem("catAColor", "blue"); else if (AColor.equals(Color.green)) iFile.addItem("catAColor", "green"); else if (AColor.equals(Color.yellow)) iFile.addItem("catAColor", "yellow"); else { //Message invalid color iFile.addItem("catAColor", "red"); } //Add highlight color for category B if (BColor.equals(Color.red)) iFile.addItem("catBColor", "red"); else if (BColor.equals(Color.blue)) iFile.addItem("catBColor", "blue"); else if (BColor.equals(Color.green)) iFile.addItem("catBColor", "green"); else if (BColor.equals(Color.yellow)) iFile.addItem("catBColor", "yellow"); else { //Message invalid color iFile.addItem("catBColor", "red"); } } //------------------------------------------------------------------------------ //-------------------------- Server Settings------------------------------------ //------------------------------------------------------------------------------ //The default server that examply categories and functors are located on. //catdir specifies the directory of categories while funcdir specifies the //directory of functors private static String server = "http://cs.mta.ca/research/rosebrugh/gdct/"; private static String catdir = "cat/"; private static String cgldir = "cgl/"; private static String fundir = "fun/"; private static String fgldir = "fgl/"; public String getServer() //Return the current address of a server //that has category and functor files { return(server); } public String getCatDir() //Return the directory on the server //that contains *.cat files { return(catdir); } public String getCglDir() //Return the directory on the server //that contains *.cgl files { return(cgldir); } public String getFunDir() //Return the directory on the server //that contains *.fun files { return(fundir); } public String getFglDir() //Return the directory on the server //that contains *.fgl files { return(fgldir); } public void setServer(String s) //Change the address of the server { //Change local server address server = s; //If the server settings section of the initialization //file exists change server address in the file if (iFile.setHeader("Server Settings")) { iFile.addItem("address", server); } else rewriteServerSettings(); if (!iFile.writeIni(filename)) { //Display message error writing ini file } } public void setCatDir(String dir) //Change the directory that category files (*.cat) //are stored in on the server { //Change local category directory catdir = dir; //If the server settings section of the initialization //file exists change category directory in the file if (iFile.setHeader("Server Settings")) { iFile.addItem("catDirectory", catdir); } else rewriteServerSettings(); if (!iFile.writeIni(filename)) { //Display message error writing ini file } } public void setCglDir(String dir) //Change the directory that category files (*.cgl) //are stored in on the server { //Change local category directory cgldir = dir; //If the server settings section of the initialization //file exists change category directory in the file if (iFile.setHeader("Server Settings")) { iFile.addItem("cglDirectory", cgldir); } else rewriteServerSettings(); if (!iFile.writeIni(filename)) { //Display message error writing ini file } } public void setFunDir(String dir) //Change the directory that functor files (*.fun) //are stored in on the server { //Change local category directory fundir = dir; //If the server settings section of the initialization //file exists change category directory in the file if (iFile.setHeader("Server Settings")) { iFile.addItem("funDirectory", fundir); } else rewriteServerSettings(); if (!iFile.writeIni(filename)) { //Display message error writing ini file } } public void setFglDir(String dir) //Change the directory that functor files (*.fgl) //are stored in on the server { //Change local category directory fgldir = dir; //If the server settings section of the initialization //file exists change category directory in the file if (iFile.setHeader("Server Settings")) { iFile.addItem("fglDirectory", fgldir); } else rewriteServerSettings(); if (!iFile.writeIni(filename)) { //Display message error writing ini file } } public void readServerSettings() //Read in the server and directory information //from the GDCT initialization file { if (iFile.setHeader("Server Settings")) { //Get server addres from the initialization file server = iFile.getItem("address"); //Get category directories from the initialization file catdir = iFile.getItem("catDirectory"); cgldir = iFile.getItem("cglDirectory"); //Get functor directories from the initialization file fundir = iFile.getItem("funDirectory"); fgldir = iFile.getItem("fglDirectory"); } } public void rewriteServerSettings() //Rewrite the server settings section of the GDCT //initialization file { //Display message //Create Server Settings section iFile.addHeader("Server Settings"); //iFile.setHeader("Server Settings"); //Server and directory information iFile.addItem("address", server); iFile.addItem("catDirectory", catdir); iFile.addItem("cglDirectory", cgldir); iFile.addItem("funDirectory", fundir); iFile.addItem("fglDirectory", fgldir); } //------------------------------------------------------------------------------ //---------------------------Recent Files Settings------------------------------ //------------------------------------------------------------------------------ public void rewriteRecentFiles() //Rewrite the recent files list in the gdct initialization file { //Create Recent Files section iFile.addHeader("Recent Files"); iFile.setHeader("Recent Files"); //Add recent files for (int i=1; i <= 8; i++) { iFile.addItem("recent" + i, "none"); recent[i-1] = ""; } } public void readRecentFiles() //Reads in all the records in the file input //and stores them in a linked list { if (!iFile.setHeader("Recent Files")) { rewriteRecentFiles(); iFile.setHeader("Recent Files"); } for (int i=1; i<=8; i++) { recent[i-1] = iFile.getItem("recent" + Integer.toString(i)); if (recent[i-1].endsWith("none")) recent[i-1] = ""; } } public void setRecent(int num, String value) { if (!iFile.setHeader("Recent Files")) { rewriteRecentFiles(); iFile.setHeader("Recent Files"); } if (num >= 1 && num <= 8) { recent[num-1] = value; iFile.addItem("recent" + num, value); if (!iFile.writeIni(filename)) { //Display message error writing ini file //new MessageDialog(new Frame(), "Error", "Unable to write GDCT initialization file.", true); } } } public String getRecent(int num) // returns recent file number num, where num is between 1 and 8 { iFile.setHeader("Recent Files"); if (num < 1 || num > 8) return new String(); return recent[num-1]; } }