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 310 2007-05-18 20:26:36Z maxberger $ */
018    
019    package net.sourceforge.jeuclid.app;
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.MathBase;
029    import net.sourceforge.jeuclid.app.mathviewer.FileIO;
030    import net.sourceforge.jeuclid.app.mathviewer.MainFrame;
031    import net.sourceforge.jeuclid.app.support.CommandLineParser;
032    
033    import org.apache.commons.logging.Log;
034    import org.apache.commons.logging.LogFactory;
035    
036    /**
037     * A simple application for viewing MathML documents.
038     * 
039     * @author Max Berger
040     * @version $Revision: 310 $
041     */
042    public final class MathViewer {
043    
044        /**
045         * Set to true if we're running under Mac OS X.
046         */
047        public static final boolean OSX = System.getProperty("mrj.version") != null; //$NON-NLS-1$
048    
049        /**
050         * Logger for this class
051         */
052        private static final Log LOGGER = LogFactory.getLog(MathViewer.class);
053    
054        private static File source;
055    
056        private MathViewer() {
057            // Empty on purpose
058        }
059    
060        /**
061         * Launches this application.
062         * 
063         * @param args
064         *            command line arguments. Ignored.
065         */
066        public static void main(final String[] args) {
067    
068            final CommandLineParser.ParseResults parseResults = CommandLineParser
069                    .parseCommandLine(args);
070            MathViewer.source = parseResults.getSource();
071            if (MathViewer.OSX) {
072                System.setProperty("apple.laf.useScreenMenuBar", MathBase.TRUE); //$NON-NLS-1$ //$NON-NLS-2$
073            }
074    
075            try {
076                UIManager.setLookAndFeel(UIManager
077                        .getSystemLookAndFeelClassName());
078            } catch (final ClassNotFoundException e) {
079                MathViewer.LOGGER.debug(e);
080            } catch (final InstantiationException e) {
081                MathViewer.LOGGER.debug(e);
082            } catch (final IllegalAccessException e) {
083                MathViewer.LOGGER.debug(e);
084            } catch (final UnsupportedLookAndFeelException e) {
085                MathViewer.LOGGER.debug(e);
086            }
087            SwingUtilities.invokeLater(new Runnable() {
088                public void run() {
089                    final MainFrame mainFrame = new MainFrame();
090                    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
091                    if (MathViewer.source != null) {
092                        mainFrame.getMathComponent().setDocument(
093                                FileIO.getFileIO().loadFile(mainFrame,
094                                        MathViewer.source));
095                    }
096                    mainFrame.setVisible(true);
097                }
098            });
099        }
100    
101    }