Java Code Examples for java.awt.LinearGradientPaint

The following examples show how to use java.awt.LinearGradientPaint. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: mars-sim   Source File: DisplaySingle.java    License: 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 2
Source Project: openjdk-8-source   Source File: D3DPaints.java    License: 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 3
Source Project: mars-sim   Source File: DigitialRadial.java    License: 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 4
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 5
@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 6
Source Project: mars-sim   Source File: DigitalRadial.java    License: 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 7
Source Project: jdk8u-dev-jdk   Source File: D3DPaints.java    License: 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 8
Source Project: jfreesvg   Source File: SVGGraphics2D.java    License: 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 9
Source Project: seaglass   Source File: SeaGlassInternalShadowEffect.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create the gradient for the top of a rectangular shadow.
 *
 * @param  s the shape of the gradient. This is only used for its bounds.
 *
 * @return the gradient.
 */
public Paint getTopShadowGradient(Shape s) {
    Rectangle2D bounds = s.getBounds2D();
    float       minY   = (float) bounds.getMinY();
    float       maxY   = (float) bounds.getMaxY();
    float       midX   = (float) bounds.getCenterX();

    return new LinearGradientPaint(midX, minY, midX, maxY, (new float[] { 0f, 1f }), new Color[] { innerShadow.top, transparentColor });
}
 
Example 10
Source Project: ccu-historian   Source File: PaintAlpha.java    License: 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 11
Source Project: hottub   Source File: RenderTests.java    License: 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 12
Source Project: jeddict   Source File: DBColorScheme.java    License: Apache License 2.0 5 votes vote down vote up
public Paint getBackgroundPaint() {
    final float[] FRACTIONS = {0.0f, 0.25f, 0.5f, 0.75f, 1.0f};
    final Color[] DARK_COLORS = {new Color(76, 30, 57), new Color(78, 29, 47), new Color(76, 24, 40), new Color(115, 68, 56), new Color(163, 83, 76)};

    LinearGradientPaint DARK_GRADIENT = new LinearGradientPaint(
            new Point2D.Double(0, 0), new Point2D.Double(1000, 0),
            FRACTIONS, DARK_COLORS, MultipleGradientPaint.CycleMethod.REFLECT);
    return DARK_GRADIENT;
}
 
Example 13
Source Project: dragonwell8_jdk   Source File: OGLPaints.java    License: 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 Project: openjdk-8   Source File: OGLPaints.java    License: 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 15
Source Project: TencentKona-8   Source File: RenderTests.java    License: 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 16
Source Project: jdk8u-jdk   Source File: SunGraphics2D.java    License: 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 17
Source Project: jdk8u_jdk   Source File: OGLPaints.java    License: 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 18
Source Project: TencentKona-8   Source File: SunGraphics2D.java    License: 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 19
Source Project: SIMVA-SoS   Source File: PaintAlpha.java    License: Apache License 2.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 20
Source Project: mars-sim   Source File: LightBulb.java    License: GNU General Public License v3.0 5 votes vote down vote up
public BufferedImage createOffImage(final int WIDTH, final int HEIGHT) {
    final GraphicsConfiguration GFX_CONF = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
    if (WIDTH <= 0 || HEIGHT <= 0) {
        return GFX_CONF.createCompatibleImage(1, 1, java.awt.Transparency.TRANSLUCENT);
    }
    final BufferedImage IMAGE = GFX_CONF.createCompatibleImage(WIDTH, HEIGHT, Transparency.TRANSLUCENT);
    final Graphics2D G2 = IMAGE.createGraphics();
    G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    G2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
    G2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    final int IMAGE_WIDTH = IMAGE.getWidth();
    final int IMAGE_HEIGHT = IMAGE.getHeight();
    final GeneralPath GLAS = new GeneralPath();
    GLAS.setWindingRule(Path2D.WIND_EVEN_ODD);
    GLAS.moveTo(0.2894736842105263 * IMAGE_WIDTH, 0.43859649122807015 * IMAGE_HEIGHT);
    GLAS.curveTo(0.2894736842105263 * IMAGE_WIDTH, 0.5614035087719298 * IMAGE_HEIGHT, 0.38596491228070173 * IMAGE_WIDTH, 0.6052631578947368 * IMAGE_HEIGHT, 0.38596491228070173 * IMAGE_WIDTH, 0.7456140350877193 * IMAGE_HEIGHT);
    GLAS.curveTo(0.38596491228070173 * IMAGE_WIDTH, 0.7456140350877193 * IMAGE_HEIGHT, 0.5877192982456141 * IMAGE_WIDTH, 0.7456140350877193 * IMAGE_HEIGHT, 0.5877192982456141 * IMAGE_WIDTH, 0.7456140350877193 * IMAGE_HEIGHT);
    GLAS.curveTo(0.5877192982456141 * IMAGE_WIDTH, 0.6052631578947368 * IMAGE_HEIGHT, 0.6929824561403509 * IMAGE_WIDTH, 0.5614035087719298 * IMAGE_HEIGHT, 0.6929824561403509 * IMAGE_WIDTH, 0.43859649122807015 * IMAGE_HEIGHT);
    GLAS.curveTo(0.6929824561403509 * IMAGE_WIDTH, 0.32456140350877194 * IMAGE_HEIGHT, 0.6052631578947368 * IMAGE_WIDTH, 0.22807017543859648 * IMAGE_HEIGHT, 0.5 * IMAGE_WIDTH, 0.22807017543859648 * IMAGE_HEIGHT);
    GLAS.curveTo(0.38596491228070173 * IMAGE_WIDTH, 0.22807017543859648 * IMAGE_HEIGHT, 0.2894736842105263 * IMAGE_WIDTH, 0.32456140350877194 * IMAGE_HEIGHT, 0.2894736842105263 * IMAGE_WIDTH, 0.43859649122807015 * IMAGE_HEIGHT);
    GLAS.closePath();
    final LinearGradientPaint GLAS_PAINT = new LinearGradientPaint(new Point2D.Double(0.5 * IMAGE_WIDTH, 0.2894736842105263 * IMAGE_HEIGHT), new Point2D.Double(0.5 * IMAGE_WIDTH, 0.7017543859649122 * IMAGE_HEIGHT), new float[]{0.0f, 0.99f, 1.0f}, new Color[]{new Color(0.9333333333f, 0.9333333333f, 0.9333333333f, 1f), new Color(0.6f, 0.6f, 0.6f, 1f), new Color(0.6f, 0.6f, 0.6f, 1f)});
    G2.setPaint(GLAS_PAINT);
    G2.fill(GLAS);
    G2.setPaint(new Color(0.8f, 0.8f, 0.8f, 1f));
    G2.setStroke(new BasicStroke((0.010101010101010102f * IMAGE_WIDTH), 0, 1));
    G2.draw(GLAS);
    G2.drawImage(Shadow.INSTANCE.createInnerShadow((Shape) GLAS, GLAS_PAINT, 0, 0.35f, new Color(0, 0, 0, 50), (int) 10.0, 45), GLAS.getBounds().x, GLAS.getBounds().y, null);

    G2.dispose();
    return IMAGE;
}
 
Example 21
Source Project: jdk8u60   Source File: RenderTests.java    License: 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 22
Source Project: ECG-Viewer   Source File: PaintAlpha.java    License: GNU General Public License v2.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 23
Source Project: hottub   Source File: BufferedPaints.java    License: 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 24
Source Project: mars-sim   Source File: DisplayRectangular.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public Paint createCustomLcdBackgroundPaint(final Color[] LCD_COLORS) {
    int offset = 1;
    if (isFrameVisible()) {
        offset = 19;
    }
    final Point2D FOREGROUND_START = new Point2D.Double(0.0, offset);
    final Point2D FOREGROUND_STOP = new Point2D.Double(0.0, getHeight() - offset);
    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 25
Source Project: jdk8u60   Source File: TransformedPaintTest.java    License: 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 26
Source Project: openjdk-jdk8u   Source File: BufferedPaints.java    License: 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 27
@Override
public LinearGradientPaint create() {
	Point2D start = ((Point2DSerializationWrapper) map.get(KEY_START))
			.create();
	Point2D end = ((Point2DSerializationWrapper) map.get(KEY_END)).create();
	return new LinearGradientPaint(start, end, getFractions(), getColors(),
			getCycleMethod(), getColorSpace(), getTransform());
}
 
Example 28
Source Project: buffer_bci   Source File: PaintAlpha.java    License: 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 29
Source Project: jdk8u-jdk   Source File: BufferedPaints.java    License: 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 Project: seaglass   Source File: SeaGlassInternalShadowEffect.java    License: 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 31
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 32
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 33
Source Project: openjdk-8   Source File: BufferedPaints.java    License: 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 34
Source Project: openjdk-8-source   Source File: RenderTests.java    License: 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 35
/**
 * 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 36
Source Project: jdk8u-dev-jdk   Source File: BufferedPaints.java    License: 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 37
Source Project: buffer_bci   Source File: PaintAlpha.java    License: 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 38
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 39
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 40
Source Project: Bytecoder   Source File: BufferedPaints.java    License: 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;
        }
    }
}