01: /*
02: * CloseBufferConfirmationDialog.java
03: *
04: * Copyright (C) 1998-2002 Peter Graves
05: * $Id: CloseBufferConfirmationDialog.java,v 1.1.1.1 2002/09/24 16:07:45 piso Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: */
21:
22: package org.armedbear.j;
23:
24: public final class CloseBufferConfirmationDialog extends ConfirmDialog {
25: private final Editor editor;
26: private final Buffer buffer;
27:
28: private boolean confirmed;
29:
30: public static boolean confirmClose(Editor editor, Buffer buffer) {
31: CloseBufferConfirmationDialog d = new CloseBufferConfirmationDialog(
32: editor, buffer);
33: d.show();
34: return d.confirmed();
35: }
36:
37: private CloseBufferConfirmationDialog(Editor editor, Buffer buffer) {
38: super (editor);
39: this .editor = editor;
40: this .buffer = buffer;
41: // Show cancel button.
42: cancel = true;
43: FastStringBuffer sb = new FastStringBuffer(buffer.getFile()
44: .getName());
45: sb
46: .append(" is modified. Do you want to save your changes before closing the buffer?");
47: initialize(Utilities.wrap(sb.toString(), 65, 8), "Close Buffer");
48: editor.setDefaultCursor();
49: centerDialog();
50: }
51:
52: private boolean confirmed() {
53: return confirmed;
54: }
55:
56: // Save the changes.
57: protected void yes() {
58: setVisible(false);
59: editor.save(buffer);
60: if (!buffer.isModified()) {
61: confirmed = true;
62: dispose();
63: return;
64: }
65: // Save failed.
66: setVisible(true);
67: }
68:
69: // Don't save the changes.
70: protected void no() {
71: confirmed = true;
72: dispose();
73: }
74:
75: protected void cancel() {
76: cancelled = true;
77: dispose();
78: }
79: }
|