Java Code Examples for javax.swing.text.ViewFactory#create()

The following examples show how to use javax.swing.text.ViewFactory#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GapBoxView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Loads child views by tracking child elements of the element
 * this view was created for.
 * @param index index at which the views should be added/replaced.
 * @param removeLength number of removed children views. It is useful
 *  when rebuilding children for a portion of the view.
 * @param elementIndex index of the first child element for which
 *  the view should be created
 * @param elementCount number of elements for which the views should be created.
 */
protected void elementReloadChildren(int index, int removeLength,
int elementCount) {

    Element e = getElement();
    View[] added = null;

    ViewFactory f = getViewFactory();
    // Null view factory can mean that one of the grand parents is already disconnected
    // from the view hierarchy. No added children for null factory.
        
    if (f != null) {
        added = new View[elementCount];
        for (int i = 0; i < elementCount; i++) {
            added[i] = f.create(e.getElement(index + i));
        }

    }

    replace(index, removeLength, added);
}
 
Example 2
Source File: JXLabel.java    From pgptool with GNU General Public License v3.0 6 votes vote down vote up
public static View createView(JXLabel c) {
	BasicEditorKit kit = getFactory();
	float rightIndent = 0;
	if (c.getIcon() != null && c.getHorizontalTextPosition() != SwingConstants.CENTER) {
		rightIndent = c.getIcon().getIconWidth() + c.getIconTextGap();
	}
	Document doc = kit.createDefaultDocument(c.getFont(), c.getForeground(), c.getTextAlignment(), rightIndent);
	Reader r = new StringReader(c.getText() == null ? "" : c.getText());
	try {
		kit.read(r, doc, 0);
	} catch (Throwable e) {
	}
	ViewFactory f = kit.getViewFactory();
	View hview = f.create(doc.getDefaultRootElement());
	View v = new Renderer(c, f, hview, true);
	return v;
}
 
Example 3
Source File: DrawEngineDocView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected @Override View createCustomView(ViewFactory f,
int startOffset, int maxEndOffset, int elementIndex) {
    if (elementIndex == -1) {
        throw new IllegalStateException("Need underlying line element structure"); // NOI18N
    }
    
    View view = null;

    Element elem = getElement();
    Element lineElem = elem.getElement(elementIndex);
    view = f.create(lineElem);
    return view;
}
 
Example 4
Source File: FoldMultiLineView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected @Override void reloadChildren(int index, int removeLength, int startOffset, int endOffset) {
    // TODO uncomment assert (index == 0 && removeLength == 0
        // && startOffset == getStartOffset() && endOffset == getEndOffset());

    // Rebuild all the present child views completely
    index = 0;
    removeLength = getViewCount();

    Element lineElem = getElement(); // starting line element
    View[] added = null;
    ViewFactory f = getViewFactory();
    if (f != null) {
        int lineElemEndOffset = lineElem.getEndOffset();
        // Ending offset of the previously created view - here start with
        //   begining of the first line
        int lastViewEndOffset = lineElem.getStartOffset();

        List childViews = new ArrayList();
        // Append ending fragment if necessary
        // asserted non-empty list => foldEndOffset populated
        if (lastViewEndOffset < lineElemEndOffset) { // need ending fragment
            View lineView = f.create(lineElem);
            View endingFrag = lineView.createFragment(lastViewEndOffset, lineElemEndOffset);
            childViews.add(endingFrag);
            // lastViewEndOffset = lineElemEndOffset;  <- can be ignored here
        }

        added = new View[childViews.size()];
        childViews.toArray(added);
    }

    
    replace(index, removeLength, added);
}
 
Example 5
Source File: DelegateView.java    From SwingBox with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void loadChildren(ViewFactory f)
{
    if (f == null) { return; }
    Element e = getElement();

    if (e.getElementCount() > 0)
    {
        View[] added = new View[1];
        // load children (element) using ViewFactory (a new View)
        // elements should contain only 1 LeafElement
        added[0] = f.create(e.getElement(0));
        replace(0, 1, added);
    }
}