*/
@SuppressWarnings("unchecked")
@Override
public <T extends RenderElement> T createElement(Class<T> renderElement) {
RenderElement re = null;
if (renderElement.isAssignableFrom(TextualRenderElement.class)) {
re = new TextualRenderElementImpl(this);
}
if (renderElement.isAssignableFrom(GraphicalRenderElement.class)) {
re = new GraphicalRenderElementImpl(this);
}
if (re == null && renderElement.isAssignableFrom(RenderElement.class)) {
re = new RenderElementImpl(this);
}
// Sanity check
if (re == null)
throw new IllegalStateException("Ups, render element must not be null at this point");
this.elementsLock.lock();
try {
this.renderElements.add(re);
} finally {
this.elementsLock.unlock();
}
// Make element visible at first
re.setVisible(true);
return (T) re;
}