teichmann@5861: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5861: * Software engineering by Intevation GmbH teichmann@5861: * teichmann@5993: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5861: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5993: * documentation coming with Dive4Elements River for details. teichmann@5861: */ teichmann@5861: teichmann@5835: package org.dive4elements.river.client.client.ui; ingo@1309: ingo@1309: import com.google.gwt.core.client.GWT; ingo@1309: import com.google.gwt.user.client.rpc.AsyncCallback; christian@5658: christian@2954: import com.smartgwt.client.types.Alignment; felix@1499: import com.smartgwt.client.util.SC; christian@2954: import com.smartgwt.client.widgets.Button; raimund@2540: import com.smartgwt.client.widgets.Canvas; christian@2954: import com.smartgwt.client.widgets.Window; ingo@1309: import com.smartgwt.client.widgets.events.ClickEvent; ingo@1309: import com.smartgwt.client.widgets.events.ClickHandler; christian@2954: import com.smartgwt.client.widgets.form.DynamicForm; ingo@1309: import com.smartgwt.client.widgets.form.events.ItemChangedEvent; ingo@1309: import com.smartgwt.client.widgets.form.events.ItemChangedHandler; christian@2954: import com.smartgwt.client.widgets.form.fields.CheckboxItem; christian@2954: import com.smartgwt.client.widgets.form.fields.ColorPickerItem; christian@2954: import com.smartgwt.client.widgets.form.fields.FormItem; christian@2954: import com.smartgwt.client.widgets.form.fields.SelectItem; christian@2954: import com.smartgwt.client.widgets.form.fields.StaticTextItem; felix@3352: import com.smartgwt.client.widgets.form.fields.events.BlurEvent; felix@3352: import com.smartgwt.client.widgets.form.fields.events.BlurHandler; christian@3384: import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; raimund@2540: import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; christian@3384: import com.smartgwt.client.widgets.form.validator.IsFloatValidator; christian@2954: import com.smartgwt.client.widgets.layout.HLayout; christian@2954: import com.smartgwt.client.widgets.layout.VLayout; raimund@2540: teichmann@5835: import org.dive4elements.river.client.client.Config; teichmann@5835: import org.dive4elements.river.client.client.FLYSConstants; teichmann@5835: import org.dive4elements.river.client.client.services.CollectionItemAttributeService; teichmann@5835: import org.dive4elements.river.client.client.services.CollectionItemAttributeServiceAsync; teichmann@5835: import org.dive4elements.river.client.client.services.ThemeListingService; teichmann@5835: import org.dive4elements.river.client.client.services.ThemeListingServiceAsync; teichmann@5835: import org.dive4elements.river.client.client.utils.DoubleValidator; teichmann@5835: import org.dive4elements.river.client.shared.model.Collection; teichmann@5835: import org.dive4elements.river.client.shared.model.CollectionItemAttribute; teichmann@5835: import org.dive4elements.river.client.shared.model.FacetRecord; teichmann@5835: import org.dive4elements.river.client.shared.model.Style; teichmann@5835: import org.dive4elements.river.client.shared.model.StyleSetting; teichmann@5835: import org.dive4elements.river.client.shared.model.Theme; ingo@1309: christian@2954: import java.util.Arrays; christian@2954: import java.util.LinkedHashMap; christian@2954: import java.util.Map; christian@2954: import java.util.Set; ingo@1309: ingo@1309: /** christian@3384: * Editor window for styles. ingo@1309: * @author Raimund Renkert ingo@1309: */ ingo@1309: public class StyleEditorWindow ingo@1309: extends Window ingo@1309: implements ClickHandler ingo@1309: { ingo@1309: /** The interface that provides i18n messages. */ ingo@1309: protected FLYSConstants MSG = GWT.create(FLYSConstants.class); ingo@1309: felix@1333: /** The collection. */ ingo@1309: protected Collection collection; ingo@1309: raimund@1336: /** The parent ThemePanel. */ raimund@1336: protected ThemePanel panel; ingo@1309: felix@1333: /** The attributes. */ ingo@1309: protected CollectionItemAttribute attributes; ingo@1309: ingo@1309: /** The selected facet. */ ingo@1309: protected FacetRecord facet; ingo@1309: felix@1333: /** Main layout. */ ingo@1309: protected VLayout layout; ingo@1309: felix@3355: /** The form that contains all the input widgets. */ christian@3384: protected DynamicForm df; felix@3355: raimund@2540: protected VLayout properties; felix@3355: raimund@2540: protected Canvas container; raimund@2540: raimund@2540: protected Map styleGroups; raimund@2540: raimund@2540: protected Style current; raimund@2540: raimund@2540: protected SelectItem styleChooser; raimund@2540: ingo@1309: /** The service used to set collection item attributes. */ ingo@1309: protected CollectionItemAttributeServiceAsync itemAttributeService = ingo@1309: GWT.create(CollectionItemAttributeService.class); ingo@1309: raimund@2540: /** The service used to request a list of themes. */ raimund@2540: protected ThemeListingServiceAsync themeListingService = raimund@2540: GWT.create(ThemeListingService.class); felix@1333: felix@3355: raimund@1345: /** raimund@1345: * Setup editor dialog. raimund@1345: * @param collection The collection the current theme belongs to. raimund@1345: * @param attributes The collection attributes. raimund@1345: * @param facet The selected facet. raimund@1345: */ ingo@1309: public StyleEditorWindow ( ingo@1309: Collection collection, ingo@1309: CollectionItemAttribute attributes, ingo@1309: FacetRecord facet) ingo@1309: { ingo@1309: this.collection = collection; ingo@1309: this.attributes = attributes; ingo@1309: this.facet = facet; ingo@1309: this.layout = new VLayout(); raimund@2540: this.properties = new VLayout(); raimund@2540: this.container = new Canvas(); raimund@2540: this.styleChooser = new SelectItem("style", "Style"); ingo@1309: raimund@2540: styleChooser.setTitleStyle("color:#000;"); raimund@2540: styleChooser.setTitleAlign(Alignment.LEFT); raimund@2540: styleChooser.setValue("aktuell"); raimund@2540: styleChooser.addChangedHandler(new ChangedHandler() { christian@2954: @Override raimund@2540: public void onChanged(ChangedEvent ce) { raimund@2540: String value = ce.getValue().toString(); raimund@2540: Style s = null; raimund@2540: if (value.equals("aktuell")) { raimund@2540: s = current; raimund@2540: } raimund@2540: else if (styleGroups.containsKey(value)) { raimund@2540: s = styleGroups.get(value); raimund@2540: } raimund@2540: raimund@2540: if (s != null) { raimund@2540: setNewStyle(s); raimund@2540: properties.removeMember(container); raimund@2540: container = createPropertyGrid(s); raimund@2540: properties.addMember(container); raimund@2540: } raimund@2540: } raimund@2540: }); raimund@2540: raimund@2540: DynamicForm f = new DynamicForm(); raimund@2540: f.setFields(styleChooser); raimund@2540: f.setColWidths("40%", "60%"); raimund@2540: raimund@2540: layout.addMember(f); ingo@1309: init(); ingo@1309: initPanels(); ingo@1309: } ingo@1309: ingo@1309: raimund@1345: /** raimund@1345: * Initialize the window and set the layout. raimund@1345: */ ingo@1309: protected void init() { ingo@1309: setTitle(MSG.properties()); ingo@1309: setCanDragReposition(true); ingo@1309: setCanDragResize(true); raimund@1381: layout.setMargin(10); ingo@1309: ingo@1309: layout.setWidth100(); ingo@1309: layout.setHeight100(); raimund@2540: raimund@2540: Config config = Config.getInstance(); raimund@2540: String locale = config.getLocale(); raimund@2540: raimund@2540: Theme theme = facet.getTheme(); raimund@2540: Style style = attributes.getStyle(theme.getFacet(), theme.getIndex()); christian@2954: if(style == null) { christian@2954: GWT.log("StyleEditorWindow.init(): style == null"); christian@2954: return; christian@2954: } raimund@2540: String name = style.getName(); raimund@2540: this.current = style; raimund@2540: raimund@2540: themeListingService.list( raimund@2540: locale, raimund@2540: name, raimund@2540: new AsyncCallback >() { christian@2954: @Override raimund@2540: public void onFailure(Throwable caught) { raimund@2540: GWT.log("No listloaded."); raimund@2540: } christian@2954: @Override raimund@2540: public void onSuccess(Map list) { raimund@2540: GWT.log("Successfully loaded list."); raimund@2540: raimund@2540: styleGroups = list; christian@2954: Set keys = list.keySet(); raimund@2540: LinkedHashMap valueMap = raimund@2540: new LinkedHashMap(); raimund@2540: valueMap.put("aktuell", "Aktuell"); teichmann@6100: for (String s: keys) { raimund@2540: Style tmp = styleGroups.get(s); raimund@2543: tmp.setFacet(current.getFacet()); raimund@2543: tmp.setIndex(current.getIndex()); raimund@2540: valueMap.put(s, s); raimund@2540: } raimund@2540: styleChooser.setValueMap(valueMap); raimund@2540: } raimund@2540: }); ingo@1309: } ingo@1309: ingo@1309: raimund@1345: /** raimund@1345: * Initialize the static window content like buttons and main layout. raimund@1345: */ ingo@1309: protected void initPanels() { ingo@1309: HLayout buttons = new HLayout(); ingo@1309: Button accept = new Button(MSG.label_ok()); ingo@1309: Button cancel = new Button(MSG.label_cancel()); ingo@1309: cancel.addClickHandler(this); ingo@1309: accept.addClickHandler(new ClickHandler() { christian@2954: @Override ingo@1309: public void onClick(ClickEvent e) { felix@3355: // TODO Fix this, for whatever reason it doesnt work felix@3355: // (always valid). rrenkert@4697: if (df == null) { rrenkert@4697: return; rrenkert@4697: } felix@3355: if (!df.hasErrors() && df.validate()) { felix@3355: saveStyle(); felix@3355: } ingo@1309: } ingo@1309: }); ingo@1309: ingo@1309: buttons.addMember(accept); ingo@1309: buttons.addMember(cancel); raimund@1381: buttons.setAlign(Alignment.CENTER); raimund@1381: buttons.setHeight(30); ingo@1309: raimund@2540: Theme theme = facet.getTheme(); raimund@2540: Style style = attributes.getStyle(theme.getFacet(), theme.getIndex()); raimund@1348: raimund@2540: container = createPropertyGrid(style); raimund@2540: properties.addMember(container); raimund@2540: layout.addMember(properties); ingo@1309: layout.addMember(buttons); ingo@1309: addItem(layout); ingo@2472: setWidth(400); raimund@1381: setHeight(410); ingo@1309: } ingo@1309: ingo@1309: raimund@1345: /** raimund@1345: * Setter for the parent panel. raimund@1345: * @param panel The panel. raimund@1345: */ raimund@1336: public void setThemePanel (ThemePanel panel) { raimund@1336: this.panel = panel; ingo@1309: } ingo@1309: ingo@1309: raimund@1345: /** raimund@1345: * this method is called when the user aborts theming. raimund@1345: * @param event The event. raimund@1345: */ christian@2954: @Override ingo@1309: public void onClick(ClickEvent event) { ingo@1309: this.hide(); ingo@1309: } ingo@1309: ingo@1309: raimund@1345: /** raimund@1345: * This method creates the property grid for available styling attributes. raimund@1345: * @return The layout containing the UI elements. raimund@1345: */ raimund@2540: protected VLayout createPropertyGrid(Style style) { raimund@2540: VLayout vl = new VLayout(); ingo@1309: raimund@1337: StaticTextItem name = new StaticTextItem("name", "Name"); ingo@1309: name.setValue(facet.getName()); ingo@2472: name.setTitleStyle("color:#000;"); ingo@1309: name.setTitleAlign(Alignment.LEFT); ingo@1309: name.setDisabled(true); ingo@1309: name.setShowDisabled(false); raimund@2540: felix@1450: DynamicForm form = new DynamicForm(); felix@1450: form.setFields(name); ingo@2472: form.setColWidths("40%", "60%"); ingo@2472: raimund@2540: raimund@2540: vl.addMember(form); ingo@1309: felix@1499: if (style == null) { raimund@2540: SC.warn("No style found."); raimund@2540: return vl; felix@1499: } felix@1499: felix@1451: // Done via array to keep the order. felix@1451: String[] sets = {"showlines", gernotbelger@8910: "showborder", felix@1451: "showpoints", felix@1451: "linetype", felix@1451: "linesize", felix@1451: "linecolor", felix@1451: "font", felix@1451: "textstyle", felix@1451: "textsize", ingo@2908: "pointcolor", ingo@1495: "pointsize", rrenkert@4666: "showpointlabel", felix@1451: "textcolor", felix@1451: "backgroundcolor", felix@2499: "showbackground", felix@2499: "showlinelabel", christian@3384: "labelfontface", christian@3384: "labelfontcolor", christian@3384: "labelfontsize", christian@3384: "labelfontstyle", christian@3703: "textorientation", christian@3384: "labelshowbg", christian@3384: "labelbgcolor", rrenkert@4666: "bandwidth", felix@3364: "bandwidthcolor", rrenkert@4666: "transparency", rrenkert@4666: "showminimum", rrenkert@4666: "showmaximum"}; felix@1451: felix@1451: for (String settingName: sets) { felix@1451: StyleSetting set = style.getSetting(settingName); felix@1451: ingo@2908: if (set == null || set.isHidden()) { felix@1451: continue; felix@1451: } felix@1451: felix@1451: DynamicForm property = createPropertyUI( felix@1451: set.getDisplayName(), andre@8601: set.getName().toLowerCase(), andre@8601: set.getType().toLowerCase(), felix@1451: set.getDefaultValue()); christian@5658: if (property != null) { christian@5658: vl.addMember(property); christian@5658: } felix@1451: } felix@1451: felix@1451: // Add settings not in whitelist above. felix@1450: for (StyleSetting set: style.getSettings()) { raimund@1380: rrenkert@4666: if (Arrays.asList(sets).contains(set.getName()) || rrenkert@4666: set == null || rrenkert@4666: set.isHidden() rrenkert@4666: ) { raimund@1380: continue; raimund@1380: } raimund@1380: ingo@1309: DynamicForm property = createPropertyUI( ingo@1309: set.getDisplayName(), andre@8600: set.getName().toLowerCase(), andre@8600: set.getType().toLowerCase(), ingo@1309: set.getDefaultValue()); christian@5658: if (property != null) { christian@5658: vl.addMember(property); christian@5658: } ingo@1309: } felix@1450: raimund@2540: return vl; ingo@1309: } ingo@1309: raimund@1336: raimund@1345: /** raimund@1345: * Create a property form. raimund@1345: * @param dname The display name. raimund@1345: * @param name The property name. raimund@1345: * @param type The property type. raimund@1345: * @param value The current value. raimund@1345: * raimund@1345: * @return The dynamic form for the attribute property. raimund@1345: */ ingo@1309: protected DynamicForm createPropertyUI( gernotbelger@8910: // FIXME: display name (which comes from the server side) is not used but i10n happens on client side,, ingo@1309: String dname, ingo@1309: String name, ingo@1309: String type, ingo@1309: String value) ingo@1309: { felix@3355: df = new DynamicForm(); ingo@2472: df.setColWidths("40%", "60%"); ingo@1309: ingo@1309: FormItem f; ingo@1309: if(type.equals("int")) { raimund@1479: f = new SelectItem(name, MSG.getString(name)); raimund@1348: if (name.equals("linesize")) { raimund@1348: f = createLineSizeUI(f); christian@3700: f.setValue(value); raimund@1348: } felix@7581: else if (name.equals("labelfontsize") || name.equals("textsize")) { tom@8856: LinkedHashMap valueMap = tom@8856: new LinkedHashMap(); raimund@1348: valueMap.put("3", "3"); raimund@1348: valueMap.put("5", "5"); raimund@1348: valueMap.put("8", "8"); raimund@1348: valueMap.put("10", "10"); raimund@1348: valueMap.put("12", "12"); raimund@1348: valueMap.put("14", "14"); raimund@1348: valueMap.put("18", "18"); raimund@1348: valueMap.put("24", "24"); raimund@1348: f.setValueMap(valueMap); christian@3700: f.setValue(value); raimund@1348: } felix@3349: else if (name.equals("bandwidth")) { tom@8856: LinkedHashMap valueMap = tom@8856: new LinkedHashMap(); felix@3349: valueMap.put("0", "0"); felix@3349: valueMap.put("1", "1"); felix@3349: valueMap.put("2", "2"); felix@3349: valueMap.put("3", "3"); felix@3349: valueMap.put("4", "4"); felix@3349: valueMap.put("5", "5"); felix@3349: valueMap.put("6", "6"); felix@3349: valueMap.put("7", "7"); felix@3349: valueMap.put("8", "8"); felix@3349: valueMap.put("9", "9"); felix@3349: valueMap.put("10", "10"); felix@3349: valueMap.put("11", "11"); felix@3349: f.setValueMap(valueMap); christian@3700: f.setValue(value); felix@3349: } ingo@1495: else if (name.equals("pointsize")) { tom@8856: LinkedHashMap valueMap = tom@8856: new LinkedHashMap(); ingo@1495: valueMap.put("1", "1"); felix@2433: valueMap.put("2", "2"); ingo@1495: valueMap.put("3", "3"); felix@2433: valueMap.put("4", "4"); ingo@1495: valueMap.put("5", "5"); felix@2433: valueMap.put("6", "6"); ingo@1495: valueMap.put("7", "7"); ingo@1495: f.setValueMap(valueMap); christian@3700: f.setValue(value); ingo@1495: } christian@4577: else if (name.equals("numclasses")) { tom@8856: LinkedHashMap valueMap = tom@8856: new LinkedHashMap(); christian@4577: valueMap.put("5", "5"); christian@4577: valueMap.put("6", "6"); christian@4577: valueMap.put("7", "7"); christian@4577: valueMap.put("8", "8"); christian@4577: valueMap.put("9", "9"); christian@4577: valueMap.put("10", "10"); christian@4577: valueMap.put("12", "12"); christian@4577: valueMap.put("14", "14"); christian@4577: valueMap.put("16", "16"); christian@4577: valueMap.put("18", "18"); christian@4577: valueMap.put("20", "20"); christian@4577: f.setValueMap(valueMap); christian@4577: f.setValue(value); christian@5658: // FIXME: Make that work again christian@5658: return null; christian@4577: } rrenkert@4687: else if (name.contains("transparency")) { tom@8856: LinkedHashMap valueMap = tom@8856: new LinkedHashMap(); christian@3700: for (int n = 10; n < 100; n += 10) { christian@3700: valueMap.put(Integer.toString(n), n + "%"); christian@3700: } christian@3700: f.setValueMap(valueMap); christian@3702: f.setValue(value); christian@3700: } ingo@1309: } ingo@1309: else if (type.equals("boolean")) { raimund@1359: if(name.equals("textorientation")) { raimund@1479: f = new SelectItem(name, MSG.getString(name)); tom@8856: LinkedHashMap valueMap = tom@8856: new LinkedHashMap(); christian@3703: valueMap.put("true", MSG.getString("horizontal")); christian@3703: valueMap.put("false", MSG.getString("vertical")); raimund@1359: f.setValueMap(valueMap); raimund@1359: f.setValue(value); ingo@1309: } ingo@1309: else { raimund@1479: CheckboxItem c = new CheckboxItem(name, MSG.getString(name)); raimund@1359: if(value.equals("true")) { raimund@1359: c.setValue(true); raimund@1359: } raimund@1359: else { raimund@1359: c.setValue(false); raimund@1359: } raimund@1359: c.setLabelAsTitle(true); raimund@1359: f = c; ingo@1309: } ingo@1309: } andre@8600: else if (type.equals("color")) { raimund@1479: ColorPickerItem c = new ColorPickerItem(name, MSG.getString(name)); ingo@1309: c.setValue(rgbToHtml(value)); ingo@1309: f = c; ingo@1309: } felix@3352: else if (type.equals("double")) { felix@3355: f = new FormItem(name); felix@3355: IsFloatValidator fpv = new IsFloatValidator(); felix@3355: felix@3355: f.setValidators(fpv); felix@3355: f.setValidateOnChange(true); felix@3355: f.setTitle(MSG.getString(name)); felix@3352: f.addBlurHandler(new BlurHandler() { christian@3384: @Override felix@3352: public void onBlur(BlurEvent e) { felix@3352: DoubleValidator validator = new DoubleValidator(); christian@3384: Map errors = e.getForm().getErrors(); felix@3352: if(validator.validate(e.getItem(), errors)) { felix@3352: e.getForm().setErrors(errors, true); felix@3352: } felix@3352: else { felix@3352: e.getForm().setErrors(errors, true); felix@3352: } felix@3352: } felix@3352: }); felix@3364: f.setValue(value); felix@3352: } andre@8600: else if (type.equals("dash")) { raimund@1479: f = new SelectItem(name, MSG.getString(name)); tom@8856: LinkedHashMap valueIcons = tom@8856: new LinkedHashMap(); tom@8856: f.setImageURLPrefix(GWT.getHostPageBaseURL() tom@8856: + "images/linestyle-dash-"); raimund@1341: f.setImageURLSuffix(".png"); raimund@1341: f.setValueIconHeight(20); raimund@1341: f.setValueIconWidth(80); tom@8856: LinkedHashMap valueMap = tom@8856: new LinkedHashMap(); raimund@1341: valueMap.put("10", ""); raimund@1341: valueMap.put("10,5", ""); raimund@1341: valueMap.put("20,10", ""); raimund@1341: valueMap.put("30,10", ""); raimund@1341: valueMap.put("20,5,15,5", ""); raimund@1341: valueIcons.put("10", "10"); raimund@1341: valueIcons.put("10,5", "10-5"); raimund@1341: valueIcons.put("20,10", "20-10"); raimund@1341: valueIcons.put("30,10", "30-10"); raimund@1341: valueIcons.put("20,5,15,5", "20-5-15-5"); raimund@1341: f.setValueIcons(valueIcons); raimund@1341: f.setValueMap(valueMap); ingo@1309: f.setValue(value); ingo@1309: } gernotbelger@8910: else if (type.equals("areapattern")) { gernotbelger@8910: f = createAreaPetternUi(name, value); gernotbelger@8910: } andre@8600: else if (type.equals("font")) { raimund@1479: f = new SelectItem(name, MSG.getString(name)); tom@8856: LinkedHashMap valueMap = tom@8856: new LinkedHashMap(); tom@8856: valueMap.put( tom@8856: "arial", "Arial"); tom@8856: valueMap.put( tom@8856: "courier", "Courier"); tom@8856: valueMap.put( tom@8856: "verdana", "Verdana"); tom@8856: valueMap.put( tom@8856: "times", "Times"); raimund@1348: f.setValueMap(valueMap); raimund@1348: f.setValue(value); raimund@1348: } andre@8600: else if (type.equals("style")) { raimund@1479: f = new SelectItem(name, MSG.getString(name)); tom@8856: LinkedHashMap valueMap = tom@8856: new LinkedHashMap(); tom@8856: valueMap.put( tom@8856: "standard", "Normal"); tom@8856: valueMap.put( tom@8856: "bold", "Bold"); tom@8856: valueMap.put( tom@8856: "italic", "Italic"); raimund@1359: f.setValueMap(valueMap); raimund@1359: f.setValue(value); raimund@1359: } andre@8600: else if (type.equals("symbol")) { raimund@2458: //create an empty element as long as this property can not be raimund@2458: //changed. raimund@2458: f = new StaticTextItem(""); raimund@2458: } ingo@1309: else { ingo@1309: f = new FormItem(); ingo@1309: } ingo@2472: f.setTitleStyle("color:#000;"); ingo@1309: f.setTitleAlign(Alignment.LEFT); ingo@1309: df.setFields(f); ingo@1309: df.addItemChangedHandler(new ItemChangedHandler() { christian@2954: @Override ingo@1309: public void onItemChanged(ItemChangedEvent e) { ingo@1309: String name = e.getItem().getName(); ingo@1309: String newValue = e.getNewValue().toString(); ingo@1309: setNewValue(name, newValue); ingo@1309: } ingo@1309: }); ingo@1309: ingo@1309: return df; ingo@1309: } ingo@1309: felix@1333: gernotbelger@8910: private FormItem createAreaPetternUi(String name, String value) { gernotbelger@8910: final FormItem f = new SelectItem(name, MSG.getString(name)); gernotbelger@8910: gernotbelger@8910: f.setImageURLPrefix(GWT.getHostPageBaseURL() + "images/areapattern-"); gernotbelger@8910: f.setImageURLSuffix(".png"); gernotbelger@8910: f.setValueIconHeight(20); gernotbelger@8910: f.setValueIconWidth(80); gernotbelger@8910: gernotbelger@8910: final LinkedHashMap valueMap = new LinkedHashMap(); gernotbelger@8910: final Map valueIcons = new LinkedHashMap(); gernotbelger@8910: gernotbelger@8910: // FIXME: ugly, using knowledge of available patterns at this point, creating redundancy with AreaFillPattern enum. gernotbelger@8910: // But the whole code does it like that, so this is 'flys style' gernotbelger@8913: final String[] patterns = new String[] {"patternFill", // gernotbelger@8913: "patternPoints", // gernotbelger@8913: "paternCross", // gernotbelger@8913: "patternDagonalLeft", // gernotbelger@8913: "patternDiagonalRight"}; gernotbelger@8913: gernotbelger@8910: for (int i = 0; i < patterns.length; i++) { gernotbelger@8910: final String pattern = patterns[i]; gernotbelger@8910: gernotbelger@8910: valueMap.put(pattern, ""); gernotbelger@8910: valueIcons.put(pattern, pattern); gernotbelger@8910: } gernotbelger@8910: gernotbelger@8910: f.setValueIcons(valueIcons); gernotbelger@8910: f.setValueMap(valueMap); gernotbelger@8910: f.setValue(value); gernotbelger@8910: return f; gernotbelger@8910: } gernotbelger@8910: raimund@1348: protected FormItem createLineSizeUI(FormItem f) { tom@8856: LinkedHashMap valueIcons = tom@8856: new LinkedHashMap(); raimund@1348: f.setImageURLPrefix(GWT.getHostPageBaseURL() + "images/linestyle-"); raimund@1348: f.setImageURLSuffix("px.png"); raimund@1348: f.setValueIconHeight(20); raimund@1348: f.setValueIconWidth(80); tom@8856: LinkedHashMap valueMap = tom@8856: new LinkedHashMap(); raimund@1348: valueMap.put("1", ""); raimund@1348: valueMap.put("2", ""); raimund@1348: valueMap.put("3", ""); raimund@1348: valueMap.put("4", ""); raimund@1348: valueMap.put("5", ""); raimund@1348: valueMap.put("6", ""); raimund@1348: valueMap.put("7", ""); raimund@1348: valueMap.put("8", ""); raimund@1348: valueIcons.put("1", "1"); raimund@1348: valueIcons.put("2", "2"); raimund@1348: valueIcons.put("3", "3"); raimund@1348: valueIcons.put("4", "4"); raimund@1348: valueIcons.put("5", "5"); raimund@1348: valueIcons.put("6", "6"); raimund@1348: valueIcons.put("7", "7"); raimund@1348: valueIcons.put("8", "8"); raimund@1348: f.setValueIcons(valueIcons); raimund@1348: f.setValueMap(valueMap); raimund@1348: return f; raimund@1348: } raimund@1348: raimund@1348: raimund@1345: /** raimund@1345: * Static method to convert a color from RGB to HTML notation. raimund@1345: * @param rgb String in RGB notation. raimund@1345: * raimund@1345: * @return String in HTML notation. raimund@1345: */ felix@1333: protected static String rgbToHtml(String rgb) { ingo@1309: String[] parts = rgb.split(","); ingo@1309: int values[] = new int[parts.length]; ingo@1309: for (int i = 0; i < parts.length; i++) { ingo@1309: parts[i] = parts[i].trim(); ingo@1309: try { ingo@1309: values[i] = Integer.parseInt(parts[i]); ingo@1309: } ingo@1309: catch(NumberFormatException nfe) { ingo@1309: return "#000000"; ingo@1309: } ingo@1309: } ingo@1309: String hex = "#"; ingo@1309: for (int i = 0; i < values.length; i++) { ingo@1309: if (values[i] < 16) { ingo@1309: hex += "0"; ingo@1309: } ingo@1309: hex += Integer.toHexString(values[i]); ingo@1309: } ingo@1309: return hex; ingo@1309: } ingo@1309: felix@1333: raimund@1345: /** raimund@1345: * Static method to convert a color from HTML to RGB notation. raimund@1345: * @param html String in HTML notation. raimund@1345: * raimund@1345: * @return String in RGB notation. raimund@1345: */ felix@1333: protected static String htmlToRgb(String html) { ingo@1309: if (!html.startsWith("#")) { ingo@1309: return "0, 0, 0"; ingo@1309: } ingo@1309: ingo@1309: int r = Integer.valueOf(html.substring(1, 3), 16); ingo@1309: int g = Integer.valueOf(html.substring(3, 5), 16); ingo@1309: int b = Integer.valueOf(html.substring(5, 7), 16); ingo@1309: ingo@1309: return r + ", " + g + ", " + b; ingo@1309: } ingo@1309: felix@1333: raimund@1345: /** raimund@1345: * Saves the current style attributes and requests a redraw. raimund@1345: */ ingo@1309: protected void saveStyle () { ingo@1309: GWT.log("StyleEditorWindow.saveStyle()"); ingo@1309: Config config = Config.getInstance(); ingo@1309: String locale = config.getLocale(); ingo@1309: ingo@1309: itemAttributeService.setCollectionItemAttribute( ingo@1309: this.collection, ingo@1309: attributes.getArtifact(), ingo@1309: locale, ingo@1309: attributes, ingo@1309: new AsyncCallback() { christian@2954: @Override ingo@1309: public void onFailure (Throwable caught) { ingo@1309: GWT.log("Could not set Collection item attributes."); ingo@1309: } christian@2954: @Override ingo@1309: public void onSuccess(Void v) { ingo@1309: GWT.log("Successfully saved collection item attributes."); raimund@1336: panel.requestRedraw(); ingo@1309: } ingo@1309: }); ingo@1309: ingo@1309: ingo@1309: this.hide(); ingo@1309: } ingo@1309: felix@1333: raimund@1345: /** raimund@1345: * Sets a new value for an attribute. raimund@1345: * @param name Attribute name. raimund@1345: * @param value The new value. raimund@1345: */ ingo@1309: protected final void setNewValue(String name, String value) { raimund@1326: Theme t = facet.getTheme(); raimund@1326: Style s = attributes.getStyle(t.getFacet(), t.getIndex()); ingo@1309: StyleSetting set = s.getSetting(name); ingo@2472: String type = set.getType(); ingo@2472: ingo@2472: if(name.indexOf("color") != -1 ingo@2472: || (type != null && type.toLowerCase().indexOf("color") > -1)) { ingo@1309: value = htmlToRgb(value); ingo@1309: } ingo@1309: set.setDefaultValue(value); ingo@1309: } raimund@2540: raimund@2540: raimund@2540: protected final void setNewStyle(Style style) { raimund@2540: Theme t = facet.getTheme(); raimund@2540: Style s = attributes.getStyle(t.getFacet(), t.getIndex()); raimund@2540: attributes.removeStyle(s.getName()); raimund@2540: attributes.appendStyle(style); raimund@2540: } ingo@1309: } ingo@1309: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :