Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ISplitPanel.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package com.itmill.toolkit.terminal.gwt.client.ui;
  2. import com.google.gwt.core.client.GWT;
  3. import com.google.gwt.user.client.DOM;
  4. import com.google.gwt.user.client.Element;
  5. import com.google.gwt.user.client.ui.HorizontalSplitPanel;
  6. import com.google.gwt.user.client.ui.HorizontalSplitPanelImages;
  7. import com.google.gwt.user.client.ui.SimplePanel;
  8. import com.google.gwt.user.client.ui.VerticalSplitPanel;
  9. import com.google.gwt.user.client.ui.VerticalSplitPanelImages;
  10. import com.google.gwt.user.client.ui.Widget;
  11. import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
  12. import com.itmill.toolkit.terminal.gwt.client.Paintable;
  13. import com.itmill.toolkit.terminal.gwt.client.UIDL;
  14. public class ISplitPanel extends SimplePanel implements Paintable {
  15. public static final String CLASSNAME = "i-splitpanel";
  16. public static final int ORIENTATION_HORIZONTAL = 0;
  17. public static final int ORIENTATION_VERTICAL = 1;
  18. private int orientation;
  19. private HorizontalSplitPanel sph;
  20. private VerticalSplitPanel spv;
  21. private Widget firstChild;
  22. private Widget secondChild;
  23. public ISplitPanel() {
  24. this(ORIENTATION_HORIZONTAL);
  25. }
  26. public ISplitPanel(int orientation) {
  27. super();
  28. setOrientation(orientation);
  29. }
  30. private void setOrientation(int orientation) {
  31. this.orientation = orientation;
  32. if(orientation == ORIENTATION_HORIZONTAL) {
  33. this.sph = new HorizontalSplitPanel((HorizontalSplitPanelImages) GWT.create(com.itmill.toolkit.terminal.gwt.client.ui.HorizontalSplitPanelImages.class));
  34. this.sph.setStyleName(CLASSNAME+"-horizontal");
  35. // Ugly work-around to allow more advanced styling (GWT's heavy use of TABLE-elements is restricting)
  36. Element handle = DOM.getChild(DOM.getChild(this.sph.getElement(), 0), 1);
  37. DOM.setElementAttribute(handle, "className", CLASSNAME+"-handle");
  38. this.setWidget(sph);
  39. if(spv != null) {
  40. // TODO cleanup contained widgets
  41. this.spv = null;
  42. }
  43. } else {
  44. this.spv = new VerticalSplitPanel((VerticalSplitPanelImages) GWT.create(com.itmill.toolkit.terminal.gwt.client.ui.VerticalSplitPanelImages.class));
  45. this.spv.setStyleName(CLASSNAME+"-vertical");
  46. // Ugly work-around to allow more advanced styling (GWT's heavy use of TABLE-elements is restricting)
  47. Element handle = DOM.getChild(DOM.getChild(this.spv.getElement(), 0), 1);
  48. DOM.setElementAttribute(handle, "className", CLASSNAME+"-handle");
  49. this.setWidget(spv);
  50. if(sph != null) {
  51. // TODO cleanup contained widgets
  52. this.sph = null;
  53. }
  54. }
  55. }
  56. public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
  57. client.updateComponent(this, uidl, true);
  58. setSplitPosition(uidl.getStringAttribute("position"));
  59. setWidth(uidl.getStringAttribute("width"));
  60. setHeight(uidl.getStringAttribute("height"));
  61. Paintable newFirstChild = (Paintable) client.getWidget(uidl.getChildUIDL(0));
  62. Paintable newSecondChild = (Paintable) client.getWidget(uidl.getChildUIDL(1));
  63. if(firstChild != newFirstChild) {
  64. if(firstChild != null)
  65. client.unregisterPaintable((Paintable) firstChild);
  66. setFirstWidget((Widget) newFirstChild);
  67. }
  68. if(secondChild != newSecondChild) {
  69. if(secondChild != null)
  70. client.unregisterPaintable((Paintable) secondChild);
  71. setSecondWidget((Widget) newSecondChild);
  72. }
  73. newFirstChild.updateFromUIDL(uidl.getChildUIDL(0), client);
  74. newSecondChild.updateFromUIDL(uidl.getChildUIDL(1), client);
  75. }
  76. private void setSplitPosition(String pos) {
  77. if(orientation == ORIENTATION_HORIZONTAL) {
  78. this.sph.setSplitPosition(pos);
  79. } else {
  80. this.spv.setSplitPosition(pos);
  81. }
  82. }
  83. private void setFirstWidget(Widget w) {
  84. firstChild = w;
  85. if(orientation == ORIENTATION_HORIZONTAL) {
  86. this.sph.setLeftWidget(w);
  87. } else {
  88. this.spv.setTopWidget(w);
  89. }
  90. }
  91. private void setSecondWidget(Widget w) {
  92. secondChild = w;
  93. if(orientation == ORIENTATION_HORIZONTAL) {
  94. this.sph.setRightWidget(w);
  95. } else {
  96. this.spv.setBottomWidget(w);
  97. }
  98. }
  99. public void setHeight(String height) {
  100. super.setHeight(height);
  101. if(orientation == ORIENTATION_HORIZONTAL) {
  102. sph.setHeight(height);
  103. } else {
  104. spv.setHeight(height);
  105. }
  106. }
  107. public void setWidth(String width) {
  108. super.setWidth(width);
  109. if(orientation == ORIENTATION_HORIZONTAL) {
  110. sph.setWidth(width);
  111. } else {
  112. spv.setWidth(width);
  113. }
  114. }
  115. }