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.

VaadinTunesLayout.java 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. package com.vaadin.tests.components.orderedlayout;
  2. import com.vaadin.annotations.Theme;
  3. import com.vaadin.server.Sizeable;
  4. import com.vaadin.server.ThemeResource;
  5. import com.vaadin.server.VaadinRequest;
  6. import com.vaadin.shared.ui.MarginInfo;
  7. import com.vaadin.shared.ui.slider.SliderOrientation;
  8. import com.vaadin.tests.components.AbstractReindeerTestUI;
  9. import com.vaadin.ui.Alignment;
  10. import com.vaadin.ui.Button;
  11. import com.vaadin.ui.ComboBox;
  12. import com.vaadin.ui.Embedded;
  13. import com.vaadin.ui.HorizontalLayout;
  14. import com.vaadin.ui.HorizontalSplitPanel;
  15. import com.vaadin.ui.Label;
  16. import com.vaadin.ui.NativeButton;
  17. import com.vaadin.ui.Slider;
  18. import com.vaadin.ui.VerticalLayout;
  19. import com.vaadin.v7.ui.NativeSelect;
  20. import com.vaadin.v7.ui.Table;
  21. @Theme("tests-components")
  22. public class VaadinTunesLayout extends AbstractReindeerTestUI {
  23. @Override
  24. public void setup(VaadinRequest request) {
  25. /*
  26. * We'll build the whole UI here, since the application will not contain
  27. * any logic. Otherwise it would be more practical to separate parts of
  28. * the UI into different classes and methods.
  29. */
  30. // Main (browser) window, needed in all Vaadin applications
  31. VerticalLayout rootLayout = new VerticalLayout();
  32. // final Window root = new Window("VaadinTunes", rootLayout);
  33. /*
  34. * We'll attach the window to the browser view already here, so we won't
  35. * forget it later.
  36. */
  37. setContent(rootLayout);
  38. // root.showNotification(
  39. // "This is an example of how you can do layouts in Vaadin.<br/>It is
  40. // not a working sound player.",
  41. // Notification.TYPE_HUMANIZED_MESSAGE);
  42. // Our root window contains one VerticalLayout, let's make
  43. // sure it's 100% sized, and remove unwanted margins
  44. rootLayout.setSizeFull();
  45. rootLayout.setMargin(false);
  46. // Top area, containing playback and volume controls, play status, view
  47. // modes and search
  48. HorizontalLayout top = new HorizontalLayout();
  49. top.setWidth("100%");
  50. top.setMargin(new MarginInfo(false, true)); // Enable
  51. // horizontal
  52. // margins
  53. top.setSpacing(true);
  54. // Let's attach that one straight away too
  55. rootLayout.addComponent(top);
  56. // Create the placeholders for all the components in the top area
  57. HorizontalLayout playback = new HorizontalLayout();
  58. HorizontalLayout volume = new HorizontalLayout();
  59. HorizontalLayout status = new HorizontalLayout();
  60. HorizontalLayout viewmodes = new HorizontalLayout();
  61. ComboBox<String> search = new ComboBox<>();
  62. // Add the components and align them properly
  63. top.addComponent(playback);
  64. top.addComponent(volume);
  65. top.addComponent(status);
  66. top.addComponent(viewmodes);
  67. top.addComponent(search);
  68. top.setComponentAlignment(playback, Alignment.MIDDLE_LEFT);
  69. top.setComponentAlignment(volume, Alignment.MIDDLE_LEFT);
  70. top.setComponentAlignment(status, Alignment.MIDDLE_CENTER);
  71. top.setComponentAlignment(viewmodes, Alignment.MIDDLE_LEFT);
  72. top.setComponentAlignment(search, Alignment.MIDDLE_LEFT);
  73. /*
  74. * We want our status area to expand if the user resizes the root
  75. * window, and we want it to accommodate as much space as there is
  76. * available. All other components in the top layout should stay fixed
  77. * sized, so we don't need to specify any expand ratios for them (they
  78. * will automatically revert to zero after the following line).
  79. */
  80. top.setExpandRatio(status, 1.0F);
  81. // Playback controls
  82. Button prev = new NativeButton("Previous");
  83. Button play = new NativeButton("Play/pause");
  84. Button next = new NativeButton("Next");
  85. playback.addComponent(prev);
  86. playback.addComponent(play);
  87. playback.addComponent(next);
  88. // Set spacing between the buttons
  89. playback.setSpacing(true);
  90. // Volume controls
  91. Button mute = new NativeButton("mute");
  92. Slider vol = new Slider();
  93. vol.setOrientation(SliderOrientation.HORIZONTAL);
  94. vol.setWidth("100px");
  95. Button max = new NativeButton("max");
  96. volume.addComponent(mute);
  97. volume.addComponent(vol);
  98. volume.addComponent(max);
  99. // Status area
  100. status.setWidth("80%");
  101. status.setSpacing(true);
  102. Button toggleVisualization = new NativeButton("Mode");
  103. Label timeFromStart = new Label("0:00");
  104. // We'll need another layout to show currently playing track and
  105. // progress
  106. VerticalLayout trackDetails = new VerticalLayout();
  107. trackDetails.setWidth("100%");
  108. Label track = new Label("Track Name");
  109. Label album = new Label("Album Name - Artist");
  110. track.setWidth(null);
  111. album.setWidth(null);
  112. Slider progress = new Slider();
  113. progress.setOrientation(SliderOrientation.HORIZONTAL);
  114. progress.setWidth("100%");
  115. trackDetails.addComponent(track);
  116. trackDetails.addComponent(album);
  117. trackDetails.addComponent(progress);
  118. trackDetails.setComponentAlignment(track, Alignment.TOP_CENTER);
  119. trackDetails.setComponentAlignment(album, Alignment.TOP_CENTER);
  120. Label timeToEnd = new Label("-4:46");
  121. Button jumpToTrack = new NativeButton("Show");
  122. // Place all components to the status layout and align them properly
  123. status.addComponent(toggleVisualization);
  124. status.setComponentAlignment(toggleVisualization,
  125. Alignment.MIDDLE_LEFT);
  126. status.addComponent(timeFromStart);
  127. status.setComponentAlignment(timeFromStart, Alignment.BOTTOM_LEFT);
  128. status.addComponent(trackDetails);
  129. status.addComponent(timeToEnd);
  130. status.setComponentAlignment(timeToEnd, Alignment.BOTTOM_LEFT);
  131. status.addComponent(jumpToTrack);
  132. status.setComponentAlignment(jumpToTrack, Alignment.MIDDLE_LEFT);
  133. // Then remember to specify the expand ratio
  134. status.setExpandRatio(trackDetails, 1.0F);
  135. // View mode buttons
  136. Button viewAsTable = new NativeButton("Table");
  137. Button viewAsGrid = new NativeButton("Grid");
  138. Button coverflow = new NativeButton("Coverflow");
  139. viewmodes.addComponent(viewAsTable);
  140. viewmodes.addComponent(viewAsGrid);
  141. viewmodes.addComponent(coverflow);
  142. /*
  143. * That covers the top bar. Now let's move on to the sidebar and track
  144. * listing
  145. */
  146. // We'll need one splitpanel to separate the sidebar and track listing
  147. HorizontalSplitPanel bottom = new HorizontalSplitPanel();
  148. rootLayout.addComponent(bottom);
  149. // The splitpanel is by default 100% x 100%, but we'll need to adjust
  150. // our main window layout to accommodate the height
  151. rootLayout.setExpandRatio(bottom, 1.0F);
  152. // Give the sidebar less space than the listing
  153. bottom.setSplitPosition(200, Sizeable.UNITS_PIXELS);
  154. // Let's add some content to the sidebar
  155. // First, we need a layout to but all components in
  156. VerticalLayout sidebar = new VerticalLayout();
  157. sidebar.setSizeFull();
  158. bottom.setFirstComponent(sidebar);
  159. /*
  160. * Then we need some labels and buttons, and an album cover image The
  161. * labels and buttons go into their own vertical layout, since we want
  162. * the 'sidebar' layout to be expanding (cover image in the bottom).
  163. * VerticalLayout is by default 100% wide.
  164. */
  165. VerticalLayout selections = new VerticalLayout();
  166. Label library = new Label("Library");
  167. Button music = new NativeButton("Music");
  168. music.setWidth("100%");
  169. Label store = new Label("Store");
  170. Button vaadinTunesStore = new NativeButton("VaadinTunes Store");
  171. vaadinTunesStore.setWidth("100%");
  172. Button purchased = new NativeButton("Purchased");
  173. purchased.setWidth("100%");
  174. Label playlists = new Label("Playlists");
  175. Button genius = new NativeButton("Geniues");
  176. genius.setWidth("100%");
  177. Button recent = new NativeButton("Recently Added");
  178. recent.setWidth("100%");
  179. // Lets add them to the 'selections' layout
  180. selections.addComponent(library);
  181. selections.addComponent(music);
  182. selections.addComponent(store);
  183. selections.addComponent(vaadinTunesStore);
  184. selections.addComponent(purchased);
  185. selections.addComponent(playlists);
  186. selections.addComponent(genius);
  187. selections.addComponent(recent);
  188. // Then add the selections to the sidebar, and set it expanding
  189. sidebar.addComponent(selections);
  190. sidebar.setExpandRatio(selections, 1.0F);
  191. // Then comes the cover artwork (we'll add the actual image in the
  192. // themeing section)
  193. Embedded cover = new Embedded("Currently Playing");
  194. sidebar.addComponent(cover);
  195. /*
  196. * And lastly, we need the track listing table It should fill the whole
  197. * left side of our bottom layout
  198. */
  199. Table listing = new Table();
  200. listing.setSizeFull();
  201. listing.setSelectable(true);
  202. bottom.setSecondComponent(listing);
  203. // Add the table headers
  204. listing.addContainerProperty("Name", String.class, "");
  205. listing.addContainerProperty("Time", String.class, "0:00");
  206. listing.addContainerProperty("Artist", String.class, "");
  207. listing.addContainerProperty("Album", String.class, "");
  208. listing.addContainerProperty("Genre", String.class, "");
  209. listing.addContainerProperty("Rating", NativeSelect.class,
  210. new NativeSelect());
  211. // Lets populate the table with random data
  212. String[] tracks = { "Red Flag", "Millstone", "Not The Sun", "Breath",
  213. "Here We Are", "Deep Heaven", "Her Voice Resides",
  214. "Natural Tan", "End It All", "Kings", "Daylight Slaving",
  215. "Mad Man", "Resolve", "Teargas", "African Air",
  216. "Passing Bird" };
  217. String[] times = { "4:12", "6:03", "5:43", "4:32", "3:42", "4:45",
  218. "2:56", "9:34", "2:10", "3:44", "5:49", "6:30", "5:18", "7:42",
  219. "3:13", "2:52" };
  220. String[] artists = { "Billy Talent", "Brand New", "Breaking Benjamin",
  221. "Becoming The Archetype", "Bullet For My Valentine",
  222. "Chasing Victory", "Chimaira", "Danko Jones", "Deadlock",
  223. "Deftones", "From Autumn To Ashes", "Haste The Day",
  224. "Four Year Strong", "In Flames", "Kemopetrol", "John Legend" };
  225. String[] albums = { "Once Again", "The Caitiff Choir",
  226. "The Devil And God", "Light Grenades", "Dicthonomy",
  227. "Back In Black", "Dreamer", "Come Clarity", "Year Zero",
  228. "Frames", "Fortress", "Phobia", "The Poison", "Manifesto",
  229. "White Pony", "The Big Dirty" };
  230. String[] genres = { "Rock", "Metal", "Hardcore", "Indie", "Pop",
  231. "Alternative", "Blues", "Jazz", "Hip Hop", "Electronica",
  232. "Punk", "Hard Rock", "Dance", "R'n'B", "Gospel", "Country" };
  233. for (int i = 0; i < 1000; i++) {
  234. NativeSelect s = new NativeSelect();
  235. s.addItem("1 star");
  236. s.addItem("2 stars");
  237. s.addItem("3 stars");
  238. s.addItem("4 stars");
  239. s.addItem("5 stars");
  240. s.select(i % 5 + " stars");
  241. final int index = i % 16;
  242. listing.addItem(new Object[] { tracks[index], times[index],
  243. artists[index], albums[index], genres[index], s }, i);
  244. }
  245. // We'll align the track time column to right as well
  246. listing.setColumnAlignment("Time", Table.ALIGN_RIGHT);
  247. // TODO the footer
  248. // Now what's left to do? Themeing of course.
  249. // setTheme("vaadintunes");
  250. /*
  251. * Let's give a namespace to our application window. This way, if
  252. * someone uses the same theme for different applications, we don't get
  253. * unwanted style conflicts.
  254. */
  255. // root.setStyleName("tTunes");
  256. top.setStyleName("top");
  257. top.setHeight("75px"); // Same as the background image height
  258. playback.setStyleName("playback");
  259. // Add right-side margin
  260. playback.setMargin(new MarginInfo(false, true, false, false));
  261. play.setStyleName("play");
  262. next.setStyleName("next");
  263. prev.setStyleName("prev");
  264. playback.setComponentAlignment(prev, Alignment.MIDDLE_LEFT);
  265. playback.setComponentAlignment(next, Alignment.MIDDLE_LEFT);
  266. volume.setStyleName("volume");
  267. mute.setStyleName("mute");
  268. max.setStyleName("max");
  269. vol.setWidth("78px");
  270. status.setStyleName("status");
  271. status.setMargin(true);
  272. status.setHeight("46px"); // Height of the background image
  273. toggleVisualization.setStyleName("toggle-vis");
  274. jumpToTrack.setStyleName("jump");
  275. viewAsTable.setStyleName("viewmode-table");
  276. viewAsGrid.setStyleName("viewmode-grid");
  277. coverflow.setStyleName("viewmode-coverflow");
  278. sidebar.setStyleName("sidebar");
  279. music.setStyleName("selected");
  280. cover.setSource(new ThemeResource("images/album-cover.jpg"));
  281. // Because this is an image, it will retain it's aspect ratio
  282. cover.setWidth("100%");
  283. }
  284. @Override
  285. protected String getTestDescription() {
  286. // TODO Auto-generated method stub
  287. return null;
  288. }
  289. @Override
  290. protected Integer getTicketNumber() {
  291. // TODO Auto-generated method stub
  292. return null;
  293. }
  294. }