package ie.dcu.apps.ist; import ie.dcu.apps.ist.recent.*; import java.io.*; /** * Manages applications recent files list. * * @author Kevin McGuinness */ public class AppRecentFiles extends RecentFiles { public static final String APP_SETTINGS_PATH = ".ist"; public static final String HISTORY_FILE_NAME = ".history"; private static AppRecentFiles history; private AppRecentFiles(File store) { super(store); } public static AppRecentFiles getInstance() { if (history == null) { history = create(); } return history; } private static AppRecentFiles create() { AppRecentFiles history = null; try { history = new AppRecentFiles(getHistoryFile()); history.load(); } catch (IOException e) { getLogger().warning("Unable to create history file: " + e); } return history; } @Override public void load() { try { super.load(); } catch (IOException e) { getLogger().warning("Error loading recent documents list: " + e); } } @Override public void store() { try { super.store(); } catch (IOException e) { getLogger().warning("Error storing recent documents list: " + e); } } private static File getHistoryFile() throws IOException { File file = new File(getSettingsDirectory(), HISTORY_FILE_NAME); if (file.exists()) { // Check we can write if (file.canWrite()) { return file; } } else { return file; } throw new IOException("History file is unwritable"); } private static File getSettingsDirectory() throws IOException { String home = System.getProperty("user.home"); File settings = new File(home, APP_SETTINGS_PATH); if (!settings.exists()) { if (settings.mkdirs()) { return settings; } } else { return settings; } throw new IOException("Unable to create application settings directory"); } }