开发者

GWT client side cropping

开发者 https://www.devze.com 2023-04-03 20:12 出处:网络
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

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 Imag开发者_JAVA百科e();
        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);

}


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

(Updated to fix the forgotten #)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号