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 {
FavoritesPlugin.getInstance().showCreateTopicFavoriteWizard(
mProgram, desc);
}
}
});
return item;
}
private void searchWebPlugin(String desc, ProgramReceiveTarget target) {
target.getReceifeIfForIdOfTarget().receiveValues(new String[] { desc },
target);
}
private void searchWikipedia(String desc) {
DontShowAgainOptionBox
.showOptionDialog(
"programInfoDialog.newActorSearch",
mDialog,
ProgramInfo.mLocalizer
.msg(
"newActorSearchText",
"This function was changed for TV-Browser 2.7. The search type is now\nchangeable in the settings of the Program details, additional now available\nis a context menu for the actor search."),
ProgramInfo.mLocalizer
.msg("newActorSearch", "New actor search"));
try {
String url = URLEncoder.encode(desc, "UTF-8").replace("+", "%20");
url = mLocalizer.msg("wikipediaLink",
"http://en.wikipedia.org/wiki/{0}", url);
Launch.openURL(url);
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
}
private void internalSearch(String desc) {
desc = desc.replaceAll(" ", " ").replaceAll(" ", " AND ");
SearchFormSettings settings = new SearchFormSettings(desc);
settings.setSearchIn(SearchFormSettings.SEARCH_IN_ALL);
settings.setSearcherType(PluginManager.SEARCHER_TYPE_BOOLEAN);
settings.setNrDays(-1);
SearchHelper.search(mInfoEP, settings, null, true);
}
private String getLink(int pos, JEditorPane html) {
Document doc = html.getDocument();
if (doc instanceof HTMLDocument) {
HTMLDocument hdoc = (HTMLDocument) doc;
Element e = hdoc.getCharacterElement(pos);
AttributeSet a = e.getAttributes();
AttributeSet anchor = (AttributeSet) a.getAttribute(HTML.Tag.A);
if (anchor != null) {
return (String) anchor.getAttribute(HTML.Attribute.HREF);
}
}
return null;
}
private String getSelection(int pos, JEditorPane html) {
Caret caret = html.getCaret();
if (caret != null) {
try {
int start = Math.min(caret.getDot(), caret.getMark());
int length = Math.abs(caret.getDot() - caret.getMark());
return html.getDocument().getText(start, length);
} catch (BadLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
});
mInfoEP.addHyperlinkListener(new HyperlinkListener() {
private String mTooltip;
public void hyperlinkUpdate(HyperlinkEvent evt) {
if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) {
mTooltip = mInfoEP.getToolTipText();
mInfoEP.setToolTipText(getLinkTooltip(evt));
}
if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) {
mInfoEP.setToolTipText(mTooltip);
}
if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
URL url = evt.getURL();
if (url != null) {
Launch.openURL(url.toString());
}
}
}
});
mFindAsYouType = new TextComponentFindAction(mInfoEP, true);
final JScrollPane scrollPane = new JScrollPane(mInfoEP);
scrollPane.getVerticalScrollBar().setUnitIncrement(30);
// ScrollActions
mUpAction = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
scrollPane.getVerticalScrollBar().setValue(
scrollPane.getVerticalScrollBar().getValue()
- scrollPane.getVerticalScrollBar().getUnitIncrement());
}
};
mDownAction = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
scrollPane.getVerticalScrollBar().setValue(
scrollPane.getVerticalScrollBar().getValue()
+ scrollPane.getVerticalScrollBar().getUnitIncrement());
}
};
mPluginsPane = new JTaskPane();
mPluginsPane.add(mFunctionGroup);
mActionsPane = new JScrollPane(mPluginsPane);
mConfigBtn = new JButton(mLocalizer.msg("config", "Configure view"));
mConfigBtn.setIcon(TVBrowserIcons.preferences(TVBrowserIcons.SIZE_SMALL));
ButtonBarBuilder2 buttonBuilder = new ButtonBarBuilder2();
buttonBuilder.addButton(mConfigBtn);
mConfigBtn.setVisible(showSettings);
if (pluginsSize == null) {
mActionsPane.setPreferredSize(new Dimension(250, 500));
} else {
mActionsPane.setPreferredSize(pluginsSize);
}
if (ProgramInfo.getInstance().getSettings().getShowFunctions()) {
JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
split.setDividerSize(5);
split.setContinuousLayout(true);
split.setDividerLocation(mActionsPane.getPreferredSize().width + 1);
split.setLeftComponent(mActionsPane);
split.setRightComponent(scrollPane);
mMainPanel.add(split, BorderLayout.CENTER);
mFindAsYouType.installKeyListener(split);
} else {
final JButton functions = new JButton(mLocalizer.msg("functions",
"Functions"));
functions.setFocusable(false);
functions.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 1) {
JPopupMenu popupMenu = PluginProxyManager.createPluginContextMenu(
mProgram, ProgramInfoProxy.getInstance());
popupMenu.show(functions, e.getX(), e.getY()
- popupMenu.getPreferredSize().height);
}
}
});
buttonBuilder.addUnrelatedGap();
buttonBuilder.addButton(functions);
mMainPanel.add(scrollPane, BorderLayout.CENTER);
}
// buttons
JPanel buttonPn = new JPanel(new BorderLayout(0, 5));
buttonPn.add(mFindAsYouType.getSearchBar(), BorderLayout.NORTH);
buttonPn.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
mMainPanel.add(buttonPn, BorderLayout.SOUTH);
mConfigBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
exit();
MainFrame.getInstance().showSettingsDialog(SettingsItem.PROGRAMINFO);
}
});
mHighlight = new JCheckBox(mLocalizer
.msg("highlight", "Highlight favorite"), ProgramInfo.getInstance()
.getSettings().getHighlightFavorite());
mHighlight.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ProgramInfo.getInstance().getSettings().setHighlightFavorite(
mHighlight.isSelected());
highlightFavorites();
}
});
buttonBuilder.addUnrelatedGap();
buttonBuilder.addFixed(mHighlight);
mCloseBtn = new JButton(Localizer.getLocalization(Localizer.I18N_CLOSE));
mCloseBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
exit();
}
});