1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package cs.pancava.caltha;
21
22 import cs.pancava.caltha.desktop.EditorDesktop;
23 import cs.pancava.caltha.desktop.EditorDesktopNone;
24 import cs.pancava.caltha.desktop.EditorDesktopTextBasedGames;
25 import java.awt.BorderLayout;
26 import java.awt.Toolkit;
27 import java.util.Locale;
28 import java.util.MissingResourceException;
29 import java.util.ResourceBundle;
30 import javax.swing.JFrame;
31 import javax.swing.JMenuBar;
32 import javax.swing.JOptionPane;
33 import javax.swing.JPanel;
34 import javax.swing.JToolBar;
35
36
37
38
39
40
41
42
43 public class Editor extends JPanel
44 {
45
46
47
48 private static final long serialVersionUID = 20080430225750L;
49
50
51
52
53 private static Locale czLocale;
54
55
56
57
58 private static EditorDesktop eDesktop;
59
60
61
62
63 private static Editor calthaEditor;
64
65
66
67
68 private static ResourceBundle resourcesBundle;
69
70
71
72
73 private static String svnVersion = "$Revision: 14 $";
74
75
76
77
78 private static String editorNameS;
79
80
81
82
83 private static JFrame mainFrame;
84
85
86
87
88 private JPanel header;
89
90
91
92
93 private MainMenu menu;
94
95
96
97
98 Editor()
99 {
100
101
102
103
104 Editor.initializeResources();
105
106
107 this.createLayout();
108
109
110 this.createHeaderDesktop();
111
112
113 this.createBodyDesktop();
114 }
115
116
117
118
119
120
121 public static void errorMissingResource(final String msg)
122 {
123
124 Editor.showDialog("Soubor prostředků pro aplikaci Caltha nebyl nalezen nebo je poškozen !\n"
125 + "Program nebude správně fungovat !!!\n"
126 + "\nResources for application Caltha not found !!!"
127 + "\n" + msg,
128 "Error",
129 JOptionPane.ERROR_MESSAGE);
130 }
131
132
133
134
135
136 public static Editor getCalthaEditor()
137 {
138 return Editor.calthaEditor;
139 }
140
141
142
143
144
145 public static Locale getCzLocale()
146 {
147 return Editor.czLocale;
148 }
149
150
151
152
153
154 public static EditorDesktop getEditorDesktop()
155 {
156 return Editor.eDesktop;
157 }
158
159
160
161
162
163 public static String getSvnVersion()
164 {
165 return Editor.svnVersion;
166 }
167
168
169
170
171
172
173 public static String getResourcesBundleString(final String name)
174 {
175 return Editor.resourcesBundle.getString(name);
176 }
177
178
179
180
181
182 static void setEditorDesktop(final int editor)
183 {
184 switch (editor)
185 {
186 case EditorDesktop.EDITOR_NONE:
187 Editor.calthaEditor.createBodyDesktopNone();
188 break;
189 case EditorDesktop.EDITOR_TEXT_BASED_GAMES:
190 Editor.calthaEditor.createBodyDesktopTextBasedGames();
191 break;
192 default:
193 Editor.calthaEditor.createBodyDesktopNone();
194 }
195 }
196
197
198
199
200 private static void initializeResources()
201 {
202 Editor.czLocale = new Locale("cs", "CZ");
203 try
204 {
205 Editor.resourcesBundle = ResourceBundle.getBundle("Caltha", Editor.czLocale);
206 }
207 catch (MissingResourceException e)
208 {
209
210 Editor.errorMissingResource(e.getMessage());
211 }
212 }
213
214
215
216
217
218
219
220 public static void showDialog(final String msg, final String title, final int typ)
221 {
222 new Thread(new Runnable()
223 {
224 @Override
225 public void run()
226 {
227
228
229
230
231 JOptionPane.showMessageDialog(null, msg, title, typ);
232 }
233 }).start();
234 }
235
236
237
238
239
240
241
242
243 public static void showDialogMissingResources(final String error)
244 {
245 final Object[] options = {"OK"};
246 JOptionPane.showOptionDialog(null,
247 "Spatne klice pro lokalizaci !" + "\n" + error,
248 "Error",
249 JOptionPane.DEFAULT_OPTION,
250 JOptionPane.QUESTION_MESSAGE,
251 null,
252 options,
253 options[0]
254 );
255
256 System.exit(0);
257 }
258
259
260
261
262
263 public static void setResourcesBundle(final ResourceBundle resourceB)
264 {
265 Editor.resourcesBundle = resourceB;
266 }
267
268
269
270
271 private static void createAndShowGUI()
272 {
273 Editor.calthaEditor = new Editor();
274
275 try
276 {
277 Editor.editorNameS = Editor.resourcesBundle.getString("cs.pancava.caltha.Editor-createAndShowGUI_editorNameS");
278 }
279 catch (MissingResourceException e)
280 {
281 Editor.showDialog("" + e.getMessage(), "", JOptionPane.ERROR_MESSAGE);
282
283
284 Editor.editorNameS = "(Caltha) RPG editor";
285 }
286
287
288 Editor.mainFrame = new JFrame(Editor.editorNameS);
289 Editor.mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
290
291
292 Editor.mainFrame.getContentPane().add(Editor.calthaEditor);
293
294
295 Editor.mainFrame.setSize(Toolkit.getDefaultToolkit().getScreenSize());
296
297 Editor.mainFrame.setVisible(true);
298
299 Editor.mainFrame.setResizable(true);
300 }
301
302
303
304
305
306 public static void main(final String[] args)
307 {
308 javax.swing.SwingUtilities.invokeLater(new Runnable()
309 {
310 @Override
311 public void run()
312 {
313 Editor.createAndShowGUI();
314 }
315 });
316 }
317
318
319
320
321 protected final void updateText()
322 {
323 Editor.editorNameS = Editor.resourcesBundle.getString("cs.pancava.caltha.Editor-createAndShowGUI_editorNameS");
324 Editor.mainFrame.setTitle(Editor.editorNameS);
325 }
326
327
328
329
330
331 private void createBodyDesktop()
332 {
333 Editor.eDesktop = new EditorDesktopNone();
334
335 this.add(Editor.eDesktop.getMainDesktop(), BorderLayout.CENTER);
336 }
337
338
339
340
341 private void createBodyDesktopNone()
342 {
343
344 this.remove(Editor.eDesktop.getMainDesktop());
345
346
347 Editor.eDesktop = new EditorDesktopNone();
348
349
350 this.add(Editor.eDesktop.getMainDesktop(), BorderLayout.CENTER);
351
352
353 Editor.eDesktop.resizeWin();
354 Editor.calthaEditor.validate();
355 }
356
357
358
359
360 private void createBodyDesktopTextBasedGames()
361 {
362
363 this.remove(Editor.eDesktop.getMainDesktop());
364
365
366 Editor.eDesktop = new EditorDesktopTextBasedGames();
367
368
369 this.add(Editor.eDesktop.getMainDesktop(), BorderLayout.CENTER);
370
371
372 Editor.eDesktop.resizeWin();
373 Editor.calthaEditor.validate();
374 }
375
376
377
378
379 private void createHeaderDesktop()
380 {
381 this.header = new JPanel();
382
383 this.header.setLayout(new BorderLayout());
384
385
386 this.header.add(this.createMenu(), BorderLayout.NORTH);
387
388
389 this.header.add(this.createToolbar(), BorderLayout.SOUTH);
390
391 this.add(this.header, BorderLayout.NORTH);
392 }
393
394
395
396
397 private void createLayout()
398 {
399 this.setLayout(new BorderLayout());
400 }
401
402
403
404
405
406 private JMenuBar createMenu()
407 {
408 this.menu = new MainMenu();
409
410 return this.menu.getMenuBar();
411 }
412
413
414
415
416
417 private JToolBar createToolbar()
418 {
419
420
421
422 return new JToolBar();
423 }
424 }