View Javadoc

1   /*
2    * @(#)$Id: ExitApplicationAction.java 689 2009-07-22 00:10:27Z bsigner $
3    *
4    * Author       :   Michele Croci, mcroci@gmail.com
5    *
6    * Purpose      :   Terminates the application.
7    *
8    * -----------------------------------------------------------------------
9    *
10   * Revision Information:
11   *
12   * Date             Who         Reason
13   *
14   * Nov 15, 2006     crocimi     Initial Release
15   * Jan 20, 2007     bsigner     Cleanup
16   * 
17   *
18   * -----------------------------------------------------------------------
19   *
20   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
21   *
22   * This software is the proprietary information of ETH Zurich.
23   * Use is subject to license terms.
24   * 
25   */
26  
27  
28  package org.ximtec.igesture.geco.gui.action;
29  
30  import java.awt.event.ActionEvent;
31  
32  import javax.swing.JOptionPane;
33  
34  import org.sigtec.graphix.widget.BasicAction;
35  import org.ximtec.igesture.geco.gui.MainView;
36  import org.ximtec.igesture.geco.util.Constant;
37  import org.ximtec.igesture.geco.util.GuiBundleTool;
38  import org.ximtec.igesture.geco.util.SystemTray;
39  
40  
41  /**
42   * Terminates the application.
43   * 
44   * @version 0.9, Nov 2007
45   * @author Michele Croci, mcroci@gmail.com
46   * @author Beat Signer, signer@inf.ethz.ch
47   */
48  
49  public class ExitApplicationAction extends BasicAction {
50  
51     /**
52      * The key used to retrieve action details from the resource bundle.
53      */
54     public static final String KEY = "ExitApplicationAction";
55  
56     private MainView mainView;
57  
58  
59     public ExitApplicationAction(MainView mainView) {
60        super(KEY, GuiBundleTool.getBundle());
61        this.mainView = mainView;
62     }
63  
64  
65     /**
66      * Exits the application.
67      * 
68      * @param event the event to be handled.
69      */
70     public void actionPerformed(ActionEvent event) {
71        if (mainView.getModel().needSave()) {
72           int n = JOptionPane.showConfirmDialog(mainView,
73                 Constant.SAVE_DIALOG_TITLE, Constant.EMPTY_STRING,
74                 JOptionPane.YES_NO_CANCEL_OPTION);
75  
76           if (n == 0) {
77              (new SaveProjectAction(mainView)).save();
78              System.exit(0);
79           }
80           else if (n == 1) {
81              System.exit(0);
82           }
83  
84        }
85        else {
86           SystemTray.removeTrayIcon();
87           System.exit(0);
88        }
89  
90     } // actionPerformed
91  
92  }