/*
 * @(#)Fonts.java  2.5.0  1 September 2006
 *
 * Copyright 2006
 * College of Computer and Information Science
 * Northeastern University
 * Boston, MA  02115
 *
 * The Java Power Tools software may be used for educational
 * purposes as long as this copyright notice is retained intact
 * at the top of all source files.
 *
 * To discuss possible commercial use of this software, 
 * contact Richard Rasala at Northeastern University, 
 * College of Computer and Information Science,
 * 617-373-2462 or rasala@ccs.neu.edu.
 *
 * The Java Power Tools software has been designed and built
 * in collaboration with Viera Proulx and Jeff Raab.
 *
 * Should this software be modified, the words "Modified from 
 * Original" must be included as a comment below this notice.
 *
 * All publication rights are retained.  This software or its 
 * documentation may not be published in any media either
 * in whole or in part without explicit permission.
 *
 * This software was created with support from Northeastern 
 * University and from NSF grant DUE-9950829.
 */

package edu.neu.ccs.gui;

import edu.neu.ccs.quick.*;

import java.awt.*;
import java.awt.font.*;

/**
 * <p>Class <code>Fonts</code> contains a static method that
 * returns a hash set with all installed font family names
 * and also some static methods that select a particular
 * font name from each of the following categories:
 * monospaced, serif, sanserif.</p>
 * 
 * <p>This class cannot be instantiated.</p>
 * 
 * @author Richard Rasala
 * @version 2.5.0
 */
public class Fonts {
    
    /** Prevent instantiation. */
    private Fonts() {}
    
    
    /**
     * <p>Returns a hash set that contains the available
     * font family names for fonts installed on this system.</p>
     */
    public static QuickHashSet getFontFamilyNames() {
        GraphicsEnvironment ge =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
        
        String[] fontFamilyNameList =
            ge.getAvailableFontFamilyNames();
        
        return new QuickHashSet(fontFamilyNameList);
    }
    
    
    /**
     * <p>Returns the font family name of a monospaced font
     * that is installed on this system.</p>
     * 
     * <p>Returns the same font family name as the method
     * of the same name in <code>ConsoleGateway</code>.</p>
     * 
     * <p>The order of the names tested as of 2.5.0 is:</p>
     * 
     * <ul>
     *   <li>Lucida Console</li>
     *   <li>Lucida Sans Typewriter</li>
     *   <li>Andale Mono</li>
     *   <li>Courier New</li>
     *   <li>Consolas</li>
     *   <li>Monospaced</li>
     *   <li>monospaced</li>
     * </ul>
     * 
     * <p>The first font name that is found is returned.</p>
     */
    public static String getMonospacedFontFamilyName() {
        QuickHashSet familyNameHash = getFontFamilyNames();
        
        String fontFamilyName = "";
        
        if (familyNameHash.contains("Lucida Console"))
            fontFamilyName = "Lucida Console";
        else
        if (familyNameHash.contains("Lucida Sans Typewriter"))
            fontFamilyName = "Lucida Sans Typewriter";
        else
        if (familyNameHash.contains("Andale Mono"))
            fontFamilyName = "Andale Mono";
        else
        if (familyNameHash.contains("Courier New"))
            fontFamilyName = "Courier New";
        else
        if (familyNameHash.contains("Consolas"))
            fontFamilyName = "Consolas";
        else
        if (familyNameHash.contains("Monospaced"))
            fontFamilyName = "Monospaced";
        else
            fontFamilyName = "monospaced";
        
        return fontFamilyName;
    }
    
    
    /**
     * <p>Returns the font family name of a serif font
     * that is installed on this system.</p>
     * 
     * <p>The order of the names tested as of 2.5.0 is:</p>
     * 
     * <ul>
     *   <li>Century Schoolbook</li>
     *   <li>New Century Schoolbook</li>
     *   <li>Palatino</li>
     *   <li>Book Antiqua</li>
     *   <li>Goudy Old Style</li>
     *   <li>Bookman Old Style</li>
     *   <li>Constantia</li>
     *   <li>Times New Roman</li>
     *   <li>Serif</li>
     *   <li>serif</li>
     * </ul>
     * 
     * <p>The first font name that is found is returned.</p>
     */
    public static String getSerifFontFamilyName() {
        QuickHashSet familyNameHash = getFontFamilyNames();
        
        String fontFamilyName = "";
        
        if (familyNameHash.contains("Century Schoolbook"))
            fontFamilyName = "Century Schoolbook";
        else
        if (familyNameHash.contains("New Century Schoolbook"))
            fontFamilyName = "New Century Schoolbook";
        else
        if (familyNameHash.contains("Palatino"))
            fontFamilyName = "Palatino";
        else
        if (familyNameHash.contains("Book Antiqua"))
            fontFamilyName = "Book Antiqua";
        else
        if (familyNameHash.contains("Goudy Old Style"))
            fontFamilyName = "Goudy Old Style";
        else
        if (familyNameHash.contains("Bookman Old Style"))
            fontFamilyName = "Bookman Old Style";
        else
        if (familyNameHash.contains("Constantia"))
            fontFamilyName = "Constantia";
        else
        if (familyNameHash.contains("Times New Roman"))
            fontFamilyName = "Times New Roman";
        else
        if (familyNameHash.contains("Serif"))
            fontFamilyName = "Serif";
        else
            fontFamilyName = "serif";
        
        return fontFamilyName;
    }
    
    
    /**
     * <p>Returns the font family name of a sans-serif font
     * that is installed on this system.</p>
     * 
     * <p>The order of the names tested as of 2.5.0 is:</p>
     * 
     * <ul>
     *   <li>Verdana</li>
     *   <li>Calibri</li>
     *   <li>Univers</li>
     *   <li>Lucida Sans</li>
     *   <li>Helvetica</li>
     *   <li>Arial</li>
     *   <li>SansSerif</li>
     *   <li>sansserif</li>
     * </ul>
     * 
     * <p>The first font name that is found is returned.</p>
     */
    public static String getSansSerifFontFamilyName() {
        QuickHashSet familyNameHash = getFontFamilyNames();
        
        String fontFamilyName = "";
        
        if (familyNameHash.contains("Verdana"))
            fontFamilyName = "Verdana";
        else
        if (familyNameHash.contains("Calibri"))
            fontFamilyName = "Calibri";
        else
        if (familyNameHash.contains("Univers"))
            fontFamilyName = "Univers";
        else
        if (familyNameHash.contains("Lucida Sans"))
            fontFamilyName = "Lucida Sans";
        else
        if (familyNameHash.contains("Helvetica"))
            fontFamilyName = "Helvetica";
        else
        if (familyNameHash.contains("Arial"))
            fontFamilyName = "Arial";
        else
        if (familyNameHash.contains("SansSerif"))
            fontFamilyName = "SansSerif";
        else
            fontFamilyName = "sansserif";
        
        return fontFamilyName;
    }
    
}

