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.eclipse.birt.chart.device.svg.SVGGraphics2D.java

public void setXORMode(Color xorColor) {
    if ((color == null) || (xorColor == null))
        return;//from ww w . j  a  va  2s  . com

    int newColor = ((xorColor.getRed() << 16) + (xorColor.getGreen() << 8) + xorColor.getBlue())
            ^ ((color.getRed() << 16) + (color.getGreen() << 8) + color.getBlue());
    int r = newColor >> 16 & 0x0000FF;
    int g = (0x00FF00 & newColor) >> 8;
    int b = 0x0000FF & newColor;
    color = new Color(r, g, b);
}

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

/**
 * Set a colour to a randomly chosen one
 *
 * @param source The button that was pressed to produce this action
 * @param index The index of the colour parameter to be set
 *///w  w w  .j  a  va  2s . c o m
protected void randomizeColour(JButton source, int index) {
    final Color newColour = randomColour();

    source.setBackground(newColour);

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

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

From source file:ca.sqlpower.architect.swingui.SwingUIProjectLoader.java

private void savePlayPenComponents(PrintWriter out, PlayPen pp) {
    List<PlayPenComponent> ppcs = new ArrayList<PlayPenComponent>();
    ppcs.addAll(pp.getContentPane().getChildren());
    Collections.reverse(ppcs);//www.ja  va 2s. co m

    // save the container panes.
    for (PlayPenComponent ppc : ppcs) {
        if (ppc instanceof TablePane) {
            TablePane tp = (TablePane) ppc;
            Point p = tp.getLocation();

            if (sqlObjectSaveIdMap.get(tp.getModel()) == null) {
                logger.error("Play pen tried to save a table pane at " + tp.getX() + ", " + tp.getY()
                        + " with the model " + tp.getModel() + " and reference id "
                        + sqlObjectSaveIdMap.get(tp.getModel()) + "."
                        + "\nSaving a table pane with a null reference will cause an NPE on loading.");
                throw new NullPointerException("Play pen table is saving a null reference.");
            }

            Color bgColor = tp.getBackgroundColor();
            String bgColorString = String.format("0x%02x%02x%02x", bgColor.getRed(), bgColor.getGreen(), //$NON-NLS-1$
                    bgColor.getBlue());
            Color fgColor = tp.getForegroundColor();
            String fgColorString = String.format("0x%02x%02x%02x", fgColor.getRed(), fgColor.getGreen(), //$NON-NLS-1$
                    fgColor.getBlue());

            ioo.println(out, "<table-pane table-ref=" + quote(sqlObjectSaveIdMap.get(tp.getModel())) //$NON-NLS-1$
                    + " x=\"" + p.x + "\" y=\"" + p.y + "\" bgColor=" + quote(bgColorString) + " fgColor=" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
                    + quote(fgColorString) + " rounded=\"" + tp.isRounded() + "\" dashed=\"" + tp.isDashed() + "\"/>"); //$NON-NLS-2$ //$NON-NLS-3$
            if (pm != null) {
                pm.setProgress(++progress);
            }
        } else if (ppc instanceof CubePane) {
            CubePane cp = (CubePane) ppc;
            Point p = cp.getLocation();

            String modelId = olapObjectSaveIdMap.get(cp.getModel());
            String paneId = "CP" + olapPaneSaveIdMap.size(); //$NON-NLS-1$

            ioo.println(out, "<cube-pane id=" + quote(paneId) + " model-ref=" + quote(modelId) //$NON-NLS-1$ //$NON-NLS-2$
                    + " x=\"" + p.x + "\" y=\"" + p.y + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            olapPaneSaveIdMap.put(cp, paneId);
        } else if (ppc instanceof DimensionPane) {
            DimensionPane dp = (DimensionPane) ppc;
            Point p = dp.getLocation();

            String paneId = "DP" + olapPaneSaveIdMap.size();
            String modelId = olapObjectSaveIdMap.get(dp.getModel());

            ioo.println(out, "<dimension-pane id=" + quote(paneId) + " model-ref=" + quote(modelId) //$NON-NLS-1$ //$NON-NLS-2$
                    + " x=\"" + p.x + "\" y=\"" + p.y + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            olapPaneSaveIdMap.put(dp, paneId);
        } else if (ppc instanceof VirtualCubePane) {
            VirtualCubePane vcp = (VirtualCubePane) ppc;
            Point p = vcp.getLocation();

            String paneId = "VCP" + olapPaneSaveIdMap.size();
            String modelId = olapObjectSaveIdMap.get(vcp.getModel());

            ioo.println(out, "<virtual-cube-pane id=" + quote(paneId) + " model-ref=" + quote(modelId) //$NON-NLS-1$ //$NON-NLS-2$
                    + " x=\"" + p.x + "\" y=\"" + p.y + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            olapPaneSaveIdMap.put(vcp, paneId);
        } else if (ppc instanceof ContainerPane<?, ?>) {
            logger.warn("Skipping unhandled playpen component: " + ppc); //$NON-NLS-1$
        }
    }

    // save the connectors.
    for (PlayPenComponent ppc : ppcs) {
        if (ppc instanceof Relationship) {
            Relationship r = (Relationship) ppc;

            Color relationshipLineColor = r.getForegroundColor();
            String rColorString = String.format("0x%02x%02x%02x", relationshipLineColor.getRed(), //$NON-NLS-1$
                    relationshipLineColor.getGreen(), relationshipLineColor.getBlue());

            ioo.println(out, "<table-link relationship-ref=" + quote(sqlObjectSaveIdMap.get(r.getModel())) //$NON-NLS-1$
                    + " pkConnection=\"" + r.getPkConnection() + "\"" //$NON-NLS-1$ //$NON-NLS-2$
                    + " fkConnection=\"" + r.getFkConnection() + "\"" //$NON-NLS-1$ //$NON-NLS-2$
                    + " rLineColor=" + quote(rColorString) //$NON-NLS-1$
                    + " pkLabelText=" + quote(r.getTextForParentLabel()) //$NON-NLS-1$
                    + " fkLabelText=" + quote(r.getTextForChildLabel()) //$NON-NLS-1$
                    + " orientation=\"" + r.getOrientation() + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
        } else if (ppc instanceof UsageComponent) {
            UsageComponent usageComp = (UsageComponent) ppc;
            String modelId = olapObjectSaveIdMap.get(usageComp.getModel());
            String pane1Id = olapPaneSaveIdMap.get(usageComp.getPane1());
            String pane2Id = olapPaneSaveIdMap.get(usageComp.getPane2());

            ioo.println(out, "<usage-comp model-ref=" + quote(modelId) + //$NON-NLS-1$
                    " pane1-ref=" + quote(pane1Id) + " pane2-ref=" + quote(pane2Id) + "/>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        } else if (ppc instanceof ContainerPane<?, ?>) {
            // do nothing, already handled.
        } else {
            logger.warn("Skipping unhandled playpen component: " + ppc); //$NON-NLS-1$
        }
    }
}

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

/**
 * Set the stroking color using an AWT color. Conversion uses the default sRGB color space.
 *
 * @param color The color to set./*from w ww.j a v  a  2 s .  co m*/
 * @throws IOException If an IO error occurs while writing to the stream.
 */
public void setStrokingColor(Color color) throws IOException {
    float[] components = new float[] { color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f };
    PDColor pdColor = new PDColor(components, PDDeviceRGB.INSTANCE);
    setStrokingColor(pdColor);
}

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

/**
 * Set the non-stroking color using an AWT color. Conversion uses the default sRGB color space.
 *
 * @param color The color to set./*  w  w w . ja  v  a 2 s .co  m*/
 * @throws IOException If an IO error occurs while writing to the stream.
 */
public void setNonStrokingColor(Color color) throws IOException {
    float[] components = new float[] { color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f };
    PDColor pdColor = new PDColor(components, PDDeviceRGB.INSTANCE);
    setNonStrokingColor(pdColor);
}

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

/**
 *
 *//*from  w  w w  .j a va  2  s . 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:savant.view.tracks.BAMTrackRenderer.java

/**
 * Render the individual bases on top of the read. Depending on the drawing
 * mode this can be either bases read or mismatches.
 *///ww w.ja  v  a  2s  .c o m
private void renderBases(Graphics2D g2, GraphPaneAdapter gp, SAMRecord samRecord, int level, byte[] refSeq,
        Range range, double unitHeight) {

    ColourScheme cs = (ColourScheme) instructions.get(DrawingInstruction.COLOUR_SCHEME);

    boolean baseQualityEnabled = (Boolean) instructions.get(DrawingInstruction.BASE_QUALITY);
    boolean drawingAllBases = lastMode == DrawingMode.SEQUENCE || baseQualityEnabled;

    double unitWidth = gp.getUnitWidth();
    int offset = gp.getOffset();

    // Cutoffs to determine when not to draw
    double leftMostX = gp.transformXPos(range.getFrom());
    double rightMostX = gp.transformXPos(range.getTo()) + unitWidth;

    int alignmentStart = samRecord.getAlignmentStart();

    byte[] readBases = samRecord.getReadBases();
    byte[] baseQualities = samRecord.getBaseQualities();
    boolean sequenceSaved = readBases.length > 0;
    Cigar cigar = samRecord.getCigar();

    // Absolute positions in the reference sequence and the read bases, set after each cigar operator is processed
    int sequenceCursor = alignmentStart;
    int readCursor = alignmentStart;
    List<Rectangle2D> insertions = new ArrayList<Rectangle2D>();

    FontMetrics fm = g2.getFontMetrics(MISMATCH_FONT);
    Rectangle2D charRect = fm.getStringBounds("G", g2);
    boolean fontFits = charRect.getWidth() <= unitWidth && charRect.getHeight() <= unitHeight;
    if (fontFits) {
        g2.setFont(MISMATCH_FONT);
    }
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    for (CigarElement cigarElement : cigar.getCigarElements()) {

        int operatorLength = cigarElement.getLength();
        CigarOperator operator = cigarElement.getOperator();
        Rectangle2D.Double opRect = null;

        double opStart = gp.transformXPos(sequenceCursor);
        double opWidth = operatorLength * unitWidth;

        // Cut off start and width so no drawing happens off-screen, must be done in the order w, then x, since w depends on first value of x
        double x2 = Math.min(rightMostX, opStart + opWidth);
        opStart = Math.max(leftMostX, opStart);
        opWidth = x2 - opStart;

        switch (operator) {
        case D: // Deletion
            if (opWidth > 0.0) {
                renderDeletion(g2, gp, opStart, level, operatorLength, unitHeight);
            }
            break;

        case I: // Insertion
            insertions.add(new Rectangle2D.Double(gp.transformXPos(sequenceCursor),
                    gp.transformYPos(0) - ((level + 1) * unitHeight) - gp.getOffset(), unitWidth, unitHeight));
            break;

        case M: // Match or mismatch
        case X:
        case EQ:
            // some SAM files do not contain the read bases
            if (sequenceSaved || operator == CigarOperator.X) {
                for (int i = 0; i < operatorLength; i++) {
                    // indices into refSeq and readBases associated with this position in the cigar string
                    int readIndex = readCursor - alignmentStart + i;
                    boolean mismatched = false;
                    if (operator == CigarOperator.X) {
                        mismatched = true;
                    } else {
                        int refIndex = sequenceCursor + i - range.getFrom();
                        if (refIndex >= 0 && refSeq != null && refIndex < refSeq.length) {
                            mismatched = refSeq[refIndex] != readBases[readIndex];
                        }
                    }

                    if (mismatched || drawingAllBases) {
                        Color col;
                        if ((mismatched && lastMode != DrawingMode.STANDARD)
                                || lastMode == DrawingMode.SEQUENCE) {
                            col = cs.getBaseColor((char) readBases[readIndex]);
                        } else {
                            col = cs.getColor(samRecord.getReadNegativeStrandFlag() ? ColourKey.REVERSE_STRAND
                                    : ColourKey.FORWARD_STRAND);
                        }

                        if (baseQualityEnabled && col != null) {
                            col = new Color(col.getRed(), col.getGreen(), col.getBlue(), getConstrainedAlpha(
                                    (int) Math.round((baseQualities[readIndex] * 0.025) * 255)));
                        }

                        double xCoordinate = gp.transformXPos(sequenceCursor + i);
                        double top = gp.transformYPos(0) - ((level + 1) * unitHeight) - offset;
                        if (col != null) {
                            opRect = new Rectangle2D.Double(xCoordinate, top, unitWidth, unitHeight);
                            g2.setColor(col);
                            g2.fill(opRect);
                        }
                        if (lastMode != DrawingMode.SEQUENCE && mismatched && fontFits) {
                            // If it's a real mismatch, we want to draw the base letter (space permitting).
                            g2.setColor(new Color(10, 10, 10));
                            String s = new String(readBases, readIndex, 1);
                            charRect = fm.getStringBounds(s, g2);
                            g2.drawString(s, (float) (xCoordinate + (unitWidth - charRect.getWidth()) * 0.5),
                                    (float) (top + fm.getAscent() + (unitHeight - charRect.getHeight()) * 0.5));
                        }
                    }
                }
            }
            break;

        case N: // Skipped
            opRect = new Rectangle2D.Double(opStart, gp.transformYPos(0) - ((level + 1) * unitHeight) - offset,
                    opWidth, unitHeight);
            g2.setColor(cs.getColor(ColourKey.SKIPPED));
            g2.fill(opRect);
            break;

        default: // P - passing, H - hard clip, or S - soft clip
            break;
        }
        if (operator.consumesReadBases()) {
            readCursor += operatorLength;
        }
        if (operator.consumesReferenceBases()) {
            sequenceCursor += operatorLength;
        }
    }
    for (Rectangle2D ins : insertions) {
        drawInsertion(g2, ins.getX(), ins.getY(), ins.getWidth(), ins.getHeight());
    }
}

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

/**
 *
 *//*from   ww w . j  a  v  a2  s .  c o  m*/
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: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 .ja va 2s.  c  o  m
 */
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:lucee.runtime.img.Image.java

public void shear(float shear, ShearDir direction, Object interpolation) throws ExpressionException {
    ParameterBlock params = new ParameterBlock();
    params.addSource(image());//ww w  .j  av  a 2s . com
    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());
}