@Test public void testEquality() { RGB rgbSalmon = new RGB(250, 128, 114); RGB rgbChocolate = new RGB(210, 105, 30); assertTrue(rgbSalmon.equals(new RGB(250, 128, 114))); assertFalse(rgbSalmon.equals(rgbChocolate)); }
/* * (non-Javadoc) * * @see org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Graphics) */ protected void paintFigure(Graphics graphics) { Rectangle area = new Rectangle(); area.setBounds(getBounds()); // area.crop(getInsets()); if (useLocalCoordinates()) area.setLocation(0, 0); // Rectangle area = getClientArea().getCopy(); RenderInfo rndInfo = getRenderedImage().getRenderInfo(); if (!useOriginalColors()) { RGB backgroundColor = getBackgroundColor().getRGB(); RGB foregroundColor = getForegroundColor().getRGB(); if ((backgroundColor != null && !backgroundColor.equals(rndInfo.getBackgroundColor())) || (foregroundColor != null && !foregroundColor.equals(rndInfo.getForegroundColor()))) { rndInfo.setValues( rndInfo.getWidth(), rndInfo.getHeight(), rndInfo.shouldMaintainAspectRatio(), rndInfo.shouldAntiAlias(), getBackgroundColor().getRGB(), getForegroundColor().getRGB()); setRenderedImage(getRenderedImage().getNewRenderedImage(rndInfo)); } } setRenderedImage( RenderHelper.getInstance( DiagramMapModeUtil.getScale(MapModeUtil.getMapMode(this)), false, false, null) .drawRenderedImage(graphics, getRenderedImage(), area, renderingListener)); }
/** * Processes the save action. * * @param rgb The new RGB value. */ protected void processAction(RGB rgb) { String newComboText = predefinedColor; if (newComboText == null) newComboText = formatRGB(rgb); if (!combo.getText().equals(newComboText)) combo.setText(newComboText); if (oldRgb == null && rgb == null) return; if (rgb != null && rgb.equals(oldRgb)) return; oldRgb = rgb; if (rgb == null || !rgb.equals(colorSelector.getColorValue())) colorSelector.setColorValue(rgb); notifyListeners(SWT.Modify, null); }
private void adaptToTextForegroundChange(Highlighting highlighting, PropertyChangeEvent event) { RGB rgb = null; Object value = event.getNewValue(); if (value instanceof RGB) rgb = (RGB) value; else if (value instanceof String) rgb = StringConverter.asRGB((String) value); if (rgb != null) { String property = event.getProperty(); Color color = fColorManager.getColor(property); if ((color == null || !rgb.equals(color.getRGB())) && fColorManager instanceof IColorManagerExtension) { IColorManagerExtension ext = (IColorManagerExtension) fColorManager; ext.unbindColor(property); ext.bindColor(property, rgb); color = fColorManager.getColor(property); } TextAttribute oldAttr = highlighting.getTextAttribute(); highlighting.setTextAttribute( new TextAttribute(color, oldAttr.getBackground(), oldAttr.getStyle())); } }
/** @param rgb New background color */ public void setPlotBackground(final RGB rgb) { if (background.equals(rgb)) return; background = rgb; // Notify listeners System.out.println("**** Model.setPlotBackground() ****"); for (ModelListener listener : listeners) listener.changedColors(); }
/** * Adds (or replaces) a color to this color registry under the given symbolic name. * * <p>A property change event is reported whenever the mapping from a symbolic name to a color * changes. The source of the event is this registry; the property name is the symbolic color * name. * * @param symbolicName the symbolic color name * @param colorData an <code>RGB</code> object * @param update - fire a color mapping changed if true. False if this method is called from the * get method as no setting has changed. */ private void put(String symbolicName, RGB colorData, boolean update) { Assert.isNotNull(symbolicName); Assert.isNotNull(colorData); RGB existing = stringToRGB.get(symbolicName); if (colorData.equals(existing)) { return; } Color oldColor = stringToColor.remove(symbolicName); stringToRGB.put(symbolicName, colorData); if (update) { fireMappingChanged(symbolicName, existing, colorData); } if (oldColor != null) { staleColors.add(oldColor); } }
protected void refreshControls() { String colorValue = fDiagramModelObject.getFillColor(); RGB rgb = ColorFactory.convertStringToRGB(colorValue); if (rgb == null) { rgb = ColorFactory.getDefaultFillColor(fDiagramModelObject).getRGB(); } fColorChooser.setColorValue(rgb); boolean enabled = fDiagramModelObject instanceof ILockable ? !((ILockable) fDiagramModelObject).isLocked() : true; fColorChooser.setEnabled(enabled); // If user pref is to save the color then it's a different meaning of default boolean isDefaultColor = (colorValue == null); if (Preferences.STORE.getBoolean(IPreferenceConstants.SAVE_USER_DEFAULT_COLOR)) { isDefaultColor = (colorValue != null) && rgb.equals(ColorFactory.getDefaultFillColor(fDiagramModelObject).getRGB()); } fColorChooser.setIsDefaultColor(isDefaultColor); }