Changeset 4802

Show
Ignore:
Timestamp:
06/09/08 08:29:45 (6 months ago)
Author:
matti.tahvonen@…
Message:

fixes #1782

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/com/itmill/toolkit/ui/Panel.java

    r4620 r4802  
    109109 
    110110    /** 
    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 
    114119     *                the New layout of the panel. 
    115120     */ 
    116     public void setLayout(Layout layout) { 
     121    public void setLayout(Layout newLayout) { 
    117122 
    118123        // Only allow non-null layouts 
    119         if (layout == null) { 
    120             layout = new OrderedLayout(); 
     124        if (newLayout == null) { 
     125            newLayout = new OrderedLayout(); 
    121126            // 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) { 
    126131            // don't set the same layout twice 
    127132            return; 
    128133        } 
    129134 
     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 
    130144        // 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); 
    147146 
    148147        // Sets the new layout 
    149         this.layout = layout; 
     148        layout = newLayout; 
    150149 
    151150        // 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); 
    154155    } 
    155156