fwpUtil
Class FontAndColorChooser


 

public class FontAndColorChooser
extends javax.swing.JDialog
implements java.awt.event.ActionListener
Title: Font and color chooser dialog.

Description: Displays a dialog in which the user can select a font and its color, bold, italic and transparency attributes.

Copyright: Copyright (c) 2011

Version:
1.0 - 2011
Author:
Fred Pospeschil - This file is placed in the public domain and can be used and adapted without restrictions. The user of the code is totally responsible for insuring its suitability in the intended application.

This dialog is an adaptation of the font chooser presented in Java Swing by Robert Eckstein, Marc Loy & Dave Wood, O'Reilly, Sebastopol, CA 1998, ISBN 1-56592-455-X. See pages 381-387. The fixed list of fonts approach used by the O'Reilly example was replaced by the more general getting a list of all available fonts as described on pages 788-791 of Java for Dummies by Doug Lowe and Barry Burd, Wiley Publishing, Inc. 2007.

NOTE: This JavaDoc file was post processed with Microsoft FrontPage and regenerating the file will cause the graphics and format changes to be lost.

Constructor Detail

FontAndColorChooser

public FontAndColorChooser(java.awt.Frame parent)
Displays a dialog in which the user can select a font and its color, bold, italic and transparancy attributes.

If a Frame, or Frame subclass, is avialable call with:
FontAndColorChooser fc = new FontAndColorChooser(this, true/false);

If a Frame, or Frame subclass, is not avialable call with:
FontAndColorChooser fc = new FontAndColorChooser(null, true/false);

If a frame is provided, the dialog is centered over that frame. Otherwise, the dialog is positioned 20 pixels down and to the right of the upper left corner of the display screen.

If the user presses the Cancel button all of the getter methods will return null. If the user presses the OK button without selecting a color or font the getFont will return a color of black (r=0,g=0,b=0) and getFont will return a system default font such as:

javax.swing.plaf.FontUIResource[family=Tahoma,name=Tahoma,style=plain,size=13]

Example usage:
FontAndColorChooser fc = new FontAndColorChooser(this);
Font font = fc.getNewFont();
Color color = fc.getNewColor();
AttributeSet atts = fc.getAttributes();
System.out.println("F&C -toString = " + fc.toString());

Parameters:
parent - The Frame, or subclass, from which the dialog was called.

Method Detail

getNewColor

public java.awt.Color getNewColor()
Returns the color and transparency settings which were selected by the user.
Returns:
Color object

getNewFont

public java.awt.Font getNewFont()
Returns the font, bold and italic settings selected by the user.
Returns:
Font object

getAttributes

public javax.swing.text.AttributeSet getAttributes()
Returns the font attribute set.
Returns:
The font attribute set.

toString

public java.lang.String toString()
Gets the font attribute set.
Returns:
The font attribute set. For example:

Font=java.awt.Font[family=AR BERKLEY,name=AR BERKLEY,style=bolditalic,size=12] newColor=java.awt.Color[r=255,g=0,b=0] Attributes+bold=true italic=true family=AR BERKLEY