KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > text > contentassist > ContextInformation


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jface.text.contentassist;
12
13 import org.eclipse.swt.graphics.Image;
14
15 import org.eclipse.core.runtime.Assert;
16
17
18
19 /**
20  * A default implementation of the <code>IContextInformation</code> interface.
21  */

22 public final class ContextInformation implements IContextInformation {
23
24     /** The name of the context. */
25     private final String JavaDoc fContextDisplayString;
26     /** The information to be displayed. */
27     private final String JavaDoc fInformationDisplayString;
28     /** The image to be displayed. */
29     private final Image fImage;
30
31     /**
32      * Creates a new context information without an image.
33      *
34      * @param contextDisplayString the string to be used when presenting the context
35      * @param informationDisplayString the string to be displayed when presenting the context information
36      */

37     public ContextInformation(String JavaDoc contextDisplayString, String JavaDoc informationDisplayString) {
38         this(null, contextDisplayString, informationDisplayString);
39     }
40
41     /**
42      * Creates a new context information with an image.
43      *
44      * @param image the image to display when presenting the context information
45      * @param contextDisplayString the string to be used when presenting the context
46      * @param informationDisplayString the string to be displayed when presenting the context information,
47      * may not be <code>null</code>
48      */

49     public ContextInformation(Image image, String JavaDoc contextDisplayString, String JavaDoc informationDisplayString) {
50
51         Assert.isNotNull(informationDisplayString);
52
53         fImage= image;
54         fContextDisplayString= contextDisplayString;
55         fInformationDisplayString= informationDisplayString;
56     }
57
58     /*
59      * @see IContextInformation#equals(Object)
60      */

61     public boolean equals(Object JavaDoc object) {
62         if (object instanceof IContextInformation) {
63             IContextInformation contextInformation= (IContextInformation) object;
64             boolean equals= fInformationDisplayString.equalsIgnoreCase(contextInformation.getInformationDisplayString());
65             if (fContextDisplayString != null)
66                 equals= equals && fContextDisplayString.equalsIgnoreCase(contextInformation.getContextDisplayString());
67             return equals;
68         }
69         return false;
70     }
71
72     /*
73      * @see java.lang.Object#hashCode()
74      * @since 3.1
75      */

76     public int hashCode() {
77         int low= fContextDisplayString != null ? fContextDisplayString.hashCode() : 0;
78         return (fInformationDisplayString.hashCode() << 16) | low;
79     }
80
81     /*
82      * @see IContextInformation#getInformationDisplayString()
83      */

84     public String JavaDoc getInformationDisplayString() {
85         return fInformationDisplayString;
86     }
87
88     /*
89      * @see IContextInformation#getImage()
90      */

91     public Image getImage() {
92         return fImage;
93     }
94
95     /*
96      * @see IContextInformation#getContextDisplayString()
97      */

98     public String JavaDoc getContextDisplayString() {
99         if (fContextDisplayString != null)
100             return fContextDisplayString;
101         return fInformationDisplayString;
102     }
103 }
104
Popular Tags