View Javadoc

1   /**********************************************
2    * Copyright (C) 2011 Lukas Laag
3    * This file is part of svgreal.
4    * 
5    * svgreal is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    * 
10   * svgreal is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License
16   * along with svgreal.  If not, see http://www.gnu.org/licenses/
17   **********************************************/
18  package org.vectomatic.svg.edit.client.gxt.form;
19  
20  import org.vectomatic.svg.edit.client.model.CssMetadata;
21  
22  import com.extjs.gxt.ui.client.util.Format;
23  import com.extjs.gxt.ui.client.widget.Component;
24  import com.extjs.gxt.ui.client.widget.LayoutContainer;
25  import com.extjs.gxt.ui.client.widget.form.Field;
26  import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
27  import com.extjs.gxt.ui.client.widget.layout.ColumnData;
28  import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
29  import com.extjs.gxt.ui.client.widget.layout.FormData;
30  import com.extjs.gxt.ui.client.widget.layout.FormLayout;
31  
32  /**
33   * Class to create a composite widget dedicated to editing
34   * CSS properties (a widget for CSS value plus
35   * a button to reset the value to its default)
36   * @author laaglu
37   */
38  public class CssContainer extends LayoutContainer {
39  	protected CssMetadata<?> metadata;
40  	
41  	public CssContainer(CssMetadata<?> metadata, Component component) {
42  		this.metadata = metadata;
43  
44  		ResetButtonField buttonField = new ResetButtonField(metadata);
45  		buttonField.setName(metadata.getName());
46  		
47  		FormData formData = new FormData("100%");
48  		LayoutContainer left = new LayoutContainer();  
49  		left.setStyleAttribute("paddingRight", "10px");  
50  		FormLayout layout = new FormLayout();  
51  		layout.setLabelAlign(LabelAlign.TOP);
52  		left.setLayout(layout);
53  		if (component instanceof Field) {
54  			Field<?> field = (Field<?>)component;
55  			field.setFieldLabel(Format.capitalize(metadata.getDescription()));
56  			field.setName(metadata.getName());
57  		}
58  		left.add(component, formData);
59  	
60  		LayoutContainer right = new LayoutContainer();
61  		right.setStyleAttribute("paddingLeft", "10px");
62  		layout = new FormLayout();
63  		layout.setLabelAlign(LabelAlign.TOP);
64  		layout.setLabelSeparator("");
65  		right.setLayout(layout); 
66  		right.add(buttonField, formData);
67  		setLayout(new ColumnLayout());
68  		add(left, new ColumnData(.8f));
69  		add(right, new ColumnData(.2f)); 		
70  	}
71  }