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.

LinkSet.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* $Id$
  2. * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  3. * For details on use and redistribution please refer to the
  4. * LICENSE file included with these sources.
  5. */
  6. package org.apache.fop.layout;
  7. // Java
  8. import java.util.Vector;
  9. import java.util.Enumeration;
  10. import java.awt.Rectangle;
  11. import org.apache.fop.layout.inline.InlineArea;
  12. import org.apache.fop.fo.properties.WrapOption; // for enumerated
  13. // values
  14. // import org.apache.fop.fo.properties.WhiteSpaceCollapse; // for
  15. // enumerated values
  16. import org.apache.fop.fo.properties.TextAlign; // for enumerated
  17. // values
  18. import org.apache.fop.fo.properties.TextAlignLast; // for enumerated
  19. // values
  20. /**
  21. * a set of rectangles on a page that are linked to a common
  22. * destination
  23. */
  24. public class LinkSet {
  25. /** the destination of the links */
  26. String destination;
  27. /** the set of rectangles */
  28. Vector rects = new Vector();
  29. private int xoffset = 0;
  30. private int yoffset = 0;
  31. /* the maximum Y offset value encountered for this LinkSet*/
  32. private int maxY = 0;
  33. protected int startIndent;
  34. protected int endIndent;
  35. private int linkType;
  36. private Area area;
  37. public final static int INTERNAL = 0, // represents internal link
  38. EXTERNAL = 1; // represents external link
  39. // property required for alignment adjustments
  40. int contentRectangleWidth = 0;
  41. public LinkSet(String destination, Area area, int linkType) {
  42. this.destination = destination;
  43. this.area = area;
  44. this.linkType = linkType;
  45. }
  46. public void addRect(Rectangle r, LineArea lineArea, InlineArea inlineArea) {
  47. LinkedRectangle linkedRectangle = new LinkedRectangle(r, lineArea, inlineArea);
  48. linkedRectangle.setY(this.yoffset);
  49. if (this.yoffset > maxY) {
  50. maxY = this.yoffset;
  51. }
  52. rects.addElement(linkedRectangle);
  53. }
  54. public void setYOffset(int y) {
  55. this.yoffset = y;
  56. }
  57. public void setXOffset(int x) {
  58. this.xoffset = x;
  59. }
  60. public void setContentRectangleWidth(int contentRectangleWidth) {
  61. this.contentRectangleWidth = contentRectangleWidth;
  62. }
  63. public void applyAreaContainerOffsets(AreaContainer ac, Area area) {
  64. int height = area.getAbsoluteHeight();
  65. BlockArea ba = (BlockArea) area;
  66. Enumeration re = rects.elements();
  67. while (re.hasMoreElements()) {
  68. LinkedRectangle r = (LinkedRectangle) re.nextElement();
  69. r.setX(r.getX() + ac.getXPosition() +
  70. area.getTableCellXOffset());
  71. r.setY(ac.getYPosition() - height + (maxY - r.getY()) -
  72. ba.getHalfLeading());
  73. }
  74. }
  75. // intermediate implementation for joining all sublinks on same line
  76. public void mergeLinks() {
  77. int numRects = rects.size();
  78. if (numRects == 1)
  79. return;
  80. LinkedRectangle curRect =
  81. new LinkedRectangle((LinkedRectangle) rects.elementAt(0));
  82. Vector nv = new Vector();
  83. for (int ri = 1; ri < numRects; ri++) {
  84. LinkedRectangle r = (LinkedRectangle) rects.elementAt(ri);
  85. // yes, I'm really happy with comparing refs...
  86. if (r.getLineArea() == curRect.getLineArea()) {
  87. curRect.setWidth(r.getX() + r.getWidth() - curRect.getX());
  88. } else {
  89. nv.addElement(curRect);
  90. curRect = new LinkedRectangle(r);
  91. }
  92. if (ri == numRects - 1)
  93. nv.addElement(curRect);
  94. }
  95. rects = nv;
  96. }
  97. public void align() {
  98. Enumeration re = rects.elements();
  99. while (re.hasMoreElements()) {
  100. LinkedRectangle r = (LinkedRectangle) re.nextElement();
  101. r.setX(r.getX() +
  102. r.getLineArea().getStartIndent() +
  103. r.getInlineArea().getXOffset());
  104. }
  105. }
  106. public String getDest() {
  107. return this.destination;
  108. }
  109. public Vector getRects() {
  110. return this.rects;
  111. }
  112. public int getEndIndent() {
  113. return endIndent;
  114. }
  115. public int getStartIndent() {
  116. return startIndent;
  117. }
  118. public Area getArea() {
  119. return area;
  120. }
  121. public int getLinkType() {
  122. return linkType;
  123. }
  124. }