Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

KnuthElement.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright 2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.layoutmgr;
  18. /**
  19. * This is the super class for KnuthBox, KnuthGlue and KnuthPenalty.
  20. *
  21. * It stores information common to all sub classes, and the methods to get it:
  22. * the width, a Position and a boolean marking KnuthElements used for some
  23. * special feature (for example, the additional elements used to represent
  24. * a space when text alignment is right, left or center).
  25. */
  26. public abstract class KnuthElement {
  27. public static final int KNUTH_BOX = 0;
  28. public static final int KNUTH_GLUE = 1;
  29. public static final int KNUTH_PENALTY = 2;
  30. public static final int INFINITE = 1000;
  31. private int type;
  32. private int width;
  33. private Position position;
  34. private boolean bIsAuxiliary;
  35. /**
  36. * Create a new KnuthElement.
  37. * This class being abstract, this can be called only by subclasses.
  38. *
  39. * @param t the type of this element (one of the KNUTH_* constants)
  40. * @param w the width of this element
  41. * @param pos the Position stored in this element
  42. * @param bAux is this an auxiliary element?
  43. */
  44. protected KnuthElement(int t, int w, Position pos, boolean bAux) {
  45. type = t;
  46. width = w;
  47. position = pos;
  48. bIsAuxiliary = bAux;
  49. }
  50. /**
  51. * Return true if this element is a KnuthBox.
  52. */
  53. public boolean isBox() {
  54. return (type == KNUTH_BOX);
  55. }
  56. /**
  57. * Return true if this element is a KnuthGlue.
  58. */
  59. public boolean isGlue() {
  60. return (type == KNUTH_GLUE);
  61. }
  62. /**
  63. * Return true if this element is a KnuthPenalty.
  64. */
  65. public boolean isPenalty() {
  66. return (type == KNUTH_PENALTY);
  67. }
  68. /**
  69. * Return true if this element is an auxiliary one.
  70. */
  71. public boolean isAuxiliary() {
  72. return bIsAuxiliary;
  73. }
  74. /**
  75. * Return the width of this element.
  76. */
  77. public int getW() {
  78. return width;
  79. }
  80. /**
  81. * Return the Position stored in this element.
  82. */
  83. public Position getPosition() {
  84. return position;
  85. }
  86. /**
  87. * Change the Position stored in this element.
  88. */
  89. public void setPosition(Position pos) {
  90. position = pos;
  91. }
  92. /**
  93. * Return the LayoutManager responsible for this element.
  94. */
  95. public LayoutManager getLayoutManager() {
  96. if (position != null) {
  97. return position.getLM();
  98. } else {
  99. return null;
  100. }
  101. }
  102. }