Example usage for java.awt Color decode

List of usage examples for java.awt Color decode

Introduction

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

Prototype

public static Color decode(String nm) throws NumberFormatException 

Source Link

Document

Converts a String to an integer and returns the specified opaque Color .

Usage

From source file:org.gofleet.module.routing.RoutingMap.java

@Override
protected JPopupMenu getContextMenu() {
    JPopupMenu menu = new JPopupMenu();

    menu.setBackground(Color.decode("#E8EDF6"));

    String mapMenuTituloPlanning = i18n.getString("map.menu.titulo.planning");
    String mapMenuNewPlanning = i18n.getString("map.menu.new.planning");
    // Ttulo/*from w  ww .j av a  2  s  .com*/
    final JMenuItem titulo = new JMenuItem(mapMenuTituloPlanning);
    titulo.setFont(LogicConstants.deriveBoldFont(10.0f));
    titulo.setBackground(Color.decode("#A4A4A4"));
    titulo.setFocusable(false);

    menu.add(titulo);

    // New Planning
    final JMenuItem to = new JMenuItem(mapMenuNewPlanning, KeyEvent.VK_F6);
    to.setIcon(LogicConstants.getIcon("menucontextual_icon_destinoruta"));
    to.addActionListener(this);
    menu.add(to);

    menu.addSeparator();

    return menu;
}

From source file:org.entrystore.repository.config.PropertiesConfiguration.java

/**
 * @see se.kth.cid.config.Config#getColor(java.lang.String)
 *//* w ww  .ja  v  a 2 s. co  m*/
public Color getColor(String key) {
    Color result = null;
    String value = getString(key);

    if (value != null) {
        try {
            if (!value.startsWith("0x"))
                result = Color.decode(value);
            else {
                int rgb = Long.decode(value).intValue();
                result = new Color(rgb);
            }
        } catch (NumberFormatException nfe) {
        }
    }

    return result;
}

From source file:com.pronoiahealth.olhie.server.services.BookCoverImageService.java

/**
 * Create an image that contains text/* w  ww  .  j ava 2s. c o  m*/
 * 
 * @param height
 * @param width
 * @param text
 * @param textColor
 * @param center
 * @param fontMap
 * @param type
 * @return
 */
private BufferedImage createText(int height, int width, String text, String textColor, boolean center,
        Map<TextAttribute, Object> fontMap, int type) {
    BufferedImage img = new BufferedImage(width, height, type);
    Graphics2D g2d = null;
    try {
        g2d = (Graphics2D) img.getGraphics();

        // Create attributed text
        AttributedString txt = new AttributedString(text, fontMap);

        // Set graphics color
        g2d.setColor(Color.decode(textColor));

        // Create a new LineBreakMeasurer from the paragraph.
        // It will be cached and re-used.
        AttributedCharacterIterator paragraph = txt.getIterator();
        int paragraphStart = paragraph.getBeginIndex();
        int paragraphEnd = paragraph.getEndIndex();
        FontRenderContext frc = g2d.getFontRenderContext();
        LineBreakMeasurer lineMeasurer = new LineBreakMeasurer(paragraph, frc);

        // Set break width to width of Component.
        float breakWidth = (float) width;
        float drawPosY = 0;
        // Set position to the index of the first character in the
        // paragraph.
        lineMeasurer.setPosition(paragraphStart);

        // Get lines until the entire paragraph has been displayed.
        while (lineMeasurer.getPosition() < paragraphEnd) {
            // Retrieve next layout. A cleverer program would also cache
            // these layouts until the component is re-sized.
            TextLayout layout = lineMeasurer.nextLayout(breakWidth);

            // Compute pen x position. If the paragraph is right-to-left we
            // will align the TextLayouts to the right edge of the panel.
            // Note: drawPosX is always where the LEFT of the text is
            // placed.
            float drawPosX = layout.isLeftToRight() ? 0 : breakWidth - layout.getAdvance();

            if (center == true) {
                double xOffSet = (width - layout.getBounds().getWidth()) / 2;
                drawPosX = drawPosX + new Float(xOffSet);
            }

            // Move y-coordinate by the ascent of the layout.
            drawPosY += layout.getAscent();

            // Draw the TextLayout at (drawPosX, drawPosY).
            layout.draw(g2d, drawPosX, drawPosY);

            // Move y-coordinate in preparation for next layout.
            drawPosY += layout.getDescent() + layout.getLeading();
        }
    } finally {
        if (g2d != null) {
            g2d.dispose();
        }
    }
    return img;
}

From source file:org.opencms.applet.upload.FileUploadApplet.java

/**
 * Gets a color for drawing the output.<p>
 * // www .j  a va  2s .  co m
 * @param colorName the name of the color
 * @return color
 */
private Color getColor(String colorName) {

    Color col = Color.black;
    try {
        col = Color.decode((String) m_colors.get(colorName));
    } catch (Exception e) {
        System.err.println("Error reading " + colorName + ":" + e);
    }
    return col;
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.barcharts.StackedBar.java

/**
 * Inherited by IChart.// w  ww  . j a va  2  s  .c o  m
 * 
 * @param chartTitle the chart title
 * @param dataset the dataset
 * 
 * @return the j free chart
 */

public JFreeChart createChart(DatasetMap datasets) {

    logger.debug("IN");
    CategoryDataset dataset = (CategoryDataset) datasets.getDatasets().get("1");

    logger.debug("Taken Dataset");

    logger.debug("Get plot orientaton");
    PlotOrientation plotOrientation = PlotOrientation.VERTICAL;
    if (horizontalView) {
        plotOrientation = PlotOrientation.HORIZONTAL;
    }

    logger.debug("Call Chart Creation");
    JFreeChart chart = ChartFactory.createStackedBarChart(name, // chart title
            categoryLabel, // domain axis label
            valueLabel, // range axis label
            dataset, // data
            plotOrientation, // the plot orientation
            false, // legend
            true, // tooltips
            false // urls
    );
    logger.debug("Chart Created");

    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(color);
    plot.setRangeGridlinePaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);

    logger.debug("set renderer");
    StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setBaseItemLabelsVisible(true);

    if (percentageValue)
        renderer.setBaseItemLabelGenerator(
                new StandardCategoryItemLabelGenerator("{2}", new DecimalFormat("#,##.#%")));
    else if (makePercentage)
        renderer.setRenderAsPercentages(true);

    /*
    else
       renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
     */
    renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());

    if (maxBarWidth != null) {
        renderer.setMaximumBarWidth(maxBarWidth.doubleValue());
    }

    boolean document_composition = false;
    if (mode.equalsIgnoreCase(SpagoBIConstants.DOCUMENT_COMPOSITION))
        document_composition = true;

    logger.debug("Calling Url Generation");

    MyCategoryUrlGenerator mycatUrl = null;
    if (rootUrl != null) {
        logger.debug("Set MycatUrl");
        mycatUrl = new MyCategoryUrlGenerator(rootUrl);

        mycatUrl.setDocument_composition(document_composition);
        mycatUrl.setCategoryUrlLabel(categoryUrlName);
        mycatUrl.setSerieUrlLabel(serieUrlname);
    }
    if (mycatUrl != null)
        renderer.setItemURLGenerator(mycatUrl);

    logger.debug("Text Title");

    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }

    logger.debug("Style Labels");

    Color colorSubInvisibleTitle = Color.decode("#FFFFFF");
    StyleLabel styleSubSubTitle = new StyleLabel("Arial", 12, colorSubInvisibleTitle);
    TextTitle subsubTitle = setStyleTitle("", styleSubSubTitle);
    chart.addSubtitle(subsubTitle);
    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(color);

    logger.debug("Axis creation");
    // set the range axis to display integers only...

    NumberFormat nf = NumberFormat.getNumberInstance(locale);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    if (makePercentage)
        rangeAxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    else
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    if (rangeIntegerValues == true) {
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setLabelPaint(styleXaxesLabels.getColor());
    rangeAxis
            .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor());
    rangeAxis.setNumberFormatOverride(nf);

    if (rangeAxisLocation != null) {
        if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_LEFT")) {
            plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT);
        } else if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_RIGHT")) {
            plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT);
        } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_RIGHT")) {
            plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_RIGHT);
        } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_LEFT")) {
            plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT);
        }
    }

    renderer.setDrawBarOutline(false);

    logger.debug("Set series color");

    int seriesN = dataset.getRowCount();
    if (orderColorVector != null && orderColorVector.size() > 0) {
        logger.debug("color serie by SERIES_ORDER_COLORS template specification");
        for (int i = 0; i < seriesN; i++) {
            if (orderColorVector.get(i) != null) {
                Color color = orderColorVector.get(i);
                renderer.setSeriesPaint(i, color);
            }
        }
    } else if (colorMap != null) {
        for (int i = 0; i < seriesN; i++) {
            String serieName = (String) dataset.getRowKey(i);

            // if serie has been rinominated I must search with the new name!
            String nameToSearchWith = (seriesLabelsMap != null && seriesLabelsMap.containsKey(serieName))
                    ? seriesLabelsMap.get(serieName).toString()
                    : serieName;

            Color color = (Color) colorMap.get(nameToSearchWith);
            if (color != null) {
                renderer.setSeriesPaint(i, color);
                renderer.setSeriesItemLabelFont(i,
                        new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
            }
        }
    }

    logger.debug("If cumulative set series paint " + cumulative);

    if (cumulative) {
        int row = dataset.getRowIndex("CUMULATIVE");
        if (row != -1) {
            if (color != null)
                renderer.setSeriesPaint(row, color);
            else
                renderer.setSeriesPaint(row, Color.WHITE);
        }
    }

    MyStandardCategoryItemLabelGenerator generator = null;
    logger.debug("Are there addition labels " + additionalLabels);
    logger.debug("Are there value labels " + showValueLabels);

    if (showValueLabels) {
        renderer.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
        renderer.setBaseItemLabelsVisible(true);
        renderer.setBaseItemLabelFont(
                new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
        renderer.setBaseItemLabelPaint(styleValueLabels.getColor());

        if (valueLabelsPosition.equalsIgnoreCase("inside")) {
            renderer.setBasePositiveItemLabelPosition(
                    new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT));
            renderer.setBaseNegativeItemLabelPosition(
                    new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT));
        } else {
            renderer.setBasePositiveItemLabelPosition(
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.BASELINE_LEFT));
            renderer.setBaseNegativeItemLabelPosition(
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.BASELINE_LEFT));
        }
    } else if (additionalLabels) {

        generator = new MyStandardCategoryItemLabelGenerator(catSerLabels, "{1}", NumberFormat.getInstance());
        logger.debug("generator set");

        double orient = (-Math.PI / 2.0);
        logger.debug("add labels style");
        if (styleValueLabels.getOrientation() != null
                && styleValueLabels.getOrientation().equalsIgnoreCase("horizontal")) {
            orient = 0.0;
        }
        renderer.setBaseItemLabelFont(
                new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
        renderer.setBaseItemLabelPaint(styleValueLabels.getColor());

        logger.debug("add labels style set");

        renderer.setBaseItemLabelGenerator(generator);
        renderer.setBaseItemLabelsVisible(true);
        //vertical labels          
        renderer.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER, TextAnchor.CENTER, orient));
        renderer.setBaseNegativeItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER, TextAnchor.CENTER, orient));

        logger.debug("end of add labels ");

    }

    logger.debug("domain axis");

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4.0));
    domainAxis.setLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize()));
    domainAxis.setLabelPaint(styleYaxesLabels.getColor());
    domainAxis
            .setTickLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize()));
    domainAxis.setTickLabelPaint(styleYaxesLabels.getColor());
    //opacizzazione colori
    if (!cumulative)
        plot.setForegroundAlpha(0.6f);
    if (legend == true)
        drawLegend(chart);

    logger.debug("OUT");
    return chart;

}

From source file:org.opencms.util.CmsStringUtil.java

/**
 * Returns the color value (<code>{@link Color}</code>) for the given String value.<p> 
 * //from   ww w  .ja  v  a 2s.  c  o  m
 * All parse errors are caught and the given default value is returned in this case.<p>
 * 
 * @param value the value to parse as color
 * @param defaultValue the default value in case of parsing errors
 * @param key a key to be included in the debug output in case of parse errors
 * 
 * @return the int value for the given parameter value String
 */
public static Color getColorValue(String value, Color defaultValue, String key) {

    Color result;
    try {
        char pre = value.charAt(0);
        if (pre != '#') {
            value = "#" + value;
        }
        result = Color.decode(value);
    } catch (Exception e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(Messages.get().getBundle().key(Messages.ERR_UNABLE_TO_PARSE_COLOR_2, value, key));
        }
        result = defaultValue;
    }
    return result;
}

From source file:org.kalypso.ui.wizards.results.editor.EditStyleDialog.java

private Color resolveColor(final Object colorObj) {
    if (colorObj instanceof Color) {
        return (Color) colorObj;
    } else if (colorObj instanceof String) {
        try {/*from w ww .j a  v  a  2  s . com*/
            return Color.decode(((String) colorObj).trim());
        } catch (final NumberFormatException e) {
            return (Color) colorObj;
        }
    } else {
        return null;
    }
}

From source file:org.nees.rpi.vis.loaders.M3DVLoader.java

private Color processColor(String tag, Color defaultColor) throws LoaderException {
    List colorList = config.getList(tag);
    String hexColor = config.getString(tag);
    try {//from w  w  w . j  av a 2s. c  o  m
        if (colorList.size() == 3) {
            int red = Integer.parseInt(colorList.get(0).toString());
            int green = Integer.parseInt(colorList.get(1).toString());
            int blue = Integer.parseInt(colorList.get(2).toString());
            return new Color(red, green, blue);
        } else if (hexColor != null) {
            return Color.decode(hexColor);
        }
    } catch (Exception e) {
        throw new LoaderException("Badly formatted color setting", e);
    }

    return defaultColor;
}

From source file:uk.co.modularaudio.service.configuration.impl.ConfigurationServiceImpl.java

@Override
public Color getSingleColorValue(final String key) throws RecordNotFoundException {
    final String strVal = this.getSingleStringValue(key);
    return Color.decode(strVal);
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.AbstractChartExpression.java

protected Color parseColorFromString(final String colStr) {
    if (colStr == null) {
        return null;
    }/*  w  w  w  . j  a va2  s  .  com*/

    try {
        return Color.decode(colStr);
    } catch (NumberFormatException ex) {
        // Ignored - try other parser...
    }
    return ColorHelper.lookupColor(colStr);
}