Example usage for java.awt Color getGreen

List of usage examples for java.awt Color getGreen

Introduction

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

Prototype

public int getGreen() 

Source Link

Document

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

Usage

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  va  2  s .c  o  m
    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 ww  .ja  v 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//w ww.  java  2  s  .c o  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.  j  av  a2 s .  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 .  j av a 2s.  c om
 * @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/*from  w  ww  .jav  a 2 s.  com*/
 * @return
 */
public static String getBGRHexFromColor(final Color color) {
    return getHexStr(color.getBlue()) + getHexStr(color.getGreen()) + getHexStr(color.getRed());
}

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();/*ww  w. j a  va2  s.c  om*/
    }

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

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

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

/**
 * @param color//  w w  w  .  j  a v  a2  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

/**
 *
 *///from  w  ww .j  a v a 2  s  . co  m
public void exportText(JRPrintText text) throws DocumentException {
    JRStyledText styledText = styledTextUtil.getProcessedStyledText(text, noBackcolorSelector, null);

    if (styledText == null) {
        return;
    }

    AbstractPdfTextRenderer textRenderer = getTextRenderer(text, styledText);
    textRenderer.initialize(this, pdfContentByte, text, styledText, getOffsetX(), getOffsetY());

    double angle = 0;

    switch (text.getRotationValue()) {
    case LEFT: {
        angle = Math.PI / 2;
        break;
    }
    case RIGHT: {
        angle = -Math.PI / 2;
        break;
    }
    case UPSIDE_DOWN: {
        angle = Math.PI;
        break;
    }
    case NONE:
    default: {
    }
    }

    AffineTransform atrans = new AffineTransform();
    atrans.rotate(angle, textRenderer.getX(), pageFormat.getPageHeight() - textRenderer.getY());
    pdfContentByte.transform(atrans);

    if (text.getModeValue() == ModeEnum.OPAQUE) {
        Color backcolor = text.getBackcolor();
        pdfContentByte.setRGBColorFill(backcolor.getRed(), backcolor.getGreen(), backcolor.getBlue());
        pdfContentByte.rectangle(textRenderer.getX(), pageFormat.getPageHeight() - textRenderer.getY(),
                textRenderer.getWidth(), -textRenderer.getHeight());
        pdfContentByte.fill();
    }

    if (glyphRendererAddActualText && textRenderer instanceof PdfGlyphRenderer) {
        tagHelper.startText(styledText.getText(), text.getLinkType() != null);
    } else {
        tagHelper.startText(text.getLinkType() != null);
    }

    /* rendering only non empty texts  */
    if (styledText.length() > 0) {
        textRenderer.render();
    }
    tagHelper.endText();

    atrans = new AffineTransform();
    atrans.rotate(-angle, textRenderer.getX(), pageFormat.getPageHeight() - textRenderer.getY());
    pdfContentByte.transform(atrans);

    /*   */
    exportBox(text.getLineBox(), text);
}

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

/**
 * @param color The color to lighten/* ww w  .j a v  a  2s  . com*/
 * @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);
}