KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > graphics > GlyphMetrics


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.swt.graphics;
12
13 import org.eclipse.swt.*;
14
15 /**
16  * Instances of this class represent glyph metrics.
17  * <p>
18  * The hashCode() method in this class uses the values of the public
19  * fields to compute the hash value. When storing instances of the
20  * class in hashed collections, do not modify these fields after the
21  * object has been inserted.
22  * </p>
23  * <p>
24  * Application code does <em>not</em> need to explicitly release the
25  * resources managed by each instance when those instances are no longer
26  * required, and thus no <code>dispose()</code> method is provided.
27  * </p>
28  *
29  * @see TextStyle
30  * @see TextLayout
31  *
32  * @since 3.2
33  */

34 public final class GlyphMetrics {
35     
36     /**
37      * the ascent of the GlyphMetrics
38      */

39     public int ascent;
40     
41     /**
42      * the descent of the GlyphMetrics
43      */

44     public int descent;
45     
46     /**
47      * the width of the GlyphMetrics
48      */

49     public int width;
50     
51 /**
52  * Constructs an instance of this class with the given
53  * ascent, descent and width values.
54  *
55  * @exception IllegalArgumentException <ul>
56  * <li>ERROR_INVALID_ARGUMENT - if the ascent, descent or width argument is negative</li>
57  * </ul>
58  */

59 public GlyphMetrics(int ascent, int descent, int width) {
60     if (ascent < 0 || descent < 0 || width < 0) {
61             SWT.error(SWT.ERROR_INVALID_ARGUMENT);
62     }
63     this.ascent = ascent;
64     this.descent = descent;
65     this.width = width;
66 }
67
68 /**
69  * Compares the argument to the receiver, and returns true
70  * if they represent the <em>same</em> object using a class
71  * specific comparison.
72  *
73  * @param object the object to compare with this object
74  * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
75  *
76  * @see #hashCode()
77  */

78 public boolean equals (Object JavaDoc object) {
79     if (object == this) return true;
80     if (!(object instanceof GlyphMetrics)) return false;
81     GlyphMetrics metrics = (GlyphMetrics)object;
82     return metrics.ascent == ascent && metrics.descent == descent && metrics.width == width;
83 }
84
85 /**
86  * Returns an integer hash code for the receiver. Any two
87  * objects that return <code>true</code> when passed to
88  * <code>equals</code> must return the same value for this
89  * method.
90  *
91  * @return the receiver's hash
92  *
93  * @see #equals(Object)
94  */

95 public int hashCode () {
96     return ascent ^ descent ^ width;
97 }
98
99 /**
100  * Returns a string containing a concise, human-readable
101  * description of the receiver.
102  *
103  * @return a string representation of the <code>GlyphMetrics</code>
104  */

105 public String JavaDoc toString () {
106     return "GlyphMetrics {" + ascent + ", " + descent + ", " + width + "}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
107
}
108
109 }
110
Popular Tags