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:com.dlya.facturews.DlyaPdfExporter2.java

protected 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, jasperPrint.getPageHeight() - y, frame.getWidth(), -frame.getHeight());
        pdfContentByte.fill();/*from   www  .  jav a2  s .c  o m*/
    }

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

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

From source file:slash.navigation.mapview.browser.BrowserMapView.java

String asColor(Color color) {
    return encodeByte((byte) color.getRed()) + encodeByte((byte) color.getGreen())
            + encodeByte((byte) color.getBlue());
}

From source file:com.dlya.facturews.DlyaPdfExporter2.java

/**
 *
 *//*www  .j a  va 2 s  . co m*/
public void exportText(JRPrintText text) throws DocumentException {
    AbstractPdfTextRenderer textRenderer = text.getLeadingOffset() == 0
            ? new PdfTextRenderer(jasperReportsContext,
                    getPropertiesUtil().getBooleanProperty(JRStyledText.PROPERTY_AWT_IGNORE_MISSING_FONT))
            : new SimplePdfTextRenderer(jasperReportsContext,
                    getPropertiesUtil().getBooleanProperty(JRStyledText.PROPERTY_AWT_IGNORE_MISSING_FONT)//FIXMECONTEXT replace with getPropertiesUtil in all exporters
            );//FIXMETAB optimize this

    textRenderer.initialize(this, pdfContentByte, text, getOffsetX(), getOffsetY());

    JRStyledText styledText = textRenderer.getStyledText();

    if (styledText == null) {
        return;
    }

    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(), jasperPrint.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(), jasperPrint.getPageHeight() - textRenderer.getY(),
                textRenderer.getWidth(), -textRenderer.getHeight());
        pdfContentByte.fill();
    }

    if (styledText.length() > 0) {
        //tagHelper.startText();

        /*   */
        textRenderer.render();

        //tagHelper.endText();
    }

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

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

From source file:com.projity.contrib.calendar.JXXMonthView.java

/**
 * {@inheritDoc}//  w ww  . jav a  2 s .  com
 */
protected void paintComponent(Graphics g) {
    Object oldAAValue = null;
    Graphics2D g2 = (g instanceof Graphics2D) ? (Graphics2D) g : null;
    if (g2 != null && _antiAlias) {
        oldAAValue = g2.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
        g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    }

    Rectangle clip = g.getClipBounds();

    updateIfNecessary();

    if (isOpaque()) {
        g.setColor(getBackground());
        g.fillRect(clip.x, clip.y, clip.width, clip.height);
    }
    g.setColor(getForeground());
    Color shadowColor = g.getColor();
    shadowColor = new Color(shadowColor.getRed(), shadowColor.getGreen(), shadowColor.getBlue(),
            (int) (.20 * 255));

    FontMetrics fm = g.getFontMetrics();

    // Reset the calendar.
    _cal.setTimeInMillis(_firstDisplayedDate);

    // Center the calendars vertically in the available space.
    int y = _startY;
    for (int row = 0; row < _numCalRows; row++) {
        // Center the calendars horizontally in the available space.
        int x = _startX;
        int tmpX, tmpY;

        // Check if this row falls in the clip region.
        _bounds.x = 0;
        _bounds.y = _startY + row * (_calendarHeight + CALENDAR_SPACING);
        _bounds.width = getWidth();
        _bounds.height = _calendarHeight;

        if (!_bounds.intersects(clip)) {
            _cal.add(Calendar.MONTH, _numCalCols);
            y += _calendarHeight + CALENDAR_SPACING;
            continue;
        }

        for (int column = 0; column < _numCalCols; column++) {
            String monthName = _monthsOfTheYear[_cal.get(Calendar.MONTH)];
            monthName = monthName + " " + _cal.get(Calendar.YEAR);

            _bounds.x = _ltr ? x : x - _calendarWidth;
            _bounds.y = y + _boxPaddingY;
            _bounds.width = _calendarWidth;
            _bounds.height = _boxHeight;

            if (_bounds.intersects(clip)) {
                // Paint month name background.
                paintMonthStringBackground(g, _bounds.x, _bounds.y, _bounds.width, _bounds.height);

                // Paint month name.
                g.setColor(getForeground());
                tmpX = _ltr ? x + (_calendarWidth / 2) - (fm.stringWidth(monthName) / 2)
                        : x - (_calendarWidth / 2) - (fm.stringWidth(monthName) / 2) - 1;
                tmpY = y + _boxPaddingY + _boxHeight - fm.getDescent();

                g.drawString(monthName, tmpX, tmpY);

                if ((_dropShadowMask & MONTH_DROP_SHADOW) != 0) {
                    g.setColor(shadowColor);
                    g.drawString(monthName, tmpX + 1, tmpY + 1);
                    g.setColor(getForeground());
                }
            }

            _bounds.x = _ltr ? x : x - _calendarWidth;
            _bounds.y = y + _boxPaddingY + _boxHeight + _boxPaddingY + _boxPaddingY;
            _bounds.width = _calendarWidth;
            _bounds.height = _boxHeight;

            if (_bounds.intersects(clip)) {
                _cal.set(Calendar.DAY_OF_MONTH, _cal.getActualMinimum(Calendar.DAY_OF_MONTH));
                Calendar weekCal = (Calendar) _cal.clone();
                // Paint short representation of day of the week.
                int dayIndex = _firstDayOfWeek - 1;
                int month = weekCal.get(Calendar.MONTH);
                //               dayIndex = (_cal.get(Calendar.DAY_OF_WEEK) -1) %7;
                for (int i = 0; i < DAYS_IN_WEEK; i++) {
                    //                  PROJITY_MODIFICATION
                    // set the week calendar to the current day of week and make sure it's still in this month
                    weekCal.set(Calendar.DAY_OF_WEEK, dayIndex + 1);
                    if (weekCal.get(Calendar.MONTH) != month)
                        weekCal.roll(Calendar.DAY_OF_YEAR, 7); // make sure in this month

                    tmpX = _ltr
                            ? x + (i * (_boxPaddingX + _boxWidth + _boxPaddingX)) + _boxPaddingX
                                    + (_boxWidth / 2) - (fm.stringWidth(_daysOfTheWeek[dayIndex]) / 2)
                            : x - (i * (_boxPaddingX + _boxWidth + _boxPaddingX)) - _boxPaddingX
                                    - (_boxWidth / 2) - (fm.stringWidth(_daysOfTheWeek[dayIndex]) / 2);
                    tmpY = y + _boxPaddingY + _boxHeight + _boxPaddingY + _boxPaddingY + fm.getAscent();
                    boolean flagged = _flaggedWeekDates[dayIndex];
                    boolean colored = _coloredWeekDates[dayIndex];
                    calculateBoundsForDay(_bounds, weekCal, true);
                    drawDay(colored, flagged, false, g, _daysOfTheWeek[dayIndex], tmpX, tmpY);

                    //                  if ((_dropShadowMask & WEEK_DROP_SHADOW) != 0) {
                    //                     calculateBoundsForDay(_bounds,weekCal,true); // add shadow arg
                    //                     drawDay(colored,flagged,false,g,_daysOfTheWeek[dayIndex], tmpX + 1,
                    //                           tmpY + 1);
                    //                  }
                    if (_selectedWeekDays[dayIndex]) {
                        paintSelectedDayBackground(g, _bounds.x, _bounds.y, _bounds.width, _bounds.height);
                    }
                    dayIndex++;
                    if (dayIndex == 7) {
                        dayIndex = 0;
                    }
                }

                int lineOffset = 2;
                // Paint a line across bottom of days of the week.
                g.drawLine(_ltr ? x + 2 : x - 3, lineOffset + y + (_boxPaddingY * 3) + (_boxHeight * 2),
                        _ltr ? x + _calendarWidth - 3 : x - _calendarWidth + 2,
                        lineOffset + y + (_boxPaddingY * 3) + (_boxHeight * 2));
                if ((_dropShadowMask & MONTH_LINE_DROP_SHADOW) != 0) {
                    g.setColor(shadowColor);
                    g.drawLine(_ltr ? x + 3 : x - 2, y + (_boxPaddingY * 3) + (_boxHeight * 2) + 1,
                            _ltr ? x + _calendarWidth - 2 : x - _calendarWidth + 3,
                            y + (_boxPaddingY * 3) + (_boxHeight * 2) + 1);
                    g.setColor(getForeground());
                }
            }

            // Check if the month to paint falls in the clip.
            _bounds.x = _startX + (_ltr ? column * (_calendarWidth + CALENDAR_SPACING)
                    : -(column * (_calendarWidth + CALENDAR_SPACING) + _calendarWidth));
            _bounds.y = _startY + row * (_calendarHeight + CALENDAR_SPACING);
            _bounds.width = _calendarWidth;
            _bounds.height = _calendarHeight;

            // Paint the month if it intersects the clip. If we don't move
            // the calendar forward a month as it would have if paintMonth
            // was called.
            if (_bounds.intersects(clip)) {
                paintMonth(g, column, row);
            } else {
                _cal.add(Calendar.MONTH, 1);
            }

            x += _ltr ? _calendarWidth + CALENDAR_SPACING : -(_calendarWidth + CALENDAR_SPACING);
        }
        y += _calendarHeight + CALENDAR_SPACING;
    }

    // Restore the calendar.
    _cal.setTimeInMillis(_firstDisplayedDate);
    if (g2 != null && _antiAlias) {
        g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, oldAAValue);
    }
}

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

public void modifyPointLight(int k, PointLightParams par, boolean on) {
    if (k < 0 || k >= pointLights.size()) {
        return;//from   w  w w.ja va  2s . co m
    }
    EditablePointLight l = pointLights.get(k);
    l.setEnabled(on);
    Color c = par.getColor();
    l.setLightColor(new Color3f(c.getRed() / 512.f, c.getGreen() / 512.f, c.getGreen() / 512.f));
    l.setAttenuation(par.getConstantAttenuation(), par.getLinearAttenuation(), par.getQuadraticAttenuation());
}

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

private void alloc(int i, Color color) {
    colors[i] = color;// ww w  .ja  v a 2 s. co  m
    r[i] = (byte) color.getRed();
    g[i] = (byte) color.getGreen();
    b[i] = (byte) color.getBlue();
}

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

protected void setColourUsed(Colour colour, Color reportColour) {
    if (log.isDebugEnabled()) {
        log.debug("Modifying palette colour " + colour.getValue() + " to " + reportColour);
    }//from   w  w w.j a  va  2  s .  c o m

    int red = reportColour.getRed();
    int green = reportColour.getGreen();
    int blue = reportColour.getBlue();

    workbook.setColourRGB(colour, red, green, blue);

    RGB customRGB = new RGB(red, green, blue);
    usedColours.put(colour, customRGB);
}

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

protected void setColourUsed(Colour colour, Color reportColour) {
    if (log.isDebugEnabled()) {
        log.debug("Modifying palette colour " + colour.getValue() + " to " + reportColour);
    }//from   w  w w  .  j  ava  2 s. c  om

    int red = reportColour.getRed();
    int green = reportColour.getGreen();
    int blue = reportColour.getBlue();

    workbook.setColourRGB(colour, red, green, blue);
    RGB customRGB = new RGB(red, green, blue);
    usedColours.put(colour, customRGB);
}

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>//from  w  w  w  .  ja  v  a2 s. com
 * 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:net.sf.jasperreports.engine.export.JRXlsMetadataExporter.java

/**
 *
 *///from ww w .j a  v  a  2s .  c  o  m
protected HSSFColor getWorkbookColor(Color awtColor) {
    HSSFColor color = null;
    if (awtColor != null) {
        byte red = (byte) awtColor.getRed();
        byte green = (byte) awtColor.getGreen();
        byte blue = (byte) awtColor.getBlue();

        XlsExporterConfiguration configuration = getCurrentConfiguration();

        if (configuration.isCreateCustomPalette()) {
            try {
                color = palette.findColor(red, green, blue) != null ? palette.findColor(red, green, blue)
                        : palette.addColor(red, green, blue);
            } catch (Exception e) {
                if (customColorIndex < MAX_COLOR_INDEX) {
                    palette.setColorAtIndex(customColorIndex, red, green, blue);
                    color = palette.getColor(customColorIndex++);
                } else {
                    color = palette.findSimilarColor(red, green, blue);
                }
            }
        }
    }
    return color == null ? getNearestColor(awtColor) : color;
}