1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
40
41
42
43
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
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 }