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.

PDFGoToRemote.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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.pdf;
  19. /**
  20. * Class representing a /GoToR object.
  21. */
  22. public class PDFGoToRemote extends PDFAction {
  23. /**
  24. * the file specification
  25. */
  26. private PDFFileSpec pdfFileSpec;
  27. private int pageReference = 0;
  28. private String destination = null;
  29. private boolean newWindow = false;
  30. /**
  31. * Create an GoToR object.
  32. *
  33. * @param pdfFileSpec the fileSpec associated with the action
  34. * @param newWindow boolean indicating whether the target should be
  35. * displayed in a new window
  36. */
  37. public PDFGoToRemote(PDFFileSpec pdfFileSpec, boolean newWindow) {
  38. /* generic creation of object */
  39. super();
  40. this.pdfFileSpec = pdfFileSpec;
  41. this.newWindow = newWindow;
  42. }
  43. /**
  44. * create an GoToR object.
  45. *
  46. * @param pdfFileSpec the fileSpec associated with the action
  47. * @param page a page reference within the remote document
  48. * @param newWindow boolean indicating whether the target should be
  49. * displayed in a new window
  50. */
  51. public PDFGoToRemote(PDFFileSpec pdfFileSpec, int page, boolean newWindow) {
  52. /* generic creation of object */
  53. super();
  54. this.pdfFileSpec = pdfFileSpec;
  55. this.pageReference = page;
  56. this.newWindow = newWindow;
  57. }
  58. /**
  59. * create an GoToR object.
  60. *
  61. * @param pdfFileSpec the fileSpec associated with the action
  62. * @param dest a named destination within the remote document
  63. * @param newWindow boolean indicating whether the target should be
  64. * displayed in a new window
  65. */
  66. public PDFGoToRemote(PDFFileSpec pdfFileSpec, String dest, boolean newWindow) {
  67. /* generic creation of object */
  68. super();
  69. this.pdfFileSpec = pdfFileSpec;
  70. this.destination = dest;
  71. this.newWindow = newWindow;
  72. }
  73. /**
  74. * return the action string which will reference this object
  75. *
  76. * @return the action String
  77. */
  78. public String getAction() {
  79. return this.referencePDF();
  80. }
  81. /**
  82. * {@inheritDoc}
  83. */
  84. public String toPDFString() {
  85. StringBuffer sb = new StringBuffer(64);
  86. sb.append(getObjectID());
  87. sb.append("<<\n/S /GoToR\n/F ");
  88. sb.append(pdfFileSpec.referencePDF());
  89. sb.append("\n");
  90. if (destination != null) {
  91. sb.append("/D (").append(this.destination).append(")");
  92. } else {
  93. sb.append("/D [ ").append(this.pageReference).append(" /XYZ null null null ]");
  94. }
  95. if (newWindow) {
  96. sb.append("/NewWindow true");
  97. }
  98. sb.append(" \n>>\nendobj\n");
  99. return sb.toString();
  100. }
  101. /*
  102. * example
  103. * 28 0 obj
  104. * <<
  105. * /S /GoToR
  106. * /F 29 0 R
  107. * /D [ 0 /XYZ -6 797 null ]
  108. * >>
  109. * endobj
  110. */
  111. /**
  112. * Check if this equals another object.
  113. *
  114. * @param obj the object to compare
  115. * @return true if this equals other object
  116. */
  117. public boolean equals(Object obj) {
  118. if (this == obj) {
  119. return true;
  120. }
  121. if (obj == null || !(obj instanceof PDFGoToRemote)) {
  122. return false;
  123. }
  124. PDFGoToRemote remote = (PDFGoToRemote)obj;
  125. if (!remote.pdfFileSpec.referencePDF().equals(pdfFileSpec.referencePDF())) {
  126. return false;
  127. }
  128. if (destination != null) {
  129. if (!destination.equals(remote.destination)) {
  130. return false;
  131. }
  132. } else {
  133. if (pageReference != remote.pageReference) {
  134. return false;
  135. }
  136. }
  137. return (this.newWindow == remote.newWindow);
  138. }
  139. }