View Javadoc

1   /**
2    *  BlueCove - Java library for Bluetooth
3    *  Copyright (C) 2006-2008 Vlad Skarzhevskyy
4    * 
5    *  Licensed to the Apache Software Foundation (ASF) under one
6    *  or more contributor license agreements.  See the NOTICE file
7    *  distributed with this work for additional information
8    *  regarding copyright ownership.  The ASF licenses this file
9    *  to you under the Apache License, Version 2.0 (the
10   *  "License"); you may not use this file except in compliance
11   *  with the License.  You may obtain a copy of the License at
12   *
13   *    http://www.apache.org/licenses/LICENSE-2.0
14   *
15   *  Unless required by applicable law or agreed to in writing,
16   *  software distributed under the License is distributed on an
17   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18   *  KIND, either express or implied.  See the License for the
19   *  specific language governing permissions and limitations
20   *  under the License.
21   *
22   *  @author vlads
23   *  @version $Id: Main.java 2539 2008-12-10 04:14:55Z skarzhevskyy $
24   */
25  package net.sf.bluecove.se;
26  
27  import java.awt.GraphicsEnvironment;
28  import java.util.Iterator;
29  import java.util.Properties;
30  import java.util.Vector;
31  
32  import net.sf.bluecove.util.CollectionUtils;
33  
34  /**
35   * This class selects the application UI
36   * 
37   */
38  public class Main {
39  
40  	public static void main(String[] args) {
41  		for (int i = 0; i < args.length; i++) {
42  		    if (args[i].equalsIgnoreCase("--debug") || args[i].equals("-d")) {
43  		        System.setProperty("bluecove.debug", "true");
44              } else if (args[i].equalsIgnoreCase("--agui")) {
45  				runAGUI(args);
46  				return;
47  			} else if (args[i].equalsIgnoreCase("--swing") || args[i].equals("-s")) {
48  				runAGUI(args);
49  				return;
50  			} else if (args[i].equalsIgnoreCase("--awt") || args[i].equals("-a")) {
51  				runAWT(args);
52  				return;
53  			} else if (args[i].equalsIgnoreCase("--console") || args[i].equals("-c")) {
54  				runConsole(args);
55  				return;
56  			} else if (args[i].equalsIgnoreCase("--help") || args[i].equals("-h")) {
57  				System.out.println(" --swing|--agui|-s\n --console|-c\n --awt|-a  (--debug)");
58  				return;
59  			}
60  		}
61  
62  		// printSystemProperties();
63  		if ("true".equals(System.getProperty("java.awt.headless"))) {
64  			runConsole(args);
65  			return;
66  		}
67  		if (GraphicsEnvironment.isHeadless()) {
68  			runConsole(args);
69  			return;
70  		}
71  		String gui = System.getProperty("awt.toolkit");
72  		if ((gui != null) && (gui.indexOf("AGUI") != -1)) {
73  			runAGUI(args);
74  			return;
75  		}
76  
77  		String vm = System.getProperty("java.vm.name");
78  		if ((vm != null) && (vm.indexOf("CDC") != -1)) {
79  			runAGUI(args);
80  			return;
81  		}
82  		runAWT(args);
83  	}
84  
85  	static void runConsole(String[] args) {
86  		Console.main(args);
87  	}
88  
89  	static void runAGUI(String[] args) {
90  		net.sf.bluecove.swing.Main.main(args);
91  	}
92  
93  	static void runAWT(String[] args) {
94  		net.sf.bluecove.awt.Main.main(args);
95  	}
96  
97  	public static void printSystemProperties() {
98  		StringBuffer sysProperties = new StringBuffer();
99  		Properties properties = System.getProperties();
100 		// Sort the list
101 		Vector list2sort = new Vector();
102 		int max_key = 0;
103 		for (Iterator iterator = properties.keySet().iterator(); iterator.hasNext();) {
104 			Object keyObj = (Object) iterator.next();
105 			String key = keyObj.toString();
106 			list2sort.add(key);
107 			int len = key.length();
108 			if (len > max_key) {
109 				max_key = len;
110 			}
111 		}
112 		CollectionUtils.sort(list2sort);
113 		if (max_key > 41) {
114 			max_key = 41;
115 		}
116 
117 		for (Iterator iterator = list2sort.iterator(); iterator.hasNext();) {
118 			String key = (String) iterator.next();
119 			StringBuffer key_p = new StringBuffer(key);
120 			while (key_p.length() < max_key) {
121 				key_p.append(" ");
122 			}
123 			String value = (String) properties.get(key);
124 			if (value == null) {
125 				value = "{null}";
126 			}
127 			StringBuffer value_p = new StringBuffer(value);
128 			value_p.append("]");
129 			while (value_p.length() < 60) {
130 				value_p.append(" ");
131 			}
132 			sysProperties.append(" \t" + key_p.toString() + " = [" + value_p.toString() + "\n");
133 		}
134 		System.out.println("System Properties:\n" + sysProperties.toString());
135 	}
136 }