List of usage examples for java.awt Color decode
public static Color decode(String nm) throws NumberFormatException
From source file:net.tbnr.gearz.game.kits.GearzKitItem.java
static GearzKitItem fromJsonObject(JSONObject object) throws GearzKitReadException { String materialName;// w w w. j a v a2 s . co m Integer quantity = 1; try { materialName = object.getString("item_type"); } catch (JSONException ex) { throw GearzKit.exceptionFromJSON("Could not read class", ex); } try { quantity = object.getInt("quantity"); } catch (JSONException ignored) { } Material material = Material.getMaterial(materialName); if (material == null) { throw new GearzKitReadException("Invalid Material Specified: " + materialName); } JSONArray enchants = null; Short data = null; try { if (object.has("enchants")) { enchants = object.getJSONArray("enchants"); } if (object.has("data")) { data = (short) object.getInt("data"); } } catch (JSONException ignored) { } HashMap<Enchantment, Integer> enchantmentMap = null; if (enchants != null) { enchantmentMap = new HashMap<>(); for (int x = 0; x < enchants.length(); x++) { try { JSONObject enchantObject = enchants.getJSONObject(x); String enchant_name = enchantObject.getString("name"); int level = enchantObject.getInt("level"); Enchantment e = Enchantment.getByName(enchant_name); if (e == null || level < 1) { throw new GearzKitReadException( "Invalid Enchantment " + x + " " + enchant_name + " " + level); } enchantmentMap.put(e, level); Gearz.getInstance().debug("Added enchant " + x + " " + e.getName() + ":" + level); } catch (JSONException e) { throw GearzKit.exceptionFromJSON("Could not read enchantment " + x, e); } } } GearzItemMeta itemMeta = new GearzItemMeta(); try { if (object.has("title")) { itemMeta.setTitle(object.getString("title")); } if (object.has("lore")) { JSONArray loreJSON = object.getJSONArray("lore"); List<String> lore = new ArrayList<>(); for (int y = 0; y < loreJSON.length(); y++) { lore.add(loreJSON.getString(y)); } itemMeta.setLore(lore); } if (object.has("owner")) { itemMeta.setOwner(object.getString("owner")); } if (object.has("color")) { Color decode = Color.decode(object.getString("color")); org.bukkit.Color color = org.bukkit.Color.fromRGB(decode.getRed(), decode.getGreen(), decode.getBlue()); itemMeta.setColor(color); } } catch (JSONException ex) { throw GearzKit.exceptionFromJSON("Could not read meta", ex); } GearzKitItem gearzKitItem = new GearzKitItem(material, quantity, itemMeta); if (enchantmentMap != null) { gearzKitItem.setEnchantments(enchantmentMap); } if (data != null) { gearzKitItem.setData(data); } return gearzKitItem; }
From source file:com.esofthead.mycollab.community.ui.chart.PieChartWrapper.java
@Override protected JFreeChart createChart() { // create the chart... pieDataSet = createDataset();//from w w w . j a v a 2 s .c om final JFreeChart chart = ChartFactory.createPieChart3D("", // chart // title pieDataSet, // data false, // include legend true, // tooltips? false // URLs? ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.getTitle().setPaint(new Color(0x5E5E5E)); chart.setBorderVisible(false); // set the background color for the chart... final PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setOutlineVisible(false); plot.setInsets(RectangleInsets.ZERO_INSETS); plot.setStartAngle(290); plot.setBackgroundPaint(Color.white); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); plot.setNoDataMessage("No data to display"); plot.setLabelGenerator(new JFreeChartLabelCustom()); final List keys = pieDataSet.getKeys(); for (int i = 0; i < keys.size(); i++) { final Comparable key = (Comparable) keys.get(i); plot.setSectionPaint(key, Color.decode( "0x" + GenericChartWrapper.CHART_COLOR_STR[i % GenericChartWrapper.CHART_COLOR_STR.length])); } // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:io.github.tavernaextras.biocatalogue.ui.search_results.ServiceListCellRenderer.java
/** * This entry can be in one of two states: * -- containing only the name of the resource and NOT loading further details; * -- containing only the name of the resource and LOADING further details. * /* www . ja v a2 s. c o m*/ * @param itemToRender * @return */ protected GridBagConstraints prepareInitiallyLoadingEntry(Object itemToRender) { TYPE resourceType = determineResourceType(itemToRender); LoadingResource resource = (LoadingResource) itemToRender; jlTypeIcon = new JLabel(resourceType.getIcon()); jlItemStatus = new JLabel(ResourceManager.getImageIcon(ResourceManager.SERVICE_STATUS_UNKNOWN_ICON)); jlItemTitle = new JLabel(Resource.getDisplayNameForResource(resource), JLabel.LEFT); jlItemTitle.setForeground(Color.decode("#AD0000")); // very dark red jlItemTitle.setFont(jlItemTitle.getFont().deriveFont(Font.PLAIN, jlItemTitle.getFont().getSize() + 2)); jlDescription = resource.isLoading() ? loaderBarAnimationGrey : loaderBarAnimationGreyStill; return (arrangeLayout(false)); }
From source file:com.netsteadfast.greenstep.action.CommonPieChartAction.java
private void setPlotColor(PiePlot plot, List<String> names, List<String> colors) throws Exception { for (int ix = 0; ix < names.size(); ix++) { plot.setSectionPaint(names.get(ix), Color.decode(colors.get(ix))); }/*from w w w . jav a 2s. co m*/ }
From source file:org.owasp.benchmark.score.report.Scatter.java
private JFreeChart display(String title, int height, int width, OverallResults or) { JFrame f = new JFrame(title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Note: this is a little weird, since each point is a separate series XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries("Scores"); for (OverallResult r : or.getResults()) { series.add(r.fpr * 100, r.tpr * 100); }/*from ww w. j a v a 2 s .c om*/ dataset.addSeries(series); chart = ChartFactory.createScatterPlot(title, "False Positive Rate", "True Positive Rate", dataset, PlotOrientation.VERTICAL, true, true, false); String fontName = "Arial"; DecimalFormat pctFormat = new DecimalFormat("0'%'"); theme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createJFreeTheme(); theme.setExtraLargeFont(new Font(fontName, Font.PLAIN, 24)); // title theme.setLargeFont(new Font(fontName, Font.PLAIN, 20)); // axis-title theme.setRegularFont(new Font(fontName, Font.PLAIN, 16)); theme.setSmallFont(new Font(fontName, Font.PLAIN, 12)); theme.setRangeGridlinePaint(Color.decode("#C0C0C0")); theme.setPlotBackgroundPaint(Color.white); theme.setChartBackgroundPaint(Color.white); theme.setGridBandPaint(Color.red); theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); theme.setBarPainter(new StandardBarPainter()); theme.setAxisLabelPaint(Color.decode("#666666")); theme.apply(chart); XYPlot xyplot = chart.getXYPlot(); NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis(); NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis(); xyplot.setOutlineVisible(true); rangeAxis.setRange(-9.99, 109.99); rangeAxis.setNumberFormatOverride(pctFormat); rangeAxis.setTickLabelPaint(Color.decode("#666666")); rangeAxis.setMinorTickCount(5); rangeAxis.setTickUnit(new NumberTickUnit(10)); rangeAxis.setAxisLineVisible(true); rangeAxis.setMinorTickMarksVisible(true); rangeAxis.setTickMarksVisible(true); rangeAxis.setLowerMargin(10); rangeAxis.setUpperMargin(10); xyplot.setRangeGridlineStroke(new BasicStroke()); xyplot.setRangeGridlinePaint(Color.lightGray); xyplot.setRangeMinorGridlinePaint(Color.decode("#DDDDDD")); xyplot.setRangeMinorGridlinesVisible(true); domainAxis.setRange(-5, 105); domainAxis.setNumberFormatOverride(pctFormat); domainAxis.setTickLabelPaint(Color.decode("#666666")); domainAxis.setMinorTickCount(5); domainAxis.setTickUnit(new NumberTickUnit(10)); domainAxis.setAxisLineVisible(true); domainAxis.setTickMarksVisible(true); domainAxis.setMinorTickMarksVisible(true); domainAxis.setLowerMargin(10); domainAxis.setUpperMargin(10); xyplot.setDomainGridlineStroke(new BasicStroke()); xyplot.setDomainGridlinePaint(Color.lightGray); xyplot.setDomainMinorGridlinePaint(Color.decode("#DDDDDD")); xyplot.setDomainMinorGridlinesVisible(true); chart.setTextAntiAlias(true); chart.setAntiAlias(true); chart.removeLegend(); chart.setPadding(new RectangleInsets(20, 20, 20, 20)); xyplot.getRenderer().setSeriesPaint(0, Color.decode("#4572a7")); // // setup item labels // XYItemRenderer renderer = xyplot.getRenderer(); // Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 7.0f, 7.0f); // for ( int i = 0; i < dataset.getSeriesCount(); i++ ) { // renderer.setSeriesShape(i, circle); // renderer.setSeriesPaint(i, Color.blue); // String letter = "" + ((String)dataset.getSeries(i).getKey()).charAt(0); // StandardXYItemLabelGenerator generator = new StandardXYItemLabelGenerator(letter); // renderer.setSeriesItemLabelGenerator(i, generator); // renderer.setSeriesItemLabelsVisible(i, true); // ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER ); // renderer.setSeriesPositiveItemLabelPosition(i, position); // } makeDataLabels(or, xyplot); makeLegend(or, 57, 48, dataset, xyplot); // put legend inside plot // LegendTitle lt = new LegendTitle(xyplot); // lt.setItemFont(theme.getSmallFont()); // lt.setPosition(RectangleEdge.RIGHT); // lt.setItemFont(theme.getSmallFont()); // XYTitleAnnotation ta = new XYTitleAnnotation(.7, .55, lt, RectangleAnchor.TOP_LEFT); // ta.setMaxWidth(0.48); // xyplot.addAnnotation(ta); // draw guessing line Stroke dashed = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 6, 3 }, 0); XYLineAnnotation guessing = new XYLineAnnotation(-5, -5, 105, 105, dashed, Color.red); xyplot.addAnnotation(guessing); XYPointerAnnotation worse = makePointer(75, 0, "Worse than guessing", TextAnchor.TOP_CENTER, 90); xyplot.addAnnotation(worse); XYPointerAnnotation better = makePointer(25, 100, "Better than guessing", TextAnchor.BOTTOM_CENTER, 270); xyplot.addAnnotation(better); XYTextAnnotation time = new XYTextAnnotation("Tool run time: " + or.getTime(), 12, -5.6); time.setTextAnchor(TextAnchor.TOP_LEFT); time.setFont(theme.getRegularFont()); time.setPaint(Color.red); xyplot.addAnnotation(time); XYTextAnnotation stroketext = new XYTextAnnotation(" Random Guess", 88, 107); stroketext.setTextAnchor(TextAnchor.CENTER_RIGHT); stroketext.setBackgroundPaint(Color.white); stroketext.setPaint(Color.red); stroketext.setFont(theme.getRegularFont()); xyplot.addAnnotation(stroketext); XYLineAnnotation strokekey = new XYLineAnnotation(58, 107, 68, 107, dashed, Color.red); xyplot.setBackgroundPaint(Color.white); xyplot.addAnnotation(strokekey); ChartPanel cp = new ChartPanel(chart, height, width, 400, 400, 1200, 1200, false, false, false, false, false, false); f.add(cp); f.pack(); f.setLocationRelativeTo(null); // f.setVisible(true); return chart; }
From source file:org.wings.plaf.ResourceFactory.java
/** * Utility method that creates an java.awt.Color from a html color hex string * * @return the create color/* w w w . j ava 2 s. c o m*/ */ public static Color makeColor(String colorString) { if (colorString != null) { try { return Color.decode(colorString.trim()); } catch (Exception ex) { throw new RuntimeException(ex); } } return null; }
From source file:es.emergya.ui.gis.HistoryMapViewer.java
/** * @param title//from w ww . ja v a 2 s. c o m * @param type * @param order * @param icon */ public HistoryMapViewer() { super("", PluginType.getType("GPS"), 2, "tab_icon_historico"); super.setTitle(i18n.getString("Main.GPS")); // Colores de los marcadores Main.pref.putColor("text", Color.decode(LogicConstants.get("TEXT_COLOR", "0xFFFFFF"))); Main.pref.putColor("node", Color.decode(LogicConstants.get("NODE_COLOR", "0xFFFFFF"))); Main.pref.putInteger("mappaint.fontsize", Integer.parseInt(LogicConstants.get("TEXT_SIZE", "12"))); resultadoHistorico = getResultadosButton(); super.mapType = true; }
From source file:org.kalypso.model.wspm.pdb.wspm.CheckoutRoughnessUpdater.java
private void updateColor() { final String colorAsString = m_roughness.getColor(); if (StringUtils.isEmpty(colorAsString)) return;/*from ww w .j a v a 2 s . c o m*/ final Color color = Color.decode(colorAsString); final RGB oldRGB = m_roughnessClass.getColor(); final Color oldColor = new Color(oldRGB.red, oldRGB.green, oldRGB.blue); if (ObjectUtils.equals(color, oldColor)) return; final RGB newRGB = new RGB(color.getRed(), color.getGreen(), color.getBlue()); m_roughnessClass.setColor(newRGB); m_changed = true; }
From source file:com.esofthead.mycollab.ui.chart.PieChartWrapper.java
@Override protected JFreeChart createChart() { // create the chart... pieDataSet = createDataset();/* w w w . j a v a 2s.co m*/ final JFreeChart chart = ChartFactory.createPieChart3D("", // chart // title pieDataSet, // data false, // include legend true, // tooltips? false // URLs? ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.getTitle().setPaint(new Color(0x5E5E5E)); chart.setBorderVisible(false); // set the background color for the chart... final PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setOutlineVisible(false); plot.setInsets(RectangleInsets.ZERO_INSETS); plot.setStartAngle(290); plot.setBackgroundPaint(Color.white); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); plot.setNoDataMessage("No data to display"); plot.setLabelGenerator(new JFreeChartLabelCustom()); final List keys = pieDataSet.getKeys(); for (int i = 0; i < keys.size(); i++) { final Comparable key = (Comparable) keys.get(i); int colorIndex = i % CHART_COLOR_STR.size(); plot.setSectionPaint(key, Color.decode("0x" + CHART_COLOR_STR.get(colorIndex))); } // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:org.wings.plaf.LookAndFeel.java
/** * Utility method that creates an java.awt.Color from a html color hex string * * @return the create color//w ww . ja v a 2 s . co m */ public static Color makeColor(String colorString) { if (colorString != null) { try { return Color.decode(colorString.trim()); } catch (Exception ex) { ex.printStackTrace(); return null; } } return null; }