use of javax.swing.text.html.StyleSheet 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.StyleSheet in project processing by processing.
the class DetailPanel method setSelectionStyle.
static void setSelectionStyle(JTextPane textPane, boolean selected) {
Document doc = textPane.getDocument();
if (doc instanceof HTMLDocument) {
HTMLDocument html = (HTMLDocument) doc;
StyleSheet styleSheet = html.getStyleSheet();
if (selected) {
styleSheet.addRule("a { text-decoration:underline } ");
} else {
styleSheet.addRule("a { text-decoration:none }");
}
}
}
use of javax.swing.text.html.StyleSheet in project intellij-community by JetBrains.
the class UnusedDeclarationPresentation method getCustomPreviewPanel.
@Override
public JComponent getCustomPreviewPanel(RefEntity entity) {
final Project project = entity.getRefManager().getProject();
JEditorPane htmlView = new JEditorPane() {
@Override
public String getToolTipText(MouseEvent evt) {
int pos = viewToModel(evt.getPoint());
if (pos >= 0) {
HTMLDocument hdoc = (HTMLDocument) getDocument();
javax.swing.text.Element e = hdoc.getCharacterElement(pos);
AttributeSet a = e.getAttributes();
SimpleAttributeSet value = (SimpleAttributeSet) a.getAttribute(HTML.Tag.A);
if (value != null) {
String objectPackage = (String) value.getAttribute("qualifiedname");
if (objectPackage != null) {
return objectPackage;
}
}
}
return null;
}
};
htmlView.setContentType(UIUtil.HTML_MIME);
htmlView.setEditable(false);
htmlView.setOpaque(false);
htmlView.setBackground(UIUtil.getLabelBackground());
htmlView.addHyperlinkListener(new HyperlinkAdapter() {
@Override
protected void hyperlinkActivated(HyperlinkEvent e) {
URL url = e.getURL();
if (url == null) {
return;
}
@NonNls String ref = url.getRef();
int offset = Integer.parseInt(ref);
String fileURL = url.toExternalForm();
fileURL = fileURL.substring(0, fileURL.indexOf('#'));
VirtualFile vFile = VirtualFileManager.getInstance().findFileByUrl(fileURL);
if (vFile == null) {
vFile = VfsUtil.findFileByURL(url);
}
if (vFile != null) {
final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, vFile, offset);
FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
}
}
});
final StyleSheet css = ((HTMLEditorKit) htmlView.getEditorKit()).getStyleSheet();
css.addRule("p.problem-description-group {text-indent: " + JBUI.scale(9) + "px;font-weight:bold;}");
css.addRule("div.problem-description {margin-left: " + JBUI.scale(9) + "px;}");
css.addRule("ul {margin-left:" + JBUI.scale(10) + "px;text-indent: 0}");
css.addRule("code {font-family:" + UIUtil.getLabelFont().getFamily() + "}");
final StringBuffer buf = new StringBuffer();
getComposer().compose(buf, entity, false);
final String text = buf.toString();
SingleInspectionProfilePanel.readHTML(htmlView, SingleInspectionProfilePanel.toHTML(htmlView, text, false));
return ScrollPaneFactory.createScrollPane(htmlView, true);
}
use of javax.swing.text.html.StyleSheet in project intellij-community by JetBrains.
the class UIUtil method getHTMLEditorKit.
public static HTMLEditorKit getHTMLEditorKit(boolean noGapsBetweenParagraphs) {
Font font = getLabelFont();
@NonNls String family = !SystemInfo.isWindows && font != null ? font.getFamily() : "Tahoma";
final int size = font != null ? font.getSize() : JBUI.scale(11);
String customCss = String.format("body, div, p { font-family: %s; font-size: %s; }", family, size);
if (noGapsBetweenParagraphs) {
customCss += " p { margin-top: 0; }";
}
final StyleSheet style = new StyleSheet();
style.addStyleSheet(isUnderDarcula() ? (StyleSheet) UIManager.getDefaults().get("StyledEditorKit.JBDefaultStyle") : DEFAULT_HTML_KIT_CSS);
style.addRule(customCss);
return new HTMLEditorKit() {
@Override
public StyleSheet getStyleSheet() {
return style;
}
};
}
Aggregations