ggeorg / gwt-mosaic

Automatically exported from code.google.com/p/gwt-mosaic
1 stars 0 forks source link

WindowPanel ImageButton header problem #21

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

Adding a new ImageButton to a WindowPanel after the popup is open,
eliminate the close button.

Demo code:

import org.gwt.mosaic.ui.client.Caption;
import org.gwt.mosaic.ui.client.ImageButton;
import org.gwt.mosaic.ui.client.WindowPanel;
import org.gwt.mosaic.ui.client.Caption.CaptionRegion;
import org.gwt.mosaic.ui.client.WindowPanel.WindowState;
import org.gwt.mosaic.ui.client.WindowPanel.WindowStateListener;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.Widget;

public class WindowTest implements EntryPoint {

  public void onModuleLoad() {
    final WindowPanel window = new WindowPanel();
    window.setCaption("Test");
    window.setAnimationEnabled(true);
    window.setSize("400px", "400px");
    window.setWidget(new TextArea());
    addMaximizeButton(window, CaptionRegion.RIGHT);    
    addMinimizeButton(window, CaptionRegion.RIGHT);    
    window.center();

    Button b = new Button("add a new button");
    b.addClickListener(new ClickListener(){
      public void onClick(Widget sender) {
        final ImageButton refreshBtn = new
ImageButton(Caption.IMAGES.toolRefresh());
        window.getHeader().add(refreshBtn, CaptionRegion.RIGHT); 

      }});
    RootPanel.get().add(b);
  }
  public static void addMaximizeButton(final WindowPanel windowPanel,
      CaptionRegion captionRegion) {
    final ImageButton maximizeBtn = new ImageButton(
        Caption.IMAGES.windowMaximize());
    maximizeBtn.addClickListener(new ClickListener() {
      public void onClick(Widget sender) {
        if (windowPanel.getWindowState() == WindowState.MAXIMIZED) {
          windowPanel.setWindowState(WindowState.NORMAL);
        } else {
          windowPanel.setWindowState(WindowState.MAXIMIZED);
        }
      }
    });  
    windowPanel.addWindowStateListener(new WindowStateListener() {
      public void onWindowStateChange(WindowPanel sender) {
        if (sender.getWindowState() == WindowState.MAXIMIZED) {
          maximizeBtn.setImage(Caption.IMAGES.windowRestore().createImage());
        } else {
          maximizeBtn.setImage(Caption.IMAGES.windowMaximize().createImage());
        }

      }
    });
    windowPanel.getHeader().add(maximizeBtn, captionRegion);    
  } 
  public static void addMinimizeButton(final WindowPanel windowPanel,
      CaptionRegion captionRegion) {
    final ImageButton minimizeBtn = new ImageButton(
        Caption.IMAGES.windowMinimize());
    minimizeBtn.addClickListener(new ClickListener() {
      public void onClick(Widget sender) {
        windowPanel.setWindowState(WindowState.MINIMIZED);
      }
    });
    windowPanel.getHeader().add(minimizeBtn, captionRegion);
  } 
}

Original issue reported on code.google.com by agarin@gmail.com on 5 Dec 2008 at 7:07

GoogleCodeExporter commented 9 years ago
Hi,

after adding or removing items in a LayoutPanel based widget that is already 
rendered
you should call layout():

b.addClickListener(new ClickListener(){
      public void onClick(Widget sender) {
        final ImageButton refreshBtn = new ImageButton(Caption.IMAGES.toolRefresh());
        window.getHeader().add(refreshBtn, CaptionRegion.RIGHT); 
        window.getHeader().layout(); // <=====================================
      }});

Kind Regards,
George.

Original comment by georgopo...@gmail.com on 6 Dec 2008 at 1:16

GoogleCodeExporter commented 9 years ago
Thank you George. Sorry but sometimes I dont´t know if it's an issue or just
something I'm doing wrong.

Regards

Original comment by agarin@gmail.com on 7 Dec 2008 at 3:14

GoogleCodeExporter commented 9 years ago
I have to document how the layout panel works.

Thanks,
George.

Original comment by georgopo...@gmail.com on 7 Dec 2008 at 4:16