Mercurial > projects > dwt-addons
diff dwtx/jface/text/contentassist/ContextInformation.d @ 129:eb30df5ca28b
Added JFace Text sources
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 23 Aug 2008 19:10:48 +0200 |
parents | |
children | c4fb132a086c |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtx/jface/text/contentassist/ContextInformation.d Sat Aug 23 19:10:48 2008 +0200 @@ -0,0 +1,108 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 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 + * Port to the D programming language: + * Frank Benoit <benoit@tionex.de> + *******************************************************************************/ +module dwtx.jface.text.contentassist.ContextInformation; + +import dwt.dwthelper.utils; + + + +import dwt.graphics.Image; +import dwtx.core.runtime.Assert; + + + +/** + * A default implementation of the <code>IContextInformation</code> interface. + */ +public final class ContextInformation : IContextInformation { + + /** The name of the context. */ + private final String fContextDisplayString; + /** The information to be displayed. */ + private final String fInformationDisplayString; + /** The image to be displayed. */ + private final Image fImage; + + /** + * Creates a new context information without an image. + * + * @param contextDisplayString the string to be used when presenting the context + * @param informationDisplayString the string to be displayed when presenting the context information + */ + public ContextInformation(String contextDisplayString, String informationDisplayString) { + this(null, contextDisplayString, informationDisplayString); + } + + /** + * Creates a new context information with an image. + * + * @param image the image to display when presenting the context information + * @param contextDisplayString the string to be used when presenting the context + * @param informationDisplayString the string to be displayed when presenting the context information, + * may not be <code>null</code> + */ + public ContextInformation(Image image, String contextDisplayString, String informationDisplayString) { + + Assert.isNotNull(informationDisplayString); + + fImage= image; + fContextDisplayString= contextDisplayString; + fInformationDisplayString= informationDisplayString; + } + + /* + * @see IContextInformation#equals(Object) + */ + public bool equals(Object object) { + if (object instanceof IContextInformation) { + IContextInformation contextInformation= (IContextInformation) object; + bool equals= fInformationDisplayString.equalsIgnoreCase(contextInformation.getInformationDisplayString()); + if (fContextDisplayString !is null) + equals= equals && fContextDisplayString.equalsIgnoreCase(contextInformation.getContextDisplayString()); + return equals; + } + return false; + } + + /* + * @see java.lang.Object#hashCode() + * @since 3.1 + */ + public int hashCode() { + int low= fContextDisplayString !is null ? fContextDisplayString.hashCode() : 0; + return (fInformationDisplayString.hashCode() << 16) | low; + } + + /* + * @see IContextInformation#getInformationDisplayString() + */ + public String getInformationDisplayString() { + return fInformationDisplayString; + } + + /* + * @see IContextInformation#getImage() + */ + public Image getImage() { + return fImage; + } + + /* + * @see IContextInformation#getContextDisplayString() + */ + public String getContextDisplayString() { + if (fContextDisplayString !is null) + return fContextDisplayString; + return fInformationDisplayString; + } +}