You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CoverflowApplication.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.demo.coverflow;
  5. import java.io.BufferedReader;
  6. import java.io.IOException;
  7. import java.io.InputStream;
  8. import java.io.InputStreamReader;
  9. import com.vaadin.data.Property;
  10. import com.vaadin.terminal.Resource;
  11. import com.vaadin.terminal.ThemeResource;
  12. import com.vaadin.ui.Alignment;
  13. import com.vaadin.ui.Button;
  14. import com.vaadin.ui.Embedded;
  15. import com.vaadin.ui.Label;
  16. import com.vaadin.ui.Panel;
  17. import com.vaadin.ui.VerticalLayout;
  18. import com.vaadin.ui.Window;
  19. import com.vaadin.ui.Button.ClickEvent;
  20. public class CoverflowApplication extends com.vaadin.Application {
  21. Coverflow covers = new Coverflow();
  22. public void init() {
  23. setMainWindow(new Window("Coverflow", createMainLayout()));
  24. setTheme("coverflow");
  25. addSlidesToCoverflow();
  26. }
  27. private VerticalLayout createMainLayout() {
  28. // Initialize coverflow component
  29. covers.setHeight("150px");
  30. covers.setWidth("100%");
  31. covers.setBackgroundColor(0, 0, 0, 100, 100, 100);
  32. // Initialize visible slide viewer
  33. Panel slidePanel = new Panel();
  34. slidePanel.setStyleName(Panel.STYLE_LIGHT);
  35. slidePanel.setSizeFull();
  36. final Embedded visibleSlide = new Embedded();
  37. visibleSlide.setHeight("480px");
  38. slidePanel.addComponent(visibleSlide);
  39. ((VerticalLayout) slidePanel.getLayout()).setComponentAlignment(
  40. visibleSlide, "center");
  41. // Listen to coverflow changes as change slides when needed
  42. covers.addListener(new Property.ValueChangeListener() {
  43. public void valueChange(Property.ValueChangeEvent event) {
  44. visibleSlide.setSource((Resource) covers.getValue());
  45. }
  46. });
  47. // Show sources button
  48. Button showSrc = new Button("Show source", new Button.ClickListener() {
  49. public void buttonClick(ClickEvent event) {
  50. Window srcWindow = new Window("Source code");
  51. srcWindow.setWidth("700px");
  52. srcWindow.setHeight("500px");
  53. Label l = new Label(getSourceCodeForThisClass(),
  54. Label.CONTENT_XHTML);
  55. srcWindow.addComponent(l);
  56. getMainWindow().addWindow(srcWindow);
  57. }
  58. });
  59. showSrc.setStyleName(Button.STYLE_LINK);
  60. // Initialize main layout
  61. VerticalLayout layout = new VerticalLayout();
  62. layout.addComponent(showSrc);
  63. layout.setComponentAlignment(showSrc, Alignment.TOP_RIGHT);
  64. layout.addComponent(slidePanel);
  65. layout.addComponent(covers);
  66. layout.setExpandRatio(slidePanel, 1);
  67. layout.setSizeFull();
  68. return layout;
  69. }
  70. private String getSourceCodeForThisClass() {
  71. String code = "Could not find source-file";
  72. try {
  73. InputStream is = this.getClass().getResource(
  74. "CoverflowApplication.html").openStream();
  75. BufferedReader r = new BufferedReader(new InputStreamReader(is));
  76. StringBuffer buf = new StringBuffer();
  77. String line;
  78. while ((line = r.readLine()) != null) {
  79. buf.append(line);
  80. }
  81. code = buf.toString();
  82. } catch (IOException ignored) {
  83. }
  84. return code;
  85. }
  86. private void addSlidesToCoverflow() {
  87. for (int i = 0; i < 20; i++) {
  88. String head = "images/";
  89. String tail = "slideshow-example.0" + ((i < 10) ? "0" : "") + i
  90. + ".jpg";
  91. ThemeResource slide = new ThemeResource(head + tail);
  92. covers.addItem(slide);
  93. covers.setItemIcon(slide,
  94. new ThemeResource(head + "thumbs/" + tail));
  95. }
  96. }
  97. }