diff options
Diffstat (limited to 'src/com/itmill/toolkit/demo/sampler/features/windows/NativeWindowExample.java')
-rw-r--r-- | src/com/itmill/toolkit/demo/sampler/features/windows/NativeWindowExample.java | 85 |
1 files changed, 57 insertions, 28 deletions
diff --git a/src/com/itmill/toolkit/demo/sampler/features/windows/NativeWindowExample.java b/src/com/itmill/toolkit/demo/sampler/features/windows/NativeWindowExample.java index 80c377fb11..43cdfdcc18 100644 --- a/src/com/itmill/toolkit/demo/sampler/features/windows/NativeWindowExample.java +++ b/src/com/itmill/toolkit/demo/sampler/features/windows/NativeWindowExample.java @@ -1,54 +1,83 @@ package com.itmill.toolkit.demo.sampler.features.windows;
+import java.util.Date;
+
import com.itmill.toolkit.terminal.ExternalResource;
import com.itmill.toolkit.ui.Button;
import com.itmill.toolkit.ui.Label;
+import com.itmill.toolkit.ui.Link;
import com.itmill.toolkit.ui.VerticalLayout;
import com.itmill.toolkit.ui.Window;
import com.itmill.toolkit.ui.Button.ClickEvent;
-import com.itmill.toolkit.ui.Window.CloseEvent;
public class NativeWindowExample extends VerticalLayout {
- Window window;
-
public NativeWindowExample() {
-
- // Create the window
- window = new Window("Automatically sized subwindow");
- // Native windows should be explicitly removed from the application
- // when appropriate; in this case when closed:
- window.addListener(new Window.CloseListener() {
- // inline close-listener
- public void windowClose(CloseEvent e) {
- getApplication().removeWindow(window);
- }
- });
-
- // Configure the windows layout; by default a VerticalLayout
- VerticalLayout layout = (VerticalLayout) window.getLayout();
- layout.setMargin(true);
- layout.setSpacing(true);
- // make it undefined for auto-sizing window
- layout.setSizeUndefined();
-
- // Add some content;
- window.addComponent(new Label("This is is native (browser) window."));
+ setSpacing(true);
// Add a button for opening the window
Button open = new Button("Open native window",
new Button.ClickListener() {
// inline click-listener
public void buttonClick(ClickEvent event) {
+ Window window = new NativeWindow();
+ // Add the window to the application
getApplication().addWindow(window);
- getApplication().getMainWindow().open(
- new ExternalResource(window.getURL()),
- "NativeWindowExample", 500, 500,
- Window.BORDER_NONE);
+
+ // Get the URL for the window, and open that in a new
+ // browser window, in this case in a small window.
+ getWindow().open(new ExternalResource(window.getURL()), // URL
+ "_blank", // window name
+ 500, // width
+ 200, // weight
+ Window.BORDER_NONE // decorations
+ );
}
});
addComponent(open);
+ // Add a link for opening sampler in a new window; this will cause
+ // Sampler's getWindow() to create a new Window.
+ Link openSampler = new Link("Open Sampler in a new window",
+ new ExternalResource("#"), // URL
+ "_blank", // window name
+ 700, // width
+ 500, // height
+ Link.TARGET_BORDER_NONE // decorations
+ );
+ addComponent(openSampler);
+
+ }
+
+ /*
+ * We'll be instantiating the same window multiple times, so we'll make an
+ * inner class for separation. You could of course just create a new
+ * Window() and addCompoent to that instead.
+ */
+ class NativeWindow extends Window {
+ NativeWindow() {
+ // Configure the layout
+ VerticalLayout layout = (VerticalLayout) getLayout();
+ layout.setMargin(true);
+ layout.setSpacing(true);
+
+ // Add some content; a label and a close-button
+ Label message = new Label("This is a native window, created at "
+ + new Date());
+ addComponent(message);
+
+ // It's a good idea to remove the window when it's closed (also
+ // when the browser window 'x' is used), unless you explicitly
+ // want the window to persist (if it's not removed from the
+ // application, it can still be retrieved from it's URL.
+ addListener(new CloseListener() {
+ public void windowClose(CloseEvent e) {
+ // remove from application
+ getApplication().removeWindow(NativeWindow.this);
+ }
+ });
+
+ }
}
}
\ No newline at end of file |