View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.hbtop.screen.top;
19  
20  import org.apache.hadoop.hbase.classification.InterfaceAudience;
21  import org.apache.hadoop.hbase.hbtop.screen.AbstractScreenView;
22  import org.apache.hadoop.hbase.hbtop.screen.Screen;
23  import org.apache.hadoop.hbase.hbtop.screen.ScreenView;
24  import org.apache.hadoop.hbase.hbtop.terminal.KeyPress;
25  import org.apache.hadoop.hbase.hbtop.terminal.Terminal;
26  
27  /**
28   * The message mode in the top screen.
29   */
30  @InterfaceAudience.Private
31  public class MessageModeScreenView extends AbstractScreenView {
32  
33    private final int row;
34    private final MessageModeScreenPresenter messageModeScreenPresenter;
35  
36    public MessageModeScreenView(Screen screen, Terminal terminal, int row, String message,
37      ScreenView nextScreenView) {
38      super(screen, terminal);
39      this.row = row;
40      this.messageModeScreenPresenter =
41        new MessageModeScreenPresenter(this, message, nextScreenView);
42    }
43  
44    @Override
45    public void init() {
46      messageModeScreenPresenter.init();
47      setTimer(2000);
48    }
49  
50    @Override
51    public ScreenView handleTimer() {
52      return messageModeScreenPresenter.returnToNextScreen();
53    }
54  
55    @Override
56    public ScreenView handleKeyPress(KeyPress keyPress) {
57      cancelTimer();
58      return messageModeScreenPresenter.returnToNextScreen();
59    }
60  
61    public void showMessage(String message) {
62      getTerminalPrinter(row).startHighlight().print(" ").print(message).print(" ").stopHighlight()
63        .endOfLine();
64    }
65  }