--- /dev/null
+// QuestionPopup.java\r
+// $Id: QuestionPopup.java,v 1.1 2010/06/15 12:20:38 smhuang Exp $\r
+// (c) COPYRIGHT MIT and INRIA, 1998.\r
+// Please first read the full copyright statement in file COPYRIGHT.html\r
+\r
+package org.w3c.tools.widgets;\r
+\r
+import java.awt.Button;\r
+import java.awt.Container;\r
+import java.awt.Dialog;\r
+import java.awt.FlowLayout;\r
+import java.awt.Frame;\r
+import java.awt.Label;\r
+import java.awt.Panel;\r
+import java.awt.Window;\r
+\r
+import java.awt.event.ActionEvent;\r
+import java.awt.event.ActionListener;\r
+\r
+/**\r
+ * @version $Revision: 1.1 $\r
+ * @author Benoît Mahé (bmahe@w3.org)\r
+ */\r
+public class QuestionPopup extends Dialog implements ActionListener {\r
+\r
+ protected Button yesB = null;\r
+ protected Button noB = null;\r
+\r
+ protected final static String defaultYesMsg = "Yes";\r
+ protected final static String defaultNoMsg = "No";\r
+ protected final static String defaultTitle = "Question";\r
+\r
+ protected AnswerListener answerListener = null;\r
+\r
+ public void registerAnswerListener (AnswerListener listener) {\r
+ answerListener = listener;\r
+ }\r
+\r
+ /**\r
+ * ActionListsner implementation - One of our button was fired.\r
+ * @param evt The ActionEvent.\r
+ */\r
+\r
+ public void actionPerformed(ActionEvent evt) {\r
+ if (answerListener != null) {\r
+ String command = evt.getActionCommand();\r
+ if (command.equals("yes"))\r
+ answerListener.questionAnswered(this, answerListener.YES);\r
+ else if (command.equals("no"))\r
+ answerListener.questionAnswered(this, answerListener.NO);\r
+ }\r
+ }\r
+\r
+ public QuestionPopup(Frame parent, String question) {\r
+ this(parent, defaultTitle, question, \r
+ defaultYesMsg, defaultNoMsg, true);\r
+ }\r
+\r
+ public QuestionPopup(Frame parent, String question, boolean modal) {\r
+ this(parent, defaultTitle, question, \r
+ defaultYesMsg, defaultNoMsg, modal);\r
+ }\r
+\r
+ public QuestionPopup (Frame parent, String title, \r
+ String question, boolean modal) \r
+ {\r
+ this(parent, title, question, defaultYesMsg, defaultNoMsg, modal);\r
+ }\r
+\r
+ public QuestionPopup (Frame parent, String title, \r
+ String question, String yes, String no,\r
+ boolean modal) \r
+ {\r
+ super(parent, title, modal);\r
+ Button yesB = new Button(yes);\r
+ yesB.setActionCommand("yes");\r
+ yesB.addActionListener(this);\r
+ Button noB = new Button(no);\r
+ noB.addActionListener(this);\r
+ noB.setActionCommand("no");\r
+ Label questionL = new Label(question);\r
+\r
+ Panel pq = new Panel();\r
+ pq.add(questionL);\r
+\r
+ BorderPanel pb = new BorderPanel(BorderPanel.IN, 2);\r
+ pb.setLayout(new FlowLayout());\r
+ pb.add(yesB);\r
+ pb.add(noB);\r
+\r
+ add(pq, "Center");\r
+ add(pb, "South");\r
+ pack();\r
+ }\r
+\r
+}\r