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:de.tor.tribes.ui.renderer.ColoredCoutdownCellRenderer.java

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    try {/*  w ww .ja  va2s.  c  o m*/
        JLabel renderComponent = ((JLabel) c);
        Long d = (Long) value;

        // renderComponent.setText(DurationFormatUtils.formatDuration(d, "HHH:mm:ss.SSS", true));

        long diff = d;
        long five_minutes = 5 * MINUTE;
        long ten_minutes = 10 * MINUTE;
        Color color = null;
        if (row % 2 == 0) {
            color = Constants.DS_ROW_A;
        } else {
            color = Constants.DS_ROW_B;
        }

        if (diff <= 0) {
            //value is expired, stroke result
            //renderComponent.setText(specialFormat.format(d));
            //renderComponent.setForeground(Color.RED);
        } else if (diff <= ten_minutes && diff > five_minutes) {
            float ratio = (float) (diff - five_minutes) / (float) five_minutes;
            Color c1 = Color.YELLOW;
            Color c2 = Color.GREEN;
            int red = (int) (c2.getRed() * ratio + c1.getRed() * (1 - ratio));
            int green = (int) (c2.getGreen() * ratio + c1.getGreen() * (1 - ratio));
            int blue = (int) (c2.getBlue() * ratio + c1.getBlue() * (1 - ratio));
            color = new Color(red, green, blue);
        } else if (diff <= five_minutes) {
            float ratio = (float) diff / (float) five_minutes;
            Color c1 = Color.RED;
            Color c2 = Color.YELLOW;
            int red = (int) (c2.getRed() * ratio + c1.getRed() * (1 - ratio));
            int green = (int) (c2.getGreen() * ratio + c1.getGreen() * (1 - ratio));
            int blue = (int) (c2.getBlue() * ratio + c1.getBlue() * (1 - ratio));
            color = new Color(red, green, blue);
        }
        renderComponent.setText(DurationFormatUtils.formatDuration(d, "HHH:mm:ss.SSS", true));
        if (isSelected) {
            color = c.getBackground();
        }
        renderComponent.setOpaque(true);
        renderComponent.setBackground(color);
        return renderComponent;
    } catch (Exception e) {
        return c;
    }
}

From source file:org.jfree.eastwood.GCategoryPlot.java

/**
 * Draws the gridlines for the plot.//from  w w  w .  jav a2s  . c o  m
 *
 * @param g2  the graphics device.
 * @param dataArea  the area inside the axes.
 * @param ticks  the ticks.
 *
 * @see #drawDomainGridlines(Graphics2D, Rectangle2D)
 */
protected void drawRangeGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) {
    // draw the range grid lines, if any...
    if (isRangeGridlinesVisible()) {
        Stroke gridStroke = getRangeGridlineStroke();
        Paint gridPaint = getRangeGridlinePaint();
        if ((gridStroke != null) && (gridPaint != null)) {
            ValueAxis axis = getRangeAxis();
            if (axis != null) {
                double lower = axis.getRange().getLowerBound();
                double upper = axis.getRange().getUpperBound();
                double y = lower;
                while (y <= upper) {
                    Paint paint = gridPaint;
                    if ((y == lower || y == upper) && gridPaint instanceof Color) {
                        Color c = (Color) gridPaint;
                        paint = new Color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha() / 3);
                    }
                    try {
                        setRangeGridlinePaint(paint);
                        getRenderer().drawRangeGridline(g2, this, getRangeAxis(), dataArea, y);
                    } finally {
                        setRangeGridlinePaint(gridPaint);
                    }
                    y += this.yAxisStepSize;
                }
            }
        }
    }
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.canvas.rendering.AwtRenderingBackend.java

/**
 * {@inheritDoc}//from w  w  w .  j a  v  a  2  s . co m
 */
public byte[] getBytes(final int width, final int height, final int sx, final int sy) {
    final byte[] array = new byte[width * height * 4];
    int index = 0;
    for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
            final Color c = new Color(image_.getRGB(sx + x, sy + y), true);
            array[index++] = (byte) c.getRed();
            array[index++] = (byte) c.getGreen();
            array[index++] = (byte) c.getBlue();
            array[index++] = (byte) c.getAlpha();
        }
    }
    return array;
}

From source file:playground.johannes.socialnetworks.graph.spatial.io.KMLVertexColorStyle.java

public List<StyleType> getObjectStyle(G graph) {
    TDoubleObjectHashMap<String> values = getValues(graph);
    double[] keys = values.keys();
    double min = StatUtils.min(keys);
    double max = StatUtils.max(keys);

    List<StyleType> styleTypes = new ArrayList<StyleType>(keys.length);
    styleIdMappings = new TDoubleObjectHashMap<String>();

    for (double val : keys) {
        StyleType styleType = objectFactory.createStyleType();
        styleType.setId(values.get(val));

        IconStyleType iconStyle = objectFactory.createIconStyleType();
        iconStyle.setIcon(vertexIconLink);
        iconStyle.setScale(0.5);//from   ww w.  j  a  v a  2 s.com
        //         iconStyle.setScale(1.0);

        Color c = colorForValue(val, min, max);
        iconStyle.setColor(
                new byte[] { (byte) c.getAlpha(), (byte) c.getBlue(), (byte) c.getGreen(), (byte) c.getRed() });

        styleType.setIconStyle(iconStyle);

        styleTypes.add(styleType);
        styleIdMappings.put(val, styleType.getId());
    }

    return styleTypes;
}

From source file:wsattacker.sso.openid.attacker.evaluation.report.SvgOutput.java

private String colorToHex(Color color) {
    return String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), color.getBlue());
}

From source file:util.program.ProgramTextCreator.java

private static String addSearchLink(String topic, String displayText) {
    Color foreground = Color.black;//Settings.propProgramPanelForegroundColor.getColor();

    String style = " style=\"color:rgb(" + foreground.getRed() + "," + foreground.getGreen() + ","
            + foreground.getBlue() + "); border-bottom: 1px dashed;\"";
    StringBuilder buffer = new StringBuilder(32);
    buffer.append("<a href=\"");
    buffer.append(TVBROWSER_URL_PROTOCOL);
    buffer.append(StringUtils.remove(StringUtils.remove(topic, '"'), '\''));

    buffer.append("\" ");
    buffer.append(style);/*w w w  . jav  a 2  s .  c om*/
    buffer.append('>');
    buffer.append(displayText);
    buffer.append("</a>");
    return buffer.toString();
}

From source file:ColorBlocks.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    Dimension d = getSize();// www. j  av a 2 s .co  m
    g2.translate(d.width / 2, d.height / 2);

    Color[] colors = { Color.white, Color.lightGray, Color.gray, Color.darkGray, Color.black, Color.red,
            Color.pink, Color.orange, Color.yellow, Color.green, Color.magenta, Color.cyan, Color.blue };

    float size = 25;
    float x = -size * colors.length / 2;
    float y = -size * 3 / 2;

    // Show all the predefined colors.
    for (int i = 0; i < colors.length; i++) {
        Rectangle2D r = new Rectangle2D.Float(x + size * (float) i, y, size, size);
        g2.setPaint(colors[i]);
        g2.fill(r);
    }

    //a linear gradient.
    y += size;
    Color c1 = Color.yellow;
    Color c2 = Color.blue;
    for (int i = 0; i < colors.length; i++) {
        float ratio = (float) i / (float) colors.length;
        int red = (int) (c2.getRed() * ratio + c1.getRed() * (1 - ratio));
        int green = (int) (c2.getGreen() * ratio + c1.getGreen() * (1 - ratio));
        int blue = (int) (c2.getBlue() * ratio + c1.getBlue() * (1 - ratio));
        Color c = new Color(red, green, blue);
        Rectangle2D r = new Rectangle2D.Float(x + size * (float) i, y, size, size);
        g2.setPaint(c);
        g2.fill(r);
    }

    // Show an alpha gradient.
    y += size;
    c1 = Color.red;
    for (int i = 0; i < colors.length; i++) {
        int alpha = (int) (255 * (float) i / (float) colors.length);
        Color c = new Color(c1.getRed(), c1.getGreen(), c1.getBlue(), alpha);
        Rectangle2D r = new Rectangle2D.Float(x + size * (float) i, y, size, size);
        g2.setPaint(c);
        g2.fill(r);
    }

    // Draw a frame around the whole thing.
    y -= size * 2;
    Rectangle2D frame = new Rectangle2D.Float(x, y, size * colors.length, size * 3);
    g2.setPaint(Color.black);
    g2.draw(frame);
}

From source file:com.mebigfatguy.polycasso.JavaSaver.java

private String getColorData(PolygonData[] data) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);

    String comma = "";
    for (PolygonData pd : data) {

        pw.println(comma);/*w  w w  .j  a  v  a  2 s . co  m*/
        pw.print(TABS);
        pw.print("{");

        Color color = pd.getColor();
        pw.print(color.getRed());
        pw.print(",");
        pw.print(color.getGreen());
        pw.print(",");
        pw.print(color.getBlue());
        pw.print("}");
        comma = ",";
    }

    pw.flush();
    return sw.toString();
}

From source file:org.jtrfp.trcl.file.LTEFile.java

/**
 * Reverse-compatible form of the emissive components in ESTuTv form where:<br>
 * R = E<br>//from www  .  j  a  v a2s . co m
 * G = S<br>
 * B = Tu<br>
 * A = Tv<br>
 * @return
 * @since Feb 5, 2015
 */
public Color[] toColors(Color[] referencePalette) {
    Color[] result = new Color[256];
    for (int i = 0; i < 256; i++) {
        final Color rColor = referencePalette[i];
        final Color loColor = referencePalette[gradientIndex(i, 0)];
        final Color hiColor = referencePalette[gradientIndex(i, 15)];
        final double loIntensity = new Vector3D(loColor.getRed(), loColor.getGreen(), loColor.getBlue())
                .getNorm();
        //Brightest
        final double hiIntensity = new Vector3D(hiColor.getRed(), hiColor.getGreen(), hiColor.getBlue())
                .getNorm();

        final float[] hsbVals = new float[3];
        Color.RGBtoHSB(rColor.getRed(), rColor.getGreen(), rColor.getBlue(), hsbVals);
        final double saturation = hsbVals[1];
        double dI = Math.pow(1 - (Math.abs(hiIntensity - loIntensity) / 442.), 1);
        //dI = nSaturation*128;
        if (dI > 255)
            dI = 255;
        else if (dI < 0)
            dI = 0;
        result[i] = new Color((int) (dI * saturation * 255.), 0, 0, 0);
    }
    return result;
}

From source file:org.neo4art.colour.service.ImageDefaultManager.java

/**
 * /*from   w  ww .  j  ava  2  s  .  c o m*/
 * @param red
 * @param green
 * @param blue
 * @return
 */
public Colour getClosestColour(Color color) {
    return getClosestColour(color.getRed(), color.getGreen(), color.getBlue());
}