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.wings.style.CSSStyleSheet.java

/**
 * Convert a "#FFFFFF" hex string to a Color.
 * If the color specification is bad, an attempt
 * will be made to fix it up./*from w w  w  .  j  a  va  2  s  . c o  m*/
 */
static final Color hexToColor(String value) {
    String digits;
    if (value.startsWith("#")) {
        digits = value.substring(1, Math.min(value.length(), 7));
    } else {
        digits = value;
    }
    String hstr = "0x" + digits;
    Color c;
    try {
        c = Color.decode(hstr);
    } catch (NumberFormatException nfe) {
        c = null;
    }
    return c;
}

From source file:com.aspose.showcase.qrcodegen.web.api.controller.QRCodeManagementController.java

private Color getColorValue(String foreColor, String defautlValue) {

    if (StringUtils.isBlank(foreColor)) {
        return Color.decode(defautlValue);
    } else {/*from ww  w  .  j  a v a2 s. c  om*/
        return Color.decode(foreColor);
    }
}

From source file:lectorarchivos.VerCSV.java

public static void mostrarGrafica(JTable jTableInfoCSV) {
    //Fuente de datos
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    //Recorremos la columna del consumo de la tabla
    for (int i = jTableInfoCSV.getRowCount() - 1; i >= 0; i--) {
        if (Double.parseDouble(jTableInfoCSV.getValueAt(i, 4).toString()) > 0)
            dataset.setValue(Double.parseDouble(jTableInfoCSV.getValueAt(i, 4).toString()), "Consumo",
                    jTableInfoCSV.getValueAt(i, 0).toString());
    }// w  w  w.j  a  v  a  2s  . co m

    //Creando el grfico
    JFreeChart chart = ChartFactory.createBarChart3D("Consumo", "Fecha", "Consumo", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(Color.cyan);
    chart.getTitle().setPaint(Color.black);
    chart.setBackgroundPaint(Color.white);
    chart.removeLegend();

    //Cambiar color de barras
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    BarRenderer barRenderer = (BarRenderer) plot.getRenderer();
    barRenderer.setSeriesPaint(0, Color.decode("#5882FA"));

    // Mostrar Grafico
    ChartFrame frame = new ChartFrame("CONSUMO", chart);
    frame.pack();
    frame.getChartPanel().setMouseZoomable(false);
    frame.setVisible(true);

    panel.add(frame);

}

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

/**
 * Create the front cover/*from  ww  w .  j  a v  a2  s .  co  m*/
 * 
 * @param coverId
 * @param logoBytes
 * @param authorStr
 * @param titleStr
 * @param textColor
 *            - ex. #FFFFFF
 * @param width
 * @param height
 * @param type
 *            - ex. BufferedImage.TYPE_INT_ARGB
 * @param imgFormat
 *            - ex. ImageFormat.IMAGE_FORMAT_PNG
 * @return
 * @throws Exception
 */
public byte[] createFrontCover(String coverId, byte[] logoBytes, String authorStr, String titleStr,
        String spineColor, String authorTextColor, String titleTextColor, int width, int height, int type,
        ImageFormat imgFormat, int maxColors) throws Exception {

    Graphics2D g = null;

    try {
        // Front cover first
        // Read in base cover image
        BufferedImage coverImg = Imaging.getBufferedImage(coverMap.get(coverId));

        // Resize cover image to the basic 300 X 400 for front cover
        BufferedImage frontCoverImg = resize(coverImg, 300, 400, type);
        g = (Graphics2D) frontCoverImg.getGraphics();

        // Draw logo if present
        if (logoBytes != null && logoBytes.length > 0) {
            // Resize logo to 200x100
            BufferedImage logoImg = Imaging.getBufferedImage(logoBytes);
            BufferedImage outLogo = null;
            int logoHeight = logoImg.getHeight();
            int logoWidth = logoImg.getWidth();

            if (logoHeight > 100 || logoWidth > 200) {
                outLogo = this.resize(logoImg, logoWidth > 200 ? 200 : logoWidth,
                        logoHeight > 100 ? 100 : logoHeight, type);
            } else {
                outLogo = logoImg;
            }

            // Add to coverImg
            g.drawImage(outLogo, 32, 25, null);
        }

        // Add spine if present
        if (spineColor != null && spineColor.length() > 0) {
            g.setColor(Color.decode(spineColor));
            g.fillRect(0, 0, 2, frontCoverImg.getHeight());
        }

        // Add author if present
        if (authorStr != null && authorStr.length() > 0) {
            // Add author text to image
            BufferedImage authorTextImg = createText(40, 220, authorStr, authorTextColor, false, authorFontMap,
                    type);
            g.drawImage(authorTextImg, 30, 215, null);
        }

        // Add title if present
        if (titleStr != null && titleStr.length() > 0) {
            BufferedImage titleTextImg = createText(100, 220, titleStr, titleTextColor, false, titleFontMap,
                    type);
            g.drawImage(titleTextImg, 30, 240, null);
        }

        // If the requested size is not 300X400 convert the image
        BufferedImage outImg = null;
        if (width != 300 || height != 400) {
            outImg = resize(frontCoverImg, width, height, type);
        } else {
            outImg = frontCoverImg;
        }

        // Do we want a PNG with a fixed number of colors
        if (maxColors >= 2 && imgFormat == ImageFormat.IMAGE_FORMAT_PNG) {
            outImg = ImageUtils.reduce32(outImg, maxColors);
        }

        // Return bytes
        Map<String, Object> params = new HashMap<String, Object>();
        byte[] outBytes = Imaging.writeImageToBytes(outImg, imgFormat, params);
        return outBytes;
    } finally {
        if (g != null) {
            g.dispose();
        }
    }
}

From source file:de.tsystems.mms.apm.performancesignature.PerfSigProjectAction.java

private JFreeChart createChart(final JSONObject jsonObject, final CategoryDataset dataset)
        throws UnsupportedEncodingException {
    final String measure = jsonObject.getString(Messages.PerfSigProjectAction_ReqParamMeasure());
    final String chartDashlet = jsonObject.getString("chartDashlet");
    final String testCase = jsonObject.getString("dashboard");
    final String customMeasureName = jsonObject.getString("customName");
    final String aggregation = jsonObject.getString("aggregation");

    String unit = "", color = Messages.PerfSigProjectAction_DefaultColor();

    for (DashboardReport dr : getLastDashboardReports()) {
        if (dr.getName().equals(testCase)) {
            final Measure m = dr.getMeasure(chartDashlet, measure);
            if (m != null) {
                unit = aggregation.equalsIgnoreCase("Count") ? "num" : m.getUnit();
                color = URLDecoder.decode(m.getColor(), "UTF-8");
            }//  www. j  a  va 2  s  . c  o  m
            break;
        }
    }

    String title = customMeasureName;
    if (StringUtils.isBlank(customMeasureName))
        title = PerfSigUtils.generateTitle(measure, chartDashlet);

    final JFreeChart chart = ChartFactory.createBarChart(title, // title
            "build", // category axis label
            unit, // value axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            false, // tooltips
            false // urls
    );

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();

    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setForegroundAlpha(0.8f);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);

    final CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    //domainAxis.setLowerMargin(0.0);
    //domainAxis.setUpperMargin(0.0);
    //domainAxis.setCategoryMargin(0.0);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    final BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
    renderer.setSeriesPaint(0, Color.decode(color));

    return chart;
}

From source file:com.uttesh.pdfngreport.handler.PdfReportHandler.java

/**
 * Not Used for the current release// ww w  .  j a  v  a 2 s .c om
 *
 * @param dataSet
 */
public void pieExplodeChart(DefaultPieDataset dataSet, String os) {
    try {
        JFreeChart chart = ChartFactory.createPieChart("", dataSet, true, true, false);
        ChartStyle.theme(chart);
        PiePlot plot = (PiePlot) chart.getPlot();
        plot.setForegroundAlpha(0.6f);
        plot.setCircular(true);
        plot.setSectionPaint("Passed", Color.decode("#019244"));
        plot.setSectionPaint("Failed", Color.decode("#EE6044"));
        plot.setSectionPaint("Skipped", Color.decode("#F0AD4E"));
        Color transparent = new Color(0.0f, 0.0f, 0.0f, 0.0f);
        //plot.setLabelLinksVisible(Boolean.FALSE);
        plot.setLabelOutlinePaint(transparent);
        plot.setLabelBackgroundPaint(transparent);
        plot.setLabelShadowPaint(transparent);
        plot.setLabelLinkPaint(Color.GRAY);
        Font font = new Font("SansSerif", Font.PLAIN, 10);
        plot.setLabelFont(font);
        plot.setLabelPaint(Color.DARK_GRAY);
        plot.setExplodePercent("Passed", 0.10);
        //plot.setExplodePercent("Failed", 0.10);
        //plot.setExplodePercent("Skipped", 0.10);
        plot.setSimpleLabels(true);
        PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{1} ({2})", new DecimalFormat("0"),
                new DecimalFormat("0%"));
        plot.setLabelGenerator(gen);

        if (os != null && os.equalsIgnoreCase("w")) {
            ChartUtilities.saveChartAsPNG(
                    new File(reportLocation + Constants.BACKWARD_SLASH + Constants.REPORT_CHART_FILE), chart,
                    560, 200);
        } else {
            ChartUtilities.saveChartAsPNG(
                    new File(reportLocation + Constants.FORWARD_SLASH + Constants.REPORT_CHART_FILE), chart,
                    560, 200);
        }
    } catch (Exception e) {
        e.printStackTrace(System.err);
        if (os != null && os.equalsIgnoreCase("w")) {
            new File(reportLocation + Constants.BACKWARD_SLASH + Constants.REPORT_CHART_FILE).delete();
        } else {
            new File(reportLocation + Constants.FORWARD_SLASH + Constants.REPORT_CHART_FILE).delete();
        }
        System.exit(-1);
    }
}

From source file:userinterface.StateNetworkAdminRole.StateReportsJPanel.java

private JFreeChart createDonorsReportsChart(CategoryDataset dataset) {
    JFreeChart barChart = ChartFactory.createBarChart("No Of Registered Donors", "Year", "Registered Donors",
            dataset, PlotOrientation.VERTICAL, true, true, false);
    barChart.setBackgroundPaint(Color.white);
    // Set the background color of the chart
    barChart.getTitle().setPaint(Color.DARK_GRAY);
    barChart.setBorderVisible(true);/*from  w w  w .j  a  v  a  2s  . c o  m*/
    // Adjust the color of the title
    CategoryPlot plot = barChart.getCategoryPlot();
    plot.getRangeAxis().setLowerBound(0.0);
    // Get the Plot object for a bar graph
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.blue);
    CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.decode("#00008B"));
    //return chart;
    return barChart;
}

From source file:net.sf.dsig.DSApplet.java

private void initSwing() {
    try {/*w ww  .  j  a  v  a2s  .c  o m*/
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        logger.warn("UIManager.setLookAndFeel() failed", e);
    }

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
    panel.setBackground(Color.decode(backgroundColor));
    add(panel);

    boolean lockPrinted = false;
    if (formId != null) {
        Icon lockIcon = new ImageIcon(getClass().getResource("/icons/lock.png"));
        lockPrinted = true;

        JButton button = new JButton("Sign", lockIcon);
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                available.acquireUninterruptibly();
                try {
                    signInternal(formId, null);
                } catch (Exception ex) {
                    logger.error("Internal sign failed", e);
                } finally {
                    available.release();
                }
            }
        });
        panel.add(button);
    }

    Icon infoIcon = new ImageIcon(getClass().getResource(lockPrinted ? "/icons/info.png" : "/icons/lock.png"));
    JLabel infoLabel = new JLabel(infoIcon);
    infoLabel.addMouseListener(new MouseListener() {
        public void mouseClicked(MouseEvent e) {
            JOptionPane.showMessageDialog(null, printInfoMessage());
        }

        public void mouseEntered(MouseEvent e) {
            /* NOOP */ }

        public void mouseExited(MouseEvent e) {
            /* NOOP */ }

        public void mousePressed(MouseEvent e) {
            /* NOOP */ }

        public void mouseReleased(MouseEvent e) {
            /* NOOP */ }
    });
    panel.add(infoLabel);
}

From source file:at.tuwien.ifs.somtoolbox.apps.viewer.GeneralUnitPNode.java

/**
 * Initializes common properties for unit PNodes and empty PNodes
 *//*from  w  w  w. j  av a2 s.co  m*/
private void initPNodeProperties(double width, double height) {
    border = new Rectangle2D.Double();
    GridGeometry helper = state.growingLayer.getGridGeometry();
    this.width = helper.adjustUnitWidth(width, height);
    this.height = helper.adjustUnitHeight(width, height);
    border.setRect(X, Y, width, height);
    this.setBounds(X, Y, width, height);
    selectionMarker = PPath.createRectangle((float) X, (float) Y, (float) width, (float) height);
    selectionMarker.setPaint(Color.decode("#ff7505"));
    selectionMarker.setTransparency(0.5f);

    queryResultMarker = PPath.createRectangle((float) X, (float) Y, (float) width, (float) height);
    queryResultMarker.setPaint(Color.ORANGE);
    queryResultMarker.setTransparency(0.5f);
}

From source file:wigraph.ShortestPathRelation.java

public ShortestPathRelation() {

    initialize();//  w ww . ja  va 2s  .c o  m

    String[] w1 = INITIAL_WORD_SET1.split(",");
    String[] w2 = INITIAL_WORD_SET2.split(",");
    this.mGraph = getGraph(w1, w2);
    removeIsolatedVertices(this.mGraph);

    setBackground(Color.WHITE);
    // show graph
    layout = new FRLayout<String, Number>(mGraph);

    vv = new VisualizationViewer<String, Number>(layout);
    vv.setBackground(Color.WHITE);

    vv.getRenderContext().setVertexDrawPaintTransformer(new MyVertexDrawPaintFunction<String>());
    vv.getRenderContext().setVertexFillPaintTransformer(new MyVertexFillPaintFunction<String>());
    vv.getRenderContext().setEdgeDrawPaintTransformer(new MyEdgePaintFunction());
    vv.getRenderContext().setEdgeStrokeTransformer(new MyEdgeStrokeFunction());
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>());
    vv.setGraphMouse(new DefaultModalGraphMouse<String, Number>());
    vv.addPostRenderPaintable(new VisualizationViewer.Paintable() {

        public boolean useTransform() {
            return true;
        }

        public void paint(Graphics g) {
            if (mPred == null)
                return;

            // for all edges, paint edges that are in shortest path
            for (Number e : layout.getGraph().getEdges()) {

                if (isBlessed(e)) {
                    String v1 = mGraph.getEndpoints(e).getFirst();
                    String v2 = mGraph.getEndpoints(e).getSecond();
                    Point2D p1 = layout.transform(v1);
                    Point2D p2 = layout.transform(v2);
                    p1 = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, p1);
                    p2 = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, p2);
                    Renderer<String, Number> renderer = vv.getRenderer();
                    renderer.renderEdge(vv.getRenderContext(), layout, e);
                }
            }
        }
    });

    edgeLabelRenderer = vv.getRenderContext().getEdgeLabelRenderer();

    Transformer<Number, String> stringer = new Transformer<Number, String>() {
        public String transform(Number e) {
            Relation r = TRelation.getRelationType(ruwikt_parsed_conn, mGraph.getEndpoints(e).getFirst(),
                    mGraph.getEndpoints(e).getSecond());

            /*System.out.println("word1=" + mGraph.getEndpoints(e).getFirst() +
                         "; word2=" + mGraph.getEndpoints(e).getSecond());
            if(null != r)
            System.out.println("relation=" + r.toString());*/

            return null == r ? "" : r.toString();

            //return "Edge:"+mGraph.getEndpoints(e).toString();
        }
    };
    vv.getRenderContext().setEdgeLabelTransformer(stringer);

    // button to search a shortest path using word sets 1 & 2, redraw picture
    search_path_btn = new JButton("Search");
    search_path_btn.setToolTipText("Search a shortest path");
    search_path_btn.setBackground(Color.decode("#D8C0C0"));

    search_path_btn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            // delete all vertices
            List<String> vertices = new ArrayList<String>();
            vertices.addAll(mGraph.getVertices());
            for (String v : vertices)
                mGraph.removeVertex(v);

            String[] w1_source = word_set1.getText().split(",");
            String[] w2_source = word_set2.getText().split(",");

            w1_source = StringUtil.trim(w1_source);
            w2_source = StringUtil.trim(w2_source);

            // get only words in Wiktionary, i.e. in a graph
            String[] w1 = GraphCreator.getOnlyVertexInGraph(g_all_relations, w1_source);
            String[] w2 = GraphCreator.getOnlyVertexInGraph(g_all_relations, w2_source);

            mGraph = getGraph(w1, w2);
            removeIsolatedVertices(mGraph);

            layout.setGraph(mGraph);
            vv.repaint();

            DistanceData dist = PathSearcher.calcPathLenRelatedness(g_all_relations, alg, w1, w2);
            result_len.setText(
                    "Shortest path len: min=" + dist.min + ", average=" + dist.average + ", max=" + dist.max);

            System.out.println("Word set 1 has length " + w1.length);
            System.out.println("Word set 2 has length " + w2.length);

            System.out.println("Vertices : " + mGraph.getVertexCount());
            System.out.println("Edges : " + mGraph.getEdgeCount());
        }
    });

    setLayout(new BorderLayout());
    add(vv, BorderLayout.CENTER);
    // set up controls
    add(setUpControls(), BorderLayout.SOUTH);
}