FileDocCategorySizeDatePackage
EditableView.javaAPI DocJava SE 5 API2575Fri Aug 26 14:58:18 BST 2005javax.swing.text.html

EditableView

public class EditableView extends ComponentView
EditableView sets the view it contains to be visible only when the JTextComponent the view is contained in is editable. The min/pref/max size is 0 when not visible.
author
Scott Violet
version
1.11, 12/19/03

Fields Summary
private boolean
isVisible
Set to true if the component is visible. This is based off the editability of the container.
Constructors Summary
EditableView(Element e)

	super(e);
    
Methods Summary
public floatgetMaximumSpan(int axis)

	if (isVisible) {
	    return super.getMaximumSpan(axis);
	}
	return 0;
    
public floatgetMinimumSpan(int axis)

	if (isVisible) {
	    return super.getMinimumSpan(axis);
	}
	return 0;
    
public floatgetPreferredSpan(int axis)

	if (isVisible) {
	    return super.getPreferredSpan(axis);
	}
	return 0;
    
public booleanisVisible()

return
true if the Component is visible.

	return isVisible;
    
public voidpaint(java.awt.Graphics g, java.awt.Shape allocation)

	Component c = getComponent();
	Container host = getContainer();
	
	if (host != null &&
	    isVisible != ((JTextComponent)host).isEditable()) {
	    isVisible = ((JTextComponent)host).isEditable();
	    preferenceChanged(null, true, true);
	    host.repaint();
	}
	/*
	 * Note: we cannot tweak the visible state of the
	 * component in createComponent() even though it
	 * gets called after the setParent() call where
	 * the value of the boolean is set.  This 
	 * because, the setComponentParent() in the 
	 * superclass, always does a setVisible(false)
	 * after calling createComponent().   We therefore
	 * use this flag in the paint() method to 
	 * setVisible() to true if required.
	 */
	if (isVisible) {
	    super.paint(g, allocation);
	}
	else {
	    setSize(0, 0);
	}
	if (c != null) {
	    c.setFocusable(isVisible);
	}
    
public voidsetParent(javax.swing.text.View parent)

	if (parent != null) {
	    Container host = parent.getContainer();
	    if (host != null) {
		isVisible = ((JTextComponent)host).isEditable();
	    }
	}
	super.setParent(parent);