Subversion Repositories svn.mios

Rev

Rev 808 | Rev 870 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
628 adamjking 1
/*
741 adamjking 2
 * @(#)MIOSStudio.java  beta8   2006/04/23
628 adamjking 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
 
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;
722 adamjking 28
import java.io.File;
628 adamjking 29
 
30
import javax.swing.JApplet;
31
import javax.swing.JFrame;
32
import javax.swing.JMenuItem;
33
 
34
import org.midibox.apps.miosstudio.gui.MIOSStudioGUI;
741 adamjking 35
import org.midibox.apps.miosstudio.gui.xml.MIOSStudioGUIXML;
628 adamjking 36
import org.midibox.utils.gui.DialogOwner;
37
import org.midibox.utils.gui.ImageLoader;
38
import org.midibox.utils.gui.SplashScreen;
39
 
633 adamjking 40
/**
642 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
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.
633 adamjking 45
 *
46
 * @author Adam King (adamjking@optusnet.com.au)
47
 */
48
 
628 adamjking 49
public class MIOSStudio extends JApplet {
50
 
762 adamjking 51
    protected static String oldConfigFileName = ".miosstudio";
738 adamjking 52
 
762 adamjking 53
    protected static String configDirectoryName = ".midibox";
54
 
55
    protected static String configFileName = "miosstudio.xml";
56
 
628 adamjking 57
    protected static String frameTitle = "MIOS Studio";
58
 
857 tk 59
    protected static String splashTitle = "MIOS Studio beta 9.4";
628 adamjking 60
 
61
    protected static String splashImage = "splash.jpg";
62
 
857 tk 63
    protected static String frameComment = "MIOS Studio beta 9.4";
723 adamjking 64
 
628 adamjking 65
    protected org.midibox.apps.miosstudio.MIOSStudio miosStudio;
723 adamjking 66
 
628 adamjking 67
    protected MIOSStudioGUI miosStudioGUI;
68
 
69
    public MIOSStudio() {
70
 
71
        this.miosStudio = new org.midibox.apps.miosstudio.MIOSStudio();
738 adamjking 72
 
762 adamjking 73
        File configDirectory = new File(System.getProperty("user.home"),
74
                configDirectoryName);
75
 
76
        File configFile = new File(configDirectory, configFileName);
77
 
741 adamjking 78
        if (configFile.exists()) {
628 adamjking 79
 
741 adamjking 80
            MIOSStudioGUIXML miosStudioGUIXML = new MIOSStudioGUIXML(
762 adamjking 81
                    miosStudio, MIOSStudioGUIXML.TAG_ROOT_ELEMENT, true, true,
82
                    true, true, true);
741 adamjking 83
 
84
            miosStudioGUIXML.loadXML(configFile);
85
 
86
            this.miosStudioGUI = miosStudioGUIXML.getMiosStudioGUI();
762 adamjking 87
 
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
                MIOSStudioGUIXML miosStudioGUIXML = new MIOSStudioGUIXML(
98
                        miosStudio, MIOSStudioGUIXML.TAG_ROOT_ELEMENT, true,
99
                        true, true, true, true);
100
 
101
                miosStudioGUIXML.loadXML(configFile);
102
 
103
                this.miosStudioGUI = miosStudioGUIXML.getMiosStudioGUI();
104
 
105
                configFile.delete();
106
            }
628 adamjking 107
        }
108
 
741 adamjking 109
        if (miosStudioGUI == null) {
628 adamjking 110
 
741 adamjking 111
            this.miosStudioGUI = new MIOSStudioGUI(miosStudio);
112
        }
628 adamjking 113
 
114
        setContentPane(miosStudioGUI);
741 adamjking 115
 
628 adamjking 116
        setJMenuBar(miosStudioGUI.createMenuBar());
762 adamjking 117
 
741 adamjking 118
        miosStudioGUI.setCommentLabel(frameComment);
628 adamjking 119
    }
120
 
121
    public void init() {
762 adamjking 122
 
628 adamjking 123
    }
124
 
125
    public void destroy() {
126
 
762 adamjking 127
        File configDirectory = new File(System.getProperty("user.home"),
128
                configDirectoryName);
723 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
 
723 adamjking 144
        if (!configFile.exists()) {
741 adamjking 145
 
722 adamjking 146
            try {
741 adamjking 147
 
722 adamjking 148
                configFile.createNewFile();
741 adamjking 149
 
723 adamjking 150
            } catch (Exception e) {
741 adamjking 151
 
722 adamjking 152
                e.printStackTrace();
153
            }
154
        }
723 adamjking 155
 
156
        if (configFile.exists()) {
157
 
741 adamjking 158
            MIOSStudioGUIXML miosStudioGUIXML = new MIOSStudioGUIXML(
159
                    miosStudioGUI, MIOSStudioGUIXML.TAG_ROOT_ELEMENT, true,
757 adamjking 160
                    true, true, true, true);
723 adamjking 161
 
741 adamjking 162
            miosStudioGUIXML.saveXML(configFile);
722 adamjking 163
        }
164
    }
723 adamjking 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
 
732 adamjking 180
        frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
628 adamjking 181
 
182
        DialogOwner.setFrame(frame);
183
 
741 adamjking 184
        frame.setIconImage(ImageLoader.getImageIcon("ucIcon.png").getImage());
185
 
762 adamjking 186
        frame.setBounds(50, 50, (screenSize.width - 100),
187
                (screenSize.height - 100));
188
 
628 adamjking 189
        final MIOSStudio miosStudio = new MIOSStudio();
741 adamjking 190
 
628 adamjking 191
        miosStudio.init();
192
 
193
        frame.setContentPane(miosStudio);
194
 
195
        JMenuItem exitMenuItem = new JMenuItem("Exit");
196
        exitMenuItem.setMnemonic(KeyEvent.VK_X);
197
        exitMenuItem.setActionCommand("exit");
198
 
199
        exitMenuItem.addActionListener(new ActionListener() {
200
            public void actionPerformed(ActionEvent ae) {
762 adamjking 201
 
628 adamjking 202
                miosStudio.destroy();
741 adamjking 203
 
204
                System.exit(0);
628 adamjking 205
            }
206
        });
207
 
208
        miosStudio.miosStudioGUI.getFileMenu().add(exitMenuItem);
209
 
210
        frame.addWindowListener(new WindowAdapter() {
211
            public void windowClosing(WindowEvent we) {
762 adamjking 212
 
628 adamjking 213
                miosStudio.destroy();
741 adamjking 214
 
215
                System.exit(0);
628 adamjking 216
            }
217
        });
218
 
219
        frame.setVisible(true);
220
        splashScreen.setVisible(false);
221
    }
222
}