* @param markDefaultIf True if the default context menu interfaces should be highlighted.
* @return The menu items of the context menu.
*/
public JMenu createContextMenuItems(ContextMenuIf callerIf, Program program, boolean markDefaultIf) {
ArrayList<JMenuItem> items = new ArrayList<JMenuItem>();
ContextMenuIf leftSingleClickIf = getInstance().getLeftSingleClickIf();
ContextMenuIf defaultIf = getInstance().getDefaultContextMenuIf();
ContextMenuIf middleClickIf = getInstance().getMiddleClickIf();
ContextMenuIf middleDoubleClickIf = getInstance().getMiddleDoubleClickIf();
ContextMenuIf[] menuIfArr = getInstance().getAvailableContextMenuIfs(false, true);
JMenu rootMenu = new JMenu();
for (ContextMenuIf element : menuIfArr) {
ContextMenuIf menuIf = element;
boolean equalsPlugin = false;
if ((callerIf != null) && (callerIf.getId().equals(menuIf.getId()))) {
equalsPlugin = true;
}
if (menuIf instanceof SeparatorMenuItem) {
if (rootMenu.getMenuComponentCount() > 0) {
rootMenu.addSeparator();
}
} else if (menuIf instanceof ConfigMenuItem) {
JMenuItem item = new JMenuItem(menuIf.toString());
item.setIcon(TVBrowserIcons.preferences(TVBrowserIcons.SIZE_SMALL));
item.setFont(MenuUtil.CONTEXT_MENU_PLAINFONT);
item.addActionListener(new ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
MainFrame.getInstance().showSettingsDialog(SettingsItem.CONTEXTMENU);
};
});
rootMenu.add(item);
} else if (menuIf instanceof LeaveFullScreenMenuItem) {
if (MainFrame.getInstance().isFullScreenMode()) {
JMenuItem item = new JMenuItem(menuIf.toString());
item.setFont(MenuUtil.CONTEXT_MENU_PLAINFONT);
item.setIcon(TVBrowserIcons.fullScreen(TVBrowserIcons.SIZE_SMALL));
item.addActionListener(new ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
if (MainFrame.getInstance().isFullScreenMode()) {
MainFrame.getInstance().switchFullscreenMode();
}
};
});
rootMenu.add(item);
}
} else if (!equalsPlugin) {
ActionMenu actionMenu = menuIf.getContextMenuActions(program);
if (actionMenu != null) {
JMenuItem menuItem = MenuUtil.createMenuItem(actionMenu);
items.add(menuItem);
if (menuIf == leftSingleClickIf && markDefaultIf && !menuIf.equals(DoNothingContextMenuItem.getInstance())) {
((JMenuItem)getLastFirstMenuEntry(menuItem)).setForeground(new Color(0,90,0));
}
else if (menuIf == middleDoubleClickIf && markDefaultIf && !menuIf.equals(DoNothingContextMenuItem.getInstance())) {
((JMenuItem)getLastFirstMenuEntry(menuItem)).setForeground(new Color(0,0,160));
}
if (menuIf == defaultIf && menuIf == middleClickIf && markDefaultIf && !menuIf.equals(DoNothingContextMenuItem.getInstance())) {
((JMenuItem)getLastFirstMenuEntry(menuItem)).setFont(MenuUtil.CONTEXT_MENU_BOLDITALICFONT);
}
else if (menuIf == defaultIf && markDefaultIf && !menuIf.equals(DoNothingContextMenuItem.getInstance())) {
((JMenuItem)getLastFirstMenuEntry(menuItem)).setFont(MenuUtil.CONTEXT_MENU_BOLDFONT);
}
else if (menuIf == middleClickIf && markDefaultIf && !menuIf.equals(DoNothingContextMenuItem.getInstance())) {
((JMenuItem)getLastFirstMenuEntry(menuItem)).setFont(MenuUtil.CONTEXT_MENU_ITALICFONT);
}
rootMenu.add(menuItem);
}