1 56 package org.objectstyle.cayenne.modeler; 57 58 import java.io.File ; 59 import java.io.FileInputStream ; 60 import java.io.FileOutputStream ; 61 import java.io.IOException ; 62 63 import org.apache.commons.collections.ExtendedProperties; 64 import org.apache.log4j.Logger; 65 import org.objectstyle.cayenne.project.CayenneUserDir; 66 67 74 public class ModelerPreferences extends ExtendedProperties { 75 76 private static final Logger logObj = Logger.getLogger(ModelerPreferences.class); 77 78 79 public static final String PREFERENCES_NAME = "modeler.preferences"; 80 81 82 public static final String LOGFILE_NAME = "modeler.log"; 83 84 86 87 public static final String LAST_PROJ_FILES = "Editor.lastSeveralProjectFiles"; 88 89 90 public static final String EDITOR_LAFNAME = "Editor.lookAndFeel"; 91 public static final String EDITOR_THEMENAME = "Editor.theme"; 92 93 94 public static final String EDITOR_LOGFILE_ENABLED = "Editor.logfileEnabled"; 95 public static final String EDITOR_LOGFILE = "Editor.logfile"; 96 97 protected static ModelerPreferences sharedInstance; 98 99 protected ModelerPreferences() { 100 } 101 102 105 public static ModelerPreferences getPreferences() { 106 if (sharedInstance == null) { 107 sharedInstance = new ModelerPreferences(); 108 sharedInstance.loadPreferences(); 109 } 110 111 return sharedInstance; 112 } 113 114 118 public File preferencesDirectory() { 119 return CayenneUserDir.getInstance().getDirectory(); 120 } 121 122 126 public void storePreferences() { 127 File prefFile = new File (preferencesDirectory(), PREFERENCES_NAME); 128 try { 129 if (!prefFile.exists()) { 130 logObj.debug("Cannot save preferences - file " 131 + prefFile 132 + " does not exist"); 133 return; 134 } 135 save(new FileOutputStream (prefFile), ""); 136 } 137 catch (IOException e) { 138 logObj.debug("Error saving preferences: ", e); 139 } 140 } 141 142 145 public void loadPreferences() { 146 try { 147 File prefsFile = new File (preferencesDirectory(), PREFERENCES_NAME); 148 if (!prefsFile.exists()) { 149 if (!prefsFile.createNewFile()) { 150 logObj.warn("Can't create preferences file " + prefsFile); 151 } 152 } 153 154 load(new FileInputStream (prefsFile)); 155 } 156 catch (IOException e) { 157 logObj.warn("Error creating preferences file.", e); 158 } 159 } 160 161 } | Popular Tags |