Rev 762 | Rev 871 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
733 | adamjking | 1 | /* |
2 | * @(#)MIOSStudioSID.java beta8 2006/04/23 |
||
3 | * |
||
4 | * Copyright (C) 2008 Adam King (adamjking@optusnet.com.au) |
||
5 | * |
||
6 | * This application 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; either version 2 of the License, or |
||
9 | * (at your option) any later version. |
||
10 | * |
||
11 | * This application is distributed in the hope that it will be useful, |
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
14 | * GNU General Public License for more details. |
||
15 | * |
||
16 | * You should have received a copy of the GNU General Public License |
||
17 | * along with this application; if not, write to the Free Software |
||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
19 | */ |
||
20 | |||
628 | adamjking | 21 | import java.awt.Dimension; |
22 | import java.awt.Toolkit; |
||
23 | import java.awt.event.ActionEvent; |
||
24 | import java.awt.event.ActionListener; |
||
25 | import java.awt.event.KeyEvent; |
||
26 | import java.awt.event.WindowAdapter; |
||
27 | import java.awt.event.WindowEvent; |
||
733 | adamjking | 28 | import java.io.File; |
628 | adamjking | 29 | |
733 | adamjking | 30 | import javax.swing.JApplet; |
628 | adamjking | 31 | import javax.swing.JFrame; |
32 | import javax.swing.JMenuItem; |
||
33 | |||
34 | import org.midibox.apps.miosstudiosid.gui.MIOSStudioSIDGUI; |
||
741 | adamjking | 35 | import org.midibox.apps.miosstudiosid.gui.xml.MIOSStudioSIDGUIXML; |
628 | adamjking | 36 | import org.midibox.utils.gui.DialogOwner; |
37 | import org.midibox.utils.gui.ImageLoader; |
||
38 | import org.midibox.utils.gui.SplashScreen; |
||
39 | |||
733 | adamjking | 40 | /** |
741 | adamjking | 41 | * Driver class for launching MIOS Studio application. MIOS Studio can be |
42 | * launched as an application or embedded in a a web page as an applet. When |
||
733 | adamjking | 43 | * launched as an application, the app shows a splash screen and is launched |
44 | * within its own frame. Preferences are saved and restored from this class. |
||
45 | * |
||
46 | * @author Adam King (adamjking@optusnet.com.au) |
||
47 | */ |
||
628 | adamjking | 48 | |
733 | adamjking | 49 | public class MIOSStudioSID extends JApplet { |
50 | |||
762 | adamjking | 51 | protected static String oldConfigFileName = ".miosstudiosid"; |
738 | adamjking | 52 | |
762 | adamjking | 53 | protected static String configDirectoryName = ".midibox"; |
54 | |||
55 | protected static String configFileName = "miosstudiosid.xml"; |
||
56 | |||
658 | adamjking | 57 | protected static String frameTitle = "MIOS Studio + SID V2 Editor"; |
738 | adamjking | 58 | |
808 | adamjking | 59 | protected static String splashTitle = "MIOS Studio beta 9.3 + SID V2 Editor"; |
628 | adamjking | 60 | |
61 | protected static String splashImage = "splash.jpg"; |
||
62 | |||
808 | adamjking | 63 | protected static String frameComment = "MIOS Studio beta 9.3"; |
628 | adamjking | 64 | |
733 | adamjking | 65 | protected org.midibox.apps.miosstudiosid.MIOSStudioSID miosStudioSID; |
628 | adamjking | 66 | |
733 | adamjking | 67 | protected MIOSStudioSIDGUI miosStudioSIDGUI; |
628 | adamjking | 68 | |
733 | adamjking | 69 | public MIOSStudioSID() { |
738 | adamjking | 70 | |
733 | adamjking | 71 | this.miosStudioSID = new org.midibox.apps.miosstudiosid.MIOSStudioSID(); |
757 | adamjking | 72 | |
762 | adamjking | 73 | File configDirectory = new File(System.getProperty("user.home"), |
74 | configDirectoryName); |
||
738 | adamjking | 75 | |
762 | adamjking | 76 | File configFile = new File(configDirectory, configFileName); |
77 | |||
741 | adamjking | 78 | if (configFile.exists()) { |
733 | adamjking | 79 | |
741 | adamjking | 80 | MIOSStudioSIDGUIXML miosStudioSIDGUIXML = new MIOSStudioSIDGUIXML( |
757 | adamjking | 81 | miosStudioSID, MIOSStudioSIDGUIXML.TAG_ROOT_ELEMENT, true, |
82 | true, true, true, true); |
||
628 | adamjking | 83 | |
741 | adamjking | 84 | miosStudioSIDGUIXML.loadXML(configFile); |
628 | adamjking | 85 | |
757 | adamjking | 86 | this.miosStudioSIDGUI = (MIOSStudioSIDGUI) miosStudioSIDGUIXML |
87 | .getMiosStudioGUI(); |
||
88 | |||
762 | adamjking | 89 | } else { |
90 | |||
91 | // check for old config file |
||
92 | |||
93 | configFile = new File(System.getProperty("user.home"), |
||
94 | oldConfigFileName); |
||
95 | |||
96 | if (configFile.exists()) { |
||
97 | |||
98 | MIOSStudioSIDGUIXML miosStudioSIDGUIXML = new MIOSStudioSIDGUIXML( |
||
99 | miosStudioSID, MIOSStudioSIDGUIXML.TAG_ROOT_ELEMENT, |
||
100 | true, true, true, true, true); |
||
101 | |||
102 | miosStudioSIDGUIXML.loadXML(configFile); |
||
103 | |||
104 | this.miosStudioSIDGUI = (MIOSStudioSIDGUI) miosStudioSIDGUIXML |
||
105 | .getMiosStudioGUI(); |
||
106 | |||
107 | configFile.delete(); |
||
108 | } |
||
757 | adamjking | 109 | } |
110 | |||
741 | adamjking | 111 | if (miosStudioSIDGUI == null) { |
628 | adamjking | 112 | |
741 | adamjking | 113 | this.miosStudioSIDGUI = new MIOSStudioSIDGUI(miosStudioSID); |
114 | } |
||
115 | |||
733 | adamjking | 116 | setContentPane(miosStudioSIDGUI); |
741 | adamjking | 117 | |
733 | adamjking | 118 | setJMenuBar(miosStudioSIDGUI.createMenuBar()); |
757 | adamjking | 119 | |
741 | adamjking | 120 | miosStudioSIDGUI.setCommentLabel(frameComment); |
628 | adamjking | 121 | } |
122 | |||
733 | adamjking | 123 | public void init() { |
757 | adamjking | 124 | |
733 | adamjking | 125 | } |
126 | |||
127 | public void destroy() { |
||
128 | |||
762 | adamjking | 129 | File configDirectory = new File(System.getProperty("user.home"), |
130 | configDirectoryName); |
||
733 | adamjking | 131 | |
762 | adamjking | 132 | File configFile = new File(configDirectory, configFileName); |
133 | |||
134 | if (!configDirectory.exists()) { |
||
135 | |||
136 | try { |
||
137 | |||
138 | configDirectory.mkdir(); |
||
139 | |||
140 | } catch (Exception e) { |
||
141 | |||
142 | e.printStackTrace(); |
||
143 | } |
||
144 | } |
||
145 | |||
733 | adamjking | 146 | if (!configFile.exists()) { |
741 | adamjking | 147 | |
733 | adamjking | 148 | try { |
741 | adamjking | 149 | |
733 | adamjking | 150 | configFile.createNewFile(); |
741 | adamjking | 151 | |
733 | adamjking | 152 | } catch (Exception e) { |
741 | adamjking | 153 | |
733 | adamjking | 154 | e.printStackTrace(); |
155 | } |
||
156 | } |
||
157 | |||
158 | if (configFile.exists()) { |
||
159 | |||
741 | adamjking | 160 | MIOSStudioSIDGUIXML miosStudioSIDGUIXML = new MIOSStudioSIDGUIXML( |
757 | adamjking | 161 | miosStudioSIDGUI, MIOSStudioSIDGUIXML.TAG_ROOT_ELEMENT, |
162 | true, true, true, true, true); |
||
733 | adamjking | 163 | |
741 | adamjking | 164 | miosStudioSIDGUIXML.saveXML(configFile); |
733 | adamjking | 165 | } |
166 | } |
||
167 | |||
628 | adamjking | 168 | public static void main(String[] args) { |
738 | adamjking | 169 | |
628 | adamjking | 170 | SplashScreen splashScreen = new SplashScreen(splashImage, splashTitle); |
171 | |||
172 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
||
173 | |||
174 | splashScreen.setLocation( |
||
175 | (screenSize.width - splashScreen.getWidth()) / 2, |
||
176 | (screenSize.height - splashScreen.getHeight()) / 2); |
||
177 | |||
178 | splashScreen.setVisible(true); |
||
179 | |||
180 | final JFrame frame = new JFrame(frameTitle); |
||
738 | adamjking | 181 | |
733 | adamjking | 182 | frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); |
628 | adamjking | 183 | |
184 | DialogOwner.setFrame(frame); |
||
738 | adamjking | 185 | |
741 | adamjking | 186 | frame.setIconImage(ImageLoader.getImageIcon("ucIcon.png").getImage()); |
187 | |||
757 | adamjking | 188 | frame.setBounds(50, 50, (screenSize.width - 100), |
189 | (screenSize.height - 100)); |
||
190 | |||
628 | adamjking | 191 | final MIOSStudioSID miosStudioSID = new MIOSStudioSID(); |
741 | adamjking | 192 | |
628 | adamjking | 193 | miosStudioSID.init(); |
194 | |||
195 | frame.setContentPane(miosStudioSID); |
||
196 | |||
197 | JMenuItem exitMenuItem = new JMenuItem("Exit"); |
||
198 | exitMenuItem.setMnemonic(KeyEvent.VK_X); |
||
199 | exitMenuItem.setActionCommand("exit"); |
||
200 | |||
201 | exitMenuItem.addActionListener(new ActionListener() { |
||
202 | public void actionPerformed(ActionEvent ae) { |
||
757 | adamjking | 203 | |
628 | adamjking | 204 | miosStudioSID.destroy(); |
741 | adamjking | 205 | |
206 | System.exit(0); |
||
628 | adamjking | 207 | } |
208 | }); |
||
209 | |||
733 | adamjking | 210 | miosStudioSID.miosStudioSIDGUI.getFileMenu().add(exitMenuItem); |
628 | adamjking | 211 | |
212 | frame.addWindowListener(new WindowAdapter() { |
||
213 | public void windowClosing(WindowEvent we) { |
||
757 | adamjking | 214 | |
628 | adamjking | 215 | miosStudioSID.destroy(); |
741 | adamjking | 216 | |
217 | System.exit(0); |
||
628 | adamjking | 218 | } |
219 | }); |
||
220 | |||
221 | frame.setVisible(true); |
||
222 | splashScreen.setVisible(false); |
||
223 | } |
||
224 | } |