Google Web Toolkit (GWT) MVP Example (3)

GreetingResponsePresenter.java

view source
<object id="highlighter_476763_clipboard" title="copy to clipboard" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="16" height="16" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" type="application/x-shockwave-flash"> </object>
print ?
01. package co.uk.hivedevelopment.greet.client.mvp;
02. import net.customware.gwt.presenter.client.EventBus;
03. import net.customware.gwt.presenter.client.place.Place;
04. import net.customware.gwt.presenter.client.place.PlaceRequest;
05. import net.customware.gwt.presenter.client.widget.WidgetDisplay;
06. import net.customware.gwt.presenter.client.widget.WidgetPresenter;
07. import co.uk.hivedevelopment.greet.shared.event.GreetingSentEvent;
08. import co.uk.hivedevelopment.greet.shared.event.GreetingSentEventHandler;
09. import com.allen_sauer.gwt.log.client.Log;
10. import com.google.gwt.event.dom.client.ClickEvent;
11. import com.google.gwt.event.dom.client.ClickHandler;
12. import com.google.gwt.event.dom.client.HasClickHandlers;
13. import com.google.gwt.user.client.ui.DialogBox;
14. import com.google.gwt.user.client.ui.HasHTML;
15. import com.google.gwt.user.client.ui.HasText;
16. import com.google.inject.Inject;
17. public class GreetingResponsePresenter extends WidgetPresenter {
18.  public interface Display extends WidgetDisplay {
19.   HasText getTextToServer();
20.   HasHTML getServerResponse();
21.   HasClickHandlers getClose();
22.   DialogBox getDialogBox();
23.  }
24.  public static final Place PLACE = new Place("GreetingResponse");
25.  @Inject
26.  public GreetingResponsePresenter(final Display display, final EventBus eventBus) {
27.   super(display, eventBus);
28.   bind();
29.  }
30.   
31.  @Override
32.  protected void onBind() {
33.   // Add a handler to close the DialogBox
34.   display.getClose().addClickHandler(new ClickHandler() {
35.    public void onClick(final ClickEvent event) {
36.     display.getDialogBox().hide();
37.     // Not sure of a nice place to put these!
38. //    sendButton.setEnabled(true);
39. //    sendButton.setFocus(true);
40.    }
41.   });
42.   eventBus.addHandler(GreetingSentEvent.TYPE, new GreetingSentEventHandler() {
43.    @Override
44.    public void onGreetingSent(final GreetingSentEvent event) {
45.     Log.info("Handling GreetingSent event");
46.      
47.     display.getTextToServer().setText(event.getName());
48.     display.getServerResponse().setHTML(event.getMessage());
49.     display.getDialogBox().show();
50.    }
51.   });
52.  }
53.  @Override
54.  protected void onUnbind() {
55.   // Add unbind functionality here for more complex presenters.
56.  }
57.  public void refreshDisplay() {
58.   // This is called when the presenter should pull the latest data
59.   // from the server, etc. In this case, there is nothing to do.
60.  }
61.  public void revealDisplay() {
62.   // Nothing to do. This is more useful in UI which may be buried
63.   // in a tab bar, tree, etc.
64.  }
65.  /**
66.   * Returning a place will allow this presenter to automatically trigger when
67.   * '#GreetingResponse' is passed into the browser URL.
68.   */
69.  @Override
70.  public Place getPlace() {
71.   return PLACE;
72.  }
73.  @Override
74.  protected void onPlaceRequest(final PlaceRequest request) {
75.   // this is a popup
76.  }
77. }

At this point, we're still missing some code but hopefully you should start to see the structure coming together.

Events

Since this is a simple application, we only have one event - the GreetingSent event which has a corresponding handler:

GreetingSent.java

view source
<object id="highlighter_883694_clipboard" title="copy to clipboard" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="16" height="16" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" type="application/x-shockwave-flash"> </object>
print ?
01. package co.uk.hivedevelopment.greet.shared.event;
02. import com.google.gwt.event.shared.GwtEvent;
03. public class GreetingSentEvent extends GwtEvent{
04.  public static Type TYPE = new Type();
05.   
06.  private final String name;
07.  private final String message;
08.   
09.  public GreetingSentEvent(final String name, final String message) {
10.   this.name = name;
11.   this.message = message;
12.  }
13.   
14.  public String getName() {
15.   return name;
16.  }
17.   
18.  public String getMessage() {
19.   return message;
20.  }
21.   
22.  @Override
23.  public Type getAssociatedType() {
24.   return TYPE;
25.  }
26.  @Override
27.  protected void dispatch(final GreetingSentEventHandler handler) {
28.   handler.onGreetingSent(this);
29.  }
30. }

GreetingSentHandler.java

view source
<object id="highlighter_65598_clipboard" title="copy to clipboard" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="16" height="16" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" type="application/x-shockwave-flash"> </object>
print ?
1. package co.uk.hivedevelopment.greet.shared.event;
2. import com.google.gwt.event.shared.EventHandler;
3. public interface GreetingSentEventHandler extends EventHandler {
4.  void onGreetingSent(GreetingSentEvent event);
5. }

If you now look at the project references for the event and handler you can see where the events are fired and subsequently handled. The components are blissfully unaware of what produced the event and it just has the information that it needs to get the job done. Now imagine if you want to have another component that also reacts to this event, say to update another part of the GUI. Simple, just register another event handler - no spaghetti code.

RPC

Let's define client RPC. As mentioned earlier, we'll not be making the RPC calls directly. Instead we'll use the command pattern and let the gwt-dispatch library handle the underlying server calls. Although this is an implementation of the command pattern, it turns out that there is already a core GWT class called Command, so the authors of the gwt-dispatch library have opted to use Action instead - so "actions" are really "commands".

In our example, we'll define the Action SendGreeting which represent our server request and a SendGreetingResult class to encapsulate the server response:

SendGreeting.java

view source
<object id="highlighter_760712_clipboard" title="copy to clipboard" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="16" height="16" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" type="application/x-shockwave-flash"> </object>
print ?
01. package co.uk.hivedevelopment.greet.shared.rpc;
02. import net.customware.gwt.dispatch.shared.Action;
03. public class SendGreeting implements Action {
04.  private static final long serialVersionUID = 5804421607858017477L;
05.  private String name;
06.  @SuppressWarnings("unused")
07.  private SendGreeting() {
08.  }
09.  public SendGreeting(final String name) {
10.   this.name = name;
11.  }
12.  public String getName() {
13.   return name;
14.  }
15. }

SendGreetingResult.java

view source
<object id="highlighter_9512_clipboard" title="copy to clipboard" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="16" height="16" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" type="application/x-shockwave-flash"> </object>
print ?
01. package co.uk.hivedevelopment.greet.shared.rpc;
02. import net.customware.gwt.dispatch.shared.Result;
03. public class SendGreetingResult implements Result {
04.  private static final long serialVersionUID = 7917449246674223581L;
05.  private String name;
06.  private String message;
07.  public SendGreetingResult(final String name, final String message) {
08.   this.name = name;
09.   this.message = message;
10.  }
11.  @SuppressWarnings("unused")
12.  private SendGreetingResult() {
13.  }
14.  public String getName() {
15.   return name;
16.  }
17.  public String getMessage() {
18.   return message;
19.  }
20. }
【评估多目标跟踪方法】9个高度敏捷目标在编队中的轨迹和测量研究(Matlab代码实现)内容概要:本文围绕“评估多目标跟踪方法”,重点研究9个高度敏捷目标在编队飞行中的轨迹生成与测量过程,并提供完整的Matlab代码实现。文中详细模拟了目标的动态行为、运动约束及编队结构,通过仿真获取目标的状态信息与观测数据,用于验证和比较不同多目标跟踪算法的性能。研究内容涵盖轨迹建模、噪声处理、传感器测量模拟以及数据可视化等关键技术环节,旨在为雷达、无人机编队、自动驾驶等领域的多目标跟踪系统提供可复现的测试基准。; 适合人群:具备一定Matlab编程基础,从事控制工程、自动化、航空航天、智能交通或人工智能等相关领域的研究生、科研人员及工程技术人员。; 使用场景及目标:①用于多目标跟踪算法(如卡尔曼滤波、粒子滤波、GM-CPHD等)的性能评估与对比实验;②作为无人机编队、空中交通监控等应用场景下的轨迹仿真与传感器数据分析的教学与研究平台;③支持对高度机动目标在复杂编队下的可观测性与跟踪精度进行深入分析。; 阅读建议:建议读者结合提供的Matlab代码进行实践操作,重点关注轨迹生成逻辑与测量模型构建部分,可通过修改目标数量、运动参数或噪声水平来拓展实验场景,进一步提升对多目标跟踪系统设计与评估的理解。
本软件实现了一种基于时域有限差分法结合时间反转算法的微波成像技术,旨在应用于乳腺癌的早期筛查。其核心流程分为三个主要步骤:数据采集、信号处理与三维可视化。 首先,用户需分别执行“WithTumor.m”与“WithoutTumor.m”两个脚本。这两个程序将在模拟生成的三维生物组织环境中进行电磁仿真,分别采集包含肿瘤模型与不包含肿瘤模型的场景下的原始场数据。所获取的数据将自动存储为“withtumor.mat”与“withouttumor.mat”两个数据文件。 随后,运行主算法脚本“TR.m”。该程序将加载上述两组数据,并实施时间反转算法。算法的具体过程是:提取两组仿真信号之间的差异成分,通过一组专门设计的数字滤波器对差异信号进行增强与净化处理,随后在数值模拟的同一组织环境中进行时间反向的电磁波传播计算。 在算法迭代计算过程中,系统会按预设的周期(每n次迭代)自动生成并显示三维模拟空间内特定二维切面的电场强度分布图。通过对比观察这些动态更新的二维场分布图像,用户有望直观地识别出由肿瘤组织引起的异常电磁散射特征,从而实现病灶的视觉定位。 关于软件的具体配置要求、参数设置方法以及更深入的技术细节,请参阅软件包内附的说明文档。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值