Java Code Examples for javafx.scene.Node#isManaged()

The following examples show how to use javafx.scene.Node#isManaged() . 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: FlowBox.java    From FxDock with Apache License 2.0 8 votes vote down vote up
public void layoutChildren()
{
	double x = left;
	double y = top;
	int col = 0;
	double max = getWidth() - right;
	
	for(int i=0; i<sz; i++)
	{
		Node ch = children.get(i);
		if(ch.isManaged())
		{
			double w = widths[i];
			if((x + w) >= max)
			{
				x = left;
				y += (vgap + lineHeight);
			}
			
			layoutInArea(ch, x, y, w, lineHeight);
			
			x += (hgap + w);
		}
	}
}
 
Example 2
Source File: GenericStyledArea.java    From RichTextFX with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
protected void layoutChildren() {
    Insets ins = getInsets();
    visibleParagraphs.suspendWhile(() -> {
        virtualFlow.resizeRelocate(
                ins.getLeft(), ins.getTop(),
                getWidth() - ins.getLeft() - ins.getRight(),
                getHeight() - ins.getTop() - ins.getBottom());

        if(followCaretRequested && ! paging) {
            try (Guard g = viewportDirty.suspend()) {
                followCaret();
            }
        }
        followCaretRequested = false;
        paging = false;
    });

    Node holder = placeholder;
    if (holder != null && holder.isResizable() && holder.isManaged()) {
        holder.autosize();
    }
}
 
Example 3
Source File: FlowBox.java    From FxDock with Apache License 2.0 5 votes vote down vote up
public Helper()
{
	Insets m = getInsets();
	top = m.getTop();
	bottom = m.getBottom();
	left = m.getLeft();
	right = m.getRight();
	double lh = 0.0;
	
	children = getChildren();
	sz = children.size();
	widths = new double[sz];
	
	for(int i=0; i<sz; i++)
	{
		Node ch = children.get(i);
		if(ch.isManaged())
		{
			double w = ch.prefWidth(-1);
			widths[i] = w;
			
			double h = ch.prefHeight(-1);
			if(h > lh)
			{
				lh = h;
			}
		}
	}
	
	lineHeight = lh;
}
 
Example 4
Source File: FlowBox.java    From FxDock with Apache License 2.0 5 votes vote down vote up
public double computePrefHeight(double forWidth)
{
	if(forWidth < 0)
	{
		return -1;
	}
	
	double max = forWidth - right;
	double x = left;
	double y = top;
	boolean addRow = false;
	
	for(int i=0; i<sz; i++)
	{
		Node ch = children.get(i);
		if(ch.isManaged())
		{
			addRow = true;
			
			double w = widths[i];
			if((x + w) >= max)
			{
				x = left;
				y += (vgap + lineHeight);
			}
			
			x += (hgap + w);
		}
	}
	
	if(addRow)
	{
		y += lineHeight;
	}
	
	return y + bottom;
}
 
Example 5
Source File: TextFlowLayout.java    From RichTextFX with BSD 2-Clause "Simplified" License 4 votes vote down vote up
int getLineCount() {
   
    if ( lineCount > -1 ) return lineCount;

    lineCount = 0;
    lineMetrics.clear();
    double totLines = 0.0, prevMinY = 1.0, prevMaxY = -1.0;
    int totCharSoFar = 0;

    for ( Node n : flow.getChildren() ) if ( n.isManaged() ) {
       
        Bounds nodeBounds = n.getBoundsInParent();
        int length = (n instanceof Text) ? ((Text) n).getText().length() : 1;
        PathElement[] shape = flow.rangeShape( totCharSoFar, totCharSoFar+length );
        double lines = Math.max( 1.0, Math.floor( shape.length / 5 ) );
        double nodeMinY = Math.max( 0.0, nodeBounds.getMinY() );
        
        if ( nodeMinY >= prevMinY && lines > 1 )  totLines += lines - 1;  // Multiline Text node 
        else if ( nodeMinY >= prevMaxY )  totLines += lines;

        if ( lineMetrics.size() < totLines ) {                            // Add additional lines
           
            if ( shape.length == 0 ) {
               lineMetrics.add( new TextFlowSpan( totCharSoFar, length, nodeMinY, nodeBounds.getWidth(), nodeBounds.getHeight() ) );
                totCharSoFar += length;
            }
            else for ( int ele = 1; ele < shape.length; ele += 5 ) {
                // Calculate the segment's line's length and width up to this point
                LineTo eleLine = (LineTo) shape[ele];
                double segWidth = eleLine.getX(), lineMinY = eleLine.getY();
                double charHeight = ((LineTo) shape[ele+1]).getY() - lineMinY;
                Point2D endPoint = new Point2D( segWidth-1, lineMinY + charHeight / 2 );

                // hitTest queries TextFlow layout internally and returns the position of the
                // last char (nearest endPoint) on the line, irrespective of the current Text node !
                int segLen = flow.hitTest( endPoint ).getCharIndex();
                segLen -= totCharSoFar - 1;

                if ( ele == 1 && nodeMinY < prevMaxY ) {
                    adjustLineMetrics( segLen, segWidth - ((MoveTo) shape[ele-1]).getX(), charHeight );
                }
                else {
                   lineMetrics.add( new TextFlowSpan( totCharSoFar, segLen, lineMinY, segWidth, charHeight ) );
                }

                totCharSoFar += segLen;
            }
        }
        else {
            // Adjust current line metrics with additional Text or Node embedded in this line 
            adjustLineMetrics( length, nodeBounds.getWidth(), nodeBounds.getHeight() );
            totCharSoFar += length;
        }

        prevMaxY = nodeBounds.getMaxY();
        prevMinY = nodeMinY;
    }
    
    lineCount = (int) totLines;
    return lineCount;
}