1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.vectomatic.svg.samples.client;
19
20 import org.vectomatic.dom.svg.utils.DOMHelper;
21 import org.vectomatic.dom.svg.utils.SVGConstants;
22 import org.vectomatic.svg.samples.client.dnd.DndSample;
23 import org.vectomatic.svg.samples.client.events.EventSample;
24 import org.vectomatic.svg.samples.client.features.FeaturesSample;
25 import org.vectomatic.svg.samples.client.parser.ParserSample;
26 import org.vectomatic.svg.samples.client.shapes.ShapesSample;
27 import org.vectomatic.svg.samples.client.smil.SmilSample;
28 import org.vectomatic.svg.samples.client.widgets.WidgetsSample;
29 import org.vectomatic.svg.samples.client.xpath.XPathSample;
30
31 import com.google.gwt.core.client.EntryPoint;
32 import com.google.gwt.core.client.GWT;
33 import com.google.gwt.event.logical.shared.SelectionEvent;
34 import com.google.gwt.event.logical.shared.SelectionHandler;
35 import com.google.gwt.resources.client.ClientBundle;
36 import com.google.gwt.resources.client.CssResource;
37 import com.google.gwt.resources.client.ImageResource;
38 import com.google.gwt.safehtml.shared.SafeHtmlUtils;
39 import com.google.gwt.uibinder.client.UiBinder;
40 import com.google.gwt.uibinder.client.UiField;
41 import com.google.gwt.user.client.DOM;
42 import com.google.gwt.user.client.ui.AbstractImagePrototype;
43 import com.google.gwt.user.client.ui.DialogBox;
44 import com.google.gwt.user.client.ui.LayoutPanel;
45 import com.google.gwt.user.client.ui.RootLayoutPanel;
46 import com.google.gwt.user.client.ui.SplitLayoutPanel;
47 import com.google.gwt.user.client.ui.Tree;
48 import com.google.gwt.user.client.ui.TreeItem;
49 import com.google.gwt.user.client.ui.Widget;
50
51
52
53
54
55
56 public class Main implements EntryPoint {
57
58
59
60 interface MainBinder extends UiBinder<SplitLayoutPanel, Main> {
61 }
62 private static MainBinder binder = GWT.create(MainBinder.class);
63
64
65
66
67
68 private static final class GeneratorInfo {
69 }
70
71
72
73
74 public interface MainBundle extends ClientBundle {
75 @Source("orgball.gif")
76 public ImageResource treeItem();
77 @Source("main.css")
78 public MainCss css();
79 }
80
81
82
83
84 public interface MainCss extends CssResource {
85
86
87
88 public String tab();
89
90
91
92 public String sample();
93 }
94
95
96
97
98 public static MainBundle mainBundle = GWT.create(MainBundle.class);
99
100
101
102
103 @UiField
104 Tree tree;
105
106
107
108 @UiField
109 SplitLayoutPanel splitPanel;
110
111
112
113
114 @UiField
115 LayoutPanel sampleContainer;
116
117
118 @Override
119 public void onModuleLoad() {
120 GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() {
121 public void onUncaughtException(Throwable throwable) {
122 String text = "Uncaught exception: ";
123 while (throwable != null) {
124 StackTraceElement[] stackTraceElements = throwable
125 .getStackTrace();
126 text += throwable.toString() + "\n";
127 for (int i = 0; i < stackTraceElements.length; i++) {
128 text += " at " + stackTraceElements[i] + "\n";
129 }
130 throwable = throwable.getCause();
131 if (throwable != null) {
132 text += "Caused by: ";
133 }
134 }
135 DialogBox dialogBox = new DialogBox(true);
136 DOM.setStyleAttribute(dialogBox.getElement(), "backgroundColor", "#ABCDEF");
137 System.err.print(text);
138 text = text.replaceAll(" ", " ");
139 dialogBox.setHTML("<pre>" + text + "</pre>");
140 dialogBox.center();
141 }
142 });
143 mainBundle.css().ensureInjected();
144
145
146 GWT.create(GeneratorInfo.class);
147 SplitLayoutPanel panel = binder.createAndBindUi(this);
148
149
150 TreeItem shapesSample = tree.addItem(SafeHtmlUtils.fromTrustedString(AbstractImagePrototype.create(mainBundle.treeItem()).getHTML() + " shapes"));
151 shapesSample.setUserObject(new ShapesSample());
152 TreeItem eventSample = tree.addItem(SafeHtmlUtils.fromTrustedString(AbstractImagePrototype.create(mainBundle.treeItem()).getHTML() + " events"));
153 eventSample.setUserObject(new EventSample());
154 TreeItem parserSample = tree.addItem(SafeHtmlUtils.fromTrustedString(AbstractImagePrototype.create(mainBundle.treeItem()).getHTML() + " parser"));
155 parserSample.setUserObject(new ParserSample());
156 TreeItem featuresSample = tree.addItem(SafeHtmlUtils.fromTrustedString(AbstractImagePrototype.create(mainBundle.treeItem()).getHTML() + " features"));
157 featuresSample.setUserObject(new FeaturesSample());
158 TreeItem widgetsSample = tree.addItem(SafeHtmlUtils.fromTrustedString(AbstractImagePrototype.create(mainBundle.treeItem()).getHTML() + " widgets"));
159 widgetsSample.setUserObject(new WidgetsSample());
160 TreeItem smilSample = tree.addItem(SafeHtmlUtils.fromTrustedString(AbstractImagePrototype.create(mainBundle.treeItem()).getHTML() + " SMIL animation"));
161 smilSample.setUserObject(new SmilSample());
162 TreeItem xpathSample = tree.addItem(SafeHtmlUtils.fromTrustedString(AbstractImagePrototype.create(mainBundle.treeItem()).getHTML() + " XPath"));
163 xpathSample.setUserObject(new XPathSample());
164 if (DOMHelper.hasFeature(SVGConstants.SVG_FEATURE_DND_EVENTS)) {
165 TreeItem dndSample = tree.addItem(SafeHtmlUtils.fromTrustedString(AbstractImagePrototype.create(mainBundle.treeItem()).getHTML() + " Drag-and-Drop"));
166 dndSample.setUserObject(new DndSample());
167 }
168 TreeItem about = tree.addItem(SafeHtmlUtils.fromTrustedString(AbstractImagePrototype.create(mainBundle.treeItem()).getHTML() + " about"));
169 about.setUserObject(new AboutSample());
170 tree.addSelectionHandler(new SelectionHandler<TreeItem>() {
171 @Override
172 public void onSelection(SelectionEvent<TreeItem> event) {
173 SampleBase currentSample = (SampleBase) event.getSelectedItem().getUserObject();
174 selectSample(currentSample.getPanel());
175 }
176
177 });
178 tree.setSelectedItem(shapesSample);
179
180 RootLayoutPanel.get().add(panel);
181 }
182
183
184
185
186
187
188 private void selectSample(Widget samplePanel) {
189 int count = sampleContainer.getWidgetCount();
190 int index = -1;
191 for (int i = 0; i < count; i++) {
192 Widget w = sampleContainer.getWidget(i);
193 if (w != samplePanel) {
194 sampleContainer.setWidgetVisible(w, false);
195 } else {
196 sampleContainer.setWidgetVisible(w, true);
197 index = i;
198 }
199 }
200 if (index == -1) {
201 sampleContainer.add(samplePanel);
202 sampleContainer.setWidgetVisible(samplePanel, true);
203 }
204 }
205 }