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.

Window.java 46KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434
  1. /*
  2. * Copyright 2000-2016 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.ui;
  17. import java.io.Serializable;
  18. import java.lang.reflect.Method;
  19. import java.util.ArrayList;
  20. import java.util.Arrays;
  21. import java.util.Collection;
  22. import java.util.Collections;
  23. import java.util.List;
  24. import java.util.Map;
  25. import org.jsoup.nodes.Element;
  26. import org.jsoup.select.Elements;
  27. import com.vaadin.event.FieldEvents.BlurEvent;
  28. import com.vaadin.event.FieldEvents.BlurListener;
  29. import com.vaadin.event.FieldEvents.BlurNotifier;
  30. import com.vaadin.event.FieldEvents.FocusEvent;
  31. import com.vaadin.event.FieldEvents.FocusListener;
  32. import com.vaadin.event.FieldEvents.FocusNotifier;
  33. import com.vaadin.event.MouseEvents.ClickEvent;
  34. import com.vaadin.event.ShortcutAction;
  35. import com.vaadin.event.ShortcutAction.KeyCode;
  36. import com.vaadin.event.ShortcutAction.ModifierKey;
  37. import com.vaadin.event.ShortcutListener;
  38. import com.vaadin.server.PaintException;
  39. import com.vaadin.server.PaintTarget;
  40. import com.vaadin.shared.Connector;
  41. import com.vaadin.shared.MouseEventDetails;
  42. import com.vaadin.shared.Registration;
  43. import com.vaadin.shared.ui.window.WindowMode;
  44. import com.vaadin.shared.ui.window.WindowRole;
  45. import com.vaadin.shared.ui.window.WindowServerRpc;
  46. import com.vaadin.shared.ui.window.WindowState;
  47. import com.vaadin.ui.declarative.DesignAttributeHandler;
  48. import com.vaadin.ui.declarative.DesignContext;
  49. import com.vaadin.ui.declarative.DesignException;
  50. import com.vaadin.util.ReflectTools;
  51. /**
  52. * A component that represents a floating popup window that can be added to a
  53. * {@link UI}. A window is added to a {@code UI} using
  54. * {@link UI#addWindow(Window)}.
  55. * </p>
  56. * <p>
  57. * The contents of a window is set using {@link #setContent(Component)} or by
  58. * using the {@link #Window(String, Component)} constructor.
  59. * </p>
  60. * <p>
  61. * A window can be positioned on the screen using absolute coordinates (pixels)
  62. * or set to be centered using {@link #center()}
  63. * </p>
  64. * <p>
  65. * The caption is displayed in the window header.
  66. * </p>
  67. * <p>
  68. * In Vaadin versions prior to 7.0.0, Window was also used as application level
  69. * windows. This function is now covered by the {@link UI} class.
  70. * </p>
  71. *
  72. * @author Vaadin Ltd.
  73. * @since 3.0
  74. */
  75. @SuppressWarnings({ "serial", "deprecation" })
  76. public class Window extends Panel
  77. implements FocusNotifier, BlurNotifier, LegacyComponent {
  78. private WindowServerRpc rpc = new WindowServerRpc() {
  79. @Override
  80. public void click(MouseEventDetails mouseDetails) {
  81. fireEvent(new ClickEvent(Window.this, mouseDetails));
  82. }
  83. @Override
  84. public void windowModeChanged(WindowMode newState) {
  85. setWindowMode(newState);
  86. }
  87. @Override
  88. public void windowMoved(int x, int y) {
  89. if (x != getState(false).positionX) {
  90. setPositionX(x);
  91. }
  92. if (y != getState(false).positionY) {
  93. setPositionY(y);
  94. }
  95. }
  96. };
  97. /**
  98. * Holds registered CloseShortcut instances for query and later removal
  99. */
  100. private List<CloseShortcut> closeShortcuts = new ArrayList<>(4);
  101. /**
  102. * Creates a new, empty window
  103. */
  104. public Window() {
  105. this("", null);
  106. }
  107. /**
  108. * Creates a new, empty window with a given title.
  109. *
  110. * @param caption
  111. * the title of the window.
  112. */
  113. public Window(String caption) {
  114. this(caption, null);
  115. }
  116. /**
  117. * Creates a new, empty window with the given content and title.
  118. *
  119. * @param caption
  120. * the title of the window.
  121. * @param content
  122. * the contents of the window
  123. */
  124. public Window(String caption, Component content) {
  125. super(caption, content);
  126. registerRpc(rpc);
  127. setSizeUndefined();
  128. setCloseShortcut(KeyCode.ESCAPE);
  129. }
  130. /* ********************************************************************* */
  131. /*
  132. * (non-Javadoc)
  133. *
  134. * @see com.vaadin.ui.Panel#paintContent(com.vaadin.server.PaintTarget)
  135. */
  136. @Override
  137. public synchronized void paintContent(PaintTarget target)
  138. throws PaintException {
  139. if (bringToFront != null) {
  140. target.addAttribute("bringToFront", bringToFront.intValue());
  141. bringToFront = null;
  142. }
  143. // Contents of the window panel is painted
  144. super.paintContent(target);
  145. }
  146. /*
  147. * (non-Javadoc)
  148. *
  149. * @see com.vaadin.ui.AbstractComponent#setParent(com.vaadin.server.
  150. * ClientConnector )
  151. */
  152. @Override
  153. public void setParent(HasComponents parent) {
  154. if (parent == null || parent instanceof UI) {
  155. super.setParent(parent);
  156. } else {
  157. throw new IllegalArgumentException(
  158. "A Window can only be added to a UI using UI.addWindow(Window window)");
  159. }
  160. }
  161. /*
  162. * (non-Javadoc)
  163. *
  164. * @see com.vaadin.ui.Panel#changeVariables(java.lang.Object, java.util.Map)
  165. */
  166. @Override
  167. public void changeVariables(Object source, Map<String, Object> variables) {
  168. // TODO Are these for top level windows or sub windows?
  169. boolean sizeHasChanged = false;
  170. // size is handled in super class, but resize events only in windows ->
  171. // so detect if size change occurs before super.changeVariables()
  172. if (variables.containsKey("height") && (getHeightUnits() != Unit.PIXELS
  173. || (Integer) variables.get("height") != getHeight())) {
  174. sizeHasChanged = true;
  175. }
  176. if (variables.containsKey("width") && (getWidthUnits() != Unit.PIXELS
  177. || (Integer) variables.get("width") != getWidth())) {
  178. sizeHasChanged = true;
  179. }
  180. super.changeVariables(source, variables);
  181. // Positioning
  182. final Integer positionx = (Integer) variables.get("positionx");
  183. if (positionx != null) {
  184. final int x = positionx.intValue();
  185. // This is information from the client so it is already using the
  186. // position. No need to repaint.
  187. setPositionX(x < 0 ? -1 : x);
  188. }
  189. final Integer positiony = (Integer) variables.get("positiony");
  190. if (positiony != null) {
  191. final int y = positiony.intValue();
  192. // This is information from the client so it is already using the
  193. // position. No need to repaint.
  194. setPositionY(y < 0 ? -1 : y);
  195. }
  196. if (isClosable()) {
  197. // Closing
  198. final Boolean close = (Boolean) variables.get("close");
  199. if (close != null && close.booleanValue()) {
  200. close();
  201. }
  202. }
  203. // fire event if size has really changed
  204. if (sizeHasChanged) {
  205. fireResize();
  206. }
  207. if (variables.containsKey(FocusEvent.EVENT_ID)) {
  208. fireEvent(new FocusEvent(this));
  209. } else if (variables.containsKey(BlurEvent.EVENT_ID)) {
  210. fireEvent(new BlurEvent(this));
  211. }
  212. }
  213. /**
  214. * Method that handles window closing (from UI).
  215. *
  216. * <p>
  217. * By default, windows are removed from their respective UIs and thus
  218. * visually closed on browser-side.
  219. * </p>
  220. *
  221. * <p>
  222. * To react to a window being closed (after it is closed), register a
  223. * {@link CloseListener}.
  224. * </p>
  225. */
  226. public void close() {
  227. UI uI = getUI();
  228. // Don't do anything if not attached to a UI
  229. if (uI != null) {
  230. // window is removed from the UI
  231. uI.removeWindow(this);
  232. }
  233. }
  234. /**
  235. * Gets the distance of Window left border in pixels from left border of the
  236. * containing (main window) when the window is in {@link WindowMode#NORMAL}.
  237. *
  238. * @return the Distance of Window left border in pixels from left border of
  239. * the containing (main window).or -1 if unspecified
  240. * @since 4.0.0
  241. */
  242. public int getPositionX() {
  243. return getState(false).positionX;
  244. }
  245. /**
  246. * Sets the position of the window on the screen using
  247. * {@link #setPositionX(int)} and {@link #setPositionY(int)}
  248. *
  249. * @since 7.5
  250. * @param x
  251. * The new x coordinate for the window
  252. * @param y
  253. * The new y coordinate for the window
  254. */
  255. public void setPosition(int x, int y) {
  256. setPositionX(x);
  257. setPositionY(y);
  258. }
  259. /**
  260. * Sets the distance of Window left border in pixels from left border of the
  261. * containing (main window). Has effect only if in {@link WindowMode#NORMAL}
  262. * mode.
  263. *
  264. * @param positionX
  265. * the Distance of Window left border in pixels from left border
  266. * of the containing (main window). or -1 if unspecified.
  267. * @since 4.0.0
  268. */
  269. public void setPositionX(int positionX) {
  270. getState().positionX = positionX;
  271. getState().centered = false;
  272. }
  273. /**
  274. * Gets the distance of Window top border in pixels from top border of the
  275. * containing (main window) when the window is in {@link WindowMode#NORMAL}
  276. * state, or when next set to that state.
  277. *
  278. * @return Distance of Window top border in pixels from top border of the
  279. * containing (main window). or -1 if unspecified
  280. *
  281. * @since 4.0.0
  282. */
  283. public int getPositionY() {
  284. return getState(false).positionY;
  285. }
  286. /**
  287. * Sets the distance of Window top border in pixels from top border of the
  288. * containing (main window). Has effect only if in {@link WindowMode#NORMAL}
  289. * mode.
  290. *
  291. * @param positionY
  292. * the Distance of Window top border in pixels from top border of
  293. * the containing (main window). or -1 if unspecified
  294. *
  295. * @since 4.0.0
  296. */
  297. public void setPositionY(int positionY) {
  298. getState().positionY = positionY;
  299. getState().centered = false;
  300. }
  301. private static final Method WINDOW_CLOSE_METHOD;
  302. static {
  303. try {
  304. WINDOW_CLOSE_METHOD = CloseListener.class
  305. .getDeclaredMethod("windowClose", CloseEvent.class);
  306. } catch (final java.lang.NoSuchMethodException e) {
  307. // This should never happen
  308. throw new java.lang.RuntimeException(
  309. "Internal error, window close method not found");
  310. }
  311. }
  312. public static class CloseEvent extends Component.Event {
  313. /**
  314. *
  315. * @param source
  316. */
  317. public CloseEvent(Component source) {
  318. super(source);
  319. }
  320. /**
  321. * Gets the Window.
  322. *
  323. * @return the window.
  324. */
  325. public Window getWindow() {
  326. return (Window) getSource();
  327. }
  328. }
  329. /**
  330. * An interface used for listening to Window close events. Add the
  331. * CloseListener to a window and
  332. * {@link CloseListener#windowClose(CloseEvent)} will be called whenever the
  333. * user closes the window.
  334. *
  335. * <p>
  336. * Since Vaadin 6.5, removing a window using {@link #removeWindow(Window)}
  337. * fires the CloseListener.
  338. * </p>
  339. */
  340. public interface CloseListener extends Serializable {
  341. /**
  342. * Called when the user closes a window. Use
  343. * {@link CloseEvent#getWindow()} to get a reference to the
  344. * {@link Window} that was closed.
  345. *
  346. * @param e
  347. * Event containing
  348. */
  349. public void windowClose(CloseEvent e);
  350. }
  351. /**
  352. * Adds a CloseListener to the window.
  353. *
  354. * For a window the CloseListener is fired when the user closes it (clicks
  355. * on the close button).
  356. *
  357. * For a browser level window the CloseListener is fired when the browser
  358. * level window is closed. Note that closing a browser level window does not
  359. * mean it will be destroyed. Also note that Opera does not send events like
  360. * all other browsers and therefore the close listener might not be called
  361. * if Opera is used.
  362. *
  363. * <p>
  364. * Since Vaadin 6.5, removing windows using {@link #removeWindow(Window)}
  365. * does fire the CloseListener.
  366. * </p>
  367. *
  368. * @param listener
  369. * the CloseListener to add, not null
  370. */
  371. public Registration addCloseListener(CloseListener listener) {
  372. return addListener(CloseEvent.class, listener, WINDOW_CLOSE_METHOD);
  373. }
  374. /**
  375. * Removes the CloseListener from the window.
  376. *
  377. * <p>
  378. * For more information on CloseListeners see {@link CloseListener}.
  379. * </p>
  380. *
  381. * @param listener
  382. * the CloseListener to remove.
  383. */
  384. @Deprecated
  385. public void removeCloseListener(CloseListener listener) {
  386. removeListener(CloseEvent.class, listener, WINDOW_CLOSE_METHOD);
  387. }
  388. protected void fireClose() {
  389. fireEvent(new Window.CloseEvent(this));
  390. }
  391. /**
  392. * Event which is fired when the mode of the Window changes.
  393. *
  394. * @author Vaadin Ltd
  395. * @since 7.1
  396. *
  397. */
  398. public static class WindowModeChangeEvent extends Component.Event {
  399. private final WindowMode windowMode;
  400. /**
  401. *
  402. * @param source
  403. */
  404. public WindowModeChangeEvent(Component source, WindowMode windowMode) {
  405. super(source);
  406. this.windowMode = windowMode;
  407. }
  408. /**
  409. * Gets the Window.
  410. *
  411. * @return the window
  412. */
  413. public Window getWindow() {
  414. return (Window) getSource();
  415. }
  416. /**
  417. * Gets the new window mode.
  418. *
  419. * @return the new mode
  420. */
  421. public WindowMode getWindowMode() {
  422. return windowMode;
  423. }
  424. }
  425. /**
  426. * An interface used for listening to Window maximize / restore events. Add
  427. * the WindowModeChangeListener to a window and
  428. * {@link WindowModeChangeListener#windowModeChanged(WindowModeChangeEvent)}
  429. * will be called whenever the window is maximized (
  430. * {@link WindowMode#MAXIMIZED}) or restored ({@link WindowMode#NORMAL} ).
  431. */
  432. public interface WindowModeChangeListener extends Serializable {
  433. public static final Method windowModeChangeMethod = ReflectTools
  434. .findMethod(WindowModeChangeListener.class, "windowModeChanged",
  435. WindowModeChangeEvent.class);
  436. /**
  437. * Called when the user maximizes / restores a window. Use
  438. * {@link WindowModeChangeEvent#getWindow()} to get a reference to the
  439. * {@link Window} that was maximized / restored. Use
  440. * {@link WindowModeChangeEvent#getWindowMode()} to get a reference to
  441. * the new state.
  442. *
  443. * @param event
  444. */
  445. public void windowModeChanged(WindowModeChangeEvent event);
  446. }
  447. /**
  448. * Adds a WindowModeChangeListener to the window.
  449. *
  450. * The WindowModeChangeEvent is fired when the user changed the display
  451. * state by clicking the maximize/restore button or by double clicking on
  452. * the window header. The event is also fired if the state is changed using
  453. * {@link #setWindowMode(WindowMode)}.
  454. *
  455. * @param listener
  456. * the WindowModeChangeListener to add.
  457. */
  458. public Registration addWindowModeChangeListener(
  459. WindowModeChangeListener listener) {
  460. return addListener(WindowModeChangeEvent.class, listener,
  461. WindowModeChangeListener.windowModeChangeMethod);
  462. }
  463. /**
  464. * Removes the WindowModeChangeListener from the window.
  465. *
  466. * @param listener
  467. * the WindowModeChangeListener to remove.
  468. */
  469. @Deprecated
  470. public void removeWindowModeChangeListener(
  471. WindowModeChangeListener listener) {
  472. removeListener(WindowModeChangeEvent.class, listener,
  473. WindowModeChangeListener.windowModeChangeMethod);
  474. }
  475. protected void fireWindowWindowModeChange() {
  476. fireEvent(
  477. new Window.WindowModeChangeEvent(this, getState().windowMode));
  478. }
  479. /**
  480. * Method for the resize event.
  481. */
  482. private static final Method WINDOW_RESIZE_METHOD;
  483. static {
  484. try {
  485. WINDOW_RESIZE_METHOD = ResizeListener.class
  486. .getDeclaredMethod("windowResized", ResizeEvent.class);
  487. } catch (final java.lang.NoSuchMethodException e) {
  488. // This should never happen
  489. throw new java.lang.RuntimeException(
  490. "Internal error, window resized method not found");
  491. }
  492. }
  493. /**
  494. * Resize events are fired whenever the client-side fires a resize-event
  495. * (e.g. the browser window is resized). The frequency may vary across
  496. * browsers.
  497. */
  498. public static class ResizeEvent extends Component.Event {
  499. /**
  500. *
  501. * @param source
  502. */
  503. public ResizeEvent(Component source) {
  504. super(source);
  505. }
  506. /**
  507. * Get the window form which this event originated
  508. *
  509. * @return the window
  510. */
  511. public Window getWindow() {
  512. return (Window) getSource();
  513. }
  514. }
  515. /**
  516. * Listener for window resize events.
  517. *
  518. * @see com.vaadin.ui.Window.ResizeEvent
  519. */
  520. public interface ResizeListener extends Serializable {
  521. public void windowResized(ResizeEvent e);
  522. }
  523. /**
  524. * Add a resize listener.
  525. *
  526. * @see Registration
  527. *
  528. * @param listener
  529. * the listener to add, not null
  530. * @return a registration object for removing the listener
  531. */
  532. public Registration addResizeListener(ResizeListener listener) {
  533. return addListener(ResizeEvent.class, listener, WINDOW_RESIZE_METHOD);
  534. }
  535. /**
  536. * Remove a resize listener.
  537. *
  538. * @param listener
  539. */
  540. @Deprecated
  541. public void removeResizeListener(ResizeListener listener) {
  542. removeListener(ResizeEvent.class, listener);
  543. }
  544. /**
  545. * Fire the resize event.
  546. */
  547. protected void fireResize() {
  548. fireEvent(new ResizeEvent(this));
  549. }
  550. /**
  551. * Used to keep the right order of windows if multiple windows are brought
  552. * to front in a single changeset. If this is not used, the order is quite
  553. * random (depends on the order getting to dirty list. e.g. which window got
  554. * variable changes).
  555. */
  556. private Integer bringToFront = null;
  557. /**
  558. * If there are currently several windows visible, calling this method makes
  559. * this window topmost.
  560. * <p>
  561. * This method can only be called if this window connected a UI. Else an
  562. * illegal state exception is thrown. Also if there are modal windows and
  563. * this window is not modal, and illegal state exception is thrown.
  564. * <p>
  565. */
  566. public void bringToFront() {
  567. UI uI = getUI();
  568. if (uI == null) {
  569. throw new IllegalStateException(
  570. "Window must be attached to parent before calling bringToFront method.");
  571. }
  572. int maxBringToFront = -1;
  573. for (Window w : uI.getWindows()) {
  574. if (!isModal() && w.isModal()) {
  575. throw new IllegalStateException(
  576. "The UI contains modal windows, non-modal window cannot be brought to front.");
  577. }
  578. if (w.bringToFront != null) {
  579. maxBringToFront = Math.max(maxBringToFront,
  580. w.bringToFront.intValue());
  581. }
  582. }
  583. bringToFront = Integer.valueOf(maxBringToFront + 1);
  584. markAsDirty();
  585. }
  586. /**
  587. * Sets window modality. When a modal window is open, components outside
  588. * that window cannot be accessed.
  589. * <p>
  590. * Keyboard navigation is restricted by blocking the tab key at the top and
  591. * bottom of the window by activating the tab stop function internally.
  592. *
  593. * @param modal
  594. * true if modality is to be turned on
  595. */
  596. public void setModal(boolean modal) {
  597. getState().modal = modal;
  598. center();
  599. }
  600. /**
  601. * @return true if this window is modal.
  602. */
  603. public boolean isModal() {
  604. return getState(false).modal;
  605. }
  606. /**
  607. * Sets window resizable.
  608. *
  609. * @param resizable
  610. * true if resizability is to be turned on
  611. */
  612. public void setResizable(boolean resizable) {
  613. getState().resizable = resizable;
  614. }
  615. /**
  616. *
  617. * @return true if window is resizable by the end-user, otherwise false.
  618. */
  619. public boolean isResizable() {
  620. return getState(false).resizable;
  621. }
  622. /**
  623. *
  624. * @return true if a delay is used before recalculating sizes, false if
  625. * sizes are recalculated immediately.
  626. */
  627. public boolean isResizeLazy() {
  628. return getState(false).resizeLazy;
  629. }
  630. /**
  631. * Should resize operations be lazy, i.e. should there be a delay before
  632. * layout sizes are recalculated. Speeds up resize operations in slow UIs
  633. * with the penalty of slightly decreased usability.
  634. *
  635. * Note, some browser send false resize events for the browser window and
  636. * are therefore always lazy.
  637. *
  638. * @param resizeLazy
  639. * true to use a delay before recalculating sizes, false to
  640. * calculate immediately.
  641. */
  642. public void setResizeLazy(boolean resizeLazy) {
  643. getState().resizeLazy = resizeLazy;
  644. }
  645. /**
  646. * Sets this window to be centered relative to its parent window. Affects
  647. * windows only. If the window is resized as a result of the size of its
  648. * content changing, it will keep itself centered as long as its position is
  649. * not explicitly changed programmatically or by the user.
  650. * <p>
  651. * <b>NOTE:</b> This method has several issues as currently implemented.
  652. * Please refer to http://dev.vaadin.com/ticket/8971 for details.
  653. */
  654. public void center() {
  655. getState().centered = true;
  656. }
  657. /**
  658. * Returns the closable status of the window. If a window is closable, it
  659. * typically shows an X in the upper right corner. Clicking on the X sends a
  660. * close event to the server. Setting closable to false will remove the X
  661. * from the window and prevent the user from closing the window.
  662. *
  663. * @return true if the window can be closed by the user.
  664. */
  665. public boolean isClosable() {
  666. return getState(false).closable;
  667. }
  668. /**
  669. * Sets the closable status for the window. If a window is closable it
  670. * typically shows an X in the upper right corner. Clicking on the X sends a
  671. * close event to the server. Setting closable to false will remove the X
  672. * from the window and prevent the user from closing the window.
  673. *
  674. * @param closable
  675. * determines if the window can be closed by the user.
  676. */
  677. public void setClosable(boolean closable) {
  678. if (closable != isClosable()) {
  679. getState().closable = closable;
  680. }
  681. }
  682. /**
  683. * Indicates whether a window can be dragged or not. By default a window is
  684. * draggable.
  685. *
  686. * @return {@code true} if window is draggable; {@code false} if not
  687. */
  688. public boolean isDraggable() {
  689. return getState(false).draggable;
  690. }
  691. /**
  692. * Enables or disables that a window can be dragged (moved) by the user. By
  693. * default a window is draggable.
  694. * <p/>
  695. *
  696. * @param draggable
  697. * true if the window can be dragged by the user
  698. */
  699. public void setDraggable(boolean draggable) {
  700. getState().draggable = draggable;
  701. }
  702. /**
  703. * Gets the current mode of the window.
  704. *
  705. * @see WindowMode
  706. * @return the mode of the window.
  707. */
  708. public WindowMode getWindowMode() {
  709. return getState(false).windowMode;
  710. }
  711. /**
  712. * Sets the mode for the window
  713. *
  714. * @see WindowMode
  715. * @param windowMode
  716. * The new mode
  717. */
  718. public void setWindowMode(WindowMode windowMode) {
  719. if (windowMode != getWindowMode()) {
  720. getState().windowMode = windowMode;
  721. fireWindowWindowModeChange();
  722. }
  723. }
  724. /**
  725. * This is the old way of adding a keyboard shortcut to close a
  726. * {@link Window} - to preserve compatibility with existing code under the
  727. * new functionality, this method now first removes all registered close
  728. * shortcuts, then adds the default ESCAPE shortcut key, and then attempts
  729. * to add the shortcut provided as parameters to this method. This method,
  730. * and its companion {@link #removeCloseShortcut()}, are now considered
  731. * deprecated, as their main function is to preserve exact backwards
  732. * compatibility with old code. For all new code, use the new keyboard
  733. * shortcuts API: {@link #addCloseShortcut(int,int...)},
  734. * {@link #removeCloseShortcut(int,int...)},
  735. * {@link #removeAllCloseShortcuts()}, {@link #hasCloseShortcut(int,int...)}
  736. * and {@link #getCloseShortcuts()}.
  737. * <p>
  738. * Original description: Makes it possible to close the window by pressing
  739. * the given {@link KeyCode} and (optional) {@link ModifierKey}s.<br/>
  740. * Note that this shortcut only reacts while the window has focus, closing
  741. * itself - if you want to close a window from a UI, use
  742. * {@link UI#addAction(com.vaadin.event.Action)} of the UI instead.
  743. *
  744. * @param keyCode
  745. * the keycode for invoking the shortcut
  746. * @param modifiers
  747. * the (optional) modifiers for invoking the shortcut. Can be set
  748. * to null to be explicit about not having modifiers.
  749. *
  750. * @deprecated Use {@link #addCloseShortcut(int, int...)} instead.
  751. */
  752. @Deprecated
  753. public void setCloseShortcut(int keyCode, int... modifiers) {
  754. removeCloseShortcut();
  755. addCloseShortcut(keyCode, modifiers);
  756. }
  757. /**
  758. * Removes all keyboard shortcuts previously set with
  759. * {@link #setCloseShortcut(int, int...)} and
  760. * {@link #addCloseShortcut(int, int...)}, then adds the default
  761. * {@link KeyCode#ESCAPE} shortcut.
  762. * <p>
  763. * This is the old way of removing the (single) keyboard close shortcut, and
  764. * is retained only for exact backwards compatibility. For all new code, use
  765. * the new keyboard shortcuts API: {@link #addCloseShortcut(int,int...)},
  766. * {@link #removeCloseShortcut(int,int...)},
  767. * {@link #removeAllCloseShortcuts()}, {@link #hasCloseShortcut(int,int...)}
  768. * and {@link #getCloseShortcuts()}.
  769. *
  770. * @deprecated Use {@link #removeCloseShortcut(int, int...)} instead.
  771. */
  772. @Deprecated
  773. public void removeCloseShortcut() {
  774. for (CloseShortcut sc : closeShortcuts) {
  775. removeAction(sc);
  776. }
  777. closeShortcuts.clear();
  778. addCloseShortcut(KeyCode.ESCAPE);
  779. }
  780. /**
  781. * Adds a close shortcut - pressing this key while holding down all (if any)
  782. * modifiers specified while this Window is in focus will close the Window.
  783. *
  784. * @since 7.6
  785. * @param keyCode
  786. * the keycode for invoking the shortcut
  787. * @param modifiers
  788. * the (optional) modifiers for invoking the shortcut. Can be set
  789. * to null to be explicit about not having modifiers.
  790. */
  791. public void addCloseShortcut(int keyCode, int... modifiers) {
  792. // Ignore attempts to re-add existing shortcuts
  793. if (hasCloseShortcut(keyCode, modifiers)) {
  794. return;
  795. }
  796. // Actually add the shortcut
  797. CloseShortcut shortcut = new CloseShortcut(this, keyCode, modifiers);
  798. addAction(shortcut);
  799. closeShortcuts.add(shortcut);
  800. }
  801. /**
  802. * Removes a close shortcut previously added with
  803. * {@link #addCloseShortcut(int, int...)}.
  804. *
  805. * @since 7.6
  806. * @param keyCode
  807. * the keycode for invoking the shortcut
  808. * @param modifiers
  809. * the (optional) modifiers for invoking the shortcut. Can be set
  810. * to null to be explicit about not having modifiers.
  811. */
  812. public void removeCloseShortcut(int keyCode, int... modifiers) {
  813. for (CloseShortcut shortcut : closeShortcuts) {
  814. if (shortcut.equals(keyCode, modifiers)) {
  815. removeAction(shortcut);
  816. closeShortcuts.remove(shortcut);
  817. return;
  818. }
  819. }
  820. }
  821. /**
  822. * Removes all close shortcuts. This includes the default ESCAPE shortcut.
  823. * It is up to the user to add back any and all keyboard close shortcuts
  824. * they may require. For more fine-grained control over shortcuts, use
  825. * {@link #removeCloseShortcut(int, int...)}.
  826. *
  827. * @since 7.6
  828. */
  829. public void removeAllCloseShortcuts() {
  830. for (CloseShortcut shortcut : closeShortcuts) {
  831. removeAction(shortcut);
  832. }
  833. closeShortcuts.clear();
  834. }
  835. /**
  836. * Checks if a close window shortcut key has already been registered.
  837. *
  838. * @since 7.6
  839. * @param keyCode
  840. * the keycode for invoking the shortcut
  841. * @param modifiers
  842. * the (optional) modifiers for invoking the shortcut. Can be set
  843. * to null to be explicit about not having modifiers.
  844. * @return true, if an exactly matching shortcut has been registered.
  845. */
  846. public boolean hasCloseShortcut(int keyCode, int... modifiers) {
  847. for (CloseShortcut shortcut : closeShortcuts) {
  848. if (shortcut.equals(keyCode, modifiers)) {
  849. return true;
  850. }
  851. }
  852. return false;
  853. }
  854. /**
  855. * Returns an unmodifiable collection of {@link CloseShortcut} objects
  856. * currently registered with this {@link Window}. This method is provided
  857. * mainly so that users can implement their own serialization routines. To
  858. * check if a certain combination of keys has been registered as a close
  859. * shortcut, use the {@link #hasCloseShortcut(int, int...)} method instead.
  860. *
  861. * @since 7.6
  862. * @return an unmodifiable Collection of CloseShortcut objects.
  863. */
  864. public Collection<CloseShortcut> getCloseShortcuts() {
  865. return Collections.unmodifiableCollection(closeShortcuts);
  866. }
  867. /**
  868. * A {@link ShortcutListener} specifically made to define a keyboard
  869. * shortcut that closes the window.
  870. *
  871. * <pre>
  872. * <code>
  873. * // within the window using helper
  874. * window.setCloseShortcut(KeyCode.ESCAPE, null);
  875. *
  876. * // or globally
  877. * getUI().addAction(new Window.CloseShortcut(window, KeyCode.ESCAPE));
  878. * </code>
  879. * </pre>
  880. *
  881. */
  882. public static class CloseShortcut extends ShortcutListener {
  883. protected Window window;
  884. /**
  885. * Creates a keyboard shortcut for closing the given window using the
  886. * shorthand notation defined in {@link ShortcutAction}.
  887. *
  888. * @param window
  889. * to be closed when the shortcut is invoked
  890. * @param shorthandCaption
  891. * the caption with shortcut keycode and modifiers indicated
  892. */
  893. public CloseShortcut(Window window, String shorthandCaption) {
  894. super(shorthandCaption);
  895. this.window = window;
  896. }
  897. /**
  898. * Creates a keyboard shortcut for closing the given window using the
  899. * given {@link KeyCode} and {@link ModifierKey}s.
  900. *
  901. * @param window
  902. * to be closed when the shortcut is invoked
  903. * @param keyCode
  904. * KeyCode to react to
  905. * @param modifiers
  906. * optional modifiers for shortcut
  907. */
  908. public CloseShortcut(Window window, int keyCode, int... modifiers) {
  909. super(null, keyCode, modifiers);
  910. this.window = window;
  911. }
  912. /**
  913. * Creates a keyboard shortcut for closing the given window using the
  914. * given {@link KeyCode}.
  915. *
  916. * @param window
  917. * to be closed when the shortcut is invoked
  918. * @param keyCode
  919. * KeyCode to react to
  920. */
  921. public CloseShortcut(Window window, int keyCode) {
  922. this(window, keyCode, null);
  923. }
  924. @Override
  925. public void handleAction(Object sender, Object target) {
  926. if (window.isClosable()) {
  927. window.close();
  928. }
  929. }
  930. public boolean equals(int keyCode, int... modifiers) {
  931. if (keyCode != getKeyCode()) {
  932. return false;
  933. }
  934. if (getModifiers() != null) {
  935. int[] mods = null;
  936. if (modifiers != null) {
  937. // Modifiers provided by the parent ShortcutAction class
  938. // are guaranteed to be sorted. We still need to sort
  939. // the modifiers passed in as argument.
  940. mods = Arrays.copyOf(modifiers, modifiers.length);
  941. Arrays.sort(mods);
  942. }
  943. return Arrays.equals(mods, getModifiers());
  944. }
  945. return true;
  946. }
  947. }
  948. /*
  949. * (non-Javadoc)
  950. *
  951. * @see
  952. * com.vaadin.event.FieldEvents.FocusNotifier#addFocusListener(com.vaadin
  953. * .event.FieldEvents.FocusListener)
  954. */
  955. @Override
  956. public Registration addFocusListener(FocusListener listener) {
  957. return addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener,
  958. FocusListener.focusMethod);
  959. }
  960. @Override
  961. @Deprecated
  962. public void removeFocusListener(FocusListener listener) {
  963. removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener);
  964. }
  965. /*
  966. * (non-Javadoc)
  967. *
  968. * @see
  969. * com.vaadin.event.FieldEvents.BlurNotifier#addBlurListener(com.vaadin.
  970. * event.FieldEvents.BlurListener)
  971. */
  972. @Override
  973. public Registration addBlurListener(BlurListener listener) {
  974. return addListener(BlurEvent.EVENT_ID, BlurEvent.class, listener,
  975. BlurListener.blurMethod);
  976. }
  977. @Override
  978. @Deprecated
  979. public void removeBlurListener(BlurListener listener) {
  980. removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener);
  981. }
  982. /**
  983. * {@inheritDoc}
  984. *
  985. * Cause the window to be brought on top of other windows and gain keyboard
  986. * focus.
  987. */
  988. @Override
  989. public void focus() {
  990. /*
  991. * When focusing a window it basically means it should be brought to the
  992. * front. Instead of just moving the keyboard focus we focus the window
  993. * and bring it top-most.
  994. */
  995. super.focus();
  996. bringToFront();
  997. }
  998. @Override
  999. protected WindowState getState() {
  1000. return (WindowState) super.getState();
  1001. }
  1002. @Override
  1003. protected WindowState getState(boolean markAsDirty) {
  1004. return (WindowState) super.getState(markAsDirty);
  1005. }
  1006. /**
  1007. * Allows to specify which components contain the description for the
  1008. * window. Text contained in these components will be read by assistive
  1009. * devices when it is opened.
  1010. *
  1011. * @param components
  1012. * the components to use as description
  1013. */
  1014. public void setAssistiveDescription(Component... components) {
  1015. if (components == null) {
  1016. throw new IllegalArgumentException(
  1017. "Parameter connectors must be non-null");
  1018. } else {
  1019. getState().contentDescription = components;
  1020. }
  1021. }
  1022. /**
  1023. * Gets the components that are used as assistive description. Text
  1024. * contained in these components will be read by assistive devices when the
  1025. * window is opened.
  1026. *
  1027. * @return array of previously set components
  1028. */
  1029. public Component[] getAssistiveDescription() {
  1030. Connector[] contentDescription = getState(false).contentDescription;
  1031. if (contentDescription == null) {
  1032. return null;
  1033. }
  1034. Component[] target = new Component[contentDescription.length];
  1035. System.arraycopy(contentDescription, 0, target, 0,
  1036. contentDescription.length);
  1037. return target;
  1038. }
  1039. /**
  1040. * Sets the accessibility prefix for the window caption.
  1041. *
  1042. * This prefix is read to assistive device users before the window caption,
  1043. * but not visible on the page.
  1044. *
  1045. * @param prefix
  1046. * String that is placed before the window caption
  1047. */
  1048. public void setAssistivePrefix(String prefix) {
  1049. getState().assistivePrefix = prefix;
  1050. }
  1051. /**
  1052. * Gets the accessibility prefix for the window caption.
  1053. *
  1054. * This prefix is read to assistive device users before the window caption,
  1055. * but not visible on the page.
  1056. *
  1057. * @return The accessibility prefix
  1058. */
  1059. public String getAssistivePrefix() {
  1060. return getState(false).assistivePrefix;
  1061. }
  1062. /**
  1063. * Sets the accessibility postfix for the window caption.
  1064. *
  1065. * This postfix is read to assistive device users after the window caption,
  1066. * but not visible on the page.
  1067. *
  1068. * @param prefix
  1069. * String that is placed after the window caption
  1070. */
  1071. public void setAssistivePostfix(String assistivePostfix) {
  1072. getState().assistivePostfix = assistivePostfix;
  1073. }
  1074. /**
  1075. * Gets the accessibility postfix for the window caption.
  1076. *
  1077. * This postfix is read to assistive device users after the window caption,
  1078. * but not visible on the page.
  1079. *
  1080. * @return The accessibility postfix
  1081. */
  1082. public String getAssistivePostfix() {
  1083. return getState(false).assistivePostfix;
  1084. }
  1085. /**
  1086. * Sets the WAI-ARIA role the window.
  1087. *
  1088. * This role defines how an assistive device handles a window. Available
  1089. * roles are alertdialog and dialog (@see
  1090. * <a href="http://www.w3.org/TR/2011/CR-wai-aria-20110118/roles">Roles
  1091. * Model</a>).
  1092. *
  1093. * The default role is dialog.
  1094. *
  1095. * @param role
  1096. * WAI-ARIA role to set for the window
  1097. */
  1098. public void setAssistiveRole(WindowRole role) {
  1099. getState().role = role;
  1100. }
  1101. /**
  1102. * Gets the WAI-ARIA role the window.
  1103. *
  1104. * This role defines how an assistive device handles a window. Available
  1105. * roles are alertdialog and dialog (@see
  1106. * <a href="http://www.w3.org/TR/2011/CR-wai-aria-20110118/roles">Roles
  1107. * Model</a>).
  1108. *
  1109. * @return WAI-ARIA role set for the window
  1110. */
  1111. public WindowRole getAssistiveRole() {
  1112. return getState(false).role;
  1113. }
  1114. /**
  1115. * Set if it should be prevented to set the focus to a component outside a
  1116. * non-modal window with the tab key.
  1117. * <p>
  1118. * This is meant to help users of assistive devices to not leaving the
  1119. * window unintentionally.
  1120. * <p>
  1121. * For modal windows, this function is activated automatically, while
  1122. * preserving the stored value of tabStop.
  1123. *
  1124. * @param tabStop
  1125. * true to keep the focus inside the window when reaching the top
  1126. * or bottom, false (default) to allow leaving the window
  1127. */
  1128. public void setTabStopEnabled(boolean tabStop) {
  1129. getState().assistiveTabStop = tabStop;
  1130. }
  1131. /**
  1132. * Get if it is prevented to leave a window with the tab key.
  1133. *
  1134. * @return true when the focus is limited to inside the window, false when
  1135. * focus can leave the window
  1136. */
  1137. public boolean isTabStopEnabled() {
  1138. return getState(false).assistiveTabStop;
  1139. }
  1140. /**
  1141. * Sets the message that is provided to users of assistive devices when the
  1142. * user reaches the top of the window when leaving a window with the tab key
  1143. * is prevented.
  1144. * <p>
  1145. * This message is not visible on the screen.
  1146. *
  1147. * @param topMessage
  1148. * String provided when the user navigates with Shift-Tab keys to
  1149. * the top of the window
  1150. */
  1151. public void setTabStopTopAssistiveText(String topMessage) {
  1152. getState().assistiveTabStopTopText = topMessage;
  1153. }
  1154. /**
  1155. * Sets the message that is provided to users of assistive devices when the
  1156. * user reaches the bottom of the window when leaving a window with the tab
  1157. * key is prevented.
  1158. * <p>
  1159. * This message is not visible on the screen.
  1160. *
  1161. * @param bottomMessage
  1162. * String provided when the user navigates with the Tab key to
  1163. * the bottom of the window
  1164. */
  1165. public void setTabStopBottomAssistiveText(String bottomMessage) {
  1166. getState().assistiveTabStopBottomText = bottomMessage;
  1167. }
  1168. /**
  1169. * Gets the message that is provided to users of assistive devices when the
  1170. * user reaches the top of the window when leaving a window with the tab key
  1171. * is prevented.
  1172. *
  1173. * @return the top message
  1174. */
  1175. public String getTabStopTopAssistiveText() {
  1176. return getState(false).assistiveTabStopTopText;
  1177. }
  1178. /**
  1179. * Gets the message that is provided to users of assistive devices when the
  1180. * user reaches the bottom of the window when leaving a window with the tab
  1181. * key is prevented.
  1182. *
  1183. * @return the bottom message
  1184. */
  1185. public String getTabStopBottomAssistiveText() {
  1186. return getState(false).assistiveTabStopBottomText;
  1187. }
  1188. @Override
  1189. public void readDesign(Element design, DesignContext context) {
  1190. super.readDesign(design, context);
  1191. if (design.hasAttr("center")) {
  1192. center();
  1193. }
  1194. if (design.hasAttr("position")) {
  1195. String[] position = design.attr("position").split(",");
  1196. setPositionX(Integer.parseInt(position[0]));
  1197. setPositionY(Integer.parseInt(position[1]));
  1198. }
  1199. // Parse shortcuts if defined, otherwise rely on default behavior
  1200. if (design.hasAttr("close-shortcut")) {
  1201. // Parse shortcuts
  1202. String[] shortcutStrings = DesignAttributeHandler
  1203. .readAttribute("close-shortcut", design.attributes(),
  1204. String.class)
  1205. .split("\\s+");
  1206. removeAllCloseShortcuts();
  1207. for (String part : shortcutStrings) {
  1208. if (!part.isEmpty()) {
  1209. ShortcutAction shortcut = DesignAttributeHandler
  1210. .getFormatter()
  1211. .parse(part.trim(), ShortcutAction.class);
  1212. addCloseShortcut(shortcut.getKeyCode(),
  1213. shortcut.getModifiers());
  1214. }
  1215. }
  1216. }
  1217. }
  1218. /**
  1219. * Reads the content and possible assistive descriptions from the list of
  1220. * child elements of a design. If an element has an
  1221. * {@code :assistive-description} attribute, adds the parsed component to
  1222. * the list of components used as the assistive description of this Window.
  1223. * Otherwise, sets the component as the content of this Window. If there are
  1224. * multiple non-description elements, throws a DesignException.
  1225. *
  1226. * @param children
  1227. * child elements in a design
  1228. * @param context
  1229. * the DesignContext instance used to parse the design
  1230. *
  1231. * @throws DesignException
  1232. * if there are multiple non-description child elements
  1233. * @throws DesignException
  1234. * if a child element could not be parsed as a Component
  1235. *
  1236. * @see #setContent(Component)
  1237. * @see #setAssistiveDescription(Component...)
  1238. */
  1239. @Override
  1240. protected void readDesignChildren(Elements children,
  1241. DesignContext context) {
  1242. List<Component> descriptions = new ArrayList<>();
  1243. Elements content = new Elements();
  1244. for (Element child : children) {
  1245. if (child.hasAttr(":assistive-description")) {
  1246. descriptions.add(context.readDesign(child));
  1247. } else {
  1248. content.add(child);
  1249. }
  1250. }
  1251. super.readDesignChildren(content, context);
  1252. setAssistiveDescription(
  1253. descriptions.toArray(new Component[descriptions.size()]));
  1254. }
  1255. @Override
  1256. public void writeDesign(Element design, DesignContext context) {
  1257. super.writeDesign(design, context);
  1258. Window def = context.getDefaultInstance(this);
  1259. if (getState().centered) {
  1260. design.attr("center", true);
  1261. }
  1262. DesignAttributeHandler.writeAttribute("position", design.attributes(),
  1263. getPosition(), def.getPosition(), String.class, context);
  1264. // Process keyboard shortcuts
  1265. if (closeShortcuts.size() == 1 && hasCloseShortcut(KeyCode.ESCAPE)) {
  1266. // By default, we won't write anything if we're relying on default
  1267. // shortcut behavior
  1268. } else {
  1269. // Dump all close shortcuts to a string...
  1270. String attrString = "";
  1271. // TODO: add canonical support for array data in XML attributes
  1272. for (CloseShortcut shortcut : closeShortcuts) {
  1273. String shortcutString = DesignAttributeHandler.getFormatter()
  1274. .format(shortcut, CloseShortcut.class);
  1275. attrString += shortcutString + " ";
  1276. }
  1277. // Write everything except the last "," to the design
  1278. DesignAttributeHandler.writeAttribute("close-shortcut",
  1279. design.attributes(), attrString.trim(), null, String.class,
  1280. context);
  1281. }
  1282. for (Component c : getAssistiveDescription()) {
  1283. Element child = context.createElement(c)
  1284. .attr(":assistive-description", true);
  1285. design.appendChild(child);
  1286. }
  1287. }
  1288. private String getPosition() {
  1289. return getPositionX() + "," + getPositionY();
  1290. }
  1291. @Override
  1292. protected Collection<String> getCustomAttributes() {
  1293. Collection<String> result = super.getCustomAttributes();
  1294. result.add("center");
  1295. result.add("position");
  1296. result.add("position-y");
  1297. result.add("position-x");
  1298. result.add("close-shortcut");
  1299. return result;
  1300. }
  1301. }