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;
28  
29  import java.awt.BorderLayout;
30  import java.awt.Dimension;
31  import java.awt.Toolkit;
32  import java.beans.PropertyVetoException;
33  import java.io.File;
34  
35  import javax.swing.ImageIcon;
36  import javax.swing.JDesktopPane;
37  import javax.swing.JFrame;
38  import javax.swing.JLabel;
39  import javax.swing.WindowConstants;
40  
41  import org.xmlcv.ConvertHTML;
42  import org.xmlcv.ConvertPDF;
43  import org.xmlcv.ConvertPS;
44  import org.xmlcv.ConvertPreview;
45  import org.xmlcv.ConvertRTF;
46  import org.xmlcv.XmlCVException;
47  import org.xmlcv.util.Config;
48  import org.xmlcv.util.I18n;
49  import org.xmlcv.util.SwingWorker;
50  
51  /***
52   * Main frame for XMLCV window
53   * 
54   * @version $Revision: 114 $
55   * @author <a href="mailto:drazzib@drazzib.com">Damien Raude-Morvan </a>
56   */
57  public class Frame extends JFrame {
58  
59  	private Menubar _menuBar;
60  
61  	JLabel _statusLabel;
62  
63  	JDesktopPane _desktopPane;
64  
65  	private Toolbar _toolBar;
66  
67  	/***
68  	 * 
69  	 */
70  	public void displayFrame() {
71  
72  		// Paramètres de la fenetre
73  		this.setIconImage(new ImageIcon(getClass()
74  				.getResource(Config.ICON_LOGO)).getImage());
75  		this.setTitle(I18n.getString("Frame.Title")); //$NON-NLS-1$
76  		this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
77  
78  		// Ajout de la barre de menu
79  		this._menuBar = new Menubar(this);
80  		this.setJMenuBar(this._menuBar);
81  
82  		// Ajout de la barre d'outils
83  		this._toolBar = new Toolbar(this);
84  		this.getContentPane().add(this._toolBar, BorderLayout.PAGE_START);
85  
86  		// Desktop
87  		this._desktopPane = new JDesktopPane();
88  		this.getContentPane().add(this._desktopPane);
89  
90  		// Barre de status
91  		this._statusLabel = new JLabel(I18n.getString("Frame.StartOK")); //$NON-NLS-1$
92  		this.getContentPane().add(this._statusLabel, BorderLayout.SOUTH);
93  
94  		// Taille et affichage
95  		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
96  		Dimension frameSize = new Dimension();
97  		frameSize.height = screenSize.height
98  				- ((int) (0.2f * screenSize.height));
99  		frameSize.width = screenSize.width - ((int) (0.2f * screenSize.width));
100 
101 		this.setSize(frameSize);
102 		this.setLocationRelativeTo(null);
103 		this.setVisible(true);
104 	}
105 
106 	/***
107 	 * @param p_pathToFile
108 	 */
109 	public void openCV(final String p_pathToFile) {
110 
111 		final SwingWorker worker = new SwingWorker() {
112 			public Object construct() {
113 				Frame.this._statusLabel
114 						.setText(I18n.getString("Frame.Loading")); //$NON-NLS-1$
115 
116 				CViFrame ji;
117 				try {
118 					ji = new CViFrame(p_pathToFile);
119 					Frame.this._desktopPane.add(ji);
120 
121 					// Size of internalFrame
122 					Dimension screenSize = Frame.this._desktopPane.getSize();
123 					Dimension frameSize = new Dimension();
124 					frameSize.height = screenSize.height
125 							- ((int) (0.2f * screenSize.height));
126 					// System.out.println(frameSize.height);
127 					frameSize.width = screenSize.width
128 							- ((int) (0.2f * screenSize.width));
129 					// System.out.println(frameSize.width);
130 					ji.setSize(frameSize);
131 
132 					ji.setSelected(true);
133 					ji.setVisible(true);
134 
135 					Frame.this._statusLabel.setText(I18n
136 							.getString("Frame.LoadingOK")); //$NON-NLS-1$
137 				} catch (XmlCVException e) {
138 					e.show();
139 				} catch (PropertyVetoException e) {
140 					(new XmlCVException(e)).show();
141 				}
142 				return null;
143 			}
144 
145 		};
146 		worker.start();
147 
148 	}
149 
150 	public void newCV() {
151 
152 		final SwingWorker worker = new SwingWorker() {
153 			public Object construct() {
154 
155 				Frame.this._statusLabel
156 						.setText(I18n.getString("Frame.Loading")); //$NON-NLS-1$
157 
158 				CViFrame ji;
159 				try {
160 					ji = new CViFrame();
161 					Frame.this._desktopPane.add(ji);
162 
163 					// Size of internalFrame
164 					Dimension screenSize = Frame.this._desktopPane.getSize();
165 					Dimension frameSize = new Dimension();
166 					frameSize.height = screenSize.height
167 							- ((int) (0.2f * screenSize.height));
168 					// System.out.println(frameSize.height);
169 					frameSize.width = screenSize.width
170 							- ((int) (0.2f * screenSize.width));
171 					// System.out.println(frameSize.width);
172 					ji.setSize(frameSize);
173 
174 					ji.setSelected(true);
175 					ji.setVisible(true);
176 
177 					Frame.this._statusLabel.setText(I18n
178 							.getString("Frame.LoadingOK")); //$NON-NLS-1$
179 				} catch (PropertyVetoException e) {
180 					(new XmlCVException(e)).show();
181 				}
182 				return null;
183 			}
184 
185 		};
186 		worker.start();
187 
188 	}
189 
190 	public void saveCV() {
191 
192 		final SwingWorker worker = new SwingWorker() {
193 			public Object construct() {
194 
195 				Frame.this._statusLabel.setText(I18n.getString("Frame.SaveCV")); //$NON-NLS-1$
196 				try {
197 					Frame.this.getSelectedFrame().getBean().save();
198 					Frame.this._statusLabel.setText(I18n
199 							.getString("Frame.SaveOK")); //$NON-NLS-1$
200 				} catch (XmlCVException e) {
201 					e.show();
202 				}
203 				return null;
204 			}
205 
206 		};
207 		worker.start();
208 	}
209 
210 	/***
211 	 * @param p_pathToFile
212 	 */
213 	public void saveHTML(final String p_pathToFile) {
214 
215 		final SwingWorker worker = new SwingWorker() {
216 			public Object construct() {
217 
218 				Frame.this._statusLabel.setText(I18n
219 						.getString("Frame.OutputHTML")); //$NON-NLS-1$
220 				try {
221 					new ConvertHTML(getSelectedFrame().getBean(), new File(
222 							p_pathToFile));
223 					Frame.this._statusLabel.setText(I18n
224 							.getString("Frame.OutputOK")); //$NON-NLS-1$
225 				} catch (XmlCVException e) {
226 					e.show();
227 				}
228 				return null;
229 			}
230 
231 		};
232 		worker.start();
233 	}
234 
235 	/***
236 	 * @param p_pathToFile
237 	 */
238 	public void savePDF(final String p_pathToFile) {
239 
240 		final SwingWorker worker = new SwingWorker() {
241 			public Object construct() {
242 
243 				Frame.this._statusLabel.setText(I18n
244 						.getString("Frame.OutputPDF")); //$NON-NLS-1$
245 				try {
246 					new ConvertPDF(getSelectedFrame().getBean(), new File(
247 							p_pathToFile));
248 					Frame.this._statusLabel.setText(I18n
249 							.getString("Frame.OutputOK")); //$NON-NLS-1$
250 				} catch (XmlCVException e) {
251 					e.show();
252 				}
253 				return null;
254 			}
255 
256 		};
257 		worker.start();
258 	}
259 
260 	/***
261 	 * @param p_pathToFile
262 	 */
263 	public void savePS(final String p_pathToFile) {
264 
265 		final SwingWorker worker = new SwingWorker() {
266 			public Object construct() {
267 
268 				Frame.this._statusLabel.setText(I18n
269 						.getString("Frame.OutputPS")); //$NON-NLS-1$
270 				try {
271 					new ConvertPS(getSelectedFrame().getBean(), new File(
272 							p_pathToFile));
273 					Frame.this._statusLabel.setText(I18n
274 							.getString("Frame.OutputOK")); //$NON-NLS-1$
275 				} catch (XmlCVException e) {
276 					e.show();
277 				}
278 				return null;
279 			}
280 
281 		};
282 		worker.start();
283 	}
284 
285 	/***
286 	 * @param p_pathToFile
287 	 */
288 	public void saveRTF(final String p_pathToFile) {
289 
290 		final SwingWorker worker = new SwingWorker() {
291 			public Object construct() {
292 
293 				Frame.this._statusLabel.setText(I18n
294 						.getString("Frame.OutputRTF")); //$NON-NLS-1$
295 				try {
296 					new ConvertRTF(getSelectedFrame().getBean(), new File(
297 							p_pathToFile));
298 					Frame.this._statusLabel.setText(I18n
299 							.getString("Frame.OutputOK")); //$NON-NLS-1$
300 				} catch (XmlCVException e) {
301 					e.show();
302 				}
303 				return null;
304 			}
305 
306 		};
307 		worker.start();
308 	}
309 
310 	public void preview() {
311 
312 		final SwingWorker worker = new SwingWorker() {
313 			public Object construct() {
314 
315 				Frame.this._statusLabel
316 						.setText(I18n.getString("Frame.Preview")); //$NON-NLS-1$
317 				new ConvertPreview(getSelectedFrame().getBean());
318 				return null;
319 			}
320 
321 		};
322 		worker.start();
323 	}
324 
325 	protected CViFrame getSelectedFrame() {
326 		// FIXME
327 		return (CViFrame) this._desktopPane.getSelectedFrame();
328 	}
329 }