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:bwem.example.MapPrinterExample.java

private Color getZoneColor(Area area, java.util.Map<Integer, Color> mapZoneColor) {
    final int zoneId = mapPrinter.showAreas ? area.getId().intValue() : area.getGroupId().intValue();
    Color color = mapZoneColor.get(zoneId);
    if (color == null) { // zoneId was not find --> insertion did occur --> we have do define the new color:
        int tries = 0;
        do {/*from   w w  w . j  ava  2 s  .  co  m*/
            color = new Color(this.randomGenerator.nextInt(256), this.randomGenerator.nextInt(256), 0); // blue unused for Terrain so that Water can be easily distinguished.
            if (++tries > 100)
                break;
        } while (
        // 1) color should not be too dark
        (color.getRed() + color.getGreen() < 150) ||

        // 2) color should differ enough from the colors of the neighboring areas
                (mapPrinter.showAreas
                        && getZoneColorCppAlgorithmAnyOf(area.getChokePointsByArea(), mapZoneColor, color)));
        mapZoneColor.put(zoneId, color);
    }

    return color;
}

From source file:com.tdclighthouse.prototype.servlets.JLatexServlet.java

private synchronized BufferedImage generateImage(String latex) {
    TeXFormula formula = new TeXFormula(latex);
    TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 20);
    icon.setInsets(new Insets(5, 5, 5, 5));

    BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = image.createGraphics();
    g2.setColor(Color.white);/*  ww  w .  j av  a 2  s.c  o  m*/
    g2.fillRect(0, 0, icon.getIconWidth(), icon.getIconHeight());
    JLabel jl = new JLabel();
    jl.setForeground(new Color(0, 0, 0));
    icon.paintIcon(jl, g2, 0, 0);
    return image;
}

From source file:com.synnex.saas.platform.core.servlet.CaptchaServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {// ww w  .  j av  a  2 s  .  c o  m
        int width = 50;
        int height = 18;
        String captchaCode = RandomStringUtils.random(4, true, true);
        HttpSession session = request.getSession(true);
        session.setAttribute("captchaCode", captchaCode);

        response.setContentType("images/jpeg");
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);

        ServletOutputStream out = response.getOutputStream();
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics g = image.getGraphics();
        g.setColor(getRandColor(200, 250));
        g.fillRect(0, 0, width, height);
        Font mFont = new Font("Times New Roman", Font.BOLD, 18);
        g.setFont(mFont);
        g.setColor(getRandColor(160, 200));
        Random random = new Random();
        for (int i = 0; i < 155; i++) {
            int x2 = random.nextInt(width);
            int y2 = random.nextInt(height);
            int x3 = random.nextInt(12);
            int y3 = random.nextInt(12);
            g.drawLine(x2, y2, x2 + x3, y2 + y3);
        }
        g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110)));
        g.drawString(captchaCode, 2, 16);
        g.dispose();
        ImageIO.write((BufferedImage) image, "JPEG", out);
        out.close();
    } catch (Exception e) {
        logger.error("Generate captcha failed.", e);
    }
}

From source file:com.chris.brkopani.gui.analytics.Graph.java

/**
 * * Creates a chart/*from   w  w  w. j a  va2s .c  om*/
 */
private JFreeChart createChart(PieDataset dataset, String title) {

    JFreeChart chart = ChartFactory.createPieChart3D(title, // chart title
            dataset, // data
            true, // include legend
            true, false);

    PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setStartAngle(290);
    plot.setSectionPaint("...-20", new Color(195, 203, 113));
    plot.setSectionPaint("21-30", new Color(174, 90, 65));
    plot.setSectionPaint("35-...", new Color(85, 158, 131));
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    return chart;

}

From source file:ChangeTrackingTest.java

/**
 * Set the background color to the values stored in the text fields.
 *///from   w ww  . jav  a 2  s.c o  m
public void setColor() {
    try {
        int red = Integer.parseInt(redField.getText().trim());
        int green = Integer.parseInt(greenField.getText().trim());
        int blue = Integer.parseInt(blueField.getText().trim());
        panel.setBackground(new Color(red, green, blue));
    } catch (NumberFormatException e) {
        // don't set the color if the input can't be parsed
    }
}

From source file:ch.epfl.lis.gnwgui.jungtransformers.NodeFillColorTransformer.java

/**
 * Constructor// ww w .  ja  v  a2 s  .  c om
 * @param pi
 */
public NodeFillColorTransformer(PickedInfo<V> pi) {
    pi_ = pi;
    defaultNodeColor = new Color(113, 153, 255); // Blue light
    pickedColor_ = Color.YELLOW;
    possibleNodeColor_ = new Color(255, 186, 0); // Orange
    solutionNodeColor_ = new Color(255, 70, 0); // Red
    //        solutionNodeColor_ = new Color(170, 255, 170);    // Pistachio
}

From source file:examples.utils.CifarReader.java

public static BufferedImage getImageFromArray(double[] pixels, int width, int height) {
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    for (int i = 0; i < pixels.length / IMAGE_DEPTH; ++i) {
        int rgb = new Color(Double.valueOf(pixels[i]).intValue(), Double.valueOf(pixels[i + 1024]).intValue(),
                Double.valueOf(pixels[i + 2048]).intValue()).getRGB();
        image.setRGB(i % IMAGE_WIDTH, i / IMAGE_HIGHT, rgb);
    }/*from  w w  w.ja v a2 s .c o m*/
    return image;
}

From source file:ColorGradient.java

/**
 * Draw a color gradient from the top of the specified component to the
 * bottom. Start with the start color and change smoothly to the end
 *//*from   www  .  j  av a 2s .  c om*/
public void fillGradient(Component c, Graphics g, Color start, Color end) {
    Rectangle bounds = this.getBounds(); // How big is the component?
    // Get the red, green, and blue components of the start and end
    // colors as floats between 0.0 and 1.0. Note that the Color class
    // also works with int values between 0 and 255
    float r1 = start.getRed() / 255.0f;
    float g1 = start.getGreen() / 255.0f;
    float b1 = start.getBlue() / 255.0f;
    float r2 = end.getRed() / 255.0f;
    float g2 = end.getGreen() / 255.0f;
    float b2 = end.getBlue() / 255.0f;
    // Figure out how much each component should change at each y value
    float dr = (r2 - r1) / bounds.height;
    float dg = (g2 - g1) / bounds.height;
    float db = (b2 - b1) / bounds.height;

    // Now loop once for each row of pixels in the component
    for (int y = 0; y < bounds.height; y++) {
        g.setColor(new Color(r1, g1, b1)); // Set the color of the row
        g.drawLine(0, y, bounds.width - 1, y); // Draw the row
        r1 += dr;
        g1 += dg;
        b1 += db; // Increment color components
    }
}

From source file:DashboardInterface.CableOutSpeedDial.java

public CableOutSpeedDial(JPanel parentIn) {
    super(new BorderLayout());
    parent = parentIn;/*w w  w.j  a  va2 s .c  o  m*/
    dataset1 = new DefaultValueDataset(0D);
    dataset2 = new DefaultValueDataset(0D);
    pipe = MessagePipeline.getInstance();
    pipe.attach(this);
    DialPlot dialplot = new DialPlot();
    dialplot.setView(0.0D, 0.0D, 1.0D, 1.0D);
    dialplot.setDataset(0, dataset1);
    dialplot.setDataset(1, dataset2);
    setBackground(Color.WHITE);
    StandardDialFrame standarddialframe = new StandardDialFrame();
    standarddialframe.setBackgroundPaint(Color.lightGray);
    standarddialframe.setForegroundPaint(Color.darkGray);

    dialplot.setDialFrame(standarddialframe);

    DialBackground dialbackground = new DialBackground(Color.LIGHT_GRAY);

    dialbackground.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
    dialplot.setBackground(dialbackground);

    DialTextAnnotation dialtextannotation = new DialTextAnnotation("Cable Out (ft)");
    dialtextannotation.setFont(new Font("Dialog", 1, 12));
    dialtextannotation.setPaint(new Color(36, 130, 9));
    dialtextannotation.setRadius(0.47999999999999996D);
    dialplot.addLayer(dialtextannotation);

    DialTextAnnotation dialtextannotation2 = new DialTextAnnotation("Speed (kts)");
    dialtextannotation2.setFont(new Font("Dialog", 1, 12));
    dialtextannotation2.setPaint(Color.BLUE);
    dialtextannotation2.setRadius(0.78999999999999996D);
    dialplot.addLayer(dialtextannotation2);

    /*DialValueIndicator dialvalueindicator = new DialValueIndicator(0);
    dialvalueindicator.setFont(new Font("Dialog", 0, 10));
    dialvalueindicator.setOutlinePaint(Color.BLACK);
    dialvalueindicator.setRadius(0.84999999999999998D);
    dialvalueindicator.setAngle(-90D);
    dialplot.addLayer(dialvalueindicator);
            
    DialValueIndicator dialvalueindicator1 = new DialValueIndicator(1);
    dialvalueindicator1.setFont(new Font("Dialog", 0, 10));
    dialvalueindicator1.setOutlinePaint(Color.BLACK);
    dialvalueindicator1.setRadius(0.60999999999999998D);
    dialvalueindicator1.setAngle(-90D);
    dialplot.addLayer(dialvalueindicator1);*/

    StandardDialScale standarddialscale = new StandardDialScale(0D, 90D, -110D, -320D, 10D, 4);
    standarddialscale.setTickRadius(0.88D);
    standarddialscale.setTickLabelOffset(0.14999999999999999D);
    standarddialscale.setTickLabelFont(new Font("Dialog", 0, 14));
    standarddialscale.setMajorTickPaint(Color.BLUE);
    standarddialscale.setMinorTickPaint(Color.BLUE);
    dialplot.addScale(0, standarddialscale);

    StandardDialScale standarddialscale1 = new StandardDialScale(0.0D, 6000D, -110D, -320D, 750D, 4);
    standarddialscale1.setTickRadius(0.5D);
    standarddialscale1.setTickLabelOffset(0.14999999999999999D);
    standarddialscale1.setTickLabelFont(new Font("Dialog", 0, 10));
    standarddialscale1.setTickLabelPaint(new Color(36, 130, 9));
    standarddialscale1.setMajorTickPaint(new Color(36, 130, 9));
    standarddialscale1.setMinorTickPaint(new Color(36, 130, 9));
    dialplot.addScale(1, standarddialscale1);

    dialplot.mapDatasetToScale(1, 1);

    org.jfree.chart.plot.dial.DialPointer.Pointer pointer = new org.jfree.chart.plot.dial.DialPointer.Pointer(
            0);
    pointer.setFillPaint(Color.BLUE);
    dialplot.addPointer(pointer);

    org.jfree.chart.plot.dial.DialPointer.Pointer pin = new org.jfree.chart.plot.dial.DialPointer.Pointer(1);
    pin.setRadius(0.55000000000000004D);
    pin.setFillPaint(new Color(36, 130, 9));
    dialplot.addPointer(pin);

    DialCap dialcap = new DialCap();
    dialcap.setRadius(0.10000000000000001D);
    dialplot.setCap(dialcap);

    Dimension size = parent.getBounds().getSize();
    int width = parent.getWidth();
    int height = parent.getHeight();

    width = 200;

    JFreeChart jfreechart = new JFreeChart(dialplot);
    jfreechart.setBackgroundPaint(Color.WHITE);
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    chartpanel.setPreferredSize(new Dimension(width, width));

    add(chartpanel);
}

From source file:com.aw.swing.mvp.view.ViewManager.java

/**
 * Setting some default colors to the screens
 *///from  w ww. j  a  va  2 s .  co  m
private void prepareView() {
    if (!(presenter instanceof FindPresenter)) {
        JPanel pnlToolBar = getIpView().getPnlToolBar();
        if (pnlToolBar != null) {
            pnlToolBar.setBackground(new Color(223, 232, 246));
            pnlToolBar.setBorder(BorderFactory.createLineBorder(new Color(131, 172, 219), 1));
        }
    }
}