Created
June 13, 2017 18:05
-
-
Save branflake2267/25d12cc2837261efc5859436af169528 to your computer and use it in GitHub Desktop.
Another way to resize SVG in GXT 4 using Resizable.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.gwt.core.client.EntryPoint; | |
import com.google.gwt.core.client.GWT; | |
import com.google.gwt.dom.client.Style.Display; | |
import com.google.gwt.user.client.ui.InlineHTML; | |
import com.google.gwt.user.client.ui.RootPanel; | |
import com.sencha.gxt.core.client.dom.XElement; | |
import com.sencha.gxt.widget.core.client.Resizable; | |
import com.sencha.gxt.widget.core.client.container.FlowLayoutContainer; | |
import com.sencha.gxt.widget.core.client.event.ResizeEndEvent; | |
import com.sencha.gxt.widget.core.client.event.ResizeEndEvent.ResizeEndHandler; | |
public class ResizeSvg implements EntryPoint { | |
@Override | |
public void onModuleLoad() { | |
String svg = "<svg width=\"100\" height=\"100\">\n" + | |
"<circle cx=\"50\" cy=\"50\" r=\"40\" stroke=\"brown\" stroke-width=\"4\" fill=\"orange\" />\n" + | |
"</svg>"; | |
InlineHTML html = new InlineHTML(svg); | |
final FlowLayoutContainer wrapper = new FlowLayoutContainer(); | |
wrapper.getElement().getStyle().setDisplay(Display.INLINE_BLOCK); | |
wrapper.setBorders(true); | |
wrapper.add(html); | |
Resizable resizable = new Resizable(wrapper); | |
resizable.addResizeEndHandler(new ResizeEndHandler() { | |
@Override | |
public void onResizeEnd(ResizeEndEvent event) { | |
GWT.log("resize "); | |
int w = wrapper.getOffsetWidth(); | |
int h = wrapper.getOffsetHeight(); | |
int cx = w / 2; | |
int cy = h / 2; | |
int r1 = (int) (cx * .90); | |
int r2 = (int) (cy * .90); | |
int r = Math.min(r1, r2); | |
GWT.log("cx=" + cx); | |
XElement svgElement = wrapper.getElement().select("svg").getItem(0).cast(); | |
XElement svgCirclElement = wrapper.getElement().select("circle").getItem(0).cast(); | |
svgElement.setAttribute("width", w + "px"); | |
svgElement.setAttribute("height", h + "px"); | |
svgCirclElement.setAttribute("cx", cx + ""); | |
svgCirclElement.setAttribute("cy", cy + ""); | |
svgCirclElement.setAttribute("r", r + ""); | |
} | |
}); | |
RootPanel.get().add(wrapper); | |
} | |
} |
Author
branflake2267
commented
Jun 13, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment