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.gui;
25
26 import java.awt.BorderLayout;
27 import java.awt.Dimension;
28 import java.awt.Rectangle;
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
31 import java.awt.event.WindowAdapter;
32 import java.awt.event.WindowEvent;
33
34 import javax.swing.AbstractAction;
35 import javax.swing.ImageIcon;
36 import javax.swing.JFrame;
37 import javax.swing.JMenu;
38 import javax.swing.JMenuBar;
39 import javax.swing.JSplitPane;
40 import javax.swing.JToolBar;
41 import javax.swing.UIManager;
42
43 import com.mindtree.techworks.insight.Controller;
44 import com.mindtree.techworks.insight.InsightConstants;
45 import com.mindtree.techworks.insight.ResourceManager;
46 import com.mindtree.techworks.insight.ShutdownHookManager;
47 import com.mindtree.techworks.insight.gui.action.ClearDisplayAction;
48 import com.mindtree.techworks.insight.gui.action.FilterAction;
49 import com.mindtree.techworks.insight.gui.action.FindAction;
50 import com.mindtree.techworks.insight.gui.action.IAction;
51 import com.mindtree.techworks.insight.gui.action.LoadFileAction;
52 import com.mindtree.techworks.insight.gui.action.LoadPageAction;
53 import com.mindtree.techworks.insight.gui.action.LocateAction;
54 import com.mindtree.techworks.insight.gui.action.MaintainPreferencesAction;
55 import com.mindtree.techworks.insight.gui.action.RemoteProtocolListenerAction;
56 import com.mindtree.techworks.insight.gui.action.ScrollLockAction;
57 import com.mindtree.techworks.insight.gui.action.SearchAction;
58 import com.mindtree.techworks.insight.gui.action.SearchEventAction;
59 import com.mindtree.techworks.insight.gui.action.StopReceiverAction;
60 import com.mindtree.techworks.insight.gui.util.AboutFrame;
61 import com.mindtree.techworks.insight.gui.util.LoadedNamespacesFrame;
62 import com.mindtree.techworks.insight.gui.widgets.InsightMenuItem;
63 import com.mindtree.techworks.insight.gui.widgets.InsightToolbarButton;
64 import com.mindtree.techworks.insight.gui.widgets.StatusBar;
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80 public class Insight extends JFrame {
81
82
83
84
85 private static final long serialVersionUID = 723734250598646319L;
86
87
88
89
90 protected final Insight instance;
91
92
93
94
95 static {
96 UIManager.getDefaults().put("ProgressBar.selectionForeground",InsightConstants.DEFAULT_FOREGROUND);
97 UIManager.getDefaults().put("ProgressBar.selectionBackground",InsightConstants.DEFAULT_FOREGROUND);
98 UIManager.getDefaults().put("ProgressBar.font", InsightConstants.DEFAULT_SMALL_FONT);
99 }
100
101
102
103
104 private Controller controller;
105
106
107
108
109
110 public Insight() {
111 this.instance = this;
112
113 this.controller = new Controller(this);
114 initialize();
115 }
116
117
118
119
120 public Controller getController() {
121 return controller;
122 }
123
124
125
126
127 private void initialize() {
128
129 setupThisFrame();
130
131 setupPresentations(controller);
132
133 addWindowListener(new WindowAdapter() {
134 public void windowClosing(WindowEvent aEvent) {
135 System.exit(0);
136 }
137 });
138
139 pack();
140
141 Dimension dim = getToolkit().getScreenSize();
142 Rectangle abounds = getBounds();
143 setLocation((dim.width - abounds.width) / 2,(dim.height - abounds.height) / 2);
144
145 setVisible(true);
146
147
148
149 ShutdownHookManager
150 .addShutdownAction (ShutdownHookManager.SHUTDOWN_ACTION_CLEAR_PAGES
151 | ShutdownHookManager.SHUTDOWN_ACTION_SAVE_PREFERENCES);
152 }
153
154
155
156
157
158
159 private void setupPresentations(Controller controller) {
160 EventListPresentation eventListPresentation = new EventListPresentation(controller);
161 EventDetailsPresentation eventDetailsPresentation = new EventDetailsPresentation(controller);
162 JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, eventListPresentation.getViewComponent(),
163 eventDetailsPresentation);
164 getContentPane().add(splitPane, BorderLayout.CENTER);
165 }
166
167
168
169
170 private void setupThisFrame() {
171 ResourceManager rm = ResourceManager.getInstance();
172 this.setTitle(InsightConstants.FRAME_TITLE);
173 this.setIconImage(rm.loadImageIcon("INSIGHT_ICON").getImage());
174 final JMenuBar menuBar = new JMenuBar();
175 final JToolBar toolBar = new JToolBar();
176 toolBar.setRollover(true);
177 toolBar.setFloatable(false);
178
179 setJMenuBar(menuBar);
180 this.getContentPane().add(toolBar, BorderLayout.NORTH);
181
182 setupFileMenu(menuBar, toolBar);
183 setupEditMenu(menuBar, toolBar);
184 setupViewMenu(menuBar, toolBar);
185 setupPreferencesMenu(menuBar, toolBar);
186 setupHelpMenu(menuBar, toolBar);
187
188 this.getContentPane().add(StatusBar.getInstance(), BorderLayout.SOUTH);
189 }
190
191
192
193
194
195
196 private void setupFileMenu(JMenuBar menuBar, JToolBar toolBar) {
197 ResourceManager rm = ResourceManager.getInstance();
198 final JMenu fileMenu = new JMenu(InsightConstants.getLiteral("FILE_MENU"));
199 menuBar.add(fileMenu);
200
201 LoadFileAction loadFileAction = new LoadFileAction(this);
202 fileMenu.add(getMenuItem(IAction.STARTUP, null, InsightConstants.getLiteral("LOAD_FILE"),loadFileAction));
203 toolBar.add(getToolbarButton(IAction.STARTUP, null, rm.loadImageIcon("OPEN_ICON"),InsightConstants.getLiteral("OPEN_FILE_TOOL_TIP"),loadFileAction));
204
205 RemoteProtocolListenerAction remoteAction = RemoteProtocolListenerAction.getInstance();
206 remoteAction.initialize(this);
207 fileMenu.add(getMenuItem(IAction.STARTUP, null, InsightConstants.getLiteral("START_RECEIVER"),remoteAction));
208 toolBar.add(getToolbarButton(IAction.STARTUP, null, rm.loadImageIcon("RECEIVER_ICON"),InsightConstants.getLiteral("START_RECEIVER_TOOL_TIP"),remoteAction));
209
210
211 fileMenu.insertSeparator(fileMenu.getMenuComponentCount());
212 fileMenu.add(getMenuItem(IAction.ALL, null, InsightConstants.getLiteral("EXIT"),
213 new AbstractAction(){
214
215
216
217 private static final long serialVersionUID = 718096549365310016L;
218
219
220
221
222 public void actionPerformed(ActionEvent actionEvent) {
223 System.exit(0);
224 }
225 }
226 ));
227
228 toolBar.addSeparator(new Dimension(InsightConstants.TOOL_BAR_GROUP_SPACING,toolBar.getHeight()));
229 }
230
231
232
233
234
235
236 private void setupEditMenu(JMenuBar menuBar, JToolBar toolBar) {
237 ResourceManager rm = ResourceManager.getInstance();
238 final JMenu editMenu = new JMenu(InsightConstants.getLiteral("EDIT_MENU"));
239 menuBar.add(editMenu);
240
241 StopReceiverAction stopReceiverAction = new StopReceiverAction(this);
242 editMenu.add(getMenuItem(IAction.TAIL, null, InsightConstants.getLiteral("STOP_RECEIVER"),stopReceiverAction));
243 toolBar.add(getToolbarButton(IAction.TAIL, null, rm.loadImageIcon("STOP_ICON"), InsightConstants.getLiteral("STOP_RECEIVER_TOOL_TIP"),stopReceiverAction));
244
245 ClearDisplayAction clearDisplayAction = new ClearDisplayAction(this);
246 editMenu.add(getMenuItem(IAction.MUTATION, null, InsightConstants.getLiteral("CLEAR_DISPLAY"),clearDisplayAction));
247 toolBar.add(getToolbarButton(IAction.MUTATION, null, rm.loadImageIcon("CLEAR_ICON"), InsightConstants.getLiteral("CLEAR_ENTRIES_TOOL_TIP"),clearDisplayAction));
248
249 FilterAction filterAction = new FilterAction(this);
250 editMenu.add(getMenuItem(IAction.MUTATION, null, InsightConstants.getLiteral("FILTER_DATA"),filterAction));
251 toolBar.add(getToolbarButton(IAction.MUTATION, null, rm.loadImageIcon("FILTER_ICON"), InsightConstants.getLiteral("FILTER_ENTRIES_TOOL_TIP"),filterAction));
252
253
254
255 toolBar.addSeparator(new Dimension(InsightConstants.TOOL_BAR_GROUP_SPACING,toolBar.getHeight()));
256 editMenu.insertSeparator(editMenu.getMenuComponentCount());
257
258 SearchAction searchAction = SearchAction.getInstance(this);
259 editMenu.add(getMenuItem(IAction.VIEW, null, InsightConstants.getLiteral("SEARCH_DATA"),searchAction));
260 toolBar.add(getToolbarButton(IAction.VIEW, null, rm.loadImageIcon("SEARCH_ICON"), InsightConstants.getLiteral("SEARCH_TOOL_TIP"),searchAction));
261
262 LocateAction locateAction = LocateAction.getInstance(this.controller);
263 editMenu.add(getMenuItem(IAction.VIEW, null, InsightConstants.getLiteral("LOCATE_EVENT"),locateAction));
264 toolBar.add(getToolbarButton(IAction.VIEW, null, rm.loadImageIcon("LOCATE_ICON"), InsightConstants.getLiteral("LOCATE_TOOL_TIP"),locateAction));
265
266 FindAction findAction = FindAction.getInstance(this);
267 editMenu.add(getMenuItem(IAction.VIEW, null, InsightConstants.getLiteral("FIND_DATA"),findAction));
268 toolBar.add(getToolbarButton(IAction.VIEW, null, rm.loadImageIcon("FIND_ICON"), InsightConstants.getLiteral("FIND_TOOL_TIP"),findAction));
269
270
271 toolBar.addSeparator(new Dimension(InsightConstants.TOOL_BAR_GROUP_SPACING,toolBar.getHeight()));
272 }
273
274
275
276
277
278
279 private void setupPreferencesMenu(JMenuBar menuBar, JToolBar toolBar) {
280 final JMenu preferencesMenu = new JMenu(InsightConstants.getLiteral("PREFERENCES_MENU"));
281 menuBar.add(preferencesMenu);
282
283 MaintainPreferencesAction maintainPreferencesAction = new MaintainPreferencesAction(this);
284 preferencesMenu.add(getMenuItem(IAction.ALL, null, InsightConstants.getLiteral("MAINTAIN_PREFERENCES"),maintainPreferencesAction));
285 toolBar.add(getToolbarButton(IAction.ALL, null, ResourceManager.getInstance().loadImageIcon("PREFERENCES_ICON"), InsightConstants.getLiteral("MAINTAIN_PREFERENCES_TOOL_TIP"),maintainPreferencesAction));
286
287
288 toolBar.addSeparator(new Dimension(InsightConstants.TOOL_BAR_GROUP_SPACING,toolBar.getHeight()));
289 }
290
291
292
293
294
295
296 private void setupViewMenu(JMenuBar menuBar, JToolBar toolBar) {
297 ResourceManager rm = ResourceManager.getInstance();
298 LoadPageAction loadPageAction = new LoadPageAction(controller);
299 final JMenu viewMenu = new JMenu(InsightConstants.getLiteral("VIEW_MENU"));
300 menuBar.add(viewMenu);
301
302 viewMenu.add(getMenuItem(IAction.VIEW, InsightConstants.getLiteral("FIRST_PAGE"),
303 InsightConstants.getLiteral("FIRST_PAGE_MENU"),loadPageAction));
304 toolBar.add(getToolbarButton(IAction.VIEW, InsightConstants.getLiteral("FIRST_PAGE"),
305 rm.loadImageIcon("FIRST_PAGE_ICON"), InsightConstants.getLiteral("FIRST_PAGE_TOOL_TIP"),
306 loadPageAction));
307
308 viewMenu.add(getMenuItem(IAction.VIEW, InsightConstants.getLiteral("PREV_PAGE"),
309 InsightConstants.getLiteral("PREV_PAGE_MENU"),loadPageAction));
310 toolBar.add(getToolbarButton(IAction.VIEW, InsightConstants.getLiteral("PREV_PAGE"),
311 rm.loadImageIcon("PREV_PAGE_ICON"), InsightConstants.getLiteral("PREV_PAGE_TOOL_TIP"),
312 loadPageAction));
313
314 viewMenu.add(getMenuItem(IAction.VIEW, InsightConstants.getLiteral("NEXT_PAGE"),
315 InsightConstants.getLiteral("NEXT_PAGE_MENU"),loadPageAction));
316 toolBar.add(getToolbarButton(IAction.VIEW, InsightConstants.getLiteral("NEXT_PAGE"),
317 rm.loadImageIcon("NEXT_PAGE_ICON"), InsightConstants.getLiteral("NEXT_PAGE_TOOL_TIP"),
318 loadPageAction));
319
320 viewMenu.add(getMenuItem(IAction.VIEW, InsightConstants.getLiteral("LAST_PAGE"),
321 InsightConstants.getLiteral("LAST_PAGE_MENU"),loadPageAction));
322 toolBar.add(getToolbarButton(IAction.VIEW, InsightConstants.getLiteral("LAST_PAGE"),
323 rm.loadImageIcon("LAST_PAGE_ICON"), InsightConstants.getLiteral("LAST_PAGE_TOOL_TIP"),
324 loadPageAction));
325
326
327
328 toolBar.addSeparator(new Dimension(InsightConstants.TOOL_BAR_GROUP_SPACING,toolBar.getHeight()));
329 viewMenu.insertSeparator(viewMenu.getMenuComponentCount());
330
331 SearchEventAction searchEventAction = SearchEventAction.getInstance(controller);
332
333 viewMenu.add(getMenuItem(IAction.VIEW, InsightConstants.getLiteral("PREV_SEARCH_MATCH"),
334 InsightConstants.getLiteral("PREV_SEARCH_MATCH"),searchEventAction));
335 toolBar.add(getToolbarButton(IAction.VIEW, InsightConstants.getLiteral("PREV_SEARCH_MATCH"),
336 rm.loadImageIcon("PREV_MATCH_ICON"), InsightConstants.getLiteral("PREV_SEARCH_MATCH_TOOL_TIP"),
337 searchEventAction));
338
339 viewMenu.add(getMenuItem(IAction.VIEW, InsightConstants.getLiteral("NEXT_SEARCH_MATCH"),
340 InsightConstants.getLiteral("NEXT_SEARCH_MATCH"),searchEventAction));
341 toolBar.add(getToolbarButton(IAction.VIEW, InsightConstants.getLiteral("NEXT_SEARCH_MATCH"),
342 rm.loadImageIcon("NEXT_MATCH_ICON"), InsightConstants.getLiteral("NEXT_SEARCH_MATCH_TOOL_TIP"),
343 searchEventAction));
344
345
346
347 toolBar.addSeparator(new Dimension(InsightConstants.TOOL_BAR_GROUP_SPACING,toolBar.getHeight()));
348 viewMenu.insertSeparator(viewMenu.getMenuComponentCount());
349
350
351 ScrollLockAction scrollLockAction = new ScrollLockAction(controller);
352 InsightToolbarButton scrollButton = getToolbarButton(IAction.VIEW, InsightConstants.getLiteral("SCROLL_LOCK_UNLOCK"),
353 rm.loadImageIcon("UNLOCK_ICON"), InsightConstants.getLiteral("SCROLL_LOCK_TOOL_TIP"),
354 scrollLockAction);
355 scrollLockAction.setScrollButton(scrollButton);
356 viewMenu.add(getMenuItem(IAction.VIEW, InsightConstants.getLiteral("SCROLL_LOCK_UNLOCK"),
357 InsightConstants.getLiteral("SCROLL_LOCK_UNLOCK"),scrollLockAction));
358 toolBar.add(scrollButton);
359
360
361 toolBar.addSeparator(new Dimension(InsightConstants.TOOL_BAR_GROUP_SPACING,toolBar.getHeight()));
362
363
364 viewMenu.insertSeparator(viewMenu.getMenuComponentCount());
365 viewMenu.add(getMenuItem(IAction.MUTATION, null,
366 InsightConstants.getLiteral("LOADED_NAMESPACES"),
367 new AbstractAction(){
368
369
370
371 private static final long serialVersionUID = -5496879826632520984L;
372
373
374
375
376 public void actionPerformed(ActionEvent actionEvent) {
377 new LoadedNamespacesFrame(instance);
378 }
379 }
380 ));
381 }
382
383
384
385
386
387
388 private void setupHelpMenu(JMenuBar menuBar, JToolBar toolBar) {
389 final JMenu helpMenu = new JMenu(InsightConstants.getLiteral("HELP_MENU"));
390 menuBar.add(helpMenu);
391 helpMenu.add(getMenuItem(IAction.ALL, null, InsightConstants.getLiteral("ABOUT_DIALOG"),
392 new AbstractAction(){
393
394
395
396 private static final long serialVersionUID = 177106344651169741L;
397
398
399
400
401 public void actionPerformed(ActionEvent actionEvent) {
402 new AboutFrame(instance);
403 }
404 }
405 ));
406 }
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436 private InsightToolbarButton getToolbarButton(int type, String name, ImageIcon imageIcon, String toolTip, ActionListener actionListener) {
437 InsightToolbarButton button = new InsightToolbarButton(type, name, imageIcon, toolTip, actionListener);
438 button.setController(this.controller);
439 return button;
440 }
441
442
443
444
445
446
447
448
449
450
451
452 private InsightMenuItem getMenuItem(int type, String name, String displayText, ActionListener actionListener) {
453 InsightMenuItem menu = new InsightMenuItem(type, name, displayText, actionListener);
454 menu.setController(this.controller);
455 return menu;
456 }
457
458 }