View Javadoc

1   /*
2    * XMLCV - Gestion de CV sous forme XML
3    * 
4    * Copyright (C) 2004-2005, Damien Raude-Morvan
5    * 
6    * This file is part of XMLCV.
7    *
8    * XMLCV is free software; you can redistribute it and/or modify
9    * it under the terms of the GNU General Public License as published by
10   * the Free Software Foundation; either version 2 of the License, or
11   * (at your option) any later version.
12   *
13   * XMLCV is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   * GNU General Public License for more details.
17   *
18   * You should have received a copy of the GNU General Public License
19   * along with XMLCV; if not, write to the Free Software
20   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21   * 
22   * Contacts :
23   * - Sébastien Mathy <smathy@tuxfamily.org>
24   * - Emmanuel Berre <eberre@tuxfamily.org>
25   * - Damien Raude-Morvan <drazzib@drazzib.com>
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.JFileChooser;
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 « Export to PS » 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 ActionOutPS extends AbstractAction {
54  
55  	/*** Parent Frame (for future modal dialog) */
56  	private Frame _parentFrame;
57  
58  	/*** Singleton */
59  	static private ActionOutPS _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 ActionOutPS(Frame parent) {
70  		this._parentFrame = parent;
71  
72  		putValue(NAME, I18n.getString("ActionOutPS.PS")); //$NON-NLS-1$
73  		putValue(SHORT_DESCRIPTION, I18n.getString("ActionOutPS.OutputPS")); //$NON-NLS-1$
74  		putValue(SMALL_ICON, new ImageIcon(getClass().getResource(
75  				Config.ICON_OUTPS)));
76  		putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_P));
77  		putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_P,
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 ActionOutPS instance(Frame parent) {
91  		if (null == _singleInstance)
92  			_singleInstance = new ActionOutPS(parent);
93  		return _singleInstance;
94  	}
95  
96  	public void actionPerformed(ActionEvent e) {
97  		System.out.println(this.getClass().toString());
98  		JFileChooser j = new JFileChooser();
99  		int retour = j.showSaveDialog(this._parentFrame);
100 
101 		if (retour == JFileChooser.APPROVE_OPTION) { // sortie par OK
102 			this._parentFrame.savePS(j.getSelectedFile().getAbsolutePath());
103 		}
104 	}
105 
106 	/***
107 	 * Activate/De-activate this action
108 	 * 
109 	 * @param state
110 	 *            true activate this Action, false de-activate
111 	 */
112 	public static void status(boolean state) {
113 		_singleInstance.setEnabled(state);
114 	}
115 
116 }