View Javadoc

1   package org.vectomatic.svg.samples.client.dnd;
2   
3   import org.vectomatic.dom.svg.ui.SVGImage;
4   import org.vectomatic.dom.svg.ui.SVGResource;
5   import org.vectomatic.svg.samples.client.Main;
6   import org.vectomatic.svg.samples.client.Main.MainBundle;
7   import org.vectomatic.svg.samples.client.SampleBase;
8   
9   import com.google.gwt.core.client.GWT;
10  import com.google.gwt.dom.client.Style.Visibility;
11  import com.google.gwt.event.dom.client.DragEnterEvent;
12  import com.google.gwt.event.dom.client.DragLeaveEvent;
13  import com.google.gwt.event.dom.client.DragOverEvent;
14  import com.google.gwt.event.dom.client.DragStartEvent;
15  import com.google.gwt.event.dom.client.DropEvent;
16  import com.google.gwt.resources.client.ClientBundle;
17  import com.google.gwt.resources.client.CssResource;
18  import com.google.gwt.uibinder.client.UiBinder;
19  import com.google.gwt.uibinder.client.UiField;
20  import com.google.gwt.uibinder.client.UiHandler;
21  import com.google.gwt.user.client.Timer;
22  import com.google.gwt.user.client.ui.FlowPanel;
23  import com.google.gwt.user.client.ui.Image;
24  import com.google.gwt.user.client.ui.TabLayoutPanel;
25  
26  public class DndSample extends SampleBase {
27  	public interface DndCss extends CssResource {
28  		@ClassName("svg-background")
29  		public String svgBackground();
30  	}
31  	
32  	public interface DndSampleBundle extends ClientBundle {
33  		
34  		@Source("bee_forestgreen.svg")
35  		SVGResource bee();
36  		@Source("flower.svg")
37  		SVGResource flower1();
38  		@Source("HakanL_Simple_Flower.svg")
39  		SVGResource flower2();
40  		@Source("PeterM_Flower.svg")
41  		SVGResource flower3();
42  		@Source("Gerald_G_Simple_Fruit_15.svg")
43  		SVGResource fruit1();
44  		@Source("Gerald_G_Simple_Fruit_2.svg")
45  		SVGResource fruit2();
46  		@Source("Gerald_G_Simple_Fruit_5.svg")
47  		SVGResource fruit3();
48  		@Source("background.svg")
49  		SVGResource svgCheckerResource();
50  		@Source("dnd.css")
51  		DndCss css();
52  	}
53  	@UiField(provided=true)
54  	public static DndSampleBundle resources = GWT.create(DndSampleBundle.class);
55  
56  	
57  	interface DndSampleBinder extends UiBinder<TabLayoutPanel, DndSample> {
58  	}
59  	private static DndSampleBinder binder = GWT.create(DndSampleBinder.class);
60  
61  	@UiField(provided=true)
62  	public static MainBundle mainBundle = Main.mainBundle;
63  	@UiField
64  	SVGImage flower1;
65  	@UiField
66  	SVGImage flower2;
67  	@UiField
68  	SVGImage flower3;
69  	@UiField
70  	SVGImage fruit1;
71  	@UiField
72  	SVGImage fruit2;
73  	@UiField
74  	SVGImage fruit3;
75  	@UiField
76  	Image bee;
77  	@UiField
78  	FlowPanel container;
79  	
80  	@Override
81  	public TabLayoutPanel getPanel() {
82  		if (tabPanel == null) {
83  			resources.css().ensureInjected();
84  			tabPanel = binder.createAndBindUi(this);
85  			tabPanel.setTabText(0, "Drag-And-Drop");
86  			createCodeTabs("DndSample");
87  			bee.getElement().setAttribute("draggable", "true");
88  			GWT.log(resources.svgCheckerResource().getUrl());
89  		}
90  		return tabPanel;
91  	}
92  	
93  	@UiHandler("flower1")
94  	public void flower1Enter(DragEnterEvent event) {
95  		flower1.getStyle().setOpacity(0.5f);
96  		event.preventDefault();
97  	}
98  	@UiHandler("flower1")
99  	public void flower1Leave(DragLeaveEvent event) {
100 		flower1.getStyle().setOpacity(1f);
101 	}
102 	@UiHandler("flower1")
103 	public void flower1Over(DragOverEvent event) {
104 		flower1.getStyle().setOpacity(0.5f);
105 		event.preventDefault();
106 	}
107 	@UiHandler("flower1")
108 	public void flower1Drop(DropEvent event) {
109 		flower1.getStyle().setVisibility(Visibility.HIDDEN);
110 		flower1.getStyle().setOpacity(1f);
111 		fruit1.getStyle().setVisibility(Visibility.VISIBLE);
112 		Timer t = new Timer() {
113 			@Override
114 			public void run() {
115 				flower1.getStyle().setVisibility(Visibility.VISIBLE);
116 				fruit1.getStyle().setVisibility(Visibility.HIDDEN);
117 			}
118 		};
119 		t.schedule(3000);
120 	}
121 
122 	@UiHandler("flower2")
123 	public void flower2Enter(DragEnterEvent event) {
124 		flower2.getStyle().setOpacity(0.5f);
125 		event.preventDefault();
126 	}
127 	@UiHandler("flower2")
128 	public void flower2Leave(DragLeaveEvent event) {
129 		flower2.getStyle().setOpacity(1f);
130 	}
131 	@UiHandler("flower2")
132 	public void flower2Over(DragOverEvent event) {
133 		event.preventDefault();
134 	}
135 	@UiHandler("flower2")
136 	public void flower2Drop(DropEvent event) {
137 		flower2.getStyle().setVisibility(Visibility.HIDDEN);
138 		flower2.getStyle().setOpacity(1f);
139 		fruit2.getStyle().setVisibility(Visibility.VISIBLE);
140 		Timer t = new Timer() {
141 			@Override
142 			public void run() {
143 				flower2.getStyle().setVisibility(Visibility.VISIBLE);
144 				fruit2.getStyle().setVisibility(Visibility.HIDDEN);
145 			}
146 		};
147 		t.schedule(3000);
148 	}
149 
150 	@UiHandler("flower3")
151 	public void flower3Enter(DragEnterEvent event) {
152 		flower3.getStyle().setOpacity(0.5f);
153 		event.preventDefault();
154 	}
155 	@UiHandler("flower3")
156 	public void flower3Leave(DragLeaveEvent event) {
157 		flower3.getStyle().setOpacity(1f);
158 	}
159 	@UiHandler("flower3")
160 	public void flower3Over(DragOverEvent event) {
161 		event.preventDefault();
162 	}
163 	@UiHandler("flower3")
164 	public void flower3Drop(DropEvent event) {
165 		flower3.getStyle().setVisibility(Visibility.HIDDEN);
166 		flower3.getStyle().setOpacity(1f);
167 		fruit3.getStyle().setVisibility(Visibility.VISIBLE);
168 		Timer t = new Timer() {
169 			@Override
170 			public void run() {
171 				flower3.getStyle().setVisibility(Visibility.VISIBLE);
172 				fruit3.getStyle().setVisibility(Visibility.HIDDEN);
173 			}
174 		};
175 		t.schedule(3000);
176 	}
177 
178 	@UiHandler("bee")
179 	public void beeDragStart(DragStartEvent event) {
180 		event.getDataTransfer().setData("text/plain", "bzzz");
181 	}
182 }