KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > LaunchAppropriateUI


1 /*
2  * FindBugs - Find Bugs in Java programs
3  * Copyright (C) 2006, University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package edu.umd.cs.findbugs;
21
22 import java.awt.GraphicsEnvironment JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.lang.reflect.Method JavaDoc;
25
26 /**
27  * Class to launch the appropriate GUI
28  * @author pugh
29  */

30 public class LaunchAppropriateUI {
31     public static void main(String JavaDoc args[]) throws Exception JavaDoc {
32         int launchProperty = getLaunchProperty();
33         if (GraphicsEnvironment.isHeadless() || launchProperty == 0)
34             FindBugs2.main(args);
35         else {
36             String JavaDoc version = System.getProperty("java.version");
37             
38             Class JavaDoc launchClass = null;
39             if ("1.5".compareTo(version) <= 0) try {
40                 launchClass = Class.forName("edu.umd.cs.findbugs.gui2.Driver", false,
41                         LaunchAppropriateUI.class.getClassLoader());
42             } catch (ClassNotFoundException JavaDoc e) {
43                 assert true;
44             }
45             if (launchClass == null || launchProperty == 1)
46                 launchClass = edu.umd.cs.findbugs.gui.FindBugsFrame.class;
47             
48             Method JavaDoc mainMethod = launchClass.getMethod("main", args.getClass());
49             mainMethod.invoke(null, (Object JavaDoc) args);
50         }
51     }
52     
53     /** user should set -Dfindbugs.launchUI=0 for textui,
54      * or -Dfindbugs.launchUI=1 for the original swing gui.
55      * Any other value (or the absense of any value) will
56      * not change the default behavior, which is to launch
57      * the newer "gui2" on systems that support it.
58      *
59      * @return 0, 1, or 2 (or possibly another user-set int value)
60      */

61     public static int getLaunchProperty() {
62         String JavaDoc s = System.getProperty("findbugs.launchUI", "2");
63         try {
64             return Integer.parseInt(s);
65         } catch (NumberFormatException JavaDoc nfe) {
66             return 2;
67         }
68     }
69
70 }
71
Popular Tags