KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > text > html > NoFramesView


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
9 import javax.swing.text.*;
10 import java.awt.*;
11
12 /**
13  * This is the view associated with the html tag NOFRAMES.
14  * This view has been written to ignore the contents of the
15  * NOFRAMES tag. The contents of the tag will only be visible
16  * when the JTextComponent the view is contained in is editable.
17  *
18  * @author Sunita Mani
19  * @version 1.9 12/19/03
20  */

21 class NoFramesView extends BlockView JavaDoc {
22
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
38     /**
39      * If this view is not visible, then it returns.
40      * Otherwise it invokes the superclass.
41      *
42      * @param g the rendering surface to use
43      * @param allocation the allocated region to render into
44      * @see #isVisible
45      * @see text.ParagraphView#paint
46      */

47     public void paint(Graphics g, Shape allocation) {
48     Container host = getContainer();
49     if (host != null &&
50         visible != ((JTextComponent)host).isEditable()) {
51         visible = ((JTextComponent)host).isEditable();
52     }
53
54     if (!isVisible()) {
55         return;
56     }
57     super.paint(g, allocation);
58     }
59
60
61     /**
62      * Determines if the JTextComponent that the view
63      * is contained in is editable. If so, then this
64      * view and all its child views are visible.
65      * Once this has been determined, the superclass
66      * is invoked to continue processing.
67      *
68      * @param p the parent View.
69      * @see BlockView#setParent
70      */

71     public void setParent(View p) {
72     if (p != null) {
73         Container host = p.getContainer();
74         if (host != null) {
75         visible = ((JTextComponent)host).isEditable();
76         }
77     }
78     super.setParent(p);
79     }
80
81     /**
82      * Returns a true/false value that represents
83      * whether the view is visible or not.
84      */

85     public boolean isVisible() {
86     return visible;
87     }
88
89
90     /**
91      * Do nothing if the view is not visible, otherwise
92      * invoke the superclass to perform layout.
93      */

94     protected void layout(int width, int height) {
95     if (!isVisible()) {
96         return;
97     }
98     super.layout(width, height);
99     }
100         
101     /**
102      * Determines the preferred span for this view. Returns
103      * 0 if the view is not visible, otherwise it calls the
104      * superclass method to get the preferred span.
105      * axis.
106      *
107      * @param axis may be either View.X_AXIS or View.Y_AXIS
108      * @return the span the view would like to be rendered into;
109      * typically the view is told to render into the span
110      * that is returned, although there is no guarantee;
111      * the parent may choose to resize or break the view
112      * @see text.ParagraphView#getPreferredSpan
113      */

114     public float getPreferredSpan(int axis) {
115         if (!visible) {
116         return 0;
117     }
118     return super.getPreferredSpan(axis);
119     }
120
121     /**
122      * Determines the minimum span for this view along an
123      * axis. Returns 0 if the view is not visible, otherwise
124      * it calls the superclass method to get the minimum span.
125      *
126      * @param axis may be either <code>View.X_AXIS</code> or
127      * <code>View.Y_AXIS</code>
128      * @return the minimum span the view can be rendered into
129      * @see text.ParagraphView#getMinimumSpan
130      */

131     public float getMinimumSpan(int axis) {
132     if (!visible) {
133         return 0;
134     }
135     return super.getMinimumSpan(axis);
136     }
137
138     /**
139      * Determines the maximum span for this view along an
140      * axis. Returns 0 if the view is not visible, otherwise
141      * it calls the superclass method ot get the maximum span.
142      *
143      * @param axis may be either <code>View.X_AXIS</code> or
144      * <code>View.Y_AXIS</code>
145      * @return the maximum span the view can be rendered into
146      * @see text.ParagraphView#getMaximumSpan
147      */

148     public float getMaximumSpan(int axis) {
149     if (!visible) {
150         return 0;
151     }
152     return super.getMaximumSpan(axis);
153     }
154
155     boolean visible;
156 }
157
Popular Tags