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/** 030 * An abstract class for {@link ScreenView} that has the common useful methods and the default 031 * implementations for the abstract methods. 032 */ 033@InterfaceAudience.Private 034public abstract class AbstractScreenView implements ScreenView { 035 036 private final Screen screen; 037 private final Terminal terminal; 038 039 public AbstractScreenView(Screen screen, Terminal terminal) { 040 this.screen = Objects.requireNonNull(screen); 041 this.terminal = Objects.requireNonNull(terminal); 042 } 043 044 @Override 045 public void init() { 046 } 047 048 @Override 049 public ScreenView handleKeyPress(KeyPress keyPress) { 050 return this; 051 } 052 053 @Override 054 public ScreenView handleTimer() { 055 return this; 056 } 057 058 protected Screen getScreen() { 059 return screen; 060 } 061 062 protected Terminal getTerminal() { 063 return terminal; 064 } 065 066 protected void setTimer(long delay) { 067 screen.setTimer(delay); 068 } 069 070 protected void cancelTimer() { 071 screen.cancelTimer(); 072 } 073 074 protected TerminalPrinter getTerminalPrinter(int startRow) { 075 return terminal.getTerminalPrinter(startRow); 076 } 077 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}