/******************************************************************************* * Copyright (c) 2003, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - Initial API and implementation *******************************************************************************/ package org.eclipse.wst.server.ui.internal; import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.jface.resource.CompositeImageDescriptor; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.graphics.Point; /** * A OverlayImageDescriptor consists of a main icon and one or more overlays. * The overlays are computed according to flags set on creation of the descriptor. */ public class OverlayImageDescriptor extends CompositeImageDescriptor { // flag to render the error overlay public final static int ERROR = 0x001; private Image fBaseImage; private int fFlags; private Point fSize; /** * Create a new OverlayImageDescriptor. * * @param baseImage an image descriptor used as the base image * @param flags flags indicating which adornments are to be rendered */ public OverlayImageDescriptor(Image baseImage, int flags) { setBaseImage(baseImage); setFlags(flags); } /** * @see CompositeImageDescriptor#getSize() */ protected Point getSize() { if (fSize == null) { ImageData data = getBaseImage().getImageData(); setSize(new Point(data.width, data.height)); } return fSize; } /** * @see Object#equals(java.lang.Object) */ public boolean equals(Object object) { if (!(object instanceof OverlayImageDescriptor)) return false; OverlayImageDescriptor other = (OverlayImageDescriptor) object; return (getBaseImage().equals(other.getBaseImage()) && getFlags() == other.getFlags()); } /** * @see Object#hashCode() */ public int hashCode() { return getBaseImage().hashCode() | getFlags(); } /** * @see CompositeImageDescriptor#drawCompositeImage(int, int) */ protected void drawCompositeImage(int width, int height) { ImageData bg = getBaseImage().getImageData(); if (bg == null) bg = DEFAULT_IMAGE_DATA; drawImage(bg, 0, 0); drawOverlays(); } /** * Add any overlays to the image as specified in the flags. */ protected void drawOverlays() { int flags = getFlags(); ImageData data = null; if ((flags & ERROR) != 0) { data = DebugUITools.getImage(IDebugUIConstants.IMG_OVR_ERROR).getImageData(); int x = getSize().x - data.width; drawImage(data, x, 0); } } protected Image getBaseImage() { return fBaseImage; } protected void setBaseImage(Image baseImage) { fBaseImage = baseImage; } protected int getFlags() { return fFlags; } protected void setFlags(int flags) { fFlags = flags; } protected void setSize(Point size) { fSize = size; } }