Package jexer.backend

Class LogicalScreen

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean cursorVisible
      If true, the cursor is visible and should be placed onscreen at (cursorX, cursorY) during a call to flushPhysical().
      protected int cursorX
      Cursor X position if visible.
      protected int cursorY
      Cursor Y position if visible.
      protected int height
      Height of the visible window.
      protected Cell[][] logical
      The logical screen being rendered to.
      protected Cell[][] physical
      The physical screen last sent out on flush().
      protected boolean reallyCleared
      Set if the user explicitly wants to redraw everything starting with a ECMATerminal.clearAll().
      protected int width
      Width of the visible window.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected LogicalScreen()
      Public constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clear the logical screen.
      void clearPhysical()
      Clear the physical screen.
      void copySelection​(Clipboard clipboard, int x0, int y0, int x1, int y1, boolean rectangle)
      Copy the screen selection area to the clipboard.
      void drawBox​(int left, int top, int right, int bottom, CellAttributes border, CellAttributes background)
      Draw a box with a border and empty background.
      void drawBox​(int left, int top, int right, int bottom, CellAttributes border, CellAttributes background, int borderType, boolean shadow)
      Draw a box with a border and empty background.
      void drawBoxShadow​(int left, int top, int right, int bottom)
      Draw a box shadow.
      void flushPhysical()
      Default implementation does nothing.
      CellAttributes getAttrXY​(int x, int y)
      Get the attributes at one location.
      Cell getCharXY​(int x, int y)
      Get the cell at one location.
      int getClipBottom()
      Get bottom drawing clipping boundary.
      int getClipLeft()
      Get left drawing clipping boundary.
      int getClipRight()
      Get right drawing clipping boundary.
      int getClipTop()
      Get top drawing clipping boundary.
      int getCursorX()
      Get the cursor X position.
      int getCursorY()
      Get the cursor Y position.
      int getHeight()
      Get the height.
      int getTextHeight()
      Get the height of a character cell in pixels.
      int getTextWidth()
      Get the width of a character cell in pixels.
      int getWidth()
      Get the width.
      void hideCursor()
      Hide the cursor.
      void hLineXY​(int x, int y, int n, int ch, CellAttributes attr)
      Draw a horizontal line from (x, y) to (x + n, y).
      void invertCell​(int x, int y)
      Invert the cell color at a position, including both halves of a double-width cell.
      void invertCell​(int x, int y, boolean onlyThisCell)
      Invert the cell color at a position.
      boolean isCursorVisible()
      Get the cursor visibility.
      boolean isDirty()
      Get dirty flag.
      void putAll​(int ch, CellAttributes attr)
      Fill the entire screen with one character with attributes.
      void putAttrXY​(int x, int y, CellAttributes attr)
      Set the attributes at one location.
      void putAttrXY​(int x, int y, CellAttributes attr, boolean clip)
      Set the attributes at one location.
      void putCharXY​(int x, int y, int ch)
      Render one character without changing the underlying attributes.
      void putCharXY​(int x, int y, int ch, CellAttributes attr)
      Render one character with attributes.
      void putCharXY​(int x, int y, Cell ch)
      Render one character with attributes.
      void putCursor​(boolean visible, int x, int y)
      Put the cursor at (x,y).
      void putFullwidthCharXY​(int x, int y, int ch)
      Render one fullwidth character with attributes.
      void putFullwidthCharXY​(int x, int y, int ch, CellAttributes attr)
      Render one fullwidth character with attributes.
      void putFullwidthCharXY​(int x, int y, Cell cell)
      Render one fullwidth cell.
      void putStringXY​(int x, int y, java.lang.String str)
      Render a string without changing the underlying attribute.
      void putStringXY​(int x, int y, java.lang.String str, CellAttributes attr)
      Render a string.
      void reset()
      Reset screen to not-bold, white-on-black.
      void resetClipping()
      Flush the offset and clip variables.
      void resizeToScreen()
      Resize the physical screen to match the logical screen dimensions.
      void setClipBottom​(int clipBottom)
      Set bottom drawing clipping boundary.
      void setClipLeft​(int clipLeft)
      Set left drawing clipping boundary.
      void setClipRight​(int clipRight)
      Set right drawing clipping boundary.
      void setClipTop​(int clipTop)
      Set top drawing clipping boundary.
      void setDimensions​(int width, int height)
      Change the width and height.
      void setHeight​(int height)
      Change the height.
      void setOffsetX​(int offsetX)
      Set drawing offset for x.
      void setOffsetY​(int offsetY)
      Set drawing offset for y.
      void setSelection​(int x0, int y0, int x1, int y1, boolean rectangle)
      Set a selection area on the screen.
      void setTitle​(java.lang.String title)
      Set the window title.
      void setWidth​(int width)
      Change the width.
      Screen snapshot()
      Obtain a snapshot copy of the screen.
      void unsetImageRow​(int y)
      Unset every image cell on one row of the physical screen, forcing images on that row to be redrawn.
      void vLineXY​(int x, int y, int n, int ch, CellAttributes attr)
      Draw a vertical line from (x, y) to (x, y + n).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • width

        protected int width
        Width of the visible window.
      • height

        protected int height
        Height of the visible window.
      • physical

        protected Cell[][] physical
        The physical screen last sent out on flush().
      • logical

        protected Cell[][] logical
        The logical screen being rendered to.
      • reallyCleared

        protected boolean reallyCleared
        Set if the user explicitly wants to redraw everything starting with a ECMATerminal.clearAll().
      • cursorVisible

        protected boolean cursorVisible
        If true, the cursor is visible and should be placed onscreen at (cursorX, cursorY) during a call to flushPhysical().
      • cursorX

        protected int cursorX
        Cursor X position if visible.
      • cursorY

        protected int cursorY
        Cursor Y position if visible.
    • Constructor Detail

      • LogicalScreen

        protected LogicalScreen()
        Public constructor. Sets everything to not-bold, white-on-black.
    • Method Detail

      • getTextWidth

        public int getTextWidth()
        Get the width of a character cell in pixels.
        Specified by:
        getTextWidth in interface Screen
        Returns:
        the width in pixels of a character cell
      • getTextHeight

        public int getTextHeight()
        Get the height of a character cell in pixels.
        Specified by:
        getTextHeight in interface Screen
        Returns:
        the height in pixels of a character cell
      • setOffsetX

        public final void setOffsetX​(int offsetX)
        Set drawing offset for x.
        Specified by:
        setOffsetX in interface Screen
        Parameters:
        offsetX - new drawing offset
      • setOffsetY

        public final void setOffsetY​(int offsetY)
        Set drawing offset for y.
        Specified by:
        setOffsetY in interface Screen
        Parameters:
        offsetY - new drawing offset
      • getClipRight

        public final int getClipRight()
        Get right drawing clipping boundary.
        Specified by:
        getClipRight in interface Screen
        Returns:
        drawing boundary
      • setClipRight

        public final void setClipRight​(int clipRight)
        Set right drawing clipping boundary.
        Specified by:
        setClipRight in interface Screen
        Parameters:
        clipRight - new boundary
      • getClipBottom

        public final int getClipBottom()
        Get bottom drawing clipping boundary.
        Specified by:
        getClipBottom in interface Screen
        Returns:
        drawing boundary
      • setClipBottom

        public final void setClipBottom​(int clipBottom)
        Set bottom drawing clipping boundary.
        Specified by:
        setClipBottom in interface Screen
        Parameters:
        clipBottom - new boundary
      • getClipLeft

        public final int getClipLeft()
        Get left drawing clipping boundary.
        Specified by:
        getClipLeft in interface Screen
        Returns:
        drawing boundary
      • setClipLeft

        public final void setClipLeft​(int clipLeft)
        Set left drawing clipping boundary.
        Specified by:
        setClipLeft in interface Screen
        Parameters:
        clipLeft - new boundary
      • getClipTop

        public final int getClipTop()
        Get top drawing clipping boundary.
        Specified by:
        getClipTop in interface Screen
        Returns:
        drawing boundary
      • setClipTop

        public final void setClipTop​(int clipTop)
        Set top drawing clipping boundary.
        Specified by:
        setClipTop in interface Screen
        Parameters:
        clipTop - new boundary
      • isDirty

        public final boolean isDirty()
        Get dirty flag.
        Specified by:
        isDirty in interface Screen
        Returns:
        if true, the logical screen is not in sync with the physical screen
      • getAttrXY

        public final CellAttributes getAttrXY​(int x,
                                              int y)
        Get the attributes at one location.
        Specified by:
        getAttrXY in interface Screen
        Parameters:
        x - column coordinate. 0 is the left-most column.
        y - row coordinate. 0 is the top-most row.
        Returns:
        attributes at (x, y)
      • getCharXY

        public Cell getCharXY​(int x,
                              int y)
        Get the cell at one location.
        Specified by:
        getCharXY in interface Screen
        Parameters:
        x - column coordinate. 0 is the left-most column.
        y - row coordinate. 0 is the top-most row.
        Returns:
        the character + attributes
      • putAttrXY

        public final void putAttrXY​(int x,
                                    int y,
                                    CellAttributes attr)
        Set the attributes at one location.
        Specified by:
        putAttrXY in interface Screen
        Parameters:
        x - column coordinate. 0 is the left-most column.
        y - row coordinate. 0 is the top-most row.
        attr - attributes to use (bold, foreColor, backColor)
      • putAttrXY

        public final void putAttrXY​(int x,
                                    int y,
                                    CellAttributes attr,
                                    boolean clip)
        Set the attributes at one location.
        Specified by:
        putAttrXY in interface Screen
        Parameters:
        x - column coordinate. 0 is the left-most column.
        y - row coordinate. 0 is the top-most row.
        attr - attributes to use (bold, foreColor, backColor)
        clip - if true, honor clipping/offset
      • putAll

        public final void putAll​(int ch,
                                 CellAttributes attr)
        Fill the entire screen with one character with attributes.
        Specified by:
        putAll in interface Screen
        Parameters:
        ch - character to draw
        attr - attributes to use (bold, foreColor, backColor)
      • putCharXY

        public final void putCharXY​(int x,
                                    int y,
                                    Cell ch)
        Render one character with attributes.
        Specified by:
        putCharXY in interface Screen
        Parameters:
        x - column coordinate. 0 is the left-most column.
        y - row coordinate. 0 is the top-most row.
        ch - character + attributes to draw
      • putCharXY

        public final void putCharXY​(int x,
                                    int y,
                                    int ch,
                                    CellAttributes attr)
        Render one character with attributes.
        Specified by:
        putCharXY in interface Screen
        Parameters:
        x - column coordinate. 0 is the left-most column.
        y - row coordinate. 0 is the top-most row.
        ch - character to draw
        attr - attributes to use (bold, foreColor, backColor)
      • putCharXY

        public final void putCharXY​(int x,
                                    int y,
                                    int ch)
        Render one character without changing the underlying attributes.
        Specified by:
        putCharXY in interface Screen
        Parameters:
        x - column coordinate. 0 is the left-most column.
        y - row coordinate. 0 is the top-most row.
        ch - character to draw
      • putStringXY

        public final void putStringXY​(int x,
                                      int y,
                                      java.lang.String str,
                                      CellAttributes attr)
        Render a string. Does not wrap if the string exceeds the line.
        Specified by:
        putStringXY in interface Screen
        Parameters:
        x - column coordinate. 0 is the left-most column.
        y - row coordinate. 0 is the top-most row.
        str - string to draw
        attr - attributes to use (bold, foreColor, backColor)
      • putStringXY

        public final void putStringXY​(int x,
                                      int y,
                                      java.lang.String str)
        Render a string without changing the underlying attribute. Does not wrap if the string exceeds the line.
        Specified by:
        putStringXY in interface Screen
        Parameters:
        x - column coordinate. 0 is the left-most column.
        y - row coordinate. 0 is the top-most row.
        str - string to draw
      • vLineXY

        public final void vLineXY​(int x,
                                  int y,
                                  int n,
                                  int ch,
                                  CellAttributes attr)
        Draw a vertical line from (x, y) to (x, y + n).
        Specified by:
        vLineXY in interface Screen
        Parameters:
        x - column coordinate. 0 is the left-most column.
        y - row coordinate. 0 is the top-most row.
        n - number of characters to draw
        ch - character to draw
        attr - attributes to use (bold, foreColor, backColor)
      • hLineXY

        public final void hLineXY​(int x,
                                  int y,
                                  int n,
                                  int ch,
                                  CellAttributes attr)
        Draw a horizontal line from (x, y) to (x + n, y).
        Specified by:
        hLineXY in interface Screen
        Parameters:
        x - column coordinate. 0 is the left-most column.
        y - row coordinate. 0 is the top-most row.
        n - number of characters to draw
        ch - character to draw
        attr - attributes to use (bold, foreColor, backColor)
      • setWidth

        public final void setWidth​(int width)
        Change the width. Everything on-screen will be destroyed and must be redrawn.
        Specified by:
        setWidth in interface Screen
        Parameters:
        width - new screen width
      • setHeight

        public final void setHeight​(int height)
        Change the height. Everything on-screen will be destroyed and must be redrawn.
        Specified by:
        setHeight in interface Screen
        Parameters:
        height - new screen height
      • setDimensions

        public final void setDimensions​(int width,
                                        int height)
        Change the width and height. Everything on-screen will be destroyed and must be redrawn.
        Specified by:
        setDimensions in interface Screen
        Parameters:
        width - new screen width
        height - new screen height
      • resizeToScreen

        public void resizeToScreen()
        Resize the physical screen to match the logical screen dimensions.
      • getHeight

        public final int getHeight()
        Get the height.
        Specified by:
        getHeight in interface Screen
        Returns:
        current screen height
      • getWidth

        public final int getWidth()
        Get the width.
        Specified by:
        getWidth in interface Screen
        Returns:
        current screen width
      • reset

        public final void reset()
        Reset screen to not-bold, white-on-black. Also flushes the offset and clip variables.
        Specified by:
        reset in interface Screen
      • resetClipping

        public final void resetClipping()
        Flush the offset and clip variables.
        Specified by:
        resetClipping in interface Screen
      • clear

        public final void clear()
        Clear the logical screen.
        Specified by:
        clear in interface Screen
      • drawBox

        public final void drawBox​(int left,
                                  int top,
                                  int right,
                                  int bottom,
                                  CellAttributes border,
                                  CellAttributes background)
        Draw a box with a border and empty background.
        Specified by:
        drawBox in interface Screen
        Parameters:
        left - left column of box. 0 is the left-most column.
        top - top row of the box. 0 is the top-most row.
        right - right column of box
        bottom - bottom row of the box
        border - attributes to use for the border
        background - attributes to use for the background
      • drawBox

        public final void drawBox​(int left,
                                  int top,
                                  int right,
                                  int bottom,
                                  CellAttributes border,
                                  CellAttributes background,
                                  int borderType,
                                  boolean shadow)
        Draw a box with a border and empty background.
        Specified by:
        drawBox in interface Screen
        Parameters:
        left - left column of box. 0 is the left-most column.
        top - top row of the box. 0 is the top-most row.
        right - right column of box
        bottom - bottom row of the box
        border - attributes to use for the border
        background - attributes to use for the background
        borderType - if 1, draw a single-line border; if 2, draw a double-line border; if 3, draw double-line top/bottom edges and single-line left/right edges (like Qmodem)
        shadow - if true, draw a "shadow" on the box
      • drawBoxShadow

        public final void drawBoxShadow​(int left,
                                        int top,
                                        int right,
                                        int bottom)
        Draw a box shadow.
        Specified by:
        drawBoxShadow in interface Screen
        Parameters:
        left - left column of box. 0 is the left-most column.
        top - top row of the box. 0 is the top-most row.
        right - right column of box
        bottom - bottom row of the box
      • flushPhysical

        public void flushPhysical()
        Default implementation does nothing.
        Specified by:
        flushPhysical in interface Screen
      • putCursor

        public void putCursor​(boolean visible,
                              int x,
                              int y)
        Put the cursor at (x,y).
        Specified by:
        putCursor in interface Screen
        Parameters:
        visible - if true, the cursor should be visible
        x - column coordinate to put the cursor on
        y - row coordinate to put the cursor on
      • hideCursor

        public final void hideCursor()
        Hide the cursor.
        Specified by:
        hideCursor in interface Screen
      • isCursorVisible

        public boolean isCursorVisible()
        Get the cursor visibility.
        Specified by:
        isCursorVisible in interface Screen
        Returns:
        true if the cursor is visible
      • getCursorX

        public int getCursorX()
        Get the cursor X position.
        Specified by:
        getCursorX in interface Screen
        Returns:
        the cursor x column position
      • getCursorY

        public int getCursorY()
        Get the cursor Y position.
        Specified by:
        getCursorY in interface Screen
        Returns:
        the cursor y row position
      • setTitle

        public void setTitle​(java.lang.String title)
        Set the window title. Default implementation does nothing.
        Specified by:
        setTitle in interface Screen
        Parameters:
        title - the new title
      • clearPhysical

        public final void clearPhysical()
        Clear the physical screen.
        Specified by:
        clearPhysical in interface Screen
      • unsetImageRow

        public final void unsetImageRow​(int y)
        Unset every image cell on one row of the physical screen, forcing images on that row to be redrawn.
        Specified by:
        unsetImageRow in interface Screen
        Parameters:
        y - row coordinate. 0 is the top-most row.
      • putFullwidthCharXY

        public final void putFullwidthCharXY​(int x,
                                             int y,
                                             Cell cell)
        Render one fullwidth cell.
        Parameters:
        x - column coordinate. 0 is the left-most column.
        y - row coordinate. 0 is the top-most row.
        cell - the cell to draw
      • putFullwidthCharXY

        public final void putFullwidthCharXY​(int x,
                                             int y,
                                             int ch,
                                             CellAttributes attr)
        Render one fullwidth character with attributes.
        Parameters:
        x - column coordinate. 0 is the left-most column.
        y - row coordinate. 0 is the top-most row.
        ch - character to draw
        attr - attributes to use (bold, foreColor, backColor)
      • putFullwidthCharXY

        public final void putFullwidthCharXY​(int x,
                                             int y,
                                             int ch)
        Render one fullwidth character with attributes.
        Parameters:
        x - column coordinate. 0 is the left-most column.
        y - row coordinate. 0 is the top-most row.
        ch - character to draw
      • invertCell

        public void invertCell​(int x,
                               int y)
        Invert the cell color at a position, including both halves of a double-width cell.
        Specified by:
        invertCell in interface Screen
        Parameters:
        x - column position
        y - row position
      • invertCell

        public void invertCell​(int x,
                               int y,
                               boolean onlyThisCell)
        Invert the cell color at a position.
        Specified by:
        invertCell in interface Screen
        Parameters:
        x - column position
        y - row position
        onlyThisCell - if true, only invert this cell, otherwise invert both halves of a double-width cell if necessary
      • setSelection

        public void setSelection​(int x0,
                                 int y0,
                                 int x1,
                                 int y1,
                                 boolean rectangle)
        Set a selection area on the screen.
        Specified by:
        setSelection in interface Screen
        Parameters:
        x0 - the starting X position of the selection
        y0 - the starting Y position of the selection
        x1 - the ending X position of the selection
        y1 - the ending Y position of the selection
        rectangle - if true, this is a rectangle select
      • copySelection

        public void copySelection​(Clipboard clipboard,
                                  int x0,
                                  int y0,
                                  int x1,
                                  int y1,
                                  boolean rectangle)
        Copy the screen selection area to the clipboard.
        Specified by:
        copySelection in interface Screen
        Parameters:
        clipboard - the clipboard to use
        x0 - the starting X position of the selection
        y0 - the starting Y position of the selection
        x1 - the ending X position of the selection
        y1 - the ending Y position of the selection
        rectangle - if true, this is a rectangle select
      • snapshot

        public Screen snapshot()
        Obtain a snapshot copy of the screen.
        Specified by:
        snapshot in interface Screen
        Returns:
        a copy of the screen's data