View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.gui.action;
21  
22  import java.awt.event.ActionEvent;
23  import java.io.File;
24  
25  import javax.swing.AbstractAction;
26  import javax.swing.*;
27  
28  import org.xnap.XNap;
29  import org.xnap.gui.XNapFrame;
30  import org.xnap.gui.util.IconHelper;
31  import org.xnap.util.*;
32  
33  /***
34   * Provides an action that shows the about dialog.
35   */
36  public class ResetPreferencesAction extends AbstractAction 
37  {
38      
39      //--- Constant(s) ---
40      
41      //--- Data field(s) ---
42      
43      //--- Constructor(s) ---
44      
45      public ResetPreferencesAction()
46      {
47  		putValue(Action.NAME, XNap.tr("Reset Preferences"));
48  		putValue(IconHelper.XNAP_ICON, "stop_hand.png");
49  		putValue(Action.SHORT_DESCRIPTION, 
50  				 XNap.tr("Resets all settings and exits XNap."));
51      }
52  
53      //--- Method(s) ---
54          
55      public void actionPerformed(ActionEvent event) 
56      {
57  		int response = JOptionPane.showConfirmDialog
58  			(XNapFrame.getInstance(),
59  			 XNap.tr("This will reset all settings and quit XNap. Please make sure all transfers are stopped."),
60  			 XNap.tr("Reset Preferences"),
61  			 JOptionPane.OK_CANCEL_OPTION);
62  		if (response == JOptionPane.OK_OPTION) {
63  			renamePreferences(Preferences.XNAP1_FILENAME);
64  			renamePreferences(Preferences.XNAP2_FILENAME);
65  			renamePreferences(Preferences.XNAP3_FILENAME);
66  			
67  			System.exit(0);
68  		}
69      }
70  
71  	private void renamePreferences(String filename)
72  	{
73  		File file = new File(FileHelper.getHomeDir() + filename);
74  		if (file.exists()) {
75  			File backupFile
76  				= new File(FileHelper.getHomeDir() + filename + ".save");
77  			if (backupFile.exists()) {
78  				backupFile.delete();
79  			}
80  			file.renameTo(backupFile);
81  		}
82  	}
83      
84  }