/* * Smart GWT (GWT for SmartClient) * Copyright 2008 and beyond, Isomorphic Software, Inc. * * Smart GWT is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3 * as published by the Free Software Foundation. Smart GWT is also * available under typical commercial license terms - see * http://smartclient.com/license * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ import java.util.ArrayList; import java.util.List; import java.util.HashMap; import java.util.Map; import com.smartgwt.client.util.SC; import com.smartgwt.client.util.BooleanCallback; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.fields.SelectItem; import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.types.ImageStyle; import com.smartgwt.client.types.Overflow; import com.smartgwt.client.types.Alignment; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Img; import com.smartgwt.client.widgets.ImgButton; import com.google.gwt.core.client.EntryPoint; public class SVGImgSample implements EntryPoint { public void onModuleLoad() { final String svgPath = "svg/"; Canvas canvas = new Canvas(); Img circle = new Img(); circle.setID("circle"); circle.setLeft(20); circle.setTop(75); circle.setWidth(100); circle.setHeight(100); circle.setOverflow(Overflow.HIDDEN); circle.setImageType(ImageStyle.NORMAL); circle.setSrc(svgPath + "circle.svg"); canvas.addChild(circle); Img square = new Img(); square.setID("square"); square.setLeft(145); square.setTop(75); square.setWidth(100); square.setHeight(100); square.setOverflow(Overflow.HIDDEN); square.setImageType(ImageStyle.NORMAL); square.setSrc(svgPath + "square.svg"); canvas.addChild(square); Img bouncyText = new Img(); bouncyText.setID("bouncyText"); bouncyText.setLeft(270); bouncyText.setTop(80); bouncyText.setWidth(150); bouncyText.setHeight(90); bouncyText.setOverflow(Overflow.HIDDEN); bouncyText.setImageType(ImageStyle.NORMAL); bouncyText.setBorder("1px solid gray"); bouncyText.setSrc(svgPath + "bouncyText.svg"); canvas.addChild(bouncyText); final List
listImages = new ArrayList
(); listImages.add(circle); listImages.add(square); listImages.add(bouncyText); DynamicForm form = new DynamicForm(); form.setLeft(22); form.setTop(15); form.setWidth(400); SelectItem selectItem = new SelectItem(); selectItem.setWrapTitle(false); selectItem.setTitle("Select Image Color Scheme"); selectItem.setWidth(155); selectItem.setAlign(Alignment.RIGHT); selectItem.setDefaultValue(0); Map mapValues = new HashMap(); mapValues.put(0, "Green"); mapValues.put(1, "Red"); selectItem.setValueMap(mapValues); selectItem.addChangedHandler(new ChangedHandler() { @Override public void onChanged(ChangedEvent event) { for (int i = 0; i < listImages.size(); i++) { String src = svgPath + listImages.get(i).getID(); if (Integer.parseInt((String)event.getValue()) > 0) src += "-" + "red"; listImages.get(i).setSrc(src + ".svg"); } } }); form.setFields(selectItem); canvas.addChild(form); ImgButton imgButton = new ImgButton(); imgButton.setHeight(200); imgButton.setLeft(75); imgButton.setTop(225); imgButton.setWidth(300); imgButton.setCanFocus(false); imgButton.setSrc(svgPath + "ellipse.svg"); imgButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { SC.ask("Are you sure you want to click on this button?", new BooleanCallback() { @Override public void execute(Boolean value) { } }); } }); canvas.addChild(imgButton); canvas.draw(); } }