From: Matti Tahvonen Date: Tue, 27 Nov 2007 13:22:56 +0000 (+0000) Subject: cleaned demo X-Git-Tag: 6.7.0.beta1~5423 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=35fddf0c349af28af59091cd629dc86d81aea44d;p=vaadin-framework.git cleaned demo svn changeset:3002/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/demo/KeyboardShortcut.java b/src/com/itmill/toolkit/demo/KeyboardShortcut.java index 34aeaf779b..bfc6532805 100644 --- a/src/com/itmill/toolkit/demo/KeyboardShortcut.java +++ b/src/com/itmill/toolkit/demo/KeyboardShortcut.java @@ -1,84 +1,104 @@ package com.itmill.toolkit.demo; +import java.util.Date; + +import com.itmill.toolkit.Application; import com.itmill.toolkit.event.Action; import com.itmill.toolkit.event.ShortcutAction; import com.itmill.toolkit.event.Action.Handler; -import com.itmill.toolkit.ui.AbstractField; import com.itmill.toolkit.ui.Button; +import com.itmill.toolkit.ui.ExpandLayout; import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.OrderedLayout; +import com.itmill.toolkit.ui.Panel; import com.itmill.toolkit.ui.TextField; import com.itmill.toolkit.ui.Window; /** - * Note: This feature is under development and is considered as beta - * - * @author IT Mill Ltd. - * + * Test application for KeyboardShortcuts */ -public class KeyboardShortcut extends com.itmill.toolkit.Application implements - Handler { - private Window main; - - private Button a; - - private Button z; - - private Button x; - - private Button close; - - private AbstractField f; - - Action[] actions = new Action[] { - new ShortcutAction("Button a action", ShortcutAction.KeyCode.A, - new int[] { ShortcutAction.ModifierKey.CTRL, - ShortcutAction.ModifierKey.SHIFT }), - new ShortcutAction("Button z action", ShortcutAction.KeyCode.Z, - new int[] { ShortcutAction.ModifierKey.CTRL, - ShortcutAction.ModifierKey.SHIFT }), - new ShortcutAction("Button x action", ShortcutAction.KeyCode.X, - new int[] { ShortcutAction.ModifierKey.CTRL, - ShortcutAction.ModifierKey.SHIFT }), - new ShortcutAction("Restart ", ShortcutAction.KeyCode.ESCAPE, null) }; +public class KeyboardShortcut extends Application implements Handler { + + private OrderedLayout loki; + + private final Label instructions = new Label( + "

Keyboard shortcuts is a must have feature for applications in a " + + "daily use. In IT Mill toolkit shortcuts are binded to " + + "Panel and its subclasses like Windows (most common place)." + + "

" + + "

Browsers reserve some keyboard combinations for their own" + + " actions, so all combinations cannot be used in web " + + "applications. (see our article on " + + "www.itmill.com)

" + + "Events are attached to Window in this application, so a " + + "component inside window must be focused to fire event on" + + " keyboard shortcut.

" + + "Shortcuts used in this example: " + + "
ESC restarts program, ctrl-shift-a (Button A), " + + "ctrl-shift-z (Button Z), ctrl-shift-x (Button X)", + Label.CONTENT_XHTML); + + private final Action ACTION_A = new ShortcutAction("Button a action", + ShortcutAction.KeyCode.A, new int[] { + ShortcutAction.ModifierKey.CTRL, + ShortcutAction.ModifierKey.SHIFT }); + + private final Action ACTION_Z = new ShortcutAction("Button z action", + ShortcutAction.KeyCode.Z, new int[] { + ShortcutAction.ModifierKey.CTRL, + ShortcutAction.ModifierKey.SHIFT }); + + private final Action ACTION_X = new ShortcutAction("Button x action", + ShortcutAction.KeyCode.X, new int[] { + ShortcutAction.ModifierKey.CTRL, + ShortcutAction.ModifierKey.SHIFT }); + + private final Action ACTION_RESTART = new ShortcutAction("Restart ", + ShortcutAction.KeyCode.ESCAPE, null); + + private Action[] actions = new Action[] { ACTION_A, ACTION_Z, ACTION_X, + ACTION_RESTART }; + + private TextField f; public void init() { - main = new Window("Keyboard shortcuts demo"); - setMainWindow(main); - - main - .addComponent(new Label( - "

Test application for shortcut actions

" - + "

Notes:
" - + "This feature is under development and it's API may still change.
" - + "If events do not work, set focus to Textfield first.
" - + "Browsers may have reserved the keyboard combinations used in " - + "this demo for other purposes.

", - Label.CONTENT_XHTML)); - main - .addComponent(new Label( - "ESC restarts program, ctrl-shift-a clicks A button, " - + "ctrl-shift-z clicks Z button, ctrl-shift-x clicks X button")); + Window w = new Window("Keyboard shortcuts demo"); + ExpandLayout main = new ExpandLayout(); + main.setMargin(true); + main.setSpacing(true); + setMainWindow(w); + w.setLayout(main); - // Restart button - close = new Button("restart", this, "close"); + Panel p = new Panel("Test application for shortcut actions"); + p.addComponent(instructions); - main.addComponent(close); + OrderedLayout buttons = new OrderedLayout( + OrderedLayout.ORIENTATION_HORIZONTAL); - a = new Button("Button A", this, "buttonAHandler"); + // Restart button + Button close = new Button("restart", this, "close"); + Button a = new Button("Button A", this, "actionAHandler"); + Button z = new Button("Button Z", this, "actionZHandler"); + Button x = new Button("Button X", this, "actionXHandler"); + f = new TextField(); - z = new Button("Button Z", this, "buttonZHandler"); + buttons.addComponent(close); - x = new Button("Button X", this, "buttonXHandler"); + buttons.addComponent(a); + buttons.addComponent(z); + buttons.addComponent(x); + buttons.addComponent(f); + p.addComponent(buttons); - f = new TextField("Textfield"); + main.addComponent(p); - main.addComponent(a); - main.addComponent(z); - main.addComponent(x); - main.addComponent(f); + loki = new OrderedLayout(); + main.addComponent(loki); + main.expand(loki); - main.addActionHandler(this); + w.addActionHandler(this); f.focus(); } @@ -88,30 +108,38 @@ public class KeyboardShortcut extends com.itmill.toolkit.Application implements } public void handleAction(Action action, Object sender, Object target) { - if (action == actions[0]) { - buttonAHandler(); + if (action == ACTION_A) { + actionAHandler(); } - if (action == actions[1]) { - buttonZHandler(); + if (action == ACTION_Z) { + actionZHandler(); } - if (action == actions[2]) { - buttonXHandler(); + if (action == ACTION_X) { + actionXHandler(); } - if (action == actions[3]) { - close(); + if (action == ACTION_RESTART) { + actionRestartHandler(); } } - public void buttonAHandler() { - main.addComponent(new Label("Button A handler fired")); + public void actionAHandler() { + log("Button A handler fired"); + } + + public void actionZHandler() { + log("Button Z handler fired"); + } + + public void actionXHandler() { + log("Button X handler fired"); } - public void buttonZHandler() { - main.addComponent(new Label("Button Z handler fired")); + public void actionRestartHandler() { + close(); } - public void buttonXHandler() { - main.addComponent(new Label("Button X handler fired")); + public void log(String s) { + loki.addComponentAsFirst(new Label(new Date() + " : " + s)); } }