Refactoring - boolean getters and miscellaneous
[fanfix.git] / src / jexer / io / Screen.java
index 29c8485f95b837d41fece27f6b9c02af6c90cd7a..ec5309d669c3cf06a36dc5c2a460615d9b3422ad 100644 (file)
@@ -183,7 +183,17 @@ public abstract class Screen {
     /**
      * When true, logical != physical.
      */
-    protected boolean dirty;
+    protected volatile boolean dirty;
+
+    /**
+     * Get dirty flag.
+     *
+     * @return if true, the logical screen is not in sync with the physical
+     * screen
+     */
+    public final boolean isDirty() {
+        return dirty;
+    }
 
     /**
      * Set if the user explicitly wants to redraw everything starting with a
@@ -243,8 +253,8 @@ public abstract class Screen {
      * @param attr attributes to use (bold, foreColor, backColor)
      * @param clip if true, honor clipping/offset
      */
-    public final void putAttrXY(final int x, final int y,
-        final CellAttributes attr, final boolean clip) {
+    public final void putAttrXY(final int x, final int y
+        final CellAttributes attr, final boolean clip) {
 
         int X = x;
         int Y = y;
@@ -265,11 +275,11 @@ public abstract class Screen {
             dirty = true;
             logical[X][Y].setForeColor(attr.getForeColor());
             logical[X][Y].setBackColor(attr.getBackColor());
-            logical[X][Y].setBold(attr.getBold());
-            logical[X][Y].setBlink(attr.getBlink());
-            logical[X][Y].setReverse(attr.getReverse());
-            logical[X][Y].setUnderline(attr.getUnderline());
-            logical[X][Y].setProtect(attr.getProtect());
+            logical[X][Y].setBold(attr.isBold());
+            logical[X][Y].setBlink(attr.isBlink());
+            logical[X][Y].setReverse(attr.isReverse());
+            logical[X][Y].setUnderline(attr.isUnderline());
+            logical[X][Y].setProtect(attr.isProtect());
         }
     }
 
@@ -280,6 +290,7 @@ public abstract class Screen {
      * @param attr attributes to use (bold, foreColor, backColor)
      */
     public final void putAll(final char ch, final CellAttributes attr) {
+
         for (int x = 0; x < width; x++) {
             for (int y = 0; y < height; y++) {
                 putCharXY(x, y, ch, attr);
@@ -332,11 +343,11 @@ public abstract class Screen {
             logical[X][Y].setChar(ch);
             logical[X][Y].setForeColor(attr.getForeColor());
             logical[X][Y].setBackColor(attr.getBackColor());
-            logical[X][Y].setBold(attr.getBold());
-            logical[X][Y].setBlink(attr.getBlink());
-            logical[X][Y].setReverse(attr.getReverse());
-            logical[X][Y].setUnderline(attr.getUnderline());
-            logical[X][Y].setProtect(attr.getProtect());
+            logical[X][Y].setBold(attr.isBold());
+            logical[X][Y].setBlink(attr.isBlink());
+            logical[X][Y].setReverse(attr.isReverse());
+            logical[X][Y].setUnderline(attr.isUnderline());
+            logical[X][Y].setProtect(attr.isProtect());
         }
     }
 
@@ -348,6 +359,7 @@ public abstract class Screen {
      * @param ch character to draw
      */
     public final void putCharXY(final int x, final int y, final char ch) {
+
         if ((x < clipLeft)
             || (x >= clipRight)
             || (y < clipTop)
@@ -398,6 +410,7 @@ public abstract class Screen {
      * @param str string to draw
      */
     public final void putStrXY(final int x, final int y, final String str) {
+
         int i = x;
         for (int j = 0; j < str.length(); j++) {
             char ch = str.charAt(j);
@@ -449,7 +462,7 @@ public abstract class Screen {
      * @param width new width
      * @param height new height
      */
-    private void reallocate(final int width, final int height) {
+    private synchronized void reallocate(final int width, final int height) {
         if (logical != null) {
             for (int row = 0; row < this.height; row++) {
                 for (int col = 0; col < this.width; col++) {
@@ -494,7 +507,7 @@ public abstract class Screen {
      *
      * @param width new screen width
      */
-    public final void setWidth(final int width) {
+    public final synchronized void setWidth(final int width) {
         reallocate(width, this.height);
     }
 
@@ -504,7 +517,7 @@ public abstract class Screen {
      *
      * @param height new screen height
      */
-    public final void setHeight(final int height) {
+    public final synchronized void setHeight(final int height) {
         reallocate(this.width, height);
     }
 
@@ -524,7 +537,7 @@ public abstract class Screen {
      *
      * @return current screen height
      */
-    public final int getHeight() {
+    public final synchronized int getHeight() {
         return this.height;
     }
 
@@ -533,7 +546,7 @@ public abstract class Screen {
      *
      * @return current screen width
      */
-    public final int getWidth() {
+    public final synchronized int getWidth() {
         return this.width;
     }
 
@@ -554,7 +567,7 @@ public abstract class Screen {
      * Reset screen to not-bold, white-on-black.  Also flushes the offset and
      * clip variables.
      */
-    public final void reset() {
+    public final synchronized void reset() {
         dirty = true;
         for (int row = 0; row < height; row++) {
             for (int col = 0; col < width; col++) {
@@ -577,12 +590,24 @@ public abstract class Screen {
     }
 
     /**
-     * Force the screen to be fully cleared and redrawn on the next flush().
+     * Clear the logical screen.
      */
     public final void clear() {
         reset();
     }
 
+    /**
+     * Clear the physical screen.
+     */
+    public final void clearPhysical() {
+        dirty = true;
+        for (int row = 0; row < height; row++) {
+            for (int col = 0; col < width; col++) {
+                physical[col][row].reset();
+            }
+        }
+    }
+
     /**
      * Draw a box with a border and empty background.
      *
@@ -619,8 +644,6 @@ public abstract class Screen {
         final CellAttributes border, final CellAttributes background,
         final int borderType, final boolean shadow) {
 
-        int boxTop = top;
-        int boxLeft = left;
         int boxWidth = right - left;
         int boxHeight = bottom - top;