PIRL.Viewers

## Class Font_Selector

- java.lang.Object
- - java.awt.Component
  - - java.awt.Container
    - - java.awt.Window
      - - java.awt.Dialog
        - - javax.swing.JDialog
          - - PIRL.Viewers.Font_Selector

All Implemented Interfaces:
  ItemListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, RootPaneContainer, WindowConstants

    public class Font_Selector
    extends JDialog
    implements ItemListener

A Font_Selector is a dialog box for selecting a named font and its size and style characteristics.

See Also:
  Serialized Form

### Nested Class Summary

### Nested classes/interfaces inherited from class javax.swing.JDialog

`JDialog.AccessibleJDialog`

### Nested classes/interfaces inherited from class java.awt.Dialog

`Dialog.AccessibleAWTDialog, Dialog.ModalExclusionType, Dialog.ModalityType`

### Nested classes/interfaces inherited from class java.awt.Window

`Window.AccessibleAWTWindow, Window.Type`

### Nested classes/interfaces inherited from class java.awt.Container

`Container.AccessibleAWTContainer`

### Nested classes/interfaces inherited from class java.awt.Component

`Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy`

### Field Summary

Fields
`static Font` `DEFAULT_FONT` The default font when no other default is available: SansSerif 12-point plain.
`static Vector` `DEFAULT_SIZES` The Vector of default Integer font sizes: 9, 10, 12, 14, 16, 18, 24.
`static int` `MAXIMUM_SIZE` The maximum acceptable value for a font size: 256.
`static int` `MINIMUM_SIZE` The minimum acceptable value for a font size: 4.

### Fields inherited from class javax.swing.JDialog

`accessibleContext, rootPane, rootPaneCheckingEnabled`

### Fields inherited from class java.awt.Dialog

`DEFAULT_MODALITY_TYPE`

### Fields inherited from class java.awt.Component

`BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT`

### Fields inherited from interface javax.swing.WindowConstants

`DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE`

### Fields inherited from interface java.awt.image.ImageObserver

`ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH`

### Constructor Summary

Constructors
Constructor and Description
`Font_Selector()` Constructs a `Font_Selector` with font and style selections enabled, with no "Apply" button, and using the `DEFAULT_SIZES` and null title, default font and owner.
`Font_Selector(Font default_font)` Constructs a `Font_Selector` with font and style selections enabled, with no "Apply" button, and using the `DEFAULT_SIZES` and a null title and owner.
`Font_Selector(String title)` Constructs a `Font_Selector` with font and style selections enabled, with no "Apply" button, and using the `DEFAULT_SIZES` and a null default font and owner.
`Font_Selector(String title, boolean select_font, boolean select_style, Vector select_sizes)` Constructs a `Font_Selector` with no "Apply" button, and using a null default font and owner.
`Font_Selector(String title, boolean select_font, boolean select_style, Vector select_sizes, Font default_font)` Constructs a `Font_Selector` with no "Apply" button, and using a null owner.
`Font_Selector(String title, boolean select_font, boolean select_style, Vector select_sizes, Font default_font, ActionListener apply_listener, Frame owner)` Constructs a `Font_Selector` containing the specified font characteteristics selection lists.
`Font_Selector(String title, boolean select_font, boolean select_style, Vector select_sizes, Frame owner)` Constructs a `Font_Selector` with no "Apply" button, and using a null default font.
`Font_Selector(String title, Font default_font)` Constructs a `Font_Selector` with font and style selections enabled, with no "Apply" button, and using the `DEFAULT_SIZES` and a null owner.
`Font_Selector(String title, Font default_font, Frame owner)` Constructs a `Font_Selector` with font and style selections enabled, with no "Apply" button, and using the `DEFAULT_SIZES`.
`Font_Selector(String title, Frame owner)` Constructs a `Font_Selector` with font and style selections enabled and using the `DEFAULT_SIZES` and a null default font.

### Method Summary

Methods
`void` `addActionListener(ActionListener apply_listener)` Adds an `ActionListener` to the "Apply" button.
`String` `Font_Name()` Gets the name of the current font.
`Font_Selector` `Font_Name(String name)` Sets the current font to the named family.
`Font` `Font()` Gets the current font.
`Font_Selector` `Font(Font font)` Set the current font.
`Font_Selector` `Font(String name, int style, int size)` Set the current font name, style and size.
`ActionListener[]` `getActionListeners()` Gets an array of `ActionListener`s currently registered with the "Apply" button.
`void` `itemStateChanged(ItemEvent event)` The method that implements the ItemListener interface to listen for list selections.
`static void` `main(String[] arguments)`
`int` `Nearest_Size(int size)` Gets the size from the selection list that is nearest to a specified size.
`Font` `Original_Font()` Gets the original font.
`void` `removeActionListener(ActionListener apply_listener)` Removes an `ActionListener`, if registered, from the "Apply" button, if present.
`void` `Reset()` Resets the current font to the original font.
`Font` `Select()` Initiates a `Select` operation using the previous original font.
`Font` `Select(Font default_font)` Initiates a user interactive font selection.
`void` `setVisible(boolean set_visible)` Sets the dialog to be visible on the display.
`int` `Size()` Gets the size of the current font.
`Font_Selector` `Size(int size)` Sets the size of the current font.
`static String` `Style_Description(int style)` Provides a description of a style value.
`int` `Style()` Gets the style of the current font.
`Font_Selector` `Style(int style)` Sets the style of the current font.
`String` `Text()` Gets the current sample text.
`Font_Selector` `Text(String text)` Sets the text to be displayed in the current font.

### Methods inherited from class javax.swing.JDialog

`addImpl, createRootPane, dialogInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update`

### Methods inherited from class java.awt.Dialog

`addNotify, getModalityType, getTitle, hide, isModal, isResizable, isUndecorated, setBackground, setModal, setModalityType, setOpacity, setResizable, setShape, setTitle, setUndecorated, show, toBack`

### Methods inherited from class java.awt.Window

`addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeNotify, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImage, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, toFront`

### Methods inherited from class java.awt.Container

`add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validate, validateTree`

### Methods inherited from class java.awt.Component

`action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### DEFAULT_FONT

    public static final Font DEFAULT_FONT

The default font when no other default is available: SansSerif 12-point plain.

#### DEFAULT_SIZES

    public static final Vector DEFAULT_SIZES

The Vector of default Integer font sizes: 9, 10, 12, 14, 16, 18, 24.

#### MINIMUM_SIZE

    public static final int MINIMUM_SIZE

The minimum acceptable value for a font size: 4.

See Also:
  Constant Field Values

#### MAXIMUM_SIZE

    public static final int MAXIMUM_SIZE

The maximum acceptable value for a font size: 256.

See Also:
  Constant Field Values

### Constructor Detail

#### Font_Selector

    public Font_Selector(String title,
                 boolean select_font,
                 boolean select_style,
                 Vector select_sizes,
                 Font default_font,
                 ActionListener apply_listener,
                 Frame owner)

Constructs a `Font_Selector` containing the specified font characteteristics selection lists.

Note: If no selection characteristics lists are enabled, then the dialog will not appear when `setVisible`. The resulting object will still provide correct responses to all of its methods, however.

Parameters:
  `title` - The String to be used as the title on the dialog box. If this is null, then the title will be "Font_Selector".
  `select_font` - If true, a pull-down list of all available font family names is included on the selection panel. If false, no font selection is provided.
  `select_style` - If true, a pull-down list of the four possible font styles - plain, bold, italic, and bold plus italic - is is included on the selection panel. If false, no style selection is provided.
  `select_sizes` - A Vector of Integer values listing the allowable font sizes to included in a pull-down on the selection panel. The list will be numerically sorted and duplicate values will be removed. If the list contains two values and the second value is negative, then all values in the range [first,-second] will be included in the selection list. Any value less than the ``MINIMUM_SIZE`` or greater than the ``MAXIMUM_SIZE`` is excluded. If the Vector is empty, or all of the listed values are outside of the acceptable range, then the ``DEFAULT_SIZES`` will be used. If the Vector is null, no size selection is provided (but the `DEFAULT_SIZES` will still be the effective selection sizes).
  `default_font` - The Font to use as the original, default, font. If the default_font is null and there is a non-null owner, then the font from the owner will be used; otherwise the default front from the dialog will be used. If this fails to produce a non-null font, then the ``DEFAULT_FONT`` will be used. If the size of the final default font is not one of the selection sizes, then the ``Nearest_Size`` to the font size in the selection list will be used.
  `apply_listener` - An ActionListener that will be associated with an "Apply" button. When the button is pressed the button will call the listener's `{#ActionListener.actionPerformed(ActionEvent) actionPerformed}` method. If null, then no button will appear; but it can be added later, if desired, by using the ``addActionListener`` method.
  `owner` - The parent Frame of the dialog. This may be null.

#### Font_Selector

    public Font_Selector(String title,
                 boolean select_font,
                 boolean select_style,
                 Vector select_sizes,
                 Font default_font)

Constructs a `Font_Selector` with no "Apply" button, and using a null owner.

See Also:
  `Font_Selector(String, boolean, boolean, Vector, Font, ActionListener, Frame)`

#### Font_Selector

    public Font_Selector(String title,
                 boolean select_font,
                 boolean select_style,
                 Vector select_sizes,
                 Frame owner)

Constructs a `Font_Selector` with no "Apply" button, and using a null default font.

See Also:
  `Font_Selector(String, boolean, boolean, Vector, Font, ActionListener, Frame)`

#### Font_Selector

    public Font_Selector(String title,
                 boolean select_font,
                 boolean select_style,
                 Vector select_sizes)

Constructs a `Font_Selector` with no "Apply" button, and using a null default font and owner.

See Also:
  `Font_Selector(String, boolean, boolean, Vector, Font, ActionListener, Frame)`

#### Font_Selector

    public Font_Selector(String title,
                 Font default_font,
                 Frame owner)

Constructs a `Font_Selector` with font and style selections enabled, with no "Apply" button, and using the `DEFAULT_SIZES`.

See Also:
  `Font_Selector(String, boolean, boolean, Vector, Font, ActionListener, Frame)`

#### Font_Selector

    public Font_Selector(String title,
                 Font default_font)

Constructs a `Font_Selector` with font and style selections enabled, with no "Apply" button, and using the `DEFAULT_SIZES` and a null owner.

See Also:
  `Font_Selector(String, boolean, boolean, Vector, Font, ActionListener, Frame)`

#### Font_Selector

    public Font_Selector(String title,
                 Frame owner)

Constructs a `Font_Selector` with font and style selections enabled and using the `DEFAULT_SIZES` and a null default font.

See Also:
  `Font_Selector(String, boolean, boolean, Vector, Font, ActionListener, Frame)`

#### Font_Selector

    public Font_Selector(String title)

Constructs a `Font_Selector` with font and style selections enabled, with no "Apply" button, and using the `DEFAULT_SIZES` and a null default font and owner.

See Also:
  `Font_Selector(String, boolean, boolean, Vector, Font, ActionListener, Frame)`

#### Font_Selector

    public Font_Selector(Font default_font)

Constructs a `Font_Selector` with font and style selections enabled, with no "Apply" button, and using the `DEFAULT_SIZES` and a null title and owner.

See Also:
  `Font_Selector(String, boolean, boolean, Vector, Font, ActionListener, Frame)`

#### Font_Selector

    public Font_Selector()

Constructs a `Font_Selector` with font and style selections enabled, with no "Apply" button, and using the `DEFAULT_SIZES` and null title, default font and owner.

See Also:
  `Font_Selector(String, boolean, boolean, Vector, Font, ActionListener, Frame)`

### Method Detail

#### itemStateChanged

    public void itemStateChanged(ItemEvent event)

The method that implements the ItemListener interface to listen for list selections. This method should only be used by the dialog itself.

Specified by:
  `itemStateChanged` in interface `ItemListener`

#### Reset

    public void Reset()

Resets the current font to the original font.

#### setVisible

    public void setVisible(boolean set_visible)

Sets the dialog to be visible on the display.

Note: If no selection lists were enabled when this `Font_Selector` was constructed, then it will never become visible.

Overrides:
  `setVisible` in class `Dialog`

#### addActionListener

    public void addActionListener(ActionListener apply_listener)

Adds an `ActionListener` to the "Apply" button. If no "Apply" button is present, one is added.

Parameters:
  `apply_listener` - The `ActionListener` for the "Apply" button.

#### removeActionListener

    public void removeActionListener(ActionListener apply_listener)

Removes an `ActionListener`, if registered, from the "Apply" button, if present.

Parameters:
  `apply_listener` - The `ActionListener` to be removed from the "Apply" button.

#### getActionListeners

    public ActionListener[] getActionListeners()

Gets an array of `ActionListener`s currently registered with the "Apply" button.

Returns:
  An `ActionListener` array. This will be empty if there is no "Apply" button, or no `ActionListener` is registered with the button.

#### Font

    public Font_Selector Font(Font font)

Set the current font.

If the font has a size that is not in the size selection list, then the ``Nearest_Size`` in the selection list will be applied to the font.

Parameters:
  `font` - The Font to become the current font.
Returns:
  This Font_Selector.

#### Font

    public Font_Selector Font(String name,
                     int style,
                     int size)

Set the current font name, style and size.

The name must be an available font name.

The style must be one of the `Font` class style constants.

If the font has a size that is not in the size selection list, then the ``Nearest_Size`` in the selection list will be applied to the font.

Parameters:
  `name` - The String providing a valid font family name.
  `style` - A `Font` class style value.
  `size` - The point size for the font.
Returns:
  This Font_Selector.
See Also:
  `Font`

#### Font

    public Font Font()

Gets the current font.

Returns:
  The current Font.

#### Original_Font

    public Font Original_Font()

Gets the original font.

Returns:
  The original Font. This was the default font determined when this `Font_Selector` was constructed or when the ``Select`` method was used.

#### Font_Name

    public Font_Selector Font_Name(String name)

Sets the current font to the named family.

Parameters:
  `name` - The font family name to be applied.
Returns:
  This Font_Selector.

#### Font_Name

    public String Font_Name()

Gets the name of the current font.

Returns:
  The name of the current font.

#### Style

    public Font_Selector Style(int style)

Sets the style of the current font.

Parameters:
  `style` - A `Font` class style value.
Returns:
  This Font_Selector.

#### Style

    public int Style()

Gets the style of the current font.

Returns:
  The `Font` class style value of the current font.

#### Style_Description

    public static String Style_Description(int style)

Provides a description of a style value.

Parameters:
  `style` - A `Font` class style value.
Returns:
  A String describing the style. This will be null if the style value is invalid.

#### Size

    public Font_Selector Size(int size)

Sets the size of the current font.

Parameters:
  `size` - The font size.
Returns:
  This Font_Selector.
See Also:
  `Font(String, int, int)`

#### Size

    public int Size()

Gets the size of the current font.

Returns:
  The point size of the current font.

#### Nearest_Size

    public int Nearest_Size(int size)

Gets the size from the selection list that is nearest to a specified size.

If the size is less than the smallest selection size, then the smallest size will be returned. If the size is greater than the largest selection size, then the largest size will be returned. Otherwise the selection size nearest to the specified size, rounded up, is returned.

Parameters:
  `size` - The size to use in searching for the nearest size in the selection list.

#### Text

    public Font_Selector Text(String text)

Sets the text to be displayed in the current font.

Parameters:
  `text` - The String of text to be displayed.
Returns:
  This Font_Selector.

#### Text

    public String Text()

Gets the current sample text. The default text is:

            ABCDEFGHIJKLMNOPQRSTUVWXYZ
            abcdefghijklmnopqrstuvwxyz
            0123456789 ~!@#$%^&*()_+`-=[]\\{}|;':\"<>?,./

Returns:
  The String of sample text.

#### Select

    public Font Select(Font default_font)

Initiates a user interactive font selection.

This dialog is ``setVisible``. When the user completes the selection or closes the dialog, the current font is returned. If the "Cancel" button is pressed, then the original font is restored before the selection operation completes.

Parameters:
  `default_font` - The font to be the original, default font for the selection. If null, then the previous original font is used.
Returns:
  The Font that was selected. This will be the original font if no selection was made or the "Cancle" button was pressed.

#### Select

    public Font Select()

Initiates a `Select` operation using the previous original font.

See Also:
  `Select(Font)`

#### main

    public static void main(String[] arguments)