GWT client side cropping
Asked Answered
V

1

2

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);

}

Viera answered 10/9, 2011 at 21:44 Comment(0)
P
2

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

(Updated to fix the forgotten #)

Polyclinic answered 11/9, 2011 at 8:19 Comment(3)
Thanks, but: ' Caused by: com.google.gwt.core.client.JavaScriptException: (TypeError): $wnd.jquery is not a function ' and ' Caused by: com.google.gwt.core.client.JavaScriptException: (TypeError): $wnd.$(&quot;previewimage&quot;).imgAreaSelect is not a function ' 'Viera
ok so because i had the imgAreaSelect is not a function i put the script header before the module script in the main html page, now i don't have any error, but nothings happen :-( i am sure the method is called as i did put a alert popup in that function, but nothing's happen...Viera
Ahh yes, I forgot the #. Sorry about that.Polyclinic

© 2022 - 2024 — McMap. All rights reserved.