Java Code Examples for java.awt.Color#getRGBComponents()
The following examples show how to use
java.awt.Color#getRGBComponents() .
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 File: Query.java From opt4j with MIT License | 6 votes |
@Override public void actionPerformed(ActionEvent e) { // Read the current color from the text field. String spec = getSelectedColor().trim(); Color newColor = JColorChooser.showDialog(Query.this, "Choose Color", stringToColor(spec)); if (newColor != null) { float[] components = newColor.getRGBComponents(null); StringBuffer string = new StringBuffer("{"); // Use the syntax of arrays. for (int j = 0; j < components.length; j++) { string.append(components[j]); if (j < (components.length - 1)) { string.append(","); } else { string.append("}"); } } _entryBox.setText(string.toString()); _notifyListeners(_name); } }
Example 2
Source File: MultiReadTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private static boolean sameColor(Color c1, Color c2) { final float delta = 0.1f; float[] rgb1 = new float[4]; float[] rgb2 = new float[4]; rgb1 = c1.getRGBComponents(rgb1); rgb2 = c2.getRGBComponents(rgb2); for (int i = 0; i < rgb1.length; i++) { if (Math.abs(rgb1[i] - rgb2[i]) > delta) { return false; } } return true; }
Example 3
Source File: DrawingPanel3D.java From osp with GNU General Public License v3.0 | 6 votes |
/** * Computes the display color of a given drawable3D based on its original color and its depth. * Transparency of the original color is not affected. * @param _aColor the original color * @param _depth the depth value of the color */ Color projectColor(Color _aColor, double _depth) { if(!visHints.isUseColorDepth()) { return _aColor; } // if (_depth<0.9) return _aColor.brighter().brighter(); // else if (_depth>1.1) return _aColor.darker().darker(); // else return _aColor; float[] crc = new float[4]; // Stands for ColorRGBComponent try { _aColor.getRGBComponents(crc); // Do not affect transparency for(int i = 0; i<3; i++) { crc[i] /= _depth; crc[i] = (float) Math.max(Math.min(crc[i], 1.0), 0.0); } return new Color(crc[0], crc[1], crc[2], crc[3]); } catch(Exception _exc) { return _aColor; } }
Example 4
Source File: ConstellationColor.java From constellation with Apache License 2.0 | 5 votes |
/** * Create a ColorValue from an existing Java Color. * * @param name The name of the color. * @param color An existing java color. */ private ConstellationColor(final String name, final Color color) { this(name, color.getRGBComponents(null)[0], color.getRGBComponents(null)[1], color.getRGBComponents(null)[2], color.getRGBComponents(null)[3]); }
Example 5
Source File: ObjectDisplayColorAction.java From opensim-gui with Apache License 2.0 | 5 votes |
public static void ChangeUserSelectedNodesColor(Vector<OneComponentNode> nodes, Color newColor) { // Cycle through ComponentNode(s) and apply color float[] newColorComponentsAsFloatArray = newColor.getRGBComponents(null); double[] newColorComponentsAsDoubleArray = {newColorComponentsAsFloatArray[0], newColorComponentsAsFloatArray[1], newColorComponentsAsFloatArray[2]}; for (OneComponentNode nextNode:nodes){ ObjectDisplayColorAction.applyOperationToNode(nextNode, newColorComponentsAsDoubleArray); } }
Example 6
Source File: NeonBorderEffect.java From Pixelitor with GNU General Public License v3.0 | 5 votes |
protected Color interpolateColor(float t, Color start, Color end) { float[] partsS = start.getRGBComponents(null); float[] partsE = end.getRGBComponents(null); float[] partsR = new float[4]; for (int i = 0; i < 4; i++) { partsR[i] = (partsS[i] - partsE[i]) * t + partsE[i]; } return new Color(partsR[0], partsR[1], partsR[2], partsR[3]); }
Example 7
Source File: VirtualBall.java From procamtracker with GNU General Public License v2.0 | 5 votes |
public void setColor(Color color) { float[] rgb = color.getRGBComponents(null); this.colorRGB.val(0, rgb[0]*255); this.colorRGB.val(1, rgb[1]*255); this.colorRGB.val(2, rgb[2]*255); this.colorBGR.val(0, rgb[2]*255); this.colorBGR.val(1, rgb[1]*255); this.colorBGR.val(2, rgb[0]*255); }
Example 8
Source File: Query.java From OpenDA with GNU Lesser General Public License v3.0 | 4 votes |
public void actionPerformed(ActionEvent e) { // Read the current color from the text field. String spec = getSelectedColor().trim(); String[] specArray = spec.split("[{},]"); float red = 0f; float green = 0f; float blue = 0f; float alpha = 1.0f; // If any exceptions occur during the attempt to parse, // then just use the default color. try { int i = 0; // Ignore any blank strings that this simple parsing produces. while (specArray[i].trim().equals("")) { i++; } if (specArray.length > i) { red = Float.parseFloat(specArray[i]); } i++; while (specArray[i].trim().equals("")) { i++; } if (specArray.length > i) { green = Float.parseFloat(specArray[i]); } i++; while (specArray[i].trim().equals("")) { i++; } if (specArray.length > i) { blue = Float.parseFloat(specArray[i]); } i++; while (specArray[i].trim().equals("")) { i++; } if (specArray.length > i) { alpha = Float.parseFloat(specArray[i]); } } catch (Exception ex) { // Ignore and use default color. } Color newColor = JColorChooser.showDialog( Query.this, "Choose Background Color", new Color(red, green, blue, alpha)); if (newColor != null) { float[] components = newColor.getRGBComponents(null); StringBuffer string = new StringBuffer("{"); // Use the syntax of arrays. for (int j = 0; j < components.length; j++) { string.append(components[j]); if (j < components.length - 1) { string.append(","); } else { string.append("}"); } } _entryBox.setText(string.toString()); _notifyListeners(_name); } }
Example 9
Source File: ColorHelper.java From openchemlib-js with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Creates a new color with the hue taken from color <code>c</code>, but adjusted * in brightness to match the desired perceived brightness. * @param c * @param perceivedBrightness * @return */ public static Color createColor(Color c, float perceivedBrightness) { float[] cc = c.getRGBComponents(null); float pb = perceivedBrightness(c); if (pb == 0f) return new Color(pb, pb, pb, cc[3]); float f = perceivedBrightness / perceivedBrightness(c); float surplusBrightness = 0f; float sum = 0f; for (int i=0; i<3; i++) { cc[i] *= f; if (cc[i] < 1f) { sum += PERCEIVED_BRIGHTNESS[i]; } else { surplusBrightness += (cc[i] - 1f) * PERCEIVED_BRIGHTNESS[i]; cc[i] = 1f; } } if (surplusBrightness != 0) { float remainingBrightness = 0f; for (int i=0; i<3; i++) { if (cc[i] < 1f) { cc[i] += surplusBrightness / sum; if (cc[i] > 1f) { remainingBrightness += (cc[i] - 1f) * PERCEIVED_BRIGHTNESS[i]; cc[i] = 1f; } } } if (remainingBrightness != 0f) { for (int i=0; i<3; i++) { if (cc[i] < 1f) { cc[i] += remainingBrightness / PERCEIVED_BRIGHTNESS[i]; if (cc[i] > 1f) { cc[i] = 1f; } } } } } return new Color(cc[0], cc[1], cc[2], cc[3]); }
Example 10
Source File: Lighting.java From MeteoInfo with GNU Lesser General Public License v3.0 | 2 votes |
/** * Set ambient * * @param value Color */ public void setAmbient(Color value) { this.ambient = value.getRGBComponents(null); }
Example 11
Source File: Lighting.java From MeteoInfo with GNU Lesser General Public License v3.0 | 2 votes |
/** * Set diffuse * * @param value Color */ public void setDiffuse(Color value) { this.diffuse = value.getRGBComponents(null); }
Example 12
Source File: Lighting.java From MeteoInfo with GNU Lesser General Public License v3.0 | 2 votes |
/** * Set specular * * @param value Color */ public void setSpecular(Color value) { this.specular = value.getRGBComponents(null); }