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.BorderLayout;
044 import java.awt.Dialog;
045 import java.awt.Dimension;
046 import java.awt.Font;
047 import java.awt.Frame;
048
049 import javax.swing.BorderFactory;
050 import javax.swing.JPanel;
051
052 /**
053 * A dialog for choosing a font from the available system fonts.
054 *
055 */
056 public class FontChooserDialog extends StandardDialog {
057
058 /** The panel within the dialog that contains the font selection controls. */
059 private FontChooserPanel fontChooserPanel;
060
061 /**
062 * Standard constructor - builds a font chooser dialog owned by another
063 * dialog.
064 *
065 * @param owner
066 * the dialog that 'owns' this dialog.
067 * @param title
068 * the title for the dialog.
069 * @param modal
070 * a boolean that indicates whether or not the dialog is modal.
071 * @param font
072 * the initial font displayed.
073 */
074 public FontChooserDialog(final Dialog owner, final String title,
075 final boolean modal, final Font font) {
076 super(owner, title, modal);
077 setContentPane(createContent(font));
078 }
079
080 /**
081 * Standard constructor - builds a font chooser dialog owned by a frame.
082 *
083 * @param owner
084 * the frame that 'owns' this dialog.
085 * @param title
086 * the title for the dialog.
087 * @param modal
088 * a boolean that indicates whether or not the dialog is modal.
089 * @param font
090 * the initial font displayed.
091 */
092 public FontChooserDialog(final Frame owner, final String title,
093 final boolean modal, final Font font) {
094 super(owner, title, modal);
095 setContentPane(createContent(font));
096 }
097
098 /**
099 * Returns the selected font.
100 *
101 * @return the font.
102 */
103 public Font getSelectedFont() {
104 return this.fontChooserPanel.getSelectedFont();
105 }
106
107 /**
108 * Returns the panel that is the user interface.
109 *
110 * @param font
111 * the font.
112 *
113 * @return the panel.
114 */
115 private JPanel createContent(Font font) {
116 final JPanel content = new JPanel(new BorderLayout());
117 content.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
118 if (font == null) {
119 font = new Font("Dialog", 10, Font.PLAIN);
120 }
121 this.fontChooserPanel = new FontChooserPanel(font);
122 content.add(this.fontChooserPanel);
123
124 final JPanel buttons = createButtonPanel();
125 buttons.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0));
126 content.add(buttons, BorderLayout.SOUTH);
127
128 setSize(new Dimension(550, 400));
129
130 return content;
131 }
132
133 }