1 /* 2 * Copyright (c) 1998, 2017, Oracle and/or its affiliates. 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package javax.swing.text.html; 26 27 import javax.swing.text.*; 28 import 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 */ 38 class 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 javax.swing.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 javax.swing.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 javax.swing.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 javax.swing.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 }