ImageVerifierCode 换一换
格式:DOCX , 页数:16 ,大小:32.57KB ,
资源ID:5901850      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/5901850.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Implement Drag and Drop in Your Web Apps.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Implement Drag and Drop in Your Web Apps.docx

1、Implement Drag and Drop in Your Web AppsImplement Drag and Drop in Your Web AppsBy David Geary and Rob GordonThe ultimate in user interactivity, drag and drop is taken for granted in desktop applications but is a litmus test of sorts for web applications: If you can easily implement drag and drop wi

2、th your web application framework, then you know youve got something special.Until now, drag and drop for web applications has, for the most part, been limited to specialized JavaScript frameworks such as Script.aculo.us and Rico. No more. With the advent of GWT, we have drag-and-drop capabilities i

3、n a Java-based web application framework. Although Google Web Toolkit (GWT) does not explicitly support drag and drop (drag and drop is an anticipated feature in the future), it provides us with all the necessary ingredients to make our own drag-and-drop module.In this solution, we explore drag-and-

4、drop implementation with GWT. We implement drag and drop in a module of its own so that you can easily incorporate drag and drop into your applications.Stuff Youre Going to LearnThis solution explores the following aspects of GWT: Implementing composite widgets with the Composite class Removing widg

5、ets from panels Changing cursors for widgets with CSS styles Implementing a GWT module Adding multiple listeners to a widget Using the AbsolutePanel class to place widgets by pixel location Capturing and releasing events for a specific widget Using an event preview to inhibit browser reactions to ev

6、ents See Solution 1 and Solution 2 for more in-depth discussions of implementing GWT modules and implementing composite widgets, respectively.The Drag-and-Drop Example ApplicationOur discussion of drag and drop (dnd) starts with a sample application that uses our drag-and-drop module. Then we peel b

7、ack the layers of the drag-and-drop onion to reveal the underlying implementation.Figure 6.1 shows the drag-and-drop example application in action. The application contains iPods and Zunes that can be dragged into their respective shopping carts. When you start dragging a music player, the cursor ch

8、anges to the pointer cursor to indicate that a drag is underway, just in case the actual movement of the music player is not enough evidence of that fact.If a user drags a music player, which in dnd parlance is known as a drag source, over its shopping cart (referred to as a drop target), two things

9、 happen: We once again change the cursor, this time to a move cursor, to indicate that a drop is acceptable for this drop target (known as a drag-over effect), and we change the border of the drop target (known as a drag-under effect). If the user subsequently releases the mouse while the drag sourc

10、e is over the drop target, we remove the drag source from the page and update the drop target to reflect the fact that it now contains the music player that was dropped.If the user starts dragging a music player and then decides against dropping it on its shopping cart panel, we scoot the music play

11、er back to its original position, as illustrated in Figure 6.2. This is standard drag-and-drop behavior.Finally, notice that we have two drop targets: one for iPods and another for Zunes. Users cannot drag an iPod into the Zune shopping cart, or vice versa. If they try to do so, the cursor changes t

12、o the no-drop cursor when the music player enters the forbidden shopping cart, as shown in Figure 6.3. When a user drops a music player over a forbidden shopping cart, the music player moves back to its original position, just as it does when dropped outside any drop target.Our drag-and-drop applica

13、tion uses a drag-and-drop module. We discuss that module in detail in Drag and Drop Implementation in a GWT Module, but for now lets see whats involved in using that module.The Drag-and-Drop ModuleThe drag-and-drop application and its associated files and directories are shown in Figure 6.4.The appl

14、ication is made up primarily of five things: Java source files; images; a CSS file; a configuration file; and an HTML page. In Solution 1, we showed you how to use custom widgets that were packaged in a module. For the drag-and-drop application, we employ the same techniquea two-step processto use t

15、he drag-and-drop module: Inherit the module with an inherits element in the configuration file. Include the modules JAR file in our applications classpath. We showed you how to include GWT Solutions Components module in your applications classpath in Custom Widget Use (page 40), so we dont cover tha

16、t ground again, but we do show you how we inherit the drag-and-drop module in the applications configuration file.Inheriting the Drag-and-Drop Module in an Applications Configuration FileThe XML configuration file for our application is shown in Listing 6.1.Listing 6.1 com/gwtsolutions/DragAndDrop.g

17、wt.xml1234 567 8910 11 121314 151617 1819The drag-and-drop application uses GWT internationalization, so we inherit GWTs I18N module in addition to the User module.The drag-and-drop module resides in the GWT Solutions Components module, so we inherit both of those modules in our applications configu

18、ration file.The configuration file also includes its CSS stylesheet in the configuration file. We could have included the stylesheet with a standard link element in the applications HTML page, but including stylesheets in GWT configuration files is a more reusable solution because users can reuse yo

19、ur stylesheet along with your module. No ones ever going to reuse our applications module, but just the same, we prefer including stylesheets in configuration files to HTML pages in general.Finally, we specify the entry point class for our application, com.gwtsolutions.client. DragAndDrop.Now that w

20、eve seen how the drag-and-drop application uses the drag-and-drop module, lets look at the code for the application. We revisit the drag-and-drop module in Drag and Drop Implementation in a GWT Module on page 182, where we look at the modules implementation.Implementation of the Drag-and-Drop Applic

21、ationListing 6.2 shows the drag-and-drop applications class.Listing 6.2 com.gwtsolutions.client.DragAndDrop20packagecom.gwtsolutions.client; 2122importcom.google.gwt.core.client.EntryPoint; 23importcom.google.gwt.core.client.GWT; 24importcom.google.gwt.user.client.ui.AbsolutePanel; 25importcom.googl

22、e.gwt.user.client.ui.RootPanel; 2627publicclassDragAndDropimplementsEntryPoint 28publicvoidonModuleLoad() 29DragAndDropConstantsconstants= 30(DragAndDropConstants)GWT 31.create(DragAndDropConstants.class); 3233finalAbsolutePanelap=newAbsolutePanel(); 3435ap.add(newIpodDropTarget(newShoppingCartPanel

23、(constants 36.iPodsOnly(),125,10); 3738ap.add(newZuneDropTarget(newShoppingCartPanel(constants 39.zunesOnly(),125,260); 4041finalMusicPlayerblackIpod= 42newMusicPlayer(images/ipod-nano-black.jpg, 43constants.blackIPodInfo(); 4445finalMusicPlayerblackZune= 46newMusicPlayer(images/zune-black.jpg,const

24、ants 47.blackZuneInfo(); 4849finalMusicPlayersilverIpod= 50newMusicPlayer(images/ipod-nano-silver.jpg, 51constants.silverIPodInfo(); 5253finalMusicPlayerbrownZune= 54newMusicPlayer(images/zune-brown.jpg,constants 55.brownZuneInfo(); 5657ap.add(newMusicPlayerDragSource(blackIpod),10,20); 58ap.add(new

25、MusicPlayerDragSource(brownZune),10,120); 59ap.add(newMusicPlayerDragSource(silverIpod),10,200); 60ap.add(newMusicPlayerDragSource(blackZune),10,300); 6162ap.addStyleName(dragPanel); 63RootPanel.get().add(ap); 64 65 view plain | print | copy to clipboard | ?The preceding code is straightforward. We

26、create an absolute panel, to which we add two shopping cart panels, each wrapped in a drop target. Then we create four music players and add each of them, wrapped in music player drag sources, to the absolute panel. After that flurry of activity, we have an absolute panel with four drag sources and

27、two drop targets. Finally, we attach a CSS style to the absolute panel and add it to the root panel of the page.The MusicPlayer and ShoppingCartPanel classes are GWT composite widgets. Lets look at their implementations before we dive into the dnd module.Using the Music Player and Shopping Cart Pane

28、l ComponentsThe MusicPlayer class is listed in Listing 6.3.Listing 6.3 com.gwtsolutions.client.MusicPlayer1packagecom.gwtsolutions.client; 23importcom.google.gwt.user.client.ui.Composite; 4importcom.google.gwt.user.client.ui.Image; 56publicclassMusicPlayerextendsComposite 7privateImageimage; 8privat

29、eStringinfo; 910publicMusicPlayer(StringimageUrl,Stringinfo) 11image=newImage(imageUrl); 12this.info=info; 13initWidget(image); 14 1516publicStringgetInfo() 17returninfo; 18 19 view plain | print | copy to clipboard | ?This is about as simple as a composite widget gets. The music player composite contains an image and some information about the pla

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1