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.drjava.ui;
038:
039: import javax.swing.*;
040: import java.awt.event.*;
041: import java.io.Serializable;
042:
043: /** Displayed when the user chooses to save the interactions history. It will show the current history and allow the
044: * user to edit or save it to a file.
045: * $Id: HistorySaveDialog.java 4255 2007-08-28 19:17:37Z mgricken $
046: */
047: public class HistorySaveDialog extends DrJavaScrollableDialog implements
048: Serializable {
049:
050: /** Reference to the history text being edited. */
051: private String _history;
052:
053: /** Lock to ensure this history is only edited by one user at a time.
054: * TODO: Is this necessary?
055: */
056: // private Object _historyLock = new Object();
057: /** Creates a new HistorySaveDialog.
058: * @param parent Parent frame for this dialog
059: */
060: public HistorySaveDialog(JFrame parent) {
061: super (
062: parent,
063: "Save Interactions History",
064: "Make any changes to the history, and then click \"Save\".",
065: "");
066: }
067:
068: /** Creates a custom set of buttons for this panel, including Save and Cancel. */
069: protected void _addButtons() {
070: // Updates the _history field with the new contents and closes the dialog
071: Action saveAction = new AbstractAction("Save") {
072: public void actionPerformed(ActionEvent ae) {
073: _history = _textArea.getText();
074: _dialog.dispose();
075: }
076: };
077:
078: // Closes the dialog
079: Action cancelAction = new AbstractAction("Cancel") {
080: public void actionPerformed(ActionEvent ae) {
081: _dialog.dispose();
082: }
083: };
084:
085: JButton saveButton = new JButton(saveAction);
086: JButton cancelButton = new JButton(cancelAction);
087: _buttonPanel.add(saveButton);
088: _buttonPanel.add(cancelButton);
089: _dialog.getRootPane().setDefaultButton(saveButton);
090: }
091:
092: /** Shows the dialog for editing the given history.
093: * @param history History to edit
094: * @return Edited history, if it is saved. Null, if not.
095: */
096: public String editHistory(String history) {
097: // synchronized(_historyLock) {
098: _history = null; // make it null by default
099: _textArea.setText(history);
100: _textArea.setEditable(true);
101:
102: // Block until the dialog is closed
103: show();
104:
105: // The save action will set the history field
106: return _history;
107: // }
108: }
109: }
|