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.lanterna;
17
18 import com.googlecode.lanterna.gui.GUIScreen;
19 import com.googlecode.lanterna.gui.Window;
20 import org.codehaus.griffon.runtime.core.AbstractGriffonApplication;
21
22 import javax.annotation.Nonnull;
23 import java.util.Map;
24
25 /**
26 * @author Andres Almiray
27 * @since 2.0.0
28 */
29 public class LanternaGriffonApplication extends AbstractGriffonApplication {
30 private GUIScreen screen;
31
32 public LanternaGriffonApplication() {
33 this(EMPTY_ARGS);
34 }
35
36 public LanternaGriffonApplication(@Nonnull String[] args) {
37 super(args);
38 }
39
40 public GUIScreen getGUIScreen() {
41 return getInjector().getInstance(GUIScreen.class);
42 }
43
44 @Override
45 public void initialize() {
46 this.screen = getGUIScreen();
47 this.screen.getScreen().startScreen();
48 super.initialize();
49 }
50
51 @Override
52 public boolean shutdown() {
53 if (super.shutdown()) {
54 exit();
55 }
56 return false;
57 }
58
59 public void exit() {
60 this.screen.getScreen().stopScreen();
61 System.exit(0);
62 }
63
64 @Nonnull
65 @Override
66 public Object createApplicationContainer(@Nonnull Map<String, Object> attributes) {
67 String title = (String) attributes.remove("title");
68 if (title == null) {
69 title = getConfiguration().getAsString("application.title");
70 }
71 return new Window(title);
72 }
73
74 public static void main(String[] args) throws Exception {
75 run(LanternaGriffonApplication.class, args);
76 }
77 }
|