Java 8 LinearGradientPaint - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 LinearGradientPaint class.

This code example shows how to use the following methods:
                fractions = parseFractions(str, parts[4].trim());
                colors = parseColors(str, parts[5].trim());
                if (fractions.length != colors.length) {
                    throw illegalValue(str, LinearGradientPaint.class);
                } 
                super.setValueInternal(new LinearGradientPaint(x1, y1, x2, y2, fractions, colors, cyclicMethod));
                break; 
            default: 
                throw illegalValue(str, LinearGradientPaint.class);
        } 
    } 
 
    private void handleAsList(List<?> list) {
        if(list.isEmpty()) {
            super.setValueInternal(null); 
            return; 
        } 
 
        float x1 = 0;
        float y1 = 0;
5
CodeRank
This code example shows how to use the following methods:
This code example shows how to use the following methods:
 
  static JavaGradient createLinear(float x0, float y0, float x1, float y1, float[] positions, int[] colors) {
    Point2D.Float start = new Point2D.Float(x0, y0);
    Point2D.Float end = new Point2D.Float(x1, y1);
    Color[] javaColors = convertColors(colors);
    LinearGradientPaint p = new LinearGradientPaint(start, end, positions, javaColors);
    return new JavaGradient(p);
  } 
 
  static JavaGradient createRadial(float x, float y, float r, float[] positions, int[] colors) {
    Point2D.Float center = new Point2D.Float(x, y);
    RadialGradientPaint p = new RadialGradientPaint(center, r, positions, convertColors(colors));
    return new JavaGradient(p);
  } 
 
  private static Color[] convertColors(int[] colors) {
    Color[] javaColors = new Color[colors.length];
    for (int i = 0; i < colors.length; ++i) {
      javaColors[i] = new Color(colors[i], true);
    } 
5
CodeRank
This code example shows how to use the following methods:getColors, getFractions
This code example shows how to use the following methods:getColors, getFractions
 
	} 
	 
	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());
		} 
	} 
} 
4
CodeRank
This code example shows how to use the following methods:
                          Color.yellow,
                          Color.blue,
                          Color.green},
            CycleMethod.REFLECT);
    LinearGradientPaint lgp =
            new LinearGradientPaint(30, 30, 120, 130, new float[] {0f, 0.2f, 0.6f, 1f},
            new Color[] {Color.red,
                         Color.yellow,
                         Color.blue,
                         Color.green});
    GradientPaint gp =
            new GradientPaint(30, 30, Color.red, 120, 130, Color.yellow, true);
 
    TexturePaint tp =
            new TexturePaint(bi, new Rectangle2D.Float(30, 30, 120, 130));
 
 
    public AccelPaintsTest() { 
        Graphics g = bi.getGraphics();
        g.setColor(Color.blue);
4
CodeRank
This code example shows how to use the following methods:
                          Color.yellow,
                          Color.blue,
                          Color.green},
            CycleMethod.REFLECT);
    LinearGradientPaint lgp =
            new LinearGradientPaint(30, 30, 120, 130, new float[] {0f, 0.2f, 0.6f, 1f},
            new Color[] {Color.red,
                         Color.yellow,
                         Color.blue,
                         Color.green});
    GradientPaint gp =
            new GradientPaint(30, 30, Color.red, 120, 130, Color.yellow, true);
 
    TexturePaint tp =
            new TexturePaint(bi, new Rectangle2D.Float(30, 30, 120, 130));
 
 
    public AccelPaintsTest() { 
        Graphics g = bi.getGraphics();
        g.setColor(Color.blue);
4
CodeRank
This code example shows how to use the following methods:
    protected final LinearGradientPaint createGradient(float x1, float y1, float x2, float y2, float[] midpoints, Color[] colors) {
        if (x1 == x2 && y1 == y2) {
            y2 += .00001f;
        } 
 
        return new LinearGradientPaint(x1, y1, x2, y2, midpoints, colors);
    } 
 
    protected final boolean testValid(int x, int y, int w, int h) {
        return x >= 0 && y >= 0 && (w - x) > 0 && (h - y) > 0;
    } 
 
    protected final Image getImage(String name) {
        String imagePath = IMAGES_PATH + name + ".png";
        try { 
            return ImageIO.read(ClassLoader.getSystemResource(imagePath));
        } catch (Throwable e) {
            throw new RuntimeException("Error loading skin image: " + imagePath, e);
        } 
    } 
4
CodeRank
This code example shows how to use the following methods:
        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;
    } 
 
    public BufferedImage createOnImage(final int WIDTH, final int HEIGHT, final Color GLOW_COLOR) {
        final GraphicsConfiguration GFX_CONF = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
        if (WIDTH <= 0 || HEIGHT <= 0) {
4
CodeRank
This code example shows how to use the following methods:
            width += 1;
        } 
        g.setColor(new Color(borderColor, true));
        g.drawRect(x, y, width - 1, height - 1);
 
        LinearGradientPaint lgp = new LinearGradientPaint(
                new Point2D.Float(x, y), new Point2D.Float(x, y + height - 1),
                stops, stopColors,
                MultipleGradientPaint.CycleMethod.REPEAT);
        g.setPaint(lgp);
        g.fillRect(x + 1, y + 1, width - 2, height - 2);
    } 
 
    private String getSegmentPosition(Component c) {
        String segmentPosition = null;
        if (c instanceof JComponent) {
        segmentPosition = (String) ((JComponent) c).getClientProperty("Palette.Component.segmentPosition");
        } 
        return (segmentPosition == null) ? "only" : segmentPosition;
    } 
4
CodeRank
See Code Examples for Java 8 LinearGradientPaint Methods: