VerticalLayout windowContent() {
VerticalLayout root = new VerticalLayout();
if (toolbarVisible) {
MenuBar menuBar = MenuBars.getToolBar();
menuBar.setSizeUndefined();
menuBar.setStyleName(toolbarStyle);
Component toolbar = menuBar;
if (toolbarLayout) {
menuBar.setWidth(null);
HorizontalLayout toolbarLayout = new HorizontalLayout();
toolbarLayout.setWidth("100%");
toolbarLayout.setSpacing(true);
Label label = new Label("Tools");
label.setSizeUndefined();
toolbarLayout.addComponents(label, menuBar);
toolbarLayout.setExpandRatio(menuBar, 1);
toolbarLayout.setComponentAlignment(menuBar,
Alignment.TOP_RIGHT);
toolbar = toolbarLayout;
}
toolbar.addStyleName("v-window-top-toolbar");
root.addComponent(toolbar);
}
Component content = null;
if (tabsVisible) {
TabSheet tabs = new TabSheet();
tabs.setSizeFull();
VerticalLayout l = new VerticalLayout();
l.addComponent(new Label(
"<h2>Subtitle</h2><p>Normal type for plain text. Etiam at risus et justo dignissim congue. Phasellus laoreet lorem vel dolor tempus vehicula.</p><p>Quisque ut dolor gravida, placerat libero vel, euismod. Etiam habebis sem dicantur magna mollis euismod. Nihil hic munitissimus habendi senatus locus, nihil horum? Curabitur est gravida et libero vitae dictum. Ullamco laboris nisi ut aliquid ex ea commodi consequat. Morbi odio eros, volutpat ut pharetra vitae, lobortis sed nibh.</p>",
ContentMode.HTML));
l.setMargin(true);
tabs.addTab(l, "Selected");
tabs.addTab(new Label(" ", ContentMode.HTML),
"Another");
tabs.addTab(new Label(" ", ContentMode.HTML),
"One more");
tabs.addStyleName("padded-tabbar");
tabs.addSelectedTabChangeListener(new SelectedTabChangeListener() {
@Override
public void selectedTabChange(
SelectedTabChangeEvent event) {
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
content = tabs;
} else if (!autoHeight) {
Panel p = new Panel();
p.setSizeFull();
p.addStyleName("borderless");
if (!toolbarVisible || !toolbarLayout) {
p.addStyleName("scroll-divider");
}
VerticalLayout l = new VerticalLayout();
l.addComponent(new Label(
"<h2>Subtitle</h2><p>Normal type for plain text. Etiam at risus et justo dignissim congue. Phasellus laoreet lorem vel dolor tempus vehicula.</p><p>Quisque ut dolor gravida, placerat libero vel, euismod. Etiam habebis sem dicantur magna mollis euismod. Nihil hic munitissimus habendi senatus locus, nihil horum? Curabitur est gravida et libero vitae dictum. Ullamco laboris nisi ut aliquid ex ea commodi consequat. Morbi odio eros, volutpat ut pharetra vitae, lobortis sed nibh.</p>",
ContentMode.HTML));
l.setMargin(true);
p.setContent(l);
content = p;
} else {
content = new Label(
"<h2>Subtitle</h2><p>Normal type for plain text. Etiam at risus et justo dignissim congue. Phasellus laoreet lorem vel dolor tempus vehicula.</p><p>Quisque ut dolor gravida, placerat libero vel, euismod. Etiam habebis sem dicantur magna mollis euismod. Nihil hic munitissimus habendi senatus locus, nihil horum? Curabitur est gravida et libero vitae dictum. Ullamco laboris nisi ut aliquid ex ea commodi consequat. Morbi odio eros, volutpat ut pharetra vitae, lobortis sed nibh.</p>",
ContentMode.HTML);
root.setMargin(true);
}
root.addComponent(content);
if (footerVisible) {
HorizontalLayout footer = new HorizontalLayout();
footer.setWidth("100%");
footer.setSpacing(true);
footer.addStyleName("v-window-bottom-toolbar");
Label footerText = new Label("Footer text");
footerText.setSizeUndefined();
Button ok = new Button("OK");
ok.addStyleName("primary");
Button cancel = new Button("Cancel");
footer.addComponents(footerText, ok, cancel);
footer.setExpandRatio(footerText, 1);
if (footerToolbar) {
MenuBar menuBar = MenuBars.getToolBar();
menuBar.setStyleName(toolbarStyle);
menuBar.setWidth(null);
footer.removeAllComponents();
footer.addComponent(menuBar);
}
root.addComponent(footer);
}
if (!autoHeight) {
root.setSizeFull();
root.setExpandRatio(content, 1);
}
return root;
}
{
setSpacing(true);
setMargin(true);
win.setWidth("380px");
win.setHeight(prevHeight);
win.setClosable(false);
win.setResizable(false);
win.setContent(windowContent());
win.setCloseShortcut(KeyCode.ESCAPE, null);
Command optionsCommand = new Command() {
@Override
public void menuSelected(MenuItem selectedItem) {
if (selectedItem.getText().equals("Footer")) {
footerVisible = selectedItem.isChecked();
}
if (selectedItem.getText().equals("Auto Height")) {
autoHeight = selectedItem.isChecked();
if (!autoHeight) {
win.setHeight(prevHeight);
} else {
prevHeight = win.getHeight()
+ win.getHeightUnits().toString();
win.setHeight(null);
}
}
if (selectedItem.getText().equals("Tabs")) {
tabsVisible = selectedItem.isChecked();
}
if (selectedItem.getText().equals("Top Toolbar")) {
toolbarVisible = selectedItem.isChecked();
}
if (selectedItem.getText().equals("Footer Toolbar")) {
footerToolbar = selectedItem.isChecked();
}
if (selectedItem.getText().equals("Top Toolbar layout")) {
toolbarLayout = selectedItem.isChecked();
}
if (selectedItem.getText()
.equals("Borderless Toolbars")) {
toolbarStyle = selectedItem.isChecked() ? "borderless"
: null;
}
win.setContent(windowContent());
}
};
MenuBar options = new MenuBar();
options.setCaption("Content");
options.addItem("Auto Height", optionsCommand).setCheckable(
true);
options.addItem("Tabs", optionsCommand).setCheckable(true);
MenuItem option = options.addItem("Footer", optionsCommand);
option.setCheckable(true);
option.setChecked(true);
options.addStyleName("small");
addComponent(options);
options = new MenuBar();
options.setCaption("Toolbars");
options.addItem("Footer Toolbar", optionsCommand).setCheckable(
true);
options.addItem("Top Toolbar", optionsCommand).setCheckable(
true);
options.addItem("Top Toolbar layout", optionsCommand)
.setCheckable(true);
options.addItem("Borderless Toolbars", optionsCommand)
.setCheckable(true);
options.addStyleName("small");
addComponent(options);
Command optionsCommand2 = new Command() {
@Override
public void menuSelected(MenuItem selectedItem) {
if (selectedItem.getText().equals("Caption")) {
win.setCaption(selectedItem.isChecked() ? "Window Caption"
: null);
} else if (selectedItem.getText().equals("Closable")) {
win.setClosable(selectedItem.isChecked());
} else if (selectedItem.getText().equals("Resizable")) {
win.setResizable(selectedItem.isChecked());
} else if (selectedItem.getText().equals("Modal")) {
win.setModal(selectedItem.isChecked());
}
}
};
options = new MenuBar();
options.setCaption("Options");
MenuItem caption = options.addItem("Caption", optionsCommand2);
caption.setCheckable(true);
caption.setChecked(true);
options.addItem("Closable", optionsCommand2).setCheckable(true);
options.addItem("Resizable", optionsCommand2)
.setCheckable(true);
options.addItem("Modal", optionsCommand2).setCheckable(true);
options.addStyleName("small");
addComponent(options);
final Button show = new Button("Open Window",
new ClickListener() {
@Override