Example usage for java.awt Color getAlpha

List of usage examples for java.awt Color getAlpha

Introduction

In this page you can find the example usage for java.awt Color getAlpha.

Prototype

public int getAlpha() 

Source Link

Document

Returns the alpha component in the range 0-255.

Usage

From source file:haven.Utils.java

public static Color blendcol(Color x, Color y, double a) {
    int f1 = (int) (a * 255), f2 = 255 - f1;
    return (new Color(((x.getRed() * f2) + (y.getRed() * f1)) / 255,
            ((x.getGreen() * f2) + (y.getGreen() * f1)) / 255, ((x.getBlue() * f2) + (y.getBlue() * f1)) / 255,
            ((x.getAlpha() * f2) + (y.getAlpha() * f1)) / 255));
}

From source file:org.openstreetmap.josm.tools.Utils.java

/**
 * convert Color to String//  w ww  .j a v  a2s .c  o  m
 * (Color.toString() omits alpha value)
 * @param c the color
 * @return the String representation, including alpha
 */
public static String toString(Color c) {
    if (c == null)
        return "null";
    if (c.getAlpha() == 255)
        return String.format("#%06x", c.getRGB() & 0x00ffffff);
    else
        return String.format("#%06x(alpha=%d)", c.getRGB() & 0x00ffffff, c.getAlpha());
}

From source file:org.openstreetmap.josm.tools.Utils.java

/**
 * Multiply the alpha value of the given color with the factor. The alpha value is clamped to 0..255
 * @param color The color//from   w  w  w  . j a va  2  s.com
 * @param alphaFactor The factor to multiply alpha with.
 * @return The new color.
 * @since 11692
 */
public static Color alphaMultiply(Color color, float alphaFactor) {
    int alpha = Utils.colorFloat2int(Utils.colorInt2float(color.getAlpha()) * alphaFactor);
    alpha = clamp(alpha, 0, 255);
    return new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);
}

From source file:org.openstreetmap.josm.tools.Utils.java

/**
 * Returns the complementary color of {@code clr}.
 * @param clr the color to complement/*w ww . ja  va  2  s  .  c o  m*/
 * @return the complementary color of {@code clr}
 */
public static Color complement(Color clr) {
    return new Color(255 - clr.getRed(), 255 - clr.getGreen(), 255 - clr.getBlue(), clr.getAlpha());
}

From source file:it.cnr.istc.utils.gui.ReverseGradientXYBarPainter.java

/**
 * Paints a single bar instance.//from w  w w  .j  a v a  2 s.co m
 *
 * @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.
 */
@Override
public void paintBar(Graphics2D g2, XYBarRenderer renderer, int row, int column, RectangularShape bar,
        RectangleEdge base) {

    Paint itemPaint = renderer.getItemPaint(row, column);

    Color c0, c1;
    if (itemPaint instanceof Color) {
        c0 = (Color) itemPaint;
        c1 = c0.brighter();
    } else if (itemPaint instanceof GradientPaint) {
        GradientPaint gp = (GradientPaint) itemPaint;
        c0 = gp.getColor1();
        c1 = gp.getColor2();
    } else {
        c0 = Color.blue;
        c1 = Color.blue.brighter();
    }

    // as a special case, if the bar colour has alpha == 0, we draw
    // nothing.
    if (c0.getAlpha() == 0) {
        return;
    }

    if (base == RectangleEdge.LEFT || base == RectangleEdge.RIGHT) {
        Rectangle2D[] regions = splitVerticalBar(bar, this.g1, this.g2, this.g3);
        GradientPaint gp = new GradientPaint((float) regions[0].getMinX(), 0.0f, c0,
                (float) regions[0].getMaxX(), 0.0f, Color.white);
        g2.setPaint(gp);
        g2.fill(regions[0]);

        gp = new GradientPaint((float) regions[1].getMinX(), 0.0f, Color.white, (float) regions[1].getMaxX(),
                0.0f, c0);
        g2.setPaint(gp);
        g2.fill(regions[1]);

        gp = new GradientPaint((float) regions[2].getMinX(), 0.0f, c0, (float) regions[2].getMaxX(), 0.0f, c1);
        g2.setPaint(gp);
        g2.fill(regions[2]);

        gp = new GradientPaint((float) regions[3].getMinX(), 0.0f, c1, (float) regions[3].getMaxX(), 0.0f, c0);
        g2.setPaint(gp);
        g2.fill(regions[3]);
    } else if (base == RectangleEdge.TOP || base == RectangleEdge.BOTTOM) {
        Rectangle2D[] regions = splitHorizontalBar(bar, this.g1, this.g2, this.g3);
        GradientPaint gp = new GradientPaint(0.0f, (float) regions[0].getMinY(), c0, 0.0f,
                (float) regions[0].getMaxX(), Color.white);
        g2.setPaint(gp);
        g2.fill(regions[0]);

        gp = new GradientPaint(0.0f, (float) regions[1].getMinY(), Color.white, 0.0f,
                (float) regions[1].getMaxY(), c0);
        g2.setPaint(gp);
        g2.fill(regions[1]);

        gp = new GradientPaint(0.0f, (float) regions[2].getMinY(), c0, 0.0f, (float) regions[2].getMaxY(), c1);
        g2.setPaint(gp);
        g2.fill(regions[2]);

        gp = new GradientPaint(0.0f, (float) regions[3].getMinY(), c1, 0.0f, (float) regions[3].getMaxY(), c0);
        g2.setPaint(gp);
        g2.fill(regions[3]);
    }

    // draw the outline...
    if (renderer.isDrawBarOutline()) {
        Stroke stroke = renderer.getItemOutlineStroke(row, column);
        Paint paint = renderer.getItemOutlinePaint(row, column);
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);
            g2.setPaint(paint);
            g2.draw(bar);
        }
    }

}

From source file:org.pentaho.reporting.engine.classic.extensions.modules.sbarcodes.BarcodeWrapper.java

/**
 * Provides the computed stylesheet of the report element that contained this drawable. The stylesheet is immutable.
 *
 * @param style/*  w w  w .j  a v  a 2s . c  om*/
 *          the stylesheet.
 */
public void setStyleSheet(final StyleSheet style) {
    if (style != null) {
        final String fontName = (String) style.getStyleProperty(TextStyleKeys.FONT);
        final int fontSize = style.getIntStyleProperty(TextStyleKeys.FONTSIZE, 0);
        final boolean bold = style.getBooleanStyleProperty(TextStyleKeys.BOLD);
        final boolean italics = style.getBooleanStyleProperty(TextStyleKeys.ITALIC);
        final Color foregroundColor = (Color) style.getStyleProperty(ElementStyleKeys.PAINT);
        final Color backgroundColor = (Color) style.getStyleProperty(ElementStyleKeys.BACKGROUND_COLOR);
        if (fontName != null && fontSize > 0) {
            int fontstyle = Font.PLAIN;
            if (bold) {
                fontstyle |= Font.BOLD;
            }
            if (italics) {
                fontstyle |= Font.ITALIC;
            }

            barcode.setFont(new Font(fontName, fontstyle, fontSize));
        }
        if (foregroundColor != null) {
            barcode.setForeground(foregroundColor);
        }
        if (backgroundColor != null) {
            barcode.setBackground(backgroundColor);
            barcode.setOpaque(backgroundColor.getAlpha() == 255);
        } else {
            barcode.setBackground(ALPHA);
            barcode.setOpaque(false);
        }

        scale = style.getBooleanStyleProperty(ElementStyleKeys.SCALE);
        keepAspectRatio = style.getBooleanStyleProperty(ElementStyleKeys.KEEP_ASPECT_RATIO);
    }
}

From source file:org.mrgeo.colorscale.ColorScale.java

/**
 * Interpolate the color value for the given scalar value. The result is placed in color.
 *
 * @param v//from ww  w.  j a  v  a2s . c o m
 * @param color
 * @return
 */
final private void interpolateValue(final double v, final int[] color) {
    final double search;
    switch (scaling) {
    case Absolute:
        search = v;
        break;
    case MinMax:
        search = (v - min) / (max - min);
        break;
    case Modulo:
        search = (v - min) % (max - min);
        break;
    default:
        search = 0;
        break;
    }

    final Map.Entry<Double, Color> lower = floorEntry(search);
    final Map.Entry<Double, Color> upper = higherEntry(search);

    assert (upper != null || lower != null);

    if (upper == null) {
        final Color c = lower.getValue();
        color[R] = c.getRed();
        color[G] = c.getGreen();
        color[B] = c.getBlue();
        color[A] = c.getAlpha();
    } else if (lower == null) {
        final Color c = upper.getValue();
        color[R] = c.getRed();
        color[G] = c.getGreen();
        color[B] = c.getBlue();
        color[A] = c.getAlpha();
    } else {
        final double diff = upper.getKey().doubleValue() - lower.getKey().doubleValue();
        final double lw = 1.0 - ((search - lower.getKey().doubleValue()) / diff);
        final double uw = 1.0 - lw;

        final Color lc = lower.getValue();
        final Color uc = upper.getValue();
        color[R] = (int) Math.round(lc.getRed() * lw + uc.getRed() * uw);
        color[G] = (int) Math.round(lc.getGreen() * lw + uc.getGreen() * uw);
        color[B] = (int) Math.round(lc.getBlue() * lw + uc.getBlue() * uw);
        color[A] = (int) Math.round(lc.getAlpha() * lw + uc.getAlpha() * uw);
    }
}

From source file:org.helioviewer.jhv.plugins.hekplugin.HEKPlugin.java

public void drawPolygon(GL2 gl, HEKEvent evt, Date now) {
    if (evt == null || !evt.isVisible(now))
        return;/*from w w  w.  ja  v a2s.c  o  m*/

    List<HEKEvent.GenericTriangle<Vector3d>> triangles = evt.getTriangulation3D(now);
    List<SphericalCoord> outerBound = evt.getStonyBound(now);
    if (outerBound == null && triangles == null)
        return;

    String type = evt.getString("event_type");
    Color eventColor = HEKConstants.getSingletonInstance().acronymToColor(type, 128);

    HeliographicCoordinate heliographicCoordinate = evt.getHeliographicCoordinate(now);
    if (heliographicCoordinate == null)
        return;

    gl.glPushMatrix();
    gl.glRotated(DifferentialRotation.calculateRotationInDegrees(heliographicCoordinate.latitude,
            (now.getTime() - evt.getStart().getTime()) / 1000d), 0, 1, 0);

    if (triangles != null) {
        gl.glColor4ub((byte) eventColor.getRed(), (byte) eventColor.getGreen(), (byte) eventColor.getBlue(),
                (byte) eventColor.getAlpha());

        gl.glEnable(GL2.GL_CULL_FACE);
        gl.glDisable(GL2.GL_DEPTH_TEST);
        gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);

        gl.glBegin(GL2.GL_TRIANGLES);
        for (GenericTriangle<Vector3d> triangle : triangles) {
            gl.glVertex3d(triangle.A.x, triangle.A.y, triangle.A.z);
            gl.glVertex3d(triangle.B.x, triangle.B.y, triangle.B.z);
            gl.glVertex3d(triangle.C.x, triangle.C.y, triangle.C.z);
        }
        gl.glEnd();
    }

    // draw bounds
    gl.glColor4f(1, 1, 1, 1);
    if (outerBound != null) {
        gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
        gl.glEnable(GL2.GL_DEPTH_TEST);

        gl.glBegin(GL.GL_LINE_LOOP);
        for (SphericalCoord boundaryPoint : outerBound) {
            Vector3d boundaryPoint3d = HEKEvent.convertToSceneCoordinates(boundaryPoint, now).scaled(1.005);
            gl.glVertex3d(boundaryPoint3d.x, boundaryPoint3d.y, boundaryPoint3d.z);
        }
        gl.glEnd();
    }

    gl.glPopMatrix();
}

From source file:lu.lippmann.cdb.ext.hydviga.ui.GapFillingFrame.java

private void showError(final double mae, final Instances decomposition, final Attribute diffAttribute,
        final List<XYAnnotation> aaa) {
    //System.out.println("*************** SHOW ERROR **************************");
    final Attribute timestampDiffAttribute = decomposition
            .attribute(WekaDataStatsUtil.getFirstDateAttributeIdx(decomposition));
    final Color cc = ColorHelper.getColorForAString(diffAttribute.name());
    final Color newcc = new Color(cc.getRed(), cc.getGreen(), cc.getBlue(), cc.getAlpha() / 4).brighter();
    for (int i = 1; i < decomposition.numInstances() - 1; i++) {
        //if (i%10!=1) continue;
        if (!decomposition.instance(i).isMissing(diffAttribute)/*&&i%10==0*/) {
            final double d = decomposition.instance(i).value(diffAttribute);
            final double timestamp = decomposition.instance(i).value(timestampDiffAttribute);

            aaa.add(new XYDrawableAnnotation(timestamp, d + mae, 0.5, 0.5, new AnnotationDrawer(newcc)));
            aaa.add(new XYDrawableAnnotation(timestamp, d - mae, 0.5, 0.5, new AnnotationDrawer(newcc)));
            for (double dd = d - mae; dd <= d + mae; dd += mae / 20) {
                aaa.add(new XYDrawableAnnotation(timestamp, dd, 1, 1, new AnnotationDrawer(newcc)));
            }//w  ww.ja  va 2  s  . co m
            //aaa.add(new XYDrawableAnnotation(timestamp,d,1,1,new AnnotationDrawer(cc)));
        }
    }
    //System.out.println("*****************************************************");
}

From source file:at.tuwien.ifs.somtoolbox.visualization.thematicmap.SOMRegion.java

private Color repairColor(Color color) {
    int red = Math.min(color.getRed() + 10, 255);
    int green = Math.min(color.getGreen() + 10, 255);
    int blue = Math.min(color.getBlue() + 10, 255);
    return new Color(red, green, blue, color.getAlpha());
}