Subversion Repositories svn.mios

Rev

Rev 873 | 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;
874 adamjking 22
import java.awt.Rectangle;
628 adamjking 23
import java.awt.Toolkit;
24
import java.awt.event.ActionEvent;
25
import java.awt.event.ActionListener;
870 adamjking 26
import java.awt.event.ContainerEvent;
27
import java.awt.event.ContainerListener;
628 adamjking 28
import java.awt.event.KeyEvent;
873 adamjking 29
import java.awt.event.WindowAdapter;
30
import java.awt.event.WindowEvent;
722 adamjking 31
import java.io.File;
628 adamjking 32
 
33
import javax.swing.JApplet;
34
import javax.swing.JFrame;
874 adamjking 35
import javax.swing.JMenu;
36
import javax.swing.JMenuBar;
628 adamjking 37
import javax.swing.JMenuItem;
874 adamjking 38
import javax.swing.SwingUtilities;
870 adamjking 39
import javax.swing.UIManager;
628 adamjking 40
 
41
import org.midibox.apps.miosstudio.gui.MIOSStudioGUI;
741 adamjking 42
import org.midibox.apps.miosstudio.gui.xml.MIOSStudioGUIXML;
628 adamjking 43
import org.midibox.utils.gui.DialogOwner;
44
import org.midibox.utils.gui.ImageLoader;
45
import org.midibox.utils.gui.SplashScreen;
46
 
874 adamjking 47
import com.apple.mrj.MRJApplicationUtils;
48
import com.apple.mrj.MRJQuitHandler;
873 adamjking 49
 
633 adamjking 50
/**
642 adamjking 51
 * Driver class for launching MIOS Studio application. MIOS Studio can be
52
 * launched as an application or embedded in a a web page as an applet. When
53
 * launched as an application, the app shows a splash screen and is launched
54
 * within its own frame. Preferences are saved and restored from this class.
633 adamjking 55
 *
56
 * @author Adam King (adamjking@optusnet.com.au)
57
 */
58
 
628 adamjking 59
public class MIOSStudio extends JApplet {
60
 
762 adamjking 61
    protected static String oldConfigFileName = ".miosstudio";
738 adamjking 62
 
762 adamjking 63
    protected static String configDirectoryName = ".midibox";
64
 
65
    protected static String configFileName = "miosstudio.xml";
66
 
628 adamjking 67
    protected static String frameTitle = "MIOS Studio";
68
 
857 tk 69
    protected static String splashTitle = "MIOS Studio beta 9.4";
628 adamjking 70
 
71
    protected static String splashImage = "splash.jpg";
72
 
857 tk 73
    protected static String frameComment = "MIOS Studio beta 9.4";
723 adamjking 74
 
628 adamjking 75
    protected org.midibox.apps.miosstudio.MIOSStudio miosStudio;
723 adamjking 76
 
628 adamjking 77
    protected MIOSStudioGUI miosStudioGUI;
78
 
79
    public MIOSStudio() {
80
 
81
        this.miosStudio = new org.midibox.apps.miosstudio.MIOSStudio();
738 adamjking 82
 
762 adamjking 83
        File configDirectory = new File(System.getProperty("user.home"),
84
                configDirectoryName);
85
 
86
        File configFile = new File(configDirectory, configFileName);
87
 
741 adamjking 88
        if (configFile.exists()) {
628 adamjking 89
 
741 adamjking 90
            MIOSStudioGUIXML miosStudioGUIXML = new MIOSStudioGUIXML(
762 adamjking 91
                    miosStudio, MIOSStudioGUIXML.TAG_ROOT_ELEMENT, true, true,
92
                    true, true, true);
741 adamjking 93
 
94
            miosStudioGUIXML.loadXML(configFile);
95
 
96
            this.miosStudioGUI = miosStudioGUIXML.getMiosStudioGUI();
762 adamjking 97
 
98
        } else {
99
 
100
            // check for old config file
101
 
102
            configFile = new File(System.getProperty("user.home"),
103
                    oldConfigFileName);
104
 
105
            if (configFile.exists()) {
106
 
107
                MIOSStudioGUIXML miosStudioGUIXML = new MIOSStudioGUIXML(
108
                        miosStudio, MIOSStudioGUIXML.TAG_ROOT_ELEMENT, true,
109
                        true, true, true, true);
110
 
111
                miosStudioGUIXML.loadXML(configFile);
112
 
113
                this.miosStudioGUI = miosStudioGUIXML.getMiosStudioGUI();
114
 
115
                configFile.delete();
116
            }
628 adamjking 117
        }
118
 
741 adamjking 119
        if (miosStudioGUI == null) {
628 adamjking 120
 
741 adamjking 121
            this.miosStudioGUI = new MIOSStudioGUI(miosStudio);
122
        }
628 adamjking 123
 
124
        setContentPane(miosStudioGUI);
741 adamjking 125
 
870 adamjking 126
        if (miosStudioGUI.isMDI()) {
762 adamjking 127
 
870 adamjking 128
            miosStudioGUI.setCommentLabel(frameComment);
129
        }
628 adamjking 130
    }
131
 
132
    public void init() {
870 adamjking 133
        setJMenuBar(miosStudioGUI.createMenuBar());
628 adamjking 134
    }
135
 
136
    public void destroy() {
137
 
762 adamjking 138
        File configDirectory = new File(System.getProperty("user.home"),
139
                configDirectoryName);
723 adamjking 140
 
762 adamjking 141
        File configFile = new File(configDirectory, configFileName);
142
 
143
        if (!configDirectory.exists()) {
144
 
145
            try {
146
 
147
                configDirectory.mkdir();
148
 
149
            } catch (Exception e) {
150
 
151
                e.printStackTrace();
152
            }
153
        }
154
 
723 adamjking 155
        if (!configFile.exists()) {
741 adamjking 156
 
722 adamjking 157
            try {
741 adamjking 158
 
722 adamjking 159
                configFile.createNewFile();
741 adamjking 160
 
723 adamjking 161
            } catch (Exception e) {
741 adamjking 162
 
722 adamjking 163
                e.printStackTrace();
164
            }
165
        }
723 adamjking 166
 
167
        if (configFile.exists()) {
168
 
741 adamjking 169
            MIOSStudioGUIXML miosStudioGUIXML = new MIOSStudioGUIXML(
170
                    miosStudioGUI, MIOSStudioGUIXML.TAG_ROOT_ELEMENT, true,
757 adamjking 171
                    true, true, true, true);
723 adamjking 172
 
741 adamjking 173
            miosStudioGUIXML.saveXML(configFile);
722 adamjking 174
        }
175
    }
723 adamjking 176
 
628 adamjking 177
    public static void main(String[] args) {
738 adamjking 178
 
870 adamjking 179
        System.setProperty("apple.laf.useScreenMenuBar", "true");
180
 
628 adamjking 181
        SplashScreen splashScreen = new SplashScreen(splashImage, splashTitle);
182
 
183
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
184
 
185
        splashScreen.setLocation(
186
                (screenSize.width - splashScreen.getWidth()) / 2,
187
                (screenSize.height - splashScreen.getHeight()) / 2);
188
 
189
        splashScreen.setVisible(true);
190
 
191
        final JFrame frame = new JFrame(frameTitle);
738 adamjking 192
 
628 adamjking 193
        DialogOwner.setFrame(frame);
194
 
741 adamjking 195
        frame.setIconImage(ImageLoader.getImageIcon("ucIcon.png").getImage());
196
 
874 adamjking 197
        frame.setBounds(new Rectangle(0, 0, 0, 0));
762 adamjking 198
 
874 adamjking 199
        frame.setVisible(true);
200
 
628 adamjking 201
        final MIOSStudio miosStudio = new MIOSStudio();
741 adamjking 202
 
874 adamjking 203
        frame.setContentPane(miosStudio);
204
 
870 adamjking 205
        if (System.getProperty("mrj.version") == null) {
628 adamjking 206
 
870 adamjking 207
            JMenuItem exitMenuItem = new JMenuItem("Exit");
208
            exitMenuItem.setMnemonic(KeyEvent.VK_X);
209
            exitMenuItem.setActionCommand("exit");
628 adamjking 210
 
870 adamjking 211
            exitMenuItem.addActionListener(new ActionListener() {
212
                public void actionPerformed(ActionEvent ae) {
628 adamjking 213
 
873 adamjking 214
                    miosStudio.destroy();
874 adamjking 215
 
870 adamjking 216
                    System.exit(0);
217
                }
218
            });
874 adamjking 219
 
220
            JMenuBar menuBar = miosStudio.miosStudioGUI.createMenuBar();
221
 
222
            JMenu fileMenu = (JMenu) menuBar.getComponent(0);
223
 
224
            fileMenu.add(exitMenuItem);
225
 
226
            miosStudio.setJMenuBar(menuBar);
227
 
873 adamjking 228
            frame.addWindowListener(new WindowAdapter() {
229
                public void windowClosing(WindowEvent we) {
741 adamjking 230
 
873 adamjking 231
                    miosStudio.destroy();
232
 
233
                    System.exit(0);
234
                }
235
            });
236
 
870 adamjking 237
        } else {
238
 
239
            frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
873 adamjking 240
 
874 adamjking 241
            MRJApplicationUtils.registerQuitHandler(new MRJQuitHandler() {
242
                public void handleQuit() {
243
                    SwingUtilities.invokeLater(new Runnable() {
244
                        public void run() {
245
                            miosStudio.destroy();
246
 
247
                            System.exit(0);
248
                        }
249
                    });
250
                    throw new IllegalStateException(
251
                            "Stop Pending User Confirmation");
873 adamjking 252
                }
874 adamjking 253
            });
873 adamjking 254
 
870 adamjking 255
            if (UIManager.getLookAndFeel().getClass().getName().toString() == UIManager
256
                    .getSystemLookAndFeelClassName()) {
257
 
258
                frame.setJMenuBar(miosStudio.miosStudioGUI.createMenuBar());
628 adamjking 259
            }
260
 
870 adamjking 261
            else {
628 adamjking 262
 
870 adamjking 263
                miosStudio
264
                        .setJMenuBar(miosStudio.miosStudioGUI.createMenuBar());
265
            }
266
        }
267
 
874 adamjking 268
        if (frame.getBounds() == new Rectangle(0, 0, 0, 0)) {
269
 
270
            frame.setBounds(50, 50, (screenSize.width - 100),
271
                    (screenSize.height - 100));
272
        }
273
 
870 adamjking 274
        if (!miosStudio.miosStudioGUI.isMDI()) {
275
 
276
            frame.setResizable(false);
277
 
278
            frame.pack();
279
 
280
            miosStudio.miosStudioGUI.getToolBar().addContainerListener(
281
                    new ContainerListener() {
282
 
283
                        @Override
284
                        public void componentRemoved(ContainerEvent e) {
285
 
286
                            frame.pack();
287
 
288
                        }
289
 
290
                        @Override
291
                        public void componentAdded(ContainerEvent e) {
292
 
293
                            frame.pack();
294
 
295
                        }
296
                    });
297
 
874 adamjking 298
        } else {
299
 
300
            frame.validate();
870 adamjking 301
        }
302
 
628 adamjking 303
        splashScreen.setVisible(false);
870 adamjking 304
 
874 adamjking 305
        frame.requestFocus();
628 adamjking 306
    }
870 adamjking 307
 
628 adamjking 308
}