From 83c5673c3c4965aa36c498a6ef335dc21bf04409 Mon Sep 17 00:00:00 2001 From: Marc Englund Date: Thu, 29 Nov 2007 12:45:42 +0000 Subject: [PATCH] Examples added. svn changeset:3037/svn branch:trunk --- .../EmbeddedBrowserExample.java | 15 +++- .../demo/featurebrowser/FeatureBrowser.java | 2 +- .../featurebrowser/NotificationExample.java | 2 + .../demo/featurebrowser/WindowingExample.java | 73 +++++++++++++++++-- 4 files changed, 82 insertions(+), 10 deletions(-) diff --git a/src/com/itmill/toolkit/demo/featurebrowser/EmbeddedBrowserExample.java b/src/com/itmill/toolkit/demo/featurebrowser/EmbeddedBrowserExample.java index ebbbbce16b..7bebaf38c3 100644 --- a/src/com/itmill/toolkit/demo/featurebrowser/EmbeddedBrowserExample.java +++ b/src/com/itmill/toolkit/demo/featurebrowser/EmbeddedBrowserExample.java @@ -23,6 +23,13 @@ public class EmbeddedBrowserExample extends ExpandLayout implements Embedded emb = new Embedded(); public EmbeddedBrowserExample() { + this(new String[] { DEFAULT_URL, + "http:// www.itmill.com/index_developers.htm", + "http://toolkit.itmill.com/demo/doc/api/", + "http://www.itmill.com/manual/index.html" }); + } + + public EmbeddedBrowserExample(String[] urls) { setSizeFull(); // create the address combobox @@ -34,14 +41,14 @@ public class EmbeddedBrowserExample extends ExpandLayout implements // no 'go' -button clicking necessary select.setImmediate(true); // add some pre-configured URLs - select.addItem(DEFAULT_URL); - select.addItem("http://www.google.com"); - select.addItem("http://toolkit.itmill.com/demo"); + for (int i = 0; i < urls.length; i++) { + select.addItem(urls[i]); + } // add to layout addComponent(select); // add listener and select initial URL select.addListener(this); - select.setValue(DEFAULT_URL); + select.setValue(urls[0]); // configure the embedded and add to layout emb.setType(Embedded.TYPE_BROWSER); diff --git a/src/com/itmill/toolkit/demo/featurebrowser/FeatureBrowser.java b/src/com/itmill/toolkit/demo/featurebrowser/FeatureBrowser.java index b5dba0ee0c..365b86299b 100644 --- a/src/com/itmill/toolkit/demo/featurebrowser/FeatureBrowser.java +++ b/src/com/itmill/toolkit/demo/featurebrowser/FeatureBrowser.java @@ -49,7 +49,7 @@ public class FeatureBrowser extends com.itmill.toolkit.Application implements // Intro { "Intro", "About", "About this demo", Button.class, Boolean.FALSE }, // Windowing - { "Intro", "Windowing", "About windowing", Button.class, + { "Intro", "Windowing", "About windowing", WindowingExample.class, Boolean.FALSE }, // Basic: Labels { "Basic", "Labels", "Some variations of Labels", Button.class, diff --git a/src/com/itmill/toolkit/demo/featurebrowser/NotificationExample.java b/src/com/itmill/toolkit/demo/featurebrowser/NotificationExample.java index c007df8e74..f0f8e2ac54 100644 --- a/src/com/itmill/toolkit/demo/featurebrowser/NotificationExample.java +++ b/src/com/itmill/toolkit/demo/featurebrowser/NotificationExample.java @@ -86,5 +86,7 @@ public class NotificationExample extends CustomComponent { } }); main.addComponent(b); + main.setComponentAlignment(b, OrderedLayout.ALIGNMENT_RIGHT, + OrderedLayout.ALIGNMENT_VERTICAL_CENTER); } } diff --git a/src/com/itmill/toolkit/demo/featurebrowser/WindowingExample.java b/src/com/itmill/toolkit/demo/featurebrowser/WindowingExample.java index 2871aef769..891e450dbe 100644 --- a/src/com/itmill/toolkit/demo/featurebrowser/WindowingExample.java +++ b/src/com/itmill/toolkit/demo/featurebrowser/WindowingExample.java @@ -3,8 +3,15 @@ */ package com.itmill.toolkit.demo.featurebrowser; +import java.net.URL; + +import com.itmill.toolkit.terminal.ExternalResource; +import com.itmill.toolkit.ui.Button; import com.itmill.toolkit.ui.CustomComponent; +import com.itmill.toolkit.ui.Label; import com.itmill.toolkit.ui.OrderedLayout; +import com.itmill.toolkit.ui.Window; +import com.itmill.toolkit.ui.Button.ClickEvent; /** * @author marc @@ -12,17 +19,73 @@ import com.itmill.toolkit.ui.OrderedLayout; */ public class WindowingExample extends CustomComponent { - public static final String txt = "There are two main types of windows:"; + public static final String txt = "

There are two main types of windows: application-level windows, and" + + "\"subwindows\".

A subwindow is rendered as a \"inline\" popup window" + + " within the (native) browser window to which it was added. You can create" + + " a subwindow by creating a new Window and adding it to a application-level window, for instance" + + " your main window.

In contrast, you create a application-level window by" + + " creating a new Window and adding it to the Application. Application-level" + + " windows are not shown by default - you need to open a browser window for" + + " the url representing the window. You can think of the application-level" + + " windows as separate views into your application - and a way to create a" + + " \"native\" browser window.

Depending on your needs, it's also" + + " possible to create a new window instance (with it's own internal state)" + + " for each new (native) browser window, or you can share the same instance" + + " (and state) between several browser windows (the latter is most useful" + + " for read-only views).

"; - /* - * application-level windows, and - * - */ + private URL windowUrl = null; public WindowingExample() { OrderedLayout main = new OrderedLayout(); + main.setMargin(true); setCompositionRoot(main); + Label l = new Label(txt); + l.setContentMode(Label.CONTENT_XHTML); + main.addComponent(l); + + main.addComponent(new Button("Create a new subwindow", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + Window w = new Window("Subwindow"); + Label l = new Label(txt); + l.setContentMode(Label.CONTENT_XHTML); + w.addComponent(l); + getApplication().getMainWindow().addWindow(w); + } + })); + main.addComponent(new Button( + "Open a application-level window, with shared state", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + if (windowUrl == null) { + Window w = new Window("Subwindow"); + Label l = new Label(txt); + l.setContentMode(Label.CONTENT_XHTML); + w.addComponent(l); + getApplication().addWindow(w); + windowUrl = w.getURL(); + } + getApplication().getMainWindow().open( + new ExternalResource(windowUrl), "_new"); + } + })); + main.addComponent(new Button( + "Create a new application-level window, with it's own state", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + Window w = new Window("Subwindow"); + getApplication().addWindow(w); + Label l = new Label(w.getName()); + l + .setCaption("Each opened window has a separate value:"); + w.addComponent(l); + getApplication().getMainWindow().open( + new ExternalResource(w.getURL()), "_new"); + } + })); + } } -- 2.39.5