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