1. /*
  2. * @(#)NoFramesView.java 1.5 00/02/02
  3. *
  4. * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package javax.swing.text.html;
  11. import javax.swing.text.*;
  12. import java.awt.*;
  13. /**
  14. * This is the view associated with the html tag NOFRAMES.
  15. * This view has been written to ignore the contents of the
  16. * NOFRAMES tag. The contents of the tag will only be visible
  17. * when the JTextComponent the view is contained in is editable.
  18. *
  19. * @author Sunita Mani
  20. * @version 1.5 02/02/00
  21. */
  22. class NoFramesView extends BlockView {
  23. /**
  24. * Creates a new view that represents an
  25. * html box. This can be used for a number
  26. * of elements. By default this view is not
  27. * visible.
  28. *
  29. * @param elem the element to create a view for
  30. * @param axis either View.X_AXIS or View.Y_AXIS
  31. */
  32. public NoFramesView(Element elem, int axis) {
  33. super(elem, axis);
  34. visible = false;
  35. }
  36. /**
  37. * If this view is not visible, then it returns.
  38. * Otherwise it invokes the superclass.
  39. *
  40. * @param g the rendering surface to use
  41. * @param allocation the allocated region to render into
  42. * @see #isVisible
  43. * @see text.ParagraphView#paint
  44. */
  45. public void paint(Graphics g, Shape allocation) {
  46. Container host = getContainer();
  47. if (host != null &&
  48. visible != ((JTextComponent)host).isEditable()) {
  49. visible = ((JTextComponent)host).isEditable();
  50. }
  51. if (!isVisible()) {
  52. return;
  53. }
  54. super.paint(g, allocation);
  55. }
  56. /**
  57. * Determines if the JTextComponent that the view
  58. * is contained in is editable. If so, then this
  59. * view and all its child views are visible.
  60. * Once this has been determined, the superclass
  61. * is invoked to continue processing.
  62. *
  63. * @param p the parent View.
  64. * @see BlockView#setParent
  65. */
  66. public void setParent(View p) {
  67. if (p != null) {
  68. Container host = p.getContainer();
  69. if (host != null) {
  70. visible = ((JTextComponent)host).isEditable();
  71. }
  72. }
  73. super.setParent(p);
  74. }
  75. /**
  76. * Returns a true/false value that represents
  77. * whether the view is visible or not.
  78. */
  79. public boolean isVisible() {
  80. return visible;
  81. }
  82. /**
  83. * Do nothing if the view is not visible, otherwise
  84. * invoke the superclass to perform layout.
  85. */
  86. protected void layout(int width, int height) {
  87. if (!isVisible()) {
  88. return;
  89. }
  90. super.layout(width, height);
  91. }
  92. /**
  93. * Determines the preferred span for this view. Returns
  94. * 0 if the view is not visible, otherwise it calls the
  95. * superclass method to get the preferred span.
  96. * axis.
  97. *
  98. * @param axis may be either View.X_AXIS or View.Y_AXIS
  99. * @returns the span the view would like to be rendered into.
  100. * Typically the view is told to render into the span
  101. * that is returned, although there is no guarantee.
  102. * The parent may choose to resize or break the view.
  103. * @see text.ParagraphView#getPreferredSpan
  104. */
  105. public float getPreferredSpan(int axis) {
  106. if (!visible) {
  107. return 0;
  108. }
  109. return super.getPreferredSpan(axis);
  110. }
  111. /**
  112. * Determines the minimum span for this view along an
  113. * axis. Returns 0 if the view is not visible, otherwise
  114. * it calls the superclass method to get the minimum span.
  115. *
  116. * @param axis may be either View.X_AXIS or View.Y_AXIS
  117. * @returns the minimum span the view can be rendered into.
  118. * @see text.ParagraphView#getMinimumSpan
  119. */
  120. public float getMinimumSpan(int axis) {
  121. if (!visible) {
  122. return 0;
  123. }
  124. return super.getMinimumSpan(axis);
  125. }
  126. /**
  127. * Determines the maximum span for this view along an
  128. * axis. Returns 0 if the view is not visible, otherwise
  129. * it calls the superclass method ot get the maximum span.
  130. *
  131. * @param axis may be either View.X_AXIS or View.Y_AXIS
  132. * @returns the maximum span the view can be rendered into.
  133. * @see text.ParagraphView#getMaximumSpan
  134. */
  135. public float getMaximumSpan(int axis) {
  136. if (!visible) {
  137. return 0;
  138. }
  139. return super.getMaximumSpan(axis);
  140. }
  141. boolean visible;
  142. }