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);
}
}
});