javax.swing.text.html
public class: ObjectView [javadoc |
source]
java.lang.Object
javax.swing.text.View
javax.swing.text.ComponentView
javax.swing.text.html.ObjectView
All Implemented Interfaces:
SwingConstants
Component decorator that implements the view interface
for <object> elements.
This view will try to load the class specified by the
classid
attribute. If possible, the Classloader
used to load the associated Document is used.
This would typically be the same as the ClassLoader
used to load the EditorKit. If the document's
ClassLoader is null, Class.forName
is used.
If the class can successfully be loaded, an attempt will
be made to create an instance of it by calling
Class.newInstance
. An attempt will be made
to narrow the instance to type java.awt.Component
to display the object.
This view can also manage a set of parameters with limitations.
The parameters to the <object> element are expected to
be present on the associated elements attribute set as simple
strings. Each bean property will be queried as a key on
the AttributeSet, with the expectation that a non-null value
(of type String) will be present if there was a parameter
specification for the property. Reflection is used to
set the parameter. Currently, this is limited to a very
simple single parameter of type String.
A simple example HTML invocation is:
<object classid="javax.swing.JLabel">
<param name="text" value="sample text">
</object>
- author:
Timothy
- Prinzing
Constructor: |
public ObjectView(Element elem) {
super(elem);
}
Creates a new ObjectView object. Parameters:
elem - the element to decorate
|
Methods from javax.swing.text.ComponentView: |
---|
createComponent, getAlignment, getComponent, getMaximumSpan, getMinimumSpan, getPreferredSpan, modelToView, paint, setComponentParent, setParent, viewToModel |
Methods from javax.swing.text.View: |
---|
append, breakView, changedUpdate, createFragment, forwardUpdate, forwardUpdateToView, getAlignment, getAttributes, getBreakWeight, getChildAllocation, getContainer, getDocument, getElement, getEndOffset, getGraphics, getMaximumSpan, getMinimumSpan, getNextVisualPositionFrom, getParent, getPreferredSpan, getResizeWeight, getStartOffset, getToolTipText, getView, getViewCount, getViewFactory, getViewIndex, getViewIndex, insert, insertUpdate, isVisible, modelToView, modelToView, modelToView, paint, preferenceChanged, remove, removeAll, removeUpdate, replace, setParent, setSize, updateChildren, updateLayout, viewToModel, viewToModel |
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from javax.swing.text.html.ObjectView Detail: |
protected Component createComponent() {
AttributeSet attr = getElement().getAttributes();
String classname = (String) attr.getAttribute(HTML.Attribute.CLASSID);
try {
Class c = Class.forName(classname, true,Thread.currentThread().
getContextClassLoader());
Object o = c.newInstance();
if (o instanceof Component) {
Component comp = (Component) o;
setParameters(comp, attr);
return comp;
}
} catch (Throwable e) {
// couldn't create a component... fall through to the
// couldn't load representation.
}
return getUnloadableRepresentation();
}
Create the component. The classid is used
as a specification of the classname, which
we try to load. |
Component getUnloadableRepresentation() {
// PENDING(prinz) get some artwork and return something
// interesting here.
Component comp = new JLabel("??");
comp.setForeground(Color.red);
return comp;
}
Fetch a component that can be used to represent the
object if it can't be created. |