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