List of usage examples for java.awt Color decode
public static Color decode(String nm) throws NumberFormatException
From source file:org.sonar.plugins.core.charts.XradarChart.java
@Override protected Plot getPlot(ChartParameters params) { SpiderWebPlot plot = new SpiderWebPlot(createDataset(params)); plot.setStartAngle(0D);//from w ww . j a va 2 s . co m plot.setOutlineVisible(false); plot.setAxisLinePaint(Color.decode("0xCCCCCC")); plot.setSeriesOutlineStroke(new BasicStroke(2f)); if (params.getValue(PARAM_INTERIOR_GAP) != null) { plot.setInteriorGap(Double.parseDouble(params.getValue(PARAM_INTERIOR_GAP, "0.4", false))); } if (params.getValue(PARAM_MAX_VALUE) != null) { plot.setMaxValue(Double.parseDouble(params.getValue(PARAM_MAX_VALUE, "100", false))); } configureColors(plot, params); return plot; }
From source file:ColorUtilitiy.java
/** * Parse a String into a Color. <p/> This method will accept either a color * name (a field name from {@link Color}, case insensitive e.g. "red"), or a * HTML hex color string (e.g. "#ff0000" for Color.RED). * /*from w w w . j a va2s.c om*/ * @param value * String to parse for color name or color number. * @return Color for s. */ private static Color parseColor(final String value) { if (value == null) { return null; } final Object o = knownColorsByName.get(value.toLowerCase()); if (o != null) { return (Color) o; } try { // get color by hex or octal value return Color.decode(value.trim()); } catch (NumberFormatException nfe) { return null; } }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.clusterchart.SimpleCluster.java
public JFreeChart createChart(DatasetMap datasets) { DefaultXYZDataset dataset = (DefaultXYZDataset) datasets.getDatasets().get("1"); JFreeChart chart = ChartFactory.createBubbleChart(name, yLabel, xLabel, dataset, PlotOrientation.HORIZONTAL, legend, true, false);//from w w w . j av a 2 s . c o m /*Font font = new Font("Tahoma", Font.BOLD, titleDimension); TextTitle title = new TextTitle(name, font); chart.setTitle(title);*/ TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } Color colorSubInvisibleTitle = Color.decode("#FFFFFF"); StyleLabel styleSubSubTitle = new StyleLabel("Arial", 12, colorSubInvisibleTitle); TextTitle subsubTitle = setStyleTitle("", styleSubSubTitle); chart.addSubtitle(subsubTitle); chart.setBackgroundPaint(color); XYPlot plot = (XYPlot) chart.getPlot(); plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD); //plot.setForegroundAlpha(0.50f); plot.setForegroundAlpha(0.65f); XYItemRenderer renderer = plot.getRenderer(); //define colors int seriesN = dataset.getSeriesCount(); if (colorMap != null) { boolean isSerieSel = true; for (int i = 0; i < seriesN; i++) { String serieName = (String) dataset.getSeriesKey(i); String tmpName = serieName.replaceAll(" ", ""); tmpName = tmpName.replace('.', ' ').trim(); if (serie_selected != null && serie_selected.size() > 0) { String serieSel = serie_selected.get(tmpName).toString(); isSerieSel = (serieSel.equalsIgnoreCase("TRUE") || serieSel.equalsIgnoreCase("YES") || serieSel.equalsIgnoreCase("1")) ? true : false; serieName = tmpName; } if (color != null && isSerieSel) { Color color = (Color) colorMap.get(serieName); renderer.setSeriesPaint(i, color); } else { Color color = new Color(Integer.decode(defaultColor).intValue()); renderer.setSeriesPaint(i, color); } } } // increase the margins to account for the fact that the auto-range // doesn't take into account the bubble size... NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); //domainAxis.setAutoRange(true); domainAxis.setRange(yMin, yMax); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); 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.setAutoRange(true); rangeAxis.setRange(xMin, xMax); TickUnits units = null; if (decimalXValues == false) units = (TickUnits) NumberAxis.createIntegerTickUnits(); else units = (TickUnits) NumberAxis.createStandardTickUnits(); rangeAxis.setStandardTickUnits(units); TickUnits domainUnits = null; if (decimalYValues == false) domainUnits = (TickUnits) NumberAxis.createIntegerTickUnits(); else domainUnits = (TickUnits) NumberAxis.createStandardTickUnits(); domainAxis.setStandardTickUnits(domainUnits); rangeAxis.setLowerMargin(1.0); rangeAxis.setUpperMargin(1.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()); domainAxis.setLowerMargin(1.0); domainAxis.setUpperMargin(1.0); //DecimalFormat format=(new DecimalFormat("0")); //rangeAxis.setNumberFormatOverride(format); if (legend == true) drawLegend(chart); return chart; }
From source file:test.uk.co.modularaudio.util.swing.colouredtoggle.TestUseColouredTextToggle.java
public void go() throws Exception { final JFrame testFrame = new JFrame("TestFrame"); testFrame.setSize(new Dimension(300, 300)); testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final Container contentPane = testFrame.getContentPane(); final MigLayoutStringHelper msh = new MigLayoutStringHelper(); msh.addLayoutConstraint("fill"); msh.addLayoutConstraint("gap 0"); msh.addLayoutConstraint("insets 0"); contentPane.setLayout(msh.createMigLayout()); final Color surroundColor = Color.decode("#44BB44"); final Color backgroundColor = Color.BLACK; final ToggleReceiver testReceiver = new ToggleReceiver() { @Override// w w w . j av a2s .co m public void receiveToggle(final int toggleId, final boolean active) { log.trace("Received a toggle of " + toggleId + " to " + active); } }; final ColouredTextToggle ctt = new ColouredTextToggle("NoTS", "Tooltip Text", backgroundColor, surroundColor, false, testReceiver, 1); contentPane.add(ctt, "grow"); testFrame.pack(); testFrame.addWindowListener(new WindowListener() { @Override public void windowOpened(final WindowEvent e) { } @Override public void windowIconified(final WindowEvent e) { } @Override public void windowDeiconified(final WindowEvent e) { } @Override public void windowDeactivated(final WindowEvent e) { } @Override public void windowClosing(final WindowEvent e) { log.trace("Window closing. Value of control is \"" + ctt.getControlValue() + "\""); } @Override public void windowClosed(final WindowEvent e) { } @Override public void windowActivated(final WindowEvent e) { } }); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { log.trace("Showing test frame"); testFrame.setVisible(true); } }); }
From source file:test.uk.co.modularaudio.util.swing.colouredtoggle.TestUseColouredLabelToggle.java
public void go() throws Exception { final JFrame testFrame = new JFrame("TestFrame"); testFrame.setSize(new Dimension(300, 300)); testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final Container contentPane = testFrame.getContentPane(); final MigLayoutStringHelper msh = new MigLayoutStringHelper(); msh.addLayoutConstraint("fill"); msh.addLayoutConstraint("gap 0"); msh.addLayoutConstraint("insets 0"); contentPane.setLayout(msh.createMigLayout()); final Color surroundColor = Color.decode("#FFFFFF"); final Color backgroundColor = Color.BLACK; final Color foregroundColor = Color.white; final ToggleReceiver testReceiver = new ToggleReceiver() { @Override/*from w w w.j a v a 2 s .c o m*/ public void receiveToggle(final int toggleId, final boolean active) { log.trace("Received a toggle of " + toggleId + " to " + active); } }; final ColouredLabelToggle clt = new ColouredLabelToggle("Trigger", "Tooltip Text", backgroundColor, foregroundColor, surroundColor, false, testReceiver, 0); contentPane.add(clt, "grow"); testFrame.pack(); testFrame.addWindowListener(new WindowListener() { @Override public void windowOpened(final WindowEvent e) { } @Override public void windowIconified(final WindowEvent e) { } @Override public void windowDeiconified(final WindowEvent e) { } @Override public void windowDeactivated(final WindowEvent e) { } @Override public void windowClosing(final WindowEvent e) { log.trace("Window closing. Value of control is \"" + clt.getControlValue() + "\""); } @Override public void windowClosed(final WindowEvent e) { } @Override public void windowActivated(final WindowEvent e) { } }); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { log.trace("Showing test frame"); testFrame.setVisible(true); } }); }
From source file:lectorarchivos.MostrarGraficaCSV.java
/** * Creates new form MostrarGraficaCSV/*from w w w . ja va 2 s. c o m*/ */ public MostrarGraficaCSV(JTable jTableInfoCSV) { initComponents(); this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); panel = new JPanel(); getContentPane().add(panel); //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()); } //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:HTMLColors.java
/** Transform a color string into a color object. * @param s the color string/* w w w. j a va 2 s. c o m*/ * @return the color object */ public static Color decodeColor(String s) { if (s == null) return null; Color c; try { c = Color.decode(s); } catch (NumberFormatException exc) { c = HTMLColors.getColor(s); } return c; }
From source file:ch.jamiete.hilda.moderatortools.commands.ServerinfoCommand.java
@Override public void execute(final Message message, final String[] arguments, final String label) { final Guild guild = message.getGuild(); final EmbedBuilder eb = new EmbedBuilder(); eb.setTitle(guild.getName());//from ww w . ja va 2s . com eb.setThumbnail(guild.getIconUrl()); eb.setColor(Color.decode("#008E09")); eb.addField("Server ID", guild.getId(), false); eb.addField("Server created on", guild.getCreationTime().format(this.dtf), false); eb.addField("Default text channel", guild.getDefaultChannel().getAsMention(), false); String channels = ""; channels += guild.getTextChannels().size() + " text "; channels += guild.getTextChannels().size() == 1 ? "channel" : "channels"; channels += " and "; channels += guild.getVoiceChannels().size() + " voice "; channels += guild.getVoiceChannels().size() == 1 ? "channel" : "channels"; eb.addField("Channels", channels, false); eb.addField("Voice region", guild.getRegion().getName(), false); if (guild.getAfkChannel() != null) { eb.addField("Voice AFK channel", "**" + guild.getAfkChannel().getName() + "** will be joined after " + Util.getFriendlyTime(guild.getAfkTimeout().getSeconds() * 1000L), false); } String members = ""; members += guild.getMembers().size() + " "; members += guild.getMembers().size() == 1 ? "member" : "members"; eb.addField("Members", members, false); if (guild.getMembers().size() > 50) { final List<Member> oldest = guild.getMembers().stream().sorted(new Comparator<Member>() { @Override public int compare(final Member one, final Member two) { final long onetime = System.currentTimeMillis() - one.getJoinDate().toInstant().toEpochMilli(); final long twotime = System.currentTimeMillis() - two.getJoinDate().toInstant().toEpochMilli(); if (onetime == twotime) { return 0; } else if (onetime > twotime) { return -1; } else { return 1; } } }).limit(10).collect(Collectors.toList()); final List<String> oldestnames = new ArrayList<String>(oldest.size()); oldest.forEach(m -> oldestnames.add(Util.getName(m))); eb.addField("Ten oldest members", Util.getAsList(oldestnames), false); final List<Member> newest = guild.getMembers().stream().sorted(new Comparator<Member>() { @Override public int compare(final Member one, final Member two) { final long onetime = System.currentTimeMillis() - one.getJoinDate().toInstant().toEpochMilli(); final long twotime = System.currentTimeMillis() - two.getJoinDate().toInstant().toEpochMilli(); if (onetime == twotime) { return 0; } else if (onetime > twotime) { return 1; } else { return -1; } } }).limit(10).collect(Collectors.toList()); final List<String> newestnames = new ArrayList<String>(newest.size()); newest.forEach(m -> newestnames.add(Util.getName(m))); eb.addField("Ten newest members", Util.getAsList(newestnames), false); } String verification = WordUtils .capitalize(guild.getVerificationLevel().name().toLowerCase().replace("_", "")); verification += " ("; switch (guild.getVerificationLevel()) { case HIGH: verification += "Users must be members for at least 10 minutes before talking."; break; case LOW: verification += "Users must have a verified email address."; break; case MEDIUM: verification += "Users must be registered on Discord for at least 5 minutes."; break; case NONE: verification += "All users can talk."; break; case VERY_HIGH: verification += "Users must have a verified phone number."; break; case UNKNOWN: verification += "Discord error."; break; } verification += ")"; eb.addField("Verification level", verification, false); eb.addField("Explicit content filter level", WordUtils.capitalize(guild.getExplicitContentLevel().name().toLowerCase().replace("_", "")) + " (" + guild.getExplicitContentLevel().getDescription() + ")", false); eb.addField("Owner", Util.getName(guild.getOwner()), false); this.reply(message, eb.build()); }
From source file:org.sonar.plugins.scmstats.charts.PieChart3D.java
@Override protected Plot getPlot(ChartParameters params) { PiePlot3D plot = new PiePlot3D(); String[] colorsHex = params.getValues(PARAM_COLORS, ",", true); String[] serie = params.getValues(PARAM_VALUES, ";", true); DefaultPieDataset set = new DefaultPieDataset(); Color[] colors = COLORS;/* w w w . j a va2 s .c o m*/ if (colorsHex != null && colorsHex.length > 0) { colors = new Color[colorsHex.length]; for (int i = 0; i < colorsHex.length; i++) { colors[i] = Color.decode("#" + colorsHex[i]); } } String[] keyValue = null; for (int i = 0; i < serie.length; i++) { if (!StringUtils.isEmpty(serie[i])) { keyValue = StringUtils.split(serie[i], "="); set.setValue(keyValue[0], Double.parseDouble(keyValue[1])); plot.setSectionPaint(keyValue[0], colors[i]); } } plot.setDataset(set); plot.setStartAngle(180); plot.setCircular(true); plot.setDirection(Rotation.CLOCKWISE); plot.setNoDataMessage(DEFAULT_MESSAGE_NODATA); plot.setInsets(RectangleInsets.ZERO_INSETS); plot.setForegroundAlpha(1.0f); plot.setBackgroundAlpha(0.0f); plot.setIgnoreNullValues(true); plot.setIgnoreZeroValues(true); plot.setOutlinePaint(Color.WHITE); plot.setShadowPaint(Color.GREEN); plot.setDarkerSides(true); plot.setLabelFont(DEFAULT_FONT); plot.setLabelPaint(Color.BLACK); plot.setLabelBackgroundPaint(Color.WHITE); plot.setLabelOutlinePaint(Color.WHITE); plot.setLabelShadowPaint(Color.GRAY); plot.setLabelPadding(new RectangleInsets(1, 1, 1, 1)); plot.setInteriorGap(0.01); plot.setMaximumLabelWidth(0.25); return plot; }
From source file:org.sonar.plugins.abacus.chart.PieChart3D.java
@Override protected Plot getPlot(ChartParameters params) { PiePlot3D plot = new PiePlot3D(); String[] colorsHex = params.getValues(PARAM_COLORS, ",", true); String[] serie = params.getValues(PARAM_VALUES, ";", true); DefaultPieDataset set = new DefaultPieDataset(); Color[] colors = COLORS;//from ww w . j a v a 2s . c o m if (colorsHex != null && colorsHex.length > 0) { colors = new Color[colorsHex.length]; for (int i = 0; i < colorsHex.length; i++) { colors[i] = Color.decode("#" + colorsHex[i]); } } String[] keyValue = null; for (int i = 0; i < serie.length; i++) { if (!StringUtils.isEmpty(serie[i])) { keyValue = StringUtils.split(serie[i], "="); set.setValue(keyValue[0], Double.parseDouble(keyValue[1])); plot.setSectionPaint(keyValue[0], colors[i]); } } plot.setDataset(set); plot.setStartAngle(360); plot.setCircular(true); plot.setDirection(Rotation.CLOCKWISE); plot.setNoDataMessage(DEFAULT_MESSAGE_NODATA); plot.setInsets(RectangleInsets.ZERO_INSETS); plot.setForegroundAlpha(1.0f); plot.setBackgroundAlpha(0.0f); plot.setIgnoreNullValues(true); plot.setIgnoreZeroValues(true); plot.setOutlinePaint(Color.WHITE); plot.setShadowPaint(Color.WHITE); plot.setDarkerSides(false); plot.setLabelFont(DEFAULT_FONT); plot.setLabelPaint(Color.BLACK); plot.setLabelBackgroundPaint(Color.WHITE); plot.setLabelOutlinePaint(Color.WHITE); plot.setLabelShadowPaint(Color.WHITE); plot.setLabelPadding(new RectangleInsets(1, 1, 1, 1)); plot.setInteriorGap(0.02); plot.setMaximumLabelWidth(0.15); return plot; }