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:base.BasePlayer.BedCanvas.java

@Override
public void keyPressed(KeyEvent e) {
    // TODO Auto-generated method stub
    int keyCode = e.getKeyCode();

    if (keyCode == KeyEvent.VK_PLUS || keyCode == 107) {
        heightchanged = true;/*from ww w  . j ava  2s . c  om*/
        for (int i = 0; i < bedTrack.size(); i++) {
            if (bedTrack.get(i).nodeHeight < 20) {
                bedTrack.get(i).nodeHeight++;

            }
        }

        repaint();
    }
    if (keyCode == KeyEvent.VK_MINUS || keyCode == 109) {

        heightchanged = true;
        for (int i = 0; i < bedTrack.size(); i++) {
            if (bedTrack.get(i).nodeHeight > 1) {
                bedTrack.get(i).nodeHeight--;
            }
        }
        repaint();
    }
    if (keyCode == KeyEvent.VK_PAGE_UP) {

        if (this.forwardColor.getAlpha() < 255) {
            this.forwardColor = new Color(this.forwardColor.getRed(), this.forwardColor.getGreen(),
                    this.forwardColor.getBlue(), this.forwardColor.getAlpha() + 15);
            this.reverseColor = new Color(this.reverseColor.getRed(), this.reverseColor.getGreen(),
                    this.reverseColor.getBlue(), this.reverseColor.getAlpha() + 15);
            for (int i = 0; i < bedTrack.size(); i++) {

                if (bedTrack.get(i).getColors().size() > 0) {
                    Iterator<Map.Entry<Integer, Color>> it;
                    Map.Entry<Integer, Color> pair;
                    Color color;
                    it = bedTrack.get(i).getColors().entrySet().iterator();
                    while (it.hasNext()) {
                        pair = (Map.Entry<Integer, Color>) it.next();
                        color = pair.getValue();
                        color = new Color(color.getRed(), color.getGreen(), color.getBlue(),
                                color.getAlpha() + 15);
                        bedTrack.get(i).getColors().put(pair.getKey(), color);
                    }
                }
            }

        }

        repaint();
    }
    if (keyCode == KeyEvent.VK_PAGE_DOWN) {

        if (this.forwardColor.getAlpha() > 0) {
            this.forwardColor = new Color(this.forwardColor.getRed(), this.forwardColor.getGreen(),
                    this.forwardColor.getBlue(), this.forwardColor.getAlpha() - 15);
            this.reverseColor = new Color(this.reverseColor.getRed(), this.reverseColor.getGreen(),
                    this.reverseColor.getBlue(), this.reverseColor.getAlpha() - 15);

            for (int i = 0; i < bedTrack.size(); i++) {
                if (bedTrack.get(i).getColors().size() > 0) {
                    Iterator<Map.Entry<Integer, Color>> it;
                    Map.Entry<Integer, Color> pair;
                    Color color;
                    it = bedTrack.get(i).getColors().entrySet().iterator();

                    while (it.hasNext()) {

                        pair = (Map.Entry<Integer, Color>) it.next();
                        color = pair.getValue();

                        color = new Color(color.getRed(), color.getGreen(), color.getBlue(),
                                color.getAlpha() - 15);
                        bedTrack.get(i).getColors().put(pair.getKey(), color);

                    }
                }
            }
        }

        repaint();
    }
}

From source file:ome.formats.OMEROMetadataStoreClient.java

public void setWellColor(Integer color, int plateIndex, int wellIndex) {
    Well o = getWell(plateIndex, wellIndex);
    Color c = new Color(color);
    o.setRed(toRType(c.getRed()));/*from w w w . j  av a 2  s.com*/
    o.setGreen(toRType(c.getGreen()));
    o.setBlue(toRType(c.getBlue()));
    o.setAlpha(toRType(c.getAlpha()));
}

From source file:ome.formats.OMEROMetadataStoreClient.java

public void setChannelColor(Integer color, int imageIndex, int channelIndex) {
    Channel o = getChannel(imageIndex, channelIndex);
    // RGBA --> ARGB
    Color c = new Color((color >>> 8) | (color << (32 - 8)));
    o.setRed(toRType(c.getRed()));//from   w  w w.  jav  a2  s . c om
    o.setGreen(toRType(c.getGreen()));
    o.setBlue(toRType(c.getBlue()));
    o.setAlpha(toRType(c.getAlpha()));
}

From source file:tufts.vue.LWComponent.java

public static String ColorToString(final Color c) {
    // if null, or no hue and no alpha, return null
    //if (c == null || ((c.getRGB() & 0xFFFFFF) == 0 && c.getAlpha() == 255))
    if (c == null)
        return null;

    if (c.getAlpha() == 255) // opaque: only bother to save hue info
        return String.format("#%06X", c.getRGB() & 0xFFFFFF);
    else/*from w w w  .ja v  a2s .  co  m*/
        return String.format("#%08X", c.getRGB());
}

From source file:tufts.vue.LWComponent.java

/**
 * Create a new buffered image, of max dimension maxSize, and render the LWComponent
 * (and all it's children), to it using the given alpha.
 * @param alpha 0.0 (invisible) to 1.0 (no alpha)
 * @param maxSize max dimensions for image. May be null.  Image may be smaller than maxSize.
 * @param fillColor -- if non-null, will be rendered as background for image.  If null, presume alpha 0 fill.
 * @param zoomRequest -- desired zoom; ignored if maxSize is non-null
 * also set, background fill will have transparency of alpha^3 to enhance contrast.
 *///from   w  ww. j a va  2 s.  co  m

// Note: as of Mac OS X 10.4.10 (Intel), when a java drag source declares it can
// generate an image (as we do when we Apple-drag something), if you drop it on the
// desktop, it will create a special mac "picture clipping", which is some kind of
// raw format, probabaly TIFF, tho you CANNOT open these in Preview.  Apparently
// there's some kind of bug in the special .pictClipping, where sometimes when
// opening it up it shows entirely as a blank space (I think if the image starts to
// get "very large"), tho the data is actually there -- if you drag the picture
// clipping into an Apple Mail message, it shows up again (and if you dragged from
// VUE to Apple Mail in the first place, it also works fine).  Note that AFTER
// dragging into Apple Mail, you can THEN double-click the attachment, and it will
// open it up in Preview as a .tiff file (Apple Mail appears to be converting the
// .pictClipping to tiff).  Note that uncompressed TIFF isn't exactly a friendly
// mail attachment format as it's huge.  But once you open the image in Preview, you
// have the option of saving it / exporting it as a jpeg, and you can even adjust
// the quality to your liking.

public BufferedImage createImage(double alpha, Dimension maxSize, Color fillColor, double zoomRequest) {
    final Rectangle2D.Float bounds = getImageBounds();

    if (DEBUG.IMAGE) {
        System.out.println();
        System.out.println(TERM_CYAN + "createImage: " + this + "\n\t zoomRequst: " + zoomRequest
                + "\n\t    maxSize: " + maxSize + "\n\t  mapBounds: " + fmt(bounds) + "\n\t  fillColor: "
                + fillColor + "\n\t      alpha: " + alpha + TERM_CLEAR);
    }

    final Size imageSize = new Size(bounds);
    final double usedZoom = computeZoomAndSize(bounds, maxSize, zoomRequest, imageSize);

    // Image type ARGB is needed if at any point in the generated image, there is a
    // not 100% opaque pixel all the way through the background.  So TYPE_INT_RGB
    // will handle transparency with a map fine -- but we need TYPE_INT_ARGB if,
    // say, we're generating drag image that we want to be a borderless node (fully
    // transparent image border), or if the whole drag image itself is
    // semi-transparent.

    final int imageType;
    final int transparency;

    if (fillColor == null || alpha != OPAQUE || fillColor.getAlpha() != 255) {
        imageType = BufferedImage.TYPE_INT_ARGB;
        transparency = Transparency.TRANSLUCENT;
    } else {
        imageType = BufferedImage.TYPE_INT_RGB;
        transparency = Transparency.OPAQUE;
    }

    //        final boolean fillHasAlpha = (fillColor != null && fillColor.getAlpha() != 255);
    //         //if (alpha == OPAQUE && fillColor != null && fillColor.getAlpha() == 255) {
    //         if (alpha == OPAQUE && (fillColor == null || fillColor.getAlpha() == 255)) {
    //             imageType = BufferedImage.TYPE_INT_RGB;
    //             transparency = Transparency.OPAQUE;
    //         } else {
    //             imageType = BufferedImage.TYPE_INT_ARGB;
    //             transparency = Transparency.TRANSLUCENT;
    //         }

    final int width = imageSize.pixelWidth();
    final int height = imageSize.pixelHeight();

    if (width >= 512 || height >= 512)
        Log.info("creating large image: " + imageSize + " = approx " + Util.abbrevBytes(width * height * 4));

    try {
        Log.info(this + "; createImage:" + "\n\t requestSize: " + imageSize + "\n\trequestAlpha: " + alpha
                + "\n\t requestFill: " + fillColor + "\n\t   pixelSize: " + width + "x" + height
                + "\n\t renderScale: " + usedZoom + "\n\t        type: "
                + (imageType == BufferedImage.TYPE_INT_RGB ? "RGB (opaque)" : "ARGB (translucent)"));
    } catch (Throwable t) {
        Log.error("logging", t);
    }

    //         if (DEBUG.IMAGE) out(TERM_CYAN
    //                              + "createImage:"
    //                              //+ "\n\tfinal size: " + width + "x" + height
    //                              + "\n\t neededSize: " + imageSize
    //                              + "\n\t   usedZoom: " + usedZoom
    //                              + "\n\t       type: " + (imageType == BufferedImage.TYPE_INT_RGB ? "OPAQUE" : "TRANSPARENT")
    //                              + TERM_CLEAR);

    if (mImageBuffer != null && mImageBuffer.getWidth() == width && mImageBuffer.getHeight() == height
            && mImageBuffer.getType() == imageType) {
        // todo: could also re-use if cached image is > our needed size as long it's
        // an ARGB and we fill it with full alpha first, tho we really shouldn't
        // have each component caching it's own image: some kind of small
        // recently used image buffers cache would make more sense.
        if (DEBUG.DND || DEBUG.IMAGE)
            out(TERM_CYAN + "\ngot cached image: " + mImageBuffer + TERM_CLEAR);
    } else {
        try {

            // TODO: manage this in a separate cache -- not one per node

            mImageBuffer = tufts.vue.gui.GUI.getDeviceConfigForWindow(null).createCompatibleImage(width, height,
                    transparency);

        } catch (Throwable t) {
            Log.error("creating image", t);
            Log.error("creating image: failing node: " + Util.tags(this));
            return null;
        }

        if (DEBUG.DND || DEBUG.IMAGE)
            out(TERM_RED + "created image: " + mImageBuffer + TERM_CLEAR);
        else
            Log.info("created image " + mImageBuffer);

    }

    drawImage((Graphics2D) mImageBuffer.getGraphics(), alpha, maxSize, fillColor, zoomRequest);

    return mImageBuffer;
}