org.crsh.text
Class VirtualScreen

java.lang.Object
  extended by org.crsh.text.VirtualScreen
All Implemented Interfaces:
Appendable, Screenable, ScreenContext

public class VirtualScreen
extends Object
implements ScreenContext

A virtual screen that can be scrolled. This class is thread safe, as it can be used concurrently by two threads, for example one thread can provide new elements while another thread is repainting the buffer to the screen, both threads can either modify the underlying data structure. Paint could also be called concurrently by two threads, one that just provided a new element and wants to repaint the structure and another that changes the current cursor and asks for a repaint too.

Author:
Julien Viet

Nested Class Summary
private static class VirtualScreen.Foo
           
 
Field Summary
private  ArrayList<VirtualScreen.Foo> buffer
          .
private  int cursorIndex
          The cursor index in the chunk at the current cursorOffset.
private  int cursorOffset
          The cursor offset in the buffer.
private  Style cursorStyle
          .
private  int cursorX
          The cursor coordinate.
private  int cursorY
          The cursor coordinate.
private  int height
          The cached width and height for the current refresh.
private  int index
          The absolute offset, index and row.
private  int offset
          The absolute offset, index and row.
private  ScreenContext out
          .
private static int PAINTED
           
private static int PAINTING
           
private static int REFRESH
           
private  int row
          The absolute offset, index and row.
private  int status
          Do we need to clear screen.
private  Style style
          The current style for last chunk in the buffer.
private  int width
          The cached width and height for the current refresh.
 
Constructor Summary
VirtualScreen(ScreenContext out)
           
 
Method Summary
 Screenable append(char c)
           
 Screenable append(CharSequence s)
           
 Screenable append(CharSequence csq, int start, int end)
           
 Screenable append(Style style)
           
 Screenable cls()
           
 void flush()
          Flush the stream.
 int getHeight()
          Returns the screen height in chars.
 int getWidth()
          Returns the screen width in chars.
 boolean isPainted()
           
 boolean isPainting()
           
 boolean isRefresh()
           
 int nextPage()
           
 boolean nextRow()
           
private  Pair<Integer,Integer> nextRow(int offset, int index, int width)
           
 VirtualScreen paint()
          Pain the underlying screen context.
 boolean previousRow()
           
private  int scroll(int amount)
           
 boolean update()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

width

private int width
The cached width and height for the current refresh.


height

private int height
The cached width and height for the current refresh.


buffer

private final ArrayList<VirtualScreen.Foo> buffer
.


style

private Style style
The current style for last chunk in the buffer.


offset

private int offset
The absolute offset, index and row.


index

private int index
The absolute offset, index and row.


row

private int row
The absolute offset, index and row.


cursorX

private int cursorX
The cursor coordinate.


cursorY

private int cursorY
The cursor coordinate.


cursorOffset

private int cursorOffset
The cursor offset in the buffer.


cursorIndex

private int cursorIndex
The cursor index in the chunk at the current cursorOffset.


cursorStyle

private Style cursorStyle
.


out

private final ScreenContext out
.


status

private int status
Do we need to clear screen.


REFRESH

private static final int REFRESH
See Also:
Constant Field Values

PAINTING

private static final int PAINTING
See Also:
Constant Field Values

PAINTED

private static final int PAINTED
See Also:
Constant Field Values
Constructor Detail

VirtualScreen

public VirtualScreen(ScreenContext out)
Method Detail

getWidth

public int getWidth()
Description copied from interface: ScreenContext
Returns the screen width in chars. When the value is not positive it means the value could not be determined.

Specified by:
getWidth in interface ScreenContext
Returns:
the term width

getHeight

public int getHeight()
Description copied from interface: ScreenContext
Returns the screen height in chars. When the value is not positive it means the value could not be determined.

Specified by:
getHeight in interface ScreenContext
Returns:
the term height

append

public Screenable append(CharSequence s)
                  throws IOException
Specified by:
append in interface Appendable
Throws:
IOException

append

public Screenable append(char c)
                  throws IOException
Specified by:
append in interface Appendable
Throws:
IOException

append

public Screenable append(CharSequence csq,
                         int start,
                         int end)
                  throws IOException
Specified by:
append in interface Appendable
Throws:
IOException

append

public Screenable append(Style style)
                  throws IOException
Specified by:
append in interface Screenable
Throws:
IOException

cls

public Screenable cls()
               throws IOException
Specified by:
cls in interface Screenable
Throws:
IOException

paint

public VirtualScreen paint()
                    throws IOException
Pain the underlying screen context.

Returns:
this screen buffer
Throws:
IOException - any io exception

previousRow

public boolean previousRow()
                    throws IOException
Throws:
IOException

isPainted

public boolean isPainted()
Returns:
true if the buffer is painted

isRefresh

public boolean isRefresh()
Returns:
true if the buffer is stale and needs a full repaint

isPainting

public boolean isPainting()
Returns:
true if the buffer is waiting for input to become painted

nextRow

public boolean nextRow()
                throws IOException
Throws:
IOException

nextPage

public int nextPage()
             throws IOException
Throws:
IOException

scroll

private int scroll(int amount)
            throws IOException
Throws:
IOException

nextRow

private Pair<Integer,Integer> nextRow(int offset,
                                      int index,
                                      int width)

update

public boolean update()
               throws IOException
Throws:
IOException

flush

public void flush()
           throws IOException
Description copied from interface: ScreenContext
Flush the stream.

Specified by:
flush in interface ScreenContext
Throws:
IOException - any io exception


Copyright © 2015 eXo Platform SAS. All Rights Reserved.