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:org.apache.fop.afp.ptoca.PtocaBuilder.java

/**
 * The Set Extended Text Color control sequence specifies a color value and
 * defines the color space and encoding for that value. The specified color
 * value is applied to foreground areas of the text presentation space.
 * <p>// w  w  w.jav  a2s  . c  om
 * This is a modal control sequence.
 *
 * @param col The color to be set.
 * @throws IOException if an I/O error occurs
 */
public void setExtendedTextColor(Color col) throws IOException {
    if (ColorUtil.isSameColor(col, currentColor)) {
        return;
    }
    if (col instanceof ColorWithAlternatives) {
        ColorWithAlternatives cwa = (ColorWithAlternatives) col;
        Color alt = cwa.getFirstAlternativeOfType(ColorSpace.TYPE_CMYK);
        if (alt != null) {
            col = alt;
        }
    }
    ColorSpace cs = col.getColorSpace();

    newControlSequence();
    if (col.getColorSpace().getType() == ColorSpace.TYPE_CMYK) {
        // Color space - 0x04 = CMYK, all else are reserved and must be zero
        writeBytes(0x00, 0x04, 0x00, 0x00, 0x00, 0x00);
        writeBytes(8, 8, 8, 8); // Number of bits in component 1, 2, 3 & 4 respectively
        float[] comps = col.getColorComponents(null);
        assert comps.length == 4;
        for (int i = 0; i < 4; i++) {
            int component = Math.round(comps[i] * 255);
            writeBytes(component);
        }
    } else if (cs instanceof CIELabColorSpace) {
        // Color space - 0x08 = CIELAB, all else are reserved and must be zero
        writeBytes(0x00, 0x08, 0x00, 0x00, 0x00, 0x00);
        writeBytes(8, 8, 8, 0); // Number of bits in component 1,2,3 & 4
        //Sadly, 16 bit components don't seem to work
        float[] colorComponents = col.getColorComponents(null);
        int l = Math.round(colorComponents[0] * 255f);
        int a = Math.round(colorComponents[1] * 255f) - 128;
        int b = Math.round(colorComponents[2] * 255f) - 128;
        writeBytes(l, a, b); // l*, a* and b*
    } else {
        // Color space - 0x01 = RGB, all else are reserved and must be zero
        writeBytes(0x00, 0x01, 0x00, 0x00, 0x00, 0x00);
        writeBytes(8, 8, 8, 0); // Number of bits in component 1, 2, 3 & 4 respectively
        writeBytes(col.getRed(), col.getGreen(), col.getBlue()); // RGB intensity
    }
    commit(chained(SEC));
    this.currentColor = col;
}

From source file:pl.edu.icm.visnow.geometries.viewer3d.Display3DPanel.java

public void setBackgroundGradient(Color c0, Color c1, Color c2) {
    bgColor = new Color3f(c0.getColorComponents(null));
    myFog.setColor(bgColor);//from   w  w w  . j  a v  a 2s. com
    fireBgrColorChanged();
    int r0 = c0.getRed(), r1 = c1.getRed(), r2 = c2.getRed();
    int g0 = c0.getGreen(), g1 = c1.getGreen(), g2 = c2.getGreen();
    int b0 = c0.getBlue(), b1 = c1.getBlue(), b2 = c2.getBlue();
    int[] bgrData = new int[256 * 256];
    int k = 0;
    for (int i = 0; i < 128; i++) {
        float t = i / 127.f;
        int r = (int) (t * r1 + (1 - t) * r0);
        int g = (int) (t * g1 + (1 - t) * g0);
        int b = (int) (t * b1 + (1 - t) * b0);
        int c = ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);
        for (int j = 0; j < 256; j++, k++) {
            bgrData[k] = c;
        }
    }
    for (int i = 0; i < 128; i++) {
        float t = i / 127.f;
        int r = (int) (t * r2 + (1 - t) * r1);
        int g = (int) (t * g2 + (1 - t) * g1);
        int b = (int) (t * b2 + (1 - t) * b1);
        int c = ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);
        for (int j = 0; j < 256; j++, k++) {
            bgrData[k] = c;
        }
    }
    BufferedImage bgrImage = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB);
    bgrImage.setRGB(0, 0, 256, 256, bgrData, 0, 256);
    ImageComponent2D bgrImageComponent = new ImageComponent2D(ImageComponent2D.FORMAT_RGBA, bgrImage);
    bg.setImage(bgrImageComponent);
}

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

/**
 *
 *//*from  w  w w. j av a 2  s .  c  o m*/
protected HSSFColor getNearestColor(Color awtColor) {
    HSSFColor color = hssfColorsCache.get(awtColor);
    if (color == null) {
        int minDiff = Integer.MAX_VALUE;
        for (Map.Entry<HSSFColor, short[]> hssfColorEntry : hssfColorsRgbs.entrySet()) {
            HSSFColor crtColor = hssfColorEntry.getKey();
            short[] rgb = hssfColorEntry.getValue();

            int diff = Math.abs(rgb[0] - awtColor.getRed()) + Math.abs(rgb[1] - awtColor.getGreen())
                    + Math.abs(rgb[2] - awtColor.getBlue());

            if (diff < minDiff) {
                minDiff = diff;
                color = crtColor;
            }
        }

        hssfColorsCache.put(awtColor, color);
    }
    return color;
}

From source file:org.nuclos.client.layout.wysiwyg.LayoutMLGenerator.java

/**
 * Method for converting {@link Color} to LayoutML XML.
 *
 * @param color/*from   w  w w  .  j av a2s.  co  m*/
 * @return {@link StringBuffer} with the LayoutML
 */
private synchronized StringBuffer getLayoutMLColorAttributes(Color color) {
    StringBuffer sb = new StringBuffer();

    sb.append(" " + ATTRIBUTE_RED + "=\"");
    sb.append(color.getRed());
    sb.append("\" " + ATTRIBUTE_GREEN + "=\"");
    sb.append(color.getGreen());
    sb.append("\" " + ATTRIBUTE_BLUE + "=\"");
    sb.append(color.getBlue());
    sb.append("\"");

    return sb;

}

From source file:com.manydesigns.portofino.actions.admin.appwizard.ApplicationWizard.java

protected void setupCalendar(List<ChildPage> childPages) throws Exception {
    List<List<String>> calendarDefinitions = new ArrayList<List<String>>();
    Color[] colors = { Color.RED, new Color(64, 128, 255), Color.CYAN.darker(), Color.GRAY,
            Color.GREEN.darker(), Color.ORANGE, Color.YELLOW.darker(), Color.MAGENTA.darker(), Color.PINK };
    int colorIndex = 0;
    for (Table table : allTables) {
        List<Column> dateColumns = new ArrayList<Column>();
        for (Column column : table.getColumns()) {
            if (column.getActualJavaType() != null && Date.class.isAssignableFrom(column.getActualJavaType())) {
                dateColumns.add(column);
            }/*from w ww . jav a 2s. c  o m*/
        }
        if (!dateColumns.isEmpty()) {
            // ["Cal 1", "db1.schema1.table1", ["column1", "column2"], Color.RED]
            Color color = colors[colorIndex++ % colors.length];
            List<String> calDef = new ArrayList<String>();
            calDef.add('"' + Util.guessToWords(table.getActualEntityName()) + '"');
            calDef.add('"' + table.getQualifiedName() + '"');
            String cols = "[";
            boolean first = true;
            for (Column column : dateColumns) {
                if (first) {
                    first = false;
                } else {
                    cols += ", ";
                }
                cols += '"' + column.getActualPropertyName() + '"';
            }
            cols += "]";
            calDef.add(cols);
            calDef.add("new java.awt.Color(" + color.getRed() + ", " + color.getGreen() + ", " + color.getBlue()
                    + ")");
            calendarDefinitions.add(calDef);
        }
    }
    if (!calendarDefinitions.isEmpty()) {
        String calendarDefinitionsStr = "[";
        calendarDefinitionsStr += StringUtils.join(calendarDefinitions, ", ");
        calendarDefinitionsStr += "]";
        String baseName = "calendar-" + connectionProvider.getDatabase().getDatabaseName();
        File dir = new File(pagesDir, baseName);
        int retries = 1;
        while (dir.exists()) {
            retries++;
            dir = new File(pagesDir, baseName + "-" + retries);
        }
        if (dir.mkdirs()) {
            CalendarConfiguration configuration = new CalendarConfiguration();
            DispatcherLogic.saveConfiguration(dir, configuration);

            Page page = new Page();
            page.setId(RandomUtil.createRandomId());
            String calendarTitle = "Calendar (" + connectionProvider.getDatabase().getDatabaseName() + ")";
            if (retries > 1) {
                calendarTitle += " - " + retries;
            }
            page.setTitle(calendarTitle);
            page.setDescription(calendarTitle);

            DispatcherLogic.savePage(dir, page);
            File actionFile = new File(dir, "action.groovy");
            try {
                TemplateEngine engine = new SimpleTemplateEngine();
                Template template = engine
                        .createTemplate(ApplicationWizard.class.getResource("CalendarPage.groovy"));
                Map<String, Object> bindings = new HashMap<String, Object>();
                bindings.put("calendarDefinitions", calendarDefinitionsStr);
                FileWriter fw = new FileWriter(actionFile);
                template.make(bindings).writeTo(fw);
                IOUtils.closeQuietly(fw);
            } catch (Exception e) {
                logger.warn("Couldn't create calendar", e);
                SessionMessages.addWarningMessage("Couldn't create calendar: " + e);
                return;
            }

            ChildPage childPage = new ChildPage();
            childPage.setName(dir.getName());
            childPage.setShowInNavigation(true);
            childPages.add(childPage);
        } else {
            logger.warn("Couldn't create directory {}", dir.getAbsolutePath());
            SessionMessages.addWarningMessage(
                    ElementsThreadLocals.getText("couldnt.create.directory", dir.getAbsolutePath()));
        }
    }
}

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * @param color//from w  w  w  . ja v a  2s  . com
 * @return
 */
public static String getRGBHexFromColor(final Color color) {
    return getHexStr(color.getRed()) + getHexStr(color.getGreen()) + getHexStr(color.getBlue());
}

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * @param color The color to lighten/*from  ww  w  .  j a  va  2s.c  o  m*/
 * @param percentage to be added to the current value 0.0 > val < 1.0
 * @return
 */
public static Color makeLighter(final Color color, final double percentage) {
    int r = Math.min(color.getRed() + (int) (color.getRed() * percentage), 255);
    int g = Math.min(color.getGreen() + (int) (color.getGreen() * percentage), 255);
    int b = Math.min(color.getBlue() + (int) (color.getBlue() * percentage), 255);
    return new Color(r, g, b);
}

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * @param color The color to lighten//from  w  w w .  jav a 2s  .  co  m
 * @param percentage to be added to the current value 0.0 > val < 1.0
 * @return
 */
public static Color makeDarker(final Color color, final double percentage) {
    int r = Math.max(color.getRed() - (int) (color.getRed() * percentage), 0);
    int g = Math.max(color.getGreen() - (int) (color.getGreen() * percentage), 0);
    int b = Math.max(color.getBlue() - (int) (color.getBlue() * percentage), 0);
    return new Color(r, g, b);
}

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * @param color//from  w  w w  .j  a  v  a 2  s. c  o  m
 * @param delta
 * @return
 */
public static Color changeColorBrightness(final Color color, final double delta) {
    int r = (int) Math.min(color.getRed() * delta, 255.0);
    int g = (int) Math.min(color.getGreen() * delta, 255.0);
    int b = (int) Math.min(color.getBlue() * delta, 255.0);

    return new Color(r, g, b);
}

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

public void exportFrame(JRPrintFrame frame) throws DocumentException, IOException, JRException {
    if (frame.getModeValue() == ModeEnum.OPAQUE) {
        int x = frame.getX() + getOffsetX();
        int y = frame.getY() + getOffsetY();

        Color backcolor = frame.getBackcolor();
        pdfContentByte.setRGBColorFill(backcolor.getRed(), backcolor.getGreen(), backcolor.getBlue());
        pdfContentByte.rectangle(x, pageFormat.getPageHeight() - y, frame.getWidth(), -frame.getHeight());
        pdfContentByte.fill();/* w ww  .ja  v a 2 s .c o  m*/
    }

    setFrameElementsOffset(frame, false);
    try {
        exportElements(frame.getElements());
    } finally {
        restoreElementOffsets();
    }

    exportBox(frame.getLineBox(), frame);
}