edu.sdsc.sirius.dialogs
Class JFontChooser

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byedu.sdsc.sirius.dialogs.JFontChooser
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener, java.awt.image.ImageObserver, javax.swing.event.ListSelectionListener, java.awt.MenuContainer, java.io.Serializable

public class JFontChooser
extends javax.swing.JComponent
implements java.awt.event.ActionListener, javax.swing.event.ListSelectionListener

A simple FontChooser dialog that implements similar functionality to the JFileChooser, JOptionPane and JColorChooser components provided with Swing.

Upon initialization, the JFontChooser polls the system for all available fonts, initializes the various JList components to the values of the default font and provides a preview of the font. As options are changed/selected the preview is updated to display the current font.

JFileChooser can either be created and added to a GUI as a typical JComponent or it can display a JDialog using the showDialog method (just like the JFileChooser component). Objects that extend JFontChooser should use the acceptSelection and cancelSelection methods to determine either an accept or cancel selection.

Example:

JFontChooser chooser = new JFontChooser(new Font("Arial", Font.BOLD, 12));
if (chooser.showDialog(this, "Choose a font...") == JFontChooser.ACCEPT_OPTION) {
  Font f = chooser.getSelectedFont();
  // Process font here...
}

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Field Summary
static int ACCEPT_OPTION
          Value returned by showDialog upon a selected font.
static int CANCEL_OPTION
          Value returned by showDialog upon a cancel.
static int ERROR_OPTION
          Value returned by showDialog upon an error.
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JFontChooser(java.awt.Font font)
          Constructs a new JFontChooser component initialized to the supplied font object.
 
Method Summary
 java.awt.Font acceptSelection()
          This method is called when the user presses the okay button, selecting the currently displayed font.
 void actionPerformed(java.awt.event.ActionEvent e)
          Processes action events from the okay and cancel buttons as well as the current size TextField.
 void cancelSelection()
          This method is called when the user presses the cancel button.
 java.awt.Font getSelectedFont()
          Returns the currently selected font.
 int showDialog(java.awt.Component parent, java.lang.String title)
          Pops up a Font chooser dialog with the supplied title, centered about the component parent.
 void valueChanged(javax.swing.event.ListSelectionEvent e)
          Processes events received from the various JList objects.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ERROR_OPTION

public static final int ERROR_OPTION
Value returned by showDialog upon an error.

See Also:
Constant Field Values

ACCEPT_OPTION

public static final int ACCEPT_OPTION
Value returned by showDialog upon a selected font.

See Also:
Constant Field Values

CANCEL_OPTION

public static final int CANCEL_OPTION
Value returned by showDialog upon a cancel.

See Also:
Constant Field Values
Constructor Detail

JFontChooser

public JFontChooser(java.awt.Font font)
Constructs a new JFontChooser component initialized to the supplied font object.

Method Detail

getSelectedFont

public java.awt.Font getSelectedFont()
Returns the currently selected font. Typically called after receipt of an ACCEPT_OPTION (using the showDialog option) or from within the approveSelection method (using the component option).

Returns:
java.awt.Font A font class that represents the currently selected font.

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Processes action events from the okay and cancel buttons as well as the current size TextField.

Specified by:
actionPerformed in interface java.awt.event.ActionListener

valueChanged

public void valueChanged(javax.swing.event.ListSelectionEvent e)
Processes events received from the various JList objects.

Specified by:
valueChanged in interface javax.swing.event.ListSelectionListener

showDialog

public int showDialog(java.awt.Component parent,
                      java.lang.String title)
Pops up a Font chooser dialog with the supplied title, centered about the component parent.

Returns:
int An integer that equates to the static variables ERROR_OPTION, ACCEPT_OPTION or CANCEL_OPTION.

acceptSelection

public java.awt.Font acceptSelection()
This method is called when the user presses the okay button, selecting the currently displayed font. Children of JFontChooser should override this method to process this event.


cancelSelection

public void cancelSelection()
This method is called when the user presses the cancel button. Children of JFontChooser should override this method to process this event.