You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NativeWindowing.java 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Copyright 2000-2013 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests;
  17. import java.net.MalformedURLException;
  18. import java.net.URL;
  19. import com.vaadin.server.LegacyApplication;
  20. import com.vaadin.shared.ui.label.ContentMode;
  21. import com.vaadin.ui.Button;
  22. import com.vaadin.ui.Button.ClickEvent;
  23. import com.vaadin.ui.Label;
  24. import com.vaadin.ui.LegacyWindow;
  25. import com.vaadin.ui.VerticalLayout;
  26. import com.vaadin.ui.Window;
  27. public class NativeWindowing extends LegacyApplication {
  28. LegacyWindow main = new LegacyWindow("Windowing test");
  29. @Override
  30. public void init() {
  31. setMainWindow(main);
  32. main.addComponent(new Button("Add new subwindow",
  33. new Button.ClickListener() {
  34. @Override
  35. public void buttonClick(ClickEvent event) {
  36. VerticalLayout layout = new VerticalLayout();
  37. layout.setMargin(true);
  38. final Window w = new Window("sw "
  39. + System.currentTimeMillis(), layout);
  40. main.addWindow(w);
  41. w.setPositionX(100);
  42. w.setPositionY(100);
  43. w.setWidth("200px");
  44. w.setHeight("200px");
  45. w.setWidth("100px");
  46. w.setHeight("400px");
  47. final Button closebutton = new Button("Close "
  48. + w.getCaption(), new Button.ClickListener() {
  49. @Override
  50. public void buttonClick(ClickEvent event) {
  51. main.removeWindow(w);
  52. }
  53. });
  54. layout.addComponent(closebutton);
  55. layout.addComponent(new Label(
  56. "<p>Lorem ipsum dolor sit amet.</p>"
  57. + "<p>Lorem ipsum dolor sit amet.</p>"
  58. + "<p>Lorem ipsum dolor sit amet.</p>"
  59. + "<p>Lorem ipsum dolor sit amet.</p>"
  60. + "<p>Lorem ipsum dolor sit amet.</p>"
  61. + "<p>Lorem ipsum dolor sit amet.</p>"
  62. + "<p>Lorem ipsum dolor sit amet.</p>"
  63. + "<p>Lorem ipsum dolor sit amet.</p>"
  64. + "<p>Lorem ipsum dolor sit amet.</p>"
  65. + "<p>Lorem ipsum dolor sit amet.</p>"
  66. + "<p>Lorem ipsum dolor sit amet.</p>"
  67. + "<p>Lorem ipsum dolor sit amet.</p>"
  68. + "<p>Lorem ipsum dolor sit amet.</p>"
  69. + "<p>Lorem ipsum dolor sit amet.</p>"
  70. + "<p>Lorem ipsum dolor sit amet.</p>"
  71. + "<p>Lorem ipsum dolor sit amet.</p>"
  72. + "<p>Lorem ipsum dolor sit amet.</p>"
  73. + "<p>Lorem ipsum dolor sit amet.</p>"
  74. + "<p>Lorem ipsum dolor sit amet.</p>"
  75. + "<p>Lorem ipsum dolor sit amet.</p>"
  76. + "<p>Lorem ipsum dolor sit amet.</p>"
  77. + "<p>Lorem ipsum dolor sit amet.</p>",
  78. ContentMode.HTML));
  79. }
  80. }));
  81. main.addComponent(new Button(
  82. "Open a currently uncreated application level window",
  83. new Button.ClickListener() {
  84. @Override
  85. public void buttonClick(ClickEvent event) {
  86. try {
  87. main.open(
  88. new com.vaadin.server.ExternalResource(
  89. new URL(
  90. getURL(),
  91. "mainwin-"
  92. + System.currentTimeMillis()
  93. + "/")), null);
  94. } catch (final MalformedURLException e) {
  95. }
  96. }
  97. }));
  98. main.addComponent(new Button(
  99. "Commit (saves window state: size, place, scrollpos)"));
  100. }
  101. @Override
  102. public LegacyWindow getWindow(String name) {
  103. final LegacyWindow w = super.getWindow(name);
  104. if (w != null) {
  105. return w;
  106. }
  107. if (name != null && name.startsWith("mainwin-")) {
  108. final String postfix = name.substring("mainwin-".length());
  109. final LegacyWindow ww = new LegacyWindow("Window: " + postfix);
  110. ww.setName(name);
  111. ww.addComponent(new Label(
  112. "This is a application-level window opened with name: "
  113. + name));
  114. ww.addComponent(new Button("Click me", new Button.ClickListener() {
  115. int state = 0;
  116. @Override
  117. public void buttonClick(ClickEvent event) {
  118. ww.addComponent(new Label("Button clicked " + (++state)
  119. + " times"));
  120. }
  121. }));
  122. addWindow(ww);
  123. return ww;
  124. }
  125. return null;
  126. }
  127. }