001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.hbtop.screen.top;
019
020import org.apache.hadoop.hbase.hbtop.screen.AbstractScreenView;
021import org.apache.hadoop.hbase.hbtop.screen.Screen;
022import org.apache.hadoop.hbase.hbtop.screen.ScreenView;
023import org.apache.hadoop.hbase.hbtop.terminal.KeyPress;
024import org.apache.hadoop.hbase.hbtop.terminal.Terminal;
025import org.apache.yetus.audience.InterfaceAudience;
026
027/**
028 * The message mode in the top screen.
029 */
030@InterfaceAudience.Private
031public class MessageModeScreenView extends AbstractScreenView {
032
033  private final int row;
034  private final MessageModeScreenPresenter messageModeScreenPresenter;
035
036  public MessageModeScreenView(Screen screen, Terminal terminal, int row, String message,
037    ScreenView nextScreenView) {
038    super(screen, terminal);
039    this.row = row;
040    this.messageModeScreenPresenter = new MessageModeScreenPresenter(this, message, nextScreenView);
041  }
042
043  @Override
044  public void init() {
045    messageModeScreenPresenter.init();
046    setTimer(2000);
047  }
048
049  @Override
050  public ScreenView handleTimer() {
051    return messageModeScreenPresenter.returnToNextScreen();
052  }
053
054  @Override
055  public ScreenView handleKeyPress(KeyPress keyPress) {
056    cancelTimer();
057    return messageModeScreenPresenter.returnToNextScreen();
058  }
059
060  public void showMessage(String message) {
061    getTerminalPrinter(row).startHighlight().print(" ").print(message).print(" ").stopHighlight()
062      .endOfLine();
063  }
064}