com.connectina.swing.fontchooser
Class DefaultFontSelectionModel

java.lang.Object
  extended by com.connectina.swing.fontchooser.DefaultFontSelectionModel
All Implemented Interfaces:
FontSelectionModel

public class DefaultFontSelectionModel
extends Object
implements FontSelectionModel

A generic implementation of FontSelectionModel.

See Also:
Font

Field Summary
protected  ChangeEvent changeEvent
          Only one ChangeEvent is needed per model instance since the event's only (read-only) state is the source property.
protected  EventListenerList listenerList
          A list of registered event listeners.
 
Constructor Summary
DefaultFontSelectionModel()
          Creates a DefaultFontSelectionModel with the current font set to new Font(Font.SANS_SERIF, Font.PLAIN, 12) .
DefaultFontSelectionModel(Font font)
          Creates a DefaultFontSelectionModel with the current font set to font, which should be non-null.
 
Method Summary
 void addChangeListener(ChangeListener l)
          Adds a ChangeListener to the model.
protected  void fireStateChanged()
          Runs each ChangeListener's stateChanged method.
 List<String> getAvailableFontNames()
          Gets the available font names.
 ChangeListener[] getChangeListeners()
          Returns an array of all the ChangeListeners added to this DefaultFontSelectionModel with addChangeListener.
 Font getSelectedFont()
          Returns the selected Font which should be non-null.
 void removeChangeListener(ChangeListener l)
          Removes a ChangeListener from the model.
 void setSelectedFont(Font font)
          Sets the selected font to font.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

changeEvent

protected transient ChangeEvent changeEvent
Only one ChangeEvent is needed per model instance since the event's only (read-only) state is the source property. The source of events generated here is always "this".


listenerList

protected EventListenerList listenerList
A list of registered event listeners.

Constructor Detail

DefaultFontSelectionModel

public DefaultFontSelectionModel()
Creates a DefaultFontSelectionModel with the current font set to new Font(Font.SANS_SERIF, Font.PLAIN, 12) . This is the default constructor.


DefaultFontSelectionModel

public DefaultFontSelectionModel(Font font)
Creates a DefaultFontSelectionModel with the current font set to font, which should be non-null. Note that setting the font to null is undefined and may have unpredictable results.

Parameters:
font - the new Font
Method Detail

getSelectedFont

public Font getSelectedFont()
Returns the selected Font which should be non-null.

Specified by:
getSelectedFont in interface FontSelectionModel
Returns:
the selected Font
See Also:
FontSelectionModel.setSelectedFont(java.awt.Font)

setSelectedFont

public void setSelectedFont(Font font)
Sets the selected font to font. Note that setting the font to null is undefined and may have unpredictable results. This method fires a state changed event if it sets the current font to a new non-null font; if the new font is the same as the current font, no event is fired.

Specified by:
setSelectedFont in interface FontSelectionModel
Parameters:
font - the new Font
See Also:
FontSelectionModel.getSelectedFont(), FontSelectionModel.addChangeListener(javax.swing.event.ChangeListener)

getAvailableFontNames

public List<String> getAvailableFontNames()
Gets the available font names. Returns a list containing the names of all font families in this GraphicsEnvironment localized for the default locale, as returned by Locale.getDefault().

Specified by:
getAvailableFontNames in interface FontSelectionModel
Returns:
a list of String containing font family names localized for the default locale, or a suitable alternative name if no name exists for this locale

addChangeListener

public void addChangeListener(ChangeListener l)
Adds a ChangeListener to the model.

Specified by:
addChangeListener in interface FontSelectionModel
Parameters:
l - the ChangeListener to be added

removeChangeListener

public void removeChangeListener(ChangeListener l)
Removes a ChangeListener from the model.

Specified by:
removeChangeListener in interface FontSelectionModel
Parameters:
l - the ChangeListener to be removed

getChangeListeners

public ChangeListener[] getChangeListeners()
Returns an array of all the ChangeListeners added to this DefaultFontSelectionModel with addChangeListener.

Returns:
all of the ChangeListeners added, or an empty array if no listeners have been added

fireStateChanged

protected void fireStateChanged()
Runs each ChangeListener's stateChanged method.