public static void drawRoundedRectangle( GC gc, Device device, Point pos, Point size, Color background, Color roundColor) { gc.setForeground(background); gc.drawRectangle(pos.x, pos.y, size.x - 1, size.y - 1); int r = (background.getRed() * 2 + roundColor.getRed()) / 3; int g = (background.getGreen() * 2 + roundColor.getGreen()) / 3; int b = (background.getBlue() * 2 + roundColor.getBlue()) / 3; Color roundColor2 = new Color(device, r, g, b); gc.setForeground(roundColor); gc.drawPoint(pos.x, pos.y); gc.drawPoint(pos.x, pos.y + size.y - 1); gc.drawPoint(pos.x + size.x - 1, pos.y); gc.drawPoint(pos.x + size.x - 1, pos.y + size.y - 1); gc.setForeground(roundColor2); gc.drawPoint(pos.x + 1, pos.y + 0); gc.drawPoint(pos.x + 0, pos.y + 1); gc.drawPoint(pos.x + 1, pos.y + size.y - 1); gc.drawPoint(pos.x + 0, pos.y + size.y - 2); gc.drawPoint(pos.x + size.x - 2, pos.y + 0); gc.drawPoint(pos.x + size.x - 1, pos.y + 1); gc.drawPoint(pos.x + size.x - 2, pos.y + size.y - 1); gc.drawPoint(pos.x + size.x - 1, pos.y + size.y - 2); }
private void setResultColor( Color colorA, Color colorB, Composite resultColorComposite, Label resultColor) { KMColor mix = new KMColor(new java.awt.Color(colorA.getRed(), colorA.getGreen(), colorA.getBlue())); mix.mix(new java.awt.Color(colorB.getRed(), colorB.getGreen(), colorB.getBlue())); java.awt.Color result = mix.getColor(); resultColorComposite.setBackground( new Color(Display.getCurrent(), result.getRed(), result.getGreen(), result.getBlue())); resultColor.setText( "R: " + result.getRed() + ", G: " + result.getGreen() + ", B: " + result.getBlue()); }
public static String serializeColor(Color value) { return Integer.toString(value.getRed()) + "," + Integer.toString(value.getGreen()) + "," + Integer.toString(value.getBlue()); }
/** * Gets the <code>RenderedImage</code> that is the for the specified <code>Dimension</code> * * @param dim * @return the <code>RenderedImage</code> */ private RenderedImage getRenderedImage(Dimension dim) { Color fill = getBackgroundColor(); Color outline = getForegroundColor(); RenderInfo newRenderInfo = getRenderedImage().getRenderInfo(); newRenderInfo.setValues( dim.width, dim.height, isMaintainAspectRatio(), // maintain aspect ratio isAntiAlias(), useOriginalColors() ? (RGB) null : new RGB(fill.getRed(), fill.getGreen(), fill.getBlue()), useOriginalColors() ? (RGB) null : new RGB(outline.getRed(), outline.getGreen(), outline.getBlue())); // antialias RenderedImage newRenderedImage = getRenderedImage().getNewRenderedImage(newRenderInfo); return newRenderedImage; }
private boolean isSameColor(RGBColorValue colorVal, Color swtColor) { if (colorVal.getCssText().contains("%")) { int nr = Math.round(swtColor.getRed() / 255f * 100); int ng = Math.round(swtColor.getGreen() / 255f * 100); int nb = Math.round(swtColor.getBlue() / 255f * 100); int or = Math.round(colorVal.getRed().getFloatValue()); int og = Math.round(colorVal.getGreen().getFloatValue()); int ob = Math.round(colorVal.getBlue().getFloatValue()); if (or == nr && og == ng && ob == nb) { return true; } } else if (colorVal.getRed().getFloatValue() == swtColor.getRed() && colorVal.getGreen().getFloatValue() == swtColor.getGreen() && colorVal.getBlue().getFloatValue() == swtColor.getBlue()) { return true; } return false; }
/** * Sets the receiver's background color to the color specified by the argument, or to the default * system color for the control if the argument is null. * * @param color the new color (or null) * @exception IllegalArgumentException * <ul> * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed * </ul> * * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> */ public void setBackground(Color color) { // super.setBackground(color); // This has no effect as the background // will // be hidden by the client script JsonObject properties = new JsonObject(); properties.add("R", color.getRed()); properties.add("G", color.getGreen()); properties.add("B", color.getBlue()); getRemoteObject().set("background", properties); }
/** @param offColor the offColor to set */ public synchronized void setOffColor(Color offColor) { if (this.offColor != null && this.offColor.equals(offColor)) { return; } if ((offColor.getRed() << 16 | offColor.getGreen() << 8 | offColor.getBlue()) == 0xFFFFFF) { this.offColor = CustomMediaFactory.getInstance().getColor(new RGB(255, 255, 254)); } else { this.offColor = offColor; } repaint(); }
/** * Calculate gradient color. * * @param contrast Contrast on color * @param bg Background color * @return color */ public static RGB getGradientColor(Color bg, double contrast) { int blue = bg.getBlue(); blue = (int) (blue - (blue * contrast)); blue = blue > 0 ? blue : 0; int red = bg.getRed(); red = (int) (red - (red * contrast)); red = red > 0 ? red : 0; int green = bg.getGreen(); green = (int) (green - (green * contrast)); green = green > 0 ? green : 0; return new RGB(red, green, blue); }
@Test public void testDispatches() { dispatcher.dispatch(); InOrder order = inOrder(gc); order.verify(gc).drawPolyline(aryEq(new int[] {0, 1, 5, 5})); order.verify(gc).setLineWidth(3); ArgumentCaptor<Color> captor = ArgumentCaptor.forClass(Color.class); order.verify(gc).setForeground(captor.capture()); order.verify(gc).setAlpha(10); Color color = captor.getValue(); assertEquals(50, color.getRed()); assertEquals(100, color.getGreen()); assertEquals(200, color.getBlue()); order.verify(gc).drawPolyline(aryEq(new int[] {0, 1, 5, 5})); }
public static Color getConnectionColor(DBPConnectionConfiguration connectionInfo) { String rgbString = connectionInfo.getConnectionColor(); if (CommonUtils.isEmpty(rgbString)) { rgbString = connectionInfo.getConnectionType().getColor(); } if (CommonUtils.isEmpty(rgbString)) { return null; } Color connectionColor = DBeaverUI.getSharedTextColors().getColor(StringConverter.asRGB(rgbString)); if (connectionColor.getBlue() == 255 && connectionColor.getRed() == 255 && connectionColor.getGreen() == 255) { // For white color return just null to avoid explicit color set. // It is important for dark themes return null; } return connectionColor; }
static Slider getSlider(Composite parent) { GridLayout layout = new GridLayout(1, false); layout.marginHeight = 4; parent.setLayout(layout); Slider slider = new Slider(parent, SWT.NONE); slider.setToolTipText(""); slider.setMinimum(0); slider.setMaximum(255); slider.setIncrement(1); Display display = slider.getDisplay(); Color widgetBackground = display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND); slider.setSelection( (widgetBackground.getRed() + widgetBackground.getGreen() + widgetBackground.getBlue()) / 3); GridData sliderGridData = new GridData(SWT.LEFT, SWT.CENTER, false, false); slider.setLayoutData(sliderGridData); slider.addListener(SWT.Selection, new ListenerImplementation()); return slider; }
public void updateCSSColor(Color colorToChange, Color newColor) { if (colorToChange == null || newColor == null || colorToChange.equals(newColor)) { return; } FloatValue newRedValue = new FloatValue((short) 1, (float) newColor.getRed()); FloatValue newGreenValue = new FloatValue((short) 1, (float) newColor.getGreen()); FloatValue newBlueValue = new FloatValue((short) 1, (float) newColor.getBlue()); RGBColorValue newRGBColorValue = new RGBColorValue(newRedValue, newGreenValue, newBlueValue); StyleDeclaration sd = originalStyle.clone(); int sdlen = sd.size(); for (int sdindex = 0; sdindex < sdlen; sdindex++) { Value val = sd.getValue(sdindex); if (val instanceof RGBColorValue) { RGBColorValue colorVal = (RGBColorValue) val; if (isSameColor(colorVal, colorToChange)) { sd.put(sdindex, newRGBColorValue, sd.getIndex(sdindex), sd.getPriority(sdindex)); } } } element.getStyle().setCssText(sd.toString(cssEngine)); }
public static Color createBorderColor(Color color) { int r = (int) (color.getRed() * 0.75); int g = (int) (color.getGreen() * 0.75); int b = (int) (color.getBlue() * 0.75); return new Color(null, r, g, b); }
/** Creates a new Color equivalent to the provides SWT color */ public static Color fromSWTColor(org.eclipse.swt.graphics.Color swtColor) { return new Color(swtColor.getRed(), swtColor.getGreen(), swtColor.getBlue()); }
/** * 色の明度を調べる。 * * @param color 調査対象の色 * @return 明度が低い場合はtrue */ public static boolean isDarkColor(Color color) { int brightness = color.getRed() + color.getGreen() + color.getBlue(); return brightness < (MAX_COLOR_VALUE * 3) / 2; }
/** * Adds the specified color to the map of colors. * * @param color The color to add. */ private void addColor(Color color) { int hex = color.getRed() << 16 | color.getGreen() << 8 | color.getBlue(); colorMap.put(hex, color); }