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;
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
73 this.setIconImage(new ImageIcon(getClass()
74 .getResource(Config.ICON_LOGO)).getImage());
75 this.setTitle(I18n.getString("Frame.Title"));
76 this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
77
78
79 this._menuBar = new Menubar(this);
80 this.setJMenuBar(this._menuBar);
81
82
83 this._toolBar = new Toolbar(this);
84 this.getContentPane().add(this._toolBar, BorderLayout.PAGE_START);
85
86
87 this._desktopPane = new JDesktopPane();
88 this.getContentPane().add(this._desktopPane);
89
90
91 this._statusLabel = new JLabel(I18n.getString("Frame.StartOK"));
92 this.getContentPane().add(this._statusLabel, BorderLayout.SOUTH);
93
94
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"));
115
116 CViFrame ji;
117 try {
118 ji = new CViFrame(p_pathToFile);
119 Frame.this._desktopPane.add(ji);
120
121
122 Dimension screenSize = Frame.this._desktopPane.getSize();
123 Dimension frameSize = new Dimension();
124 frameSize.height = screenSize.height
125 - ((int) (0.2f * screenSize.height));
126
127 frameSize.width = screenSize.width
128 - ((int) (0.2f * screenSize.width));
129
130 ji.setSize(frameSize);
131
132 ji.setSelected(true);
133 ji.setVisible(true);
134
135 Frame.this._statusLabel.setText(I18n
136 .getString("Frame.LoadingOK"));
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"));
157
158 CViFrame ji;
159 try {
160 ji = new CViFrame();
161 Frame.this._desktopPane.add(ji);
162
163
164 Dimension screenSize = Frame.this._desktopPane.getSize();
165 Dimension frameSize = new Dimension();
166 frameSize.height = screenSize.height
167 - ((int) (0.2f * screenSize.height));
168
169 frameSize.width = screenSize.width
170 - ((int) (0.2f * screenSize.width));
171
172 ji.setSize(frameSize);
173
174 ji.setSelected(true);
175 ji.setVisible(true);
176
177 Frame.this._statusLabel.setText(I18n
178 .getString("Frame.LoadingOK"));
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"));
196 try {
197 Frame.this.getSelectedFrame().getBean().save();
198 Frame.this._statusLabel.setText(I18n
199 .getString("Frame.SaveOK"));
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"));
220 try {
221 new ConvertHTML(getSelectedFrame().getBean(), new File(
222 p_pathToFile));
223 Frame.this._statusLabel.setText(I18n
224 .getString("Frame.OutputOK"));
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"));
245 try {
246 new ConvertPDF(getSelectedFrame().getBean(), new File(
247 p_pathToFile));
248 Frame.this._statusLabel.setText(I18n
249 .getString("Frame.OutputOK"));
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"));
270 try {
271 new ConvertPS(getSelectedFrame().getBean(), new File(
272 p_pathToFile));
273 Frame.this._statusLabel.setText(I18n
274 .getString("Frame.OutputOK"));
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"));
295 try {
296 new ConvertRTF(getSelectedFrame().getBean(), new File(
297 p_pathToFile));
298 Frame.this._statusLabel.setText(I18n
299 .getString("Frame.OutputOK"));
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"));
317 new ConvertPreview(getSelectedFrame().getBean());
318 return null;
319 }
320
321 };
322 worker.start();
323 }
324
325 protected CViFrame getSelectedFrame() {
326
327 return (CViFrame) this._desktopPane.getSelectedFrame();
328 }
329 }