Java Code Examples for java.awt.Color#decode()
The following examples show how to use
java.awt.Color#decode() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: birt File: PropertyUtil.java License: Eclipse Public License 1.0 | 6 votes |
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; }
Example 2
Source Project: pentaho-reporting File: ColorValueConverter.java License: GNU Lesser General Public License v2.1 | 6 votes |
/** * Converts a string to a {@link Integer}. * * @param value * the string. * @return a {@link Integer}. */ public Object toPropertyValue( final String value ) throws BeanException { if ( value == null ) { throw new NullPointerException(); } final Object o = ColorValueConverter.knownColorsByName.get( value.toLowerCase() ); if ( o != null ) { return o; } try { // get color by hex or octal value return Color.decode( value.trim() ); } catch ( NumberFormatException nfe ) { // if we can't decode lets try to get it by name throw new BeanException( "Failed to parse color text as RGB-number.", nfe ); } }
Example 3
Source Project: openjdk-8 File: CSS.java License: GNU General Public License v2.0 | 6 votes |
/** * Convert a "#FFFFFF" hex string to a Color. * If the color specification is bad, an attempt * will be made to fix it up. */ static final Color hexToColor(String value) { String digits; int n = value.length(); 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; }
Example 4
Source Project: astor File: PaintUtilities.java License: GNU General Public License v2.0 | 6 votes |
/** * Converts a given string into a color. * * @param value the string, either a name or a hex-string. * @return the color. */ public static Color stringToColor(String value) { if (value == null) { return Color.black; } try { // get color by hex or octal value return Color.decode(value); } catch (NumberFormatException nfe) { // if we can't decode lets try to get it by name try { // try to get a color by name using reflection final Field f = Color.class.getField(value); return (Color) f.get(null); } catch (Exception ce) { // if we can't get any color return black return Color.black; } } }
Example 5
Source Project: plugins File: GroundItemsConfig.java License: GNU General Public License v3.0 | 5 votes |
@ConfigItem( keyName = "highlightedColor", name = "Highlighted items", description = "Configures the color for highlighted items", position = 3, titleSection = "colorsTitle" ) @Alpha default Color highlightedColor() { return Color.decode("#C46AFF"); }
Example 6
Source Project: visualvm File: Configuration.java License: GNU General Public License v2.0 | 5 votes |
/** * return the COlor that has the given key = prefix.key or key = key or * default, in that order * @param prefix * @param key * @param Default * @return */ public Color getPrefixColor(String prefix, String key, Color Default) { String c = getPrefixProperty(prefix, key, null); if (c == null) { return Default; } try { return Color.decode(c); } catch (NumberFormatException e) { return Default; } }
Example 7
Source Project: dsworkbench File: TableHelper.java License: Apache License 2.0 | 5 votes |
private static Color getColorCode(int num) { int initialColorAngle = 60; float hueDiv = 0; float satDiv = 0; float valMax = 0; float satSec = 0; float hueSec = 0; float valSec = 0; if (sortBySaturation) { hueDiv = 10; satDiv = 6; valMax = 3; satSec = num % satDiv; hueSec = num / satDiv % hueDiv; valSec = num / satDiv / hueDiv; } else { hueDiv = 15; satDiv = 4; valMax = 3; hueSec = num % hueDiv; satSec = num / hueDiv % satDiv; valSec = num / hueDiv / satDiv; } float colorMaximum = hueDiv * satDiv * valMax; if (num > colorMaximum) { return new Color(50, 10, 100); } //we ran out of colors else { float h = -360 / hueDiv * hueSec + initialColorAngle; float s = 20 + 80 / (satDiv - 1) * satSec; float v = 100 - 20 * valSec; return Color.decode(hsv2rgb_hex(h, s, v)); } }
Example 8
Source Project: astor File: StandardChartTheme.java License: GNU General Public License v2.0 | 5 votes |
/** * Creates and returns a theme called "Darkness". In this theme, the * charts have a black background. * * @return The "Darkness" theme. */ public static ChartTheme createDarknessTheme() { StandardChartTheme theme = new StandardChartTheme("Darkness"); theme.titlePaint = Color.white; theme.subtitlePaint = Color.white; theme.legendBackgroundPaint = Color.black; theme.legendItemPaint = Color.white; theme.chartBackgroundPaint = Color.black; theme.plotBackgroundPaint = Color.black; theme.plotOutlinePaint = Color.yellow; theme.baselinePaint = Color.white; theme.crosshairPaint = Color.red; theme.labelLinkPaint = Color.lightGray; theme.tickLabelPaint = Color.white; theme.axisLabelPaint = Color.white; theme.shadowPaint = Color.darkGray; theme.itemLabelPaint = Color.white; theme.drawingSupplier = new DefaultDrawingSupplier( new Paint[] {Color.decode("0xFFFF00"), Color.decode("0x0036CC"), Color.decode("0xFF0000"), Color.decode("0xFFFF7F"), Color.decode("0x6681CC"), Color.decode("0xFF7F7F"), Color.decode("0xFFFFBF"), Color.decode("0x99A6CC"), Color.decode("0xFFBFBF"), Color.decode("0xA9A938"), Color.decode("0x2D4587")}, new Paint[] {Color.decode("0xFFFF00"), Color.decode("0x0036CC")}, new Stroke[] {new BasicStroke(2.0f)}, new Stroke[] {new BasicStroke(0.5f)}, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE); theme.wallPaint = Color.darkGray; theme.errorIndicatorPaint = Color.lightGray; theme.gridBandPaint = new Color(255, 255, 255, 20); theme.gridBandAlternatePaint = new Color(255, 255, 255, 40); return theme; }
Example 9
Source Project: rapidminer-studio File: ParameterTypeColor.java License: GNU Affero General Public License v3.0 | 5 votes |
public static Color string2Color(String colorString) { try { return Color.decode(colorString); } catch (Exception e) { String[] colors = colorString.split(","); if (colors.length == 3) { return new Color(Integer.parseInt(colors[0]), Integer.parseInt(colors[1]), Integer.parseInt(colors[2])); } else { // LogService.getRoot().warning("Cannot parse color: "+colorString); LogService.getRoot().log(Level.WARNING, "com.rapidminer.parameter.ParameterTypeColor.parsing_color_error", colorString); return Color.BLACK; } } }
Example 10
Source Project: netbeans File: SettingsConversions.java License: Apache License 2.0 | 5 votes |
/** Converts a String to an integer and returns the specified opaque Color. */ public static Color parseColor(String s) { try { return Color.decode(s); } catch (NumberFormatException nfe) { LOG.log(Level.WARNING, null, nfe); return null; } }
Example 11
Source Project: buffer_bci File: StandardChartTheme.java License: GNU General Public License v3.0 | 5 votes |
/** * Creates and returns a theme called "Darkness". In this theme, the * charts have a black background. * * @return The "Darkness" theme. */ public static ChartTheme createDarknessTheme() { StandardChartTheme theme = new StandardChartTheme("Darkness"); theme.titlePaint = Color.white; theme.subtitlePaint = Color.white; theme.legendBackgroundPaint = Color.black; theme.legendItemPaint = Color.white; theme.chartBackgroundPaint = Color.black; theme.plotBackgroundPaint = Color.black; theme.plotOutlinePaint = Color.yellow; theme.baselinePaint = Color.white; theme.crosshairPaint = Color.red; theme.labelLinkPaint = Color.lightGray; theme.tickLabelPaint = Color.white; theme.axisLabelPaint = Color.white; theme.shadowPaint = Color.darkGray; theme.itemLabelPaint = Color.white; theme.drawingSupplier = new DefaultDrawingSupplier( new Paint[] {Color.decode("0xFFFF00"), Color.decode("0x0036CC"), Color.decode("0xFF0000"), Color.decode("0xFFFF7F"), Color.decode("0x6681CC"), Color.decode("0xFF7F7F"), Color.decode("0xFFFFBF"), Color.decode("0x99A6CC"), Color.decode("0xFFBFBF"), Color.decode("0xA9A938"), Color.decode("0x2D4587")}, new Paint[] {Color.decode("0xFFFF00"), Color.decode("0x0036CC")}, new Stroke[] {new BasicStroke(2.0f)}, new Stroke[] {new BasicStroke(0.5f)}, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE); theme.wallPaint = Color.darkGray; theme.errorIndicatorPaint = Color.lightGray; theme.gridBandPaint = new Color(255, 255, 255, 20); theme.gridBandAlternatePaint = new Color(255, 255, 255, 40); theme.shadowGenerator = null; return theme; }
Example 12
Source Project: restcommander File: Images.java License: Apache License 2.0 | 4 votes |
public String getText(String color, int length, String chars) { this.textColor = Color.decode(color); return getText(length, chars); }
Example 13
Source Project: tectonicus File: MutableLayer.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public Color getBackgroundColorRGB() { return Color.decode(backgroundColor); }
Example 14
Source Project: rapidminer-studio File: ClassColorMap.java License: GNU Affero General Public License v3.0 | 4 votes |
@Override public Color parseValue(String value, ClassLoader classLoader, Plugin provider) { return Color.decode(value.trim()); }
Example 15
Source Project: dsworkbench File: AttackToBBCodeFormater.java License: Apache License 2.0 | 4 votes |
public static String getRandomGreen() { Color c = Color.decode("#2eb92e"); int randomColor = c.getRGB() + (int) Math.rint(Math.random() * 10); return "#" + Integer.toHexString(new Color(randomColor).getRGB()).substring(2); }
Example 16
Source Project: binnavi File: CResultColor.java License: Apache License 2.0 | 4 votes |
/** * Determines the background color to be used in the table and in the graph to highlight a given * instruction result. * * @param startInstruction The start instruction of the operand tracking operation. * @param trackedRegister The tracked register of the operand tracking operation. * @param result The result to highlight. * * @return The color used for highlighting. */ public static Color determineBackgroundColor(final INaviInstruction startInstruction, final String trackedRegister, final CInstructionResult result) { Preconditions.checkNotNull( startInstruction, "IE01671: Start instruction argument can not be null"); Preconditions.checkNotNull( trackedRegister, "IE01672: Tracked register argument can not be null"); Preconditions.checkNotNull(result, "IE01673: Result argument can not be null"); if (result.getInstruction() == startInstruction) { // This is the color used for the start instruction. return Color.decode("0x00BF00"); } else if (result.undefinesAll()) { // This is the color for instructions that undefine all tracked // registers and therefore end the register tracking for one // code execution path. return Color.decode("0xB30000"); } else if (result.clearsTrackedRegister(trackedRegister)) { // This is the color used for instructions that undefined the // tracked register but do not undefine all tracked registers. return Color.decode("0xA12967"); } else if (result.undefinesSome()) { // This is the color used for instructions that undefine some // tracked registers but not the originally tracked register. return Color.decode("0xED693F"); } else if (result.defines()) { // This is the color used for instructions that do not undefine // any registers but use any of the tracked registers. return Color.decode("0xFFCD55"); } else if (result.updates()) { // This is the color used for instructions that update any of // the tainted registers with new information. return Color.decode("0x5AAB47"); } else if (result.uses()) { // This is the text used for instructions that read any of // the tainted registers. return Color.decode("0x414142"); } else { return Color.WHITE; } }
Example 17
Source Project: chipster File: SOM.java License: MIT License | 4 votes |
/** * Makes a chartPanel with SOM visualization from the data of dataBean. * Finds the biggest coordinate pair from the imput and assumes that all lower * coordinate pairs are found from the data ( otherwise Viski-library throws nullPointer * from the deSelectAll-method of the SOMDataSet class). */ @Override public JComponent getVisualisation(DataBean data) throws Exception { // iterate over input data to find out the dimensions of the table int maxX=0; int maxY=0; try (Table som = data.queryFeatures("/clusters/som").asTable()) { while (som.nextRow()) { if (som.getIntValue("x") > maxX) { maxX = som.getIntValue("x"); } if (som.getIntValue("y") > maxY) { maxY = som.getIntValue("y"); } } } // these has to be exactly right, otherwise NPE is thrown SOMDataset dataset = new SOMDataset(maxX,maxY); // iterate again to read actual data try (Table som = data.queryFeatures("/clusters/som").asTable()) { TableAnnotationProvider annotationProvider = new TableAnnotationProvider(data); // parse and convert values from dataBean to SOMDataset while (som.nextRow()) { // color from hex to Color-object String colorStr = som.getStringValue("color"); Color color; if (colorStr.charAt(0) == '#'){ color = Color.decode(colorStr.substring(0)); } else { throw new RuntimeException("color format not supported for SOM visualization: " + colorStr); } // values and vectors from string to typed tables ArrayList<String> values = new ArrayList<String>(); //For all clusters for(String idList: som.getStringValue("values").split(", ")){ //For all genes in a cluster for(String id: idList.trim().split(" ")){ values.add(annotationProvider.getAnnotatedRowname(id.trim())); } } String[] vectorStrings = som.getStringValue("vector").split(","); double[] vectorDoubles = new double[vectorStrings.length]; for(int i = 0; i< vectorStrings.length; i++){ vectorDoubles[i] = Double.parseDouble(vectorStrings[i]); } // create data item (cluster) SOMDataItem dataItem = new SOMDataItem(color, values.toArray(new String[values.size()]), vectorDoubles); int x = som.getIntValue("x"); int y = som.getIntValue("y"); // array indexes start from zero dataset.addValue(x-1, y-1, dataItem); } } JFreeChart chart = BioChartFactory.createSOMChart( data.getName() + " SOM Chart", // chart title dataset, // data true, // tooltips? false // URLs? ); ChartPanel chartPanel = makePanel(chart); chartPanel.addChartMouseListener((SOMPlot)chart.getPlot()); chartPanel.setFocusable(true); return chartPanel; }
Example 18
Source Project: gama File: GamaColorType.java License: GNU General Public License v3.0 | 4 votes |
public static GamaColor staticCast(final IScope scope, final Object obj, final Object param, final boolean copy) throws GamaRuntimeException { // param can contain the alpha value if (obj == null) { return null; } if (obj instanceof GamaColor) { final GamaColor col = (GamaColor) obj; if (param instanceof Integer) { return new GamaColor(col.getRed(), col.getGreen(), col.getBlue(), (Integer) param); } else if (param instanceof Double) { return new GamaColor(col.getRed(), col.getGreen(), col.getBlue(), (Double) param); } else { return (GamaColor) obj; } } if (obj instanceof List) { final List l = (List) obj; final int size = l.size(); if (size == 0) { return new GamaColor(Color.black); } if (size == 1 || size == 2) { return staticCast(scope, ((List) obj).get(0), param, copy); } else if (size == 3) { return new GamaColor(Cast.asInt(scope, l.get(0)), Cast.asInt(scope, l.get(1)), Cast.asInt(scope, l.get(2)), 255); } else if (size >= 4) { return new GamaColor(Cast.asInt(scope, l.get(0)), Cast.asInt(scope, l.get(1)), Cast.asInt(scope, l.get(2)), Cast.asInt(scope, l.get(3))); } /* To allow constructions like rgb [255,255,255] */ } if (obj instanceof IContainer) { return staticCast(scope, ((IContainer) obj).listValue(scope, Types.NO_TYPE, false), param, copy); } if (obj instanceof String) { final String s = ((String) obj).toLowerCase(); GamaColor c = GamaColor.colors.get(s); if (c == null) { try { c = new GamaColor(Color.decode(s)); } catch (final NumberFormatException e) { final GamaRuntimeException ex = GamaRuntimeException.error("'" + s + "' is not a valid color name", scope); throw ex; } GamaColor.colors.put(s, c); } if (param == null) { return c; } else if (param instanceof Integer) { return new GamaColor(c, (Integer) param); } else if (param instanceof Double) { return new GamaColor(c, (Double) param); } } if (obj instanceof Boolean) { return (Boolean) obj ? new GamaColor(Color.black) : new GamaColor(Color.white); } final int i = Cast.asInt(scope, obj); final GamaColor gc = GamaColor.getInt((255 & 0xFF) << 24 | i & 0xFFFFFF << 0); if (param instanceof Integer) { return new GamaColor(gc, (Integer) param); } else if (param instanceof Double) { return new GamaColor(gc, (Double) param); } return gc; }
Example 19
Source Project: openAGV File: Colors.java License: Apache License 2.0 | 3 votes |
/** * Returns a {@code Color} instance described by the given hexadecimal representation. * * @param rgbHex The hexadecimal representation of the color to be returned in the RGB color * space. * * @return A {@code Color} instance described by the given value. * @throws NumberFormatException If the given string cannot be parsed. */ @Nonnull public static Color decodeFromHexRGB(@Nonnull String rgbHex) throws NumberFormatException { requireNonNull(rgbHex, "rgbHex"); return Color.decode(rgbHex); }
Example 20
Source Project: ET_Redux File: Preferences.java License: Apache License 2.0 | 2 votes |
/** * * @return @throws Exception */ public Color pointsfillcolour() throws Exception { return Color.decode((String) this.preferences.get("points_fill_colour")); }