GWT 客户端裁剪

发布于 2024-12-04 03:06:19 字数 2534 浏览 2 评论 0原文

我一直坚持将 gwt 与 JCrop 或 imgareaselect javascript 库集成 我有一个图像,每次客户端更改从其文件系统中选择的文件(使用上传小部件)时,该 url 都会更改。 我希望用户选择其图像中的区域,这样我就能够得到具有尊重客户意愿的长宽比的图像。 问题是我无法成功在加载事件上调用 imgareaselect 或 jcrop,每次我都有 null,如果我尝试 jquery ("imagepreview") jquery 在执行时是未知的,如果我尝试一些 $("#imagepreview")我得到一个 $ 未定义...

请帮忙... 问候。

public class ThisWidget extends LayoutContainer {


public void onRender(Element parent, int index) {
    super.onRender(parent, index);
    setLayout(new VBoxLayout());
    setWidth("100%");

    final FormPanel uploadPhotoPanel = new FormPanel();
    uploadPhotoPanel.setWidth("100%");
    uploadPhotoPanel.setHeight("150px");

    Label label = new Label("Ajouter une photo");
    add(label);

    uploadPhotoPanel.setAction(GWT.getModuleBaseURL()
        + "photoload/uploadpreview.ctz");
    uploadPhotoPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
    uploadPhotoPanel.setMethod(FormPanel.METHOD_POST);


    final FileUploadField file = new FileUploadField();
    file.setName("FILE");
    uploadPhotoPanel.add(file);
    file.addHandler(new ChangeHandler() {
    @Override
    public void onChange(ChangeEvent event) {
        uploadPhotoPanel.submit();

    }
    }, ChangeEvent.getType());

    final Button btn = new Button("Ajouter",
        new SelectionListener<ButtonEvent>() {
        @Override
        public void componentSelected(ButtonEvent ce) {
            uploadPhotoPanel.submit();
        }
        });



    final Image previewimage;

        previewimage = new Image();
        DOM.setElementAttribute(previewimage.getElement(), "id",
            "previewimage");
        previewimage.setSize("200px", "200px");


    previewimage.addLoadHandler(new LoadHandler(){

        protected native void onPreviewLoad() /*-{
                document.getElementById("previewimage").imgAreaSelect({
                    aspectRatio : '1:1',
                    handles : true,
                    fadeSpeed : 200
                });

        }-*/;

        @Override
        public void onLoad(LoadEvent event) {
            onPreviewLoad();
        }});

    uploadPhotoPanel
        .addSubmitCompleteHandler(new SubmitCompleteHandler() {

        @Override
        public void onSubmitComplete(SubmitCompleteEvent event) {
            previewimage.setUrl(GWT.getModuleBaseURL()
                + "photoload/downloadpreview.ctz?tsp="
                + System.currentTimeMillis());
        }
        });

    add(uploadPhotoPanel);
    add(previewimage);
    add(btn);

}

I'm stuck on integrating gwt with JCrop or imgareaselect javascript libraries
I have an image, which url is changing each time the client change the file choosen from its filesystem (using an upload widget).
I want the user select the area in its image, this way i will be able to have images with aspect ratio respected respect to the client wishes.
Problem is i can't succed in making imgareaselect or jcrop called on load event, each time i have null, if i try jquery ("imagepreview") jquery is unknow at execution time, if i try some $("#imagepreview") i get a $ is undefined...

PLEASE any help...
Regards.

public class ThisWidget extends LayoutContainer {


public void onRender(Element parent, int index) {
    super.onRender(parent, index);
    setLayout(new VBoxLayout());
    setWidth("100%");

    final FormPanel uploadPhotoPanel = new FormPanel();
    uploadPhotoPanel.setWidth("100%");
    uploadPhotoPanel.setHeight("150px");

    Label label = new Label("Ajouter une photo");
    add(label);

    uploadPhotoPanel.setAction(GWT.getModuleBaseURL()
        + "photoload/uploadpreview.ctz");
    uploadPhotoPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
    uploadPhotoPanel.setMethod(FormPanel.METHOD_POST);


    final FileUploadField file = new FileUploadField();
    file.setName("FILE");
    uploadPhotoPanel.add(file);
    file.addHandler(new ChangeHandler() {
    @Override
    public void onChange(ChangeEvent event) {
        uploadPhotoPanel.submit();

    }
    }, ChangeEvent.getType());

    final Button btn = new Button("Ajouter",
        new SelectionListener<ButtonEvent>() {
        @Override
        public void componentSelected(ButtonEvent ce) {
            uploadPhotoPanel.submit();
        }
        });



    final Image previewimage;

        previewimage = new Image();
        DOM.setElementAttribute(previewimage.getElement(), "id",
            "previewimage");
        previewimage.setSize("200px", "200px");


    previewimage.addLoadHandler(new LoadHandler(){

        protected native void onPreviewLoad() /*-{
                document.getElementById("previewimage").imgAreaSelect({
                    aspectRatio : '1:1',
                    handles : true,
                    fadeSpeed : 200
                });

        }-*/;

        @Override
        public void onLoad(LoadEvent event) {
            onPreviewLoad();
        }});

    uploadPhotoPanel
        .addSubmitCompleteHandler(new SubmitCompleteHandler() {

        @Override
        public void onSubmitComplete(SubmitCompleteEvent event) {
            previewimage.setUrl(GWT.getModuleBaseURL()
                + "photoload/downloadpreview.ctz?tsp="
                + System.currentTimeMillis());
        }
        });

    add(uploadPhotoPanel);
    add(previewimage);
    add(btn);

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

水中月 2024-12-11 03:06:19

使用 $wnd.$("#imagepreview")$wnd.jquery("#imagepreview")

(更新以修复被遗忘的#

Use $wnd.$("#imagepreview") or $wnd.jquery("#imagepreview").

(Updated to fix the forgotten #)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文