Example usage for java.awt Color Color

List of usage examples for java.awt Color Color

Introduction

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

Prototype

public Color(ColorSpace cspace, float[] components, float alpha) 

Source Link

Document

Creates a color in the specified ColorSpace with the color components specified in the float array and the specified alpha.

Usage

From source file:ShadowText.java

public void paint(Graphics g) {
    String text = "Hello World";
    int x = 10;/* ww  w.j  a  va 2 s . c o  m*/
    int y = 100;

    Font font = new Font("Georgia", Font.ITALIC, 50);
    Graphics2D g1 = (Graphics2D) g;

    TextLayout textLayout = new TextLayout(text, font, g1.getFontRenderContext());
    g1.setPaint(new Color(150, 150, 150));
    textLayout.draw(g1, x + 3, y + 3);

    g1.setPaint(Color.BLACK);
    textLayout.draw(g1, x, y);
}

From source file:Main.java

public static Object getPropertyValue(Element element) {
    NamedNodeMap map = element.getAttributes();
    map.removeNamedItem(NAME_ATTR);//w ww  .  ja va2 s. c o  m

    if (map.item(0).getNodeName().equals(STRING_ATTR))
        return map.item(0).getNodeValue();
    else if (map.item(0).getNodeName().equals(INTEGER_ATTR))
        return new Integer(map.item(0).getNodeValue());
    else if (map.item(0).getNodeName().equals(DOUBLE_ATTR))
        return new Double(map.item(0).getNodeValue());
    else if (map.item(0).getNodeName().equals(FLOAT_ATTR))
        return new Float(map.item(0).getNodeValue());
    else if (map.item(0).getNodeName().equals(BOOLEAN_ATTR))
        return Boolean.valueOf(map.item(0).getNodeValue());
    else if (map.item(0).getNodeName().equals(COLOR_ATTR)) {
        String[] rgb = map.item(0).getNodeValue().split(",");
        return new Color(new Integer(rgb[0]), new Integer(rgb[1]), new Integer(rgb[2]));
    } else if (map.item(0).getNodeName().equals(FONT_ATTR)) {
        String[] font = map.item(0).getNodeValue().split(",");
        return new Font(font[0], new Integer(font[1]), new Integer(font[2]));
    } else {
        return null;
    }
}

From source file:Utils.java

/**
 * Converts the <code>String</code> representation of a color to an actual
 * <code>Color</code> object.
 *
 * @param value String representation of the color in "r,g,b" format (e.g.
 * "100,255,0")//  w  ww  .j  av  a2s  . c  o m
 * @return <code>Color</code> object that matches the red-green-blue values
 * provided by the parameter. Returns <code>null</code> for empty string.
 */
public static Color stringToColor(String value) {
    try {
        if (!value.equals("")) {
            String[] s = value.split(",");
            if (s.length == 3) {
                int red = Integer.parseInt(s[0]);
                int green = Integer.parseInt(s[1]);
                int blue = Integer.parseInt(s[2]);
                return new Color(red, green, blue);
            }
        }
    } catch (NumberFormatException ex) {
        // ignore it, don't change anything.
        return null;
    } catch (IllegalArgumentException ex) {
        // if a user entered 548 as the red value....
        // ignore it, don't change anything.
        return null;
    }
    return null;
}

From source file:ColorFadingAnimation.java

public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;
    g2d.setColor(new Color(50, 50, 50));
    RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2d.setRenderingHints(rh);//ww  w.j a  va  2  s  .c o  m
    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha_rectangle));
    g2d.fill(rect);
}

From source file:com.github.fritaly.svngraph.SvnGraph.java

private static Color randomColor() {
    return new Color(RandomUtils.nextInt(255), RandomUtils.nextInt(255), RandomUtils.nextInt(255));
}

From source file:Main.java

/**
 * Creates a new <code>Color</code> that is a darker version of this
 * <code>Color</code>. This method is the same implementation
 * java.awt.Color#darker is usind except it has a configurable factor.
 * The java.awt.Color default facotr is 0.7
 * @return  a new <code>Color</code> object that is 
 *                    a darker version of this <code>Color</code>.
 * @see        java.awt.Color#brighter//  ww w .java 2 s . c  o  m
 */
public static Color darkerColor(Color color, double factor) {
    return new Color(Math.max((int) (color.getRed() * factor), 0),
            Math.max((int) (color.getGreen() * factor), 0), Math.max((int) (color.getBlue() * factor), 0));
}

From source file:Main.java

public static Object getPropertyValue(Element element) {
    NamedNodeMap map = element.getAttributes();
    map.removeNamedItem(NAME_ATTR);/*from   w w  w.  ja v a  2  s.c  o m*/

    if (map.item(0).getNodeName().equals(STRING_ATTR)) {
        return map.item(0).getNodeValue();
    } else if (map.item(0).getNodeName().equals(INTEGER_ATTR)) {
        return new Integer(map.item(0).getNodeValue());
    } else if (map.item(0).getNodeName().equals(DOUBLE_ATTR)) {
        return new Double(map.item(0).getNodeValue());
    } else if (map.item(0).getNodeName().equals(FLOAT_ATTR)) {
        return new Float(map.item(0).getNodeValue());
    } else if (map.item(0).getNodeName().equals(BOOLEAN_ATTR)) {
        return Boolean.valueOf(map.item(0).getNodeValue());
    } else if (map.item(0).getNodeName().equals(COLOR_ATTR)) {
        String[] rgb = map.item(0).getNodeValue().split(",");
        return new Color(new Integer(rgb[0]), new Integer(rgb[1]), new Integer(rgb[2]));
    } else if (map.item(0).getNodeName().equals(FONT_ATTR)) {
        String[] font = map.item(0).getNodeValue().split(",");
        return new Font(font[0], new Integer(font[1]), new Integer(font[2]));
    } else {
        return null;
    }
}

From source file:org.jfree.chart.demo.XYShapeRendererDemo1.java

private static JFreeChart createChart(XYZDataset xyzdataset) {
    NumberAxis numberaxis = new NumberAxis("X");
    numberaxis.setAutoRangeIncludesZero(false);
    NumberAxis numberaxis1 = new NumberAxis("Y");
    numberaxis1.setAutoRangeIncludesZero(false);
    XYShapeRenderer xyshaperenderer = new XYShapeRenderer();
    LookupPaintScale lookuppaintscale = new LookupPaintScale(1.0D, 4D, new Color(0, 0, 255));
    lookuppaintscale.add(2D, new Color(100, 100, 255));
    lookuppaintscale.add(3D, new Color(200, 200, 255));
    xyshaperenderer.setPaintScale(lookuppaintscale);
    XYPlot xyplot = new XYPlot(xyzdataset, numberaxis, numberaxis1, xyshaperenderer);
    xyplot.setDomainPannable(true);/*from w  w w . j a  v a  2s.  c om*/
    xyplot.setRangePannable(true);
    JFreeChart jfreechart = new JFreeChart("XYShapeRendererDemo1", xyplot);
    jfreechart.removeLegend();
    NumberAxis numberaxis2 = new NumberAxis("Score");
    numberaxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    PaintScaleLegend paintscalelegend = new PaintScaleLegend(lookuppaintscale, numberaxis2);
    paintscalelegend.setPosition(RectangleEdge.RIGHT);
    paintscalelegend.setMargin(4D, 4D, 40D, 4D);
    paintscalelegend.setAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    jfreechart.addSubtitle(paintscalelegend);
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

From source file:org.operamasks.faces.render.graph.CustomDrawingSupplier.java

private static Paint[] createCustomColorPalette() {
    return new Paint[] { new Color(81, 121, 214), new Color(102, 204, 102), new Color(239, 47, 65),
            new Color(255, 199, 0), new Color(97, 189, 242), new Color(255, 255, 204), new Color(117, 136, 221),
            new Color(47, 94, 140), new Color(7, 186, 206), new Color(186, 229, 92), new Color(186, 24, 113),
            new Color(255, 121, 0), new Color(199, 199, 199), new Color(173, 168, 255),
            new Color(47, 166, 117) };
}

From source file:SplashScreenTest.java

private static void drawOnSplash(int percent) {
    Rectangle bounds = splash.getBounds();
    Graphics2D g = splash.createGraphics();
    int height = 20;
    int x = 2;// w ww. j  a va 2s .  co  m
    int y = bounds.height - height - 2;
    int width = bounds.width - 4;
    Color brightPurple = new Color(76, 36, 121);
    g.setColor(brightPurple);
    g.fillRect(x, y, width * percent / 100, height);
    splash.update();
}