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:org.webcurator.ui.admin.controller.CreateFlagController.java

public String getComplementColour(String hexColour) throws JspException {

    String output = null;/* www.  j  a  va  2 s .  c  o  m*/
    Integer i = null;

    if (hexColour == null || hexColour.equals("")) {
        i = 0;
    } else {
        i = Integer.parseInt(hexColour, 16);
    }

    int red = (i >> 16);
    int green = (i >> 8) & 0xFF;
    int blue = i & 0xFF;

    float[] hsl;
    float alpha;

    Color rgb = new Color(red, green, blue);
    hsl = fromRGB(rgb);
    alpha = rgb.getAlpha() / 255.0f;

    float hue = (hsl[0] + 180.0f) % 360.0f;
    Color complement = toRGB(hue, hsl[1], hsl[2], 1.0f);

    output = rgb2hex(complement.getRed(), complement.getGreen(), complement.getBlue());

    return output;
}

From source file:org.apache.fop.util.ColorUtil.java

private static String toRGBFunctionCall(Color color) {
    StringBuffer sbuf = new StringBuffer();
    sbuf.append('#');
    String s = Integer.toHexString(color.getRed());
    if (s.length() == 1) {
        sbuf.append('0');
    }/*from w  ww .  ja v a 2 s  . com*/
    sbuf.append(s);
    s = Integer.toHexString(color.getGreen());
    if (s.length() == 1) {
        sbuf.append('0');
    }
    sbuf.append(s);
    s = Integer.toHexString(color.getBlue());
    if (s.length() == 1) {
        sbuf.append('0');
    }
    sbuf.append(s);
    if (color.getAlpha() != 255) {
        s = Integer.toHexString(color.getAlpha());
        if (s.length() == 1) {
            sbuf.append('0');
        }
        sbuf.append(s);
    }
    return sbuf.toString();
}

From source file:haven.Utils.java

public static float[] c2fa(Color c) {
    return (new float[] { ((float) c.getRed() / 255.0f), ((float) c.getGreen() / 255.0f),
            ((float) c.getBlue() / 255.0f), ((float) c.getAlpha() / 255.0f) });
}

From source file:org.trianacode.gui.main.imp.TrianaTask.java

protected void paintProcessProgress(Graphics g) {
    if (processled) {
        Color col = ColorManager.getColor(PROGRESS_ELEMENT, getTaskInterface());

        if (col.getAlpha() > 0) {
            Dimension size = getSize();

            int width = (int) (size.width * PROCESS_LED_WIDTH_FACTOR);
            int height = (int) (size.height * PROCESS_LED_HEIGHT_FACTOR);
            int left = (size.width / 2) - (width / 2);
            int top = 0;

            if (getTaskInterface() instanceof TaskGraph) {
                int processCount = (getStartProcessCount() % 3);
                left = (size.width / 2) - (width / 2 * 3) + (processCount * width);
            }/*w  ww  . j av a  2s . co m*/

            g.setColor(col);
            g.fill3DRect(left, top, width, height, true);

            left += width + 1;
            int offset = height / 2;

            for (int count = 0; (count < getStartProcessCount() - getStopProcessCount() - 1)
                    && (left + height < size.width); count++) {
                g.drawLine(left, top + offset, left + height, top + offset);
                g.drawLine(left + offset, top, left + offset, top + height);

                left += height + 1;
            }
        }
    }
}

From source file:io.github.minecraftgui.models.network.packets.PacketSetAttribute.java

public PacketSetAttribute(Component component, Shape shape, State state, double percentage, long time,
        Color value) {
    this.component = component;
    this.shape = shape;
    this.state = state;
    this.percentage = percentage;
    this.time = time;
    this.value = new JSONObject().put(NetworkController.R, value.getRed())
            .put(NetworkController.G, value.getGreen()).put(NetworkController.B, value.getBlue())
            .put(NetworkController.A, value.getAlpha());
}

From source file:haven.Utils.java

public static Color contrast(Color col) {
    int max = Math.max(col.getRed(), Math.max(col.getGreen(), col.getBlue()));
    if (max > 128) {
        return (new Color(col.getRed() / 2, col.getGreen() / 2, col.getBlue() / 2, col.getAlpha()));
    } else if (max == 0) {
        return (Color.WHITE);
    } else {/*from   w  w w  . jav a 2 s  .c  o m*/
        int f = 128 / max;
        return (new Color(col.getRed() * f, col.getGreen() * f, col.getBlue() * f, col.getAlpha()));
    }
}

From source file:io.github.minecraftgui.models.network.packets.PacketSetAttribute.java

public PacketSetAttribute(Component component, State state, Color value) {
    this.component = component;
    this.shape = component.getShape();
    this.state = state;
    this.percentage = 1;
    this.time = 0;
    this.value = new JSONObject().put(NetworkController.R, value.getRed())
            .put(NetworkController.G, value.getGreen()).put(NetworkController.B, value.getBlue())
            .put(NetworkController.A, value.getAlpha());
}

From source file:io.github.minecraftgui.models.network.packets.PacketInitClient.java

@Override
public JSONObject toJSON() {
    JSONObject jsonObject = new JSONObject();
    JSONArray fonts = new JSONArray();
    JSONArray images = new JSONArray();
    JSONArray fontsToGenerate = new JSONArray();

    for (String font : this.fonts)
        fonts.put(font);/*w w w  . j  a v a  2 s  .  co m*/

    for (Map.Entry pairs : this.images.entrySet())
        images.put(new JSONObject().put(NetworkController.URL, pairs.getKey()).put(NetworkController.NAME,
                pairs.getValue()));

    for (Map.Entry pairs : this.fontsGenerate.entrySet()) {
        JSONObject font = new JSONObject();
        JSONArray colorList = new JSONArray();

        for (Map.Entry pairs1 : ((HashMap<Color, Integer>) pairs.getValue()).entrySet()) {
            JSONObject colorObj = new JSONObject();
            JSONArray sizeList = new JSONArray();
            Color color = (Color) pairs1.getKey();
            ArrayList<Integer> sizes = (ArrayList) pairs1.getValue();

            for (Integer size : sizes)
                sizeList.put(size);

            colorObj.put(NetworkController.R, color.getRed());
            colorObj.put(NetworkController.G, color.getGreen());
            colorObj.put(NetworkController.B, color.getBlue());
            colorObj.put(NetworkController.A, color.getAlpha());
            colorObj.put(NetworkController.LIST, sizeList);
            colorList.put(colorObj);
        }

        font.put(NetworkController.NAME, pairs.getKey());
        font.put(NetworkController.LIST, colorList);
        fontsToGenerate.put(font);
    }

    jsonObject.put(NetworkController.FONTS, fonts);
    jsonObject.put(NetworkController.IMAGES, images);
    jsonObject.put(NetworkController.FONTS_TO_GENERATE, fontsToGenerate);

    return jsonObject;
}

From source file:org.apache.fop.svg.AbstractFOPTextPainter.java

private boolean hasUnsupportedAttributes(AttributedCharacterIterator aci) {
    boolean hasUnsupported = false;

    Font font = getFont(aci);/*ww  w . j  av a  2s.  c o m*/
    String text = getText(aci);
    if (hasUnsupportedGlyphs(text, font)) {
        log.trace("-> Unsupported glyphs found");
        hasUnsupported = true;
    }

    TextPaintInfo tpi = (TextPaintInfo) aci
            .getAttribute(GVTAttributedCharacterIterator.TextAttribute.PAINT_INFO);
    if ((tpi != null)
            && ((tpi.strokeStroke != null && tpi.strokePaint != null) || (tpi.strikethroughStroke != null)
                    || (tpi.underlineStroke != null) || (tpi.overlineStroke != null))) {
        log.trace("-> under/overlines etc. found");
        hasUnsupported = true;
    }

    //Alpha is not supported
    Paint foreground = (Paint) aci.getAttribute(TextAttribute.FOREGROUND);
    if (foreground instanceof Color) {
        Color col = (Color) foreground;
        if (col.getAlpha() != 255) {
            log.trace("-> transparency found");
            hasUnsupported = true;
        }
    }

    Object letSpace = aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.LETTER_SPACING);
    if (letSpace != null) {
        log.trace("-> letter spacing found");
        hasUnsupported = true;
    }

    Object wordSpace = aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.WORD_SPACING);
    if (wordSpace != null) {
        log.trace("-> word spacing found");
        hasUnsupported = true;
    }

    Object lengthAdjust = aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.LENGTH_ADJUST);
    if (lengthAdjust != null) {
        log.trace("-> length adjustments found");
        hasUnsupported = true;
    }

    Object writeMod = aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.WRITING_MODE);
    if (writeMod != null && !GVTAttributedCharacterIterator.TextAttribute.WRITING_MODE_LTR.equals(writeMod)) {
        log.trace("-> Unsupported writing modes found");
        hasUnsupported = true;
    }

    Object vertOr = aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.VERTICAL_ORIENTATION);
    if (GVTAttributedCharacterIterator.TextAttribute.ORIENTATION_ANGLE.equals(vertOr)) {
        log.trace("-> vertical orientation found");
        hasUnsupported = true;
    }

    Object rcDel = aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.TEXT_COMPOUND_DELIMITER);
    //Batik 1.6 returns null here which makes it impossible to determine whether this can
    //be painted or not, i.e. fall back to stroking. :-(
    if (rcDel != null && !(rcDel instanceof SVGOMTextElement)) {
        log.trace("-> spans found");
        hasUnsupported = true; //Filter spans
    }

    if (hasUnsupported) {
        log.trace("Unsupported attributes found in ACI, using StrokingTextPainter");
    }
    return hasUnsupported;
}

From source file:org.geoserver.wms.wms_1_1_1.GetLegendGraphicTest.java

/**
 * Tests an custom legend graphic/*ww w  . j a  v  a  2s .  co m*/
 */
@Test
public void testCustomLegend() throws Exception {
    String base = "wms?service=WMS&version=1.1.1&request=GetLegendGraphic" + "&layer=sf:states&style=custom"
            + "&format=image/png&width=22&height=22";

    BufferedImage image = getAsImage(base, "image/png");
    Resource resource = getResourceLoader().get("styles/legend.png");
    BufferedImage expected = ImageIO.read(resource.file());

    assertEquals(getPixelColor(expected, 10, 2).getRGB(), getPixelColor(image, 10, 2).getRGB());

    // test rescale
    base = "wms?service=WMS&version=1.1.1&request=GetLegendGraphic" + "&layer=sf:states&style=custom"
            + "&format=image/png&width=16&height=16";

    image = getAsImage(base, "image/png");

    Color expectedColor = getPixelColor(expected, 11, 11);
    Color actualColor = getPixelColor(image, 8, 8);
    assertEquals("red", expectedColor.getRed(), actualColor.getRed());
    assertEquals("green", expectedColor.getGreen(), actualColor.getGreen());
    assertEquals("blue", expectedColor.getBlue(), actualColor.getBlue());
    assertEquals("alpha", expectedColor.getAlpha(), actualColor.getAlpha());

}