blob: 083a1a467c8684bf8e7bb8ef86060c8b8ce0cf5d [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1998-2000 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25package javax.swing.text.html;
26
27import javax.swing.text.*;
28import java.awt.*;
29
30/**
31 * This is the view associated with the html tag NOFRAMES.
32 * This view has been written to ignore the contents of the
33 * NOFRAMES tag. The contents of the tag will only be visible
34 * when the JTextComponent the view is contained in is editable.
35 *
36 * @author Sunita Mani
37 */
38class NoFramesView extends BlockView {
39
40 /**
41 * Creates a new view that represents an
42 * html box. This can be used for a number
43 * of elements. By default this view is not
44 * visible.
45 *
46 * @param elem the element to create a view for
47 * @param axis either View.X_AXIS or View.Y_AXIS
48 */
49 public NoFramesView(Element elem, int axis) {
50 super(elem, axis);
51 visible = false;
52 }
53
54
55 /**
56 * If this view is not visible, then it returns.
57 * Otherwise it invokes the superclass.
58 *
59 * @param g the rendering surface to use
60 * @param allocation the allocated region to render into
61 * @see #isVisible
62 * @see text.ParagraphView#paint
63 */
64 public void paint(Graphics g, Shape allocation) {
65 Container host = getContainer();
66 if (host != null &&
67 visible != ((JTextComponent)host).isEditable()) {
68 visible = ((JTextComponent)host).isEditable();
69 }
70
71 if (!isVisible()) {
72 return;
73 }
74 super.paint(g, allocation);
75 }
76
77
78 /**
79 * Determines if the JTextComponent that the view
80 * is contained in is editable. If so, then this
81 * view and all its child views are visible.
82 * Once this has been determined, the superclass
83 * is invoked to continue processing.
84 *
85 * @param p the parent View.
86 * @see BlockView#setParent
87 */
88 public void setParent(View p) {
89 if (p != null) {
90 Container host = p.getContainer();
91 if (host != null) {
92 visible = ((JTextComponent)host).isEditable();
93 }
94 }
95 super.setParent(p);
96 }
97
98 /**
99 * Returns a true/false value that represents
100 * whether the view is visible or not.
101 */
102 public boolean isVisible() {
103 return visible;
104 }
105
106
107 /**
108 * Do nothing if the view is not visible, otherwise
109 * invoke the superclass to perform layout.
110 */
111 protected void layout(int width, int height) {
112 if (!isVisible()) {
113 return;
114 }
115 super.layout(width, height);
116 }
117
118 /**
119 * Determines the preferred span for this view. Returns
120 * 0 if the view is not visible, otherwise it calls the
121 * superclass method to get the preferred span.
122 * axis.
123 *
124 * @param axis may be either View.X_AXIS or View.Y_AXIS
125 * @return the span the view would like to be rendered into;
126 * typically the view is told to render into the span
127 * that is returned, although there is no guarantee;
128 * the parent may choose to resize or break the view
129 * @see text.ParagraphView#getPreferredSpan
130 */
131 public float getPreferredSpan(int axis) {
132 if (!visible) {
133 return 0;
134 }
135 return super.getPreferredSpan(axis);
136 }
137
138 /**
139 * Determines the minimum span for this view along an
140 * axis. Returns 0 if the view is not visible, otherwise
141 * it calls the superclass method to get the minimum span.
142 *
143 * @param axis may be either <code>View.X_AXIS</code> or
144 * <code>View.Y_AXIS</code>
145 * @return the minimum span the view can be rendered into
146 * @see text.ParagraphView#getMinimumSpan
147 */
148 public float getMinimumSpan(int axis) {
149 if (!visible) {
150 return 0;
151 }
152 return super.getMinimumSpan(axis);
153 }
154
155 /**
156 * Determines the maximum span for this view along an
157 * axis. Returns 0 if the view is not visible, otherwise
158 * it calls the superclass method ot get the maximum span.
159 *
160 * @param axis may be either <code>View.X_AXIS</code> or
161 * <code>View.Y_AXIS</code>
162 * @return the maximum span the view can be rendered into
163 * @see text.ParagraphView#getMaximumSpan
164 */
165 public float getMaximumSpan(int axis) {
166 if (!visible) {
167 return 0;
168 }
169 return super.getMaximumSpan(axis);
170 }
171
172 boolean visible;
173}