protected void setup() {
final Styles stylesheet = Page.getCurrent().getStyles();
// Inject some resources initially
final StreamResource initialResource = new StreamResource(
new StreamResource.StreamSource() {
@Override
public InputStream getStream() {
return new ByteArrayInputStream(
".hello, .world { color:silver; }".getBytes());
}
}, "mystyles-" + System.currentTimeMillis() + ".css");
stylesheet.add(initialResource);
Label hello = new Label(
"<span class='hello'>Hello</span> <span class='world'>world</span>",
ContentMode.HTML);
addComponent(hello);
final TextArea cssToInject = new TextArea();
cssToInject.setImmediate(true);
addComponent(cssToInject);
Button inject = new Button("Inject!", new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
stylesheet.add(cssToInject.getValue());
cssToInject.setValue("");
}
});
addComponent(inject);
Button injectRandom = new Button("Inject as resource!",
new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
final String css = cssToInject.getValue();
stylesheet.add(new StreamResource(
new StreamResource.StreamSource() {
@Override
public InputStream getStream() {
return new ByteArrayInputStream(css