|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.core; import java.awt.*; import java.awt.event.*; import java.beans.*; import java.io.*; import java.security.*; import java.util.Locale; import javax.swing.*; import javax.swing.border.*; import org.netbeans.CLIHandler; import org.netbeans.core.perftool.StartLog; import org.openide.util.NbBundle; /** * Handler for core options. * @author Jaroslav Tulach */ public class CLIOptions extends CLIHandler { private static boolean specifiedBranding = false; /** * Create a default handler. */ public CLIOptions() { super(WHEN_BOOT); } protected int cli(Args arguments) { return cli(arguments.getArguments()); } private static boolean isOption (String value, String optionName) { if (value == null) return false; if (value.startsWith ("--")) { return value.substring (2).equals (optionName); } else if (value.startsWith ("-")) { return value.substring (1).equals (optionName); } return false; } final int cli(String[] args) { // let's go through the command line for (int i = 0; i < args.length; i++) { if (args[i] == null) { continue; } boolean used = true; if (isOption (args[i], "nogui")) { // NOI18N System.getProperties().put("org.openide.TopManager", "org.netbeans.core.NonGui"); // NOI18N } else if (isOption (args[i], "nosplash")) { // NOI18N NonGui.noSplash = true; } else if (isOption (args[i], "noinfo")) { // NOI18N // obsolete switch, ignore } else if (isOption (args[i], "nologging")) { // NOI18N NonGui.noLogging = true; } else if (isOption (args[i], "userdir")) { // NOI18N args[i] = null; try { System.setProperty ("netbeans.user", args[++i]); } catch(ArrayIndexOutOfBoundsException e) { System.err.println(NonGui.getString("ERR_UserDirExpected")); return 2; } } else if (isOption (args[i], "ui") || isOption (args[i], "laf")) { // NOI18N args[i] = null; try { String ui = args[++i]; //Do not allow GTK L&F on 1.4.2 - it will throw nasty //exceptions in strange places and not work right if ("com.sun.java.swing.plaf.gtk.GTKLookAndFeel".equals(ui) && System.getProperty("java.version").indexOf ("1.4.2") != -1) { System.err.println(NonGui.getString("MSG_GTKNotSupported")); } else { NonGui.uiClass = Class.forName(ui); } } catch(ArrayIndexOutOfBoundsException e) { System.err.println(NonGui.getString("ERR_UIExpected")); return 2; } catch (ClassNotFoundException e2) { System.err.println(NonGui.getString("ERR_UINotFound")); } } else if (isOption (args[i], "fontsize")) { // NOI18N args[i] = null; try { NonGui.uiFontSize = Integer.parseInt(args[++i]); } catch(ArrayIndexOutOfBoundsException e) { System.err.println(NonGui.getString("ERR_FontSizeExpected")); return 2; } catch (NumberFormatException e2) { System.err.println(NonGui.getString("ERR_BadFontSize")); return 1; } } else if (isOption (args[i], "locale")) { // NOI18N args[i] = null; String localeParam = args[++i]; String language; String country = ""; // NOI18N String variant = ""; // NOI18N int index1 = localeParam.indexOf(":"); // NOI18N if (index1 == -1) language = localeParam; else { language = localeParam.substring(0, index1); int index2 = localeParam.indexOf(":", index1+1); // NOI18N if (index2 != -1) { country = localeParam.substring(index1+1, index2); variant = localeParam.substring(index2+1); } else country = localeParam.substring(index1+1); } Locale.setDefault(new Locale(language, country, variant)); } else if (isOption (args[i], "branding")) { // NOI18N args[i] = null; if (++i == args.length) { System.err.println(NonGui.getString("ERR_BrandingNeedsArgument")); return 2; } String branding = args[i]; if (branding.equals("-")) branding = null; // NOI18N try { NbBundle.setBranding(branding); } catch (IllegalArgumentException iae) { iae.printStackTrace(); return 1; } specifiedBranding = true; } else { used = false; } if (used) { args[i] = null; } } return 0; } /** Initializes logging etc. */ public static void initialize() { if (! specifiedBranding) { // Read default branding from file "lib/branding" in installation. File branding = new File(new File(NonGui.getHomeDir(), "lib"), "branding"); // NOI18N if (branding.exists()) { try { InputStream is = new FileInputStream(branding); try { BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line = rd.readLine(); if (line == null || line.equals("")) // NOI18N throw new IOException("empty branding file"); // NOI18N if (rd.readLine() != null) throw new IOException("branding file more than one line"); // NOI18N line = line.trim(); if (line.equals("-")) line = null; // NOI18N try { org.openide.util.NbBundle.setBranding(line); } catch (IllegalArgumentException iae) { iae.printStackTrace(); } } finally { is.close(); } } catch (IOException ioe) { ioe.printStackTrace(); } } } if (!NonGui.noLogging) { try { NonGui.logger = new TopLogging(NonGui.getLogDir()); } catch (IOException e) { System.err.println("Cannot create log file. Logging disabled."); // NOI18N e.printStackTrace(); } } StartLog.logProgress("TopLogging initialized"); // NOI18N } protected void usage(PrintWriter w) { w.println("Core options:"); w.println(" --laf |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.