Eclipse Platform
Release 3.1

org.eclipse.jface.resource
Class FontDescriptor

java.lang.Object
  extended byorg.eclipse.jface.resource.DeviceResourceDescriptor
      extended byorg.eclipse.jface.resource.FontDescriptor

public abstract class FontDescriptor
extends DeviceResourceDescriptor

Lightweight descriptor for a font. Creates the described font on demand. Subclasses can implement different ways of describing a font. These objects will be compared, so hashCode(...) and equals(...) must return something meaningful.

Since:
3.1

Constructor Summary
FontDescriptor()
           
 
Method Summary
abstract  Font createFont(Device device)
          Creates the Font described by this descriptor.
static FontDescriptor createFrom(Font font)
          Creates a FontDescriptor that describes an existing font.
static FontDescriptor createFrom(FontData data)
          Creates a new FontDescriptor given the associated FontData
static FontDescriptor createFrom(FontData[] data)
          Creates a new FontDescriptor given the an array of FontData that describes the font.
static FontDescriptor createFrom(Font font, Device originalDevice)
          Creates a FontDescriptor that describes an existing font.
static FontDescriptor createFrom(String name, int height, int style)
          Creates a new FontDescriptor given an OS-specific font name, height, and style.
 Object createResource(Device device)
          Creates the resource described by this descriptor
abstract  void destroyFont(Font previouslyCreatedFont)
          Deallocates anything that was allocated by createFont, given a font that was allocated by an equal FontDescriptor.
 void destroyResource(Object previouslyCreatedObject)
          Undoes everything that was done by a previous call to create(...), given the object that was returned by create(...).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FontDescriptor

public FontDescriptor()
Method Detail

createFrom

public static FontDescriptor createFrom(Font font,
                                        Device originalDevice)
Creates a FontDescriptor that describes an existing font. The resulting descriptor depends on the Font. Disposing the Font while the descriptor is still in use may throw a graphic disposed exception.

Parameters:
font - a font to describe
originalDevice - must be the same Device that was passed into the font's constructor when it was first created.
Returns:
a newly created FontDescriptor.
Since:
3.1

createFrom

public static FontDescriptor createFrom(Font font)
Creates a FontDescriptor that describes an existing font. The resulting descriptor depends on the original Font, and disposing the original Font while the descriptor is still in use may cause SWT to throw a graphic disposed exception. This is less efficient than createFrom(Font, Device) , so the other version should be used whenever possible.

Parameters:
font - font to create
Returns:
a newly created FontDescriptor that describes the given font
Since:
3.1

createFrom

public static FontDescriptor createFrom(FontData[] data)
Creates a new FontDescriptor given the an array of FontData that describes the font.

Parameters:
data - an array of FontData that describes the font (will be passed into the Font's constructor)
Returns:
a FontDescriptor that describes the given font
Since:
3.1

createFrom

public static FontDescriptor createFrom(FontData data)
Creates a new FontDescriptor given the associated FontData

Parameters:
data - FontData describing the font to create
Returns:
a newly created FontDescriptor

createFrom

public static FontDescriptor createFrom(String name,
                                        int height,
                                        int style)
Creates a new FontDescriptor given an OS-specific font name, height, and style.

Parameters:
name - os-specific font name
height - height (pixels)
style - a bitwise combination of NORMAL, BOLD, ITALIC
Returns:
a new FontDescriptor
See Also:
Font.Font(org.eclipse.swt.graphics.Device, java.lang.String, int, int)

createFont

public abstract Font createFont(Device device)
                         throws DeviceResourceException
Creates the Font described by this descriptor.

Parameters:
device - device on which to allocate the font
Returns:
a newly allocated Font (never null)
Throws:
DeviceResourceException - if unable to allocate the Font
Since:
3.1

destroyFont

public abstract void destroyFont(Font previouslyCreatedFont)
Deallocates anything that was allocated by createFont, given a font that was allocated by an equal FontDescriptor.

Parameters:
previouslyCreatedFont - previously allocated font
Since:
3.1

createResource

public final Object createResource(Device device)
                            throws DeviceResourceException
Description copied from class: DeviceResourceDescriptor
Creates the resource described by this descriptor

Specified by:
createResource in class DeviceResourceDescriptor
Parameters:
device - the Device on which to allocate the resource
Returns:
the newly allocated resource (not null)
Throws:
DeviceResourceException - if unable to allocate the resource

destroyResource

public final void destroyResource(Object previouslyCreatedObject)
Description copied from class: DeviceResourceDescriptor
Undoes everything that was done by a previous call to create(...), given the object that was returned by create(...).

Specified by:
destroyResource in class DeviceResourceDescriptor
Parameters:
previouslyCreatedObject - an object that was returned by an equal descriptor in a previous call to createResource(...).

Eclipse Platform
Release 3.1

Guidelines for using Eclipse APIs.

Copyright (c) IBM Corp. and others 2000, 2005. All rights reserved.