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;
19  
20  import edu.umd.cs.findbugs.annotations.Nullable;
21  import java.util.Objects;
22  
23  import org.apache.hadoop.hbase.classification.InterfaceAudience;
24  import org.apache.hadoop.hbase.hbtop.terminal.KeyPress;
25  import org.apache.hadoop.hbase.hbtop.terminal.Terminal;
26  import org.apache.hadoop.hbase.hbtop.terminal.TerminalPrinter;
27  import org.apache.hadoop.hbase.hbtop.terminal.TerminalSize;
28  
29  /**
30   * An abstract class for {@link ScreenView} that has the common useful methods and the default
31   * implementations for the abstract methods.
32   */
33  @InterfaceAudience.Private
34  public abstract class AbstractScreenView implements ScreenView {
35  
36    private final Screen screen;
37    private final Terminal terminal;
38  
39    public AbstractScreenView(Screen screen, Terminal terminal) {
40      this.screen = Objects.requireNonNull(screen);
41      this.terminal = Objects.requireNonNull(terminal);
42    }
43  
44    @Override
45    public void init() {
46    }
47  
48    @Override
49    public ScreenView handleKeyPress(KeyPress keyPress) {
50      return this;
51    }
52  
53    @Override
54    public ScreenView handleTimer() {
55      return this;
56    }
57  
58    protected Screen getScreen() {
59      return screen;
60    }
61  
62    protected Terminal getTerminal() {
63      return terminal;
64    }
65  
66    protected void setTimer(long delay) {
67      screen.setTimer(delay);
68    }
69  
70    protected void cancelTimer() {
71      screen.cancelTimer();
72    }
73  
74    protected TerminalPrinter getTerminalPrinter(int startRow) {
75      return terminal.getTerminalPrinter(startRow);
76    }
77  
78    @Nullable
79    protected TerminalSize getTerminalSize() {
80      return terminal.getSize();
81    }
82  
83    @Nullable
84    protected TerminalSize doResizeIfNecessary() {
85      return terminal.doResizeIfNecessary();
86    }
87  
88    public void clearTerminal() {
89      terminal.clear();
90    }
91  
92    public void refreshTerminal() {
93      terminal.refresh();
94    }
95  
96    public void hideCursor() {
97      terminal.hideCursor();
98    }
99  
100   public void setCursorPosition(int column, int row) {
101     terminal.setCursorPosition(column, row);
102   }
103 }