001    /*
002     * Copyright 2002 - 2007 JEuclid, http://jeuclid.sf.net
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    /* $Id: MathViewer.java,v 4add00437054 2010/01/21 11:39:11 MARIO $ */
018    
019    package net.sourceforge.jeuclid.app.mathviewer;
020    
021    import java.io.File;
022    
023    import javax.swing.JFrame;
024    import javax.swing.SwingUtilities;
025    import javax.swing.UIManager;
026    import javax.swing.UnsupportedLookAndFeelException;
027    
028    import net.sourceforge.jeuclid.Constants;
029    
030    import org.apache.commons.logging.Log;
031    import org.apache.commons.logging.LogFactory;
032    
033    import com.apple.eawt.Application;
034    
035    /**
036     * A simple application for viewing MathML documents.
037    
038     * @version $Revision: 4add00437054 $
039     */
040    public final class MathViewer {
041    
042        /**
043         * Set to true if we're running under Mac OS X.
044         */
045        public static final boolean OSX =
046                System.getProperty("mrj.version") != null; //$NON-NLS-1$
047    
048        /**
049         * Logger for this class.
050         */
051        private static final Log LOGGER = LogFactory.getLog(MathViewer.class);
052    
053        /**
054         * Source file.
055         */
056        private static File source;
057    
058        /**
059         * Default constructor.
060         */
061        private MathViewer() {
062            // Empty on purpose
063        }
064    
065        /**
066         * Launches this application.
067         * @param args
068         *            command line arguments. Ignored.
069         */
070        public static void main(final String[] args) {
071            MathViewer.source = null;
072            if (args.length > 0) {
073                MathViewer.source = new File(args[0]);
074            }
075            if (MathViewer.OSX) {
076                System.setProperty("apple.laf.useScreenMenuBar",
077                        Constants.TRUE); //$NON-NLS-1$ //$NON-NLS-2$
078            }
079    
080            try {
081                UIManager.setLookAndFeel(UIManager
082                        .getSystemLookAndFeelClassName());
083            } catch (final ClassNotFoundException e) {
084                MathViewer.LOGGER.debug(e);
085            } catch (final InstantiationException e) {
086                MathViewer.LOGGER.debug(e);
087            } catch (final IllegalAccessException e) {
088                MathViewer.LOGGER.debug(e);
089            } catch (final UnsupportedLookAndFeelException e) {
090                MathViewer.LOGGER.debug(e);
091            }
092            SwingUtilities.invokeLater(new Runnable() {
093                public void run() {
094                    final MainFrame mainFrame = new MainFrame();
095                    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
096                    if (MathViewer.OSX) {
097                        final Application a = Application.getApplication();
098                        a.setEnabledAboutMenu(true);
099                        a.setEnabledPreferencesMenu(true);
100                        a.addApplicationListener(new MainFrameAppListener(
101                                mainFrame));
102                    }
103                    if (MathViewer.source != null) {
104                        mainFrame.loadFile(MathViewer.source);
105                    }
106                    mainFrame.setVisible(true);
107                }
108            });
109        }
110    }