Add 'src/jexer/' from commit 'cf01c92f5809a0732409e280fb0f32f27393618d'
[nikiroo-utils.git] / src / jexer / demos / DemoTextFieldWindow.java
index 196f3b9c3fa7f8b137d1428438e119a122681316..2c6116a980a4c0c243599c82a99fc0abee09f4a1 100644 (file)
 package jexer.demos;
 
 import java.text.MessageFormat;
+import java.util.Calendar;
 import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.Locale;
 import java.util.ResourceBundle;
 
 import jexer.TAction;
 import jexer.TApplication;
 import jexer.TCalendar;
 import jexer.TField;
+import jexer.TLabel;
 import jexer.TMessageBox;
 import jexer.TWindow;
+import jexer.layout.StretchLayoutManager;
 import static jexer.TCommand.*;
 import static jexer.TKeypress.*;
 
@@ -61,6 +66,17 @@ public class DemoTextFieldWindow extends TWindow {
      */
     TCalendar calendar = null;
 
+    /**
+     * Day of week label is updated with TSpinner clicks.
+     */
+    TLabel dayOfWeekLabel;
+
+    /**
+     * Day of week to demonstrate TSpinner.  Has to be at class scope so that
+     * it can be accessed by the anonymous TAction class.
+     */
+    GregorianCalendar dayOfWeekCalendar = new GregorianCalendar();
+
     // ------------------------------------------------------------------------
     // Constructors -----------------------------------------------------------
     // ------------------------------------------------------------------------
@@ -85,6 +101,9 @@ public class DemoTextFieldWindow extends TWindow {
         // will be centered on screen.
         super(parent, i18n.getString("windowTitle"), 0, 0, 60, 20, flags);
 
+        setLayoutManager(new StretchLayoutManager(getWidth() - 2,
+                getHeight() - 2));
+
         int row = 1;
 
         addLabel(i18n.getString("textField1"), 1, row);
@@ -111,6 +130,33 @@ public class DemoTextFieldWindow extends TWindow {
             }
         );
 
+        dayOfWeekLabel = addLabel("Wednesday-", 35, row - 1, "tmenu", false);
+        dayOfWeekLabel.setLabel(String.format("%-10s",
+                dayOfWeekCalendar.getDisplayName(Calendar.DAY_OF_WEEK,
+                    Calendar.LONG, Locale.getDefault())));
+
+        addSpinner(35 + dayOfWeekLabel.getWidth(), row - 1,
+            new TAction() {
+                public void DO() {
+                    dayOfWeekCalendar.add(Calendar.DAY_OF_WEEK, 1);
+                    dayOfWeekLabel.setLabel(String.format("%-10s",
+                            dayOfWeekCalendar.getDisplayName(
+                            Calendar.DAY_OF_WEEK, Calendar.LONG,
+                            Locale.getDefault())));
+                }
+            },
+            new TAction() {
+                public void DO() {
+                    dayOfWeekCalendar.add(Calendar.DAY_OF_WEEK, -1);
+                    dayOfWeekLabel.setLabel(String.format("%-10s",
+                            dayOfWeekCalendar.getDisplayName(
+                            Calendar.DAY_OF_WEEK, Calendar.LONG,
+                            Locale.getDefault())));
+                }
+            }
+        );
+
+
         addButton(i18n.getString("closeWindow"),
             (getWidth() - 14) / 2, getHeight() - 4,
             new TAction() {