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:edu.stanford.epadd.launcher.Splash.java

void setSplashText(String text) {
    if (splash == null)
        return;/* w w  w .  jav  a  2s .c  o m*/

    int SPLASH_SCREEN_WIDTH = ((int) splash.getBounds().getWidth());
    int MARGIN = 10; // margin for text on each side

    // clear the previous text
    g.setColor(new Color(1, 117, 188)); // epadd color, #0175bc
    g.fillRect(0, 175, SPLASH_SCREEN_WIDTH, 40);
    g.setPaintMode();

    // write the new text
    g.setColor(Color.WHITE); // #0175bc
    g.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 14));

    // compute the startX so as to center align the string,
    int stringWidth = g.getFontMetrics().stringWidth(text);
    int startX = (stringWidth > (SPLASH_SCREEN_WIDTH - MARGIN * 2)) ? MARGIN
            : MARGIN + (SPLASH_SCREEN_WIDTH - stringWidth) / 2;
    g.drawString(text, startX, 200);

    splash.update();
}

From source file:WeatherFrame.java

public WeatherFrame() {
    initComponents();// w w w  .j  av  a 2s  .  c o  m

    fc = new JFileChooser();
    fc.setMultiSelectionEnabled(true);

    //only can select a single button a time
    ButtonGroup group = new ButtonGroup();
    group.add(AllRadioButton);
    group.add(YearlyRadioButton);
    group.add(MonthlyRadioButton);
    group.add(WeeklyRadioButton);
    group.add(DailyRadioButton);

    jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Temperature", "Humidity",
            "Barometric Pressure", "Windspeed", "UVindex", "Raindfall" }));

    TempSet = new TimeSeriesCollection();
    JFreeChart chart = ChartFactory.createXYLineChart("Temperature", "", "Degree Fahrenheit", TempSet,
            PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(Color.white);
    ChartPanel.setLayout(new java.awt.BorderLayout());
    ChartPanel CP = new ChartPanel(chart);
    CP.setPreferredSize(new Dimension(ChartPanel.getWidth(), ChartPanel.getHeight()));
    ChartPanel.add(CP, BorderLayout.CENTER);

    DefaultValueDataset dataset = new DefaultValueDataset(20f);
    ThermometerPlot thermometerplot = new ThermometerPlot(dataset);
    JFreeChart jfreechart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, thermometerplot, true);
    jfreechart.setBackgroundPaint(new Color(240, 240, 240));
    thermometerplot.setThermometerPaint(Color.lightGray);
    thermometerplot.setThermometerStroke(new BasicStroke(2.0F));
    ChartPanel DP = new ChartPanel(jfreechart);
    DP.setPreferredSize(new Dimension(TempThermoPanel.getWidth(), TempThermoPanel.getHeight()));
    TempThermoPanel.setLayout(new java.awt.BorderLayout());
    TempThermoPanel.add(DP);
    TempThermoPanel.validate();
}

From source file:de.fub.maps.project.detector.model.inference.ui.charts.PrecisionRecallBarChartPanel.java

/**
 * Creates new form PrecisionRecallBarChartPanel
 *///from w ww. j a v a 2s .c  om
public PrecisionRecallBarChartPanel() {
    super();
    initComponents();
    barChart = ChartFactory.createBarChart(
            NbBundle.getMessage(PrecisionRecallBarChartPanel.class, "CLT_Chart_Precision_Recall_Name"),
            NbBundle.getMessage(PrecisionRecallBarChartPanel.class, "CLT_Doman_Axis_Name"),
            NbBundle.getMessage(PrecisionRecallBarChartPanel.class, "CLT_Value_Axis_Name"), dataset,
            PlotOrientation.VERTICAL, true, true, true);

    Font font = new JLabel().getFont().deriveFont(Font.BOLD, 14);

    barChart.getTitle().setFont(font);
    barChart.getTitle().setPaint(new Color(153, 153, 153));

    plot = barChart.getCategoryPlot();
    NumberAxis preciAxis = new NumberAxis(
            NbBundle.getMessage(PrecisionRecallBarChartPanel.class, "CLT_Value_Axis_Name"));
    preciAxis.setAutoRange(true);
    preciAxis.setUpperMargin(.20);
    plot.setRangeAxis(0, preciAxis);
    plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT);
    plot.setBackgroundPaint(Color.white);

    BarRenderer barRenderer = new BarRenderer();
    barRenderer.setBarPainter(new StandardBarPainter());
    barRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
            StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, new CustomNumberFormat()));
    barRenderer.setBaseItemLabelsVisible(true);
    barRenderer.setSeriesPaint(0, precColor);
    barRenderer.setSeriesPaint(1, recColor);

    plot.setRenderer(barRenderer);

    chartPanel = new ChartPanel(barChart, false);
    chartPanel.setVerticalAxisTrace(false);
    add(chartPanel, BorderLayout.CENTER);
}

From source file:Reportes.BarChart.java

public ChartPanel reporteCantidadVehiculosPorSede(DefaultCategoryDataset data) {
    JFreeChart chart = ChartFactory.createBarChart("Reporte de cantidad de vehiculos por sede", "Sedes",
            "Cantidad", data, PlotOrientation.VERTICAL, true, true, true);

    CategoryPlot categoryP = chart.getCategoryPlot();
    BarRenderer renderer = (BarRenderer) categoryP.getRenderer();
    renderer.setMaximumBarWidth(0.35);//from   w w w  .  j  ava 2s  .  c o m
    Color color = new Color(67, 165, 208);
    renderer.setSeriesPaint(0, color);

    ChartPanel panel = new ChartPanel(chart, true, true, true, false, false);
    panel.setSize(ancho, alto);

    return panel;
}

From source file:it.marcoberri.mbmeteo.action.chart.GetLastRDial.java

/**
 * Processes requests for both HTTP//from   w ww  .  j  a v a2s .co m
 * <code>GET</code> and
 * <code>POST</code> methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    log.debug("start : " + this.getClass().getName());

    final HashMap<String, String> params = getParams(request.getParameterMap());
    final Integer dimy = Default.toInteger(params.get("dimy"), 600);
    final Integer dimx = Default.toInteger(params.get("dimx"), 800);

    Meteolog meteolog = ds.find(Meteolog.class).order("-time").limit(1).get();

    DefaultValueDataset dataset = new DefaultValueDataset(meteolog.getDayRainfall());

    // get data for diagrams
    DialPlot plot = new DialPlot();
    plot.setView(0.0, 0.0, 1.0, 1.0);
    plot.setDataset(0, dataset);

    GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(),
            new Color(170, 170, 220));

    DialBackground db = new DialBackground(gp);

    db.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL));
    plot.setBackground(db);

    StandardDialScale scale = new StandardDialScale();
    scale.setLowerBound(0);
    scale.setUpperBound(50);
    scale.setTickLabelOffset(0.14);
    scale.setTickLabelFont(new Font("Dialog", Font.PLAIN, 10));
    plot.addScale(0, scale);

    DialPointer needle = new DialPointer.Pointer(0);

    plot.addLayer(needle);

    JFreeChart chart1 = new JFreeChart(plot);
    chart1.setTitle("Daily Rain mm");

    final File f = File.createTempFile("mbmeteo", ".jpg");
    ChartUtilities.saveChartAsJPEG(f, chart1, dimx, dimy);

    response.setContentType("image/jpeg");
    response.setHeader("Content-Length", "" + f.length());
    response.setHeader("Content-Disposition", "inline; filename=\"" + f.getName() + "\"");
    final OutputStream out = response.getOutputStream();
    final FileInputStream in = new FileInputStream(f.toString());
    final int size = in.available();
    final byte[] content = new byte[size];
    in.read(content);
    out.write(content);
    in.close();
    out.close();
}

From source file:probe.com.view.body.quantcompare.PieChart.java

public PieChart(String title, double full, double found, final String notfound) {

    this.setWidth(200 + "px");
    this.setHeight(200 + "px");
    defaultKeyColorMap.put("Found", new Color(110, 177, 206));
    defaultKeyColorMap.put("Not found", new Color(219, 169, 1));
    otherSymbols.setGroupingSeparator('.');
    this.setStyleName("click");

    labels = new String[] { "Found", "Not found" };

    double foundPercent = ((found / full) * 100.0);
    df = new DecimalFormat("#.##", otherSymbols);
    valuesMap.put("Found", ((int) found) + " (" + df.format(foundPercent) + "%)");
    values = new Double[] { foundPercent, 100.0 - foundPercent };
    valuesMap.put("Not found", ((int) (full - found)) + " (" + df.format(100.0 - foundPercent) + "%)");

    String defaultImgURL = initPieChart(200, 200, title);
    chartImg.setSource(new ExternalResource(defaultImgURL));
    this.addComponent(chartImg);
    this.addLayoutClickListener(PieChart.this);

    popupLayout = new PopupView(null, popupBody);
    popupLayout.setHideOnMouseOut(false);
    popupBody.setWidth("300px");
    popupBody.setStyleName(Reindeer.LAYOUT_WHITE);
    popupBody.setHeightUndefined();//from   w  w w .  j a va2s  . c  o m
    this.addComponent(popupLayout);
    this.notfound = notfound.replace(" ", "").replace(",", "/n");

    HorizontalLayout topLayout = new HorizontalLayout();
    topLayout.setWidth("100%");
    topLayout.setHeight("20px");

    Label header = new Label("<b>Not Found (New Proteins)</b>");
    header.setStyleName(Reindeer.LABEL_SMALL);
    topLayout.addComponent(header);
    header.setContentMode(ContentMode.HTML);

    VerticalLayout closeBtn = new VerticalLayout();
    closeBtn.setWidth("10px");
    closeBtn.setHeight("10px");
    closeBtn.setStyleName("closebtn");
    topLayout.addComponent(closeBtn);
    topLayout.setComponentAlignment(closeBtn, Alignment.TOP_RIGHT);
    closeBtn.addLayoutClickListener(new LayoutEvents.LayoutClickListener() {

        @Override
        public void layoutClick(LayoutEvents.LayoutClickEvent event) {
            popupLayout.setPopupVisible(false);
        }
    });
    popupBody.addComponent(topLayout);
    popupBody.addComponent(textArea);
    textArea.setWidth("100%");
    textArea.setHeight("150px");
    textArea.setValue(this.notfound);
    textArea.setReadOnly(true);
    popupBody.setSpacing(true);

    HorizontalLayout bottomLayout = new HorizontalLayout();
    bottomLayout.setWidth("100%");
    bottomLayout.setHeight("40px");
    bottomLayout.setMargin(new MarginInfo(false, true, true, true));
    popupBody.addComponent(bottomLayout);

    Button exportTableBtn = new Button("");
    exportTableBtn.setHeight("24px");
    exportTableBtn.setWidth("24px");
    exportTableBtn.setPrimaryStyleName("exportxslbtn");
    exportTableBtn.setDescription("Export table data");
    exportTableBtn.addClickListener(new Button.ClickListener() {

        private Table table;

        @Override
        public void buttonClick(Button.ClickEvent event) {

            if (table == null) {
                table = new Table();
                table.addContainerProperty("Index", Integer.class, null, "", null, Table.Align.RIGHT);
                table.addContainerProperty("Accession", String.class, Table.Align.CENTER);
                table.setVisible(false);
                addComponent(table);
                int i = 1;
                for (String str : notfound.replace(" ", "").replace(",", "\n").split("\n")) {
                    table.addItem(new Object[] { i, str }, i++);
                }

            }

            ExcelExport csvExport = new ExcelExport(table, "Not found protein accessions (New proteins)");
            //                csvExport.setReportTitle("CSF-PR /  Not found protein accessions (New proteins) ");
            csvExport.setExportFileName("CSF-PR - Not found protein accessions" + ".xls");
            csvExport.setMimeType(CsvExport.EXCEL_MIME_TYPE);
            csvExport.setDisplayTotals(false);
            csvExport.setExcelFormatOfProperty("Index", "#0;[Red] #0");
            csvExport.export();

        }
    });

    bottomLayout.addComponent(exportTableBtn);
    bottomLayout.setComponentAlignment(exportTableBtn, Alignment.MIDDLE_RIGHT);

}

From source file:com.googlecode.logVisualizer.chart.ConsumptionBarChart.java

@Override
protected ChartPanel createChartPanel() {
    final ChartPanel panel = super.createChartPanel();
    final CategoryPlot plot = (CategoryPlot) panel.getChart().getPlot();
    final StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer();
    final CategoryDataset dataset = plot.getDataset();

    for (int i = 0; i < dataset.getRowCount(); i++)
        if (dataset.getRowKey(i).equals("Food"))
            renderer.setSeriesPaint(i, new Color(255, 80, 80));
        else if (dataset.getRowKey(i).equals("Booze"))
            renderer.setSeriesPaint(i, new Color(100, 100, 255));
        else if (dataset.getRowKey(i).equals("Spleen"))
            renderer.setSeriesPaint(i, new Color(80, 255, 80));
        else if (dataset.getRowKey(i).equals("Other"))
            renderer.setSeriesPaint(i, Color.LIGHT_GRAY);

    return panel;
}

From source file:it.marcoberri.mbmeteo.action.chart.GetLastTDial.java

/**
 * Processes requests for both HTTP/*from www. ja  v  a  2 s.  c o  m*/
 * <code>GET</code> and
 * <code>POST</code> methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    log.debug("start : " + this.getClass().getName());

    final HashMap<String, String> params = getParams(request.getParameterMap());
    final Integer dimy = Default.toInteger(params.get("dimy"), 600);
    final Integer dimx = Default.toInteger(params.get("dimx"), 800);

    Meteolog meteolog = ds.find(Meteolog.class).order("-time").limit(1).get();

    DefaultValueDataset dataset = new DefaultValueDataset(meteolog.getOutdoorTemperature());

    // get data for diagrams
    DialPlot plot = new DialPlot();
    plot.setView(0.0, 0.0, 1.0, 1.0);
    plot.setDataset(0, dataset);

    GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(),
            new Color(170, 170, 220));

    DialBackground db = new DialBackground(gp);

    db.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL));
    plot.setBackground(db);

    StandardDialScale scale = new StandardDialScale();
    scale.setLowerBound(-20);
    scale.setUpperBound(40);
    scale.setTickLabelOffset(0.14);
    scale.setTickLabelFont(new Font("Dialog", Font.PLAIN, 10));
    plot.addScale(0, scale);

    DialPointer needle = new DialPointer.Pointer(0);

    plot.addLayer(needle);

    JFreeChart chart1 = new JFreeChart(plot);
    chart1.setTitle("Temperature C");

    final File f = File.createTempFile("mbmeteo", ".jpg");
    ChartUtilities.saveChartAsJPEG(f, chart1, dimx, dimy);

    response.setContentType("image/jpeg");
    response.setHeader("Content-Length", "" + f.length());
    response.setHeader("Content-Disposition", "inline; filename=\"" + f.getName() + "\"");
    final OutputStream out = response.getOutputStream();
    final FileInputStream in = new FileInputStream(f.toString());
    final int size = in.available();
    final byte[] content = new byte[size];
    in.read(content);
    out.write(content);
    in.close();
    out.close();
}

From source file:com.celements.photo.plugin.cmd.ComputeImageCommand.java

public XWikiAttachment computeImage(XWikiAttachment attachment, XWikiContext context,
        XWikiAttachment attachmentClone, String sheight, String swidth, String copyright, String watermark,
        Color defaultBg, String defaultBgString) {
    // crop params
    int cropX = parseIntWithDefault(context.getRequest().get("cropX"), -1);
    int cropY = parseIntWithDefault(context.getRequest().get("cropY"), -1);
    int cropW = parseIntWithDefault(context.getRequest().get("cropW"), -1);
    int cropH = parseIntWithDefault(context.getRequest().get("cropH"), -1);
    boolean needsCropping = needsCropping(cropX, cropY, cropW, cropH);
    LOGGER.debug("Crop needed: " + needsCropping + " -> " + cropX + ":" + cropY + " " + cropW + "x" + cropH);
    // resize params
    if ((defaultBgString != null) && defaultBgString.matches("[0-9A-Fa-f]{6}")) {
        int r = Integer.parseInt(defaultBgString.substring(1, 3), 16);
        int g = Integer.parseInt(defaultBgString.substring(3, 5), 16);
        int b = Integer.parseInt(defaultBgString.substring(5), 16);
        defaultBg = new Color(r, g, b);
    }//  w  w w .j av a 2 s . com
    int height = parseIntWithDefault(sheight, 0);
    int width = parseIntWithDefault(swidth, 0);
    try {
        attachmentClone = (XWikiAttachment) attachment.clone();
        //      mLogger.debug("dimension: target width=" + width + "; target height=" + height
        //          + "; resized width=" + dimension.getWidth() + "; resized height="
        //          + dimension.getHeight());
        String key = getImageCacheCmd().getCacheKey(attachmentClone, new ImageDimensions(width, height),
                copyright, watermark, cropX, cropY, cropW, cropH);
        LOGGER.debug("attachment key: '" + key + "'");
        InputStream data = getImageCacheCmd().getImageForKey(key);
        if (data != null) {
            LOGGER.info("Found image in Cache.");
            attachmentClone.setContent(data);
        } else {
            LOGGER.info("No cached image.");
            GenerateThumbnail thumbGen = new GenerateThumbnail();
            InputStream in = attachmentClone.getContentInputStream(context);
            DecodeImageCommand decodeImageCommand = new DecodeImageCommand();
            BufferedImage img = decodeImageCommand.readImage(attachmentClone, context);
            in.close();
            if (needsCropping) {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                ICropImage cropComp = Utils.getComponent(ICropImage.class);
                cropComp.crop(img, cropX, cropY, cropW, cropH, attachmentClone.getMimeType(context), out);
                attachmentClone
                        .setContent(new ByteArrayInputStream(((ByteArrayOutputStream) out).toByteArray()));
                in = attachmentClone.getContentInputStream(context);
                img = decodeImageCommand.readImage(attachmentClone, context);
                in.close();
            }
            if ((height > 0) || (width > 0)) {
                ImageDimensions dimension = thumbGen.getThumbnailDimensions(img, width, height);
                byte[] thumbImageData = getThumbAttachment(img, dimension, thumbGen,
                        attachmentClone.getMimeType(context), watermark, copyright, defaultBg);
                attachmentClone.setContent(new ByteArrayInputStream(thumbImageData));
            }
            getImageCacheCmd().addToCache(key, attachmentClone);
        }
    } catch (Exception exp) {
        LOGGER.error("Error, could not resize / cache image", exp);
        attachmentClone = attachment;
    }
    return attachmentClone;
}

From source file:multiplayer.pong.client.LobbyFrame.java

/**
 * Creates new form LobbyFrame//  w w  w.  j  a  v  a 2 s .  c o m
 */
public LobbyFrame() {
    setTitle("Lobby - Pong!");
    getContentPane().setPreferredSize(new Dimension(800, 600));
    setResizable(false);
    setMaximumSize(new Dimension(800, 600));
    getContentPane().setMaximumSize(new Dimension(800, 600));
    // Initialisations
    getContentPane().setSize(new Dimension(800, 600));
    getContentPane().setBackground(new Color(0, 0, 0));
    initComponents();
    JRootPane rootPane = this.getRootPane();
    rootPane.setDefaultButton(commandBtn);
    usernamesT.setShowHorizontalLines(false);
    friendsT.setShowHorizontalLines(false);
    ta.setMargin(new Insets(10, 10, 10, 10));
    // Display initial text
    welcomeMessage();
    pendingRequests();
    // Listen to events
    socket = SocketHandler.getSocket();
    handleSockets();
    refresh();
}