Example usage for java.awt Color getRed

List of usage examples for java.awt Color getRed

Introduction

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

Prototype

public int getRed() 

Source Link

Document

Returns the red component in the range 0-255 in the default sRGB space.

Usage

From source file:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImpl.java

/**
 * Internal implementation to add a topic map to a slide.
 * @param slide the slide to add to.//from ww  w.  ja  v a 2 s . c  o m
 * @param anchor bounding rectangle to draw onto, in PowerPoint coordinates.
 * @param data the topic map data.
 */
private static void addTopicMap(final XSLFSlide slide, final Rectangle2D.Double anchor,
        final TopicMapData data) {
    for (final TopicMapData.Path reqPath : data.getPaths()) {
        final XSLFFreeformShape shape = slide.createFreeform();
        final Path2D.Double path = new Path2D.Double();

        boolean first = true;

        for (double[] point : reqPath.getPoints()) {
            final double x = point[0] * anchor.getWidth() + anchor.getMinX();
            final double y = point[1] * anchor.getHeight() + anchor.getMinY();
            if (first) {
                path.moveTo(x, y);
                first = false;
            } else {
                path.lineTo(x, y);
            }
        }
        path.closePath();

        shape.setPath(path);
        shape.setStrokeStyle(2);
        shape.setLineColor(Color.GRAY);
        shape.setHorizontalCentered(true);
        shape.setVerticalAlignment(VerticalAlignment.MIDDLE);
        shape.setTextAutofit(TextShape.TextAutofit.NORMAL);

        final XSLFTextParagraph text = shape.addNewTextParagraph();
        final XSLFTextRun textRun = text.addNewTextRun();
        textRun.setText(reqPath.name);
        textRun.setFontColor(Color.WHITE);
        textRun.setBold(true);

        final CTShape cs = (CTShape) shape.getXmlObject();

        double max = 100, min = 1, scale = 100;
        final CTTextNormalAutofit autoFit = cs.getTxBody().getBodyPr().getNormAutofit();
        final double availHeight = path.getBounds2D().getHeight();
        final int RESIZE_ATTEMPTS = 7;

        for (int attempts = 0; attempts < RESIZE_ATTEMPTS; ++attempts) {
            // PowerPoint doesn't resize the text till you edit it once, which means the text initially looks too
            //   large when you first view the slide; so we binary-chop to get a sensible initial approximation.
            // OpenOffice does the text resize on load so it doesn't have this problem.
            autoFit.setFontScale(Math.max(1, (int) (scale * 1000)));

            final double textHeight = shape.getTextHeight();
            if (textHeight < availHeight) {
                min = scale;
                scale = 0.5 * (min + max);
            } else if (textHeight > availHeight) {
                max = scale;
                scale = 0.5 * (min + max);
            } else {
                break;
            }
        }

        final int opacity = (int) (100000 * reqPath.getOpacity());
        final Color c1 = Color.decode(reqPath.getColor());
        final Color c2 = Color.decode(reqPath.getColor2());

        final CTGradientFillProperties gFill = cs.getSpPr().addNewGradFill();
        gFill.addNewLin().setAng(3300000);
        final CTGradientStopList list = gFill.addNewGsLst();

        final CTGradientStop stop1 = list.addNewGs();
        stop1.setPos(0);
        final CTSRgbColor color1 = stop1.addNewSrgbClr();
        color1.setVal(new byte[] { (byte) c1.getRed(), (byte) c1.getGreen(), (byte) c1.getBlue() });
        color1.addNewAlpha().setVal(opacity);

        final CTGradientStop stop2 = list.addNewGs();
        stop2.setPos(100000);
        final CTSRgbColor color2 = stop2.addNewSrgbClr();
        color2.setVal(new byte[] { (byte) c2.getRed(), (byte) c2.getGreen(), (byte) c2.getBlue() });
        color2.addNewAlpha().setVal(opacity);

        if (reqPath.level > 0) {
            // The nodes which aren't leaf nodes can be clicked on to hide them so you can see the nodes underneath.
            // This only works in PowerPoint; OpenOffice doesn't seem to support it. OpenOffice has its own syntax
            //   to do something similar, but we don't use it since PowerPoint treats it as corrupt.
            final String shapeId = Integer.toString(shape.getShapeId());
            final CTSlide slXML = slide.getXmlObject();

            final CTTimeNodeList childTnLst;
            final CTBuildList bldLst;
            if (!slXML.isSetTiming()) {
                final CTSlideTiming timing = slXML.addNewTiming();
                final CTTLCommonTimeNodeData ctn = timing.addNewTnLst().addNewPar().addNewCTn();
                ctn.setDur("indefinite");
                ctn.setRestart(STTLTimeNodeRestartTypeImpl.NEVER);
                ctn.setNodeType(STTLTimeNodeType.TM_ROOT);
                childTnLst = ctn.addNewChildTnLst();
                bldLst = timing.addNewBldLst();
            } else {
                final CTSlideTiming timing = slXML.getTiming();
                childTnLst = timing.getTnLst().getParArray(0).getCTn().getChildTnLst();
                bldLst = timing.getBldLst();
            }

            final CTTLTimeNodeSequence seq = childTnLst.addNewSeq();
            seq.setConcurrent(true);
            seq.setNextAc(STTLNextActionType.SEEK);
            final CTTLCommonTimeNodeData common = seq.addNewCTn();

            common.setRestart(STTLTimeNodeRestartType.WHEN_NOT_ACTIVE);
            common.setFill(STTLTimeNodeFillType.HOLD);
            common.setEvtFilter("cancelBubble");
            common.setNodeType(STTLTimeNodeType.INTERACTIVE_SEQ);

            final CTTLTimeConditionList condList = common.addNewStCondLst();
            final CTTLTimeCondition cond = condList.addNewCond();
            cond.setEvt(STTLTriggerEvent.ON_CLICK);
            cond.setDelay(0);
            cond.addNewTgtEl().addNewSpTgt().setSpid(shapeId);

            final CTTLTimeCondition endSync = common.addNewEndSync();
            endSync.setEvt(STTLTriggerEvent.END);
            endSync.setDelay(0);
            endSync.addNewRtn().setVal(STTLTriggerRuntimeNode.ALL);

            // These holdCtn* 'hold' transitions with zero delay might seem redundant; but they're exported in the
            //   PowerPoint XML, and the online PowerPoint Office365 viewer won't support the click animations
            //   unless they're present (e.g. from the 'Start Slide Show' button in the browser).
            final CTTLCommonTimeNodeData holdCtn1 = common.addNewChildTnLst().addNewPar().addNewCTn();

            holdCtn1.setFill(STTLTimeNodeFillType.HOLD);
            holdCtn1.addNewStCondLst().addNewCond().setDelay(0);

            final CTTLCommonTimeNodeData holdCtn2 = holdCtn1.addNewChildTnLst().addNewPar().addNewCTn();

            holdCtn2.setFill(STTLTimeNodeFillType.HOLD);
            holdCtn2.addNewStCondLst().addNewCond().setDelay(0);

            final CTTLCommonTimeNodeData clickCtn = holdCtn2.addNewChildTnLst().addNewPar().addNewCTn();

            clickCtn.setPresetID(10);
            clickCtn.setPresetClass(STTLTimeNodePresetClassType.EXIT);
            clickCtn.setPresetSubtype(0);
            clickCtn.setFill(STTLTimeNodeFillType.HOLD);
            clickCtn.setGrpId(0);
            clickCtn.setNodeType(STTLTimeNodeType.CLICK_EFFECT);

            clickCtn.addNewStCondLst().addNewCond().setDelay(0);

            final CTTimeNodeList clickChildTnList = clickCtn.addNewChildTnLst();

            final CTTLAnimateEffectBehavior animEffect = clickChildTnList.addNewAnimEffect();
            animEffect.setTransition(STTLAnimateEffectTransition.OUT);
            animEffect.setFilter("fade");
            final CTTLCommonBehaviorData cBhvr = animEffect.addNewCBhvr();
            final CTTLCommonTimeNodeData bhvrCtn = cBhvr.addNewCTn();

            bhvrCtn.setDur(500);
            cBhvr.addNewTgtEl().addNewSpTgt().setSpid(shapeId);

            final CTTLSetBehavior clickSet = clickChildTnList.addNewSet();
            final CTTLCommonBehaviorData clickSetBhvr = clickSet.addNewCBhvr();
            final CTTLCommonTimeNodeData hideCtn = clickSetBhvr.addNewCTn();

            hideCtn.setDur(1);
            hideCtn.setFill(STTLTimeNodeFillType.HOLD);
            hideCtn.addNewStCondLst().addNewCond().setDelay(499);

            clickSetBhvr.addNewTgtEl().addNewSpTgt().setSpid(shapeId);
            clickSetBhvr.addNewAttrNameLst().addAttrName("style.visibility");
            clickSet.addNewTo().addNewStrVal().setVal("hidden");

            final CTTLBuildParagraph bldP = bldLst.addNewBldP();
            bldP.setSpid(shapeId);
            bldP.setGrpId(0);
            bldP.setAnimBg(true);
        }
    }
}

From source file:ImageOpByRomain.java

/**
 * <p>//from  w ww  .  ja  v  a2 s  . c o m
 * Creates a new color mixer filter. The specified color will be used to tint
 * the source image, with a mixing strength defined by <code>mixValue</code>.
 * </p>
 * 
 * @param mixColor
 *            the solid color to mix with the source image
 * @param mixValue
 *            the strength of the mix, between 0.0 and 1.0; if the specified
 *            value lies outside this range, it is clamped
 * @throws IllegalArgumentException
 *             if <code>mixColor</code> is null
 */
public ColorTintFilter(Color mixColor, float mixValue) {
    if (mixColor == null) {
        throw new IllegalArgumentException("mixColor cannot be null");
    }

    this.mixColor = mixColor;
    if (mixValue < 0.0f) {
        mixValue = 0.0f;
    } else if (mixValue > 1.0f) {
        mixValue = 1.0f;
    }
    this.mixValue = mixValue;

    int mix_r = (int) (mixColor.getRed() * mixValue);
    int mix_g = (int) (mixColor.getGreen() * mixValue);
    int mix_b = (int) (mixColor.getBlue() * mixValue);

    // Since we use only lookup tables to apply the filter, this filter
    // could be implemented as a LookupOp.
    float factor = 1.0f - mixValue;
    preMultipliedRed = new int[256];
    preMultipliedGreen = new int[256];
    preMultipliedBlue = new int[256];

    for (int i = 0; i < 256; i++) {
        int value = (int) (i * factor);
        preMultipliedRed[i] = value + mix_r;
        preMultipliedGreen[i] = value + mix_g;
        preMultipliedBlue[i] = value + mix_b;
    }
}

From source file:org.apache.pdfbox.pdmodel.edit.PDPageContentStream.java

/**
 * Set the stroking color, specified as RGB.
 *
 * @param color The color to set./*w  ww .  ja  va 2s .  co  m*/
 * @throws IOException If an IO error occurs while writing to the stream.
 */
public void setStrokingColor(Color color) throws IOException {
    ColorSpace colorSpace = color.getColorSpace();
    if (colorSpace.getType() == ColorSpace.TYPE_RGB) {
        setStrokingColor(color.getRed(), color.getGreen(), color.getBlue());
    } else if (colorSpace.getType() == ColorSpace.TYPE_GRAY) {
        color.getColorComponents(colorComponents);
        setStrokingColor(colorComponents[0]);
    } else if (colorSpace.getType() == ColorSpace.TYPE_CMYK) {
        color.getColorComponents(colorComponents);
        setStrokingColor(colorComponents[0], colorComponents[2], colorComponents[2], colorComponents[3]);
    } else {
        throw new IOException("Error: unknown colorspace:" + colorSpace);
    }
}

From source file:org.apache.pdfbox.pdmodel.edit.PDPageContentStream.java

/**
 * Set the non stroking color, specified as RGB.
 *
 * @param color The color to set./*from   w w  w.  j a  v  a  2  s .  c  o m*/
 * @throws IOException If an IO error occurs while writing to the stream.
 */
public void setNonStrokingColor(Color color) throws IOException {
    ColorSpace colorSpace = color.getColorSpace();
    if (colorSpace.getType() == ColorSpace.TYPE_RGB) {
        setNonStrokingColor(color.getRed(), color.getGreen(), color.getBlue());
    } else if (colorSpace.getType() == ColorSpace.TYPE_GRAY) {
        color.getColorComponents(colorComponents);
        setNonStrokingColor(colorComponents[0]);
    } else if (colorSpace.getType() == ColorSpace.TYPE_CMYK) {
        color.getColorComponents(colorComponents);
        setNonStrokingColor(colorComponents[0], colorComponents[2], colorComponents[2], colorComponents[3]);
    } else {
        throw new IOException("Error: unknown colorspace:" + colorSpace);
    }
}

From source file:net.sf.jabref.JabRefPreferences.java

/**
 * Stores a color in preferences./*from w  ww .ja v  a  2s.  c  o  m*/
 *
 * @param key The key for this setting.
 * @param color The Color to store.
 */
public void putColor(String key, Color color) {
    String rgb = String.valueOf(color.getRed()) + ':' + color.getGreen() + ':' + color.getBlue();
    put(key, rgb);
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.visio.informationflow.VisioInformationFlowExport.java

/**
 * Adds a defined set of custom properties to the GLXNode.
 * These properties will be exported to the Visio shapes as custom properties.
 * /*w  w w .  j a v  a 2  s .  c o  m*/
 * @param isRelease An InformationSystemRelease containing the attributes to add to the GLXNode.
 * @param node The corresponding graph node for the isRelease.
 * @param isName The formated name of the isRelease.
 */
private void addShapePropertiesToInsNode(InformationSystemRelease isRelease, GXLNode node, String isName) {

    setTextPropertyToNode(node, PROP_ID, isRelease.getId().toString());
    setTextPropertyToNode(node, PROP_APP_NAME_FULL, isName);
    setTextPropertyToNode(node, PROP_APP_INFORMATION_OBJECTS_FULL,
            GeneralHelper.makeConcatenatedNameStringForBbCollection(isRelease.getBusinessObjects()));
    String urlToEntity = this.retrieveXLinkUrlForIdentityEntity(isRelease,
            this.informationFlowOptions.getServerUrl());
    setTextPropertyToNode(node, PROP_XREF_URL, urlToEntity);

    // create a string containing all INS Domains, separated by a semicolon
    StringBuilder isdAttribute = new StringBuilder();
    // check if the user has the permission to read the INS Domains:
    if (UserContext.getCurrentPerms()
            .userHasFunctionalPermission(TypeOfFunctionalPermission.INFORMATIONSYSTEMDOMAIN)) {
        for (InformationSystemDomain isd : isRelease.getInformationSystemDomains()) {
            isdAttribute.append(isd.getName() + "(" + isd.getId() + ");");
        }
    }
    setTextPropertyToNode(node, PROP_APP_INS_DOMAIN, isdAttribute.toString());

    // create a string containing all assigned attributes, separated by a semicolon
    StringBuilder attributesString = new StringBuilder();
    Set<AttributeValueAssignment> avas = isRelease.getAttributeValueAssignments();
    for (AttributeValueAssignment ava : avas) {
        AttributeValue av = ava.getAttributeValue();
        AttributeType at = av.getAbstractAttributeType();
        AttributeTypeGroup atg = at.getAttributeTypeGroup();
        // check if the user has the permission to read the attributeGroup:
        if (UserContext.getCurrentPerms().userHasAttrTypeGroupPermission(atg,
                AttributeTypeGroupPermissionEnum.READ)) {
            attributesString.append("(" + at.getName() + ")=" + av.getLocalizedValueString(getLocale()) + ";");
        }
    }
    setTextPropertyToNode(node, PROP_ATTRIBUTES, attributesString.toString());

    setTextPropertyToNode(node, PROP_APP_VERSION, isRelease.getVersion());
    setTextPropertyToNode(node, PROP_STATUS, mapTypeOfStatusVisioExport(isRelease.getTypeOfStatus()));
    setTextPropertyToNode(node, PROP_DESCRIPTION, isRelease.getDescription());
    setTextPropertyToNode(node, PROP_START_DATE,
            DateUtils.formatAsStringToDefault(isRelease.runtimeStartsAt(), getLocale()));
    setTextPropertyToNode(node, PROP_END_DATE,
            DateUtils.formatAsStringToDefault(isRelease.runtimeEndsAt(), getLocale()));

    Color color = getColorDimension().getValue(isRelease);
    LOGGER.debug("Color for node: {0}", color);

    setTextPropertyToNode(node, PROP_COLOR_RED, String.valueOf(color.getRed()));
    setTextPropertyToNode(node, PROP_COLOR_GREEN, String.valueOf(color.getGreen()));
    setTextPropertyToNode(node, PROP_COLOR_BLUE, String.valueOf(color.getBlue()));
}

From source file:com.jcraft.weirdx.XColormap.java

@SuppressWarnings("unused")
static void reqLookupColor(Client c) throws IOException {
    int foo, n;/*www . ja  v  a  2 s  .c o  m*/
    InputOutput io = c.client;

    n = c.length;
    foo = io.readInt();
    XColormap cmap = (XColormap) XResource.lookupIDByType(foo, XResource.RT_COLORMAP);
    c.length -= 2;
    if (cmap == null) {
        c.errorValue = foo;
        c.errorReason = 12; // Colormap
        return;
    }

    foo = io.readShort();
    io.readPad(2);
    io.readByte(c.bbuffer, 0, foo);
    io.readPad((-foo) & 3);
    c.length = 0;
    foo = chopspace(c.bbuffer, foo);
    if (foo == 0) {
        c.errorReason = 2; // BadValue
        return;
    }
    String s = new String(c.bbuffer, 0, foo);
    Color color = (Color) rgbTable.get(s);
    if (color != null) {
        synchronized (io) {
            io.writeByte(1);
            io.writePad(1);
            io.writeShort(c.seq);
            io.writeInt(0);

            foo = color.getRed();
            io.writeShort(foo | (foo << 8));
            foo = color.getGreen();
            io.writeShort(foo | (foo << 8));
            foo = color.getBlue();
            io.writeShort(foo | (foo << 8));
            foo = color.getRed();
            io.writeShort(foo | (foo << 8));
            foo = color.getGreen();
            io.writeShort(foo | (foo << 8));
            foo = color.getBlue();
            io.writeShort(foo | (foo << 8));
            io.writePad(12);
            io.flush();
            return;
        }
    }

    synchronized (io) {
        io.writeByte((byte) 0);
        io.writeByte((byte) 15);
        io.writeShort(c.seq);
        io.writePad(4);
        io.writeShort(0);
        io.writeByte((byte) 92);
        io.writePad(21);
        io.flush();
    }
}

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

/**
 * Returns <code>true</code> if the passed color is a dark color,
 * <code>false</code> otherwise.
 * //from  w  w w.  java2s.c o  m
 * @param c The color to handle. Mustn't be <code>null</code>.
 * @return See above.
 */
public static boolean isDarkColor(Color c) {
    if (c == null)
        return false;
    return (c.getRed() + c.getGreen() + c.getBlue()) / 3 < 128;
}

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

/**
 * Returns {@link #RED}, {@link #RED} or {@link #RED} to indicate the
 * range of the color.//from   w w w  .  j a v  a2  s. c o  m
 * 
 * @param color The color to handle.
 * @return See above
 */
public static int getColorRange(Color color) {
    if (color == null)
        return -1;
    int r = color.getRed();
    int g = color.getGreen();
    int b = color.getBlue();
    if (g < r / 2 && b < r / 2)
        return RED_COLOR;
    if (r < g / 2 && b < g / 2)
        return GREEN_COLOR;
    return BLUE_COLOR;
}

From source file:net.sf.jasperreports.engine.export.JRRtfExporter.java

/**
 *
 */// w  w  w . ja v a  2s .  c  o m
private int getColorRGB(Color color) {
    return color.getRed() + 256 * color.getGreen() + 65536 * color.getBlue();
}