1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package org.xmlcv.gui.action;
28
29 import java.awt.event.ActionEvent;
30 import java.awt.event.InputEvent;
31 import java.awt.event.KeyEvent;
32
33 import javax.swing.AbstractAction;
34 import javax.swing.ImageIcon;
35 import javax.swing.JOptionPane;
36 import javax.swing.KeyStroke;
37
38 import org.xmlcv.gui.Frame;
39 import org.xmlcv.util.Config;
40 import org.xmlcv.util.I18n;
41
42 /***
43 * Listener for « Save this CV » action
44 *
45 * This class follow the pattern Singleton from GOF. So that only one object is
46 * shared between all the Button/MenuItem.<br>
47 * The <code>actionPerformed()</code> method is the core of the class.<br>
48 * The <code>parent</code> is present to allow further modal dialog creation.
49 *
50 * @version $Revision: 114 $
51 * @author <a href="mailto:drazzib@drazzib.com">Damien Raude-Morvan </a>
52 */
53 public class ActionSaveCV extends AbstractAction {
54
55 /*** Parent Frame (for future modal dialog) */
56 private Frame _parentFrame;
57
58 /*** Singleton */
59 static private ActionSaveCV _singleInstance = null;
60
61 /***
62 * Create a new Action that could be used in JMenuItem, JButton to asign
63 * text, icon, accesskey. <br>
64 * Don't access directly :)
65 *
66 * @param parent
67 * main window of XMLCV
68 */
69 private ActionSaveCV(Frame parent) {
70 this._parentFrame = parent;
71
72 putValue(NAME, I18n.getString("ActionSaveCV.SaveCV"));
73 putValue(SHORT_DESCRIPTION, I18n.getString("ActionSaveCV.SaveCVDesc"));
74 putValue(SMALL_ICON, new ImageIcon(getClass().getResource(
75 Config.ICON_FILESAVE)));
76 putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_S));
77 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S,
78 InputEvent.CTRL_MASK));
79
80 setEnabled(false);
81 }
82
83 /***
84 * Get a new instance of the singleton (create it if doesn't exist)
85 *
86 * @param parent
87 * main window of XMLCV
88 * @return singleton instance of Action
89 */
90 public static ActionSaveCV instance(Frame parent) {
91 if (null == _singleInstance)
92 _singleInstance = new ActionSaveCV(parent);
93 return _singleInstance;
94 }
95
96
97
98
99
100
101 public void actionPerformed(ActionEvent e) {
102 System.out.println(this.getClass().toString());
103 int retour = JOptionPane
104 .showConfirmDialog(
105 this._parentFrame,
106 I18n.getString("ActionSaveCV.SaveThisCV"), I18n.getString("ActionSaveCV.SaveCV"), JOptionPane.YES_NO_OPTION);
107
108 if (retour == JOptionPane.YES_OPTION) {
109 this._parentFrame.saveCV();
110 }
111 }
112
113 /***
114 * Activate/De-activate this action
115 *
116 * @param state
117 * true activate this Action, false de-activate
118 */
119 public static void status(boolean state) {
120 _singleInstance.setEnabled(state);
121 }
122
123 }