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/**
029 * The message mode in the top screen.
030 */
031@InterfaceAudience.Private
032public class MessageModeScreenView extends AbstractScreenView {
033
034  private final int row;
035  private final MessageModeScreenPresenter messageModeScreenPresenter;
036
037  public MessageModeScreenView(Screen screen, Terminal terminal, int row, String message,
038    ScreenView nextScreenView) {
039    super(screen, terminal);
040    this.row = row;
041    this.messageModeScreenPresenter =
042      new MessageModeScreenPresenter(this, message, nextScreenView);
043  }
044
045  @Override
046  public void init() {
047    messageModeScreenPresenter.init();
048    setTimer(2000);
049  }
050
051  @Override
052  public ScreenView handleTimer() {
053    return messageModeScreenPresenter.returnToNextScreen();
054  }
055
056  @Override
057  public ScreenView handleKeyPress(KeyPress keyPress) {
058    cancelTimer();
059    return messageModeScreenPresenter.returnToNextScreen();
060  }
061
062  public void showMessage(String message) {
063    getTerminalPrinter(row).startHighlight().print(" ").print(message).print(" ").stopHighlight()
064      .endOfLine();
065  }
066}