KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > resource > NamedFontDescriptor


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 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.resource;
12
13 import org.eclipse.swt.graphics.Device;
14 import org.eclipse.swt.graphics.Font;
15 import org.eclipse.swt.graphics.FontData;
16
17 /**
18  * Identifies a font by its name, height, and style.
19  *
20  * @since 3.1
21  */

22 final class NamedFontDescriptor extends FontDescriptor {
23
24     private FontData data;
25     
26     /**
27      * Creates a font descriptor for a font with the given name, height,
28      * and style. These arguments are passed directly to the constructor
29      * of Font.
30      *
31      * @param data FontData describing the font to create
32      *
33      * @see org.eclipse.swt.graphics.Font#Font(org.eclipse.swt.graphics.Device, org.eclipse.swt.graphics.FontData)
34      */

35     public NamedFontDescriptor(FontData data) {
36         this.data = data;
37     }
38     
39     /* (non-Javadoc)
40      * @see org.eclipse.jface.resource.FontDescriptor#createFont(org.eclipse.swt.graphics.Device)
41      */

42     public Font createFont(Device device) {
43         return new Font(device, data);
44     }
45
46     /* (non-Javadoc)
47      * @see java.lang.Object#equals(java.lang.Object)
48      */

49     public boolean equals(Object JavaDoc obj) {
50         if ((obj.getClass() == NamedFontDescriptor.class)) {
51             NamedFontDescriptor descr = (NamedFontDescriptor)obj;
52             
53             return data.equals(descr.data);
54         }
55         
56         return super.equals(obj);
57     }
58     
59     /* (non-Javadoc)
60      * @see java.lang.Object#hashCode()
61      */

62     public int hashCode() {
63         return data.hashCode();
64     }
65
66     /* (non-Javadoc)
67      * @see org.eclipse.jface.resource.FontDescriptor#destroyFont(org.eclipse.swt.graphics.Font)
68      */

69     public void destroyFont(Font previouslyCreatedFont) {
70         previouslyCreatedFont.dispose();
71     }
72
73 }
74
Popular Tags