01 /*
02 * Copyright 2008-2014 the original author or authors.
03 *
04 * Licensed under the Apache License, Version 2.0 (the "License");
05 * you may not use this file except in compliance with the License.
06 * You may obtain a copy of the License at
07 *
08 * http://www.apache.org/licenses/LICENSE-2.0
09 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package griffon.swing;
17
18 import griffon.swing.support.SwingUtils;
19 import org.codehaus.griffon.runtime.core.AbstractGriffonApplication;
20
21 import javax.annotation.Nonnull;
22 import java.awt.Toolkit;
23 import java.util.Map;
24
25 /**
26 * @author Andres Almiray
27 * @since 2.0.0
28 */
29 public class SwingGriffonApplication extends AbstractGriffonApplication {
30 public SwingGriffonApplication() {
31 this(EMPTY_ARGS);
32 }
33
34 public SwingGriffonApplication(@Nonnull String[] args) {
35 super(args);
36 }
37
38 @Override
39 protected void showStartingWindow() {
40 super.showStartingWindow();
41
42 // wait for EDT to empty out.... somehow
43 final boolean[] empty = {false};
44 while (true) {
45 getUIThreadManager().runInsideUISync(new Runnable() {
46 public void run() {
47 empty[0] = Toolkit.getDefaultToolkit().getSystemEventQueue().peekEvent() == null;
48 }
49 });
50 if (empty[0]) break;
51 try {
52 Thread.sleep(100);
53 } catch (InterruptedException e) {
54 // ignore
55 }
56 }
57 }
58
59 @Override
60 public boolean shutdown() {
61 if (super.shutdown()) {
62 exit();
63 }
64 return false;
65 }
66
67 public void exit() {
68 System.exit(0);
69 }
70
71 @Nonnull
72 @Override
73 public Object createApplicationContainer(@Nonnull Map<String, Object> attributes) {
74 return SwingUtils.createApplicationFrame(this, attributes);
75 }
76
77 public static void main(String[] args) throws Exception {
78 run(SwingGriffonApplication.class, args);
79 }
80 }
|