Subversion Repositories svn.mios

Rev

Rev 871 | 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;
733 adamjking 26
import java.io.File;
628 adamjking 27
 
733 adamjking 28
import javax.swing.JApplet;
628 adamjking 29
import javax.swing.JFrame;
30
import javax.swing.JMenuItem;
871 adamjking 31
import javax.swing.UIManager;
628 adamjking 32
 
33
import org.midibox.apps.miosstudiosid.gui.MIOSStudioSIDGUI;
741 adamjking 34
import org.midibox.apps.miosstudiosid.gui.xml.MIOSStudioSIDGUIXML;
628 adamjking 35
import org.midibox.utils.gui.DialogOwner;
36
import org.midibox.utils.gui.ImageLoader;
37
import org.midibox.utils.gui.SplashScreen;
38
 
733 adamjking 39
/**
741 adamjking 40
 * Driver class for launching MIOS Studio application. MIOS Studio can be
41
 * launched as an application or embedded in a a web page as an applet. When
733 adamjking 42
 * launched as an application, the app shows a splash screen and is launched
43
 * within its own frame. Preferences are saved and restored from this class.
44
 *
45
 * @author Adam King (adamjking@optusnet.com.au)
46
 */
628 adamjking 47
 
733 adamjking 48
public class MIOSStudioSID extends JApplet {
49
 
762 adamjking 50
    protected static String oldConfigFileName = ".miosstudiosid";
738 adamjking 51
 
762 adamjking 52
    protected static String configDirectoryName = ".midibox";
53
 
54
    protected static String configFileName = "miosstudiosid.xml";
55
 
658 adamjking 56
    protected static String frameTitle = "MIOS Studio + SID V2 Editor";
738 adamjking 57
 
808 adamjking 58
    protected static String splashTitle = "MIOS Studio beta 9.3 + SID V2 Editor";
628 adamjking 59
 
60
    protected static String splashImage = "splash.jpg";
61
 
808 adamjking 62
    protected static String frameComment = "MIOS Studio beta 9.3";
628 adamjking 63
 
733 adamjking 64
    protected org.midibox.apps.miosstudiosid.MIOSStudioSID miosStudioSID;
628 adamjking 65
 
733 adamjking 66
    protected MIOSStudioSIDGUI miosStudioSIDGUI;
628 adamjking 67
 
733 adamjking 68
    public MIOSStudioSID() {
738 adamjking 69
 
733 adamjking 70
        this.miosStudioSID = new org.midibox.apps.miosstudiosid.MIOSStudioSID();
757 adamjking 71
 
762 adamjking 72
        File configDirectory = new File(System.getProperty("user.home"),
73
                configDirectoryName);
738 adamjking 74
 
762 adamjking 75
        File configFile = new File(configDirectory, configFileName);
76
 
741 adamjking 77
        if (configFile.exists()) {
733 adamjking 78
 
741 adamjking 79
            MIOSStudioSIDGUIXML miosStudioSIDGUIXML = new MIOSStudioSIDGUIXML(
757 adamjking 80
                    miosStudioSID, MIOSStudioSIDGUIXML.TAG_ROOT_ELEMENT, true,
81
                    true, true, true, true);
628 adamjking 82
 
741 adamjking 83
            miosStudioSIDGUIXML.loadXML(configFile);
628 adamjking 84
 
757 adamjking 85
            this.miosStudioSIDGUI = (MIOSStudioSIDGUI) miosStudioSIDGUIXML
86
                    .getMiosStudioGUI();
87
 
762 adamjking 88
        } else {
89
 
90
            // check for old config file
91
 
92
            configFile = new File(System.getProperty("user.home"),
93
                    oldConfigFileName);
94
 
95
            if (configFile.exists()) {
96
 
97
                MIOSStudioSIDGUIXML miosStudioSIDGUIXML = new MIOSStudioSIDGUIXML(
98
                        miosStudioSID, MIOSStudioSIDGUIXML.TAG_ROOT_ELEMENT,
99
                        true, true, true, true, true);
100
 
101
                miosStudioSIDGUIXML.loadXML(configFile);
102
 
103
                this.miosStudioSIDGUI = (MIOSStudioSIDGUI) miosStudioSIDGUIXML
104
                        .getMiosStudioGUI();
105
 
106
                configFile.delete();
107
            }
757 adamjking 108
        }
109
 
741 adamjking 110
        if (miosStudioSIDGUI == null) {
628 adamjking 111
 
741 adamjking 112
            this.miosStudioSIDGUI = new MIOSStudioSIDGUI(miosStudioSID);
113
        }
114
 
733 adamjking 115
        setContentPane(miosStudioSIDGUI);
741 adamjking 116
 
117
        miosStudioSIDGUI.setCommentLabel(frameComment);
628 adamjking 118
    }
119
 
733 adamjking 120
    public void init() {
757 adamjking 121
 
871 adamjking 122
        setJMenuBar(miosStudioSIDGUI.createMenuBar());
733 adamjking 123
    }
124
 
125
    public void destroy() {
126
 
762 adamjking 127
        File configDirectory = new File(System.getProperty("user.home"),
128
                configDirectoryName);
733 adamjking 129
 
762 adamjking 130
        File configFile = new File(configDirectory, configFileName);
131
 
132
        if (!configDirectory.exists()) {
133
 
134
            try {
135
 
136
                configDirectory.mkdir();
137
 
138
            } catch (Exception e) {
139
 
140
                e.printStackTrace();
141
            }
142
        }
143
 
733 adamjking 144
        if (!configFile.exists()) {
741 adamjking 145
 
733 adamjking 146
            try {
741 adamjking 147
 
733 adamjking 148
                configFile.createNewFile();
741 adamjking 149
 
733 adamjking 150
            } catch (Exception e) {
741 adamjking 151
 
733 adamjking 152
                e.printStackTrace();
153
            }
154
        }
155
 
156
        if (configFile.exists()) {
157
 
741 adamjking 158
            MIOSStudioSIDGUIXML miosStudioSIDGUIXML = new MIOSStudioSIDGUIXML(
757 adamjking 159
                    miosStudioSIDGUI, MIOSStudioSIDGUIXML.TAG_ROOT_ELEMENT,
160
                    true, true, true, true, true);
733 adamjking 161
 
741 adamjking 162
            miosStudioSIDGUIXML.saveXML(configFile);
733 adamjking 163
        }
164
    }
165
 
628 adamjking 166
    public static void main(String[] args) {
738 adamjking 167
 
628 adamjking 168
        SplashScreen splashScreen = new SplashScreen(splashImage, splashTitle);
169
 
170
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
171
 
172
        splashScreen.setLocation(
173
                (screenSize.width - splashScreen.getWidth()) / 2,
174
                (screenSize.height - splashScreen.getHeight()) / 2);
175
 
176
        splashScreen.setVisible(true);
177
 
178
        final JFrame frame = new JFrame(frameTitle);
738 adamjking 179
 
871 adamjking 180
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
628 adamjking 181
 
182
        DialogOwner.setFrame(frame);
738 adamjking 183
 
741 adamjking 184
        frame.setIconImage(ImageLoader.getImageIcon("ucIcon.png").getImage());
185
 
757 adamjking 186
        frame.setBounds(50, 50, (screenSize.width - 100),
187
                (screenSize.height - 100));
188
 
628 adamjking 189
        final MIOSStudioSID miosStudioSID = new MIOSStudioSID();
741 adamjking 190
 
871 adamjking 191
        if (System.getProperty("mrj.version") == null) {
628 adamjking 192
 
871 adamjking 193
            JMenuItem exitMenuItem = new JMenuItem("Exit");
194
            exitMenuItem.setMnemonic(KeyEvent.VK_X);
195
            exitMenuItem.setActionCommand("exit");
628 adamjking 196
 
871 adamjking 197
            exitMenuItem.addActionListener(new ActionListener() {
198
                public void actionPerformed(ActionEvent ae) {
628 adamjking 199
 
871 adamjking 200
                    System.exit(0);
201
                }
202
            });
757 adamjking 203
 
874 adamjking 204
            // miosStudioSID.miosStudioSIDGUI.getFileMenu().add(exitMenuItem);
741 adamjking 205
 
871 adamjking 206
            miosStudioSID.setJMenuBar(miosStudioSID.miosStudioSIDGUI
207
                    .createMenuBar());
208
 
209
        } else {
210
 
211
            if (UIManager.getLookAndFeel().getClass().getName().toString() == UIManager
212
                    .getSystemLookAndFeelClassName()) {
213
 
214
                System.setProperty("apple.laf.useScreenMenuBar", "true");
215
 
216
                frame.setJMenuBar(miosStudioSID.miosStudioSIDGUI
217
                        .createMenuBar());
628 adamjking 218
            }
219
 
871 adamjking 220
            else {
628 adamjking 221
 
871 adamjking 222
                miosStudioSID.setJMenuBar(miosStudioSID.miosStudioSIDGUI
223
                        .createMenuBar());
224
            }
225
        }
757 adamjking 226
 
871 adamjking 227
        Runtime.getRuntime().addShutdownHook(new Thread() {
228
 
229
            public void run() {
628 adamjking 230
                miosStudioSID.destroy();
871 adamjking 231
            }
741 adamjking 232
 
628 adamjking 233
        });
234
 
871 adamjking 235
        frame.setContentPane(miosStudioSID);
236
 
628 adamjking 237
        frame.setVisible(true);
871 adamjking 238
 
628 adamjking 239
        splashScreen.setVisible(false);
240
    }
241
}