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 * StandardDialog.java 029 * ------------------- 030 * (C) Copyright 2000-2004, by Object Refinery Limited. 031 * 032 * Original Author: David Gilbert (for Object Refinery Limited); 033 * Contributor(s): Arnaud Lelievre; 034 * 035 * $Id: StandardDialog.java,v 1.5 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 * 08-Sep-2003 : Added internationalization via use of properties resourceBundle (RFE 690236) (AL); 041 * 042 */ 043 044package org.jfree.ui; 045 046import java.awt.Dialog; 047import java.awt.Frame; 048import java.awt.event.ActionEvent; 049import java.awt.event.ActionListener; 050import java.util.ResourceBundle; 051 052import javax.swing.BorderFactory; 053import javax.swing.JButton; 054import javax.swing.JDialog; 055import javax.swing.JPanel; 056 057/** 058 * The base class for standard dialogs. 059 * 060 * @author David Gilbert 061 */ 062public class StandardDialog extends JDialog implements ActionListener { 063 064 /** Flag that indicates whether or not the dialog was cancelled. */ 065 private boolean cancelled; 066 067 /** The resourceBundle for the localization. */ 068 protected static final ResourceBundle localizationResources = 069 ResourceBundle.getBundle("org.jfree.ui.LocalizationBundle"); 070 071 /** 072 * Standard constructor - builds a dialog... 073 * 074 * @param owner the owner. 075 * @param title the title. 076 * @param modal modal? 077 */ 078 public StandardDialog(final Frame owner, final String title, final boolean modal) { 079 super(owner, title, modal); 080 this.cancelled = false; 081 } 082 083 /** 084 * Standard constructor - builds a dialog... 085 * 086 * @param owner the owner. 087 * @param title the title. 088 * @param modal modal? 089 */ 090 public StandardDialog(final Dialog owner, final String title, final boolean modal) { 091 super(owner, title, modal); 092 this.cancelled = false; 093 } 094 095 /** 096 * Returns a flag that indicates whether or not the dialog has been cancelled. 097 * 098 * @return boolean. 099 */ 100 public boolean isCancelled() { 101 return this.cancelled; 102 } 103 104 /** 105 * Handles clicks on the standard buttons. 106 * 107 * @param event the event. 108 */ 109 public void actionPerformed(final ActionEvent event) { 110 final String command = event.getActionCommand(); 111 if (command.equals("helpButton")) { 112 // display help information 113 } 114 else if (command.equals("okButton")) { 115 this.cancelled = false; 116 setVisible(false); 117 } 118 else if (command.equals("cancelButton")) { 119 this.cancelled = true; 120 setVisible(false); 121 } 122 } 123 124 /** 125 * Builds and returns the user interface for the dialog. This method is shared among the 126 * constructors. 127 * 128 * @return the button panel. 129 */ 130 protected JPanel createButtonPanel() { 131 132 final L1R2ButtonPanel buttons = new L1R2ButtonPanel(localizationResources.getString("Help"), 133 localizationResources.getString("OK"), 134 localizationResources.getString("Cancel")); 135 136 final JButton helpButton = buttons.getLeftButton(); 137 helpButton.setActionCommand("helpButton"); 138 helpButton.addActionListener(this); 139 140 final JButton okButton = buttons.getRightButton1(); 141 okButton.setActionCommand("okButton"); 142 okButton.addActionListener(this); 143 144 final JButton cancelButton = buttons.getRightButton2(); 145 cancelButton.setActionCommand("cancelButton"); 146 cancelButton.addActionListener(this); 147 148 buttons.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0)); 149 return buttons; 150 } 151 152}