1 package fr.ifremer.quadrige2.ui.swing.common;
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 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.jdesktop.swingx.util.JVM;
29
30 import java.lang.reflect.Field;
31
32
33
34
35 public abstract class Application {
36
37 private static final Log LOG = LogFactory.getLog(Application.class);
38
39 public static final int NORMAL_EXIT_CODE = 0;
40 public static final int UPDATE_EXIT_CODE = 88;
41
42 public Application() {
43
44
45 Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler());
46
47
48 JVM jvm = JVM.current();
49 Class jvmClass = jvm.getClass();
50 try {
51 Field jdkVersionField = jvmClass.getDeclaredField("jdkVersion");
52 jdkVersionField.setAccessible(true);
53
54 jdkVersionField.setInt(jvm, JVM.JDK1_7);
55 } catch (NoSuchFieldException | IllegalAccessException e) {
56 LOG.warn("Unable to simulate JVM 1.7 in SwingLabs components. Flickering will happen !");
57 }
58
59 }
60
61
62
63
64
65
66 protected final void start(String... args) {
67 if (init(args)) {
68 show();
69 }
70 }
71
72
73
74
75
76
77
78 protected abstract boolean init(String... args);
79
80
81
82
83 protected abstract void show();
84
85
86
87
88
89 public static void exit(int exitCode) {
90 System.exit(exitCode);
91 }
92 }