Examples of NinePatchInterval


Examples of com.alee.utils.ninepatch.NinePatchInterval

                intervalType.equals ( NinePatchIntervalType.verticalStretch );
        final int l = ( intervalType.equals ( NinePatchIntervalType.horizontalStretch ) ||
                intervalType.equals ( NinePatchIntervalType.horizontalContent ) ? image.getWidth () : image.getHeight () ) - 1;

        final List<NinePatchInterval> intervals = new ArrayList<NinePatchInterval> ();
        NinePatchInterval interval = null;
        boolean pixelPart;
        for ( int i = 1; i < l; i++ )
        {
            final int rgb;
            switch ( intervalType )
            {
                case horizontalStretch:
                    rgb = image.getRGB ( i, 0 );
                    break;
                case verticalStretch:
                    rgb = image.getRGB ( 0, i );
                    break;
                case horizontalContent:
                    rgb = image.getRGB ( i, image.getHeight () - 1 );
                    break;
                case verticalContent:
                    rgb = image.getRGB ( image.getWidth () - 1, i );
                    break;
                default:
                    rgb = 0;
                    break;
            }

            pixelPart = rgb != Color.BLACK.getRGB ();
            if ( interval == null )
            {
                // Initial interval
                interval = new NinePatchInterval ( i - 1, i - 1, pixelPart );
            }
            else if ( pixelPart == interval.isPixel () )
            {
                // Enlarge interval
                interval.setEnd ( i - 1 );
            }
            else if ( pixelPart != interval.isPixel () )
            {
                // Add pixel interval only for stretch types and nonpixel for any type
                if ( hv || !interval.isPixel () )
                {
                    intervals.add ( interval );
                }
                // New interval starts
                interval = new NinePatchInterval ( i - 1, i - 1, pixelPart );
            }
        }
        if ( interval != null )
        {
            // Add pixel interval only for stretch types and nonpixel for any type
            if ( hv || !interval.isPixel () )
            {
                intervals.add ( interval );
            }
        }
        return intervals;
View Full Code Here

Examples of com.alee.utils.ninepatch.NinePatchInterval

     * @return nine-patch stretch intervals
     */
    public static List<NinePatchInterval> parseStretchIntervals ( final boolean[] filled )
    {
        final List<NinePatchInterval> intervals = new ArrayList<NinePatchInterval> ();
        NinePatchInterval interval = null;
        boolean pixelPart;
        for ( int i = 0; i < filled.length; i++ )
        {
            pixelPart = !filled[ i ];
            if ( interval == null )
            {
                // Initial interval
                interval = new NinePatchInterval ( i, i, pixelPart );
            }
            else if ( pixelPart == interval.isPixel () )
            {
                // Enlarge interval
                interval.setEnd ( i );
            }
            else if ( pixelPart != interval.isPixel () )
            {
                intervals.add ( interval );

                // New interval starts
                interval = new NinePatchInterval ( i, i, pixelPart );
            }
        }
        if ( interval != null )
        {
            intervals.add ( interval );
View Full Code Here

Examples of com.alee.utils.ninepatch.NinePatchInterval

                            x < imageStartX + iw && y < imageStartY )
                    {
                        someDragged = true;
                        addingHorizontalStretch = true;
                        startX = x;
                        changedInterval = new NinePatchInterval ( ( x - imageStartX ) / zoom, false );
                        ninePatchIcon.addHorizontalStretch ( changedInterval );
                        repaintRequired = true;
                    }
                    else if ( addingHorizontalStretch && mouseEventType.equals ( MouseEventType.mouseDragged ) )
                    {
                        final int start = ( startX - imageStartX ) / zoom;
                        final int end = ( x - imageStartX ) / zoom;
                        changedInterval.setStart ( Math.max ( 0, Math.min ( start, end ) ) );
                        changedInterval.setEnd ( Math.min ( image.getWidth () - 1, Math.max ( start, end ) ) );
                        repaintRequired = true;
                    }
                    else if ( addingHorizontalStretch && mouseEventType.equals ( MouseEventType.mouseReleased ) )
                    {
                        someDragged = false;
                        addingHorizontalStretch = false;
                        verifyHorizontalStretchAreas ();
                        repaintRequired = true;
                        saveHistoryState ();
                        fireStateChanged ();
                    }
                }
                if ( addingVerticalStretch || !someDragged )
                {
                    if ( mouseEventType.equals ( MouseEventType.mousePressed ) && y > imageStartY &&
                            y < imageStartY + ih && x < imageStartX )
                    {
                        someDragged = true;
                        addingVerticalStretch = true;
                        startY = y;
                        changedInterval = new NinePatchInterval ( ( y - imageStartY ) / zoom, false );
                        ninePatchIcon.addVerticalStretch ( changedInterval );
                        repaintRequired = true;
                    }
                    else if ( addingVerticalStretch && mouseEventType.equals ( MouseEventType.mouseDragged ) )
                    {
                        final int start = ( startY - imageStartY ) / zoom;
                        final int end = ( y - imageStartY ) / zoom;
                        changedInterval.setStart ( Math.max ( 0, Math.min ( start, end ) ) );
                        changedInterval.setEnd ( Math.min ( image.getHeight () - 1, Math.max ( start, end ) ) );
                        repaintRequired = true;
                    }
                    else if ( addingVerticalStretch && mouseEventType.equals ( MouseEventType.mouseReleased ) )
                    {
                        someDragged = false;
                        addingVerticalStretch = false;
                        verifyVerticalStretchAreas ();
                        repaintRequired = true;
                        saveHistoryState ();
                        fireStateChanged ();
                    }
                }
            }

            // Removing stretch areas  
            if ( SwingUtilities.isRightMouseButton ( e ) )
            {
                if ( removingHorizontalStretch || !someDragged )
                {
                    if ( mouseEventType.equals ( MouseEventType.mousePressed ) && x > imageStartX &&
                            x < imageStartX + iw && y < imageStartY )
                    {
                        someDragged = true;
                        removingHorizontalStretch = true;
                        startX = x;
                        removedInterval = new NinePatchInterval ( ( x - imageStartX ) / zoom, false );
                        finishHorizontalRemoval ();
                        repaintRequired = true;
                    }
                    else if ( removingHorizontalStretch && mouseEventType.equals ( MouseEventType.mouseDragged ) )
                    {
                        final int start = ( startX - imageStartX ) / zoom;
                        final int end = ( x - imageStartX ) / zoom;
                        removedInterval.setStart ( Math.max ( 0, Math.min ( start, end ) ) );
                        removedInterval.setEnd ( Math.min ( image.getWidth () - 1, Math.max ( start, end ) ) );
                        finishHorizontalRemoval ();
                        repaintRequired = true;
                    }
                    else if ( removingHorizontalStretch && mouseEventType.equals ( MouseEventType.mouseReleased ) )
                    {
                        someDragged = false;
                        removingHorizontalStretch = false;
                        repaintRequired = true;
                        saveHistoryState ();
                        fireStateChanged ();
                    }
                }
                if ( removingVerticalStretch || !someDragged )
                {
                    if ( mouseEventType.equals ( MouseEventType.mousePressed ) && y > imageStartY &&
                            y < imageStartY + ih && x < imageStartX )
                    {
                        someDragged = true;
                        removingVerticalStretch = true;
                        startY = y;
                        removedInterval = new NinePatchInterval ( ( y - imageStartY ) / zoom, false );
                        finishVerticalRemoval ();
                        repaintRequired = true;
                    }
                    else if ( removingVerticalStretch && mouseEventType.equals ( MouseEventType.mouseDragged ) )
                    {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.