X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=sidebyside;f=demos%2FDemo1.java;h=7735b055b80062cdb5d7a79c98b376315029c271;hb=128e5be1ffb65d047d8461ea1cfb65c22686ec91;hp=44333a42b4be7f3a30f93f38c995bf31f5a395c1;hpb=7272e49f35db74caa16eead38aa39a80bb9fc641;p=fanfix.git diff --git a/demos/Demo1.java b/demos/Demo1.java index 44333a4..7735b05 100644 --- a/demos/Demo1.java +++ b/demos/Demo1.java @@ -60,19 +60,18 @@ class DemoCheckboxWindow extends TWindow { addCheckbox(35, row++, "Checkbox 2", true); row += 2; - /* - auto group = addRadioGroup(1, row, "Group 1"); + TRadioGroup group = addRadioGroup(1, row, "Group 1"); group.addRadioButton("Radio option 1"); group.addRadioButton("Radio option 2"); group.addRadioButton("Radio option 3"); - addButton("&Close Window", (width - 14) / 2, height - 4, - { - application.closeWindow(this); + addButton("&Close Window", (getWidth() - 14) / 2, getHeight() - 4, + new TAction() { + public void DO() { + DemoCheckboxWindow.this.getApplication().closeWindow(DemoCheckboxWindow.this); + } } - ); - */ } } @@ -198,10 +197,13 @@ EOS", class DemoMainWindow extends TWindow { - /* // Timer that increments a number private TTimer timer; + // Timer label is updated with timerrr ticks + TLabel timerLabel; + + /* // The modal window is a more low-level example of controlling a window // "from the outside". Most windows will probably subclass TWindow and // do this kind of logic on their own. @@ -217,14 +219,17 @@ class DemoMainWindow extends TWindow { private void modalWindowClose() { application.closeWindow(modalWindow); } + */ - /// We need to override onClose so that the timer will no longer be - /// called after we close the window. TTimers currently are completely - /// unaware of the rest of the UI classes. - override public void onClose() { - application.removeTimer(timer); - } + /** + * We need to override onClose so that the timer will no longer be called + * after we close the window. TTimers currently are completely unaware + * of the rest of the UI classes. */ + @Override + public void onClose() { + getApplication().removeTimer(timer); + } /** * Construct demo window. It will be centered on screen. @@ -233,6 +238,9 @@ class DemoMainWindow extends TWindow { this(parent, CENTERED | RESIZABLE); } + int timerI = 0; + TProgressBar progressBar; + /** * Constructor. */ @@ -267,21 +275,19 @@ class DemoMainWindow extends TWindow { row += 2; - /* addLabel("Variable-width text field:", 1, row); addField(35, row++, 15, false, "Field text"); addLabel("Fixed-width text field:", 1, row); addField(35, row, 15, true); row += 2; - */ if (!isModal()) { addLabel("Radio buttons and checkboxes", 1, row); addButton("&Checkboxes", 35, row, new TAction() { public void DO() { - new DemoCheckboxWindow(getApplication(), MODAL); + new DemoCheckboxWindow(getApplication()); } } ); @@ -328,24 +334,25 @@ class DemoMainWindow extends TWindow { ); } row += 2; + */ - TProgressBar bar = addProgressBar(1, row, 22); + progressBar = addProgressBar(1, row, 22, 0); row++; - TLabel timerLabel = addLabel("Timer", 1, row); - timer = parent.addTimer(100, - { - static int i = 0; - auto writer = appender!dstring(); - formattedWrite(writer, "Timer: %d", i); - timerLabel.text = writer.data; - timerLabel.width = cast(uint)timerLabel.text.length; - if (i < 100) { - i++; + timerLabel = addLabel("Timer", 1, row); + timer = getApplication().addTimer(100, true, + new TAction() { + + public void DO() { + timerLabel.setText(String.format("Timer: %d", timerI)); + timerLabel.setWidth(timerLabel.getText().length()); + if (timerI < 100) { + timerI++; + } + progressBar.setValue(timerI); + DemoMainWindow.this.setRepaint(); } - bar.value = i; - parent.repaint = true; - }, true); - */ + } + ); } }