use of javax.swing.text.html.HTMLDocument in project intellij-community by JetBrains.
the class NotificationMessageElement method updateStyle.
protected void updateStyle(@NotNull JEditorPane editorPane, @Nullable JTree tree, Object value, boolean selected, boolean hasFocus) {
final HTMLDocument htmlDocument = (HTMLDocument) editorPane.getDocument();
final Style style = htmlDocument.getStyleSheet().getStyle(MSG_STYLE);
if (value instanceof LoadingNode) {
StyleConstants.setForeground(style, JBColor.GRAY);
} else {
if (selected) {
StyleConstants.setForeground(style, hasFocus ? UIUtil.getTreeSelectionForeground() : UIUtil.getTreeTextForeground());
} else {
StyleConstants.setForeground(style, UIUtil.getTreeTextForeground());
}
}
if (UIUtil.isUnderGTKLookAndFeel() || UIUtil.isUnderNimbusLookAndFeel() && selected && hasFocus || tree != null && WideSelectionTreeUI.isWideSelection(tree)) {
editorPane.setOpaque(false);
} else {
editorPane.setOpaque(selected && hasFocus);
}
htmlDocument.setCharacterAttributes(0, htmlDocument.getLength(), style, false);
}
use of javax.swing.text.html.HTMLDocument in project intellij-community by JetBrains.
the class NotificationMessageElement method installJep.
protected JEditorPane installJep(@NotNull JEditorPane myEditorPane) {
String message = StringUtil.join(this.getText(), "<br>");
myEditorPane.setEditable(false);
myEditorPane.setOpaque(false);
myEditorPane.setEditorKit(UIUtil.getHTMLEditorKit());
myEditorPane.setHighlighter(null);
final StyleSheet styleSheet = ((HTMLDocument) myEditorPane.getDocument()).getStyleSheet();
final Style style = styleSheet.addStyle(MSG_STYLE, null);
styleSheet.addStyle(LINK_STYLE, style);
myEditorPane.setText(message);
return myEditorPane;
}
use of javax.swing.text.html.HTMLDocument in project intellij-community by JetBrains.
the class AppUIUtil method showPrivacyPolicyAgreement.
/**
* @param htmlText Updated version of Privacy Policy text if any.
* If it's {@code null}, the standard text from bundled resources would be used.
*/
public static void showPrivacyPolicyAgreement(@NotNull String htmlText) {
DialogWrapper dialog = new DialogWrapper(true) {
@Nullable
@Override
protected JComponent createCenterPanel() {
JPanel centerPanel = new JPanel(new BorderLayout(JBUI.scale(5), JBUI.scale(5)));
JEditorPane viewer = SwingHelper.createHtmlViewer(true, null, JBColor.WHITE, JBColor.BLACK);
viewer.setFocusable(true);
viewer.addHyperlinkListener(new HyperlinkAdapter() {
@Override
protected void hyperlinkActivated(HyperlinkEvent e) {
URL url = e.getURL();
if (url != null) {
BrowserUtil.browse(url);
} else {
SwingHelper.scrollToReference(viewer, e.getDescription());
}
}
});
viewer.setText(htmlText);
StyleSheet styleSheet = ((HTMLDocument) viewer.getDocument()).getStyleSheet();
styleSheet.addRule("body {font-family: \"Segoe UI\", Tahoma, sans-serif;}");
styleSheet.addRule("body {margin-top:0;padding-top:0;}");
styleSheet.addRule("body {font-size:" + JBUI.scaleFontSize(13) + "pt;}");
styleSheet.addRule("h2, em {margin-top:" + JBUI.scaleFontSize(20) + "pt;}");
styleSheet.addRule("h1, h2, h3, p, h4, em {margin-bottom:0;padding-bottom:0;}");
styleSheet.addRule("p, h1 {margin-top:0;padding-top:" + JBUI.scaleFontSize(6) + "pt;}");
styleSheet.addRule("li {margin-bottom:" + JBUI.scaleFontSize(6) + "pt;}");
styleSheet.addRule("h2 {margin-top:0;padding-top:" + JBUI.scaleFontSize(13) + "pt;}");
viewer.setCaretPosition(0);
viewer.setBorder(JBUI.Borders.empty(0, 5, 5, 5));
centerPanel.add(new JLabel("Please read and accept these terms and conditions:"), BorderLayout.NORTH);
centerPanel.add(new JBScrollPane(viewer, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
return centerPanel;
}
@Override
protected void createDefaultActions() {
super.createDefaultActions();
init();
setOKButtonText("Accept");
setCancelButtonText("Reject and Exit");
setAutoAdjustable(false);
}
@Override
public void doCancelAction() {
super.doCancelAction();
ApplicationEx application = ApplicationManagerEx.getApplicationEx();
if (application == null) {
System.exit(Main.PRIVACY_POLICY_REJECTION);
} else {
((ApplicationImpl) application).exit(true, true, false);
}
}
};
dialog.setModal(true);
dialog.setTitle(ApplicationNamesInfo.getInstance().getFullProductName() + " Privacy Policy Agreement");
dialog.setSize(JBUI.scale(509), JBUI.scale(395));
dialog.show();
}
use of javax.swing.text.html.HTMLDocument in project sling by apache.
the class WebloaderJob method getDocumentUrlsFromGoogle.
private URL[] getDocumentUrlsFromGoogle(String currentFiletype, int start) throws IOException, BadLocationException {
final List urls = new ArrayList();
String query = webQuery + " filetype:" + currentFiletype;
final URL google = new URL("http://www.google.com/search?q=" + URLEncoder.encode(query, "UTF-8") + "&start=" + start);
log.debug("Querying {}", google.toString());
statusInfo = "Querying " + google.toString();
statusDetails = "";
URLConnection con = google.openConnection();
con.setRequestProperty("User-Agent", "");
InputStream in = con.getInputStream();
try {
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc = new HTMLDocument();
doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
kit.read(new InputStreamReader(in, "UTF-8"), doc, 0);
HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
while (it.isValid()) {
if (it.getAttributes() != null) {
String href = (String) it.getAttributes().getAttribute(HTML.Attribute.HREF);
if (href != null && href.endsWith("." + currentFiletype)) {
URL url = new URL(new URL("http", "www.google.com", "dummy"), href);
if (url.getHost().indexOf("google") == -1) {
log.debug("Got document URL from google: {}", url);
statusDetails = "Got URL " + url;
urls.add(url);
}
}
}
it.next();
}
} finally {
in.close();
}
return (URL[]) urls.toArray(new URL[urls.size()]);
}
use of javax.swing.text.html.HTMLDocument in project languagetool by languagetool-org.
the class ResultAreaHelper method appendMain.
private void appendMain(String html) {
HTMLDocument d = (HTMLDocument) statusPane.getDocument();
Element e = d.getElement(MAIN);
try {
d.insertBeforeEnd(e, html);
} catch (BadLocationException ex) {
Tools.showError(ex);
} catch (IOException ex) {
Tools.showError(ex);
}
}
Aggregations