java.lang.Object
org.springframework.shell.component.view.control.AbstractControl
org.springframework.shell.component.view.control.AbstractView
All Implemented Interfaces:
Control, View
Direct Known Subclasses:
BoxView, WindowView

public abstract class AbstractView extends AbstractControl implements View
Base implementation of a View and its parent interface Control providing some common functionality for implementations.
  • Constructor Details

    • AbstractView

      public AbstractView()
  • Method Details

    • onDestroy

      protected void onDestroy(reactor.core.Disposable disposable)
      Register Disposable to get disposed when view terminates.
      Parameters:
      disposable - a disposable to dispose
    • destroy

      public void destroy()
      Cleans running state of a View so that it can be left to get garbage collected.
    • init

      public final void init()
      Initialize a view. Mostly reserved for future use and simply calls initInternal().
      Specified by:
      init in interface View
      See Also:
    • shortcut

      public void shortcut(Integer key, Runnable runnable)
    • initInternal

      protected void initInternal()
      Internal init method called from init(). Override to do something usefull. Typically key and mousebindings are registered from this method.
    • setLayer

      public void setLayer(int index)
      Description copied from interface: View
      Sets a layer index this View operates on.
      Specified by:
      setLayer in interface View
      Parameters:
      index - the layer index
    • getLayer

      protected int getLayer()
    • draw

      public final void draw(Screen screen)
      Calls drawing logic in two stages. First a background is drawn and then an actual content. This logic allows to separate how child implementation can use drawing logic from its parent as usually background should get overridden in child but actual content should get overridden in a parent.
      Specified by:
      draw in interface Control
      Parameters:
      screen - the screen
    • drawInternal

      protected abstract void drawInternal(Screen screen)
      Component internal drawing method. Implementing classes needs to define this method to draw something into a Screen.
      Parameters:
      screen - the screen
    • drawBackground

      protected void drawBackground(Screen screen)
      Internal drawing method for background.
      Parameters:
      screen - the screen
    • focus

      public void focus(View view, boolean focus)
      Description copied from interface: View
      Called when View gets or loses a focus.
      Specified by:
      focus in interface View
      Parameters:
      view - the view receiving focus
      focus - flag if focus is received
    • hasFocus

      public boolean hasFocus()
      Description copied from interface: View
      Gets if this View has a focus.
      Specified by:
      hasFocus in interface View
      Returns:
      true if view has a focus
    • getMouseHandler

      public MouseHandler getMouseHandler()
      Handles mouse events by dispatching registered consumers into an event loop. Override to change default behaviour.
      Specified by:
      getMouseHandler in interface View
      Returns:
      a view mouse handler
      See Also:
    • getKeyHandler

      public KeyHandler getKeyHandler()
      Handles keys by dispatching registered command runnable into an event loop. Override to change default behaviour.
      Specified by:
      getKeyHandler in interface View
      Returns:
      a view key handler
      See Also:
    • getHotKeyHandler

      public KeyHandler getHotKeyHandler()
      Description copied from interface: View
      Gets a View hotkey KeyHandler. Can be null which indicates view will not handle any key events.
      Specified by:
      getHotKeyHandler in interface View
      Returns:
      a view hotkey handler
      See Also:
    • setDrawFunction

      public void setDrawFunction(BiFunction<Screen,Rectangle,Rectangle> drawFunction)
      Sets a callback function which is invoked after a View has been drawn.
      Parameters:
      drawFunction - the draw function
    • getDrawFunction

      public BiFunction<Screen,Rectangle,Rectangle> getDrawFunction()
      Gets a draw function.
      Returns:
      null if function is not set
      See Also:
    • setEventLoop

      public void setEventLoop(@Nullable EventLoop eventLoop)
      Set an EventLoop.
      Specified by:
      setEventLoop in interface View
      Parameters:
      eventLoop - the event loop
    • getEventLoop

      protected EventLoop getEventLoop()
      Get an EventLoop.
      Returns:
      event loop
    • setViewService

      public void setViewService(ViewService viewService)
      Specified by:
      setViewService in interface View
      Parameters:
      viewService - the view service
    • getViewService

      protected ViewService getViewService()
      Returns:
      view service
    • registerViewCommand

      protected void registerViewCommand(String command, Runnable runnable)
    • getViewCommands

      public Set<String> getViewCommands()
      Description copied from interface: View
      Get supported commands.
      Specified by:
      getViewCommands in interface View
      Returns:
      supported commands
      See Also:
    • registerKeyBinding

      protected void registerKeyBinding(Integer keyType, String keyCommand)
    • registerKeyBinding

      protected void registerKeyBinding(Integer keyType, KeyBindingConsumer keyConsumer)
    • registerKeyBinding

      protected void registerKeyBinding(Integer keyType, Runnable keyRunnable)
    • registerHotKeyBinding

      protected void registerHotKeyBinding(Integer keyType, String keyCommand)
    • registerHotKeyBinding

      protected void registerHotKeyBinding(Integer keyType, KeyBindingConsumer keyConsumer)
    • registerHotKeyBinding

      protected void registerHotKeyBinding(Integer keyType, Runnable keyRunnable)
    • getKeyBindings

      protected Map<Integer,org.springframework.shell.component.view.control.AbstractView.KeyBindingValue> getKeyBindings()
      Get key bindings.
      Returns:
      key bindings
    • getHotKeyBindings

      protected Map<Integer,org.springframework.shell.component.view.control.AbstractView.KeyBindingValue> getHotKeyBindings()
      Get hotkey bindings.
      Returns:
      hotkey bindings
    • getMouseBindings

      protected Map<Integer,org.springframework.shell.component.view.control.AbstractView.MouseBindingValue> getMouseBindings()
      Get mouse bindings.
      Returns:
      mouse bindings
    • registerMouseBinding

      protected void registerMouseBinding(Integer keyType, String mouseCommand)
    • registerMouseBinding

      protected void registerMouseBinding(Integer keyType, MouseBindingConsumer mouseConsumer)
    • registerMouseBinding

      protected void registerMouseBinding(Integer keyType, Runnable mouseRunnable)
    • dispatch

      protected void dispatch(org.springframework.messaging.Message<?> message)
      Dispatch a Message into an event loop.
      Parameters:
      message - the message to dispatch
    • dispatchRunnable

      protected boolean dispatchRunnable(Runnable runnable)
    • runViewCommand

      public boolean runViewCommand(String command)
      Description copied from interface: View
      Run command.
      Specified by:
      runViewCommand in interface View
      Parameters:
      command - the command to run
      Returns:
      true if command was succesfully dispatched
      See Also:
    • dispatchKeyRunCommand

      protected boolean dispatchKeyRunCommand(KeyEvent event, org.springframework.shell.component.view.control.AbstractView.KeyBindingValue keyBindingValue)
    • dispatchMouseRunCommand

      protected boolean dispatchMouseRunCommand(MouseEvent event, org.springframework.shell.component.view.control.AbstractView.MouseBindingValue mouseBindingValue)