FontChooserDialog.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* ========================================================================
  2. * JCommon : a free general purpose class library for the Java(tm) platform
  3. * ========================================================================
  4. *
  5. * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
  6. *
  7. * Project Info: http://www.jfree.org/jcommon/index.html
  8. *
  9. * This library is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU Lesser General Public License as published by
  11. * the Free Software Foundation; either version 2.1 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  16. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  17. * License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  22. * USA.
  23. *
  24. * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  25. * in the United States and other countries.]
  26. *
  27. * ----------------------
  28. * FontChooserDialog.java
  29. * ----------------------
  30. * (C) Copyright 2000-2004, by Object Refinery Limited.
  31. *
  32. * Original Author: David Gilbert (for Object Refinery Limited);
  33. * Contributor(s): -;
  34. *
  35. * $Id: FontChooserDialog.java,v 1.5 2007/11/02 17:50:36 taqua Exp $
  36. *
  37. * Changes (from 26-Oct-2001)
  38. * --------------------------
  39. * 26-Oct-2001 : Changed package to com.jrefinery.ui.*;
  40. * 14-Oct-2002 : Fixed errors reported by Checkstyle (DG);
  41. *
  42. */
  43. package org.jfree.ui;
  44. import java.awt.BorderLayout;
  45. import java.awt.Dialog;
  46. import java.awt.Font;
  47. import java.awt.Frame;
  48. import javax.swing.BorderFactory;
  49. import javax.swing.JPanel;
  50. /**
  51. * A dialog for choosing a font from the available system fonts.
  52. *
  53. * @author David Gilbert
  54. */
  55. public class FontChooserDialog extends StandardDialog {
  56. /** The panel within the dialog that contains the font selection controls. */
  57. private FontChooserPanel fontChooserPanel;
  58. /**
  59. * Standard constructor - builds a font chooser dialog owned by another dialog.
  60. *
  61. * @param owner the dialog that 'owns' this dialog.
  62. * @param title the title for the dialog.
  63. * @param modal a boolean that indicates whether or not the dialog is modal.
  64. * @param font the initial font displayed.
  65. */
  66. public FontChooserDialog(final Dialog owner, final String title, final boolean modal, final Font font) {
  67. super(owner, title, modal);
  68. setContentPane(createContent(font));
  69. }
  70. /**
  71. * Standard constructor - builds a font chooser dialog owned by a frame.
  72. *
  73. * @param owner the frame that 'owns' this dialog.
  74. * @param title the title for the dialog.
  75. * @param modal a boolean that indicates whether or not the dialog is modal.
  76. * @param font the initial font displayed.
  77. */
  78. public FontChooserDialog(final Frame owner, final String title, final boolean modal, final Font font) {
  79. super(owner, title, modal);
  80. setContentPane(createContent(font));
  81. }
  82. /**
  83. * Returns the selected font.
  84. *
  85. * @return the font.
  86. */
  87. public Font getSelectedFont() {
  88. return this.fontChooserPanel.getSelectedFont();
  89. }
  90. /**
  91. * Returns the panel that is the user interface.
  92. *
  93. * @param font the font.
  94. *
  95. * @return the panel.
  96. */
  97. private JPanel createContent(Font font) {
  98. final JPanel content = new JPanel(new BorderLayout());
  99. content.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
  100. if (font == null) {
  101. font = new Font("Dialog", 10, Font.PLAIN);
  102. }
  103. this.fontChooserPanel = new FontChooserPanel(font);
  104. content.add(this.fontChooserPanel);
  105. final JPanel buttons = createButtonPanel();
  106. buttons.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0));
  107. content.add(buttons, BorderLayout.SOUTH);
  108. return content;
  109. }
  110. }