| 
01 /*02  * Copyright 2008-2017 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 org.codehaus.griffon.runtime.lanterna;
 17
 18 import com.googlecode.lanterna.gui.GUIScreen;
 19 import com.googlecode.lanterna.gui.Window;
 20 import griffon.lanterna.LanternaWindowDisplayHandler;
 21
 22 import javax.annotation.Nonnull;
 23 import javax.inject.Inject;
 24
 25 import static griffon.util.GriffonNameUtils.requireNonBlank;
 26 import static java.util.Objects.requireNonNull;
 27
 28 /**
 29  * @author Andres Almiray
 30  * @since 2.0.0
 31  */
 32 public class DefaultLanternaWindowDisplayHandler implements LanternaWindowDisplayHandler {
 33     private static final String ERROR_NAME_BLANK = "Argument 'name' must not be null";
 34     private static final String ERROR_WINDOW_NULL = "Argument 'window' must not be null";
 35
 36     private final GUIScreen screen;
 37
 38     @Inject
 39     public DefaultLanternaWindowDisplayHandler(@Nonnull GUIScreen screen) {
 40         this.screen = requireNonNull(screen, "Argument 'screen' must not be null");
 41     }
 42
 43     public void show(@Nonnull String name, @Nonnull Window window) {
 44         requireNonBlank(name, ERROR_NAME_BLANK);
 45         requireNonNull(window, ERROR_WINDOW_NULL);
 46         screen.showWindow(window, GUIScreen.Position.CENTER);
 47     }
 48
 49     public void hide(@Nonnull String name, @Nonnull Window window) {
 50         requireNonBlank(name, ERROR_NAME_BLANK);
 51         requireNonNull(window, ERROR_WINDOW_NULL);
 52         window.close();
 53     }
 54 }
 |