java.awt.MultipleGradientPaint.CycleMethod Java Examples

The following examples show how to use java.awt.MultipleGradientPaint.CycleMethod. 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 dragonwell8_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 #2
Source File: MultiGradientTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();

    if (source == cmbPaint) {
        paintType = (PaintType)cmbPaint.getSelectedItem();
    } else if (source == cmbCycle) {
        cycleMethod = (CycleMethod)cmbCycle.getSelectedItem();
    } else if (source == cmbSpace) {
        colorSpace = (ColorSpaceType)cmbSpace.getSelectedItem();
    } else if (source == cmbShape) {
        shapeType = (ShapeType)cmbShape.getSelectedItem();
    } else if (source == cmbXform) {
        xformType = (XformType)cmbXform.getSelectedItem();
    } else if (source == cbAntialias) {
        antialiasHint = cbAntialias.isSelected() ?
            RenderingHints.VALUE_ANTIALIAS_ON :
            RenderingHints.VALUE_ANTIALIAS_OFF;
    } else if (source == cbRender) {
        renderHint = cbRender.isSelected() ?
            RenderingHints.VALUE_RENDER_QUALITY :
            RenderingHints.VALUE_RENDER_SPEED;
    }

    gradientPanel.updatePaint();
}
 
Example #3
Source File: D3DPaints.java    From jdk8u60 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 #4
Source File: MultiGradientTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();

    if (source == cmbPaint) {
        paintType = (PaintType)cmbPaint.getSelectedItem();
    } else if (source == cmbCycle) {
        cycleMethod = (CycleMethod)cmbCycle.getSelectedItem();
    } else if (source == cmbSpace) {
        colorSpace = (ColorSpaceType)cmbSpace.getSelectedItem();
    } else if (source == cmbShape) {
        shapeType = (ShapeType)cmbShape.getSelectedItem();
    } else if (source == cmbXform) {
        xformType = (XformType)cmbXform.getSelectedItem();
    } else if (source == cbAntialias) {
        antialiasHint = cbAntialias.isSelected() ?
            RenderingHints.VALUE_ANTIALIAS_ON :
            RenderingHints.VALUE_ANTIALIAS_OFF;
    } else if (source == cbRender) {
        renderHint = cbRender.isSelected() ?
            RenderingHints.VALUE_RENDER_QUALITY :
            RenderingHints.VALUE_RENDER_SPEED;
    }

    gradientPanel.updatePaint();
}
 
Example #5
Source File: AngleGradientPaint.java    From Pixelitor with GNU General Public License v3.0 6 votes vote down vote up
private AngleGradientPaintContext(ImDrag imDrag,
                                  Color startColor, Color endColor,
                                  ColorModel cm, CycleMethod cycleMethod) {
    this.imDrag = imDrag;
    this.cycleMethod = cycleMethod;

    startAlpha = startColor.getAlpha();
    startRed = startColor.getRed();
    startGreen = startColor.getGreen();
    startBlue = startColor.getBlue();

    endAlpha = endColor.getAlpha();
    endRed = endColor.getRed();
    endGreen = endColor.getGreen();
    endBlue = endColor.getBlue();

    this.cm = cm;
    drawAngle = imDrag.getDrawAngle();
}
 
Example #6
Source File: D3DPaints.java    From TencentKona-8 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 #7
Source File: MultiGradientTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();

    if (source == cmbPaint) {
        paintType = (PaintType)cmbPaint.getSelectedItem();
    } else if (source == cmbCycle) {
        cycleMethod = (CycleMethod)cmbCycle.getSelectedItem();
    } else if (source == cmbSpace) {
        colorSpace = (ColorSpaceType)cmbSpace.getSelectedItem();
    } else if (source == cmbShape) {
        shapeType = (ShapeType)cmbShape.getSelectedItem();
    } else if (source == cmbXform) {
        xformType = (XformType)cmbXform.getSelectedItem();
    } else if (source == cbAntialias) {
        antialiasHint = cbAntialias.isSelected() ?
            RenderingHints.VALUE_ANTIALIAS_ON :
            RenderingHints.VALUE_ANTIALIAS_OFF;
    } else if (source == cbRender) {
        renderHint = cbRender.isSelected() ?
            RenderingHints.VALUE_RENDER_QUALITY :
            RenderingHints.VALUE_RENDER_SPEED;
    }

    gradientPanel.updatePaint();
}
 
Example #8
Source File: D3DPaints.java    From jdk8u-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 #9
Source File: ArcDecorationPainter.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Paints the background of non-title decoration areas.
 * 
 * @param graphics
 *            Graphics context.
 * @param parent
 *            Component ancestor for computing the correct offset of the background painting.
 * @param comp
 *            Component.
 * @param width
 *            Width.
 * @param height
 *            Height.
 * @param scheme
 *            Color scheme for painting the title background.
 */
private void paintExtraBackground(Graphics2D graphics, Container parent, Component comp,
        int width, int height, SubstanceColorScheme scheme) {
    Point offset = SubstanceCoreUtilities.getOffsetInRootPaneCoords(comp);
    JRootPane rootPane = SwingUtilities.getRootPane(parent);
    // fix for bug 234 - Window doesn't have a root pane.
    JLayeredPane layeredPane = rootPane.getLayeredPane();
    Insets layeredPaneInsets = (layeredPane != null) ? layeredPane.getInsets() : null;

    int pWidth = (layeredPane == null) ? parent.getWidth()
            : layeredPane.getWidth() - layeredPaneInsets.left - layeredPaneInsets.right;

    if (pWidth != 0) {
        LinearGradientPaint gradientBottom = new LinearGradientPaint(-offset.x, 0,
                -offset.x + pWidth, 0, new float[] { 0.0f, 0.5f, 1.0f },
                new Color[] { scheme.getMidColor(), scheme.getLightColor(),
                                scheme.getMidColor() },
                CycleMethod.REPEAT);
        Graphics2D g2d = (Graphics2D) graphics.create();
        g2d.setPaint(gradientBottom);
        g2d.fillRect(-offset.x, 0, pWidth, height);
        g2d.dispose();
    }
}
 
Example #10
Source File: ArcDecorationPainter.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void paintDecorationArea(Graphics2D graphics, Component comp, DecorationAreaType
        decorationAreaType, Shape contour, SubstanceColorScheme colorScheme) {
    Component parent = SubstanceCoreUtilities.getHeaderParent(comp);
    Point offset = SubstanceCoreUtilities.getOffsetInRootPaneCoords(comp);
    JRootPane rootPane = SwingUtilities.getRootPane(parent);
    // fix for bug 234 - Window doesn't have a root pane.
    JLayeredPane layeredPane = rootPane.getLayeredPane();
    Insets layeredPaneInsets = (layeredPane != null) ? layeredPane.getInsets() : null;

    int pWidth = (layeredPane == null) ? parent.getWidth()
            : layeredPane.getWidth() - layeredPaneInsets.left - layeredPaneInsets.right;

    if (pWidth != 0) {
        LinearGradientPaint gradientBottom = new LinearGradientPaint(-offset.x, 0,
                -offset.x + pWidth, 0, new float[] { 0.0f, 0.5f, 1.0f },
                new Color[] { colorScheme.getMidColor(), colorScheme.getLightColor(),
                        colorScheme.getMidColor() },
                CycleMethod.REPEAT);
        Graphics2D g2d = (Graphics2D) graphics.create();
        g2d.setPaint(gradientBottom);
        g2d.fill(contour);
        g2d.dispose();
    }
}
 
Example #11
Source File: D3DPaints.java    From openjdk-jdk8u-backup 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 #12
Source File: MultiGradientTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();

    if (source == cmbPaint) {
        paintType = (PaintType)cmbPaint.getSelectedItem();
    } else if (source == cmbCycle) {
        cycleMethod = (CycleMethod)cmbCycle.getSelectedItem();
    } else if (source == cmbSpace) {
        colorSpace = (ColorSpaceType)cmbSpace.getSelectedItem();
    } else if (source == cmbShape) {
        shapeType = (ShapeType)cmbShape.getSelectedItem();
    } else if (source == cmbXform) {
        xformType = (XformType)cmbXform.getSelectedItem();
    } else if (source == cbAntialias) {
        antialiasHint = cbAntialias.isSelected() ?
            RenderingHints.VALUE_ANTIALIAS_ON :
            RenderingHints.VALUE_ANTIALIAS_OFF;
    } else if (source == cbRender) {
        renderHint = cbRender.isSelected() ?
            RenderingHints.VALUE_RENDER_QUALITY :
            RenderingHints.VALUE_RENDER_SPEED;
    }

    gradientPanel.updatePaint();
}
 
Example #13
Source File: GradientPaints.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void testOne(BufferedImage refImg, VolatileImage testImg) {
    Graphics2D gref  = refImg.createGraphics();
    Graphics2D gtest = testImg.createGraphics();
    Paint paint =
        makePaint(PaintType.RADIAL, CycleMethod.REPEAT,
                  ColorSpaceType.SRGB, XformType.IDENTITY, 7);
    Object aahint = hints[0];
    renderTest(gref,  paint, aahint);
    renderTest(gtest, paint, aahint);
    Toolkit.getDefaultToolkit().sync();
    compareImages(refImg, testImg.getSnapshot(),
                  TOLERANCE, 0, "");
    gref.dispose();
    gtest.dispose();
}
 
Example #14
Source File: RenderTests.java    From jdk8u60 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 #15
Source File: PlayerCharacterVisionPainter.java    From WorldGrower with GNU General Public License v3.0 5 votes vote down vote up
private BufferedImage createPlayerVisionImage(int circleRadius) {
	float circleDiameter = circleRadius * 2.0f;
	Shape circle = new Ellipse2D.Float(0, 0, circleDiameter, circleDiameter);
	BufferedImage image = new BufferedImage((int)circleDiameter, (int)circleDiameter, BufferedImage.TYPE_INT_ARGB);
	
	Graphics2D ga = (Graphics2D) image.createGraphics();
	
	Point2D center = new Point2D.Float(circleRadius, circleRadius);
    Point2D focus = new Point2D.Float(circleRadius, circleRadius);
    float[] dist = {0.0f, 0.70f, 0.95f};
    Color transparentBlack = new Color(0, 0, 0, 0);
	Color[] colors = {transparentBlack, transparentBlack, Color.BLACK};
    RadialGradientPaint p =
        new RadialGradientPaint(center, circleRadius, focus,
                                 dist, colors,
                                 CycleMethod.NO_CYCLE);
    
    ga.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    ga.setPaint(p);
	
	ga.fill(circle);
	ga.setStroke(new BasicStroke(2));
	ga.draw(circle);
	
	ga.dispose();
	
	return image;
}
 
Example #16
Source File: OGLPaints.java    From openjdk-jdk9 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 #17
Source File: RenderTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private RadialGradientPaint makeRadial(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 RadialGradientPaint(0.0f, 0.0f, 10.0f,
                                   fractions, colors,
                                   CycleMethod.REFLECT);
}
 
Example #18
Source File: TransformedPaintTest.java    From jdk8u-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 #19
Source File: RenderTests.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private RadialGradientPaint makeRadial(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 RadialGradientPaint(0.0f, 0.0f, 10.0f,
                                   fractions, colors,
                                   CycleMethod.REFLECT);
}
 
Example #20
Source File: GradientPaints.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void testOne(BufferedImage refImg, VolatileImage testImg) {
    Graphics2D gref  = refImg.createGraphics();
    Graphics2D gtest = testImg.createGraphics();
    Paint paint =
        makePaint(PaintType.RADIAL, CycleMethod.REPEAT,
                  ColorSpaceType.SRGB, XformType.IDENTITY, 7);
    Object aahint = hints[0];
    renderTest(gref,  paint, aahint);
    renderTest(gtest, paint, aahint);
    Toolkit.getDefaultToolkit().sync();
    compareImages(refImg, testImg.getSnapshot(),
                  TOLERANCE, 0, "");
    gref.dispose();
    gtest.dispose();
}
 
Example #21
Source File: TransformedPaintTest.java    From openjdk-jdk8u 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 #22
Source File: GradientTool.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
private static CycleMethod getCycleMethodFromString(String s) {
    switch (s) {
        case NO_CYCLE_AS_STRING:
            return NO_CYCLE;
        case REFLECT_AS_STRING:
            return REFLECT;
        case REPEAT_AS_STRING:
            return REPEAT;
    }
    throw new IllegalStateException("should not get here");
}
 
Example #23
Source File: GradientPaints.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void testOne(BufferedImage refImg, VolatileImage testImg) {
    Graphics2D gref  = refImg.createGraphics();
    Graphics2D gtest = testImg.createGraphics();
    Paint paint =
        makePaint(PaintType.RADIAL, CycleMethod.REPEAT,
                  ColorSpaceType.SRGB, XformType.IDENTITY, 7);
    Object aahint = hints[0];
    renderTest(gref,  paint, aahint);
    renderTest(gtest, paint, aahint);
    Toolkit.getDefaultToolkit().sync();
    compareImages(refImg, testImg.getSnapshot(),
                  TOLERANCE, 0, "");
    gref.dispose();
    gtest.dispose();
}
 
Example #24
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 #25
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 #26
Source File: RenderTests.java    From jdk8u_jdk 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 #27
Source File: FractionBasedBorderPainter.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void paintBorder(Graphics g, Component c, float width, float height, Shape contour,
		Shape innerContour, SubstanceColorScheme borderScheme) {
	if (contour == null)
		return;

	Graphics2D graphics = (Graphics2D) g.create();
	graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_ON);
	graphics.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
			RenderingHints.VALUE_STROKE_PURE);

	Color[] drawColors = new Color[this.fractions.length];
	for (int i = 0; i < this.fractions.length; i++) {
		ColorSchemeSingleColorQuery colorQuery = this.colorQueries[i];
		drawColors[i] = colorQuery.query(borderScheme);
	}

	// System.out.println("\t" + interpolationScheme1.getDisplayName()
	// + " -> [" + cyclePos + "] "
	// + interpolationScheme2.getDisplayName());

	float strokeWidth = SubstanceSizeUtils.getBorderStrokeWidth();
	// issue 433 - the "c" can be null when painting
	// the border of a tree icon used outside the
	// JTree context.
	boolean isSpecialButton = (c != null) && c.getClass()
			.isAnnotationPresent(SubstanceInternalArrowButton.class);
	int joinKind = isSpecialButton ? BasicStroke.JOIN_MITER : BasicStroke.JOIN_ROUND;
	int capKind = isSpecialButton ? BasicStroke.CAP_SQUARE : BasicStroke.CAP_BUTT;
	graphics.setStroke(new BasicStroke(strokeWidth, capKind, joinKind));

	MultipleGradientPaint gradient = new LinearGradientPaint(0, 0, 0, height, this.fractions,
			drawColors, CycleMethod.REPEAT);
	graphics.setPaint(gradient);
	graphics.draw(contour);
	graphics.dispose();
}
 
Example #28
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 #29
Source File: RenderTests.java    From openjdk-8 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 #30
Source File: RenderTests.java    From openjdk-jdk8u 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);
}