001    /* ========================================================================
002     * JCommon : a free general purpose class library for the Java(tm) platform
003     * ========================================================================
004     *
005     * (C) Copyright 2000-2004, by Object Refinery Limited and Contributors.
006     *
007     * Project Info:  http://www.jfree.org/jcommon/index.html
008     *
009     * This library is free software; you can redistribute it and/or modify it under the terms
010     * of the GNU Lesser General Public License as published by the Free Software Foundation;
011     * either version 2.1 of the License, or (at your option) any later version.
012     *
013     * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
014     * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
015     * See the GNU Lesser General Public License for more details.
016     *
017     * You should have received a copy of the GNU Lesser General Public License along with this
018     * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
019     * Boston, MA 02111-1307, USA.
020     *
021     * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
022     * in the United States and other countries.]
023     *
024     * ----------------------
025     * FontChooserDialog.java
026     * ----------------------
027     * (C) Copyright 2000-2004, by Object Refinery Limited.
028     *
029     * Original Author:  David Gilbert (for Object Refinery Limited);
030     * Contributor(s):   -;
031     *
032     * $Id: FontChooserDialog.java,v 1.7 2004/04/26 19:15:44 taqua Exp $
033     *
034     * Changes (from 26-Oct-2001)
035     * --------------------------
036     * 26-Oct-2001 : Changed package to com.jrefinery.ui.*;
037     * 14-Oct-2002 : Fixed errors reported by Checkstyle (DG);
038     *
039     */
040    
041    package org.jfree.ui;
042    
043    import java.awt.*;
044    
045    import javax.swing.*;
046    
047    /**
048     * A dialog for choosing a font from the available system fonts.
049     *
050     */
051    public class FontChooserDialog extends StandardDialog {
052    
053        /** The panel within the dialog that contains the font selection controls. */
054        private FontChooserPanel fontChooserPanel;
055    
056        /**
057         * Standard constructor - builds a font chooser dialog owned by another dialog.
058         *
059         * @param owner  the dialog that 'owns' this dialog.
060         * @param title  the title for the dialog.
061         * @param modal  a boolean that indicates whether or not the dialog is modal.
062         * @param font  the initial font displayed.
063         */
064        public FontChooserDialog(final Dialog owner, final String title, final boolean modal, final Font font) {
065            super(owner, title, modal);
066            setContentPane(createContent(font));
067        }
068    
069        /**
070         * Standard constructor - builds a font chooser dialog owned by a frame.
071         *
072         * @param owner  the frame that 'owns' this dialog.
073         * @param title  the title for the dialog.
074         * @param modal  a boolean that indicates whether or not the dialog is modal.
075         * @param font  the initial font displayed.
076         */
077        public FontChooserDialog(final Frame owner, final String title, final boolean modal, final Font font) {
078            super(owner, title, modal);
079            setContentPane(createContent(font));
080        }
081    
082        /**
083         * Returns the selected font.
084         *
085         * @return the font.
086         */
087        public Font getSelectedFont() {
088            return this.fontChooserPanel.getSelectedFont();
089        }
090    
091        /**
092         * Returns the panel that is the user interface.
093         *
094         * @param font  the font.
095         *
096         * @return the panel.
097         */
098        private JPanel createContent(Font font) {
099            final JPanel content = new JPanel(new BorderLayout());
100            content.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
101            if (font == null) {
102                font = new Font("Dialog", 10, Font.PLAIN);
103            }
104            this.fontChooserPanel = new FontChooserPanel(font);
105            content.add(this.fontChooserPanel);
106    
107            final JPanel buttons = createButtonPanel();
108            buttons.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0));
109            content.add(buttons, BorderLayout.SOUTH);
110    
111                    setSize( new Dimension( 550, 400 ) );
112    
113            return content;
114        }
115    
116    }