X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fdemos%2FDemoMainWindow.java;h=8f77448b29f45c65cd67e52c38268e0564ad1e0d;hb=505be508ae7d3fb48122be548b310a238cfb91eb;hp=5433d44924006ccdfad3b59e4ee96da9f41c9dc2;hpb=1dac6b8d395e2bf3c1b58915f8f4f481d9e46793;p=nikiroo-utils.git diff --git a/src/jexer/demos/DemoMainWindow.java b/src/jexer/demos/DemoMainWindow.java index 5433d44..8f77448 100644 --- a/src/jexer/demos/DemoMainWindow.java +++ b/src/jexer/demos/DemoMainWindow.java @@ -31,9 +31,6 @@ package jexer.demos; import java.io.File; import java.io.IOException; import java.text.MessageFormat; -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.Locale; import java.util.ResourceBundle; import jexer.TAction; @@ -47,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.*; @@ -68,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. @@ -79,24 +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; /** - * Progress bar used by the timer loop. Has to be at class scope so that - * it can be accessed by the anonymous TAction class. + * Timer increment used by the timer loop. Has to be at class scope so + * that it can be accessed by the anonymous TAction class. */ - TProgressBar progressBar; + int timer2I = 0; /** - * Day of week label is updated with TSpinner clicks. + * Progress bar used by the timer loop. Has to be at class scope so that + * it can be accessed by the anonymous TAction class. */ - TLabel dayOfWeekLabel; + TProgressBar progressBar1; /** - * Day of week to demonstrate TSpinner. Has to be at class scope so that + * Progress bar used by the timer loop. Has to be at class scope so that * it can be accessed by the anonymous TAction class. */ - GregorianCalendar calendar = new GregorianCalendar(); + TProgressBar progressBar2; // ------------------------------------------------------------------------ // Constructors ----------------------------------------------------------- @@ -120,7 +124,10 @@ public class DemoMainWindow extends TWindow { private DemoMainWindow(final TApplication parent, final int flags) { // Construct a demo window. X and Y don't matter because it will be // centered on screen. - super(parent, i18n.getString("windowTitle"), 0, 0, 64, 25, flags); + super(parent, i18n.getString("windowTitle"), 0, 0, 64, 23, flags); + + setLayoutManager(new StretchLayoutManager(getWidth() - 2, + getHeight() - 2)); int row = 1; @@ -196,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")); } } ); @@ -242,54 +250,62 @@ public class DemoMainWindow extends TWindow { } } ); - row += 2; - progressBar = addProgressBar(1, row, 22, 0); + row = 15; + progressBar1 = addProgressBar(48, row, 12, 0); row++; - timerLabel = addLabel(i18n.getString("timerLabel"), 1, row); - timer = getApplication().addTimer(250, true, + timerLabel = addLabel(i18n.getString("timerLabel"), 48, row); + 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); } - progressBar.setValue(timerI); + progressBar1.setValue(timer1I); } } ); - dayOfWeekLabel = addLabel("Wednesday-", 35, row - 1, "tmenu", false); - dayOfWeekLabel.setLabel(String.format("%-10s", - calendar.getDisplayName(Calendar.DAY_OF_WEEK, - Calendar.LONG, Locale.getDefault()))); - - addSpinner(35 + dayOfWeekLabel.getWidth(), row - 1, + 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() { - calendar.add(Calendar.DAY_OF_WEEK, 1); - dayOfWeekLabel.setLabel(String.format("%-10s", - calendar.getDisplayName( - Calendar.DAY_OF_WEEK, Calendar.LONG, - Locale.getDefault()))); + if (timer2I < 100) { + timer2I++; + } else { + timer2.setRecurring(false); + } + progressBar2.setValue(timer2I); } - }, + } + ); + + /* + addButton("Exception", 35, row + 3, new TAction() { public void DO() { - calendar.add(Calendar.DAY_OF_WEEK, -1); - dayOfWeekLabel.setLabel(String.format("%-10s", - calendar.getDisplayName( - Calendar.DAY_OF_WEEK, Calendar.LONG, - Locale.getDefault()))); + try { + throw new RuntimeException("FUBAR'd!"); + } catch (Exception e) { + new jexer.TExceptionDialog(getApplication(), e); + } } } ); - + */ activate(first); @@ -315,7 +331,8 @@ public class DemoMainWindow extends TWindow { */ @Override public void onClose() { - getApplication().removeTimer(timer); + getApplication().removeTimer(timer1); + getApplication().removeTimer(timer2); } /**