// This file is part of Penn TotalRecall <http://memory.psych.upenn.edu/TotalRecall>. // // TotalRecall is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, version 3 only. // // TotalRecall is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with TotalRecall. If not, see <http://www.gnu.org/licenses/>. package components.preferences; import java.awt.event.ActionEvent; import java.awt.event.WindowEvent; import java.util.ArrayList; import javax.swing.AbstractAction; import util.GiveMessage; /** * Restores all preferences to their factory defaults. * * @author Yuvi Masory */ public class RestoreDefaultsAction extends AbstractAction { /** * Recurses through all <code>AbstractPreferenceDisplays</code>, and restores them to their defaults. * Afterward notifies user of success and hides the <code>PreferencesFrame</code>. * * @param e The <code>ActionEvent</code> generated by the trigger */ public void actionPerformed(ActionEvent e) { ArrayList<AbstractPreferenceDisplay> allPrefs = PreferencesFrame.getInstance().getAbstractPreferences(); for(int i = 0; i < allPrefs.size(); i++) { allPrefs.get(i).restoreDefault(); } GiveMessage.infoMessage("All preferences successfully restored to defaults."); //safer than directly using setVisible(false), since this double checks the assumption that all preferences are saved PreferencesFrame.getInstance().windowClosing(new WindowEvent(PreferencesFrame.getInstance(), WindowEvent.WINDOW_CLOSING)); } }