Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 


Eclipse Platform
Release 3.5

org.eclipse.jface.resource
Class FontRegistry

java.lang.Object
  extended by 

org.eclipse.core.commands.common.EventManager
      extended by 

org.eclipse.jface.resource.ResourceRegistry
          extended by 
org.eclipse.jface.resource.FontRegistry

public class FontRegistry
extends ResourceRegistry

A font registry maintains a mapping between symbolic font names and SWT fonts.

A font registry owns all of the font objects registered with it, and automatically disposes of them when the SWT Display that creates the fonts is disposed. Because of this, clients do not need to (indeed, must not attempt to) dispose of font objects themselves.

A special constructor is provided for populating a font registry from a property files using the standard Java resource bundle mechanism.

Methods are provided for registering listeners that will be kept apprised of changes to list of registered fonts.

Clients may instantiate this class (it was not designed to be subclassed).

Since 3.0 this class extends ResourceRegistry.

Restriction:
This class is not intended to be subclassed by clients.

Field Summary
protected   Runnable displayRunnable
          Runnable that cleans up the manager on disposal of the display.
 
Constructor Summary
FontRegistry ()
          Creates an empty font registry.
FontRegistry ( Display display)
          Creates an empty font registry.
FontRegistry ( Display display, boolean cleanOnDisplayDisposal)
          Creates an empty font registry.
FontRegistry ( String location)
          Load the FontRegistry using the ClassLoader from the PlatformUI plug-in This method should only be called from the UI thread.
FontRegistry ( String location, ClassLoader loader)
          Creates a font registry and initializes its content from a property file.
 
Method Summary
  FontData bestData ( FontData[] fonts, Display display)
          Deprecated. use bestDataArray in order to support Motif multiple entry fonts.
  FontData[] bestDataArray ( FontData[] fonts, Display display)
          Deprecated. use filterData in order to preserve multiple entry fonts on Motif
protected  void clearCaches ()
          Disposes all currently allocated resources.
  Font defaultFont ()
          Returns the default font data.
  FontDescriptor defaultFontDescriptor ()
          Returns the font descriptor for the JFace default font.
  FontData[] filterData ( FontData[] fonts, Display display)
          Removes from the list all fonts that do not exist in this system.
  Font get ( String symbolicName)
          Returns the font associated with the given symbolic font name.
  Font getBold ( String symbolicName)
          Returns the bold font associated with the given symbolic font name.
  FontDescriptor getDescriptor ( String symbolicName)
          Returns the font descriptor for the font with the given symbolic font name.
  FontData[] getFontData ( String symbolicName)
          Returns the font data associated with the given symbolic font name.
  Font getItalic ( String symbolicName)
          Returns the italic font associated with the given symbolic font name.
  Set getKeySet ()
           
 boolean hasValueFor ( String fontKey)
          Return whether or not the receiver has a value for the supplied key.
 void put ( String symbolicName, FontData[] fontData)
          Adds (or replaces) a font to this font registry under the given symbolic name.
 
Methods inherited from class org.eclipse.jface.resource. ResourceRegistry
addListener, fireMappingChanged, removeListener
 
Methods inherited from class org.eclipse.core.commands.common. EventManager
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
 
Methods inherited from class java.lang. Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

displayRunnable

protected 
Runnable displayRunnable
Runnable that cleans up the manager on disposal of the display.

Constructor Detail

FontRegistry

public FontRegistry()
Creates an empty font registry.

There must be an SWT Display created in the current thread before calling this method.


FontRegistry

public FontRegistry(
String location,
                    
ClassLoader loader)
             throws 
MissingResourceException
Creates a font registry and initializes its content from a property file.

There must be an SWT Display created in the current thread before calling this method.

The OS name (retrieved using System.getProperty("os.name")) is converted to lowercase, purged of whitespace, and appended as suffix (separated by an underscore '_') to the given location string to yield the base name of a resource bundle acceptable to ResourceBundle.getBundle. The standard Java resource bundle mechanism is then used to locate and open the appropriate properties file, taking into account locale specific variations.

For example, on the Windows 2000 operating system the location string "com.example.myapp.Fonts" yields the base name "com.example.myapp.Fonts_windows2000". For the US English locale, this further elaborates to the resource bundle name "com.example.myapp.Fonts_windows2000_en_us".

If no appropriate OS-specific resource bundle is found, the process is repeated using the location as the base bundle name.

The property file contains entries that look like this:

        textfont.0=MS Sans Serif-regular-10
        textfont.1=Times New Roman-regular-10
        
        titlefont.0=MS Sans Serif-regular-12
        titlefont.1=Times New Roman-regular-12
 
Each entry maps a symbolic font names (the font registry keys) with a ".n suffix to standard font names on the right. The suffix indicated order of preference: ".0" indicates the first choice, ".1" indicates the second choice, and so on.

The following example shows how to use the font registry:
        FontRegistry registry = new FontRegistry("com.example.myapp.fonts");
  Font font = registry.get("textfont");
  control.setFont(font);
  ...
 

Parameters:
location - the name of the resource bundle
loader - the ClassLoader to use to find the resource bundle
Throws:
MissingResourceException - if the resource bundle cannot be found
Since:
2.1

FontRegistry

public FontRegistry(
String location)
             throws 
MissingResourceException
Load the FontRegistry using the ClassLoader from the PlatformUI plug-in

This method should only be called from the UI thread. If you are not on the UI thread then wrap the call with a PlatformUI.getWorkbench().getDisplay().synchExec() in order to guarantee the correct result. Failure to do this may result in an SWTException being thrown.

Parameters:
location - the location to read the resource bundle from
Throws:
MissingResourceException - Thrown if a resource is missing

FontRegistry

public FontRegistry(
Display display)
Creates an empty font registry.

Parameters:
display - the Display

FontRegistry

public FontRegistry(
Display display,
                    boolean cleanOnDisplayDisposal)
Creates an empty font registry.

Parameters:
display - the Display
cleanOnDisplayDisposal - whether all fonts allocated by this FontRegistry should be disposed when the display is disposed
Since:
3.1
Method Detail

bestData

public 
FontData bestData(
FontData[] fonts,
                         
Display display)
Deprecated. use bestDataArray in order to support Motif multiple entry fonts.

Find the first valid fontData in the provided list. If none are valid return the first one regardless. If the list is empty return null. Return null if one cannot be found.

Parameters:
fonts - the font list
display - the display used
Returns:
the font data of the like describe above

bestDataArray

public 
FontData[] bestDataArray(
FontData[] fonts,
                                
Display display)
Deprecated. use filterData in order to preserve multiple entry fonts on Motif

Find the first valid fontData in the provided list. If none are valid return the first one regardless. If the list is empty return null.

Parameters:
fonts - list of fonts
display - the display
Returns:
font data like described above

filterData

public 
FontData[] filterData(
FontData[] fonts,
                             
Display display)
Removes from the list all fonts that do not exist in this system. If none are valid, return the first irregardless. If the list is empty return null.

Parameters:
fonts - the fonts to check
display - the display to check against
Returns:
the list of fonts that have been found on this system
Since:
3.1

defaultFont

public 
Font defaultFont()
Returns the default font data. Creates it if necessary.

This method should only be called from the UI thread. If you are not on the UI thread then wrap the call with a PlatformUI.getWorkbench().getDisplay().synchExec() in order to guarantee the correct result. Failure to do this may result in an SWTException being thrown.

Returns:
Font

getDescriptor

public 
FontDescriptor getDescriptor(
String symbolicName)
Returns the font descriptor for the font with the given symbolic font name. Returns the default font if there is no special value associated with that name

Parameters:
symbolicName - symbolic font name
Returns:
the font descriptor (never null)
Since:
3.3

getFontData

public 
FontData[] getFontData(
String symbolicName)
Returns the font data associated with the given symbolic font name. Returns the default font data if there is no special value associated with that name.

Parameters:
symbolicName - symbolic font name
Returns:
the font

get

public 
Font get(
String symbolicName)
Returns the font associated with the given symbolic font name. Returns the default font if there is no special value associated with that name.

This method should only be called from the UI thread. If you are not on the UI thread then wrap the call with a PlatformUI.getWorkbench().getDisplay().synchExec() in order to guarantee the correct result. Failure to do this may result in an SWTException being thrown.

Parameters:
symbolicName - symbolic font name
Returns:
the font

getBold

public 
Font getBold(
String symbolicName)
Returns the bold font associated with the given symbolic font name. Returns the bolded default font if there is no special value associated with that name.

This method should only be called from the UI thread. If you are not on the UI thread then wrap the call with a PlatformUI.getWorkbench().getDisplay().synchExec() in order to guarantee the correct result. Failure to do this may result in an SWTException being thrown.

Parameters:
symbolicName - symbolic font name
Returns:
the font
Since:
3.0

getItalic

public 
Font getItalic(
String symbolicName)
Returns the italic font associated with the given symbolic font name. Returns the italic default font if there is no special value associated with that name.

This method should only be called from the UI thread. If you are not on the UI thread then wrap the call with a PlatformUI.getWorkbench().getDisplay().synchExec() in order to guarantee the correct result. Failure to do this may result in an SWTException being thrown.

Parameters:
symbolicName - symbolic font name
Returns:
the font
Since:
3.0

getKeySet

public 
Set getKeySet()
Specified by:
getKeySet in class ResourceRegistry
Returns:
the set of keys this manager knows about. This collection should be immutable.

hasValueFor

public boolean hasValueFor(
String fontKey)
Description copied from class: ResourceRegistry
Return whether or not the receiver has a value for the supplied key.

Specified by:
hasValueFor in class ResourceRegistry
Parameters:
fontKey - the key
Returns:
true if there is a value for this key

clearCaches

protected void clearCaches()
Description copied from class: ResourceRegistry
Disposes all currently allocated resources.

Specified by:
clearCaches in class ResourceRegistry

put

public void put(
String symbolicName,
                
FontData[] fontData)
Adds (or replaces) a font to this font registry under the given symbolic name.

A property change event is reported whenever the mapping from a symbolic name to a font changes. The source of the event is this registry; the property name is the symbolic font name.

Parameters:
symbolicName - the symbolic font name
fontData - an Array of FontData

defaultFontDescriptor

public 
FontDescriptor defaultFontDescriptor()
Returns the font descriptor for the JFace default font.

Returns:
the font descriptor for the JFace default font
Since:
3.3

Eclipse Platform
Release 3.5

Guidelines for using Eclipse APIs.

Copyright (c) Eclipse contributors and others 2000, 2008. All rights reserved.


 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire