Java Code Examples for java.awt.Color#getHSBColor()
The following examples show how to use
java.awt.Color#getHSBColor() .
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: ZebraJTable.java From mars-sim with GNU General Public License v3.0 | 6 votes |
private void updateZebraColors( ) { if ( (rowColors[1] = getBackground( )) == null ) { rowColors[1] = rowColors[0] = Color.white; return; } final Color sel = getSelectionBackground( ); if ( sel == null ) { rowColors[0] = rowColors[1]; return; } final float[] bgHSB = Color.RGBtoHSB( rowColors[1].getRed( ), rowColors[1].getGreen( ), rowColors[1].getBlue( ), null ); final float[] selHSB = Color.RGBtoHSB( sel.getRed( ), sel.getGreen( ), sel.getBlue( ), null ); rowColors[0] = Color.getHSBColor( (selHSB[1]==0.0||selHSB[2]==0.0) ? bgHSB[0] : selHSB[0], 0.1f * selHSB[1] + 0.9f * bgHSB[1], // bgHSB[2] + ((bgHSB[2]<0.5f) ? 0.05f : -0.05f) // Match the slightly darkened background color of a zebra row bgHSB[2] + ((bgHSB[2]<0.5f) ? 0.0005f : -0.0005f) ); }
Example 2
Source File: CustomLedColor.java From mars-sim with GNU General Public License v3.0 | 6 votes |
public CustomLedColor(final Color COLOR) { this.COLOR = COLOR; final float HUE = Color.RGBtoHSB(COLOR.getRed(), COLOR.getGreen(), COLOR.getBlue(), null)[0]; if (COLOR.getRed() == COLOR.getGreen() && COLOR.getRed() == COLOR.getBlue()) { INNER_COLOR1_ON = Color.getHSBColor(HUE, 0.0f, 1.0f); INNER_COLOR2_ON = Color.getHSBColor(HUE, 0.0f, 1.0f); OUTER_COLOR_ON = Color.getHSBColor(HUE, 0.0f, 0.99f); CORONA_COLOR = Color.getHSBColor(HUE, 0.0f, 1.00f); INNER_COLOR1_OFF = Color.getHSBColor(HUE, 0.0f, 0.35f); INNER_COLOR2_OFF = Color.getHSBColor(HUE, 0.0f, 0.35f); OUTER_COLOR_OFF = Color.getHSBColor(HUE, 0.0f, 0.26f); } else { INNER_COLOR1_ON = Color.getHSBColor(HUE, 0.75f, 1.0f); INNER_COLOR2_ON = Color.getHSBColor(HUE, 0.75f, 1.0f); OUTER_COLOR_ON = Color.getHSBColor(HUE, 1.0f, 0.99f); CORONA_COLOR = Color.getHSBColor(HUE, 0.75f, 1.00f); INNER_COLOR1_OFF = Color.getHSBColor(HUE, 1.0f, 0.35f); INNER_COLOR2_OFF = Color.getHSBColor(HUE, 1.0f, 0.35f); OUTER_COLOR_OFF = Color.getHSBColor(HUE, 1.0f, 0.26f); } }
Example 3
Source File: VectorColorMapper.java From osp with GNU General Public License v3.0 | 6 votes |
private void createRedSpectrumPalette() { colors = new Color[numColors]; compColors = new Color[numColors]; int bgr = background.getRed(); int bgg = background.getGreen(); int bgb = background.getBlue(); for(int i = 0; i<numColors; i++) { // start with the background and increase toward pure RED int tr = bgr+(255-bgr)*i/numColors; // increase the red int tg = bgg-bgg*i/numColors; // decrease the green int tb = bgb-bgb*i/numColors; // decrease the blue colors[i] = new Color(tr, tg, tb); float[] hsb = Color.RGBtoHSB(tr, tg, tb, null); Color c = Color.getHSBColor((hsb[0]+0.5f)%1, hsb[1], hsb[2]); // complementary hue tr = bgr+(c.getRed()-bgr)*i/numColors; tg = bgg+(c.getGreen()-bgg)*i/numColors; tb = bgb+(c.getBlue()-bgb)*i/numColors; compColors[i] = new Color(tr, tg, tb); } }
Example 4
Source File: AttributeGuiTools.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
/** * Transforms the given color in regard to the scope. If the scope is {@code null} the given * color will be returned. * * @param color * the color which should be transformed * @param scope * the purpose of the the color * @return the transformed color */ private static Color transformColor(Color color, ColorScope scope) { if (color == null || scope == null) { return color; } float hsb[] = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null); float sFactor = 1; float vFactor = 1; switch (scope) { case BORDER: sFactor = 3f; vFactor = .6f; break; case CONTENT: sFactor = 1.5f; vFactor = .8f; break; case HOVER: vFactor = .95f; break; case BACKGROUND: default: } return Color.getHSBColor(hsb[0], Math.min(sFactor * hsb[1], 1f), vFactor * hsb[2]); }
Example 5
Source File: Heatmap.java From systemsgenetics with GNU General Public License v3.0 | 5 votes |
private static Color getColor(double power) { float h = (float) (power * 0.3); // Hue // float h = (float) (240d / 360d); // Blue Hue float s = (float) 0.9; // Saturation float b = (float) 0.9; // Brightness return Color.getHSBColor(h, s, b); }
Example 6
Source File: SnakeAnnotation.java From tomcatsrc with Apache License 2.0 | 5 votes |
public static String getRandomHexColor() { float hue = random.nextFloat(); // sat between 0.1 and 0.3 float saturation = (random.nextInt(2000) + 1000) / 10000f; float luminance = 0.9f; Color color = Color.getHSBColor(hue, saturation, luminance); return '#' + Integer.toHexString( (color.getRGB() & 0xffffff) | 0x1000000).substring(1); }
Example 7
Source File: ColorUtils.java From ghidra with Apache License 2.0 | 5 votes |
public static Color deriveBackground(Color src, float hue, float sfact, float bfact) { float vals[] = new float[3]; Color.RGBtoHSB(src.getRed(), src.getGreen(), src.getBlue(), vals); // Assign the requested hue without modification vals[0] = hue; // Multiply the source saturation by the desired saturation vals[1] *= sfact; // Compress the brightness toward 0.5 vals[2] = 0.5f + (vals[2] - 0.5f) * bfact; // Compute the color return Color.getHSBColor(vals[0], vals[1], vals[2]); }
Example 8
Source File: SnakeAnnotation.java From tomcatsrc with Apache License 2.0 | 5 votes |
public static String getRandomHexColor() { float hue = random.nextFloat(); // sat between 0.1 and 0.3 float saturation = (random.nextInt(2000) + 1000) / 10000f; float luminance = 0.9f; Color color = Color.getHSBColor(hue, saturation, luminance); return '#' + Integer.toHexString( (color.getRGB() & 0xffffff) | 0x1000000).substring(1); }
Example 9
Source File: LegendManage.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
/** * Get rainbow color by HSV/HSB * * @param cNum Color number * @return Rainbow colors */ public static Color[] getRainBowColors_HSV(int cNum) { double p = 360.0 / cNum; Color[] colors = new Color[cNum]; for (int i = 0; i < cNum; i++) { colors[cNum - i - 1] = Color.getHSBColor((float) (i * p), 1.0f, 1.0f); } return colors; }
Example 10
Source File: SnakeWebSocketServlet.java From tomcatsrc with Apache License 2.0 | 5 votes |
public static String getRandomHexColor() { float hue = random.nextFloat(); // sat between 0.1 and 0.3 float saturation = (random.nextInt(2000) + 1000) / 10000f; float luminance = 0.9f; Color color = Color.getHSBColor(hue, saturation, luminance); return '#' + Integer.toHexString( (color.getRGB() & 0xffffff) | 0x1000000).substring(1); }
Example 11
Source File: PixelBlend.java From MyBox with Apache License 2.0 | 5 votes |
@Override protected int blend(int forePixel, int backPixel) { if (forePixel == 0) { // Pass transparency return backPixel; } if (backPixel == 0) { // Pass transparency return forePixel; } float[] sA = ImageColor.pixel2HSB(forePixel); float[] sB = ImageColor.pixel2HSB(backPixel); Color sColor = Color.getHSBColor(sB[0], sA[1], sB[2]); return sColor.getRGB(); }
Example 12
Source File: GssFunctions.java From closure-stylesheets with Apache License 2.0 | 5 votes |
protected String makeMutedColor( String backgroundColorStr, String foregroundColorStr, String lossStr) { // If the background is transparent, or if the foreground is transparent, // there's really no way we can know how to pick a muted color. We thus // return the foreground color unchanged. if ("transparent".equalsIgnoreCase(backgroundColorStr) || "transparent".equalsIgnoreCase(foregroundColorStr)) { return foregroundColorStr; } Color backgroundColor = ColorParser.parseAny(backgroundColorStr); Color foregroundColor = ColorParser.parseAny(foregroundColorStr); float[] backgroundColorHsb = toHsb(backgroundColor); float[] foregroundColorHsb = toHsb(foregroundColor); float lossOfSaturationForMutedTone = Float.valueOf(lossStr); // Make sure that 0 <= lossOfSaturationForMutedTone <= 1 if (lossOfSaturationForMutedTone < 0) { lossOfSaturationForMutedTone = 0; } else if (lossOfSaturationForMutedTone > 1) { lossOfSaturationForMutedTone = 1; } // We take the hue from the foreground color, we desaturate it a little // bit, and choose a brightness halfway between foreground and background. // For example, if the background has a brightness of 50, and 100 for the // foreground, the muted color will have 75. If we have a dark background, // it should be the reverse. float mutedHue = foregroundColorHsb[0]; float mutedSaturation = Math.max( foregroundColorHsb[1] - lossOfSaturationForMutedTone, 0); float mutedBrightness = (foregroundColorHsb[2] + backgroundColorHsb[2]) / 2; Color mutedColor = Color.getHSBColor(mutedHue, mutedSaturation, mutedBrightness); return formatColor(mutedColor); }
Example 13
Source File: NebulaDataObject.java From constellation with Apache License 2.0 | 4 votes |
@Override public void open() { final Properties props = new Properties(); try (final FileReader reader = new FileReader(getPrimaryFile().getPath())) { props.load(reader); } catch (final IOException ex) { Exceptions.printStackTrace(ex); } // Generate a color for the nebula marker. // First, see if the user has specified a color in the nebula file. Color c = null; final String cname = props.getProperty("colour") != null ? props.getProperty("colour") : props.getProperty("color"); if (cname != null) { ConstellationColor cv = ConstellationColor.fromHtmlColor(cname); if (cv == null) { cv = ConstellationColor.getColorValue(cname); } if (cv != null) { c = cv.getJavaColor(); } } // At this point, we should check to see if there are already any other graphs in this nebula open, // so we can use the existing color. However, we're a bit low-level here. // Therefore, we track the random colors as we create them, if (c == null) { c = NEBULA_COLOR.get(getPrimaryFile().getPath()); } // Otherwise, create a random color for this nebula. if (c == null) { final float h = new SecureRandom().nextFloat(); c = Color.getHSBColor(h, 0.5f, 0.95f); NEBULA_COLOR.put(getPrimaryFile().getPath(), c); } for (final Enumeration<DataObject> i = getFolder().children(); i.hasMoreElements();) { final DataObject dobj = i.nextElement(); if (dobj instanceof GraphDataObject) { final GraphDataObject gdo = (GraphDataObject) dobj; gdo.setNebulaDataObject(this); gdo.setNebulaColor(c); GraphOpener.getDefault().openGraph(gdo); } } // Because we haven't registered an editor, a TopComponent won't open for this file (which is good). // However, the recent files stuff works by watching for opening TopComponents (which is bad). // So, do it manually. // FileObject.getPath() returns a path containing "/"; we need to convert it to local separators for RecentFiles. String path = getPrimaryFile().getPath(); path = new File(path).getAbsolutePath(); RecentFiles.addFile(path); }
Example 14
Source File: SimpleScatterPlot.java From mzmine3 with GNU General Public License v2.0 | 4 votes |
public SimpleScatterPlot(double[] xValues, double[] yValues, double[] colors, String xLabel, String yLabel) { super(null); // setBackground(Color.white); setCursor(Cursor.CROSSHAIR); xAxis = new NumberAxis(xLabel); xAxis.setAutoRangeIncludesZero(false); xAxis.setUpperMargin(0); xAxis.setLowerMargin(0); yAxis = new NumberAxis(yLabel); yAxis.setAutoRangeIncludesZero(false); yAxis.setUpperMargin(0); yAxis.setLowerMargin(0); xyDataset = new DefaultXYZDataset(); int length = Math.min(xValues.length, yValues.length); double[][] data = new double[3][length]; System.arraycopy(xValues, 0, data[0], 0, length); System.arraycopy(yValues, 0, data[1], 0, length); System.arraycopy(colors, 0, data[2], 0, length); xyDataset.addSeries(SERIES_ID, data); XYDotRenderer renderer = new XYDotRenderer() { @Override public Paint getItemPaint(int row, int col) { double c = xyDataset.getZ(row, col).doubleValue(); return Color.getHSBColor((float) c, 1.0f, 1.0f); } }; renderer.setDotHeight(3); renderer.setDotWidth(3); plot = new XYPlot(xyDataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinesVisible(true); chart = new JFreeChart("", new Font("SansSerif", Font.BOLD, 12), plot, false); chart.setBackgroundPaint(Color.white); super.setChart(chart); // reset zoom history ZoomHistory history = getZoomHistory(); if (history != null) history.clear(); }
Example 15
Source File: DPPAnyElementIsotopeGrouperTask.java From mzmine3 with GNU General Public License v2.0 | 4 votes |
public static Color getColor(double power) { double H = power; // Hue (note 0.4 = Green, see huge chart below) double S = 0.9; // Saturation double B = 0.9; // Brightness return Color.getHSBColor((float) H, (float) S, (float) B); }
Example 16
Source File: EdgeWidget.java From netbeans with Apache License 2.0 | 4 votes |
/** Derives color from specified with saturation multiplied by given ratio. */ static Color deriveColor (Color c, float saturationR) { Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), hsbVals); hsbVals[1] = Math.min(1.0f, hsbVals[1] * saturationR); return Color.getHSBColor(hsbVals[0], hsbVals[1], hsbVals[2]); }
Example 17
Source File: TriangularByteLattice.java From osp with GNU General Public License v3.0 | 4 votes |
public void createDefaultColors() { for(int i = 0; i<256; i++) { Color c = Color.getHSBColor((-0.07f+0.80f*i/255f)%1, 1, 1); colors[i] = c; } }
Example 18
Source File: JGraphTab.java From binnavi with Apache License 2.0 | 4 votes |
private Color selectTabBackGroundColor(final int seed) { final int insertionPosition = Iterables.indexOf(moduleIdCount.keySet(), Predicates.equalTo(seed)); switch (insertionPosition) { case 0: return Color.getHSBColor((float) 0.55, (float) 0.2, (float) 0.8); case 1: return Color.getHSBColor((float) 0.6, (float) 0.2, (float) 0.8); case 2: return Color.getHSBColor((float) 0.65, (float) 0.2, (float) 0.8); case 3: return Color.getHSBColor((float) 0.7, (float) 0.2, (float) 0.8); case 4: return Color.getHSBColor((float) 0.75, (float) 0.2, (float) 0.8); case 5: return Color.getHSBColor((float) 0.8, (float) 0.2, (float) 0.8); case 6: return Color.getHSBColor((float) 0.85, (float) 0.2, (float) 0.8); case 7: return Color.getHSBColor((float) 0.9, (float) 0.2, (float) 0.8); case 8: return Color.getHSBColor((float) 0.95, (float) 0.2, (float) 0.8); case 9: return Color.getHSBColor(1, (float) 0.2, (float) 0.8); case 10: return Color.getHSBColor((float) 0.05, (float) 0.2, (float) 0.8); case 11: return Color.getHSBColor((float) 0.1, (float) 0.2, (float) 0.8); case 12: return Color.getHSBColor((float) 0.15, (float) 0.2, (float) 0.8); case 13: return Color.getHSBColor((float) 0.2, (float) 0.2, (float) 0.8); case 14: return Color.getHSBColor((float) 0.25, (float) 0.2, (float) 0.8); case 15: return Color.getHSBColor((float) 0.3, (float) 0.2, (float) 0.8); case 16: return Color.getHSBColor((float) 0.35, (float) 0.2, (float) 0.8); case 17: return Color.getHSBColor((float) 0.4, (float) 0.2, (float) 0.8); case 18: return Color.getHSBColor((float) 0.45, (float) 0.2, (float) 0.8); case 19: return Color.getHSBColor((float) 0.5, (float) 0.2, (float) 0.8); default: return Color.WHITE; } }
Example 19
Source File: AbstractRegionPainter.java From seaglass with Apache License 2.0 | 3 votes |
/** * Decodes and returns a color, which is derived from a base color in UI * defaults. * * @param key A key corresponding to the value in the UI Defaults table * of UIManager where the base color is defined * @param hOffset The hue offset used for derivation. * @param sOffset The saturation offset used for derivation. * @param bOffset The brightness offset used for derivation. * @param aOffset The alpha offset used for derivation. Between 0...255 * * @return The derived color, whos color value will change if the parent * uiDefault color changes. */ protected final Color decodeColor(String key, float hOffset, float sOffset, float bOffset, int aOffset) { if (UIManager.getLookAndFeel() instanceof SeaGlassLookAndFeel) { SeaGlassLookAndFeel laf = (SeaGlassLookAndFeel) UIManager.getLookAndFeel(); return laf.getDerivedColor(key, hOffset, sOffset, bOffset, aOffset, true); } else { // can not give a right answer as painter should not be used outside // of nimbus laf but do the best we can return Color.getHSBColor(hOffset, sOffset, bOffset); } }
Example 20
Source File: SwingTools.java From rapidminer-studio with GNU Affero General Public License v3.0 | 3 votes |
/** * Changes the saturation of the given {@link Color} by multiplying the saturation with the * specified factor. * * @param color * the color to change * @param factor * the factor to multiply the current saturation with * @return color with changed saturation */ public static Color saturateColor(final Color color, final float factor) { int initialAlpha = color.getAlpha(); // convert to H(ue) S(aturation) B(rightness), which is designed for // this kind of operation float hsb[] = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null); // adjust saturation and return color Color returnColor = Color.getHSBColor(hsb[0], factor * hsb[1], hsb[2]); return new Color(returnColor.getRed(), returnColor.getGreen(), returnColor.getBlue(), initialAlpha); }