Java Code Examples for com.alee.utils.SwingUtils#maxNonNull()

The following examples show how to use com.alee.utils.SwingUtils#maxNonNull() . 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: SizeCache.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns maximum {@link Dimension} combined from maximum sizes of all {@link Container}'s children.
 *
 * @param container {@link Container}
 * @param cache     {@link SizeCache} to reuse sizes from
 * @return maximum {@link Dimension} combined from maximum sizes of all {@link Container}'s children
 */
public Dimension maxPreferred ( @NotNull final Container container, @NotNull final SizeCache cache )
{
    if ( preferred == null )
    {
        preferred = new Dimension ( 0, 0 );
        for ( int index = 0; index < container.getComponentCount (); index++ )
        {
            preferred = SwingUtils.maxNonNull (
                    preferred,
                    cache.preferred ( container, index )
            );
        }
    }
    return preferred;
}
 
Example 2
Source File: SizeCache.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns maximum {@link Dimension} combined from minimum sizes of all {@link Container}'s children.
 *
 * @param container {@link Container}
 * @param cache     {@link SizeCache} to reuse sizes from
 * @return maximum {@link Dimension} combined from minimum sizes of all {@link Container}'s children
 */
public Dimension maxMinimum ( @NotNull final Container container, @NotNull final SizeCache cache )
{
    if ( preferred == null )
    {
        preferred = new Dimension ( 0, 0 );
        for ( int index = 0; index < container.getComponentCount (); index++ )
        {
            preferred = SwingUtils.maxNonNull (
                    preferred,
                    cache.minimum ( container, index )
            );
        }
    }
    return preferred;
}
 
Example 3
Source File: SizeCache.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns maximum {@link Dimension} combined from maximum sizes of all {@link Container}'s children.
 *
 * @param container {@link Container}
 * @param cache     {@link SizeCache} to reuse sizes from
 * @return maximum {@link Dimension} combined from maximum sizes of all {@link Container}'s children
 */
public Dimension maxMaximum ( @NotNull final Container container, @NotNull final SizeCache cache )
{
    if ( preferred == null )
    {
        preferred = new Dimension ( 0, 0 );
        for ( int index = 0; index < container.getComponentCount (); index++ )
        {
            preferred = SwingUtils.maxNonNull (
                    preferred,
                    cache.maximum ( container, index )
            );
        }
    }
    return preferred;
}
 
Example 4
Source File: OverlayLayout.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
@NotNull
@Override
public Dimension preferredLayoutSize ( @NotNull final Container parent )
{
    Dimension ps = new Dimension ( 0, 0 );

    // Adding content size
    final WebOverlay container = ( WebOverlay ) parent;
    final JComponent content = container.getContent ();
    if ( content != null )
    {
        final Dimension cps = content.getPreferredSize ();
        ps = SwingUtils.maxNonNull ( ps, cps );
    }

    // Adding maximum overlay margin
    ps = SwingUtils.increase ( ps, getOverlaysPadding ( container ) );

    // Adding container insets
    SwingUtils.increase ( ps, container.getInsets () );

    return ps;
}
 
Example 5
Source File: AbstractDecorationPainter.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
@NotNull
@Override
public Dimension getPreferredSize ()
{
    final Dimension ps = super.getPreferredSize ();
    final D d = getDecoration ();
    return d != null ? SwingUtils.maxNonNull ( d.getPreferredSize ( component ), ps ) : ps;
}
 
Example 6
Source File: OverlayLayout.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns maximum overlays padding.
 *
 * @param container {@link WebOverlay}
 * @return maximum overlays padding
 */
@NotNull
protected Insets getOverlaysPadding ( @NotNull final WebOverlay container )
{
    Insets maxMargin = new Insets ( 0, 0, 0, 0 );
    for ( final Overlay overlay : container.getOverlays () )
    {
        maxMargin = SwingUtils.maxNonNull ( maxMargin, overlay.margin () );
    }
    return maxMargin;
}
 
Example 7
Source File: TabbedPaneLayout.java    From weblaf with GNU General Public License v3.0 4 votes vote down vote up
@NotNull
@Override
public Dimension preferredLayoutSize ( @NotNull final Container parent )
{
    final Dimension preferredSize;

    // Calculating maximum content preferred size
    final JTabbedPane tabbedPane = ( JTabbedPane ) parent;
    final ComponentSize contentSize = getContentSize ();
    Dimension contentPreferredSize = new Dimension ( 0, 0 );
    for ( int i = 0; i < tabbedPane.getTabCount (); i++ )
    {
        final Component componentAt = tabbedPane.getComponentAt ( i );
        if ( componentAt != null )
        {
            contentPreferredSize = SwingUtils.maxNonNull (
                    contentPreferredSize,
                    contentSize.size ( componentAt )
            );
        }
    }

    // Calculating resulting preferred size
    final TabArea tabArea = getTabArea ( tabbedPane );
    if ( tabArea != null && tabArea.isVisible () )
    {
        final Dimension tabAreaSize = tabArea.getPreferredSize ();
        switch ( tabbedPane.getTabPlacement () )
        {
            default:
            case SwingConstants.TOP:
            case SwingConstants.BOTTOM:
            {
                preferredSize = new Dimension (
                        Math.max ( tabAreaSize.width, contentPreferredSize.width ),
                        tabAreaSize.height + contentPreferredSize.height
                );
            }
            break;

            case SwingConstants.LEFT:
            case SwingConstants.RIGHT:
            {
                preferredSize = new Dimension (
                        tabAreaSize.width + contentPreferredSize.width,
                        Math.max ( tabAreaSize.height, contentPreferredSize.height )
                );
            }
            break;
        }
    }
    else
    {
        preferredSize = contentPreferredSize;
    }

    // Adding tabbed pane insets
    SwingUtils.increase ( preferredSize, tabbedPane.getInsets () );

    return preferredSize;
}