1 package com.nilhcem.fakesmtp.gui;
2
3 import com.nilhcem.fakesmtp.core.ArgsHandler;
4 import com.nilhcem.fakesmtp.core.I18n;
5 import com.nilhcem.fakesmtp.gui.listeners.AboutActionListener;
6 import com.nilhcem.fakesmtp.gui.listeners.ExitActionListener;
7
8 import javax.swing.JMenu;
9 import javax.swing.JMenuBar;
10 import javax.swing.JMenuItem;
11 import java.awt.event.ActionEvent;
12 import java.awt.event.ActionListener;
13 import java.util.Observable;
14
15
16
17
18
19
20
21 public final class MenuBar extends Observable {
22
23 private final I18n i18n = I18n.INSTANCE;
24 private final JMenuBar menuBar = new JMenuBar();
25 private final MainFrame mainFrame;
26
27
28
29
30
31
32 public MenuBar(MainFrame mainFrame) {
33 this.mainFrame = mainFrame;
34
35 menuBar.add(createFileMenu());
36 menuBar.add(createEditMenu());
37 menuBar.add(createHelpMenu());
38 }
39
40
41
42
43
44
45 public JMenuBar get() {
46 return menuBar;
47 }
48
49
50
51
52
53
54
55
56
57 private JMenu createFileMenu() {
58 JMenu fileMenu = new JMenu(i18n.get("menubar.file"));
59 fileMenu.setMnemonic(i18n.get("menubar.mnemo.file").charAt(0));
60
61 JMenuItem exit = new JMenuItem(i18n.get("menubar.exit"));
62 exit.setMnemonic(i18n.get("menubar.mnemo.exit").charAt(0));
63 exit.addActionListener(new ExitActionListener(mainFrame));
64
65 fileMenu.add(exit);
66 return fileMenu;
67 }
68
69
70
71
72
73
74
75
76
77 private JMenu createEditMenu() {
78 JMenu editMenu = new JMenu(i18n.get("menubar.edit"));
79 editMenu.setMnemonic(i18n.get("menubar.mnemo.edit").charAt(0));
80
81 JMenuItem mailsLocation = new JMenuItem(i18n.get("menubar.messages.location"));
82 mailsLocation.setMnemonic(i18n.get("menubar.mnemo.msglocation").charAt(0));
83 if (ArgsHandler.INSTANCE.memoryModeEnabled()) {
84 mailsLocation.setEnabled(false);
85 } else {
86 mailsLocation.addActionListener(new ActionListener() {
87 @Override
88 public void actionPerformed(ActionEvent e) {
89 setChanged();
90 notifyObservers();
91 }
92 });
93 }
94
95 editMenu.add(mailsLocation);
96 return editMenu;
97 }
98
99
100
101
102
103
104
105
106
107 private JMenu createHelpMenu() {
108 JMenu helpMenu = new JMenu(i18n.get("menubar.help"));
109 helpMenu.setMnemonic(i18n.get("menubar.mnemo.help").charAt(0));
110
111 JMenuItem about = new JMenuItem(i18n.get("menubar.about"));
112 about.setMnemonic(i18n.get("menubar.mnemo.about").charAt(0));
113 about.addActionListener(new AboutActionListener(menuBar.getParent()));
114
115 helpMenu.add(about);
116 return helpMenu;
117 }
118 }