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.

ThemeResource.java 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal;
  5. import com.vaadin.service.FileTypeResolver;
  6. /**
  7. * <code>ThemeResource</code> is a named theme dependant resource provided and
  8. * managed by a theme. The actual resource contents are dynamically resolved to
  9. * comply with the used theme by the terminal adapter. This is commonly used to
  10. * provide static images, flash, java-applets, etc for the terminals.
  11. *
  12. * @author IT Mill Ltd.
  13. * @version
  14. * @VERSION@
  15. * @since 3.0
  16. */
  17. @SuppressWarnings("serial")
  18. public class ThemeResource implements Resource {
  19. /**
  20. * Id of the terminal managed resource.
  21. */
  22. private String resourceID = null;
  23. /**
  24. * Creates a resource.
  25. *
  26. * @param resourceId
  27. * the Id of the resource.
  28. */
  29. public ThemeResource(String resourceId) {
  30. if (resourceId == null) {
  31. throw new NullPointerException("Resource ID must not be null");
  32. }
  33. if (resourceId.length() == 0) {
  34. throw new IllegalArgumentException("Resource ID can not be empty");
  35. }
  36. if (resourceId.charAt(0) == '/') {
  37. throw new IllegalArgumentException(
  38. "Resource ID must be relative (can not begin with /)");
  39. }
  40. resourceID = resourceId;
  41. }
  42. /**
  43. * Tests if the given object equals this Resource.
  44. *
  45. * @param obj
  46. * the object to be tested for equality.
  47. * @return <code>true</code> if the given object equals this Icon,
  48. * <code>false</code> if not.
  49. * @see java.lang.Object#equals(Object)
  50. */
  51. @Override
  52. public boolean equals(Object obj) {
  53. return obj instanceof ThemeResource
  54. && resourceID.equals(((ThemeResource) obj).resourceID);
  55. }
  56. /**
  57. * @see java.lang.Object#hashCode()
  58. */
  59. @Override
  60. public int hashCode() {
  61. return resourceID.hashCode();
  62. }
  63. /**
  64. * @see java.lang.Object#toString()
  65. */
  66. @Override
  67. public String toString() {
  68. return resourceID.toString();
  69. }
  70. /**
  71. * Gets the resource id.
  72. *
  73. * @return the resource id.
  74. */
  75. public String getResourceId() {
  76. return resourceID;
  77. }
  78. /**
  79. * @see com.vaadin.terminal.Resource#getMIMEType()
  80. */
  81. public String getMIMEType() {
  82. return FileTypeResolver.getMIMEType(getResourceId());
  83. }
  84. }