1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package com.mindtree.techworks.insight;
25
26 import java.io.File;
27 import java.io.IOException;
28 import java.io.InputStream;
29 import java.lang.reflect.Method;
30 import java.util.Properties;
31
32 import javax.swing.UIManager;
33 import javax.swing.plaf.metal.MetalTheme;
34
35 import org.apache.commons.cli.CommandLine;
36 import org.apache.commons.cli.CommandLineParser;
37 import org.apache.commons.cli.HelpFormatter;
38 import org.apache.commons.cli.Options;
39 import org.apache.commons.cli.ParseException;
40 import org.apache.commons.cli.PosixParser;
41
42 import com.mindtree.techworks.insight.gui.action.LoadLocalFileAction;
43 import com.mindtree.techworks.insight.gui.preferences.PreferencesFrame;
44 import com.mindtree.techworks.insight.preferences.xmlpersistence.XMLPreferenceDataHandler;
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 public class Insight {
67
68
69
70
71
72
73
74 public static void main (String [] args) {
75
76
77 CommandLineParser parser = new PosixParser();
78
79 try {
80 CommandLine line = parser.parse(getApplicationOptions(), args);
81
82
83 String insightHome = null;
84 if (line.hasOption("ih")) {
85 insightHome = line.getOptionValue("ih");
86 }
87
88 if (line.hasOption("h")) {
89
90 HelpFormatter helpFormatter = new HelpFormatter();
91 helpFormatter.printHelp(40, Insight.class.getName(),
92 "MindTree Insight ver. "
93 + VersionUtil.getInsightVersion(),
94 getApplicationOptions(), "Build Id: "
95 + VersionUtil.getInsightBuild()
96 + "\nWith Remote Protocol ver. "
97 + VersionUtil.getRemoteProtocolVersion(), true);
98 } else if (line.hasOption("p")) {
99
100
101
102
103 prepareToLaunch(insightHome);
104
105 PreferencesFrame preferencesFrame = new PreferencesFrame();
106 preferencesFrame.showPreferences();
107 } else if( line.hasOption("f")) {
108 prepareToLaunch(insightHome);
109 new com.mindtree.techworks.insight.gui.Insight();
110 LoadLocalFileAction.getInstance().LoadOnFileSelection(line.getOptionValue("f"));
111 } else {
112
113
114
115 prepareToLaunch(insightHome);
116 new com.mindtree.techworks.insight.gui.Insight();
117 }
118
119 } catch (ParseException e) {
120 System.out.println ("Unrecognized options in Insight.");
121 }
122
123 }
124
125
126
127
128
129 private static void prepareToLaunch(String insightHome) {
130 initializeInsightHome(insightHome);
131 readDefaultProperties();
132 setLookAndFeel();
133 }
134
135
136
137
138 private static void setLookAndFeel() {
139 try {
140 com.jgoodies.looks.Options.setPopupDropShadowEnabled(true);
141 String lfClass = System.getProperty(InsightConstants.LOOK_AND_FEEL,
142 "com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
143 Class lfClazz = Class.forName(lfClass);
144 Method themeMethod = lfClazz.getMethod("setCurrentTheme", new Class[]{MetalTheme.class});
145
146 if (null != themeMethod) {
147 String themeClass = System.getProperty(
148 InsightConstants.LOOK_AND_FEEL_THEME,
149 "com.jgoodies.looks.plastic.theme.SkyBlue");
150 Class themeClazz = Class.forName(themeClass);
151 themeMethod.invoke(null, new Object[] {themeClazz.newInstance()});
152 }
153 UIManager.setLookAndFeel(lfClass);
154 } catch (Exception e) {
155 e.printStackTrace();
156 }
157 }
158
159
160
161
162
163
164
165
166
167
168
169 private static void initializeInsightHome (String insightHome) {
170
171 if (insightHome == null) {
172
173
174 insightHome = System.getProperty(InsightConstants.INSIGHT_HOME);
175 }
176 if(insightHome == null) {
177 insightHome = System.getProperty("user.dir");
178 System.setProperty(InsightConstants.INSIGHT_HOME, insightHome);
179 }
180 File insightPreferences = new File(insightHome + XMLPreferenceDataHandler.XML_PROP_FILE_URI);
181 if (!insightPreferences.exists()) {
182 System.err.println(InsightConstants.getLiteral("ERROR_INVALID_INSIGHT_HOME"));
183 System.exit(1);
184 }
185
186 }
187
188
189
190
191
192 private static void readDefaultProperties() {
193
194 InputStream propertiesInputStream = Thread.currentThread()
195 .getContextClassLoader().getResourceAsStream(
196 "insight.properties");
197 Properties insightproperties = new Properties();
198 try {
199 insightproperties.load(propertiesInputStream);
200
201
202 System.getProperties().putAll(insightproperties);
203 } catch (IOException e) {
204 System.err.println(InsightConstants.getLiteral("ERROR_INVALID_INSIGHT_PROPERTIES"));
205 System.exit(1);
206 }
207 }
208
209
210
211
212
213
214 private static Options getApplicationOptions() {
215 Options appOptions = new Options();
216
217
218 appOptions.addOption("", false, "<No Arguments> Launches the Insight Application");
219
220
221 appOptions.addOption("p", "preferences", false, "Brings Up the " +
222 "Preferences of the Insight instance");
223
224
225 appOptions.addOption("h", "help", false, "Displays this help");
226
227
228 appOptions.addOption("ih", "insight-home", true, "Set the Insight Home location");
229
230 appOptions.addOption("f", "openfile", true, "Opens the specified log file with Insight");
231
232 return appOptions;
233 }
234
235 }