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.

ToolkitTunesLayout.java 13KB

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