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:lu.lippmann.cdb.ext.hydviga.ui.GapFillingFrame.java

private void showEnvelope(final int[] arr, final List<XYAnnotation> aaa) throws Exception {
    final Color cc = ColorHelper.getColorForAString(attr.name());
    final Color newcc = new Color(cc.getRed(), cc.getGreen(), cc.getBlue(), cc.getAlpha() / 4).brighter();

    final Map<Double, Double> minMap = new HashMap<Double, Double>();
    final Map<Double, Double> maxMap = new HashMap<Double, Double>();

    for (final Algo aall : Algo.values()) {
        Instances filteredDs2 = WekaDataProcessingUtil.buildFilteredByAttributesDataSet(dataSet, arr);

        filteredDs2 = WekaDataProcessingUtil.buildFilteredDataSet(filteredDs2, 0,
                filteredDs2.numAttributes() - 1, Math.max(0, this.position - this.valuesBeforeAndAfter),
                Math.min(this.position + this.gapsize + this.valuesBeforeAndAfter,
                        filteredDs2.numInstances() - 1));

        final GapFiller gp = GapFillerFactory.getGapFiller(aall);

        final Instances completedds2 = gp.fillGaps(filteredDs2);
        final Instances diff2 = WekaTimeSeriesUtil.buildDiff(filteredDs2, completedds2);

        //final double mae2=this.gapFiller.evaluateMeanAbsoluteError(filteredDs2,valuesBeforeAndAfterForMAE);

        final Instances decomposition2 = WekaTimeSeriesUtil.buildMergedDataSet(filteredDs2, diff2);
        final Attribute diffAttribute2 = decomposition2.attribute(attr.name() + "_diff");

        final Attribute timestampDiffAttribute2 = decomposition2
                .attribute(WekaDataStatsUtil.getFirstDateAttributeIdx(decomposition2));

        for (int i = 1; i < decomposition2.numInstances() - 1; i++) {
            if (!decomposition2.instance(i).isMissing(diffAttribute2)/*&&i%10==0*/) {
                final double d = decomposition2.instance(i).value(diffAttribute2);
                final double timestamp = decomposition2.instance(i).value(timestampDiffAttribute2);

                aaa.add(new XYDrawableAnnotation(timestamp, d, 1, 1, new AnnotationDrawer(newcc)));

                if (!minMap.containsKey(timestamp) || minMap.get(timestamp) > d)
                    minMap.put(timestamp, d);
                if (!maxMap.containsKey(timestamp) || maxMap.get(timestamp) < d)
                    maxMap.put(timestamp, d);
            }//from   w w  w .j av a  2 s.  co  m
        }
    }

    for (final Map.Entry<Double, Double> entry : minMap.entrySet()) {
        final Double timestamp = entry.getKey();
        final Double min = minMap.get(timestamp);
        final Double max = maxMap.get(timestamp);
        if (min > max)
            throw new IllegalStateException("min>max -> " + min + ">" + max);
        else if (max > min) {
            final double step = (max - min) / 20d;
            for (double dd = min; dd <= max; dd += step) {
                aaa.add(new XYDrawableAnnotation(timestamp, dd, 1, 1, new AnnotationDrawer(newcc)));
            }
        }
    }

    System.out.println("done");
}

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

/**
 * Find the color band that this value falls in and assign that color.
 *
 * @param v//  ww  w.j  ava 2 s .  c  o m
 * @param color
 */
final private void absoluteValue(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 % (max - min);
        break;
    default:
        search = 0;
        break;
    }

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

    Color c;
    if (lower == null) {
        c = entrySet().iterator().next().getValue();
    } else {
        c = lower.getValue();
    }

    color[R] = c.getRed();
    color[G] = c.getGreen();
    color[B] = c.getBlue();
    color[A] = c.getAlpha();
}

From source file:org.openmicroscopy.shoola.agents.dataBrowser.view.WellsModel.java

/**
 * Handles the selection of a cell//w w  w.  j a  v a  2 s. c o m
 * 
 * @param cell The selected cell.
 * @param well The well to handle.
 * @param results The collection of objects to update.
 */
private void handleCellSelection(CellDisplay cell, WellImageSet well, List<DataObject> results) {
    String description = cell.getDescription();
    Color c = cell.getHighlight();
    WellData data = (WellData) well.getHierarchyObject();
    data.setWellType(description);
    well.setDescription(description);
    results.add(data);
    if (c == null || !cell.isSpecified()) {
        data.setRed(null);
    } else {
        data.setRed(c.getRed());
        data.setGreen(c.getGreen());
        data.setBlue(c.getBlue());
        data.setAlpha(c.getAlpha());
    }
    well.setHighlight(c);
}

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
 * Converts the passed color.//from   ww w .ja  v a 2  s .  c om
 * 
 * @param c The color to handle.
 * @return See above.
 */
public static int convertColor(Color c) {
    int alpha = c.getAlpha();
    if (alpha == 0)
        alpha = 255;
    return ((alpha & 0xFF) << 24) | ((c.getRed() & 0xFF) << 16) | ((c.getGreen() & 0xFF) << 8)
            | ((c.getBlue() & 0xFF) << 0);
}

From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java

@Override
public void drawRectangle(RectangleRenderEvent rre) throws ChartException {
    if (iv != null) {
        iv.modifyEvent(rre);//w  w w  . j a  va2  s  .c om
    }
    // CHECK IF THE LINE ATTRIBUTES ARE CORRECTLY DEFINED
    final LineAttributes lia = rre.getOutline();
    if (!validateLineAttributes(rre.getSource(), lia)) {
        return;
    }

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

    // RENDER THE RECTANGLE WITH THE APPROPRIATE LINE STYLE
    final Bounds bo = normalizeBounds(rre.getBounds());
    Stroke sPrevious = null;
    Stroke sCurrent = getCachedStroke(lia);
    if (sCurrent != null) // SOME STROKE DEFINED?
    {
        sPrevious = _g2d.getStroke();
        _g2d.setStroke(sCurrent);
    }
    _g2d.setColor(cFG);
    _g2d.draw(new Rectangle2D.Double(bo.getLeft(), bo.getTop(), bo.getWidth() - 1, bo.getHeight() - 1));
    if (sPrevious != null) // RESTORE PREVIOUS STROKE
    {
        _g2d.setStroke(sPrevious);
    }
}

From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java

@Override
public void drawPolygon(PolygonRenderEvent pre) throws ChartException {
    if (iv != null) {
        iv.modifyEvent(pre);//from   www  . ja va  2  s  .  c om
    }
    // CHECK IF THE LINE ATTRIBUTES ARE CORRECTLY DEFINED
    final LineAttributes lia = pre.getOutline();
    if (!validateLineAttributes(pre.getSource(), lia)) {
        return;
    }

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

    // DRAW THE POLYGON
    final Location[] la = pre.getPoints();
    Stroke sPrevious = null;
    final Stroke sCurrent = getCachedStroke(lia);
    if (sCurrent != null) // SOME STROKE DEFINED?
    {
        sPrevious = _g2d.getStroke();
        _g2d.setStroke(sCurrent);
    }

    _g2d.setColor(cFG);
    _g2d.draw(getPolygon(la));
    if (sPrevious != null) // RESTORE PREVIOUS STROKE
    {
        _g2d.setStroke(sPrevious);
    }
}

From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java

@Override
public void drawOval(OvalRenderEvent ore) throws ChartException {
    if (iv != null) {
        iv.modifyEvent(ore);/*from w  w w. java2 s  .  c o m*/
    }

    // CHECK IF THE LINE ATTRIBUTES ARE CORRECTLY DEFINED
    final LineAttributes lia = ore.getOutline();
    if (!validateLineAttributes(ore.getSource(), lia)) {
        return;
    }

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

    // RENDER THE ELLIPSE WITH THE APPROPRIATE LINE STYLE
    final Bounds bo = ore.getBounds();
    final Ellipse2D.Double e2d = new Ellipse2D.Double(bo.getLeft(), bo.getTop(), bo.getWidth(), bo.getHeight());

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

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

    if (sPrevious != null) // RESTORE PREVIOUS STROKE
    {
        _g2d.setStroke(sPrevious);
    }
}

From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java

@Override
public void drawArc(ArcRenderEvent are) throws ChartException {
    if (iv != null) {
        iv.modifyEvent(are);//  w w  w . j  a v a 2s  . c o m
    }

    // 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 (cFG == null || cFG.getAlpha() == 0) {
        return;
    }

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

    if ((are.getInnerRadius() >= 0 && are.getOuterRadius() > 0 && are.getInnerRadius() < are.getOuterRadius())
            || (are.getInnerRadius() > 0 && are.getOuterRadius() <= 0)) {
        Bounds rctOuter = getOuterRectangle(are);
        Bounds rctInner = getInnerRectangle(are);

        Shape outerArc = new Arc2D.Double(rctOuter.getLeft(), rctOuter.getTop(), rctOuter.getWidth(),
                rctOuter.getHeight(), are.getStartAngle(), are.getAngleExtent(), Arc2D.OPEN);
        Shape innerArc = new Arc2D.Double(rctInner.getLeft(), rctInner.getTop(), rctInner.getWidth(),
                rctInner.getHeight(), are.getStartAngle() + are.getAngleExtent(), -are.getAngleExtent(),
                Arc2D.OPEN);

        double startAngle = Math.toRadians(-are.getStartAngle());
        double stopAngle = Math.toRadians(-are.getStartAngle() - are.getAngleExtent());

        double xsOuter = (rctOuter.getLeft() + (Math.cos(startAngle) * 0.5 + 0.5) * rctOuter.getWidth());
        double ysOuter = (rctOuter.getTop() + (Math.sin(startAngle) * 0.5 + 0.5) * rctOuter.getHeight());

        double xeInner = (rctInner.getLeft() + (Math.cos(stopAngle) * 0.5 + 0.5) * rctInner.getWidth());
        double yeInner = (rctInner.getTop() + (Math.sin(stopAngle) * 0.5 + 0.5) * rctInner.getHeight());

        GeneralPath gp = new GeneralPath();
        gp.append(outerArc, false);
        gp.lineTo((float) xeInner, (float) yeInner);
        gp.append(innerArc, false);
        gp.lineTo((float) xsOuter, (float) ysOuter);

        Area area = new Area(gp);
        Shape prevClip = _g2d.getClip();
        Area ar2 = new Area(area);
        if (prevClip != null) {
            Area ar1 = new Area(prevClip);
            ar2.intersect(ar1);
        }
        _g2d.setClip(ar2);
        _g2d.draw(area);
        _g2d.setClip(prevClip);

    } else {
        _g2d.draw(new Arc2D.Double(are.getTopLeft().getX(), are.getTopLeft().getY(), are.getWidth(),
                are.getHeight(), are.getStartAngle(), are.getAngleExtent(), toG2dArcType(are.getStyle())));
    }

    if (sPrevious != null) // RESTORE PREVIOUS STROKE
    {
        _g2d.setStroke(sPrevious);
    }
}

From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java

@Override
public void drawArea(AreaRenderEvent are) throws ChartException {
    if (iv != null) {
        iv.modifyEvent(are);/*from  w w  w .ja v  a 2  s.com*/
    }

    // 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);
    }
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java

/**
 * Method contributed by Alexej Suchov//  w  w w.j av a 2 s  .  co  m
 *
 * @see Graphics2D#setPaint(Paint)
 */
@Override
public void setPaint(final Paint paint) {
    if (paint == null) {
        return;
    }
    this.paint = paint;
    realPaint = paint;

    if ((composite instanceof AlphaComposite) && (paint instanceof Color)) {

        final AlphaComposite co = (AlphaComposite) composite;

        if (co.getRule() == 3) {
            final Color c = (Color) paint;
            this.paint = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (c.getAlpha() * alpha));
            realPaint = paint;
        }
    }

}