| public static final String | documentBaseKey | Key stored as a client property to indicate the base that relative
references are resolved against. For example, lets say you keep
your images in the directory resources relative to the code path,
you would use the following the set the base:
jComponent.putClientProperty(documentBaseKey,
xxx.class.getResource("resources/"));
|
| Method from javax.swing.plaf.basic.BasicHTML Detail: |
public static View createHTMLView(JComponent c,
String html) {
BasicEditorKit kit = getFactory();
Document doc = kit.createDefaultDocument(c.getFont(),
c.getForeground());
Object base = c.getClientProperty(documentBaseKey);
if (base instanceof URL) {
((HTMLDocument)doc).setBase((URL)base);
}
Reader r = new StringReader(html);
try {
kit.read(r, doc, 0);
} catch (Throwable e) {
}
ViewFactory f = kit.getViewFactory();
View hview = f.create(doc.getDefaultRootElement());
View v = new Renderer(c, f, hview);
return v;
}
Create an html renderer for the given component and
string of html. |
static int getBaseline(View view,
int w,
int h) {
if (hasParagraph(view)) {
view.setSize(w, h);
return getBaseline(view, new Rectangle(0, 0, w, h));
}
return -1;
}
Gets the baseline for the specified View. |
static int getBaseline(JComponent c,
int y,
int ascent,
int w,
int h) {
View view = (View)c.getClientProperty(BasicHTML.propertyKey);
if (view != null) {
int baseline = getHTMLBaseline(view, w, h);
if (baseline < 0) {
return baseline;
}
return y + baseline;
}
return y + ascent;
}
Gets the baseline for the specified component. This digs out
the View client property, and if non-null the baseline is calculated
from it. Otherwise the baseline is the value y + ascent. |
static BasicHTML.BasicEditorKit getFactory() {
if (basicHTMLFactory == null) {
basicHTMLViewFactory = new BasicHTMLViewFactory();
basicHTMLFactory = new BasicEditorKit();
}
return basicHTMLFactory;
}
|
public static int getHTMLBaseline(View view,
int w,
int h) {
if (w < 0 || h < 0) {
throw new IllegalArgumentException(
"Width and height must be >= 0");
}
if (view instanceof Renderer) {
return getBaseline(view.getView(0), w, h);
}
return -1;
}
Returns the baseline for the html renderer. |
public static boolean isHTMLString(String s) {
if (s != null) {
if ((s.length() >= 6) && (s.charAt(0) == '< ") && (s.charAt(5) == ' >")) {
String tag = s.substring(1,5);
return tag.equalsIgnoreCase(propertyKey);
}
}
return false;
}
Check the given string to see if it should trigger the
html rendering logic in a non-text component that supports
html rendering. |
public static void updateRenderer(JComponent c,
String text) {
View value = null;
View oldValue = (View)c.getClientProperty(BasicHTML.propertyKey);
Boolean htmlDisabled = (Boolean) c.getClientProperty(htmlDisable);
if (htmlDisabled != Boolean.TRUE && BasicHTML.isHTMLString(text)) {
value = BasicHTML.createHTMLView(c, text);
}
if (value != oldValue && oldValue != null) {
for (int i = 0; i < oldValue.getViewCount(); i++) {
oldValue.getView(i).setParent(null);
}
}
c.putClientProperty(BasicHTML.propertyKey, value);
}
Stash the HTML render for the given text into the client
properties of the given JComponent. If the given text is
NOT HTML the property will be cleared of any
renderer.
This method is useful for ComponentUI implementations
that are static (i.e. shared) and get their state
entirely from the JComponent. |