Java Code Examples for java.awt.LinearGradientPaint

The following are top voted examples for showing how to use java.awt.LinearGradientPaint. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: mars-sim   File: DigitalRadial.java   Source Code and License 7 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 2
Project: Lernkartei_2017   File: Push.java   Source Code and License 6 votes vote down vote up
public Push() {
  setUndecorated(true);
  setSize(300, 100);
  this.setAlwaysOnTop(true);

  // size of the screen
  final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

  // height of the task bar
  final Insets scnMax = Toolkit.getDefaultToolkit().getScreenInsets(
      getGraphicsConfiguration());
  final int taskBarSize = scnMax.bottom;

  setLocation(screenSize.width - getWidth(), screenSize.height - taskBarSize
      - getHeight());

  // background paint
  lpg = new LinearGradientPaint(0, 0, 0, getHeight() / 2, new float[] { 0f,
      0.3f, 1f }, new Color[] { new Color(0.8f, 0.8f, 1f),
      new Color(0.7f, 0.7f, 1f), new Color(0.6f, 0.6f, 1f) });

  // blue background panel
  setContentPane(new BackgroundPanel());
}
 
Example 3
Project: incubator-netbeans   File: RowForegroundDecorator.java   Source Code and License 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 4
Project: rapidminer   File: DynamicIconUrlStreamHandler.java   Source Code and License 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 5
Project: OpenJSharp   File: D3DPaints.java   Source Code and License 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
Project: jdk8u-jdk   File: D3DPaints.java   Source Code and License 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
Project: openjdk-jdk10   File: D3DPaints.java   Source Code and License 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
Project: openjdk9   File: D3DPaints.java   Source Code and License 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
Project: Lernkartei   File: Push.java   Source Code and License 6 votes vote down vote up
public Push() {
  setUndecorated(true);
  setSize(300, 100);
  this.setAlwaysOnTop(true);

  // size of the screen
  final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

  // height of the task bar
  final Insets scnMax = Toolkit.getDefaultToolkit().getScreenInsets(
      getGraphicsConfiguration());
  final int taskBarSize = scnMax.bottom;

  setLocation(screenSize.width - getWidth(), screenSize.height - taskBarSize
      - getHeight());

  // background paint
  lpg = new LinearGradientPaint(0, 0, 0, getHeight() / 2, new float[] { 0f,
      0.3f, 1f }, new Color[] { new Color(0.8f, 0.8f, 1f),
      new Color(0.7f, 0.7f, 1f), new Color(0.6f, 0.6f, 1f) });

  // blue background panel
  setContentPane(new BackgroundPanel());
}
 
Example 10
Project: jdk8u_jdk   File: D3DPaints.java   Source Code and License 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 11
Project: lookaside_java-1.8.0-openjdk   File: D3DPaints.java   Source Code and License 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
Project: rapidminer-studio   File: DynamicIconUrlStreamHandler.java   Source Code and License 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 13
Project: mars-sim   File: DigitalRadial.java   Source Code and License 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 14
Project: mars-sim   File: WindDirection.java   Source Code and License 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 15
Project: mars-sim   File: DisplayMulti.java   Source Code and License 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 16
Project: mars-sim   File: RadialBargraph.java   Source Code and License 6 votes vote down vote up
@Override
public java.awt.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 17
Project: mars-sim   File: DisplaySingle.java   Source Code and License 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 18
Project: mars-sim   File: Radial.java   Source Code and License 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 19
Project: mars-sim   File: RadialCounter.java   Source Code and License 6 votes vote down vote up
@Override
public java.awt.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 20
Project: mars-sim   File: LinearBargraph.java   Source Code and License 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 21
Project: mars-sim   File: DigitialRadial.java   Source Code and License 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 22
Project: mars-sim   File: DisplayCircular.java   Source Code and License 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 23
Project: mgoban   File: WoodTexture.java   Source Code and License 6 votes vote down vote up
private WoodTexture() {
    Color c0 = new Color(231, 190, 106);
    Color c1 = new Color(232, 185, 96);
    Color c2 = new Color(216, 168, 82);
    
    Point2D start = new Point2D.Float(0, 0);
    Point2D end = new Point2D.Float(100, 10);
    float[] dist = {0.0f, 0.6f, 1.0f};
    Color[] colors = {c0, c1, c2};
    LinearGradientPaint p = new LinearGradientPaint(start, end, dist, colors);
    
    texture = new BufferedImage(100, 10, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = texture.createGraphics();
    
    g.setPaint(p);
    g.fill(new Rectangle2D.Double(0, 0, 100, 10));
    
}
 
Example 24
Project: swingx   File: PaintPicker.java   Source Code and License 6 votes vote down vote up
/**
 * Creates a flat version of the current gradient. This is a linear gradient
 * from 0.0 to length,0. This gradient is suitable for drawing previews of
 * the real gradient.
 *
 * @param length
 * @return a gradient Paint with values between 0.0 and length
 */
private MultipleGradientPaint getFlatGradient(JXGradientChooser chooser, double length) {
    MultipleGradientPaint gp = chooser.getGradient();

    // set up the data for the gradient
    float[] fractions = gp.getFractions();
    Color[] colors = gp.getColors();

    // fill in the gradient
    Point2D start = new Point2D.Float(0, 0);
    Point2D end = new Point2D.Float((float) length, 0);
    MultipleGradientPaint paint = new LinearGradientPaint(
            (float) start.getX(),
            (float) start.getY(),
            (float) end.getX(),
            (float) end.getY(),
            fractions, colors);
    return paint;
}
 
Example 25
Project: ExportImageSOI   File: ColorMapper.java   Source Code and License 6 votes vote down vote up
private BufferedImage createGradientImage(Color... colors)
{
    final float[] fractions = new float[colors.length];

    final float step = 1.0F / colors.length;

    for (int i = 0; i < colors.length; i++)
    {
        fractions[i] = i * step;
    }

    final LinearGradientPaint gradient = new LinearGradientPaint(0, 0, 256, 1, fractions, colors, MultipleGradientPaint.CycleMethod.REPEAT);
    final BufferedImage bi = new BufferedImage(256, 1, BufferedImage.TYPE_INT_ARGB);
    final Graphics2D g = bi.createGraphics();
    try
    {
        g.setPaint(gradient);
        g.fillRect(0, 0, 256, 1);
    }
    finally
    {
        g.dispose();
    }
    return bi;
}
 
Example 26
Project: infobip-open-jdk-8   File: D3DPaints.java   Source Code and License 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 27
Project: jdk8u-dev-jdk   File: D3DPaints.java   Source Code and License 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 28
Project: raccoon4   File: TitleStrip.java   Source Code and License 6 votes vote down vote up
@Override
protected void paintComponent(Graphics graphics) {
	super.paintComponent(graphics);
	Graphics2D g2d = (Graphics2D) graphics;
	g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_ON);
	Point2D start = new Point2D.Float(0, 0);
	Point2D end = new Point2D.Float(0, getHeight());
	float[] dist = { 0.0f, 0.8f, .95f, 1f };
	Color bg = getBackground();
	Color bgd = getBackground().darker();
	Color[] colors = { bgd, bg, bgd, bgd.darker() };
	LinearGradientPaint gp1 = new LinearGradientPaint(start, end, dist, colors);
	g2d.setPaint(gp1);
	g2d.fillRect(0, 0, getWidth(), getHeight());
}
 
Example 29
Project: jhc   File: JHCGradient.java   Source Code and License 6 votes vote down vote up
/**
 * Gets the gradient.
 * 
 * @param colors the colors
 * @param steps the steps
 * @return the gradient
 */
private int[] getGradient(Color[] colors, int steps) {

    // Draw the gradient to a buffered image
    Point2D start = new Point2D.Float(0, 0);
    Point2D end = new Point2D.Float(1, steps);
    float[] dist = new float[colors.length];
    for (int i = 0; i < dist.length; i++) {
        dist[i] = (1.0f / dist.length) * i;
    }
    LinearGradientPaint p = new LinearGradientPaint(start, end, dist, colors);
    BufferedImage legend = new BufferedImage(1, steps, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = (Graphics2D) legend.getGraphics();
    g2d.setPaint(p);
    g2d.drawRect(0, 0, 1, steps);
    g2d.dispose();

    // Convert to color array
    int[] result = new int[steps];
    for (int y = 0; y < steps; y++) {
        result[y] = legend.getRGB(0, y);
    }

    // Return
    return result;
}
 
Example 30
Project: jdk7-jdk   File: D3DPaints.java   Source Code and License 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 31
Project: openjdk-source-code-learn   File: D3DPaints.java   Source Code and License 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 32
Project: OLD-OpenJDK8   File: D3DPaints.java   Source Code and License 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 33
Project: game-client   File: ServerListEntry.java   Source Code and License 6 votes vote down vote up
public Gui getGui() {
return new Gui() {

    @Override
    public void render(Graphics2D g2d, int width, int height) {
	LinearGradientPaint gradient = new LinearGradientPaint(0, 0, 0, 100, new float[]{0,1}, new Color[]{new Color(0x666666),new Color(0x444444)});
	g2d.setPaint(gradient);
	g2d.fillRect(0, 0, width, 100);
	g2d.setColor(new Color(0x666666));
	g2d.fillRect(0, 100, width, height - 100);
	g2d.setColor(Color.WHITE);
	g2d.setFont(Client.instance.translation.font.deriveFont(Font.BOLD, 35F));
	g2d.drawString(name, 50, 50);
	g2d.setFont(Client.instance.translation.font.deriveFont(Font.BOLD, 18F));
	g2d.setColor(Color.GRAY);
	g2d.drawString(ip, 50, 75);
	if(ping >= 0) {
	    if(ping == 0)
		g2d.setColor(Color.RED.darker());
	    g2d.drawString(ping == 0 ? Client.instance.translation.translate("protocol.timeout") : ping + "ms", 50, 95);
	}
    }
    
};
   }
 
Example 34
Project: openjdk-jdk7u-jdk   File: D3DPaints.java   Source Code and License 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 35
Project: org.dayflower   File: ProgressUpdateFutureImpl.java   Source Code and License 6 votes vote down vote up
private void doPaintBackground(Graphics2D graphics2D, int x, int y, int width, int height) {
	Color color = Colors.darker(Color.decode("#006699"), 64, 64, 64);
	
	graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	
	Paint paint = graphics2D.getPaint();
	
	float startX = x;
	float startY = y;
	float endX = x;
	float endY = y + height - 1;
	
	Color[] colors = new Color[4];
	
	colors[0] = Colors.brighter(color, 32, 32, 32);
	colors[1] = Colors.darker(color, 16, 16, 16);
	colors[2] = Colors.darker(color, 16, 16, 16);
	colors[3] = Colors.darker(color, 16, 16, 16);
	
	graphics2D.setPaint(new LinearGradientPaint(startX, startY, endX, endY, fractions, colors));
	graphics2D.fillRoundRect(x, y, width - 1, height - 1, 2, 2);
	graphics2D.setColor(Colors.brighter(color, 32, 32, 32));
	graphics2D.setStroke(stroke);
	graphics2D.drawRoundRect(x, y, width - 1, height - 1, 2, 2);
	graphics2D.setPaint(paint);
}
 
Example 36
Project: org.dayflower   File: Java2DGame.java   Source Code and License 6 votes vote down vote up
private void doPaintBackground(Graphics2D graphics2D, int x, int y, int width, int height) {
	Color color = Colors.darker(Color.decode("#006699"), 64, 64, 64);
	
	graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	
	Paint paint = graphics2D.getPaint();
	
	float startX = x;
	float startY = y;
	float endX = x;
	float endY = y + height - 1;
	
	Color[] colors = new Color[4];
	
	colors[0] = Colors.brighter(color, 32, 32, 32);
	colors[1] = Colors.darker(color, 16, 16, 16);
	colors[2] = Colors.darker(color, 16, 16, 16);
	colors[3] = Colors.darker(color, 16, 16, 16);
	
	graphics2D.setPaint(new LinearGradientPaint(startX, startY, endX, endY, fractions, colors));
	graphics2D.fillRoundRect(x, y, width - 1, height - 1, 2, 2);
	graphics2D.setColor(Colors.brighter(color, 32, 32, 32));
	graphics2D.setStroke(stroke);
	graphics2D.drawRoundRect(x, y, width - 1, height - 1, 2, 2);
	graphics2D.setPaint(paint);
}
 
Example 37
Project: openjdk-icedtea7   File: D3DPaints.java   Source Code and License 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 38
Project: griffon2   File: LinearGradientPaintPropertyEditor.java   Source Code and License 6 votes vote down vote up
public String getAsText() {
    if (null == getValue()) return null;
    LinearGradientPaint p = (LinearGradientPaint) getValue();
    return new StringBuilder()
        .append(p.getStartPoint().getX())
        .append(", ")
        .append(p.getStartPoint().getY())
        .append(", ")
        .append(p.getEndPoint().getX())
        .append(", ")
        .append(p.getEndPoint().getY())
        .append(", ")
        .append(formatFractions(p.getFractions()))
        .append(", ")
        .append(formatColors(p.getColors()))
        .append(", ")
        .append(p.getCycleMethod().name())
        .toString();
}
 
Example 39
Project: griffon2   File: LinearGradientPaintPropertyEditor.java   Source Code and License 6 votes vote down vote up
private void handleAsMap(Map<?, ?> map) {
    if(map.isEmpty()) {
        super.setValueInternal(null);
        return;
    }

    float x1 = (Float) getMapValue(map, "x1", 0f);
    float y1 = (Float) getMapValue(map, "y1", 0f);
    float x2 = (Float) getMapValue(map, "x2", 0f);
    float y2 = (Float) getMapValue(map, "y2", 0f);
    MultipleGradientPaint.CycleMethod cyclicMethod = MultipleGradientPaint.CycleMethod.NO_CYCLE;

    float[] fractions = parseFractions(map, map.get("fractions"));
    Color[] colors = parseColors(map, map.get("colors"));
    if (fractions.length != colors.length) {
        throw illegalValue(map, LinearGradientPaint.class);
    }
    Object cyclicValue = map.get("cycle");
    if (null != cyclicValue) {
        cyclicMethod = parseCyclicMethod(map, String.valueOf(cyclicValue));
    }

    super.setValueInternal(new LinearGradientPaint(x1, y1, x2, y2, fractions, colors, cyclicMethod));
}
 
Example 40
Project: griffon2   File: LinearGradientPaintPropertyEditor.java   Source Code and License 6 votes vote down vote up
private Color[] parseColors(Object source, String str) {
    if (!str.startsWith("[") || !str.endsWith("]")) {
        throw illegalValue(source, LinearGradientPaint.class);
    }

    String[] strs = str.substring(1, str.length() - 1).split(":");
    Color[] colors = new Color[strs.length];
    ColorPropertyEditor colorEditor = new ColorPropertyEditor();
    for (int i = 0; i < strs.length; i++) {
        try {
            colorEditor.setValueInternal(strs[i]);
            colors[i] = (Color) colorEditor.getValue();
        } catch (Exception e) {
            throw illegalValue(strs[i], LinearGradientPaint.class);
        }
    }

    return colors;
}