List of usage examples for java.awt Color getBlue
public int getBlue()
From source file:org.polymap.rhei.batik.engine.svg.Svg2Png.java
/** * @param imageConfiguration//from w w w . j av a2 s . co m * @param color * @param newRGB * @return */ private static BufferedImage makeColorsTransparent(BufferedImage finalThresholdImage, ImageConfiguration imageConfiguration, Color color) { boolean found = imageConfiguration.getTransparenceConfigurations().stream().anyMatch( tc -> tc.red == color.getRed() && tc.green == color.getGreen() && tc.blue == color.getBlue()); if (found) { finalThresholdImage = makeColorTransparent(finalThresholdImage, color); } return finalThresholdImage; }
From source file:org.pgptool.gui.ui.tools.UiUtils.java
public static void setLookAndFeel() { // NOTE: We doing it this way to prevent dead=locks that is sometimes // happens if do it in main thread Edt.invokeOnEdtAndWait(new Runnable() { @Override/*from ww w. jav a 2 s . c om*/ public void run() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); fixCheckBoxMenuItemForeground(); fixFontSize(); } catch (Throwable t) { log.error("Failed to set L&F", t); } } /** * In some cases (depends on OS theme) check menu item foreground is same as * bacground - thus it;'s invisible when cheked */ private void fixCheckBoxMenuItemForeground() { UIDefaults defaults = UIManager.getDefaults(); Color selectionForeground = defaults.getColor("CheckBoxMenuItem.selectionForeground"); Color foreground = defaults.getColor("CheckBoxMenuItem.foreground"); Color background = defaults.getColor("CheckBoxMenuItem.background"); if (colorsDiffPercentage(selectionForeground, background) < 10) { // TODO: That doesn't actually affect defaults. Need to find out how to fix it defaults.put("CheckBoxMenuItem.selectionForeground", foreground); } } private int colorsDiffPercentage(Color c1, Color c2) { int diffRed = Math.abs(c1.getRed() - c2.getRed()); int diffGreen = Math.abs(c1.getGreen() - c2.getGreen()); int diffBlue = Math.abs(c1.getBlue() - c2.getBlue()); float pctDiffRed = (float) diffRed / 255; float pctDiffGreen = (float) diffGreen / 255; float pctDiffBlue = (float) diffBlue / 255; return (int) ((pctDiffRed + pctDiffGreen + pctDiffBlue) / 3 * 100); } private void fixFontSize() { if (isJreHandlesScaling()) { log.info("JRE handles font scaling, won't change it"); return; } log.info("JRE doesnt't seem to support font scaling"); Toolkit toolkit = Toolkit.getDefaultToolkit(); int dpi = toolkit.getScreenResolution(); if (dpi == 96) { if (log.isDebugEnabled()) { Font font = UIManager.getDefaults().getFont("TextField.font"); String current = font != null ? Integer.toString(font.getSize()) : "unknown"; log.debug( "Screen dpi seem to be 96. Not going to change font size. Btw current size seem to be " + current); } return; } int targetFontSize = 12 * dpi / 96; log.debug("Screen dpi = " + dpi + ", decided to change font size to " + targetFontSize); setDefaultSize(targetFontSize); } private boolean isJreHandlesScaling() { try { JreVersion noNeedToScaleForVer = JreVersion.parseString("9"); String jreVersionStr = System.getProperty("java.version"); if (jreVersionStr != null) { JreVersion curVersion = JreVersion.parseString(jreVersionStr); if (noNeedToScaleForVer.compareTo(curVersion) <= 0) { return true; } } return false; } catch (Throwable t) { log.warn("Failed to see oif JRE can handle font scaling. Will assume it does. JRE version: " + System.getProperty("java.version"), t); return true; } } public void setDefaultSize(int size) { Set<Object> keySet = UIManager.getLookAndFeelDefaults().keySet(); Object[] keys = keySet.toArray(new Object[keySet.size()]); for (Object key : keys) { if (key != null && key.toString().toLowerCase().contains("font")) { Font font = UIManager.getDefaults().getFont(key); if (font != null) { Font changedFont = font.deriveFont((float) size); UIManager.put(key, changedFont); Font doubleCheck = UIManager.getDefaults().getFont(key); log.debug("Font size changed for " + key + ". From " + font.getSize() + " to " + doubleCheck.getSize()); } } } } }); log.info("L&F set"); }
From source file:smanilov.mandelbrot.compute.Computer.java
/** * Mixes the given colors in the given proportion. *//*www . java 2 s . c o m*/ private static Color mixColors(Color c1, Color c2, double proportion) { Color result = new Color((int) (c1.getRed() * (1 - proportion) + c2.getRed() * proportion), (int) (c1.getGreen() * (1 - proportion) + c2.getGreen() * proportion), (int) (c1.getBlue() * (1 - proportion) + c2.getBlue() * proportion)); return result; }
From source file:org.opensha.commons.geo.RegionUtils.java
private static String colorToHex(Color c) { StringBuffer sb = new StringBuffer(); sb.append(toHex(c.getAlpha()));/*from ww w . j a v a2 s. c om*/ sb.append(toHex(c.getBlue())); sb.append(toHex(c.getGreen())); sb.append(toHex(c.getRed())); return sb.toString(); }
From source file:org.nuclos.client.common.Utils.java
public static Color getBestForegroundColor(Color background) { int backgroundBrightness = (background.getBlue() + background.getRed() * 2 + background.getGreen() * 3) / 6; return backgroundBrightness > 160 ? Color.BLACK : Color.WHITE; }
From source file:org.kalypso.commons.java.util.StringUtilities.java
/** * Converts a Color into a String.//from ww w . j av a 2s . c o m * <p> * String will have same format as specified in {@link StringUtilities#stringToColor(String)} * * @param c * @throws IllegalArgumentException * if color is null */ public static String colorToString(final Color c) { if (c == null) throw new IllegalArgumentException( Messages.getString("org.kalypso.commons.java.util.StringUtilities.1")); //$NON-NLS-1$ final StringBuffer buf = new StringBuffer(); buf.append(c.getRed()).append(";").append(c.getGreen()).append(";").append(c.getBlue()); //$NON-NLS-1$ //$NON-NLS-2$ // alpha component is optional if (c.getAlpha() != 255) buf.append(";").append(c.getAlpha()); //$NON-NLS-1$ return buf.toString(); }
From source file:org.kalypso.ui.wizards.results.ResultSldHelper.java
/** * returns the interpolated color of a color map defined by start and end color. * /*from w w w. j a v a 2 s . c o m*/ * @param currentClass * current class * @param numOfClasses * number of all classes in which the colormap is divided. */ public static Color interpolateColor(final Color minColor, final Color maxColor, final int currentClass, final int numOfClasses) { // interpolate color final float[] minhsb = Color.RGBtoHSB(minColor.getRed(), minColor.getGreen(), minColor.getBlue(), null); final float[] maxhsb = Color.RGBtoHSB(maxColor.getRed(), maxColor.getGreen(), maxColor.getBlue(), null); final float minHue = minhsb[0]; final float maxHue = maxhsb[0]; final float minSat = minhsb[1]; final float maxSat = maxhsb[1]; final float minBri = minhsb[2]; final float maxBri = maxhsb[2]; final double Hue = minHue + (currentClass * (maxHue - minHue) / (numOfClasses - 1)); final double Sat = minSat + (currentClass * (maxSat - minSat) / (numOfClasses - 1)); final double Bri = minBri + (currentClass * (maxBri - minBri) / (numOfClasses - 1)); final Color hsbColor = Color.getHSBColor((float) Hue, (float) Sat, (float) Bri); final Color rgbColor = new Color(hsbColor.getRed(), hsbColor.getGreen(), hsbColor.getBlue()); return rgbColor; }
From source file:net.groupbuy.util.ImageUtils.java
/** * ????// w ww . ja v a 2 s. c om * * @param color * * @return ??? */ private static String toHexEncoding(Color color) { String R, G, B; StringBuffer stringBuffer = new StringBuffer(); R = Integer.toHexString(color.getRed()); G = Integer.toHexString(color.getGreen()); B = Integer.toHexString(color.getBlue()); R = R.length() == 1 ? "0" + R : R; G = G.length() == 1 ? "0" + G : G; B = B.length() == 1 ? "0" + B : B; stringBuffer.append("#"); stringBuffer.append(R); stringBuffer.append(G); stringBuffer.append(B); return stringBuffer.toString(); }
From source file:imageprocessingproject.ImageHistogram.java
public static BufferedImage normalizeImage(BufferedImage image) { int height = image.getHeight(); int width = image.getWidth(); int r, g, b, minr = 255, ming = 255, minb = 255, maxr = 0, maxg = 0, maxb = 0; Color c; BufferedImage tempImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { c = new Color(image.getRGB(i, j)); if (minr > c.getRed()) { minr = c.getRed();// w ww. j a v a 2 s . c om } if (ming > c.getGreen()) { ming = c.getGreen(); } if (minb > c.getBlue()) { minb = c.getBlue(); } if (maxr < c.getRed()) { maxr = c.getRed(); } if (maxg < c.getGreen()) { maxg = c.getGreen(); } if (maxb < c.getBlue()) { maxb = c.getBlue(); } } } for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { c = new Color(image.getRGB(i, j)); r = (int) ((c.getRed() - minr) * 255 / (maxr - minr)); g = (int) ((c.getGreen() - ming) * 255 / (maxg - ming)); b = (int) ((c.getBlue() - minb) * 255 / (maxb - minb)); tempImage.setRGB(i, j, new Color(r, g, b, c.getAlpha()).getRGB()); } } return tempImage; }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.xls.helper.StaticExcelColorSupport.java
public static short getNearestColor(final Color awtColor, final Map triplets) { if (awtColor == null) { throw new NullPointerException(); }/*from w w w. j a v a 2 s . co m*/ if (triplets == null || triplets.isEmpty()) { logger.warn("Unable to get triplet hashtable"); return HSSFColor.BLACK.index; } short color = HSSFColor.BLACK.index; double minDiff = Double.MAX_VALUE; // get the color without the alpha chanel final float[] hsb = Color.RGBtoHSB(awtColor.getRed(), awtColor.getGreen(), awtColor.getBlue(), null); float[] excelHsb = null; final Iterator elements = triplets.values().iterator(); while (elements.hasNext()) { final HSSFColor crtColor = (HSSFColor) elements.next(); final short[] rgb = crtColor.getTriplet(); excelHsb = Color.RGBtoHSB(rgb[0], rgb[1], rgb[2], excelHsb); final double weight = 3.0 * (Math.min(Math.abs(excelHsb[0] - hsb[0]), Math.abs(excelHsb[0] - hsb[0] + 1))) + Math.abs(excelHsb[1] - hsb[1]) + Math.abs(excelHsb[2] - hsb[2]); if (weight < minDiff) { minDiff = weight; if (minDiff == 0) { // we found the color ... return crtColor.getIndex(); } color = crtColor.getIndex(); } } return color; }