KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > gui > action > ExitCommand


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/gui/action/ExitCommand.java,v 1.12 2004/02/13 02:21:36 sebb Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.gui.action;
20
21 import java.awt.event.ActionEvent JavaDoc;
22 import java.util.HashSet JavaDoc;
23 import java.util.Set JavaDoc;
24
25 import javax.swing.JOptionPane JavaDoc;
26
27 import org.apache.jmeter.gui.GuiPackage;
28 import org.apache.jmeter.util.JMeterUtils;
29
30 /**
31  * @author Brendan Burns
32  * @author <a HREF="mailto:klancast@swbell.net">Keith Lancaster</a>
33  * @version $Revision: 1.12 $ updated on $Date: 2004/02/13 02:21:36 $
34  */

35 public class ExitCommand implements Command
36 {
37
38     public static final String JavaDoc EXIT = "exit";
39     private static Set JavaDoc commands = new HashSet JavaDoc();
40     static {
41         commands.add(EXIT);
42     }
43
44     /**
45      * Constructor for the ExitCommand object
46      */

47     public ExitCommand()
48     {}
49
50     /**
51      * Gets the ActionNames attribute of the ExitCommand object
52      *
53      *@return The ActionNames value
54      */

55     public Set JavaDoc getActionNames()
56     {
57         return commands;
58     }
59
60     /**
61      * Description of the Method
62      *
63      *@param e Description of Parameter
64      */

65     public void doAction(ActionEvent JavaDoc e)
66     {
67         ActionRouter.getInstance().doActionNow(
68             new ActionEvent JavaDoc(e.getSource(), e.getID(), CheckDirty.CHECK_DIRTY));
69         if (GuiPackage.getInstance().isDirty())
70         {
71             int chosenOption =
72                 JOptionPane.showConfirmDialog(
73                     GuiPackage.getInstance().getMainFrame(),
74                     JMeterUtils.getResString("cancel_exit_to_save"),
75                     JMeterUtils.getResString("Save?"),
76                     JOptionPane.YES_NO_CANCEL_OPTION,
77                     JOptionPane.QUESTION_MESSAGE);
78             if (chosenOption == JOptionPane.NO_OPTION)
79             {
80                 System.exit(0);
81             }
82             else if (chosenOption == JOptionPane.YES_OPTION)
83             {
84                 ActionRouter.getInstance().doActionNow(
85                     new ActionEvent JavaDoc(e.getSource(), e.getID(), Save.SAVE_ALL_AS));
86                 if (!GuiPackage.getInstance().isDirty())
87                 {
88                     System.exit(0);
89                 }
90             }
91         }
92         else
93         {
94             System.exit(0);
95         }
96     }
97 }
98
Popular Tags