java.awt.LinearGradientPaint Java Examples

The following examples show how to use java.awt.LinearGradientPaint. 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: D3DPaints.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
boolean isPaintValid(SunGraphics2D sg2d) {
    LinearGradientPaint paint = (LinearGradientPaint)sg2d.paint;

    if (paint.getFractions().length == 2 &&
        paint.getCycleMethod() != CycleMethod.REPEAT &&
        paint.getColorSpace() != ColorSpaceType.LINEAR_RGB)
    {
        D3DSurfaceData dstData = (D3DSurfaceData)sg2d.surfaceData;
        D3DGraphicsDevice gd = (D3DGraphicsDevice)
            dstData.getDeviceConfiguration().getDevice();
        if (gd.isCapPresent(CAPS_LCD_SHADER)) {
            // we can delegate to the optimized two-color gradient
            // codepath, which should be faster
            return true;
        }
    }

    return super.isPaintValid(sg2d);
}
 
Example #2
Source File: DigitialRadial.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Paint createCustomLcdBackgroundPaint(final Color[] LCD_COLORS) {
    final Point2D FOREGROUND_START = new Point2D.Double(0.0, LCD.getMinY() + 1.0);
    final Point2D FOREGROUND_STOP = new Point2D.Double(0.0, LCD.getMaxY() - 1);
    if (FOREGROUND_START.equals(FOREGROUND_STOP)) {
        FOREGROUND_STOP.setLocation(0.0, FOREGROUND_START.getY() + 1);
    }

    final float[] FOREGROUND_FRACTIONS = {
        0.0f,
        0.03f,
        0.49f,
        0.5f,
        1.0f
    };

    final Color[] FOREGROUND_COLORS = {
        LCD_COLORS[0],
        LCD_COLORS[1],
        LCD_COLORS[2],
        LCD_COLORS[3],
        LCD_COLORS[4]
    };

    return new LinearGradientPaint(FOREGROUND_START, FOREGROUND_STOP, FOREGROUND_FRACTIONS, FOREGROUND_COLORS);
}
 
Example #3
Source File: DynamicIconUrlStreamHandler.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void drawIcon(Graphics2D g2, int width, int height, int percentage) {
	// prepare background
	g2.setColor(Color.WHITE);
	g2.fillRect(0, 0, width, height);

	// 0-50 % is the same color, only the last 50% fade into red
	Color startColor = new Color(0f, .5f, 0, 0.7f);
	g2.setColor(startColor);
	g2.setPaint(new LinearGradientPaint(width / 2, 0f, width, 0f, new float[] { 0f, 0.5f, 1f }, new Color[] {
			new Color(0f, .5f, 0, 0.7f), new Color(1f, 1f, 0f, 0.7f), new Color(1f, 0, 0, 0.7f) }));
	g2.fillRect(0, 0, (int) (percentage / 100d * width), height);

	// draw border
	g2.setColor(Color.GRAY);
	g2.drawRect(0, 0, width - 1, height - 1);
	g2.dispose();
}
 
Example #4
Source File: DigitalRadial.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Paint createCustomLcdBackgroundPaint(final Color[] LCD_COLORS) {
    final Point2D FOREGROUND_START = new Point2D.Double(0.0, LCD.getMinY() + 1.0);
    final Point2D FOREGROUND_STOP = new Point2D.Double(0.0, LCD.getMaxY() - 1);
    if (FOREGROUND_START.equals(FOREGROUND_STOP)) {
        FOREGROUND_STOP.setLocation(0.0, FOREGROUND_START.getY() + 1);
    }

    final float[] FOREGROUND_FRACTIONS = {
        0.0f,
        0.03f,
        0.49f,
        0.5f,
        1.0f
    };

    final Color[] FOREGROUND_COLORS = {
        LCD_COLORS[0],
        LCD_COLORS[1],
        LCD_COLORS[2],
        LCD_COLORS[3],
        LCD_COLORS[4]
    };

    return new LinearGradientPaint(FOREGROUND_START, FOREGROUND_STOP, FOREGROUND_FRACTIONS, FOREGROUND_COLORS);
}
 
Example #5
Source File: D3DPaints.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
boolean isPaintValid(SunGraphics2D sg2d) {
    LinearGradientPaint paint = (LinearGradientPaint)sg2d.paint;

    if (paint.getFractions().length == 2 &&
        paint.getCycleMethod() != CycleMethod.REPEAT &&
        paint.getColorSpace() != ColorSpaceType.LINEAR_RGB)
    {
        D3DSurfaceData dstData = (D3DSurfaceData)sg2d.surfaceData;
        D3DGraphicsDevice gd = (D3DGraphicsDevice)
            dstData.getDeviceConfiguration().getDevice();
        if (gd.isCapPresent(CAPS_LCD_SHADER)) {
            // we can delegate to the optimized two-color gradient
            // codepath, which should be faster
            return true;
        }
    }

    return super.isPaintValid(sg2d);
}
 
Example #6
Source File: DisplaySingle.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Paint createCustomLcdBackgroundPaint(final Color[] LCD_COLORS) {
    final Point2D FOREGROUND_START = new Point2D.Double(0.0, 1.0);
    final Point2D FOREGROUND_STOP = new Point2D.Double(0.0, getHeight() - 1);
    if (FOREGROUND_START.equals(FOREGROUND_STOP)) {
        FOREGROUND_STOP.setLocation(0.0, FOREGROUND_START.getY() + 1);
    }

    final float[] FOREGROUND_FRACTIONS = {
        0.0f,
        0.03f,
        0.49f,
        0.5f,
        1.0f
    };

    final Color[] FOREGROUND_COLORS = {
        LCD_COLORS[0],
        LCD_COLORS[1],
        LCD_COLORS[2],
        LCD_COLORS[3],
        LCD_COLORS[4]
    };

    return new LinearGradientPaint(FOREGROUND_START, FOREGROUND_STOP, FOREGROUND_FRACTIONS, FOREGROUND_COLORS);
}
 
Example #7
Source File: RowForegroundDecorator.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public void paint(Graphics2D g, Rectangle dirtyArea, ChartContext context) {
    if (gradient || selection) {
        int rowsCount = chart.getRowsCount();
        for (int i = 0; i < rowsCount; i++) {
            TimelineChart.Row row = chart.getRow(i);
            ChartContext rowContext = row.getContext();

            int y = Utils.checkedInt(rowContext.getViewportOffsetY());
            int h = Utils.checkedInt(rowContext.getViewportHeight() - 1);

            if (gradient) {
                g.setPaint(new LinearGradientPaint(0, y, 0, y + h, FRACTIONS, COLORS));
                g.fillRect(0, y, chart.getWidth(), h);
            }

            if (selection && chart.isRowSelected(row)) {
                g.setColor(SELECTED_FILTER);
                g.fillRect(0, y, chart.getWidth(), h);
            }
        }
    }
}
 
Example #8
Source File: java_awt_LinearGradientPaint.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected LinearGradientPaint getAnotherObject() {
    return null; /* TODO: could not update property
    float[] f = { 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f };
    Color[] c = { Color.RED, Color.GREEN, Color.BLUE, Color.RED, Color.GREEN, Color.BLUE };
    return new LinearGradientPaint(
            new Point2D.Float(f[0], f[1]),
            new Point2D.Float(f[2], f[3]),
            f, c, REFLECT, LINEAR_RGB,
            new AffineTransform(f));*/
}
 
Example #9
Source File: BufferedPaints.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void setPaint(RenderQueue rq, SunGraphics2D sg2d,
                     Paint paint, int ctxflags)
{
    if (sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR) {
        setColor(rq, sg2d.pixel);
    } else {
        boolean useMask = (ctxflags & BufferedContext.USE_MASK) != 0;
        switch (sg2d.paintState) {
        case SunGraphics2D.PAINT_GRADIENT:
            setGradientPaint(rq, sg2d,
                             (GradientPaint)paint, useMask);
            break;
        case SunGraphics2D.PAINT_LIN_GRADIENT:
            setLinearGradientPaint(rq, sg2d,
                                   (LinearGradientPaint)paint, useMask);
            break;
        case SunGraphics2D.PAINT_RAD_GRADIENT:
            setRadialGradientPaint(rq, sg2d,
                                   (RadialGradientPaint)paint, useMask);
            break;
        case SunGraphics2D.PAINT_TEXTURE:
            setTexturePaint(rq, sg2d,
                            (TexturePaint)paint, useMask);
            break;
        default:
            break;
        }
    }
}
 
Example #10
Source File: CustomLegendGraphic.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
private static LinearGradientPaint getTranslatedLinearGradientPaint(LinearGradientPaint gradient, Point2D startPoint,
		Point2D endPoint, boolean vertical) {
	if (vertical) {
		return new LinearGradientPaint(0f, (float) startPoint.getY(), 0f, (float) endPoint.getY(),
				gradient.getFractions(), gradient.getColors());
	} else {
		return new LinearGradientPaint((float) startPoint.getX(), 0f, (float) endPoint.getX(), 0f,
				gradient.getFractions(), gradient.getColors());
	}
}
 
Example #11
Source File: OGLPaints.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
boolean isPaintValid(SunGraphics2D sg2d) {
    LinearGradientPaint paint = (LinearGradientPaint)sg2d.paint;

    if (paint.getFractions().length == 2 &&
        paint.getCycleMethod() != CycleMethod.REPEAT &&
        paint.getColorSpace() != ColorSpaceType.LINEAR_RGB)
    {
        // we can delegate to the optimized two-color gradient
        // codepath, which does not require fragment shader support
        return true;
    }

    return super.isPaintValid(sg2d);
}
 
Example #12
Source File: PaintAlpha.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new (if possible, darker) <code>Paint</code> of the same Type.
 * If the Type is not supported, the original <code>Paint</code> is returned.
 * <p>
 * @param paint a <code>Paint</code> implementation
 * (e.g. {@link Color}, {@link GradientPaint}, {@link TexturePaint},..)
 * <p>
 * @return a (usually new, see above) <code>Paint</code>
 */
public static Paint darker(Paint paint) {

    if (paint instanceof Color) {
        return darker((Color) paint);
    }
    if (legacyAlpha == true) {
        /*
         * Legacy? Just return the original Paint.
         * (this corresponds EXACTLY to how Paints used to be darkened)
         */
        return paint;
    }
    if (paint instanceof GradientPaint) {
        return darker((GradientPaint) paint);
    }
    if (paint instanceof LinearGradientPaint) {
        return darkerLinearGradientPaint((LinearGradientPaint) paint);
    }
    if (paint instanceof RadialGradientPaint) {
        return darkerRadialGradientPaint((RadialGradientPaint) paint);
    }
    if (paint instanceof TexturePaint) {
        try {
            return darkerTexturePaint((TexturePaint) paint);
        }
        catch (Exception e) {
            /*
             * Lots can go wrong while fiddling with Images, Color Models
             * & such!  If anything at all goes awry, just return the original
             * TexturePaint.  (TexturePaint's are immutable anyway, so no harm
             * done)
             */
            return paint;
        }
    }
    return paint;
}
 
Example #13
Source File: OGLPaints.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
boolean isPaintValid(SunGraphics2D sg2d) {
    LinearGradientPaint paint = (LinearGradientPaint)sg2d.paint;

    if (paint.getFractions().length == 2 &&
        paint.getCycleMethod() != CycleMethod.REPEAT &&
        paint.getColorSpace() != ColorSpaceType.LINEAR_RGB)
    {
        // we can delegate to the optimized two-color gradient
        // codepath, which does not require fragment shader support
        return true;
    }

    return super.isPaintValid(sg2d);
}
 
Example #14
Source File: SVGGraphics2D.java    From jfreesvg with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns an SVG color string based on the current paint.  To handle
 * {@code GradientPaint} we rely on the {@code setPaint()} method
 * having set the {@code gradientPaintRef} attribute.
 * 
 * @return An SVG color string. 
 */
private String svgColorStr() {
    String result = "black;";
    if (this.paint instanceof Color) {
        return rgbColorStr((Color) this.paint);
    } else if (this.paint instanceof GradientPaint 
            || this.paint instanceof LinearGradientPaint
            || this.paint instanceof RadialGradientPaint) {
        return "url(#" + this.gradientPaintRef + ")";
    }
    return result;
}
 
Example #15
Source File: LinearGradientPrintingTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void doPaint(Graphics2D g2d) {

        g2d.translate(DIM*0.2, DIM*0.2);
        Shape s = new Rectangle2D.Float(0, 0, DIM*2, DIM*2);
        Point2D.Double p1 = new Point2D.Double(0.0, 0.0);
        Point2D.Double p2 = new Point2D.Double(DIM/2.0, DIM/2.0);

        // LinearGradientPaint
        //g2d.translate(DIM*2.2, 0);
        Color colors[] =  { Color.red, Color.blue} ;
        float fractions[]  = { 0.0f, 1.0f };

        LinearGradientPaint lgp =
           new LinearGradientPaint(p1, p2, fractions, colors,
              LinearGradientPaint.CycleMethod.NO_CYCLE);
        g2d.setPaint(lgp);
        g2d.fill(s);

        g2d.translate(DIM*2.2, 0);
        Color colors1[] =  { Color.red, Color.blue, Color.green, Color.white} ;
        float fractions1[]  = { 0.0f, 0.3f, 0.6f, 1.0f };

        LinearGradientPaint lgp1 =
           new LinearGradientPaint(p1, p2, fractions1, colors1,
              LinearGradientPaint.CycleMethod.REFLECT);
        g2d.setPaint(lgp1);
        g2d.fill(s);

        g2d.translate(-DIM*2.2, DIM*2.2);
        Color colors2[] =  { Color.red, Color.blue, Color.green, Color.white} ;
        float fractions2[]  = { 0.0f, 0.3f, 0.6f, 1.0f };

        LinearGradientPaint lgp2 =
           new LinearGradientPaint(p1, p2, fractions2, colors2,
              LinearGradientPaint.CycleMethod.REPEAT);
        g2d.setPaint(lgp2);
        g2d.fill(s);
    }
 
Example #16
Source File: BufferedPaints.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
static void setPaint(RenderQueue rq, SunGraphics2D sg2d,
                     Paint paint, int ctxflags)
{
    if (sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR) {
        setColor(rq, sg2d.pixel);
    } else {
        boolean useMask = (ctxflags & BufferedContext.USE_MASK) != 0;
        switch (sg2d.paintState) {
        case SunGraphics2D.PAINT_GRADIENT:
            setGradientPaint(rq, sg2d,
                             (GradientPaint)paint, useMask);
            break;
        case SunGraphics2D.PAINT_LIN_GRADIENT:
            setLinearGradientPaint(rq, sg2d,
                                   (LinearGradientPaint)paint, useMask);
            break;
        case SunGraphics2D.PAINT_RAD_GRADIENT:
            setRadialGradientPaint(rq, sg2d,
                                   (RadialGradientPaint)paint, useMask);
            break;
        case SunGraphics2D.PAINT_TEXTURE:
            setTexturePaint(rq, sg2d,
                            (TexturePaint)paint, useMask);
            break;
        default:
            break;
        }
    }
}
 
Example #17
Source File: TransformedPaintTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private Paint createPaint(PaintType type, int startx, int starty,
                          int w, int h)
{
    // make sure that the blue color doesn't show up when filling a
    // w by h rect
    w++; h++;

    int endx = startx + w;
    int endy = starty + h;
    Rectangle2D.Float r = new Rectangle2D.Float(startx, starty, w, h);
    switch (type) {
        case COLOR: return Color.red;
        case GRADIENT: return
            new GradientPaint(startx, starty, Color.red,
                              endx, endy, Color.green);
        case LINEAR_GRADIENT: return
            new LinearGradientPaint(startx, starty, endx, endy,
                new float[] { 0.0f, 0.999f, 1.0f },
                new Color[] { Color.red, Color.green, Color.blue });
        case RADIAL_GRADIENT: return
            new RadialGradientPaint(startx, starty,
                (float)Math.sqrt(w * w + h * h),
                new float[] { 0.0f, 0.999f, 1.0f },
                new Color[] { Color.red, Color.green, Color.blue },
                CycleMethod.NO_CYCLE);
        case TEXTURE: {
            BufferedImage bi =
                new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
            Graphics2D g = (Graphics2D) bi.getGraphics();
            g.setPaint(createPaint(PaintType.LINEAR_GRADIENT, 0, 0, w, h));
            g.fillRect(0, 0, w, h);
            return new TexturePaint(bi, r);
        }
    }
    return Color.green;
}
 
Example #18
Source File: TransformedPaintTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private Paint createPaint(PaintType type, int startx, int starty,
                          int w, int h)
{
    // make sure that the blue color doesn't show up when filling a
    // w by h rect
    w++; h++;

    int endx = startx + w;
    int endy = starty + h;
    Rectangle2D.Float r = new Rectangle2D.Float(startx, starty, w, h);
    switch (type) {
        case COLOR: return Color.red;
        case GRADIENT: return
            new GradientPaint(startx, starty, Color.red,
                              endx, endy, Color.green);
        case LINEAR_GRADIENT: return
            new LinearGradientPaint(startx, starty, endx, endy,
                new float[] { 0.0f, 0.999f, 1.0f },
                new Color[] { Color.red, Color.green, Color.blue });
        case RADIAL_GRADIENT: return
            new RadialGradientPaint(startx, starty,
                (float)Math.sqrt(w * w + h * h),
                new float[] { 0.0f, 0.999f, 1.0f },
                new Color[] { Color.red, Color.green, Color.blue },
                CycleMethod.NO_CYCLE);
        case TEXTURE: {
            BufferedImage bi =
                new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
            Graphics2D g = (Graphics2D) bi.getGraphics();
            g.setPaint(createPaint(PaintType.LINEAR_GRADIENT, 0, 0, w, h));
            g.fillRect(0, 0, w, h);
            return new TexturePaint(bi, r);
        }
    }
    return Color.green;
}
 
Example #19
Source File: TransformedPaintTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private Paint createPaint(PaintType type, int startx, int starty,
                          int w, int h)
{
    // make sure that the blue color doesn't show up when filling a
    // w by h rect
    w++; h++;

    int endx = startx + w;
    int endy = starty + h;
    Rectangle2D.Float r = new Rectangle2D.Float(startx, starty, w, h);
    switch (type) {
        case COLOR: return Color.red;
        case GRADIENT: return
            new GradientPaint(startx, starty, Color.red,
                              endx, endy, Color.green);
        case LINEAR_GRADIENT: return
            new LinearGradientPaint(startx, starty, endx, endy,
                new float[] { 0.0f, 0.999f, 1.0f },
                new Color[] { Color.red, Color.green, Color.blue });
        case RADIAL_GRADIENT: return
            new RadialGradientPaint(startx, starty,
                (float)Math.sqrt(w * w + h * h),
                new float[] { 0.0f, 0.999f, 1.0f },
                new Color[] { Color.red, Color.green, Color.blue },
                CycleMethod.NO_CYCLE);
        case TEXTURE: {
            BufferedImage bi =
                new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
            Graphics2D g = (Graphics2D) bi.getGraphics();
            g.setPaint(createPaint(PaintType.LINEAR_GRADIENT, 0, 0, w, h));
            g.fillRect(0, 0, w, h);
            return new TexturePaint(bi, r);
        }
    }
    return Color.green;
}
 
Example #20
Source File: java_awt_LinearGradientPaint.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
protected LinearGradientPaint getAnotherObject() {
    return null; /* TODO: could not update property
    float[] f = { 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f };
    Color[] c = { Color.RED, Color.GREEN, Color.BLUE, Color.RED, Color.GREEN, Color.BLUE };
    return new LinearGradientPaint(
            new Point2D.Float(f[0], f[1]),
            new Point2D.Float(f[2], f[3]),
            f, c, REFLECT, LINEAR_RGB,
            new AffineTransform(f));*/
}
 
Example #21
Source File: PaintAlpha.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new Gradient with its colours darkened.
 *
 * @param paint a <code>LinearGradientPaint</code>
 *
 * @return a darker version of the <code>LinearGradientPaint</code>
 */
private static Paint darkerLinearGradientPaint(LinearGradientPaint paint) {
    final Color[] paintColors = paint.getColors();
    for (int i = 0; i < paintColors.length; i++) {
        paintColors[i] = darker(paintColors[i]);
    }
    return new LinearGradientPaint(paint.getStartPoint(),
            paint.getEndPoint(), paint.getFractions(), paintColors,
            paint.getCycleMethod(), paint.getColorSpace(), 
            paint.getTransform());
}
 
Example #22
Source File: BufferedPaints.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void setPaint(RenderQueue rq, SunGraphics2D sg2d,
                     Paint paint, int ctxflags)
{
    if (sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR) {
        setColor(rq, sg2d.pixel);
    } else {
        boolean useMask = (ctxflags & BufferedContext.USE_MASK) != 0;
        switch (sg2d.paintState) {
        case SunGraphics2D.PAINT_GRADIENT:
            setGradientPaint(rq, sg2d,
                             (GradientPaint)paint, useMask);
            break;
        case SunGraphics2D.PAINT_LIN_GRADIENT:
            setLinearGradientPaint(rq, sg2d,
                                   (LinearGradientPaint)paint, useMask);
            break;
        case SunGraphics2D.PAINT_RAD_GRADIENT:
            setRadialGradientPaint(rq, sg2d,
                                   (RadialGradientPaint)paint, useMask);
            break;
        case SunGraphics2D.PAINT_TEXTURE:
            setTexturePaint(rq, sg2d,
                            (TexturePaint)paint, useMask);
            break;
        default:
            break;
        }
    }
}
 
Example #23
Source File: SunGraphics2D.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the Paint in the current graphics state.
 * @param paint The Paint object to be used to generate color in
 * the rendering process.
 * @see java.awt.Graphics#setColor
 * @see GradientPaint
 * @see TexturePaint
 */
public void setPaint(Paint paint) {
    if (paint instanceof Color) {
        setColor((Color) paint);
        return;
    }
    if (paint == null || this.paint == paint) {
        return;
    }
    this.paint = paint;
    if (imageComp == CompositeType.SrcOverNoEa) {
        // special case where compState depends on opacity of paint
        if (paint.getTransparency() == Transparency.OPAQUE) {
            if (compositeState != COMP_ISCOPY) {
                compositeState = COMP_ISCOPY;
            }
        } else {
            if (compositeState == COMP_ISCOPY) {
                compositeState = COMP_ALPHA;
            }
        }
    }
    Class<? extends Paint> paintClass = paint.getClass();
    if (paintClass == GradientPaint.class) {
        paintState = PAINT_GRADIENT;
    } else if (paintClass == LinearGradientPaint.class) {
        paintState = PAINT_LIN_GRADIENT;
    } else if (paintClass == RadialGradientPaint.class) {
        paintState = PAINT_RAD_GRADIENT;
    } else if (paintClass == TexturePaint.class) {
        paintState = PAINT_TEXTURE;
    } else {
        paintState = PAINT_CUSTOM;
    }
    validFontInfo = false;
    invalidatePipe();
}
 
Example #24
Source File: RenderTests.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private LinearGradientPaint makeLinear(int numColors, boolean alpha) {
    float interval = 1.0f / (numColors - 1);
    float[] fractions = new float[numColors];
    for (int i = 0; i < fractions.length; i++) {
        fractions[i] = i * interval;
    }
    Color[] colors = makeGradientColors(numColors, alpha);
    return new LinearGradientPaint(0.0f, 0.0f,
                                   10.0f, 10.0f,
                                   fractions, colors,
                                   CycleMethod.REFLECT);
}
 
Example #25
Source File: BufferedPaints.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
static void setPaint(RenderQueue rq, SunGraphics2D sg2d,
                     Paint paint, int ctxflags)
{
    if (sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR) {
        setColor(rq, sg2d.pixel);
    } else {
        boolean useMask = (ctxflags & BufferedContext.USE_MASK) != 0;
        switch (sg2d.paintState) {
        case SunGraphics2D.PAINT_GRADIENT:
            setGradientPaint(rq, sg2d,
                             (GradientPaint)paint, useMask);
            break;
        case SunGraphics2D.PAINT_LIN_GRADIENT:
            setLinearGradientPaint(rq, sg2d,
                                   (LinearGradientPaint)paint, useMask);
            break;
        case SunGraphics2D.PAINT_RAD_GRADIENT:
            setRadialGradientPaint(rq, sg2d,
                                   (RadialGradientPaint)paint, useMask);
            break;
        case SunGraphics2D.PAINT_TEXTURE:
            setTexturePaint(rq, sg2d,
                            (TexturePaint)paint, useMask);
            break;
        default:
            break;
        }
    }
}
 
Example #26
Source File: java_awt_LinearGradientPaint.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected LinearGradientPaint getAnotherObject() {
    return null; /* TODO: could not update property
    float[] f = { 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f };
    Color[] c = { Color.RED, Color.GREEN, Color.BLUE, Color.RED, Color.GREEN, Color.BLUE };
    return new LinearGradientPaint(
            new Point2D.Float(f[0], f[1]),
            new Point2D.Float(f[2], f[3]),
            f, c, REFLECT, LINEAR_RGB,
            new AffineTransform(f));*/
}
 
Example #27
Source File: TransformedPaintTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private Paint createPaint(PaintType type, int startx, int starty,
                          int w, int h)
{
    // make sure that the blue color doesn't show up when filling a
    // w by h rect
    w++; h++;

    int endx = startx + w;
    int endy = starty + h;
    Rectangle2D.Float r = new Rectangle2D.Float(startx, starty, w, h);
    switch (type) {
        case COLOR: return Color.red;
        case GRADIENT: return
            new GradientPaint(startx, starty, Color.red,
                              endx, endy, Color.green);
        case LINEAR_GRADIENT: return
            new LinearGradientPaint(startx, starty, endx, endy,
                new float[] { 0.0f, 0.999f, 1.0f },
                new Color[] { Color.red, Color.green, Color.blue });
        case RADIAL_GRADIENT: return
            new RadialGradientPaint(startx, starty,
                (float)Math.sqrt(w * w + h * h),
                new float[] { 0.0f, 0.999f, 1.0f },
                new Color[] { Color.red, Color.green, Color.blue },
                CycleMethod.NO_CYCLE);
        case TEXTURE: {
            BufferedImage bi =
                new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
            Graphics2D g = (Graphics2D) bi.getGraphics();
            g.setPaint(createPaint(PaintType.LINEAR_GRADIENT, 0, 0, w, h));
            g.fillRect(0, 0, w, h);
            return new TexturePaint(bi, r);
        }
    }
    return Color.green;
}
 
Example #28
Source File: SeaGlassInternalShadowEffect.java    From seaglass with Apache License 2.0 5 votes vote down vote up
/**
 * Create the gradient for a rounded shadow.
 *
 * @param  s the shape of the gradient. This is only used for its bounds.
 *
 * @return the gradient.
 */
public Paint getRoundedShadowGradient(Shape s) {
    Rectangle r    = s.getBounds();
    int       x    = r.x + r.width / 2;
    int       y1   = r.y;
    float     frac = 1.0f / r.height;
    int       y2   = r.y + r.height;

    return new LinearGradientPaint(x, y1, x, y2, (new float[] { 0f, frac, 1f }),
                                   new Color[] { innerShadow.top, innerShadow.bottom, innerShadow.bottom });
}
 
Example #29
Source File: BufferedPaints.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void setPaint(RenderQueue rq, SunGraphics2D sg2d,
                     Paint paint, int ctxflags)
{
    if (sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR) {
        setColor(rq, sg2d.pixel);
    } else {
        boolean useMask = (ctxflags & BufferedContext.USE_MASK) != 0;
        switch (sg2d.paintState) {
        case SunGraphics2D.PAINT_GRADIENT:
            setGradientPaint(rq, sg2d,
                             (GradientPaint)paint, useMask);
            break;
        case SunGraphics2D.PAINT_LIN_GRADIENT:
            setLinearGradientPaint(rq, sg2d,
                                   (LinearGradientPaint)paint, useMask);
            break;
        case SunGraphics2D.PAINT_RAD_GRADIENT:
            setRadialGradientPaint(rq, sg2d,
                                   (RadialGradientPaint)paint, useMask);
            break;
        case SunGraphics2D.PAINT_TEXTURE:
            setTexturePaint(rq, sg2d,
                            (TexturePaint)paint, useMask);
            break;
        default:
            break;
        }
    }
}
 
Example #30
Source File: java_awt_LinearGradientPaint.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
protected LinearGradientPaint getAnotherObject() {
    return null; /* TODO: could not update property
    float[] f = { 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f };
    Color[] c = { Color.RED, Color.GREEN, Color.BLUE, Color.RED, Color.GREEN, Color.BLUE };
    return new LinearGradientPaint(
            new Point2D.Float(f[0], f[1]),
            new Point2D.Float(f[2], f[3]),
            f, c, REFLECT, LINEAR_RGB,
            new AffineTransform(f));*/
}