JPopupMenu popupMenu = new JPopupMenu();
if (searchText != null && searchText.length() > 0) {
String value = ProgramInfo.getInstance().getSettings()
.getActorSearch();
JMenuItem item = searchTextMenuItem(searchText);
if (value.equals("internalSearch")) {
item.setFont(item.getFont().deriveFont(Font.BOLD));
}
popupMenu.add(item);
item = new JMenuItem(mLocalizer.msg("searchWikipedia",
"Search in Wikipedia"));
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
searchWikipedia(searchText);
}
});
if (value.equals("internalWikipedia")) {
item.setFont(item.getFont().deriveFont(Font.BOLD));
}
popupMenu.add(item);
final PluginAccess webPlugin = PluginManagerImpl.getInstance()
.getActivatedPluginForId("java.webplugin.WebPlugin");
if (webPlugin != null && webPlugin.canReceiveProgramsWithTarget()) {
ProgramReceiveTarget[] targets = webPlugin
.getProgramReceiveTargets();
if (targets != null && targets.length > 0) {
final JMenu subMenu = new JMenu(webPlugin.getInfo().getName());
subMenu.setIcon(webPlugin.getMarkIcon());
popupMenu.add(subMenu);
for (final ProgramReceiveTarget target : targets) {
item = new JMenuItem(target.toString());
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
searchWebPlugin(searchText, target);
}
});
if (value.endsWith(target.getTargetId())) {
item.setFont(item.getFont().deriveFont(Font.BOLD));
}
subMenu.add(item);
}
}
}
popupMenu.addSeparator();
popupMenu.add(addFavoriteMenuItem(searchText, actorFavorite));
popupMenu.addSeparator();
}
JMenu subMenu = ContextMenuManager.getInstance()
.createContextMenuItems(ProgramInfoProxy.getInstance(), mProgram,
true);
subMenu.setText(Localizer.getLocalization(Localizer.I18N_PROGRAM));
popupMenu.add(subMenu);
return popupMenu;
}
private void handleEvent(MouseEvent e, boolean popupEvent) {
JEditorPane editor = (JEditorPane) e.getSource();
Point pt = new Point(e.getX(), e.getY());
int pos = editor.viewToModel(pt);
if (pos >= 0) {
String link = getLink(pos, editor);
if (link != null
&& link.startsWith(ProgramTextCreator.TVBROWSER_URL_PROTOCOL)) {
final String searchText = link
.substring(ProgramTextCreator.TVBROWSER_URL_PROTOCOL.length());
if (popupEvent) {
JPopupMenu popupMenu = getPopupMenu(searchText, true);
popupMenu.show(e.getComponent(), e.getX(), e.getY());
} else {
String value = ProgramInfo.getInstance().getSettings()
.getActorSearch();
boolean found = false;
if (value.contains("#_#_#")) {
String[] keys = value.split("#_#_#");
PluginAccess webPlugin = PluginManagerImpl.getInstance()
.getActivatedPluginForId(keys[0]);
if (webPlugin != null
&& webPlugin.canReceiveProgramsWithTarget()) {
ProgramReceiveTarget[] targets = webPlugin
.getProgramReceiveTargets();
if (targets != null) {
for (ProgramReceiveTarget target : targets) {
if (target.getTargetId().equals(keys[1])) {
searchWebPlugin(searchText, target);
found = true;
}
}
}
}
}
if (!found) {
if (value.equals("internalSearch")) {
internalSearch(searchText);
} else {
searchWikipedia(searchText);
}
}
}
} else if (popupEvent){
String selection = getSelection(pos, editor);
JPopupMenu popupMenu = getPopupMenu(selection, false);
TextComponentPopupEventQueue.addStandardContextMenu(mInfoEP,
popupMenu);
popupMenu.show(e.getComponent(), e.getX(), e.getY());
}
}
}
private JMenuItem searchTextMenuItem(final String desc) {
JMenuItem item = new JMenuItem(mLocalizer.msg("searchTvBrowser",
"Search in TV-Browser"), IconLoader.getInstance().getIconFromTheme(
"actions", "edit-find"));
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
internalSearch(desc);
}
});
return item;
}
private JMenuItem addFavoriteMenuItem(final String desc,
final boolean actor) {
JMenuItem item;
item = new JMenuItem(mLocalizer.ellipsisMsg("addFavorite",
"Create favorite"), IconLoader.getInstance().getIconFromTheme(
"emblems", "emblem-favorite"));
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (actor) {
FavoritesPlugin.getInstance().showCreateActorFavoriteWizard(
mProgram, desc);
} else {