Example usage for com.google.gwt.user.client.ui Label addMouseDownHandler

List of usage examples for com.google.gwt.user.client.ui Label addMouseDownHandler

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui Label addMouseDownHandler.

Prototype

public HandlerRegistration addMouseDownHandler(MouseDownHandler handler) 

Source Link

Usage

From source file:asquare.gwt.tests.circularbinding.client.Demo.java

License:Apache License

private Widget createDemoPanel() {
    VerticalPanel outer = new VerticalPanel();

    final TextArea output = new TextArea();
    outer.add(output);//  w w w .j ava2 s .c  om

    Label label = new Label("Click me");
    label.addMouseDownHandler(new MouseDownHandler() {
        public void onMouseDown(MouseDownEvent event) {
            // this works
            output.setText("x=" + DOM2.eventGetClientX());

            // this results in an infinite loop
            output.setText(output.getText() + "\r\ny=" + DOM2.eventGetClientY());
        }
    });
    DOM.setStyleAttribute(label.getElement(), "border", "solid black 1px");
    outer.insert(label, 0);

    return outer;
}

From source file:com.ait.toolkit.clientio.uploader.client.Uploader.java

License:Apache License

@Override
protected void onLoad() {

    // Make sure our entire panel fits the size that they wanted for the button
    if (this.buttonWidth >= 0) {
        this.setWidth(this.buttonWidth + "px");
    }//from w ww  .  j  av a2s.  c o  m
    if (this.buttonHeight >= 0) {
        this.setHeight(this.buttonHeight + "px");
    }

    if (ajaxUploadEnabled && isAjaxUploadWithProgressEventsSupported()) {

        // If the browser supports the XMLHttpRequest Level 2 type then we can avoid rendering the flash component
        // and just stick with a DOM/Ajax approach.

        // Use a hidden file input component to handle allowing the user to popup the file system dialog
        // (but keep it outside of the button itself so it doesn't interfere with the mouse events)
        this.add(createFileUpload());

        // Create the main element that will hold all of the inner workings of the uploader component
        Label button = new Label();
        button.setWidth("100%");
        button.setHeight("100%");
        if (this.buttonCursor != null) {
            switch (this.buttonCursor) {
            case ARROW:
                button.getElement().getStyle().setCursor(Style.Cursor.DEFAULT);
                break;
            case HAND:
                button.getElement().getStyle().setCursor(Style.Cursor.POINTER);
                break;
            }
        }

        // Setup what we want to happen when someone clicks anywhere on the button
        button.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                if (buttonDisabled) {
                    return;
                }
                switch (buttonAction) {
                case START_UPLOAD:
                    startUpload();
                    break;
                case SELECT_FILES:
                    openFileDialog(fileUpload, true);
                    break;
                case SELECT_FILE:
                default:
                    openFileDialog(fileUpload, false);
                    break;
                }
            }
        });

        button.addMouseOverHandler(new MouseOverHandler() {
            public void onMouseOver(MouseOverEvent event) {
                if (buttonImageURL != null && buttonHeight >= 0 && !buttonDisabled) {
                    buttonImageElement.getStyle().setProperty("backgroundPosition",
                            "0px -" + buttonHeight + "px");
                }
            }
        });
        button.addMouseOutHandler(new MouseOutHandler() {
            public void onMouseOut(MouseOutEvent event) {
                if (buttonImageURL != null && buttonHeight >= 0 && !buttonDisabled) {
                    buttonImageElement.getStyle().setProperty("backgroundPosition", "0px 0px");
                }
            }
        });
        button.addMouseDownHandler(new MouseDownHandler() {
            public void onMouseDown(MouseDownEvent event) {
                if (buttonImageURL != null && buttonHeight >= 0 && !buttonDisabled) {
                    buttonImageElement.getStyle().setProperty("backgroundPosition",
                            "0px -" + (buttonHeight * 2) + "px");
                }
            }
        });
        button.addMouseUpHandler(new MouseUpHandler() {
            public void onMouseUp(MouseUpEvent event) {
                if (buttonImageURL != null && buttonHeight >= 0 && !buttonDisabled) {
                    buttonImageElement.getStyle().setProperty("backgroundPosition", "0px 0px");
                }
            }
        });

        // Depending on the way they wanted the uploader button rendered, create the appropriate elements
        // in the DOM that the user will click on.
        if (this.buttonTextStyle != null) {
            buttonTextStyleElement = Document.get().createStyleElement();
            buttonTextStyleElement.setInnerText(this.buttonTextStyle);
            button.getElement().appendChild(buttonTextStyleElement);
        }
        if (this.buttonText != null) {
            buttonTextElement = Document.get().createDivElement();
            buttonTextElement.setInnerHTML(this.buttonText);
            buttonTextElement.getStyle().setWidth(100, Style.Unit.PCT);
            buttonTextElement.getStyle().setHeight(100, Style.Unit.PCT);
            if (this.buttonTextLeftPadding > Integer.MIN_VALUE) {
                buttonTextElement.getStyle().setPaddingLeft(this.buttonTextLeftPadding, Style.Unit.PX);
            }
            if (this.buttonTextTopPadding > Integer.MIN_VALUE) {
                buttonTextElement.getStyle().setPaddingTop(this.buttonTextTopPadding, Style.Unit.PX);
            }
            button.getElement().appendChild(buttonTextElement);
        }

        if (this.buttonImageURL != null) {
            buttonImageElement = Document.get().createDivElement();
            buttonImageElement.getStyle().setBackgroundImage("url(\"" + this.buttonImageURL + "\")");
            if (this.buttonDisabled) {
                buttonImageElement.getStyle().setProperty("backgroundPosition",
                        "0px -" + (buttonHeight * 3) + "px");
            } else {
                buttonImageElement.getStyle().setProperty("backgroundPosition", "0px 0px");
            }
            buttonImageElement.getStyle().setWidth(100, Style.Unit.PCT);
            buttonImageElement.getStyle().setHeight(100, Style.Unit.PCT);
            button.getElement().appendChild(buttonImageElement);
        }

        // Add the entire button to the DOM
        this.add(button);

    } else {

        // If the browser doesn't support the XMLHttpRequest Level 2 type, then our only option is to use
        // the Flash/SWFUpload component.

        // The SWFUpload JS code completely replaces the DOM element that you give it as a target,
        // so we're creating an inner component that it can replace - leaving the outer component
        // for the caller to use as the GWT Widget that they can manage and style within the appropriate
        // container within their GWT application
        DivElement swfUploadElement = Document.get().createDivElement();
        swfUploadElement.setId(Document.get().createUniqueId());
        this.getElement().appendChild(swfUploadElement);

        JavaScriptObject nativeOptions = createNativeOptions(swfUploadElement.getId());

        // Build a map that we'll use during the native creation process to setup
        // the necessary JSNI bridges to our Java event handlers...
        JSONObject eventHandlers = new JSONObject();
        eventHandlers.put("swfupload_loaded_handler", JSONBoolean.getInstance(swfUploadLoadedHandler != null));
        eventHandlers.put("file_dialog_start_handler", JSONBoolean.getInstance(fileDialogStartHandler != null));
        eventHandlers.put("file_queued_handler", JSONBoolean.getInstance(fileQueuedHandler != null));
        eventHandlers.put("file_queue_error_handler", JSONBoolean.getInstance(fileQueueErrorHandler != null));
        eventHandlers.put("file_dialog_complete_handler",
                JSONBoolean.getInstance(fileDialogCompleteHandler != null));
        eventHandlers.put("upload_start_handler", JSONBoolean.getInstance(uploadStartHandler != null));
        eventHandlers.put("upload_progress_handler", JSONBoolean.getInstance(uploadProgressHandler != null));
        eventHandlers.put("upload_error_handler", JSONBoolean.getInstance(uploadErrorHandler != null));
        eventHandlers.put("upload_success_handler", JSONBoolean.getInstance(uploadSuccessHandler != null));
        eventHandlers.put("upload_complete_handler", JSONBoolean.getInstance(uploadCompleteHandler != null));

        swfUpload = nativeCreateSWFUpload(nativeOptions, eventHandlers.getJavaScriptObject());
    }
}

From source file:com.google.appinventor.client.explorer.youngandroid.ProjectList.java

License:Open Source License

/**
 * Adds the header row to the table./*w  w w  .  ja  va 2  s  . c o  m*/
 *
 */
private void setHeaderRow() {
    table.getRowFormatter().setStyleName(0, "ode-ProjectHeaderRow");

    HorizontalPanel nameHeader = new HorizontalPanel();
    final Label nameHeaderLabel = new Label(MESSAGES.projectNameHeader());
    nameHeaderLabel.addStyleName("ode-ProjectHeaderLabel");
    nameHeader.add(nameHeaderLabel);
    nameSortIndicator.addStyleName("ode-ProjectHeaderLabel");
    nameHeader.add(nameSortIndicator);
    table.setWidget(0, 1, nameHeader);

    HorizontalPanel dateCreatedHeader = new HorizontalPanel();
    final Label dateCreatedHeaderLabel = new Label(MESSAGES.projectDateCreatedHeader());
    dateCreatedHeaderLabel.addStyleName("ode-ProjectHeaderLabel");
    dateCreatedHeader.add(dateCreatedHeaderLabel);
    dateCreatedSortIndicator.addStyleName("ode-ProjectHeaderLabel");
    dateCreatedHeader.add(dateCreatedSortIndicator);
    table.setWidget(0, 2, dateCreatedHeader);

    HorizontalPanel dateModifiedHeader = new HorizontalPanel();
    final Label dateModifiedHeaderLabel = new Label(MESSAGES.projectDateModifiedHeader());
    dateModifiedHeaderLabel.addStyleName("ode-ProjectHeaderLabel");
    dateModifiedHeader.add(dateModifiedHeaderLabel);
    dateModifiedSortIndicator.addStyleName("ode-ProjectHeaderLabel");
    dateModifiedHeader.add(dateModifiedSortIndicator);
    table.setWidget(0, 3, dateModifiedHeader);

    HorizontalPanel publishedHeader = new HorizontalPanel();
    final Label publishedHeaderLabel = new Label(MESSAGES.projectPublishedHeader());
    publishedHeaderLabel.addStyleName("ode-ProjectHeaderLabel");
    publishedHeader.add(publishedHeaderLabel);
    publishedSortIndicator.addStyleName("ode-ProjectHeaderLabel");
    publishedHeader.add(publishedSortIndicator);
    table.setWidget(0, 4, publishedHeader);

    MouseDownHandler mouseDownHandler = new MouseDownHandler() {
        @Override
        public void onMouseDown(MouseDownEvent e) {
            SortField clickedSortField;
            if (e.getSource() == nameHeaderLabel || e.getSource() == nameSortIndicator) {
                clickedSortField = SortField.NAME;
            } else if (e.getSource() == dateCreatedHeaderLabel || e.getSource() == dateCreatedSortIndicator) {
                clickedSortField = SortField.DATE_CREATED;
            } else if (e.getSource() == dateModifiedHeaderLabel || e.getSource() == dateModifiedSortIndicator) {
                clickedSortField = SortField.DATE_MODIFIED;
            } else {
                clickedSortField = SortField.PUBLISHED;
            }
            changeSortOrder(clickedSortField);
        }
    };
    nameHeaderLabel.addMouseDownHandler(mouseDownHandler);
    nameSortIndicator.addMouseDownHandler(mouseDownHandler);
    dateCreatedHeaderLabel.addMouseDownHandler(mouseDownHandler);
    dateCreatedSortIndicator.addMouseDownHandler(mouseDownHandler);
    dateModifiedHeaderLabel.addMouseDownHandler(mouseDownHandler);
    dateModifiedSortIndicator.addMouseDownHandler(mouseDownHandler);
    publishedHeaderLabel.addMouseDownHandler(mouseDownHandler);
    publishedSortIndicator.addMouseDownHandler(mouseDownHandler);
}

From source file:io.apiman.manager.ui.client.local.pages.common.PolicyList.java

License:Apache License

/**
 * Creates a single policy row./*from   ww  w  .  ja va2  s.c  o m*/
 * @param bean
 */
private Widget createPolicyRow(final PolicyBean bean) {
    PolicyRow container = new PolicyRow(bean);

    final FlowPanel row = new FlowPanel();
    row.getElement().setClassName("row"); //$NON-NLS-1$

    // Grabber
    Label grabber = new Label();
    grabber.getElement().setDraggable(Element.DRAGGABLE_TRUE);
    grabber.getElement().setClassName("grabber"); //$NON-NLS-1$
    grabber.getElement().getStyle().setHeight(48, Unit.PX);
    row.add(grabber);

    createIconColumn(bean, row);
    createSummaryColumn(bean, row);
    createActionColumn(bean, row);
    container.add(new HTMLPanel("<hr/>")); //$NON-NLS-1$

    container.add(row);

    PolicyDragHandler handler = new PolicyDragHandler(grabber, container);
    grabber.addMouseDownHandler(handler);
    grabber.addMouseUpHandler(handler);
    grabber.addMouseMoveHandler(handler);

    return container;
}

From source file:org.waveprotocol.wave.client.widget.button.icon.IconButtonTemplate.java

License:Apache License

@UiConstructor
public IconButtonTemplate() {
    Label label = new Label();
    initWidget(label);/*from www.  j  a va  2 s  .c o  m*/
    label.addClickHandler(this);
    label.addMouseOverHandler(this);
    label.addMouseOutHandler(this);
    label.addMouseUpHandler(this);
    label.addMouseDownHandler(this);
}

From source file:org.wisepersist.gwt.uploader.client.Uploader.java

License:Apache License

@Override
protected void onLoad() {
    if (loaded) {
        return;/*  w w  w  .j a  v a2 s .c  o m*/
    }
    loaded = true;

    // Make sure our entire panel fits the size that they wanted for the button
    if (this.buttonWidth >= 0) {
        this.setWidth(this.buttonWidth + "px");
    }
    if (this.buttonHeight >= 0) {
        this.setHeight(this.buttonHeight + "px");
    }

    if (ajaxUploadEnabled && isAjaxUploadWithProgressEventsSupported()) {

        // If the browser supports the XMLHttpRequest Level 2 type then we can avoid rendering the
        // flash component and just stick with a DOM/Ajax approach.

        // Use a hidden file input component to handle allowing the user to popup the file system
        // dialog (but keep it outside of the button itself so it doesn't interfere with the mouse
        // events)
        this.add(createFileUpload());

        // Create the main element that will hold all of the inner workings of the uploader component
        Label button = new Label();
        button.setWidth("100%");
        button.setHeight("100%");
        if (this.buttonCursor != null) {
            switch (this.buttonCursor) {
            case ARROW:
                button.getElement().getStyle().setCursor(Style.Cursor.DEFAULT);
                break;
            case HAND:
                button.getElement().getStyle().setCursor(Style.Cursor.POINTER);
                break;
            }
        }

        // Setup what we want to happen when someone clicks anywhere on the button
        button.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                if (buttonDisabled) {
                    return;
                }
                switch (buttonAction) {
                case START_UPLOAD:
                    startUpload();
                    break;
                case SELECT_FILES:
                    openFileDialog(fileUpload, true);
                    break;
                case SELECT_FILE:
                default:
                    openFileDialog(fileUpload, false);
                    break;
                }
            }
        });

        button.addMouseOverHandler(new MouseOverHandler() {
            public void onMouseOver(MouseOverEvent event) {
                if (buttonImageURL != null && buttonHeight >= 0 && !buttonDisabled) {
                    buttonImageElement.getStyle().setProperty("backgroundPosition",
                            "0px -" + buttonHeight + "px");
                }
            }
        });
        button.addMouseOutHandler(new MouseOutHandler() {
            public void onMouseOut(MouseOutEvent event) {
                if (buttonImageURL != null && buttonHeight >= 0 && !buttonDisabled) {
                    buttonImageElement.getStyle().setProperty("backgroundPosition", "0px 0px");
                }
            }
        });
        button.addMouseDownHandler(new MouseDownHandler() {
            public void onMouseDown(MouseDownEvent event) {
                if (buttonImageURL != null && buttonHeight >= 0 && !buttonDisabled) {
                    buttonImageElement.getStyle().setProperty("backgroundPosition",
                            "0px -" + (buttonHeight * 2) + "px");
                }
            }
        });
        button.addMouseUpHandler(new MouseUpHandler() {
            public void onMouseUp(MouseUpEvent event) {
                if (buttonImageURL != null && buttonHeight >= 0 && !buttonDisabled) {
                    buttonImageElement.getStyle().setProperty("backgroundPosition", "0px 0px");
                }
            }
        });

        // Depending on the way they wanted the uploader button rendered, create the appropriate
        // elements in the DOM that the user will click on.
        if (this.buttonTextStyle != null) {
            buttonTextStyleElement = Document.get().createStyleElement();
            buttonTextStyleElement.setInnerText(this.buttonTextStyle);
            button.getElement().appendChild(buttonTextStyleElement);
        }
        if (this.buttonText != null) {
            buttonTextElement = Document.get().createDivElement();
            buttonTextElement.setInnerHTML(this.buttonText);
            buttonTextElement.getStyle().setWidth(100, Style.Unit.PCT);
            buttonTextElement.getStyle().setHeight(100, Style.Unit.PCT);
            if (this.buttonTextLeftPadding > Integer.MIN_VALUE) {
                buttonTextElement.getStyle().setPaddingLeft(this.buttonTextLeftPadding, Style.Unit.PX);
            }
            if (this.buttonTextTopPadding > Integer.MIN_VALUE) {
                buttonTextElement.getStyle().setPaddingTop(this.buttonTextTopPadding, Style.Unit.PX);
            }
            button.getElement().appendChild(buttonTextElement);
        }

        if (this.buttonImageURL != null) {
            buttonImageElement = Document.get().createDivElement();
            buttonImageElement.getStyle().setBackgroundImage("url(\"" + this.buttonImageURL + "\")");
            if (this.buttonDisabled) {
                buttonImageElement.getStyle().setProperty("backgroundPosition",
                        "0px -" + (buttonHeight * 3) + "px");
            } else {
                buttonImageElement.getStyle().setProperty("backgroundPosition", "0px 0px");
            }
            buttonImageElement.getStyle().setWidth(100, Style.Unit.PCT);
            buttonImageElement.getStyle().setHeight(100, Style.Unit.PCT);
            button.getElement().appendChild(buttonImageElement);
        }

        // Add the entire button to the DOM
        this.add(button);

    } else {

        // If the browser doesn't support the XMLHttpRequest Level 2 type, then our only option is
        // to use the Flash/SWFUpload component.

        // The SWFUpload JS code completely replaces the DOM element that you give it as a target,
        // so we're creating an inner component that it can replace - leaving the outer component
        // for the caller to use as the GWT Widget that they can manage and style within the
        // appropriate container within their GWT application
        DivElement swfUploadElement = Document.get().createDivElement();
        swfUploadElement.setId(Document.get().createUniqueId());
        this.getElement().appendChild(swfUploadElement);

        JavaScriptObject nativeOptions = createNativeOptions(swfUploadElement.getId());

        // Build a map that we'll use during the native creation process to setup
        // the necessary JSNI bridges to our Java event handlers...
        JSONObject eventHandlers = new JSONObject();
        eventHandlers.put("swfupload_loaded_handler", JSONBoolean.getInstance(swfUploadLoadedHandler != null));
        eventHandlers.put("file_dialog_start_handler", JSONBoolean.getInstance(fileDialogStartHandler != null));
        eventHandlers.put("file_queued_handler", JSONBoolean.getInstance(fileQueuedHandler != null));
        eventHandlers.put("file_queue_error_handler", JSONBoolean.getInstance(fileQueueErrorHandler != null));
        eventHandlers.put("file_dialog_complete_handler",
                JSONBoolean.getInstance(fileDialogCompleteHandler != null));
        eventHandlers.put("upload_start_handler", JSONBoolean.getInstance(uploadStartHandler != null));
        eventHandlers.put("upload_progress_handler", JSONBoolean.getInstance(uploadProgressHandler != null));
        eventHandlers.put("upload_error_handler", JSONBoolean.getInstance(uploadErrorHandler != null));
        eventHandlers.put("upload_success_handler", JSONBoolean.getInstance(uploadSuccessHandler != null));
        eventHandlers.put("upload_complete_handler", JSONBoolean.getInstance(uploadCompleteHandler != null));

        swfUpload = nativeCreateSWFUpload(nativeOptions, eventHandlers.getJavaScriptObject());
    }
}