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.

Coverflow.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.demo.coverflow;
  5. import com.vaadin.terminal.PaintException;
  6. import com.vaadin.terminal.PaintTarget;
  7. import com.vaadin.ui.AbstractSelect;
  8. public class Coverflow extends AbstractSelect {
  9. private String backgroundGradientStart = "FFFFFF";
  10. private String backgroundGradientEnd = "EEEEEE";
  11. private boolean scrollbarVisibility = true;
  12. public String getTag() {
  13. return "cover";
  14. }
  15. /**
  16. * Paints the uidl
  17. * @param PaintTarget target
  18. * @throws PaintException
  19. */
  20. public void paintContent(PaintTarget target) throws PaintException {
  21. // Superclass writes any common attributes in the paint target.
  22. super.paintContent(target);
  23. target.addAttribute("backgroundGradientStart", backgroundGradientStart);
  24. target.addAttribute("backgroundGradientEnd", backgroundGradientEnd);
  25. target.addAttribute("scrollbarVisibility", scrollbarVisibility);
  26. }
  27. /**
  28. * The user can specify a background gradient for the coverflow. The input values
  29. * are RGB values for the start and end gradients.
  30. * @param int startR
  31. * @param int startG
  32. * @param int startB
  33. * @param int endR
  34. * @param int endG
  35. * @param int endB
  36. */
  37. public void setBackgroundColor(int startR, int startG, int startB, int endR, int endG, int endB) {
  38. backgroundGradientStart = "";
  39. backgroundGradientEnd = "";
  40. // Convert all integers to hexadecimal format and make sure they are two characters long (in
  41. // other words, add a zero infront if the value is less than 16 => 0x0F
  42. if(startR < 16)
  43. backgroundGradientStart += "0";
  44. backgroundGradientStart += Integer.toHexString(Math.max(Math.min(startR,255),0));
  45. if(startG < 16)
  46. backgroundGradientStart += "0";
  47. backgroundGradientStart += Integer.toHexString(Math.max(Math.min(startG,255),0));
  48. if(startB < 16)
  49. backgroundGradientStart += "0";
  50. backgroundGradientStart += Integer.toHexString(Math.max(Math.min(startB,255),0));
  51. if(endR < 16)
  52. backgroundGradientEnd += "0";
  53. backgroundGradientEnd += Integer.toHexString(Math.max(Math.min(endR,255),0));
  54. if(endG < 16)
  55. backgroundGradientEnd += "0";
  56. backgroundGradientEnd += Integer.toHexString(Math.max(Math.min(endG,255),0));
  57. if(endB < 16)
  58. backgroundGradientEnd += "0";
  59. backgroundGradientEnd += Integer.toHexString(Math.max(Math.min(endB,255),0));
  60. this.requestRepaint();
  61. }
  62. /**
  63. * The user can toggle the visibility of the scrollbar
  64. * @param boolean visible
  65. */
  66. public void setScrollbarVisibility(boolean visible) {
  67. if(scrollbarVisibility != visible) {
  68. scrollbarVisibility = visible;
  69. this.requestRepaint();
  70. }
  71. }
  72. }