下面列出了javax.swing.plaf.basic.BasicHTML#createHTMLView ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected void updateHtmlViews(final int index, final boolean inserted) {
String title = ui.tabPane.getTitleAt(index);
boolean isHTML = BasicHTML.isHTMLString(title);
if (isHTML) {
if (ui.htmlViews == null) { // Initialize vector
ui.htmlViews = ui.createHTMLVector();
} else { // Vector already exists
View v = BasicHTML.createHTMLView(ui.tabPane, title);
setHtmlView(v, inserted, index);
}
} else { // Not HTML
if (ui.htmlViews != null) { // Add placeholder
setHtmlView(null, inserted, index);
} // else nada!
}
ui.updateMnemonics();
}
@Override
public void componentAdded(ContainerEvent e) {
JTabbedPane tp = (JTabbedPane) e.getContainer();
Component child = e.getChild();
if (child instanceof UIResource) {
return;
}
int index = tp.indexOfComponent(child);
String title = tp.getTitleAt(index);
boolean isHTML = BasicHTML.isHTMLString(title);
if (isHTML) {
if (htmlViews == null) { // Initialize vector
htmlViews = createHTMLVector();
}
else { // Vector already exists
View v = BasicHTML.createHTMLView(tp, title);
htmlViews.insertElementAt(v, index);
}
}
else { // Not HTML
if (htmlViews != null) { // Add placeholder
htmlViews.insertElementAt(null, index);
} // else nada!
}
}
private Header(boolean obeyWidth) {
setFont(deriveHeaderFont(getFont()));
setForeground(UIUtil.getToolTipForeground());
if (obeyWidth) {
View v = BasicHTML.createHTMLView(this, String.format("<html>%s%s</html>", title, getShortcutAsHTML()));
float width = v.getPreferredSpan(View.X_AXIS);
isMultiline = isMultiline || width > MAX_WIDTH.get();
setText(width > MAX_WIDTH.get()
? String.format("<html><div width=%d>%s%s</div></html>", MAX_WIDTH.get(), title, getShortcutAsHTML())
: String.format("<html>%s%s</html>", title, getShortcutAsHTML()));
setSizeForWidth(width);
}
else {
setText(String.format("<html>%s%s</html>", title, getShortcutAsHTML()));
}
}
private Paragraph(String text, boolean hasTitle) {
setForeground(hasTitle ? INFO_COLOR : UIUtil.getToolTipForeground());
setFont(deriveDescriptionFont(getFont(), hasTitle));
View v = BasicHTML.createHTMLView(this, String.format("<html>%s</html>", text));
float width = v.getPreferredSpan(View.X_AXIS);
isMultiline = isMultiline || width > MAX_WIDTH.get();
setText(width > MAX_WIDTH.get() ? String.format("<html><div width=%d>%s</div></html>", MAX_WIDTH.get(), text) : String.format("<html>%s</html>", text));
setSizeForWidth(width);
}
@Nonnull
public static ComponentPopupBuilder createPopupBuilder(@Nonnull ValidationInfo info, @Nullable Consumer<? super JEditorPane> configurator) {
JEditorPane tipComponent = new JEditorPane();
View v = BasicHTML.createHTMLView(tipComponent, String.format("<html>%s</html>", info.message));
String text = v.getPreferredSpan(View.X_AXIS) > MAX_WIDTH.get()
? String.format("<html><body><div width=%d>%s</div><body></html>", MAX_WIDTH.get(), trimMessage(info.message, tipComponent))
: String.format("<html><body><div>%s</div></body></html>", info.message);
tipComponent.setContentType("text/html");
tipComponent.setEditable(false);
tipComponent.setEditorKit(UIUtil.getHTMLEditorKit());
EditorKit kit = tipComponent.getEditorKit();
if (kit instanceof HTMLEditorKit) {
StyleSheet css = ((HTMLEditorKit)kit).getStyleSheet();
css.addRule("a, a:link {color:#" + ColorUtil.toHex(JBUI.CurrentTheme.Link.linkColor()) + ";}");
css.addRule("a:visited {color:#" + ColorUtil.toHex(JBUI.CurrentTheme.Link.linkVisitedColor()) + ";}");
css.addRule("a:hover {color:#" + ColorUtil.toHex(JBUI.CurrentTheme.Link.linkHoverColor()) + ";}");
css.addRule("a:active {color:#" + ColorUtil.toHex(JBUI.CurrentTheme.Link.linkPressedColor()) + ";}");
css.addRule("body {background-color:#" + ColorUtil.toHex(info.warning ? warningBackgroundColor() : errorBackgroundColor()) + ";}");
}
if (tipComponent.getCaret() instanceof DefaultCaret) {
((DefaultCaret)tipComponent.getCaret()).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
}
tipComponent.setCaretPosition(0);
tipComponent.setText(text);
tipComponent.setBackground(info.warning ? warningBackgroundColor() : errorBackgroundColor());
tipComponent.setOpaque(true);
tipComponent.setBorder(getBorder());
if (configurator != null) {
configurator.accept(tipComponent);
}
return JBPopupFactory.getInstance().createComponentPopupBuilder(tipComponent, null).
setBorderColor(info.warning ? warningBorderColor() : errorBorderColor()).
setCancelOnClickOutside(false).
setShowShadow(true);
}