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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. import org.apache.fop.afp.AFPResourceLevel.ResourceType;
  21. /**
  22. * The level at which a resource is to reside in the AFP output
  23. */
  24. public class AFPResourceInfo {
  25. /** the general default resource level */
  26. public static final AFPResourceLevel DEFAULT_LEVEL
  27. = new AFPResourceLevel(ResourceType.PRINT_FILE);
  28. /** the URI of this resource */
  29. private String uri;
  30. /**
  31. * the image dimension in page coordinates (non-null only when page segments are
  32. * generated because the cannot be scaled for painting).
  33. */
  34. private Dimension imageDimension;
  35. /** the reference name of this resource */
  36. private String name;
  37. /** the resource level of this resource */
  38. private AFPResourceLevel level = DEFAULT_LEVEL;
  39. /** true when the resource level was changed */
  40. private boolean levelChanged;
  41. /**
  42. * Sets the data object URI.
  43. *
  44. * @param uri the data object URI
  45. */
  46. public void setUri(String uri) {
  47. this.uri = uri;
  48. }
  49. /**
  50. * Returns the URI of this data object.
  51. *
  52. * @return the URI of this data object
  53. */
  54. public String getUri() {
  55. return uri;
  56. }
  57. /**
  58. * Sets an optional image dimension (in page coordinates). This is only used if
  59. * a page segment is created for this resource as page segments cannot be rescaled
  60. * for painting.
  61. * @param dim the image dimension (in page coordinates)
  62. */
  63. public void setImageDimension(Dimension dim) {
  64. this.imageDimension = dim;
  65. }
  66. /**
  67. * Returns an optional image dimension (in page coordinates). This is only used if
  68. * a page segment is created for this resource as page segments cannot be rescaled
  69. * for painting.
  70. * @return the image dimension (or null if not applicable)
  71. */
  72. public Dimension getImageDimension() {
  73. return this.imageDimension;
  74. }
  75. /**
  76. * Sets the resource reference name
  77. *
  78. * @param resourceName the resource reference name
  79. */
  80. public void setName(String resourceName) {
  81. this.name = resourceName;
  82. }
  83. /**
  84. * Returns the resource reference name
  85. *
  86. * @return the resource reference name
  87. */
  88. public String getName() {
  89. return this.name;
  90. }
  91. /**
  92. * Returns the resource level
  93. *
  94. * @return the resource level
  95. */
  96. public AFPResourceLevel getLevel() {
  97. if (level == null) {
  98. return DEFAULT_LEVEL;
  99. }
  100. return this.level;
  101. }
  102. /**
  103. * Sets the resource level
  104. *
  105. * @param resourceLevel the resource level
  106. */
  107. public void setLevel(AFPResourceLevel resourceLevel) {
  108. this.level = resourceLevel;
  109. levelChanged = true;
  110. }
  111. /**
  112. * Returns true when the resource level was set
  113. *
  114. * @return true when the resource level was set
  115. */
  116. public boolean levelChanged() {
  117. return levelChanged;
  118. }
  119. /** {@inheritDoc} */
  120. public String toString() {
  121. return "AFPResourceInfo{uri=" + uri
  122. + (imageDimension != null
  123. ? ", " + imageDimension.width + "x" + imageDimension.height : "")
  124. + (name != null ? ", name=" + name : "")
  125. + (level != null ? ", level=" + level : "")
  126. + "}";
  127. }
  128. /** {@inheritDoc} */
  129. public boolean equals(Object obj) {
  130. if (this == obj) {
  131. return true;
  132. }
  133. if ((obj == null) || !(obj instanceof AFPResourceInfo)) {
  134. return false;
  135. }
  136. AFPResourceInfo ri = (AFPResourceInfo)obj;
  137. return (uri == ri.uri || uri != null && uri.equals(ri.uri))
  138. && (imageDimension == ri.imageDimension
  139. || imageDimension != null && imageDimension.equals(ri.imageDimension))
  140. && (name == ri.name || name != null && name.equals(ri.name))
  141. && (level == ri.level || level != null && level.equals(ri.level));
  142. }
  143. /** {@inheritDoc} */
  144. public int hashCode() {
  145. int hash = 7;
  146. hash = 31 * hash + (null == uri ? 0 : uri.hashCode());
  147. hash = 31 * hash + (null == imageDimension ? 0 : imageDimension.hashCode());
  148. hash = 31 * hash + (null == name ? 0 : name.hashCode());
  149. hash = 31 * hash + (null == level ? 0 : level.hashCode());
  150. return hash;
  151. }
  152. }