EMMA Coverage Report (generated Sun Apr 20 22:38:01 CEST 2008)
[all classes][net.sf.jomic.ui]

COVERAGE SUMMARY FOR SOURCE FILE [FramelessJomicMenuBar.java]

nameclass, %method, %block, %line, %
FramelessJomicMenuBar.java0%   (0/1)0%   (0/1)0%   (0/132)0%   (0/23)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class FramelessJomicMenuBar0%   (0/1)0%   (0/1)0%   (0/132)0%   (0/23)
FramelessJomicMenuBar (): void 0%   (0/1)0%   (0/132)0%   (0/23)

1// Jomic - a viewer for comic book archives.
2// Copyright (C) 2004-2008 Thomas Aglassinger
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program.  If not, see <http://www.gnu.org/licenses/>.
16package net.sf.jomic.ui;
17 
18import java.util.Arrays;
19 
20import javax.swing.JMenu;
21import javax.swing.JMenuItem;
22 
23import net.sf.jomic.tools.StringTools;
24import net.sf.wraplog.Logger;
25 
26/**
27 *  JomicMenuBar to be used under Mac OS X when no window is open. Most items will be disabled
28 *  because they only make sense in context of a comic.
29 *
30 * @see       net.roydesign.mac.MRJAdapter#setFramelessJMenuBar(javax.swing.JMenuBar)
31 * @author    Thomas Aglassinger
32 */
33public class FramelessJomicMenuBar extends JomicMenuBar
34{
35    private String[] commandsToEnable = new String[]{
36            Commands.CONVERT,
37            Commands.DUMMY_GO_TO_URI,
38            Commands.HELP,
39            Commands.NEW_COMIC,
40            Commands.OPEN,
41            Commands.OPEN_IN_NEW_WINDOW,
42            Commands.OPEN_RECENT,
43            Commands.SYSTEM_INFO
44            };
45    private Logger logger;
46    private StringTools stringTools;
47 
48    public FramelessJomicMenuBar() {
49        super();
50        logger = Logger.getLogger(FramelessJomicMenuBar.class);
51        stringTools = StringTools.instance();
52        Arrays.sort(commandsToEnable);
53 
54        // Disable all menu items except those that make sense without a comic
55        // opened.
56        for (int menuIndex = 0; menuIndex < getMenuCount(); menuIndex += 1) {
57            boolean anyItemEnabled = false;
58            JMenu menu = getMenu(menuIndex);
59 
60            for (int itemIndex = 0; itemIndex < menu.getItemCount(); itemIndex += 1) {
61                JMenuItem item = menu.getItem(itemIndex);
62                boolean isSeparator = (item == null);
63                boolean isSubMenu = (item instanceof JMenu);
64 
65                if (!isSeparator && !isSubMenu) {
66                    String command = item.getActionCommand();
67 
68                    if ((command == null) || (stringTools.equalsAnyOf(commandsToEnable, command))) {
69                        anyItemEnabled = true;
70                        // There is no window open, so we actually have to
71                        // open the comic in a new window.
72                        if (command.equals(Commands.OPEN)) {
73                            item.setActionCommand(Commands.OPEN_IN_NEW_WINDOW);
74                        }
75                    } else {
76                        logger.debug("disable menu item \"{}\" (command={})", item.getText(), command);
77                        item.setEnabled(false);
78                    }
79                }
80            }
81            if (!anyItemEnabled) {
82                menu.setEnabled(false);
83            }
84        }
85 
86    }
87}

[all classes][net.sf.jomic.ui]
EMMA 2.0.4217 (C) Vladimir Roubtsov