/*
 * @(#)BasePane.java  2.6.0  27 May 2007
 *
 * Copyright 2007
 * 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.*;

import java.awt.*;
import java.awt.font.*;

/**
 * <p>Class <code>BasePane</code> contains common font and size
 * definitions for use in certain other JPT classes.</p>
 * 
 * <p>In 2.5.0, this class was designed as a base class that
 * defined certain protected variables that could be used in a
 * derived class.  That usage is still possible.  In addition,
 * in 2.6.0, public &ldquo;get&rdquo; methods were added that
 * allow a caller access the same definitions.  Therefore, a
 * designer need not used inheritance but may simply add items
 * to this panel and use the definitions as desired.</p>
 * 
 * <p>Note that it is the responsibility of the caller to set
 * fonts for fields, labels, and buttons.  That cannot be
 * done automatically.</p>
 * 
 * <p>In 2.5.0, the font size used for the fonts was computed
 * by the formula:</p>
 * 
 * <ul>
 *   <li><code>14 + (int)LookAndFeelTools.getNetFontSizeAdjustment()</code></li>
 * </ul>
 * 
 * <p>The rationale for this formula was to start with a base
 * font size (14) and then adjust that size by whatever font
 * size adjustment was already defined via the class
 * <code>LookAndFeelTools</code>.  In this way, the usability
 * features of <code>LookAndFeelTools</code> would be taken
 * into account automatically.</p>
 * 
 * <p>In 2.6.0, the decision was made to permit the base font
 * size to be supplied in a constructor and to make 12 rather
 * than 14 be the default if no such size is supplied.</p>
 * 
 * <p>This class chooses font families using the methods in
 * class <code>Fonts</code>.</p>
 * 
 * @author  Richard Rasala
 * @version 2.6.0
 * @since   2.5.0
 * @see     Fonts
 */
public class BasePane
    extends DisplayPanel
{
    /** The default value of the base font size. */
    public static final int DEFAULT_BASE_FONT_SIZE = 12;
    
    /**
     * The minimum value permitted for the common font size
     * regardless of other settings.
     */
    public static final int MINIMUM_FONT_SIZE = 8;
    
    
    /** The monospaced font name from class <code>Fonts</code>. */
    protected String monospacedFontName =
        Fonts.getMonospacedFontFamilyName();
    
    /** The serif font name from class <code>Fonts</code>. */
    protected String serifFontName =
        Fonts.getSerifFontFamilyName();
    
    /** The sans serif font name from class <code>Fonts</code>. */
    protected String sansserifFontName =
        Fonts.getSansSerifFontFamilyName();
    
    
    /**
     * The base font size which either defaults to 12 or
     * is supplied in the constructor.
     */
    protected int baseFontSize = DEFAULT_BASE_FONT_SIZE;
    
    /**
     * <p>The common font size for fields, labels, and buttons.</p>
     * 
     * <p>This font size is computed as the base font size plus
     * the net font size adjustment from <code>LookAndFeelTools</code>.
     * The resulting font size will be forced to be at least as
     * big as <code>MINIMUM_FONT_SIZE</code>.</p>
     */
    protected int fontSize = DEFAULT_BASE_FONT_SIZE;
    
    
    /**
     * The field font uses the monospaced font
     * with BOLD style in the common font size.
     */
    protected Font fieldFont = null;
    
    /**
     * The label font uses the serif font
     * with BOLD style in the common font size.
     */
    protected Font labelFont = null;
    
    /**
     * The button font uses the sans serif font
     * with BOLD style in the common font size.
     */
    protected Font buttonFont = null;
    
    
    /**
     * The small field width is the width of 20 characters in
     * the field font.
     */
    protected int smallFieldWidth = 100;
    
    /**
     * The medium field width is 2 times the small field width.
     */
    protected int mediumFieldWidth = 200;
    
    /**
     * The large field width is 3 times the small field width.
     */
    protected int largeFieldWidth = 300;
    
    
    /** The recommend common gap for use in table panels. */
    protected int gap = 6;
    
    
    /**
     * <p>The default constructor that assumes a base font size
     * of 12.<p>
     */
    public BasePane() {
        initializeBasePane();
    }
    
    
    /**
     * <p>The constructor that permits the base font size to be
     * supplied by the caller.</p>
     * 
     * @param baseFontSize the desired base font size
     */
    public BasePane(int baseFontSize) {
        this.baseFontSize = baseFontSize;
        initializeBasePane();
    }
    
    
    /** Returns the common font size. */
    public int getFontSize() {
        return fontSize;
    }
    
    
    /** Returns the recommended field font. */
    public Font getFieldFont() {
        return fieldFont;
    }
    
    
    /** Returns the recommended label font. */
    public Font getLabelFont() {
        return labelFont;
    }
    
    
    /** Returns the recommended button font. */
    public Font getButtonFont() {
        return buttonFont;
    }
    
    
    /** Returns the recommended small field width. */
    public int getSmallFieldWidth() {
        return smallFieldWidth;
    }
    
    
    /** Returns the recommended medium field width. */
    public int getMediumFieldWidth() {
        return mediumFieldWidth;
    }
    
    
    /** Returns the recommended large field width. */
    public int getLargeFieldWidth() {
        return largeFieldWidth;
    }
    
    
    /** Returns the recommended table panel gap. */
    public int getGap() {
        return gap;
    }
    
    
    /**
     * <p>The common initialization code for both constructors.</p>
     */
    protected void initializeBasePane() {
        fontSize =
            baseFontSize + (int)LookAndFeelTools.getNetFontSizeAdjustment();
        
        if (fontSize < MINIMUM_FONT_SIZE)
            fontSize = MINIMUM_FONT_SIZE;
        
        fieldFont =
            new Font(monospacedFontName, Font.BOLD, fontSize);
        
        labelFont =
            new Font(serifFontName, Font.BOLD, fontSize);
        
        buttonFont =
            new Font(sansserifFontName, Font.BOLD, fontSize);
        
        smallFieldWidth =
            TextFieldView.getSampleWidth
                (fieldFont, Strings.suffixRepeatChar("", ' ', 20));
        
        mediumFieldWidth = 2 * smallFieldWidth;
        
        largeFieldWidth  = 3 * smallFieldWidth;
    }
    
}

