Java Code Examples for java.awt.Color#getAlpha()

The following examples show how to use java.awt.Color#getAlpha() . 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: GradientXYBarPainter.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Paints a single bar instance.
 *
 * @param g2  the graphics target.
 * @param renderer  the renderer.
 * @param row  the row index.
 * @param column  the column index.
 * @param bar  the bar
 * @param base  indicates which side of the rectangle is the base of the
 *              bar.
 * @param pegShadow  peg the shadow to the base of the bar?
 */
@Override
public void paintBarShadow(Graphics2D g2, XYBarRenderer renderer, int row,
        int column, RectangularShape bar, RectangleEdge base,
        boolean pegShadow) {

    // handle a special case - if the bar colour has alpha == 0, it is
    // invisible so we shouldn't draw any shadow
    Paint itemPaint = renderer.getItemPaint(row, column);
    if (itemPaint instanceof Color) {
        Color c = (Color) itemPaint;
        if (c.getAlpha() == 0) {
            return;
        }
    }

    RectangularShape shadow = createShadow(bar, renderer.getShadowXOffset(),
            renderer.getShadowYOffset(), base, pegShadow);
    g2.setPaint(Color.gray);
    g2.fill(shadow);

}
 
Example 2
Source File: GradientXYBarPainter.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Paints a single bar instance.
 *
 * @param g2  the graphics target.
 * @param renderer  the renderer.
 * @param row  the row index.
 * @param column  the column index.
 * @param bar  the bar
 * @param base  indicates which side of the rectangle is the base of the
 *              bar.
 * @param pegShadow  peg the shadow to the base of the bar?
 */
@Override
public void paintBarShadow(Graphics2D g2, XYBarRenderer renderer, int row,
        int column, RectangularShape bar, RectangleEdge base,
        boolean pegShadow) {

    // handle a special case - if the bar colour has alpha == 0, it is
    // invisible so we shouldn't draw any shadow
    Paint itemPaint = renderer.getItemPaint(row, column);
    if (itemPaint instanceof Color) {
        Color c = (Color) itemPaint;
        if (c.getAlpha() == 0) {
            return;
        }
    }

    RectangularShape shadow = createShadow(bar, renderer.getShadowXOffset(),
            renderer.getShadowYOffset(), base, pegShadow);
    g2.setPaint(Color.gray);
    g2.fill(shadow);

}
 
Example 3
Source File: StandardBarPainter.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Paints a single bar instance.
 *
 * @param g2  the graphics target.
 * @param renderer  the renderer.
 * @param row  the row index.
 * @param column  the column index.
 * @param bar  the bar
 * @param base  indicates which side of the rectangle is the base of the
 *              bar.
 * @param pegShadow  peg the shadow to the base of the bar?
 */
public void paintBarShadow(Graphics2D g2, BarRenderer renderer, int row,
        int column, boolean selected, RectangularShape bar,
        RectangleEdge base, boolean pegShadow) {

    // handle a special case - if the bar colour has alpha == 0, it is
    // invisible so we shouldn't draw any shadow
    Paint itemPaint = renderer.getItemPaint(row, column, selected);
    if (itemPaint instanceof Color) {
        Color c = (Color) itemPaint;
        if (c.getAlpha() == 0) {
            return;
        }
    }

    RectangularShape shadow = createShadow(bar, renderer.getShadowXOffset(),
            renderer.getShadowYOffset(), base, pegShadow);
    g2.setPaint(renderer.getShadowPaint());
    g2.fill(shadow);

}
 
Example 4
Source File: StandardXYBarPainter.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Paints a single bar instance.
 *
 * @param g2  the graphics target.
 * @param renderer  the renderer.
 * @param row  the row index.
 * @param column  the column index.
 * @param bar  the bar
 * @param base  indicates which side of the rectangle is the base of the
 *              bar.
 * @param pegShadow  peg the shadow to the base of the bar?
 */
@Override
public void paintBarShadow(Graphics2D g2, XYBarRenderer renderer, int row,
        int column, RectangularShape bar, RectangleEdge base,
        boolean pegShadow) {

    // handle a special case - if the bar colour has alpha == 0, it is
    // invisible so we shouldn't draw any shadow
    Paint itemPaint = renderer.getItemPaint(row, column);
    if (itemPaint instanceof Color) {
        Color c = (Color) itemPaint;
        if (c.getAlpha() == 0) {
            return;
        }
    }

    RectangularShape shadow = createShadow(bar, renderer.getShadowXOffset(),
            renderer.getShadowYOffset(), base, pegShadow);
    g2.setPaint(Color.gray);
    g2.fill(shadow);

}
 
Example 5
Source File: NimbusLookAndFeel.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Derives the ARGB value for a color based on an offset between two
 * other colors.
 *
 * @param color1   The first color
 * @param color2   The second color
 * @param midPoint The offset between color 1 and color 2, a value of 0.0 is
 *                 color 1 and 1.0 is color 2;
 * @return the ARGB value for a new color based on this derivation
 */
static int deriveARGB(Color color1, Color color2, float midPoint) {
    int r = color1.getRed() +
            Math.round((color2.getRed() - color1.getRed()) * midPoint);
    int g = color1.getGreen() +
            Math.round((color2.getGreen() - color1.getGreen()) * midPoint);
    int b = color1.getBlue() +
            Math.round((color2.getBlue() - color1.getBlue()) * midPoint);
    int a = color1.getAlpha() +
            Math.round((color2.getAlpha() - color1.getAlpha()) * midPoint);
    return ((a & 0xFF) << 24) |
            ((r & 0xFF) << 16) |
            ((g & 0xFF) << 8) |
            (b & 0xFF);
}
 
Example 6
Source File: HexColorCellEditor.java    From niftyeditor with Apache License 2.0 5 votes vote down vote up
@Override
public void updateChooser() {
    Color color = getColorFromModel();
    if (color.getAlpha() != slider.getValue()) {
	slider.setValue(color.getAlpha());
    }
}
 
Example 7
Source File: TabbedPaneTabCloseButtonPainter.java    From seaglass with Apache License 2.0 5 votes vote down vote up
/**
 * Draw a border around the graphic.
 *
 * @param g      the Graphic context.
 * @param width  the width of the border.
 * @param height the height of the border.
 * @param color  the color of the border.
 * @param size   the spread of the border from outside in, expressed as a
 *               percentage of the height.
 */
private void drawBorder(Graphics2D g, int width, int height, Color color, float size) {
    int max        = (int) (Math.min((height - 2) * size, height / 2.0f) + 0.5);
    int alphaDelta = color.getAlpha() / max;

    for (int i = 0; i < max; i++) {
        Shape s        = shapeGenerator.createRoundRectangle(i, i, width - 2 * i - 1, height - 2 * i - 1, CornerSize.CHECKBOX_INTERIOR);
        Color newColor = new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha() - i * alphaDelta);

        g.setPaint(newColor);
        g.draw(s);
    }
}
 
Example 8
Source File: Colour4f.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Colour4f(Color src)
{
	this.r = (float)(src.getRed()) / 255.0f;
	this.g = (float)(src.getGreen()) / 255.0f;
	this.b = (float)(src.getBlue()) / 255.0f;
	this.a = (float)(src.getAlpha()) / 255.0f;
}
 
Example 9
Source File: JRPdfExporter.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void setStrokeColor(Color color)
{
	int alpha = color.getAlpha();
	if (alpha != 255)
	{
		setStrokeAlpha(alpha);
		strokeAlphaSet = true;
	}
	
	pdfContentByte.setRGBColorStroke(
			color.getRed(),
			color.getGreen(),
			color.getBlue());		
}
 
Example 10
Source File: AnimationManager.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * Tween between two colors.
 * 
 * @param c1
 * @param c2
 * @param f
 * @return
 */
public static final Color tween(Color c1, Color c2, double f) {
	if (f <= 0)
		return c1;
	if (f >= 1)
		return c2;
	int r = (int) (c1.getRed() * (1 - f) + f * c2.getRed());
	int g = (int) (c1.getGreen() * (1 - f) + f * c2.getGreen());
	int b = (int) (c1.getBlue() * (1 - f) + f * c2.getBlue());
	int a = (int) (c1.getAlpha() * (1 - f) + f * c2.getAlpha());
	return new Color(r, g, b, a);
}
 
Example 11
Source File: PaletteBuilder.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
protected void buildPalette() {
    reduceList = new ColorNode[MAXLEVEL + 1];
    for (int i = 0; i < reduceList.length; i++) {
        reduceList[i] = null;
    }

    numNodes = 0;
    maxNodes = 0;
    root = null;
    currSize = 0;
    currLevel = MAXLEVEL;

    /*
      from the book

    */

    int w = src.getWidth();
    int h = src.getHeight();
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {

            Color aColor = getSrcColor(w - x - 1, h - y - 1);
            /*
             * If transparency of given image is not opaque we assume all
             * colors with alpha less than 1.0 as fully transparent.
             */
            if (transparency != Transparency.OPAQUE &&
                aColor.getAlpha() != 0xff)
            {
                if (transColor == null) {
                    this.requiredSize --; // one slot for transparent color

                    transColor = new ColorNode();
                    transColor.isLeaf = true;
                }
                transColor = insertNode(transColor, aColor, 0);
            } else {
                root = insertNode(root, aColor, 0);
            }
            if (currSize > requiredSize) {
                reduceTree();
            }
        }
    }
}
 
Example 12
Source File: PixelsOperation.java    From MyBox with Apache License 2.0 4 votes vote down vote up
@Override
protected Color operateColor(Color color) {
    int v = Math.min(Math.max(intPara1, 0), 255);
    return new Color(v, color.getGreen(), v, color.getAlpha());
}
 
Example 13
Source File: PixelsOperation.java    From MyBox with Apache License 2.0 4 votes vote down vote up
@Override
protected Color operateColor(Color color) {
    return new Color(255 - color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
}
 
Example 14
Source File: PixelsOperation.java    From MyBox with Apache License 2.0 4 votes vote down vote up
@Override
protected Color operateColor(Color color) {
    return new Color(color.getRed(), Math.min(Math.max(intPara1, 0), 255),
            color.getBlue(), color.getAlpha());
}
 
Example 15
Source File: PaletteBuilder.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
protected void buildPalette() {
    reduceList = new ColorNode[MAXLEVEL + 1];
    for (int i = 0; i < reduceList.length; i++) {
        reduceList[i] = null;
    }

    numNodes = 0;
    maxNodes = 0;
    root = null;
    currSize = 0;
    currLevel = MAXLEVEL;

    /*
      from the book

    */

    int w = src.getWidth();
    int h = src.getHeight();
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {

            Color aColor = getSrcColor(w - x - 1, h - y - 1);
            /*
             * If transparency of given image is not opaque we assume all
             * colors with alpha less than 1.0 as fully transparent.
             */
            if (transparency != Transparency.OPAQUE &&
                aColor.getAlpha() != 0xff)
            {
                if (transColor == null) {
                    this.requiredSize --; // one slot for transparent color

                    transColor = new ColorNode();
                    transColor.isLeaf = true;
                }
                transColor = insertNode(transColor, aColor, 0);
            } else {
                root = insertNode(root, aColor, 0);
            }
            if (currSize > requiredSize) {
                reduceTree();
            }
        }
    }
}
 
Example 16
Source File: PaletteBuilder.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
protected void buildPalette() {
    reduceList = new ColorNode[MAXLEVEL + 1];
    for (int i = 0; i < reduceList.length; i++) {
        reduceList[i] = null;
    }

    numNodes = 0;
    maxNodes = 0;
    root = null;
    currSize = 0;
    currLevel = MAXLEVEL;

    /*
      from the book

    */

    int w = src.getWidth();
    int h = src.getHeight();
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {

            Color aColor = getSrcColor(w - x - 1, h - y - 1);
            /*
             * If transparency of given image is not opaque we assume all
             * colors with alpha less than 1.0 as fully transparent.
             */
            if (transparency != Transparency.OPAQUE &&
                aColor.getAlpha() != 0xff)
            {
                if (transColor == null) {
                    this.requiredSize --; // one slot for transparent color

                    transColor = new ColorNode();
                    transColor.isLeaf = true;
                }
                transColor = insertNode(transColor, aColor, 0);
            } else {
                root = insertNode(root, aColor, 0);
            }
            if (currSize > requiredSize) {
                reduceTree();
            }
        }
    }
}
 
Example 17
Source File: G2dRendererBase.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void drawArea( AreaRenderEvent are ) throws ChartException
{
	if ( iv != null )
	{
		iv.modifyEvent( are );
	}
	
	// CHECK IF THE LINE ATTRIBUTES ARE CORRECTLY DEFINED
	final LineAttributes lia = are.getOutline( );
	if ( !validateLineAttributes( are.getSource( ), lia ) )
	{
		return;
	}

	// SETUP THE FOREGROUND COLOR (DARKER BACKGROUND IF DEFINED AS NULL)
	final Color cFG = (Color) validateEdgeColor( lia.getColor( ),
			are.getBackground( ),
			_ids );
	// IF UNDEFINED OR TOTALLY TRANSPARENT, EXIT
	if ( cFG == null || cFG.getAlpha( ) == 0 )
	{
		return;
	}

	// BUILD THE GENERAL PATH STRUCTURE
	final GeneralPath gp = new GeneralPath( );
	PrimitiveRenderEvent pre;
	for ( int i = 0; i < are.getElementCount( ); i++ )
	{
		pre = are.getElement( i );
		if ( pre instanceof ArcRenderEvent )
		{
			final ArcRenderEvent acre = (ArcRenderEvent) pre;
			final Arc2D.Double a2d = new Arc2D.Double( acre.getTopLeft( )
					.getX( ),
					acre.getTopLeft( ).getY( ),
					acre.getWidth( ),
					acre.getHeight( ),
					acre.getStartAngle( ),
					acre.getAngleExtent( ),
					toG2dArcType( acre.getStyle( ) ) );
			gp.append( a2d, true );
		}
		else if ( pre instanceof LineRenderEvent )
		{
			final LineRenderEvent lre = (LineRenderEvent) pre;
			final Line2D.Double l2d = new Line2D.Double( lre.getStart( )
					.getX( ),
					lre.getStart( ).getY( ),
					lre.getEnd( ).getX( ),
					lre.getEnd( ).getY( ) );
			gp.append( l2d, true );
		}
	}

	// DRAW THE GENERAL PATH
	Stroke sPrevious = null;
	Stroke sCurrent = getCachedStroke( lia );
	if ( sCurrent != null ) // SOME STROKE DEFINED?
	{
		sPrevious = _g2d.getStroke( );
		_g2d.setStroke( sCurrent );
	}

	_g2d.setColor( cFG );
	_g2d.draw( gp );

	if ( sPrevious != null ) // RESTORE PREVIOUS STROKE
	{
		_g2d.setStroke( sPrevious );
	}
}
 
Example 18
Source File: PaletteBuilder.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
protected void buildPalette() {
    reduceList = new ColorNode[MAXLEVEL + 1];
    for (int i = 0; i < reduceList.length; i++) {
        reduceList[i] = null;
    }

    numNodes = 0;
    maxNodes = 0;
    root = null;
    currSize = 0;
    currLevel = MAXLEVEL;

    /*
      from the book

    */

    int w = src.getWidth();
    int h = src.getHeight();
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {

            Color aColor = getSrcColor(w - x - 1, h - y - 1);
            /*
             * If transparency of given image is not opaque we assume all
             * colors with alpha less than 1.0 as fully transparent.
             */
            if (transparency != Transparency.OPAQUE &&
                aColor.getAlpha() != 0xff)
            {
                if (transColor == null) {
                    this.requiredSize --; // one slot for transparent color

                    transColor = new ColorNode();
                    transColor.isLeaf = true;
                }
                transColor = insertNode(transColor, aColor, 0);
            } else {
                root = insertNode(root, aColor, 0);
            }
            if (currSize > requiredSize) {
                reduceTree();
            }
        }
    }
}
 
Example 19
Source File: ColorHelper.java    From openchemlib-js with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Creates a new <code>Color</code> that is a darker version of this
 * <code>Color</code>. This is a copy of Color.darker(), but lets you choose
 * the factor.
 * @param c the color to be darkened
 * @param factor value < 1.0; Color.darker() uses 0.7
 * @return  a new <code>Color</code> object that is
 *                    a darker version of this <code>Color</code>
 *                    with the same {@code alpha} value.
 */
public static Color darker(Color c, float factor) {
	return new Color(Math.max((int)(c.getRed()  *factor), 0),
					 Math.max((int)(c.getGreen()*factor), 0),
					 Math.max((int)(c.getBlue() *factor), 0),
					 c.getAlpha());
	}
 
Example 20
Source File: ColorRGB.java    From rapidminer-studio with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Converts a {@link Color} input to a {@link ColorRGB} object including the alpha value.
 * 
 * @param colorRGB
 * @return
 */
public static ColorRGB convertColorWithAlphaToColorRGB(Color color) {
	return new ColorRGB(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
}