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.

AFPResourceInfo.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.afp;
  19. import java.awt.Dimension;
  20. /**
  21. * The level at which a resource is to reside in the AFP output
  22. */
  23. public class AFPResourceInfo {
  24. /** the general default resource level */
  25. public static final AFPResourceLevel DEFAULT_LEVEL
  26. = new AFPResourceLevel(AFPResourceLevel.PRINT_FILE);
  27. /** the URI of this resource */
  28. private String uri = null;
  29. /**
  30. * the image dimension in page coordinates (non-null only when page segments are
  31. * generated because the cannot be scaled for painting).
  32. */
  33. private Dimension imageDimension = null;
  34. /** the reference name of this resource */
  35. private String name = null;
  36. /** the resource level of this resource */
  37. private AFPResourceLevel level = DEFAULT_LEVEL;
  38. /** true when the resource level was changed */
  39. private boolean levelChanged = false;
  40. /**
  41. * Sets the data object URI.
  42. *
  43. * @param uri the data object URI
  44. */
  45. public void setUri(String uri) {
  46. this.uri = uri;
  47. }
  48. /**
  49. * Returns the URI of this data object.
  50. *
  51. * @return the URI of this data object
  52. */
  53. public String getUri() {
  54. return uri;
  55. }
  56. /**
  57. * Sets an optional image dimension (in page coordinates). This is only used if
  58. * a page segment is created for this resource as page segments cannot be rescaled
  59. * for painting.
  60. * @param dim the image dimension (in page coordinates)
  61. */
  62. public void setImageDimension(Dimension dim) {
  63. this.imageDimension = dim;
  64. }
  65. /**
  66. * Returns an optional image dimension (in page coordinates). This is only used if
  67. * a page segment is created for this resource as page segments cannot be rescaled
  68. * for painting.
  69. * @return the image dimension (or null if not applicable)
  70. */
  71. public Dimension getImageDimension() {
  72. return this.imageDimension;
  73. }
  74. /**
  75. * Sets the resource reference name
  76. *
  77. * @param resourceName the resource reference name
  78. */
  79. public void setName(String resourceName) {
  80. this.name = resourceName;
  81. }
  82. /**
  83. * Returns the resource reference name
  84. *
  85. * @return the resource reference name
  86. */
  87. public String getName() {
  88. return this.name;
  89. }
  90. /**
  91. * Returns the resource level
  92. *
  93. * @return the resource level
  94. */
  95. public AFPResourceLevel getLevel() {
  96. if (level == null) {
  97. return DEFAULT_LEVEL;
  98. }
  99. return this.level;
  100. }
  101. /**
  102. * Sets the resource level
  103. *
  104. * @param resourceLevel the resource level
  105. */
  106. public void setLevel(AFPResourceLevel resourceLevel) {
  107. this.level = resourceLevel;
  108. levelChanged = true;
  109. }
  110. /**
  111. * Returns true when the resource level was set
  112. *
  113. * @return true when the resource level was set
  114. */
  115. public boolean levelChanged() {
  116. return levelChanged;
  117. }
  118. /** {@inheritDoc} */
  119. public String toString() {
  120. return "AFPResourceInfo{uri=" + uri
  121. + (imageDimension != null
  122. ? ", " + imageDimension.width + "x" + imageDimension.height : "")
  123. + (name != null ? ", name=" + name : "")
  124. + (level != null ? ", level=" + level : "")
  125. + "}";
  126. }
  127. /** {@inheritDoc} */
  128. public boolean equals(Object obj) {
  129. if (this == obj) {
  130. return true;
  131. }
  132. if ((obj == null) || !(obj instanceof AFPResourceInfo)) {
  133. return false;
  134. }
  135. AFPResourceInfo ri = (AFPResourceInfo)obj;
  136. return (uri == ri.uri || uri != null && uri.equals(ri.uri))
  137. && (imageDimension == ri.imageDimension
  138. || (imageDimension != null && imageDimension.equals(ri.imageDimension)))
  139. && (name == ri.name || name != null && name.equals(ri.name))
  140. && (level == ri.level || level != null && level.equals(ri.level));
  141. }
  142. /** {@inheritDoc} */
  143. public int hashCode() {
  144. int hash = 7;
  145. hash = 31 * hash + (null == uri ? 0 : uri.hashCode());
  146. hash = 31 * hash + (null == imageDimension ? 0 : imageDimension.hashCode());
  147. hash = 31 * hash + (null == name ? 0 : name.hashCode());
  148. hash = 31 * hash + (null == level ? 0 : level.hashCode());
  149. return hash;
  150. }
  151. }