001 /*
002 * Copyright 1998-2000 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025 package javax.swing.text.html;
026
027 import javax.swing.text.*;
028 import java.awt.*;
029
030 /**
031 * This is the view associated with the html tag NOFRAMES.
032 * This view has been written to ignore the contents of the
033 * NOFRAMES tag. The contents of the tag will only be visible
034 * when the JTextComponent the view is contained in is editable.
035 *
036 * @author Sunita Mani
037 * @version 1.16 05/05/07
038 */
039 class NoFramesView extends BlockView {
040
041 /**
042 * Creates a new view that represents an
043 * html box. This can be used for a number
044 * of elements. By default this view is not
045 * visible.
046 *
047 * @param elem the element to create a view for
048 * @param axis either View.X_AXIS or View.Y_AXIS
049 */
050 public NoFramesView(Element elem, int axis) {
051 super (elem, axis);
052 visible = false;
053 }
054
055 /**
056 * If this view is not visible, then it returns.
057 * Otherwise it invokes the superclass.
058 *
059 * @param g the rendering surface to use
060 * @param allocation the allocated region to render into
061 * @see #isVisible
062 * @see text.ParagraphView#paint
063 */
064 public void paint(Graphics g, Shape allocation) {
065 Container host = getContainer();
066 if (host != null
067 && visible != ((JTextComponent) host).isEditable()) {
068 visible = ((JTextComponent) host).isEditable();
069 }
070
071 if (!isVisible()) {
072 return;
073 }
074 super .paint(g, allocation);
075 }
076
077 /**
078 * Determines if the JTextComponent that the view
079 * is contained in is editable. If so, then this
080 * view and all its child views are visible.
081 * Once this has been determined, the superclass
082 * is invoked to continue processing.
083 *
084 * @param p the parent View.
085 * @see BlockView#setParent
086 */
087 public void setParent(View p) {
088 if (p != null) {
089 Container host = p.getContainer();
090 if (host != null) {
091 visible = ((JTextComponent) host).isEditable();
092 }
093 }
094 super .setParent(p);
095 }
096
097 /**
098 * Returns a true/false value that represents
099 * whether the view is visible or not.
100 */
101 public boolean isVisible() {
102 return visible;
103 }
104
105 /**
106 * Do nothing if the view is not visible, otherwise
107 * invoke the superclass to perform layout.
108 */
109 protected void layout(int width, int height) {
110 if (!isVisible()) {
111 return;
112 }
113 super .layout(width, height);
114 }
115
116 /**
117 * Determines the preferred span for this view. Returns
118 * 0 if the view is not visible, otherwise it calls the
119 * superclass method to get the preferred span.
120 * axis.
121 *
122 * @param axis may be either View.X_AXIS or View.Y_AXIS
123 * @return the span the view would like to be rendered into;
124 * typically the view is told to render into the span
125 * that is returned, although there is no guarantee;
126 * the parent may choose to resize or break the view
127 * @see text.ParagraphView#getPreferredSpan
128 */
129 public float getPreferredSpan(int axis) {
130 if (!visible) {
131 return 0;
132 }
133 return super .getPreferredSpan(axis);
134 }
135
136 /**
137 * Determines the minimum span for this view along an
138 * axis. Returns 0 if the view is not visible, otherwise
139 * it calls the superclass method to get the minimum span.
140 *
141 * @param axis may be either <code>View.X_AXIS</code> or
142 * <code>View.Y_AXIS</code>
143 * @return the minimum span the view can be rendered into
144 * @see text.ParagraphView#getMinimumSpan
145 */
146 public float getMinimumSpan(int axis) {
147 if (!visible) {
148 return 0;
149 }
150 return super .getMinimumSpan(axis);
151 }
152
153 /**
154 * Determines the maximum span for this view along an
155 * axis. Returns 0 if the view is not visible, otherwise
156 * it calls the superclass method ot get the maximum span.
157 *
158 * @param axis may be either <code>View.X_AXIS</code> or
159 * <code>View.Y_AXIS</code>
160 * @return the maximum span the view can be rendered into
161 * @see text.ParagraphView#getMaximumSpan
162 */
163 public float getMaximumSpan(int axis) {
164 if (!visible) {
165 return 0;
166 }
167 return super .getMaximumSpan(axis);
168 }
169
170 boolean visible;
171 }
|