table row/column insert
[fanfix.git] / src / jexer / TField.java
index aa0d18f05f174332c9191017502475150608a3ec..992f274fb388792c1ed76c5e33bcc6a4472cb6a8 100644 (file)
@@ -3,7 +3,7 @@
  *
  * The MIT License (MIT)
  *
- * Copyright (C) 2017 Kevin Lamonte
+ * Copyright (C) 2019 Kevin Lamonte
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -43,6 +43,11 @@ public class TField extends TWidget {
     // Variables --------------------------------------------------------------
     // ------------------------------------------------------------------------
 
+    /**
+     * Background character for unfilled-in text.
+     */
+    protected char backgroundChar = GraphicsChars.HATCH;
+
     /**
      * Field text.
      */
@@ -84,6 +89,16 @@ public class TField extends TWidget {
      */
     protected TAction updateAction;
 
+    /**
+     * The color to use when this field is active.
+     */
+    private String activeColorKey = "tfield.active";
+
+    /**
+     * The color to use when this field is not active.
+     */
+    private String inactiveColorKey = "tfield.inactive";
+
     // ------------------------------------------------------------------------
     // Constructors -----------------------------------------------------------
     // ------------------------------------------------------------------------
@@ -349,18 +364,17 @@ public class TField extends TWidget {
         CellAttributes fieldColor;
 
         if (isAbsoluteActive()) {
-            fieldColor = getTheme().getColor("tfield.active");
+            fieldColor = getTheme().getColor(activeColorKey);
         } else {
-            fieldColor = getTheme().getColor("tfield.inactive");
+            fieldColor = getTheme().getColor(inactiveColorKey);
         }
 
         int end = windowStart + getWidth();
         if (end > text.length()) {
             end = text.length();
         }
-        getScreen().hLineXY(0, 0, getWidth(), GraphicsChars.HATCH, fieldColor);
-        getScreen().putStringXY(0, 0, text.substring(windowStart, end),
-            fieldColor);
+        hLineXY(0, 0, getWidth(), backgroundChar, fieldColor);
+        putStringXY(0, 0, text.substring(windowStart, end), fieldColor);
 
         // Fix the cursor, it will be rendered by TApplication.drawAll().
         updateCursor();
@@ -370,6 +384,24 @@ public class TField extends TWidget {
     // TField -----------------------------------------------------------------
     // ------------------------------------------------------------------------
 
+    /**
+     * Get field background character.
+     *
+     * @return background character
+     */
+    public final char getBackgroundChar() {
+        return backgroundChar;
+    }
+
+    /**
+     * Set field background character.
+     *
+     * @param backgroundChar the background character
+     */
+    public void setBackgroundChar(final char backgroundChar) {
+        this.backgroundChar = backgroundChar;
+    }
+
     /**
      * Get field text.
      *
@@ -385,6 +417,7 @@ public class TField extends TWidget {
      * @param text the new field text
      */
     public void setText(final String text) {
+        assert (text != null);
         this.text = text;
         position = 0;
         windowStart = 0;
@@ -520,4 +553,42 @@ public class TField extends TWidget {
         normalizeWindowStart();
     }
 
+    /**
+     * Set the active color key.
+     *
+     * @param activeColorKey ColorTheme key color to use when this field is
+     * active
+     */
+    public void setActiveColorKey(final String activeColorKey) {
+        this.activeColorKey = activeColorKey;
+    }
+
+    /**
+     * Set the inactive color key.
+     *
+     * @param inactiveColorKey ColorTheme key color to use when this field is
+     * inactive
+     */
+    public void setInactiveColorKey(final String inactiveColorKey) {
+        this.inactiveColorKey = inactiveColorKey;
+    }
+
+    /**
+     * Set the action to perform when the user presses enter.
+     *
+     * @param action the action to perform when the user presses enter
+     */
+    public void setEnterAction(final TAction action) {
+        enterAction = action;
+    }
+
+    /**
+     * Set the action to perform when the field is updated.
+     *
+     * @param action the action to perform when the field is updated
+     */
+    public void setUpdateAction(final TAction action) {
+        updateAction = action;
+    }
+
 }