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 java.util.List;
21  import org.apache.hadoop.hbase.classification.InterfaceAudience;
22  import org.apache.hadoop.hbase.hbtop.screen.AbstractScreenView;
23  import org.apache.hadoop.hbase.hbtop.screen.Screen;
24  import org.apache.hadoop.hbase.hbtop.screen.ScreenView;
25  import org.apache.hadoop.hbase.hbtop.terminal.KeyPress;
26  import org.apache.hadoop.hbase.hbtop.terminal.Terminal;
27  
28  /**
29   * The input mode in the top screen.
30   */
31  @InterfaceAudience.Private
32  public class InputModeScreenView extends AbstractScreenView {
33  
34    private final int row;
35    private final InputModeScreenPresenter inputModeScreenPresenter;
36  
37    public InputModeScreenView(Screen screen, Terminal terminal, int row, String message,
38      List<String> histories, InputModeScreenPresenter.ResultListener resultListener) {
39      super(screen, terminal);
40      this.row = row;
41      this.inputModeScreenPresenter = new InputModeScreenPresenter(this, message, histories,
42        resultListener);
43    }
44  
45    @Override
46    public void init() {
47      inputModeScreenPresenter.init();
48    }
49  
50    @Override
51    public ScreenView handleKeyPress(KeyPress keyPress) {
52  
53      switch (keyPress.getType()) {
54        case Enter:
55          return inputModeScreenPresenter.returnToNextScreen();
56  
57        case Character:
58          inputModeScreenPresenter.character(keyPress.getCharacter());
59          break;
60  
61        case Backspace:
62          inputModeScreenPresenter.backspace();
63          break;
64  
65        case Delete:
66          inputModeScreenPresenter.delete();
67          break;
68  
69        case ArrowLeft:
70          inputModeScreenPresenter.arrowLeft();
71          break;
72  
73        case ArrowRight:
74          inputModeScreenPresenter.arrowRight();
75          break;
76  
77        case Home:
78          inputModeScreenPresenter.home();
79          break;
80  
81        case End:
82          inputModeScreenPresenter.end();
83          break;
84  
85        case ArrowUp:
86          inputModeScreenPresenter.arrowUp();
87          break;
88  
89        case ArrowDown:
90          inputModeScreenPresenter.arrowDown();
91          break;
92  
93        default:
94          break;
95      }
96      return this;
97    }
98  
99    public void showInput(String message, String inputString, int cursorPosition) {
100     getTerminalPrinter(row).startBold().print(message).stopBold().print(" ").print(inputString)
101       .endOfLine();
102     setCursorPosition(message.length() + 1 + cursorPosition, row);
103     refreshTerminal();
104   }
105 }