Example usage for java.awt Color getRGBColorComponents

List of usage examples for java.awt Color getRGBColorComponents

Introduction

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

Prototype

public float[] getRGBColorComponents(float[] compArray) 

Source Link

Document

Returns a float array containing only the color components of the Color , in the default sRGB color space.

Usage

From source file:Main.java

public static void main(String[] args) {

    Color myColor = Color.RED;

    System.out.println(Arrays.toString(myColor.getRGBColorComponents(null)));

}

From source file:net.sf.jasperreports.engine.fill.JRFillChart.java

/**
 * Converts a JasperReports meter interval to one that JFreeChart understands.
 *
 * @param interval the JasperReports definition of an interval
 * @param evaluation current evaluation time
 * @return the JFreeChart version of the same interval
 * @throws JRException thrown when the interval contains an invalid range
 *//*ww w .  j av a  2s .  c o  m*/
protected MeterInterval convertInterval(JRMeterInterval interval, byte evaluation) throws JRException {
    String label = interval.getLabel();
    if (label == null) {
        label = "";
    }

    Range range = convertRange(interval.getDataRange(), evaluation);

    Color color = interval.getBackgroundColor();
    float[] components = color.getRGBColorComponents(null);
    float alpha = (float) (interval.getAlphaDouble() == null ? JRMeterInterval.DEFAULT_TRANSPARENCY
            : interval.getAlphaDouble());

    Color alphaColor = new Color(components[0], components[1], components[2], alpha);

    return new MeterInterval(label, range, alphaColor, null, alphaColor);
}

From source file:musite.ui.MusiteResultPanel.java

private Color invertColor(Color color) {
    float[] rgb = color.getRGBColorComponents(null);
    return new Color(1 - rgb[0], 1 - rgb[1], 1 - rgb[2]);
}

From source file:musite.ui.MusiteResultPanel.java

private Color getColorOfSite(double score) {
    double leftScore = 0;
    double rightScore = 0;

    for (double tick : mapScoreColor.keySet()) {
        if (Math.abs(tick - score) < (maxScore - minScore) / maxTick / 2)
            return mapScoreColor.get(tick);

        if (tick < score) {
            leftScore = tick;// ww  w. j  a  v  a  2  s .c o m
        } else {
            rightScore = tick;
            break;
        }
    }

    Color leftColor = mapScoreColor.get(leftScore);
    Color rightColor = mapScoreColor.get(rightScore);

    float[] leftRGB = leftColor.getRGBColorComponents(null);
    float[] rightRGB = rightColor.getRGBColorComponents(null);

    float perc = (float) ((score - leftScore) / (rightScore - leftScore));

    float red = (rightRGB[0] - leftRGB[0]) * perc + leftRGB[0];
    float green = (rightRGB[1] - leftRGB[1]) * perc + leftRGB[1];
    float blue = (rightRGB[2] - leftRGB[2]) * perc + leftRGB[2];

    return new Color(red, green, blue);
}

From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java

/**
 * Converts a JasperReports meter interval to one that JFreeChart understands.
 *
 * @param interval the JasperReports definition of an interval
 * @return the JFreeChart version of the same interval
 * @throws JRException thrown when the interval contains an invalid range
 *//*  w ww . j  ava 2  s.  co  m*/
protected MeterInterval convertInterval(JRMeterInterval interval) throws JRException {
    String label = interval.getLabel();
    if (label == null) {
        label = "";
    }

    Range range = convertRange(interval.getDataRange());

    Color color = interval.getBackgroundColor() == null ? getChart().getBackcolor()
            : interval.getBackgroundColor();//FIXMETHEME check this null protection
    float[] components = color.getRGBColorComponents(null);

    float alpha = (float) (interval.getAlphaDouble() == null ? JRMeterInterval.DEFAULT_TRANSPARENCY
            : interval.getAlphaDouble());
    Color alphaColor = new Color(components[0], components[1], components[2], alpha);

    return new MeterInterval(label, range, alphaColor, null, alphaColor);
}

From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java

/**
 * Converts a fspdfs meter interval to one that JFreeChart understands.
 *
 * @param interval the fspdfs definition of an interval
 * @param evaluation current evaluation time
 * @return the JFreeChart version of the same interval
 * @throws JRException thrown when the interval contains an invalid range
 *///ww w  . ja  v a2 s .  com
protected MeterInterval convertInterval(JRMeterInterval interval) throws JRException {
    String label = interval.getLabel();
    if (label == null)
        label = "";

    Range range = convertRange(interval.getDataRange());

    Color color = interval.getBackgroundColor() != null ? interval.getBackgroundColor()
            : (Color) ChartThemesConstants.TRANSPARENT_PAINT;
    float[] components = color.getRGBColorComponents(null);

    float alpha = interval.getAlphaDouble() == null ? (float) JRMeterInterval.DEFAULT_TRANSPARENCY
            : interval.getAlphaDouble().floatValue();
    Color alphaColor = new Color(components[0], components[1], components[2], alpha);

    return new MeterInterval(label, range, alphaColor, null, alphaColor);
}

From source file:com.alvermont.terraj.fracplanet.ui.ControlsDialog.java

private void fogButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_fogButtonActionPerformed
{//GEN-HEADEREND:event_fogButtonActionPerformed

    final Color newColour = JColorChooser.showDialog(this, "Choose Fog Colour", fogButton.getBackground());

    if (newColour != null) {
        /// then a new colour was chosen
        final float[] comps = newColour.getRGBColorComponents(null);

        final RenderParameters params = this.parent.getParameters().getRenderParameters();

        FloatRGBA newRGB = new FloatRGBA(comps[0], comps[1], comps[2]);
        params.setFogColour(newRGB);/* w  ww .j a v  a  2  s . c  om*/
        fogButton.setBackground(newColour);
    }
}

From source file:com.alvermont.terraj.fracplanet.ui.ControlsDialog.java

private void snowButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_snowButtonActionPerformed
{//GEN-HEADEREND:event_snowButtonActionPerformed

    final Color newColour = JColorChooser.showDialog(this, "Choose Snow Colour", snowButton.getBackground());

    if (newColour != null) {
        /// then a new colour was chosen
        final float[] comps = newColour.getRGBColorComponents(null);

        final TerrainParameters params = this.parent.getParameters().getTerrainParameters();

        final FloatRGBA newRGB = new FloatRGBA(comps[0], comps[1], comps[2]);
        params.setColourSnow(newRGB);//from   w  ww .  j a  va2 s  .c om
        snowButton.setBackground(newColour);
    }
}

From source file:com.alvermont.terraj.fracplanet.ui.ControlsDialog.java

private void cloudButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_cloudButtonActionPerformed
{//GEN-HEADEREND:event_cloudButtonActionPerformed

    final Color newColour = JColorChooser.showDialog(this, "Choose Cloud Colour", cloudButton.getBackground());

    if (newColour != null) {
        /// then a new colour was chosen
        final float[] comps = newColour.getRGBColorComponents(null);

        final CloudParameters params = this.parent.getParameters().getCloudParameters();

        final FloatRGBA newRGB = new FloatRGBA(comps[0], comps[1], comps[2]);
        params.setColour(newRGB);//www.  ja va  2 s.c om
        cloudButton.setBackground(newColour);
    }
}

From source file:com.alvermont.terraj.fracplanet.ui.ControlsDialog.java

private void riverButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_riverButtonActionPerformed
{//GEN-HEADEREND:event_riverButtonActionPerformed

    final Color newColour = JColorChooser.showDialog(this, "Choose River Colour", riverButton.getBackground());

    if (newColour != null) {
        /// then a new colour was chosen
        final float[] comps = newColour.getRGBColorComponents(null);

        final TerrainParameters params = this.parent.getParameters().getTerrainParameters();

        final FloatRGBA newRGB = new FloatRGBA(comps[0], comps[1], comps[2]);

        params.setColourRiver(newRGB);/*w w w  .j ava2 s .c o m*/
        riverButton.setBackground(newColour);
    }
}