1 /********************************************************************************
2 * InternetCafe is a software solution that helps the management of Cybercafes
3 * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4 * Copyright (C) 2006 Guido Angelo Ingenito
5
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *******************************************************************************/
20 package ui;
21
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.awt.event.KeyEvent;
25
26 import javax.swing.Box;
27 import javax.swing.ImageIcon;
28 import javax.swing.JMenu;
29 import javax.swing.JMenuBar;
30 import javax.swing.JMenuItem;
31 import javax.swing.JSeparator;
32 import javax.swing.KeyStroke;
33
34 import org.apache.log4j.Logger;
35
36 import ui.command.CommandExecutor;
37 import ui.command.IO.ExitCommand;
38 import ui.command.IO.ExportSessionListCommand;
39 import ui.command.IO.ExportUserListCommand;
40 import ui.command.IO.ImportUserFromVCardCommand;
41 import ui.command.IO.LoadDBCommand;
42 import ui.command.IO.LogOutAdministratorCommand;
43 import ui.command.IO.SaveDBAsCommand;
44 import ui.command.IO.SaveDBCommand;
45 import ui.command.information.ShowAboutFrameCommand;
46 import ui.command.information.ShowMessageFrameCommand;
47 import ui.command.information.ShowTextFileDialogCommand;
48 import ui.help.HelpMenuItem;
49 import base.ConfigurationManager;
50
51 @SuppressWarnings("serial")
52 public class ICMenuBar extends JMenuBar {
53
54 private static final transient Logger logger = Logger
55 .getLogger(ICMenuBar.class.getName());
56
57 private JMenu menuFile;
58
59 private JMenu subMenuFileNew;
60
61 private JMenuItem subMenuFileNewUserFromVCard;
62
63 private JMenu subMenuFileExport;
64
65 private JMenuItem subMenuFileExportSessionList;
66
67 private JMenuItem subMenuFileExportUserList;
68
69 private JMenuItem menuFileLoadDB;
70
71 private JMenuItem menuFileSaveDB;
72
73 private JMenuItem menuFileSaveDBAs;
74
75 private JMenuItem menuFilePrint;
76
77 private JMenuItem menuFilePrintPreview;
78
79 private JMenuItem menuFileExit;
80
81 private JMenu menuEdit;
82
83 private JMenuItem menuEditUndo;
84
85 private JMenuItem menuEditRedo;
86
87 private JMenuItem menuEditCut;
88
89 private JMenuItem menuEditCopy;
90
91 private JMenuItem menuEditPaste;
92
93 private JMenuItem menuEditSelectAll;
94
95 private JMenu menuSecurity;
96
97 private JMenuItem menuSecurityLogOut;
98
99 private JMenu menuHelp;
100
101 private JMenuItem menuHelpContent;
102
103 private JMenuItem menuHelpMessage;
104
105 private JMenuItem menuHelpAbout;
106
107 private JMenuItem menuHelpLicense;
108
109 public ICMenuBar() {
110 initialize();
111 }
112
113 protected void initialize() {
114 add(getMenuFile());
115 add(getMenuEdit());
116 add(getMenuSecurity());
117 add(Box.createHorizontalGlue());
118 add(getMenuHelp());
119 }
120
121 /***
122 * @return Returns the menuFile.
123 */
124 protected JMenu getMenuFile() {
125 if (menuFile == null) {
126 menuFile = new JMenu(Messages.getString("menubar.file"));
127 menuFile.setMnemonic(KeyEvent.VK_F);
128
129 menuFile.add(getSubMenuFileNew());
130 menuFile.add(new JSeparator());
131 menuFile.add(getMenuFileLoadDB());
132 menuFile.add(new JSeparator());
133 menuFile.add(getMenuFileSaveDB());
134 menuFile.add(getMenuFileSaveDBAs());
135 menuFile.add(new JSeparator());
136 menuFile.add(getSubMenuFileExport());
137 menuFile.add(new JSeparator());
138 menuFile.add(getMenuFilePrint());
139 menuFile.add(getMenuFilePrintPreview());
140 menuFile.add(new JSeparator());
141 menuFile.add(getMenuFileExit());
142
143 }
144 return menuFile;
145 }
146
147 /***
148 * @return Returns the subMenuFileNew.
149 */
150 protected JMenu getSubMenuFileNew() {
151 if (subMenuFileNew == null) {
152 subMenuFileNew = new JMenu(Messages.getString("menubar.file.new"));
153 subMenuFileNew.add(getSubMenuFileNewUserFromVCard());
154 }
155 return subMenuFileNew;
156 }
157
158 /***
159 * @return Returns the menuFilePrint.
160 */
161 protected JMenuItem getMenuFilePrint() {
162 if (menuFilePrint == null) {
163 menuFilePrint = new JMenuItem(Messages.getString("menubar.file.print"));
164 menuFilePrint.setIcon(new ImageIcon(this.getClass().getResource(
165 "/icon/16x16/actions/document-print.png")));
166
167 menuFilePrint.addActionListener(new ActionListener() {
168 public void actionPerformed(ActionEvent arg0) {
169 logger.debug("actionPerformed menuFilePrint");
170 }
171 });
172 }
173 return menuFilePrint;
174 }
175
176 /***
177 * @return Returns the menuFilePrintPreview.
178 */
179 protected JMenuItem getMenuFilePrintPreview() {
180 if (menuFilePrintPreview == null) {
181 menuFilePrintPreview = new JMenuItem(Messages.getString("menubar.file.printpreview"));
182 menuFilePrintPreview.setIcon(new ImageIcon(this.getClass()
183 .getResource(
184 "/icon/16x16/actions/document-print-preview.png")));
185
186 menuFilePrintPreview.addActionListener(new ActionListener() {
187 public void actionPerformed(ActionEvent arg0) {
188 logger.debug("actionPerformed menuFilePrintPreview");
189
190 }
191 });
192 }
193 return menuFilePrintPreview;
194 }
195
196 /***
197 * @return Returns the menuFileExit.
198 */
199 protected JMenuItem getMenuFileExit() {
200 if (menuFileExit == null) {
201 menuFileExit = new JMenuItem(Messages.getString("menubar.file.exit"));
202
203
204
205 menuFileExit.setAccelerator(KeyStroke.getKeyStroke(
206 KeyEvent.VK_Q, ActionEvent.ALT_MASK));
207
208 menuFileExit.addActionListener(new ActionListener() {
209 public void actionPerformed(ActionEvent arg0) {
210 logger.debug("actionPerformed menuFileExit");
211 CommandExecutor.getInstance().executeCommand(
212 new ExitCommand(), false);
213 }
214 });
215 }
216 return menuFileExit;
217 }
218
219 /***
220 * @return Returns the menuFileLoadDB.
221 */
222 protected JMenuItem getMenuFileLoadDB() {
223 if (menuFileLoadDB == null) {
224 menuFileLoadDB = new JMenuItem(Messages.getString("menubar.file.loaddatabase"));
225 menuFileLoadDB.setIcon(new ImageIcon(this.getClass().getResource(
226 "/icon/16x16/actions/document-open.png")));
227
228 menuFileLoadDB.addActionListener(new ActionListener() {
229 public void actionPerformed(ActionEvent arg0) {
230 logger.debug("actionPerformed menuFileLoadDB");
231 CommandExecutor.getInstance().executeCommand(
232 new LoadDBCommand(), false);
233 }
234 });
235 }
236 return menuFileLoadDB;
237 }
238
239 /***
240 * @return Returns the menuFileSaveDB.
241 */
242 protected JMenuItem getMenuFileSaveDB() {
243 if (menuFileSaveDB == null) {
244 menuFileSaveDB = new JMenuItem(Messages.getString("menubar.file.savedatabase"));
245 menuFileSaveDB.setIcon(new ImageIcon(this.getClass().getResource(
246 "/icon/16x16/actions/document-save.png")));
247
248 menuFileSaveDB.setAccelerator(KeyStroke.getKeyStroke(
249 KeyEvent.VK_S, ActionEvent.CTRL_MASK));
250
251 menuFileSaveDB.addActionListener(new ActionListener() {
252 public void actionPerformed(ActionEvent arg0) {
253 logger.debug("actionPerformed menuFileSaveDB");
254 CommandExecutor.getInstance().executeCommand(
255 new SaveDBCommand(), false);
256 }
257 });
258 }
259 return menuFileSaveDB;
260 }
261
262 /***
263 * @return Returns the menuFileSaveDBAs.
264 */
265 protected JMenuItem getMenuFileSaveDBAs() {
266 if (menuFileSaveDBAs == null) {
267 menuFileSaveDBAs = new JMenuItem(Messages.getString("menubar.file.savedatabaseas"));
268 menuFileSaveDBAs.setIcon(new ImageIcon(this.getClass().getResource(
269 "/icon/16x16/actions/document-save-as.png")));
270
271 menuFileSaveDBAs.setAccelerator(KeyStroke.getKeyStroke(
272 KeyEvent.VK_S, ActionEvent.CTRL_MASK+ActionEvent.SHIFT_MASK));
273
274 menuFileSaveDBAs.addActionListener(new ActionListener() {
275 public void actionPerformed(ActionEvent arg0) {
276 logger.debug("actionPerformed menuFileSaveDBAs");
277 CommandExecutor.getInstance().executeCommand(
278 new SaveDBAsCommand(), false);
279 }
280 });
281 }
282 return menuFileSaveDBAs;
283 }
284
285 /***
286 * @return Returns the menuSecurity.
287 */
288 protected JMenu getMenuSecurity() {
289 if (menuSecurity == null) {
290 menuSecurity = new JMenu(Messages.getString("menubar.security"));
291 menuSecurity.setMnemonic(KeyEvent.VK_S);
292 menuSecurity.add(getMenuSecurityLogOut());
293 }
294 return menuSecurity;
295 }
296
297 /***
298 * @return Returns the menuSecurityLogOut.
299 */
300 protected JMenuItem getMenuSecurityLogOut() {
301 if (menuSecurityLogOut == null) {
302 menuSecurityLogOut = new JMenuItem(Messages.getString("menubar.security.logout"));
303 menuSecurityLogOut.setIcon(new ImageIcon(this.getClass()
304 .getResource("/icon/16x16/actions/system-log-out.png")));
305
306 menuSecurityLogOut.addActionListener(new ActionListener() {
307 public void actionPerformed(ActionEvent arg0) {
308 logger.debug("actionPerformed menuSecurityLogOut");
309 CommandExecutor.getInstance().executeCommand(
310 new LogOutAdministratorCommand(), false);
311 }
312 });
313 }
314 return menuSecurityLogOut;
315 }
316
317 /***
318 * @return Returns the menuHelp.
319 */
320 protected JMenu getMenuHelp() {
321 if (menuHelp == null) {
322 menuHelp = new JMenu(Messages.getString("menubar.help"));
323 menuHelp.setMnemonic(KeyEvent.VK_H);
324
325 menuHelp.add(getMenuHelpContent());
326 menuHelp.add(getMenuHelpAbout());
327 menuHelp.add(getMenuHelpLicense());
328 menuHelp.add(new JSeparator());
329 menuHelp.add(getMenuHelpMessage());
330
331 }
332 return menuHelp;
333 }
334
335 /***
336 * @return Returns the menuHelpContent.
337 */
338 protected JMenuItem getMenuHelpContent() {
339 if (menuHelpContent == null) {
340 menuHelpContent = new HelpMenuItem(Messages.getString("menubar.help.contents"));
341
342
343
344 }
345 return menuHelpContent;
346 }
347
348 /***
349 * @return Returns the menuHelpAbout.
350 */
351 protected JMenuItem getMenuHelpAbout() {
352 if (menuHelpAbout == null) {
353 menuHelpAbout = new JMenuItem(Messages.getString("menubar.help.about"));
354
355
356
357 menuHelpAbout.addActionListener(new ActionListener() {
358 public void actionPerformed(ActionEvent arg0) {
359 logger.debug("actionPerformed menuHelpAbout");
360 CommandExecutor.getInstance().executeCommand(
361 new ShowAboutFrameCommand(), false);
362 }
363 });
364
365 }
366 return menuHelpAbout;
367 }
368
369 /***
370 * @return Returns the menuHelpMessage.
371 */
372 protected JMenuItem getMenuHelpMessage() {
373 if (menuHelpMessage == null) {
374 menuHelpMessage = new JMenuItem(Messages.getString("menubar.help.messages"));
375 menuHelpMessage.addActionListener(new ActionListener() {
376 public void actionPerformed(ActionEvent arg0) {
377 logger.debug("actionPerformed menuHelpMessage");
378 CommandExecutor.getInstance().executeCommand(
379 new ShowMessageFrameCommand(), false);
380 }
381 });
382 }
383 return menuHelpMessage;
384 }
385
386 /***
387 * @return Returns the menuHelpLicense.
388 */
389 protected JMenuItem getMenuHelpLicense() {
390 if (menuHelpLicense == null) {
391 menuHelpLicense = new JMenuItem(Messages.getString("menubar.help.license"));
392 menuHelpLicense.setIcon(new ImageIcon(this.getClass().getResource(
393 "/icon/16x16/mimetypes/application-certificate.png")));
394
395 menuHelpLicense.addActionListener(new ActionListener() {
396 public void actionPerformed(ActionEvent arg0) {
397 logger.debug("actionPerformed menuHelpLicense");
398 CommandExecutor.getInstance().executeCommand(
399 new ShowTextFileDialogCommand("License",
400 ConfigurationManager.LICENSE_FILE), false);
401 }
402 });
403 }
404 return menuHelpLicense;
405 }
406
407 /***
408 * @return Returns the menuEdit.
409 */
410 protected JMenu getMenuEdit() {
411 if (menuEdit == null) {
412 menuEdit = new JMenu(Messages.getString("menubar.edit"));
413 menuEdit.setMnemonic(KeyEvent.VK_E);
414
415 menuEdit.add(getMenuEditUndo());
416 menuEdit.add(getMenuEditRedo());
417 menuEdit.add(new JSeparator());
418 menuEdit.add(getMenuEditCut());
419 menuEdit.add(getMenuEditCopy());
420 menuEdit.add(getMenuEditPaste());
421 menuEdit.add(new JSeparator());
422 menuEdit.add(getMenuEditSelectAll());
423 }
424 return menuEdit;
425 }
426
427 /***
428 * @return Returns the menuEditCopy.
429 */
430 protected JMenuItem getMenuEditCopy() {
431 if (menuEditCopy == null) {
432 menuEditCopy = new JMenuItem(Messages.getString("menubar.edit.copy"));
433 menuEditCopy.setAccelerator(KeyStroke.getKeyStroke(
434 KeyEvent.VK_C, ActionEvent.CTRL_MASK));
435
436 menuEditCopy.setIcon(new ImageIcon(this.getClass().getResource(
437 "/icon/16x16/actions/edit-copy.png")));
438 }
439 return menuEditCopy;
440 }
441
442 /***
443 * @return Returns the menuEditCut.
444 */
445 protected JMenuItem getMenuEditCut() {
446 if (menuEditCut == null) {
447 menuEditCut = new JMenuItem(Messages.getString("menubar.edit.cut"));
448 menuEditCut.setAccelerator(KeyStroke.getKeyStroke(
449 KeyEvent.VK_X, ActionEvent.CTRL_MASK));
450
451 menuEditCut.setIcon(new ImageIcon(this.getClass().getResource(
452 "/icon/16x16/actions/edit-cut.png")));
453 }
454 return menuEditCut;
455 }
456
457 /***
458 * @return Returns the menuEditPaste.
459 */
460 protected JMenuItem getMenuEditPaste() {
461 if (menuEditPaste == null) {
462 menuEditPaste = new JMenuItem(Messages.getString("menubar.edit.paste"));
463 menuEditPaste.setAccelerator(KeyStroke.getKeyStroke(
464 KeyEvent.VK_V, ActionEvent.CTRL_MASK));
465
466 menuEditPaste.setIcon(new ImageIcon(this.getClass().getResource(
467 "/icon/16x16/actions/edit-paste.png")));
468 }
469 return menuEditPaste;
470 }
471
472 /***
473 * @return Returns the menuEditRedo.
474 */
475 protected JMenuItem getMenuEditRedo() {
476 if (menuEditRedo == null) {
477 menuEditRedo = new JMenuItem(Messages.getString("menubar.edit.redo"));
478 menuEditRedo.setAccelerator(KeyStroke.getKeyStroke(
479 KeyEvent.VK_Y, ActionEvent.CTRL_MASK));
480
481 menuEditRedo.setIcon(new ImageIcon(this.getClass().getResource(
482 "/icon/16x16/actions/edit-redo.png")));
483 }
484 return menuEditRedo;
485 }
486
487 /***
488 * @return Returns the menuEditUndo.
489 */
490 protected JMenuItem getMenuEditUndo() {
491 if (menuEditUndo == null) {
492 menuEditUndo = new JMenuItem(Messages.getString("menubar.edit.undo"));
493 menuEditUndo.setAccelerator(KeyStroke.getKeyStroke(
494 KeyEvent.VK_Z, ActionEvent.CTRL_MASK));
495 menuEditUndo.setIcon(new ImageIcon(this.getClass().getResource(
496 "/icon/16x16/actions/edit-undo.png")));
497 }
498 return menuEditUndo;
499 }
500
501 /***
502 * @return Returns the menuEditSelectAll.
503 */
504 protected JMenuItem getMenuEditSelectAll() {
505 if (menuEditSelectAll == null) {
506 menuEditSelectAll = new JMenuItem(Messages.getString("menubar.edit.selectall"));
507 menuEditSelectAll.setAccelerator(KeyStroke.getKeyStroke(
508 KeyEvent.VK_A, ActionEvent.CTRL_MASK));
509
510 menuEditSelectAll.setIcon(new ImageIcon(this.getClass().getResource(
511 "/icon/16x16/actions/edit-select-all.png")));
512 }
513 return menuEditSelectAll;
514 }
515
516 /***
517 * @return Returns the subMenuFileNewUserFromVCard.
518 */
519 protected JMenuItem getSubMenuFileNewUserFromVCard() {
520 if (subMenuFileNewUserFromVCard == null) {
521 subMenuFileNewUserFromVCard = new JMenuItem(Messages.getString("menubar.file.new.userfromvcard"));
522 subMenuFileNewUserFromVCard.setAccelerator(KeyStroke.getKeyStroke(
523 KeyEvent.VK_N, ActionEvent.CTRL_MASK));
524
525 subMenuFileNewUserFromVCard.setIcon(new ImageIcon(this.getClass().getResource(
526 "/icon/16x16/actions/contact-new.png")));
527 subMenuFileNewUserFromVCard.addActionListener(new ActionListener(){
528
529 public void actionPerformed(ActionEvent arg0) {
530 logger
531 .debug("actionPerformed subMenuFileNewUserFromVCard");
532
533 CommandExecutor.getInstance().executeCommand(
534 new ImportUserFromVCardCommand(), false);
535 }
536
537 });
538
539 }
540 return subMenuFileNewUserFromVCard;
541 }
542
543 /***
544 * @return Returns the subMenuFileExport.
545 */
546 protected JMenu getSubMenuFileExport() {
547 if (subMenuFileExport == null) {
548 subMenuFileExport = new JMenu(Messages.getString("menubar.file.export"));
549 subMenuFileExport
550 .add(getSubMenuFileExportUserList());
551 subMenuFileExport
552 .add(getSubMenuFileExportSessionList());
553 }
554 return subMenuFileExport;
555 }
556
557 /***
558 * @return Returns the subMenuFileExportSessionList.
559 */
560 protected JMenuItem getSubMenuFileExportSessionList() {
561 if (subMenuFileExportSessionList == null) {
562 subMenuFileExportSessionList = new JMenuItem(
563 Messages.getString("menubar.file.export.sessionlist"));
564 subMenuFileExportSessionList.setIcon(new ImageIcon(this.getClass().getResource(
565 "/icon/16x16/apps/preferences-system-windows.png")));
566 subMenuFileExportSessionList
567 .addActionListener(new ActionListener() {
568 public void actionPerformed(ActionEvent arg0) {
569 logger
570 .debug("actionPerformed subMenuFileExportUserList");
571 CommandExecutor
572 .getInstance()
573 .executeCommand(
574 new ExportSessionListCommand(),false);
575 }
576 });
577 }
578 return subMenuFileExportSessionList;
579 }
580
581 /***
582 * @return Returns the subMenuFileExportUserList.
583 */
584 protected JMenuItem getSubMenuFileExportUserList() {
585 if (subMenuFileExportUserList == null) {
586 subMenuFileExportUserList = new JMenuItem(
587 Messages.getString("menubar.file.export.userlist"));
588 subMenuFileExportUserList.setIcon(new ImageIcon(this.getClass().getResource(
589 "/icon/16x16/apps/system-users.png")));
590
591 subMenuFileExportUserList
592 .addActionListener(new ActionListener() {
593 public void actionPerformed(ActionEvent arg0) {
594 logger
595 .debug("actionPerformed subMenuFileExportUserList");
596 CommandExecutor
597 .getInstance()
598 .executeCommand(
599 new ExportUserListCommand(),false);
600 }
601 });
602
603 }
604 return subMenuFileExportUserList;
605 }
606 }