01: /*
02: * GWT-Ext Widget Library
03: * Copyright(c) 2007-2008, GWT-Ext.
04: * licensing@gwt-ext.com
05: *
06: * http://www.gwt-ext.com/license
07: */
08: package com.gwtext.sample.showcase2.client.form;
09:
10: import com.gwtext.client.core.Position;
11: import com.gwtext.client.core.EventObject;
12: import com.gwtext.client.widgets.Button;
13: import com.gwtext.client.widgets.Panel;
14: import com.gwtext.client.widgets.Window;
15: import com.gwtext.client.widgets.event.ButtonListenerAdapter;
16: import com.gwtext.client.widgets.form.FormPanel;
17: import com.gwtext.client.widgets.form.TextArea;
18: import com.gwtext.client.widgets.form.TextField;
19: import com.gwtext.client.widgets.layout.AnchorLayoutData;
20: import com.gwtext.client.widgets.layout.FitLayout;
21: import com.gwtext.sample.showcase2.client.ShowcasePanel;
22:
23: public class AnchoringSample extends ShowcasePanel {
24:
25: public String getSourceUrl() {
26: return "source/form/AnchoringSample.java.html";
27: }
28:
29: public Panel getViewPanel() {
30: if (panel == null) {
31: panel = new Panel();
32:
33: final Window window = new Window();
34: window.setTitle("Resize Me");
35: window.setWidth(500);
36: window.setHeight(300);
37: window.setMinWidth(300);
38: window.setMinHeight(200);
39: window.setLayout(new FitLayout());
40: window.setPaddings(5);
41: window.setButtonAlign(Position.CENTER);
42: window.addButton(new Button("Send"));
43: window.addButton(new Button("Cancel"));
44:
45: window.setCloseAction(Window.HIDE);
46: window.setPlain(true);
47:
48: FormPanel formPanel = new FormPanel();
49: //strips all Ext styling for the component
50: formPanel.setBaseCls("x-plain");
51: formPanel.setLabelWidth(55);
52: formPanel.setUrl("save-form.php");
53:
54: formPanel.setWidth(500);
55: formPanel.setHeight(300);
56:
57: // anchor width by percentage
58: formPanel.add(new TextField("Send To", "to"),
59: new AnchorLayoutData("100%"));
60:
61: // anchor width by percentage
62: formPanel.add(new TextField("Subject", "subject"),
63: new AnchorLayoutData("100%"));
64:
65: TextArea textArea = new TextArea("Subject", "subject");
66: textArea.setHideLabel(true);
67: // anchor width by percentage and height by raw adjustment
68: // sets width to 100% and height to "remainder" height - 53px
69: formPanel.add(textArea, new AnchorLayoutData("100% -53"));
70:
71: window.add(formPanel);
72:
73: Button button = new Button("Show Form",
74: new ButtonListenerAdapter() {
75: public void onClick(Button button, EventObject e) {
76: window.show(button.getId());
77: }
78: });
79: panel.add(button);
80: }
81: return panel;
82: }
83:
84: public String getIntro() {
85: return "<p><br>Anchor Layout with Forms</b>"
86: + "<p>This example illustrates positioning form fields by anchor. A FormLayout extends AnchorLayout and "
87: + "so all anchoring layout properties apply.</p>"
88: + "<p>The 'Send To' field has an anchor property '100%' and so it takes up the rest of the panel width.</p>"
89: + "<p>The 'Subject' field also has a width anchor property of '100%' and so it takes up the rest of the panel width.</p>"
90: + "<p>The TextArea field has its label hidden and has an anchor property of '100% -53' and so it takes up the panel width and"
91: + "the rest of the panel height less 53px.</p>"
92: + "<p>The other thing worth noting is that the FormPanel is added to a Window</p>"
93: + "</p>";
94: }
95: }
|