Example usage for java.awt Color getBlue

List of usage examples for java.awt Color getBlue

Introduction

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

Prototype

public int getBlue() 

Source Link

Document

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

Usage

From source file:org.eclipse.birt.chart.device.svg.SVGGraphics2D.java

/**
 * @returns the color definition in a string with the format: #RRGGBBAA:
 *          RRGGBB are the color components in hexa in the range 00..FF AA
 *          is the transparency value in hexa in the range 00..FF ex: Solid
 *          light gray : #777777/*from   w ww  . ja v a  2  s  . com*/
 */
protected String serializeToString(Color color) {

    String r = Integer.toHexString(color.getRed());
    if (color.getRed() <= 0xF)
        r = "0" + r; //$NON-NLS-1$
    String g = Integer.toHexString(color.getGreen());
    if (color.getGreen() <= 0xF)
        g = "0" + g; //$NON-NLS-1$
    String b = Integer.toHexString(color.getBlue());
    if (color.getBlue() <= 0xF)
        b = "0" + b; //$NON-NLS-1$

    String ret = "#" + r + g + b; //$NON-NLS-1$
    return ret;
}

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

/**
 *
 *///from  w  ww  . ja v a2s.  c om
protected static HSSFColor getNearestColor(Color awtColor) {
    HSSFColor color = hssfColorsCache.get(awtColor);
    if (color == null) {
        Map<?, ?> triplets = HSSFColor.getTripletHash();
        if (triplets != null) {
            Collection<?> keys = triplets.keySet();
            if (keys != null && keys.size() > 0) {
                Object key = null;
                HSSFColor crtColor = null;
                short[] rgb = null;
                int diff = 0;
                int minDiff = 999;
                for (Iterator<?> it = keys.iterator(); it.hasNext();) {
                    key = it.next();
                    crtColor = (HSSFColor) triplets.get(key);
                    rgb = crtColor.getTriplet();
                    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:net.sf.jasperreports.engine.export.JRXlsExporter.java

/**
 *
 *//*from   w ww  .  ja  va2 s  .c om*/
protected HSSFColor getWorkbookColor(Color awtColor) {
    byte red = (byte) awtColor.getRed();
    byte green = (byte) awtColor.getGreen();
    byte blue = (byte) awtColor.getBlue();
    HSSFColor color = null;

    if (getCurrentConfiguration().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;
}

From source file:lucee.runtime.img.Image.java

public void shear(float shear, ShearDir direction, Object interpolation) throws ExpressionException {
    ParameterBlock params = new ParameterBlock();
    params.addSource(image());/*from  www.j ava2 s  .  co  m*/
    params.add(shear);
    params.add(direction);
    params.add(0.0F);
    params.add(0.0F);
    RenderingHints hints = null;

    if (interpolation == RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)
        params.add(Interpolation.getInstance(0));
    else if (interpolation == RenderingHints.VALUE_INTERPOLATION_BILINEAR) {
        params.add(Interpolation.getInstance(1));
        BorderExtender extender = BorderExtender.createInstance(1);
        hints = new RenderingHints(JAI.KEY_BORDER_EXTENDER, extender);
    } else if (interpolation == RenderingHints.VALUE_INTERPOLATION_BICUBIC) {
        params.add(Interpolation.getInstance(2));
        BorderExtender extender = BorderExtender.createInstance(1);
        hints = new RenderingHints(JAI.KEY_BORDER_EXTENDER, extender);
    }
    // TODO
    Color bg = getGraphics().getBackground();
    params.add(new double[] { bg.getRed(), bg.getGreen(), bg.getBlue() });
    image(JAI.create("shear", params, hints).getAsBufferedImage());
}

From source file:lucee.runtime.img.Image.java

/**
 * add a border to image//w  w w. j a va  2 s  .c  o m
 * @param thickness
 * @param color
 * @param borderType 
 */
public void addBorder(int thickness, Color color, int borderType) throws ExpressionException {

    double colorArray[] = { color.getRed(), color.getGreen(), color.getBlue() };
    BorderExtender borderExtender = new BorderExtenderConstant(colorArray);

    ParameterBlock params = new ParameterBlock();
    params.addSource(image());
    params.add(thickness);
    params.add(thickness);
    params.add(thickness);
    params.add(thickness);
    if (BORDER_TYPE_CONSTANT == borderType)
        params.add(borderExtender);
    else
        params.add(BorderExtender.createInstance(borderType));
    //else if(BORDER_TYPE_WRAP==borderType)params.add(BorderExtender.createInstance(BorderExtender.BORDER_REFLECT));

    image((JAI.create("border", params)).getAsBufferedImage());

}

From source file:com.alvermont.terraj.planet.ui.MainFrame.java

/**
 * Bring up a colour selector for the specified colour and set the
 * corresponding colour parameter if the user picks a new one
 *
 * @param source The button that was pressed to produce this action
 * @param label The string to be displayed by the colour dialog
 * @param index The index of the colour parameter to be set
 * @return The new colour that was chosen or <code>null</code> if the
 * user cancelled./*from  w  w w  . j a  va2  s  . c  om*/
 */
protected Color pickColour(JButton source, String label, int index) {
    final Color newColour = JColorChooser.showDialog(this, label, source.getBackground());

    if (newColour != null) {
        /// then a new colour was chosen
        source.setBackground(newColour);

        final int[][] colours = params.getProjectionParameters().getColors();

        colours[index][0] = newColour.getRed();
        colours[index][1] = newColour.getGreen();
        colours[index][2] = newColour.getBlue();
    }

    return newColour;
}

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();/* w  ww .ja  v a2s .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

/**
 *
 *///from   w  ww  .  j  a  v  a2s  .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}//from   ww  w .  java 2  s . c  o m
 */
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);
    }
}