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;
019
020import edu.umd.cs.findbugs.annotations.Nullable;
021import java.util.Objects;
022import org.apache.hadoop.hbase.hbtop.terminal.KeyPress;
023import org.apache.hadoop.hbase.hbtop.terminal.Terminal;
024import org.apache.hadoop.hbase.hbtop.terminal.TerminalPrinter;
025import org.apache.hadoop.hbase.hbtop.terminal.TerminalSize;
026import org.apache.yetus.audience.InterfaceAudience;
027
028/**
029 * An abstract class for {@link ScreenView} that has the common useful methods and the default
030 * implementations for the abstract methods.
031 */
032@InterfaceAudience.Private
033public abstract class AbstractScreenView implements ScreenView {
034
035  private final Screen screen;
036  private final Terminal terminal;
037
038  public AbstractScreenView(Screen screen, Terminal terminal) {
039    this.screen = Objects.requireNonNull(screen);
040    this.terminal = Objects.requireNonNull(terminal);
041  }
042
043  @Override
044  public void init() {
045  }
046
047  @Override
048  public ScreenView handleKeyPress(KeyPress keyPress) {
049    return this;
050  }
051
052  @Override
053  public ScreenView handleTimer() {
054    return this;
055  }
056
057  protected Screen getScreen() {
058    return screen;
059  }
060
061  protected Terminal getTerminal() {
062    return terminal;
063  }
064
065  protected void setTimer(long delay) {
066    screen.setTimer(delay);
067  }
068
069  protected void cancelTimer() {
070    screen.cancelTimer();
071  }
072
073  protected TerminalPrinter getTerminalPrinter(int startRow) {
074    return terminal.getTerminalPrinter(startRow);
075  }
076
077  @Nullable
078  protected TerminalSize getTerminalSize() {
079    return terminal.getSize();
080  }
081
082  @Nullable
083  protected TerminalSize doResizeIfNecessary() {
084    return terminal.doResizeIfNecessary();
085  }
086
087  public void clearTerminal() {
088    terminal.clear();
089  }
090
091  public void refreshTerminal() {
092    terminal.refresh();
093  }
094
095  public void hideCursor() {
096    terminal.hideCursor();
097  }
098
099  public void setCursorPosition(int column, int row) {
100    terminal.setCursorPosition(column, row);
101  }
102}