1. /*
  2. * @(#)NoFramesView.java 1.9 03/12/19
  3. *
  4. * Copyright 2004 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.9 12/19/03
  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. * @return 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 <code>View.X_AXIS</code> or
  114. * <code>View.Y_AXIS</code>
  115. * @return the minimum span the view can be rendered into
  116. * @see text.ParagraphView#getMinimumSpan
  117. */
  118. public float getMinimumSpan(int axis) {
  119. if (!visible) {
  120. return 0;
  121. }
  122. return super.getMinimumSpan(axis);
  123. }
  124. /**
  125. * Determines the maximum span for this view along an
  126. * axis. Returns 0 if the view is not visible, otherwise
  127. * it calls the superclass method ot get the maximum span.
  128. *
  129. * @param axis may be either <code>View.X_AXIS</code> or
  130. * <code>View.Y_AXIS</code>
  131. * @return the maximum span the view can be rendered into
  132. * @see text.ParagraphView#getMaximumSpan
  133. */
  134. public float getMaximumSpan(int axis) {
  135. if (!visible) {
  136. return 0;
  137. }
  138. return super.getMaximumSpan(axis);
  139. }
  140. boolean visible;
  141. }