001: /*BEGIN_COPYRIGHT_BLOCK
002: *
003: * Copyright (c) 2001-2007, JavaPLT group at Rice University (javaplt@rice.edu)
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are met:
008: * * Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: * * Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
014: * names of its contributors may be used to endorse or promote products
015: * derived from this software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
018: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
019: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
020: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
021: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
023: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
024: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: *
029: * This software is Open Source Initiative approved Open Source Software.
030: * Open Source Initative Approved is a trademark of the Open Source Initiative.
031: *
032: * This file is part of DrJava. Download the current version of this project
033: * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
034: *
035: * END_COPYRIGHT_BLOCK*/
036:
037: package edu.rice.cs.util.swing;
038:
039: import edu.rice.cs.drjava.ui.MainFrame;
040: import javax.swing.*;
041:
042: /**
043: * Simple class wrapping JOptionPane to have a checkbox underneath the message.
044: * @version $Id: ConfirmCheckBoxDialog.java 4255 2007-08-28 19:17:37Z mgricken $
045: */
046: public class ConfirmCheckBoxDialog {
047: private JDialog _dialog;
048: private JOptionPane _optionPane;
049: private JCheckBox _checkBox;
050:
051: /** Instantiates a new confirm dialog with default checkbox text.
052: * @param parent the parent frame
053: * @param title the title of the dialog
054: * @param message the stuff to display in the body of the dialog. For a simple message, it should be a String; it can
055: * also be an Object[] including Strings and Components to display in the body of the dialog.
056: */
057: public ConfirmCheckBoxDialog(JFrame parent, String title,
058: Object message) {
059: this (parent, title, message, "Do not show this message again");
060: }
061:
062: /** Instantiates a new confirm dialog with Yes/No as the options.
063: * @param parent the parent frame
064: * @param title the title of the dialog
065: * @param message the stuff to display in the body of the dialog. For a simple message, it should be a String; it can
066: * also be an Object[] including Strings and Components to display in the body of the dialog.
067: * @param checkBoxText the text to display with the checkbox
068: */
069: public ConfirmCheckBoxDialog(JFrame parent, String title,
070: Object message, String checkBoxText) {
071: this (parent, title, message, checkBoxText,
072: JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
073: }
074:
075: /** Instantiates a new confirm dialog with Yes/No as the options.
076: * @param parent The parent frame
077: * @param title The title of the dialog
078: * @param message The stuff to display in the body of the dialog. For a simple message, it should be a String; it can
079: * also be an Object[] including Strings and Components to display in the body of the dialog.
080: * @param checkBoxText The text to display with the checkbox
081: * @param messageType The JOptionPane message type
082: * @param optionType The JOptionPane option type
083: */
084: public ConfirmCheckBoxDialog(JFrame parent, String title,
085: Object message, String checkBoxText, int messageType,
086: int optionType) {
087: _optionPane = new JOptionPane(message, messageType, optionType);
088: JPanel checkBoxPane = new JPanel();
089: checkBoxPane.add(_initCheckBox(checkBoxText));
090: _optionPane.add(checkBoxPane, 1);
091: _dialog = _optionPane.createDialog(parent, title);
092: }
093:
094: /** Initializes the JCheckBox to have the given text. */
095: private JCheckBox _initCheckBox(String text) {
096: _checkBox = new JCheckBox(text);
097: return _checkBox;
098: }
099:
100: /** Shows the dialog.
101: * @return the JOptionPane result of showing the dialog.
102: */
103: public int show() {
104: MainFrame.setPopupLoc(_dialog, _dialog.getOwner());
105: _dialog.setVisible(true);
106:
107: Object val = _optionPane.getValue();
108: if (val == null || !(val instanceof Integer)) {
109: return JOptionPane.CLOSED_OPTION;
110: }
111: return ((Integer) val).intValue();
112: }
113:
114: /**
115: * Gets the selected value of the check box. Should not be called until
116: * the dialog is shown.
117: * @return the value of the checkbox
118: */
119: public boolean getCheckBoxValue() {
120: return _checkBox.isSelected();
121: }
122: }
|