7 package org.libcsdbg.jtracer;
9 import java.util.Vector;
11 import java.beans.PropertyChangeEvent;
12 import java.beans.PropertyChangeListener;
14 import java.awt.event.InputEvent;
15 import java.awt.event.ActionEvent;
16 import java.awt.event.ActionListener;
18 import java.awt.Color;
19 import java.awt.Component;
21 import javax.swing.KeyStroke;
22 import javax.swing.JMenuItem;
23 import javax.swing.JMenu;
24 import javax.swing.JMenuBar;
25 import javax.swing.JFrame;
26 import javax.swing.ImageIcon;
27 import javax.swing.BorderFactory;
28 import javax.swing.border.EtchedBorder;
30 import static java.awt.event.KeyEvent.*;
35 public class MenuBar extends JMenuBar implements
37 PropertyChangeListener
58 setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
60 Registry conf = Registry.getCurrent();
61 Font fnt = (Font) conf.
get(
"component",
"font");
62 Color fg = (Color) conf.get(
"component",
"fgcolor");
65 JMenu menu =
new JMenu(
"Service");
67 menu.setForeground(fg);
68 menu.setMnemonic(VK_S);
80 menu =
new JMenu(
"View");
82 menu.setForeground(fg);
83 menu.setMnemonic(VK_V);
91 menu.add(
createItem(
"Preferences...", VK_P, VK_P));
94 menu.add(
createItem(
"Full screen", VK_U, VK_F11));
98 menu =
new JMenu(
"Session");
100 menu.setForeground(fg);
101 menu.setMnemonic(VK_I);
103 menu.add(
createItem(
"Select previous", VK_P, VK_COMMA));
104 menu.add(
createItem(
"Select next", VK_N, VK_PERIOD));
108 menu.add(
createItem(
"Cascade", VK_S, VK_SLASH));
109 menu.add(
createItem(
"Minimize all", VK_M, VK_DOWN));
110 menu.add(
createItem(
"Restore all", VK_R, VK_UP));
111 menu.add(
createItem(
"Close all", VK_E, VK_E));
115 menu =
new JMenu(
"Help");
117 menu.setForeground(fg);
118 menu.setMnemonic(VK_H);
120 menu.add(
createItem(
"Online documentation", VK_D, 0));
122 menu.add(
createItem(
"Submit feedback", VK_F, 0));
123 menu.add(
createItem(
"Check for updates", VK_U, 0));
126 String nm = (String) conf.get(
"generic",
"name");
127 menu.add(
createItem(
"About " + nm, VK_A, VK_F1));
143 JMenu menu = getMenu(2);
144 Registry conf = Registry.getCurrent();
145 ImageIcon onIcon = conf.loadIcon(
"on16.png");
146 ImageIcon offIcon = conf.loadIcon(
"voidrect16.png");
148 for (
int i = menu.getMenuComponentCount() - 1; i >= 9; i--) {
149 JMenuItem item = (JMenuItem) menu.getMenuComponent(i);
150 item.setIcon((i - 9 == sel) ? onIcon : offIcon);
164 JMenu menu = getMenu(2);
165 while (menu.getMenuComponentCount() > 8)
168 int cnt = list.size();
173 Registry conf = Registry.getCurrent();
174 Font fnt = (Font) conf.
get(
"component",
"font");
175 Color fg = (Color) conf.get(
"component",
"fgcolor");
176 Integer delay = (Integer) conf.get(
"component",
"click-delay");
177 ImageIcon onIcon = conf.loadIcon(
"on16.png");
178 ImageIcon offIcon = conf.loadIcon(
"voidrect16.png");
180 for (
int i = 0; i < cnt; i++) {
181 JFrame sess = (JFrame) list.get(i);
183 JMenuItem item =
new JMenuItem(sess.getTitle() +
" ");
185 item.setForeground(fg);
187 item.setMultiClickThreshhold(delay);
190 int accel = VK_0 + i;
191 KeyStroke ks = KeyStroke.getKeyStroke(accel, InputEvent.ALT_DOWN_MASK);
192 item.setAccelerator(ks);
195 item.setIcon((i == sel) ? onIcon : offIcon);
196 item.setActionCommand(
"Select session " + i);
197 item.addActionListener(
handler);
227 private JMenuItem
createItem(String text,
int mnemonic,
int accel)
229 JMenuItem retval =
new JMenuItem(text +
" ");
230 retval.setMnemonic(mnemonic);
232 Registry conf = Registry.getCurrent();
233 retval.setFont((Font) conf.get(
"component",
"font"));
234 retval.setForeground((Color) conf.get(
"component",
"fgcolor"));
236 Integer delay = (Integer) conf.
get(
"component",
"click-delay");
238 retval.setMultiClickThreshhold(delay);
242 if (accel < VK_F1 || accel > VK_F12)
243 modifiers |= InputEvent.CTRL_DOWN_MASK;
245 KeyStroke ks = KeyStroke.getKeyStroke(accel, modifiers);
246 retval.setAccelerator(ks);
250 text = text.replace(
'.',
' ').trim();
251 retval.setActionCommand(text);
252 retval.addActionListener(
handler);
254 String nm = text.toLowerCase().replace(
' ',
'_') +
"16.png";
255 retval.setIcon(conf.loadIcon(nm));
273 JMenuItem retval =
new JMenuItem(text);
274 retval.setMnemonic(mnemonic);
276 Registry conf = Registry.getCurrent();
277 retval.setFont((Font) conf.get(
"component",
"font"));
278 retval.setForeground((Color) conf.get(
"component",
"fgcolor"));
280 Integer delay = (Integer) conf.
get(
"component",
"click-delay");
282 retval.setMultiClickThreshhold(delay);
284 retval.setActionCommand(text);
285 retval.addActionListener(
handler);
286 retval.addActionListener(
this);
288 String nm = ((
toggleStates[index]) ?
"on" :
"off") +
"16.png";
289 retval.setIcon(conf.loadIcon(nm));
307 private void renderItem(Component c,
int menu,
int i, String key, Object val)
309 Boolean how = (Boolean) val;
311 if (key.equals(
"isServing")) {
326 else if (key.equals(
"hasClients"))
348 String cmd = event.getActionCommand();
351 if (cmd.equals(
"Statusbar"))
354 else if (cmd.equals(
"Always on top"))
360 String nm = ((state) ?
"on" :
"off") +
"16.png";
362 Registry conf = Registry.getCurrent();
363 getMenu(1).getItem(index).setIcon(conf.
loadIcon(nm));
366 catch (Throwable t) {
380 String key = event.getPropertyName();
381 Object val = event.getNewValue();
383 for (
int i = getMenuCount() - 1; i >= 0; i--) {
384 JMenu menu = getMenu(i);
386 for (
int j = menu.getMenuComponentCount() - 1; j >= 0; j--) {
387 Component c = menu.getMenuComponent(j);
388 if (c instanceof JMenuItem)
394 catch (Throwable t) {
Object get(String section, String key)
Get an entry.
ImageIcon loadIcon(String nm)
Load an icon from the current theme.