raimund@1287: package de.intevation.flys.client.client.ui.chart; raimund@1287: raimund@1287: import com.google.gwt.core.client.GWT; raimund@1287: raimund@1287: import com.smartgwt.client.widgets.Window; raimund@1287: import com.smartgwt.client.widgets.layout.VLayout; raimund@1287: import com.smartgwt.client.widgets.layout.HLayout; raimund@1287: import com.smartgwt.client.widgets.Button; raimund@1290: import com.smartgwt.client.widgets.form.DynamicForm; raimund@1290: import com.smartgwt.client.widgets.form.fields.FormItem; raimund@1290: import com.smartgwt.client.widgets.form.fields.CheckboxItem; raimund@1290: import com.smartgwt.client.widgets.form.fields.SpinnerItem; raimund@1290: import com.smartgwt.client.widgets.form.fields.ColorPickerItem; raimund@1290: import com.smartgwt.client.widgets.form.fields.ComboBoxItem; raimund@1287: raimund@1287: import com.smartgwt.client.widgets.events.ClickEvent; raimund@1287: import com.smartgwt.client.widgets.events.ClickHandler; raimund@1290: import com.smartgwt.client.types.Alignment; raimund@1287: raimund@1287: import de.intevation.flys.client.shared.model.Collection; raimund@1287: import de.intevation.flys.client.shared.model.CollectionItemAttribute; raimund@1290: import de.intevation.flys.client.shared.model.Style; raimund@1290: import de.intevation.flys.client.shared.model.StyleSetting; raimund@1287: import de.intevation.flys.client.client.ui.CollectionView; raimund@1287: raimund@1287: import de.intevation.flys.client.client.FLYSConstants; raimund@1287: raimund@1287: /** raimund@1287: * @author Raimund Renkert raimund@1287: */ raimund@1287: public class StyleEditorWindow raimund@1287: extends Window raimund@1287: implements ClickHandler raimund@1287: { raimund@1287: /** The interface that provides i18n messages. */ raimund@1287: protected FLYSConstants MSG = GWT.create(FLYSConstants.class); raimund@1287: raimund@1287: /** The collection */ raimund@1287: protected Collection collection; raimund@1287: raimund@1287: /** The parent collection view */ raimund@1287: protected CollectionView view; raimund@1287: raimund@1287: /** The attributes */ raimund@1287: protected CollectionItemAttribute attributes; raimund@1287: raimund@1287: /** Main layout */ raimund@1287: protected VLayout layout; raimund@1287: raimund@1287: raimund@1287: public StyleEditorWindow ( raimund@1287: Collection collection, raimund@1287: CollectionItemAttribute attributes) raimund@1287: { raimund@1287: this.collection = collection; raimund@1287: this.attributes = attributes; raimund@1287: this.layout = new VLayout(); raimund@1287: raimund@1287: init(); raimund@1287: initPanels(); raimund@1287: } raimund@1287: raimund@1287: raimund@1287: protected void init() { raimund@1287: setTitle(MSG.properties()); raimund@1290: setWidth(270); raimund@1290: setHeight(200); raimund@1287: setCanDragReposition(true); raimund@1287: setCanDragResize(true); raimund@1287: setKeepInParentRect(true); raimund@1287: raimund@1287: layout.setWidth100(); raimund@1287: layout.setHeight100(); raimund@1287: raimund@1287: } raimund@1287: raimund@1287: raimund@1287: protected void initPanels() { raimund@1287: HLayout buttons = new HLayout(); raimund@1287: Button accept = new Button(MSG.label_ok()); raimund@1287: Button cancel = new Button(MSG.label_cancel()); raimund@1287: cancel.addClickHandler(this); raimund@1290: accept.addClickHandler(new ClickHandler() { raimund@1290: public void onClick(ClickEvent e) { raimund@1287: raimund@1290: } raimund@1290: }); raimund@1287: raimund@1287: buttons.addMember(accept); raimund@1287: buttons.addMember(cancel); raimund@1290: buttons.setAlign(Alignment.RIGHT); raimund@1290: raimund@1290: layout.addMember(createPropertyGrid("LongitudinalSectionW"));; raimund@1287: layout.addMember(buttons); raimund@1287: addItem(layout); raimund@1287: } raimund@1287: raimund@1287: raimund@1287: public void setCollectionView (CollectionView view) { raimund@1287: this.view = view; raimund@1287: setParentElement(this.view.getParentElement()); raimund@1287: } raimund@1287: raimund@1287: raimund@1287: public void onClick(ClickEvent event) { raimund@1287: this.hide(); raimund@1287: } raimund@1290: raimund@1290: raimund@1290: protected VLayout createPropertyGrid(String stylename) { raimund@1290: //TODO use the style-(theme-)name from response to get the correct raimund@1290: //attribute set. raimund@1290: raimund@1290: VLayout properties = new VLayout(); raimund@1290: raimund@1290: // get the correct style using the name. raimund@1290: Style s = attributes.getStyle(0); raimund@1290: raimund@1290: for (int i = 0; i < s.getNumSettings(); i ++) { raimund@1290: final StyleSetting set = s.getSetting(i); raimund@1290: DynamicForm property = createPropertyUI( raimund@1290: set.getDisplayName(), raimund@1290: set.getName(), raimund@1290: set.getType(), raimund@1290: set.getDefaultValue()); raimund@1290: properties.addMember(property); raimund@1290: } raimund@1290: return properties; raimund@1290: } raimund@1290: raimund@1290: protected DynamicForm createPropertyUI( raimund@1290: String dname, raimund@1290: String name, raimund@1290: String type, raimund@1290: String value) raimund@1290: { raimund@1290: DynamicForm df = new DynamicForm(); raimund@1290: raimund@1290: FormItem f; raimund@1290: if(type.equals("int")) { raimund@1290: SpinnerItem s = new SpinnerItem(name, dname); raimund@1290: s.setMin(1); raimund@1290: s.setMax(10); raimund@1291: s.setValue(value); raimund@1290: f = s; raimund@1290: } raimund@1290: else if (type.equals("boolean")) { raimund@1290: CheckboxItem c = new CheckboxItem(name, dname); raimund@1290: if(value.equals("true")) { raimund@1290: c.setValue(true); raimund@1290: } raimund@1290: else { raimund@1290: c.setValue(false); raimund@1290: } raimund@1290: c.setLabelAsTitle(true); raimund@1290: f = c; raimund@1290: } raimund@1290: else if (type.equals("Color")) { raimund@1291: ColorPickerItem c = new ColorPickerItem(name, dname); raimund@1291: c.setValue(rgbToHtml(value)); raimund@1291: f = c; raimund@1290: } raimund@1290: else if (type.equals("Dash")) { raimund@1290: f = new ComboBoxItem(name, dname); raimund@1291: f.setValue(value); raimund@1290: } raimund@1290: else { raimund@1290: f = new FormItem(); raimund@1290: } raimund@1290: f.setTitleStyle("color:#000; width:120px"); raimund@1290: f.setTitleAlign(Alignment.LEFT); raimund@1290: df.setFields(f); raimund@1290: raimund@1290: return df; raimund@1290: } raimund@1291: raimund@1291: protected String rgbToHtml(String rgb) { raimund@1291: String[] parts = rgb.split(","); raimund@1291: int values[] = new int[parts.length]; raimund@1291: for (int i = 0; i < parts.length; i++) { raimund@1291: parts[i] = parts[i].trim(); raimund@1291: try { raimund@1291: values[i] = Integer.parseInt(parts[i]); raimund@1291: } raimund@1291: catch(NumberFormatException nfe) { raimund@1291: return "#000000"; raimund@1291: } raimund@1291: } raimund@1291: String hex = "#"; raimund@1291: for (int i = 0; i < values.length; i++) { raimund@1291: hex += Integer.toHexString(values[i]); raimund@1291: } raimund@1291: return hex; raimund@1291: } raimund@1291: raimund@1291: protected String htmlToRgb(String html) { raimund@1291: if (!html.startsWith("#")) { raimund@1291: return "0, 0, 0"; raimund@1291: } raimund@1291: raimund@1291: GWT.log("sub: " + html.substring(1, 3)); raimund@1291: int r = Integer.valueOf(html.substring(1, 3), 16); raimund@1291: int g = Integer.valueOf(html.substring(3, 5), 16); raimund@1291: int b = Integer.valueOf(html.substring(5, 7), 16); raimund@1291: raimund@1291: return r + ", " + g + ", " + b; raimund@1291: } raimund@1291: raimund@1287: } raimund@1290: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :