Label desc = new Label(
"FancyImage can be used when you want to present multiple images in one place. This component allows you to select which image to show when or just enabled the automatic slide show mode.");
addComponent(desc);
final FancyImage image = new FancyImage();
image.setWidth("500px");
image.setHeight("281px");
// Setting images used
final List<Resource> resources = getImageResources();
for (Resource resource : resources) {
image.addResource(resource);
}
// Setting slideshow timeout to 3 seconds (3000 millisecs)
image.setSlideShowTimeout(3000);
HorizontalLayout buttonLayout = new HorizontalLayout();
buttonLayout.setSpacing(true);
addComponent(buttonLayout);
addComponent(image);
setComponentAlignment(image, Alignment.TOP_CENTER);
for (int i = 0; i < resources.size(); ++i) {
final Button button = new Button("Pic " + (i + 1));
buttonLayout.addComponent(button);
final Resource res = resources.get(i);
button.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
image.showResource(res);
}
});
disableWhenAutoPlay.add(button);
}
CheckBox auto = new CheckBox("Slide show");
auto.setImmediate(true);
buttonLayout.addComponent(auto);
CheckBox fade = new CheckBox("Fade");
fade.setDescription("Fade image when changing");
fade.setImmediate(true);
fade.setValue(image.isFadeTransition());
buttonLayout.addComponent(fade);
CheckBox rotate = new CheckBox("Rotate");
rotate.setDescription("Rotate image when changing");
rotate.setImmediate(true);
rotate.setValue(image.isRotateTransition());
buttonLayout.addComponent(rotate);
horizontal = new CheckBox("Horizontal");
horizontal
.setDescription("Should rotate happen horizontally or vertically.");
horizontal.setValue(true);
buttonLayout.addComponent(horizontal);
TextField timeout = new TextField();
timeout.setCaption("Slide show millisecs");
timeout.setValue(String.valueOf(image.getSlideShowTimeout()));
timeout.setDescription("How many millisec the slideshow shows one image");
buttonLayout.addComponent(timeout);
timeout.addTextChangeListener(new TextChangeListener() {
@Override
public void textChange(TextChangeEvent event) {
try {
int value = Integer.parseInt(event.getText());
// Change slide show value
image.setSlideShowTimeout(value);
} catch (NumberFormatException e) {
}
}
});
auto.addValueChangeListener(new Property.ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
Boolean value = (Boolean) event.getProperty().getValue();
// Enable/disable slideshow mode
image.setSlideShowEnabled(value);
for (Component component : disableWhenAutoPlay) {
component.setEnabled(!value);
}
}
});
fade.addValueChangeListener(new Property.ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
Boolean value = (Boolean) event.getProperty().getValue();
image.setFadeTransition(value.booleanValue());
}
});
rotate.addValueChangeListener(new Property.ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
Boolean value = (Boolean) event.getProperty().getValue();
image.setRotateTransition(value.booleanValue(),
horizontal.getValue());
}
});
horizontal.addValueChangeListener(new Property.ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
if (image.isRotateTransition()) {
image.setRotateTransition(true, (Boolean) event
.getProperty().getValue());
}
}
});
}