View Javadoc

1   /**
2    * This program is free software: you can redistribute it and/or modify
3    * it under the terms of the GNU General Public License as published by
4    * the Free Software Foundation, version 3.
5    *
6    * This program is distributed in the hope that it will be useful,
7    * but WITHOUT ANY WARRANTY; without even the implied warranty of
8    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9    * GNU General Public License for more details.
10   *
11   * You should have received a copy of the GNU General Public License
12   * along with this program. If not, see <http://www.gnu.org/licenses/>.
13   */
14  
15  package net.curre.prefcount.event;
16  
17  import java.awt.event.ActionEvent;
18  import java.awt.event.ActionListener;
19  import java.util.logging.Level;
20  import java.util.logging.Logger;
21  
22  import net.curre.prefcount.PrefCountRegistry;
23  import net.curre.prefcount.gui.MainWindow;
24  import net.curre.prefcount.service.ServiceException;
25  import net.curre.prefcount.service.SettingsService;
26  
27  /**
28   * Object of this class represents an action
29   * listener to save or reset current settings.
30   * <p/>
31   * Created date: Jun 22, 2007
32   *
33   * @author Yevgeny Nyden
34   */
35  public class SaveResetSettingsActionListener implements ActionListener {
36  
37    /** Private class logger. */
38    private static Logger log = Logger.getLogger(SaveResetSettingsActionListener.class.toString());
39  
40    /**
41     * Flag to indicate the save action (when true)
42     * or reset action (when false).
43     */
44    private boolean isSave;
45  
46    /**
47     * Constructor.
48     *
49     * @param isSave True if this is a save action;
50     *               false if this is a reset action.
51     */
52    public SaveResetSettingsActionListener(boolean isSave) {
53      this.isSave = isSave;
54    }
55  
56    /** {@inheritDoc} */
57    public void actionPerformed(ActionEvent actionEvent) {
58      try {
59        if (isSave) {
60          SettingsService.saveSettings();
61        } else {
62          SettingsService.resetSettings();
63          MainWindow win = PrefCountRegistry.getInstance().getMainWindow();
64          win.repaint(); // this will also repaint the player dialog frame
65        }
66      } catch (ServiceException e) {
67        log.log(Level.WARNING, "Unable to perform save/reset action!", e);
68      }
69    }
70  
71  }