1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sf.magicproject.ui;
22
23 import java.awt.event.ActionEvent;
24 import java.awt.event.ActionListener;
25 import java.io.File;
26 import java.io.IOException;
27
28 import javax.swing.JOptionPane;
29
30 import net.sf.magicproject.AbstractMainForm;
31 import net.sf.magicproject.Magic;
32 import net.sf.magicproject.token.IdConst;
33 import net.sf.magicproject.tools.Configuration;
34 import net.sf.magicproject.tools.Log;
35 import net.sf.magicproject.tools.MToolKit;
36 import net.sf.magicproject.tools.WebBrowser;
37 import net.sf.magicproject.ui.i18n.LanguageManager;
38 import net.sf.magicproject.xml.XmlConfiguration;
39
40 import org.apache.commons.io.FileUtils;
41
42 /***
43 * An ActionListener that listens to the radio buttons menus
44 *
45 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
46 * @since 0.83
47 * @since 0.85 settings are "per TBS"
48 */
49 public class MdbListener implements ActionListener {
50
51 /***
52 * Create a new instance of MdbListener given an AbstractMainForm instance.
53 *
54 * @param abstractMainForm
55 */
56 public MdbListener(AbstractMainForm abstractMainForm) {
57 this.abstractMainForm = abstractMainForm;
58 }
59
60 /***
61 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
62 */
63 public void actionPerformed(ActionEvent e) {
64 if ("menu_options_tbs_more".equals(e.getActionCommand())) {
65
66 try {
67 WebBrowser
68 .launchBrowser("http://sourceforge.net/project/showfiles.php?group_id=92519&package_id=107882");
69 } catch (Exception e1) {
70 JOptionPane.showOptionDialog(MagicUIComponents.magicForm,
71 LanguageManager.getString("error") + " : " + e1.getMessage(),
72 LanguageManager.getString("web-pb"), JOptionPane.OK_OPTION,
73 JOptionPane.INFORMATION_MESSAGE, UIHelper
74 .getIcon("wiz_update_error.gif"), null, null);
75 }
76 return;
77 }
78 if ("menu_options_tbs_update".equals(e.getActionCommand())) {
79
80 XmlConfiguration.main(new String[] { "-update", MToolKit.tbsName });
81 return;
82 }
83 if ("menu_options_tbs_rebuild".equals(e.getActionCommand())) {
84
85
86
87 XmlConfiguration.main(new String[] { "-full", MToolKit.tbsName });
88 return;
89 }
90
91 if (JOptionPane.YES_OPTION == JOptionPane.showOptionDialog(
92 MagicUIComponents.magicForm, LanguageManager
93 .getString("warn-disconnect"), LanguageManager
94 .getString("disconnect"), JOptionPane.YES_NO_OPTION,
95 JOptionPane.QUESTION_MESSAGE, UIHelper.getIcon("wiz_update.gif"), null,
96 null)) {
97
98
99 Magic.saveSettings();
100 final File propertyFile = new File(IdConst.FILE_SETTINGS);
101 try {
102 FileUtils.copyFile(propertyFile, new File(MToolKit.getTbsFile(
103 IdConst.FILE_SETTINGS_SAVED, false)));
104
105 abstractMainForm.setMdb(e.getActionCommand());
106 Configuration.loadTemplateFile(IdConst.FILE_SETTINGS_SAVED);
107 FileUtils.copyFile(new File(MToolKit.getTbsFile(
108 IdConst.FILE_SETTINGS_SAVED, false)), propertyFile);
109 Log.info("Successfull TBS swith to " + MToolKit.tbsName);
110 System.exit(0);
111 } catch (IOException e1) {
112 e1.printStackTrace();
113 }
114 }
115 }
116
117 /***
118 * The AbstractMainForm instance that would receive the "setMdb(String)"
119 * message.
120 *
121 * @see AbstractMainForm#setMdb(String)
122 */
123 private AbstractMainForm abstractMainForm;
124 }