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