01: // QuestionPopup.java
02: // $Id: QuestionPopup.java,v 1.2 2000/08/16 21:37:57 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1998.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.tools.widgets;
07:
08: import java.awt.Button;
09: import java.awt.Container;
10: import java.awt.Dialog;
11: import java.awt.FlowLayout;
12: import java.awt.Frame;
13: import java.awt.Label;
14: import java.awt.Panel;
15: import java.awt.Window;
16:
17: import java.awt.event.ActionEvent;
18: import java.awt.event.ActionListener;
19:
20: /**
21: * @version $Revision: 1.2 $
22: * @author Benoît Mahé (bmahe@w3.org)
23: */
24: public class QuestionPopup extends Dialog implements ActionListener {
25:
26: protected Button yesB = null;
27: protected Button noB = null;
28:
29: protected final static String defaultYesMsg = "Yes";
30: protected final static String defaultNoMsg = "No";
31: protected final static String defaultTitle = "Question";
32:
33: protected AnswerListener answerListener = null;
34:
35: public void registerAnswerListener(AnswerListener listener) {
36: answerListener = listener;
37: }
38:
39: /**
40: * ActionListsner implementation - One of our button was fired.
41: * @param evt The ActionEvent.
42: */
43:
44: public void actionPerformed(ActionEvent evt) {
45: if (answerListener != null) {
46: String command = evt.getActionCommand();
47: if (command.equals("yes"))
48: answerListener.questionAnswered(this ,
49: answerListener.YES);
50: else if (command.equals("no"))
51: answerListener
52: .questionAnswered(this , answerListener.NO);
53: }
54: }
55:
56: public QuestionPopup(Frame parent, String question) {
57: this (parent, defaultTitle, question, defaultYesMsg,
58: defaultNoMsg, true);
59: }
60:
61: public QuestionPopup(Frame parent, String question, boolean modal) {
62: this (parent, defaultTitle, question, defaultYesMsg,
63: defaultNoMsg, modal);
64: }
65:
66: public QuestionPopup(Frame parent, String title, String question,
67: boolean modal) {
68: this (parent, title, question, defaultYesMsg, defaultNoMsg,
69: modal);
70: }
71:
72: public QuestionPopup(Frame parent, String title, String question,
73: String yes, String no, boolean modal) {
74: super (parent, title, modal);
75: Button yesB = new Button(yes);
76: yesB.setActionCommand("yes");
77: yesB.addActionListener(this );
78: Button noB = new Button(no);
79: noB.addActionListener(this );
80: noB.setActionCommand("no");
81: Label questionL = new Label(question);
82:
83: Panel pq = new Panel();
84: pq.add(questionL);
85:
86: BorderPanel pb = new BorderPanel(BorderPanel.IN, 2);
87: pb.setLayout(new FlowLayout());
88: pb.add(yesB);
89: pb.add(noB);
90:
91: add(pq, "Center");
92: add(pb, "South");
93: pack();
94: }
95:
96: }
|