/*
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License");  you may not use this file except in 
 * compliance with the License.  You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 *
 * The Original Code is Protege-2000.
 *
 * The Initial Developer of the Original Code is Stanford University. Portions
 * created by Stanford University are Copyright (C) 2007.  All Rights Reserved.
 *
 * Protege was developed by Stanford Medical Informatics
 * (http://www.smi.stanford.edu) at the Stanford University School of Medicine
 * with support from the National Library of Medicine, the National Science
 * Foundation, and the Defense Advanced Research Projects Agency.  Current
 * information about Protege can be obtained at http://protege.stanford.edu.
 *
 */

package edu.stanford.smi.protege.action;

import java.awt.*;

import javax.swing.*;

import edu.stanford.smi.protege.resource.*;
import edu.stanford.smi.protege.ui.*;
import edu.stanford.smi.protege.util.*;

/**
 *  Base class for any action to change the application font sizes.
 *
 * @author    Ray Fergerson <fergerson@smi.stanford.edu>
 */
public abstract class FontAction extends StandardAction {

    protected FontAction(ResourceKey text) {
        super(text);
    }

    protected static void changeSize(int delta) {
        changeSize("Tree.font", delta);
        changeSize("Label.font", delta);
        changeSize("Table.font", delta);
        changeSize("Button.font", delta);
        changeSize("MenuBar.font", delta);
        changeSize("Menu.font", delta);
        changeSize("MenuItem.font", delta);
        changeSize("PopupMenu.font", delta);
        changeSize("RadioButtonMenuItem.font", delta);
        changeSize("CheckBoxMenuItem.font", delta);
        changeSize("List.font", delta);
        changeSize("TextField.font", delta);
        changeSize("TextArea.font", delta);
        changeSize("CheckBox.font", delta);
        changeSize("TableHeader.font", delta);
        changeSize("TabbedPane.font", delta);
        changeSize("RadioButton.font", delta);
        changeSize("ToolTip.font", delta);
        changeSize("OptionPane.font", delta);

        ProjectManager.getProjectManager().reloadUI(true);
    }

    private static void changeSize(String key, int delta) {
        Font oldFont = UIManager.getFont(key);
        Font newFont = new Font(oldFont.getName(), oldFont.getStyle(), oldFont.getSize() + delta);
        UIManager.put(key, newFont);
    }
}
