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.

ITabsheetPanel.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package com.itmill.toolkit.terminal.gwt.client.ui;
  2. import com.google.gwt.user.client.DOM;
  3. import com.google.gwt.user.client.ui.ComplexPanel;
  4. import com.google.gwt.user.client.ui.Widget;
  5. /**
  6. * A panel that displays all of its child widgets in a 'deck', where only one
  7. * can be visible at a time. It is used by
  8. * {@link com.itmill.toolkit.terminal.gwt.client.ui.ITabsheetPanel}.
  9. *
  10. * This class has the same basic functionality as the GWT DeckPanel
  11. * {@link com.google.gwt.user.client.ui.DeckPanel}, with the exception that it
  12. * doesn't manipulate the child widgets' width and height attributes.
  13. */
  14. public class ITabsheetPanel extends ComplexPanel {
  15. private Widget visibleWidget;
  16. /**
  17. * Creates an empty tabsheet panel.
  18. */
  19. public ITabsheetPanel() {
  20. setElement(DOM.createDiv());
  21. }
  22. /**
  23. * Adds the specified widget to the deck.
  24. *
  25. * @param w
  26. * the widget to be added
  27. */
  28. public void add(Widget w) {
  29. super.add(w, getElement());
  30. initChildWidget(w);
  31. }
  32. /**
  33. * Gets the index of the currently-visible widget.
  34. *
  35. * @return the visible widget's index
  36. */
  37. public int getVisibleWidget() {
  38. return getWidgetIndex(visibleWidget);
  39. }
  40. /**
  41. * Inserts a widget before the specified index.
  42. *
  43. * @param w
  44. * the widget to be inserted
  45. * @param beforeIndex
  46. * the index before which it will be inserted
  47. * @throws IndexOutOfBoundsException
  48. * if <code>beforeIndex</code> is out of range
  49. */
  50. public void insert(Widget w, int beforeIndex) {
  51. super.insert(w, getElement(), beforeIndex, true);
  52. initChildWidget(w);
  53. }
  54. public boolean remove(Widget w) {
  55. boolean removed = super.remove(w);
  56. if (removed) {
  57. resetChildWidget(w);
  58. if (visibleWidget == w) {
  59. visibleWidget = null;
  60. }
  61. }
  62. return removed;
  63. }
  64. /**
  65. * Shows the widget at the specified index. This causes the currently-
  66. * visible widget to be hidden.
  67. *
  68. * @param index
  69. * the index of the widget to be shown
  70. */
  71. public void showWidget(int index) {
  72. checkIndexBoundsForAccess(index);
  73. if (visibleWidget != null) {
  74. visibleWidget.setVisible(false);
  75. }
  76. visibleWidget = getWidget(index);
  77. visibleWidget.setVisible(true);
  78. }
  79. /**
  80. * Make the widget invisible, and set its width and height to full.
  81. */
  82. private void initChildWidget(Widget w) {
  83. w.setVisible(false);
  84. }
  85. /**
  86. * Make the widget visible, and clear the widget's width and height
  87. * attributes. This is done so that any changes to the visibility, height,
  88. * or width of the widget that were done by the panel are undone.
  89. */
  90. private void resetChildWidget(Widget w) {
  91. w.setVisible(true);
  92. }
  93. }