Changeset 4802
- Timestamp:
- 06/09/08 08:29:45 (6 months ago)
- Files:
-
- 1 modified
-
trunk/src/com/itmill/toolkit/ui/Panel.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/itmill/toolkit/ui/Panel.java
r4620 r4802 109 109 110 110 /** 111 * Sets the layout of the panel. All the components are moved to new layout. 112 * 113 * @param layout 111 * Sets the layout of the panel. 112 * 113 * If given layout is null, an OrderedLayout is used as a default. 114 * 115 * Components from old layout are not moved to new layout by default 116 * (changed in 5.2.2). Use function in Layout interface manually. 117 * 118 * @param newLayout 114 119 * the New layout of the panel. 115 120 */ 116 public void setLayout(Layout layout) {121 public void setLayout(Layout newLayout) { 117 122 118 123 // Only allow non-null layouts 119 if ( layout == null) {120 layout = new OrderedLayout();124 if (newLayout == null) { 125 newLayout = new OrderedLayout(); 121 126 // Force margins by default 122 layout.setMargin(true);123 } 124 125 if ( layout == this.layout) {127 newLayout.setMargin(true); 128 } 129 130 if (newLayout == layout) { 126 131 // don't set the same layout twice 127 132 return; 128 133 } 129 134 135 // detach old layout if present 136 if (layout != null) { 137 layout.setParent(null); 138 layout 139 .removeListener((ComponentContainer.ComponentAttachListener) this); 140 layout 141 .removeListener((ComponentContainer.ComponentDetachListener) this); 142 } 143 130 144 // Sets the panel to be parent for the layout 131 layout.setParent(this); 132 133 // If panel already contains a layout, move the contents to new one 134 // and detach old layout from the panel 135 if (this.layout != null) { 136 layout.moveComponentsFrom(this.layout); 137 this.layout.setParent(null); 138 } 139 140 // Removes the event listeners from the old layout 141 if (this.layout != null) { 142 this.layout 143 .removeListener((ComponentContainer.ComponentAttachListener) this); 144 this.layout 145 .removeListener((ComponentContainer.ComponentDetachListener) this); 146 } 145 newLayout.setParent(this); 147 146 148 147 // Sets the new layout 149 this.layout = layout;148 layout = newLayout; 150 149 151 150 // Adds the event listeners for new layout 152 layout.addListener((ComponentContainer.ComponentAttachListener) this); 153 layout.addListener((ComponentContainer.ComponentDetachListener) this); 151 newLayout 152 .addListener((ComponentContainer.ComponentAttachListener) this); 153 newLayout 154 .addListener((ComponentContainer.ComponentDetachListener) this); 154 155 } 155 156
