001: /*
002: * FindBugs - Find Bugs in Java programs
003: * Copyright (C) 2006, University of Maryland
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307, USA
018: */
019:
020: package edu.umd.cs.findbugs.gui2;
021:
022: import javax.swing.UIManager;
023:
024: import edu.umd.cs.findbugs.DetectorFactoryCollection;
025: import edu.umd.cs.findbugs.SystemProperties;
026:
027: /**
028: * This is where it all begins
029: * run with -f int to set font size
030: * run with -clear to clear recent projects menu, or any other issues with program not starting properly due to
031: * something being corrupted (or just faulty) in backend store for GUISaveState.
032: *
033: */
034: public class Driver {
035:
036: private static float fontSize = 12;
037: private static boolean docking = true;
038: private static SplashFrame splash;
039:
040: public static void main(String[] args) throws Exception {
041: if (SystemProperties.getProperty("os.name").startsWith("Mac")) {
042: System.setProperty("apple.laf.useScreenMenuBar", "true");
043: System.setProperty(
044: "com.apple.mrj.application.apple.menu.about.name",
045: "FindBugs");
046: Debug.println("Mac OS detected");
047: }
048:
049: splash = new SplashFrame();
050: splash.setVisible(true);
051:
052: try {
053: Class.forName("net.infonode.docking.DockingWindow");
054: Class.forName("edu.umd.cs.findbugs.gui2.DockLayout");
055: } catch (Exception e) {
056: docking = false;
057: }
058:
059: for (int i = 0; i < args.length; i++) {
060: if ((args[i].equals("-f")) && (i + 1 < args.length)) {
061: float num = 0;
062: try {
063: i++;
064: num = Integer.valueOf(args[i]);
065: } catch (NumberFormatException exc) {
066: num = fontSize;
067: }
068: fontSize = num;
069: }
070:
071: else if (args[i].startsWith("--font=")) {
072: float num = 0;
073: try {
074: num = Integer.valueOf(args[i].substring("--font="
075: .length()));
076: } catch (NumberFormatException exc) {
077: num = fontSize;
078: }
079: fontSize = num;
080: }
081:
082: else if (args[i].equals("-clear")) {
083: GUISaveState.clear();
084: System.exit(0);
085: }
086:
087: else if (args[i].equals("-d") || args[i].equals("--nodock")) {
088: docking = false;
089: }
090:
091: else if (args[i].startsWith("-look:")) {
092: String arg = args[i].substring("-look:".length());
093:
094: String theme = null;
095: if (arg.equals("plastic")) {
096: // You can get the Plastic look and feel from jgoodies.com:
097: // http://www.jgoodies.com/downloads/libraries.html
098: // Just put "plastic.jar" in the lib directory, right next
099: // to the other jar files.
100: theme = "com.jgoodies.plaf.plastic.PlasticXPLookAndFeel";
101: } else if (arg.equals("gtk")) {
102: theme = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
103: } else if (arg.equals("native")) {
104: theme = UIManager.getSystemLookAndFeelClassName();
105: } else {
106: System.err.println("Style '" + arg
107: + "' not supported");
108: }
109:
110: if (theme != null) {
111: try {
112: UIManager.setLookAndFeel(theme);
113: } catch (Exception e) {
114: System.err.println("Couldn't load " + arg
115: + " look and feel: " + e.toString());
116: }
117: }
118: }
119:
120: else {
121: System.err.println("Unknown option: " + args[i]);
122: System.exit(1);
123: }
124: }
125:
126: try {
127: GUISaveState.loadInstance();
128: } catch (RuntimeException e) {
129: GUISaveState.clear();
130: e.printStackTrace();
131: }
132:
133: if (fontSize == 12
134: && GUISaveState.getInstance().getFontSize() != 12)
135: fontSize = GUISaveState.getInstance().getFontSize();
136: else
137: GUISaveState.getInstance().setFontSize(fontSize);
138:
139: // System.setProperty("findbugs.home",".."+File.separator+"findbugs");
140: DetectorFactoryCollection.instance();
141:
142: // The bug with serializable idiom detection has been fixed on the findbugs end.
143: // DetectorFactory serializableIdiomDetector=DetectorFactoryCollection.instance().getFactory("SerializableIdiom");
144: // System.out.println(serializableIdiomDetector.getFullName());
145: // UserPreferences.getUserPreferences().enableDetector(serializableIdiomDetector,false);
146:
147: FindBugsLayoutManagerFactory factory;
148:
149: if (isDocking())
150: factory = new FindBugsLayoutManagerFactory(
151: "edu.umd.cs.findbugs.gui2.DockLayout");
152: else
153: factory = new FindBugsLayoutManagerFactory(
154: SplitLayout.class.getName());
155: MainFrame.makeInstance(factory);
156:
157: splash.setVisible(false);
158: splash.dispose();
159: }
160:
161: public static void removeSplashScreen() {
162: splash.setVisible(false);
163: splash.dispose();
164: }
165:
166: public static boolean isDocking() {
167: return docking;
168: }
169:
170: public static float getFontSize() {
171: return fontSize;
172: }
173: }
|