Merge commit '77d3a60869e7a780c6ae069e51530e1eacece5e2'
[fanfix.git] / src / jexer / demos / DemoMainWindow.java
index c5e599c53bcebade57dbe95ff13e1786d256d4b9..8f77448b29f45c65cd67e52c38268e0564ad1e0d 100644 (file)
@@ -44,6 +44,7 @@ import jexer.TTimer;
 import jexer.TWidget;
 import jexer.TWindow;
 import jexer.event.TCommandEvent;
+import jexer.layout.StretchLayoutManager;
 import static jexer.TCommand.*;
 import static jexer.TKeypress.*;
 
@@ -65,7 +66,12 @@ public class DemoMainWindow extends TWindow {
     /**
      * Timer that increments a number.
      */
-    private TTimer timer;
+    private TTimer timer1;
+
+    /**
+     * Timer that increments a number.
+     */
+    private TTimer timer2;
 
     /**
      * Timer label is updated with timer ticks.
@@ -76,13 +82,25 @@ public class DemoMainWindow extends TWindow {
      * Timer increment used by the timer loop.  Has to be at class scope so
      * that it can be accessed by the anonymous TAction class.
      */
-    int timerI = 0;
+    int timer1I = 0;
+
+    /**
+     * Timer increment used by the timer loop.  Has to be at class scope so
+     * that it can be accessed by the anonymous TAction class.
+     */
+    int timer2I = 0;
 
     /**
      * Progress bar used by the timer loop.  Has to be at class scope so that
      * it can be accessed by the anonymous TAction class.
      */
-    TProgressBar progressBar;
+    TProgressBar progressBar1;
+
+    /**
+     * Progress bar used by the timer loop.  Has to be at class scope so that
+     * it can be accessed by the anonymous TAction class.
+     */
+    TProgressBar progressBar2;
 
     // ------------------------------------------------------------------------
     // Constructors -----------------------------------------------------------
@@ -108,6 +126,9 @@ public class DemoMainWindow extends TWindow {
         // centered on screen.
         super(parent, i18n.getString("windowTitle"), 0, 0, 64, 23, flags);
 
+        setLayoutManager(new StretchLayoutManager(getWidth() - 2,
+                getHeight() - 2));
+
         int row = 1;
 
         // Add some widgets
@@ -182,7 +203,8 @@ public class DemoMainWindow extends TWindow {
         addButton(i18n.getString("ttableButton1"), 35, row,
             new TAction() {
                 public void DO() {
-                    // TODO
+                    new DemoTableWindow(getApplication(),
+                        i18n.getString("tableWidgetDemo"));
                 }
             }
         );
@@ -230,25 +252,60 @@ public class DemoMainWindow extends TWindow {
         );
 
         row = 15;
-        progressBar = addProgressBar(48, row, 12, 0);
+        progressBar1 = addProgressBar(48, row, 12, 0);
         row++;
         timerLabel = addLabel(i18n.getString("timerLabel"), 48, row);
-        timer = getApplication().addTimer(250, true,
+        timer1 = getApplication().addTimer(250, true,
             new TAction() {
 
                 public void DO() {
                     timerLabel.setLabel(String.format(i18n.
-                            getString("timerText"), timerI));
+                            getString("timerText"), timer1I));
                     timerLabel.setWidth(timerLabel.getLabel().length());
-                    if (timerI < 100) {
-                        timerI++;
+                    if (timer1I < 100) {
+                        timer1I++;
                     } else {
-                        timer.setRecurring(false);
+                        timer1.setRecurring(false);
+                    }
+                    progressBar1.setValue(timer1I);
+                }
+            }
+        );
+
+        row += 2;
+        progressBar2 = addProgressBar(48, row, 12, 0);
+        progressBar2.setLeftBorderChar('\u255e');
+        progressBar2.setRightBorderChar('\u2561');
+        progressBar2.setCompletedChar('\u2592');
+        progressBar2.setRemainingChar('\u2550');
+        row++;
+        timer2 = getApplication().addTimer(125, true,
+            new TAction() {
+
+                public void DO() {
+                    if (timer2I < 100) {
+                        timer2I++;
+                    } else {
+                        timer2.setRecurring(false);
+                    }
+                    progressBar2.setValue(timer2I);
+                }
+            }
+        );
+
+        /*
+        addButton("Exception", 35, row + 3,
+            new TAction() {
+                public void DO() {
+                    try {
+                        throw new RuntimeException("FUBAR'd!");
+                    } catch (Exception e) {
+                        new jexer.TExceptionDialog(getApplication(), e);
                     }
-                    progressBar.setValue(timerI);
                 }
             }
         );
+         */
 
         activate(first);
 
@@ -274,7 +331,8 @@ public class DemoMainWindow extends TWindow {
      */
     @Override
     public void onClose() {
-        getApplication().removeTimer(timer);
+        getApplication().removeTimer(timer1);
+        getApplication().removeTimer(timer2);
     }
 
     /**