Java/GWT/Composite

Материал из Java эксперт
Перейти к: навигация, поиск

Create Custom Panel Based On Composite

package com.jexp.gwt.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.ruposite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ScrollListener;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.RootPanel;
public class GWTClient implements EntryPoint{
  public void onModuleLoad() {
    LicensePanel e = new LicensePanel("License: scroll to enable the check box");
    
    RootPanel.get().add(e);
  }
}
class LicensePanel extends Composite {
    private VerticalPanel vPanel = new VerticalPanel(); 
    final Label text;
    private ScrollPanel sPanel = new ScrollPanel();
    private CheckBox accept = new CheckBox("Accept Terms");
    public LicensePanel(final String licenseText) {
        text = new Label(licenseText); 
        
        sPanel.setAlwaysShowScrollBars(true);
        sPanel.setHeight("100px");
        sPanel.setWidth("200px");        
        sPanel.add(text);   
        
        accept.setChecked(false);
        accept.setEnabled(false); // scroll to enable it
        
        vPanel.add(sPanel);
        vPanel.add(accept);
        initWidget(vPanel);
        
        sPanel.addScrollListener(new ScrollListener() {            
                public void onScroll(Widget sender, int x, int y) {
                    Widget textItem = sPanel.getWidget();
                    if (sPanel.getOffsetHeight() + y >= textItem.getOffsetHeight())
                    {
                        accept.setEnabled(true);
                    }                    
                }
            });        
        //setStyleName("licensePanel");
    }     
    
    public boolean isAccepted() {
        return accept.isChecked();
    }
}
/////////////
.layouts-Label {
  background-color: #C3D9FF;
  font-weight: bold;
  margin-top: 1em;
  padding: 2px 0px 2px 0px;
  width: 100%;
}





Extends Composite To Create Custom Component

package com.jexp.gwt.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;
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.Widget;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.ruposite;
public class GWTClient implements EntryPoint {
  public void onModuleLoad() {
    MyComponent com = new MyComponent();
    RootPanel.get().add(com);
  }
}
class MyComponent extends Composite {
  private Button dialogButton = new Button("Show Dialog");
  private Button popupButton = new Button("Show Popup");
  
  public MyComponent(){
    
    VerticalPanel panel = new VerticalPanel();
    panel.add(popupButton);
    panel.add(dialogButton);
    panel.setSpacing(8);    
    initWidget(panel);
  }
  
  
}