View Javadoc

1   /*
2    * Copyright 2002 - 2007 JEuclid, http://jeuclid.sf.net
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  /* $Id: MathViewer.java,v 4add00437054 2010/01/21 11:39:11 MARIO $ */
18  
19  package net.sourceforge.jeuclid.app.mathviewer;
20  
21  import java.io.File;
22  
23  import javax.swing.JFrame;
24  import javax.swing.SwingUtilities;
25  import javax.swing.UIManager;
26  import javax.swing.UnsupportedLookAndFeelException;
27  
28  import net.sourceforge.jeuclid.Constants;
29  
30  import org.apache.commons.logging.Log;
31  import org.apache.commons.logging.LogFactory;
32  
33  import com.apple.eawt.Application;
34  
35  /**
36   * A simple application for viewing MathML documents.
37  
38   * @version $Revision: 4add00437054 $
39   */
40  public final class MathViewer {
41  
42      /**
43       * Set to true if we're running under Mac OS X.
44       */
45      public static final boolean OSX =
46              System.getProperty("mrj.version") != null; //$NON-NLS-1$
47  
48      /**
49       * Logger for this class.
50       */
51      private static final Log LOGGER = LogFactory.getLog(MathViewer.class);
52  
53      /**
54       * Source file.
55       */
56      private static File source;
57  
58      /**
59       * Default constructor.
60       */
61      private MathViewer() {
62          // Empty on purpose
63      }
64  
65      /**
66       * Launches this application.
67       * @param args
68       *            command line arguments. Ignored.
69       */
70      public static void main(final String[] args) {
71          MathViewer.source = null;
72          if (args.length > 0) {
73              MathViewer.source = new File(args[0]);
74          }
75          if (MathViewer.OSX) {
76              System.setProperty("apple.laf.useScreenMenuBar",
77                      Constants.TRUE); //$NON-NLS-1$ //$NON-NLS-2$
78          }
79  
80          try {
81              UIManager.setLookAndFeel(UIManager
82                      .getSystemLookAndFeelClassName());
83          } catch (final ClassNotFoundException e) {
84              MathViewer.LOGGER.debug(e);
85          } catch (final InstantiationException e) {
86              MathViewer.LOGGER.debug(e);
87          } catch (final IllegalAccessException e) {
88              MathViewer.LOGGER.debug(e);
89          } catch (final UnsupportedLookAndFeelException e) {
90              MathViewer.LOGGER.debug(e);
91          }
92          SwingUtilities.invokeLater(new Runnable() {
93              public void run() {
94                  final MainFrame mainFrame = new MainFrame();
95                  mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
96                  if (MathViewer.OSX) {
97                      final Application a = Application.getApplication();
98                      a.setEnabledAboutMenu(true);
99                      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 }