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

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

Introduction

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

Prototype

public HandlerRegistration addClickHandler(ClickHandler handler) 

Source Link

Usage

From source file:com.sensia.tools.client.swetools.editors.sensorml.panels.widgets.AbstractSensorElementWidget.java

License:Open Source License

/**
 * Gets a panel represented as a PLUS icon. The panel has the action to create a new panel.
 *
 * @param annotation the annotation/* w w  w .ja v a 2 s .c o  m*/
 * @param label the label
 * @return the adds the button panel
 */
protected Panel getAddButtonPanel(String annotation, final String label) {

    Label addButton = new Label(annotation);
    addButton.addStyleName("rng-optional-select");

    addButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            if (!getElements().isEmpty() && getMode() == MODE.EDIT) {
                //concatenates every panels
                VerticalPanel allEditPanels = new VerticalPanel();
                final List<ISensorWidget> clones = new ArrayList<ISensorWidget>();

                for (final ISensorWidget panelToAdd : getElements()) {
                    ISensorWidget clone = panelToAdd.cloneSensorWidget();
                    if (clone != null) {
                        clone.switchMode(getMode());
                        clones.add(clone);
                        allEditPanels.add(clone.getPanel());
                    } else {
                        GWT.log("Clone method is not implemented yet for class : "
                                + panelToAdd.getClass().toString());
                    }

                }

                final DialogBox dialogBox = Utils.createAddDialogBox(allEditPanels, "Add " + label,
                        new IButtonCallback() {

                            @Override
                            public void onClick() {
                                for (ISensorWidget clone : clones) {
                                    getParent().addElement(clone);
                                }
                            }
                        });
                dialogBox.show();
            }
        }
    });

    final HorizontalPanel panel = new HorizontalPanel();
    panel.add(addButton);
    panel.add(new HTML(label));

    return panel;
}

From source file:com.sun.labs.aura.music.wsitm.client.ui.ContextMenu.java

License:Open Source License

public void addElement(Label l, ClickHandler cH) {
    l.addClickHandler(cH);
    l.addClickHandler(hideOnClickHandler);
    l.addStyleName("contextMenuItem");

    l.addMouseOutHandler(new DEMouseOutHandler<Label>(l) {
        @Override/*from  w ww. ja  v  a2  s  .c  o  m*/
        public void onMouseOut(MouseOutEvent event) {
            data.removeStyleName("contextMenuItemHover");
        }
    });
    l.addMouseOverHandler(new DEMouseOverHandler<Label>(l) {
        @Override
        public void onMouseOver(MouseOverEvent event) {
            data.addStyleName("contextMenuItemHover");
        }
    });
    vP.add(l);
}

From source file:com.sun.labs.aura.music.wsitm.client.ui.ContextMenu.java

License:Open Source License

/**
 * @deprecated//from   w  w  w. j a va 2  s . c o m
 * @param l
 * @param cL
 */
public void addElement(Label l, ClickListener cL) {
    l.addClickListener(cL);
    l.addClickHandler(hideOnClickHandler);
    l.addStyleName("contextMenuItem");
    l.addMouseListener(new DataEmbededMouseListener<Label>(l) {

        public void onMouseEnter(Widget sender) {
            data.addStyleName("contextMenuItemHover");
        }

        public void onMouseLeave(Widget sender) {
            data.removeStyleName("contextMenuItemHover");
        }

        public void onMouseDown(Widget sender, int x, int y) {
        }

        public void onMouseMove(Widget sender, int x, int y) {
        }

        public void onMouseUp(Widget sender, int x, int y) {
        }
    });
    vP.add(l);
}

From source file:com.sun.labs.aura.music.wsitm.client.ui.HelpPopup.java

License:Open Source License

/**
 * Build the menu of the pannel and create the rounded popup
 *///  ww w  .  ja v  a 2  s. c om
private void buildPanel() {

    HorizontalPanel menu = new HorizontalPanel();
    menu.setStyleName("helpPopupMenu");
    menu.setWidth("460px");
    menu.setHorizontalAlignment(HorizontalPanel.ALIGN_CENTER);
    for (HelpSection hS : sections) {
        Label sL = hS.lbl;
        sL.addClickHandler(new DEClickHandler<HELP_SECTIONS>(hS.section) {
            @Override
            public void onClick(ClickEvent event) {
                showHelp(data);
            }
        });
        menu.add(sL);
        menu.add(new Label(" - "));
    }
    menu.remove(menu.getWidgetCount() - 1);

    RoundedPanel rp = new RoundedPanel(menu, RoundedPanel.ALL, 3);
    rp.setCornerStyleName("helpPopupMenu");
    rp.setWidth("460px");
    rp.getElement().getStyle().setPropertyPx("marginBottom", 8);

    VerticalPanel vP = new VerticalPanel();
    vP.setHorizontalAlignment(HorizontalPanel.ALIGN_CENTER);
    vP.add(rp);
    vP.add(contentPanel);
    Popup.showRoundedPopup(vP, "Music Explaura Help", popup, 800);
    isInit = true;

}

From source file:com.sun.labs.aura.music.wsitm.client.ui.Popup.java

License:Open Source License

public static void showPopup(Widget w, String title, final DialogBox popup) {

    DockPanel docPanel = new DockPanel();

    Label closeButton = new Label("Close");
    closeButton.setStyleName("clickableLabel");
    closeButton.addStyleName("whiteTxt");
    closeButton.addClickHandler(new ClickHandler() {
        @Override/*from  w ww . java  2 s .  co  m*/
        public void onClick(ClickEvent ce) {
            popup.hide();
        }
    });

    FlowPanel container = new FlowPanel();
    container.setStyleName("outerpopup");
    container.add(w);

    docPanel.add(container, DockPanel.CENTER);
    docPanel.add(closeButton, DockPanel.SOUTH);
    docPanel.setCellHorizontalAlignment(closeButton, DockPanel.ALIGN_RIGHT);
    popup.add(docPanel);
    popup.setText(title);
    popup.setAnimationEnabled(true);
    popup.center();
}

From source file:com.sun.labs.aura.music.wsitm.client.ui.swidget.HomeSwidget.java

License:Open Source License

public HomeSwidget(ClientDataManager cdm) {
    super("Home", cdm);

    HorizontalPanel titleHp = new HorizontalPanel();
    titleHp.setWidth("100%");
    titleHp.setStyleName("h2");
    titleHp.add(new Label("Popular artists"));
    titleHp.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT);
    Label featMore = new Label("More");
    featMore.addStyleName("headerMenuMedItem");
    featMore.addClickHandler(new ClickHandler() {
        @Override/*from ww w .jav  a 2s .  c  o m*/
        public void onClick(ClickEvent ce) {
            invokeFetchRandomArtists();
        }
    });

    titleHp.add(featMore);
    popArtists = new DualRoundedPanel();
    popArtists.setVisible(false);
    popArtists.setHeader(titleHp);
    popArtists.setContent(WebLib.getSunLoaderWidget(), false);

    mainPanel = new Grid(3, 1);
    mainPanel.getCellFormatter().setHorizontalAlignment(0, 0, HorizontalPanel.ALIGN_CENTER);
    //mainPanel.setWidget(0, 0, search);
    mainPanel.getCellFormatter().setHorizontalAlignment(1, 0, HorizontalPanel.ALIGN_CENTER);
    mainPanel.setWidget(1, 0, popArtists);

    if (DEBUG_MODE) {
        Label exLabel = new Label("Trigger exception");
        exLabel.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                invokeTriggerDebugException();
            }
        });
        mainPanel.setWidget(2, 0, exLabel);
    }

    initWidget(mainPanel, true);
    invokeFetchRandomArtists();
}

From source file:com.sun.labs.aura.music.wsitm.client.ui.swidget.ServerInfoSwidget.java

License:Open Source License

public ServerInfoSwidget(ClientDataManager cdm) {
    super("Server information", cdm);

    g = new Grid(2, 1);

    Label update = new Label("Update");
    update.addStyleName("pointer");
    update.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent ce) {
            g.setWidget(1, 0, WebLib.getSunLoaderWidget());
            invokeGetServerInfo();/*from  ww  w. ja v a  2 s  .c  o  m*/
        }
    });
    g.setWidget(0, 0, update);

    initWidget(g);
}

From source file:com.sun.labs.aura.music.wsitm.client.ui.swidget.SimpleSearchSwidget.java

License:Open Source License

private void invokeGetArtistInfo(String artistID, boolean refresh, SearchResults listResults) {
    PerformanceTimer.start("invokeGetArtistInfo");
    ///*from w ww  .  j  a  v  a 2 s  . c  o  m*/
    // If we are currently fetching the similarity type, we can't fetch the
    // artist's info yet so let's try again in 250ms
    if (cdm.getCurrSimTypeName() == null || cdm.getCurrSimTypeName().equals("")) {
        Timer t = new TimerWithArtist(artistID, refresh);
        t.schedule(250);
    } else {
        if (artistID.startsWith("artist:")) {
            artistID = artistID.replaceAll("artist:", "");
        }

        AsyncCallback callback = new DEAsyncCallback<SearchResults, ArtistDetails>(listResults) {

            public void onSuccess(ArtistDetails artistDetails) {
                PerformanceTimer.stop("getArtistDetails");
                // do some UI stuff to show success
                if (artistDetails != null && artistDetails.isOK()) {
                    PerformanceTimer.start("createArtistPanel");
                    cdm.setCurrArtistInfo(artistDetails.getId(), artistDetails.getName());
                    Widget artistPanel = createArtistPanel(artistDetails);
                    //search.setText(artistDetails.getName(), searchTypes.SEARCH_FOR_ARTIST_BY_ARTIST);
                    //search.updateSuggestBox(Oracles.ARTIST);
                    setResults("artist:" + artistDetails.getId(), artistPanel);
                    hideLoader();

                    showTopMessage(new Label("Artist bio is displayed below.  Click any tag for details. "
                            + "Similar artists are shown on the left.  See where they overlap "
                            + "with \"why?\".  The big steering wheel on the right lets you "
                            + "customize the recommended artists."));

                    // If we embeded a search result, a serch was made and although aura returned
                    // multiple results, one of them matched exacly. Offer to display the full list
                    if (data != null) {
                        int length = data.getItemResults(null).length;
                        Label l = new Label("Not the artist you were looking for? Show "
                                + String.valueOf(length - 1) + " similar result" + (length > 2 ? "s" : ""));
                        l.setStyleName("pointer topMsgIndicatorSmall");
                        l.addClickHandler(new ClickHandler() {
                            @Override
                            public void onClick(ClickEvent event) {
                                searchResultsToArtistList(data);
                            }
                        });
                        showTopMessage(l);
                    }

                    PerformanceTimer.stop("createArtistPanel");
                } else {
                    if (artistDetails == null) {
                        showTopMessage("Sorry. The details for the artist don't seem to be in our database.");
                        clearResults();
                    } else {
                        showTopMessage("Whooops " + artistDetails.getStatus());
                        clearResults();
                    }
                }
                PerformanceTimer.stop("invokeGetArtistInfo");
            }

            public void onFailure(Throwable caught) {
                PerformanceTimer.stop("getArtistDetails");
                Popup.showErrorPopup(caught, Popup.ERROR_MSG_PREFIX.ERROR_OCC_WHILE, "retrieve artist details.",
                        Popup.ERROR_LVL.NORMAL, null);
                PerformanceTimer.stop("invokeGetArtistInfo");
            }
        };

        showLoader();

        try {
            PerformanceTimer.start("getArtistDetails");
            musicServer.getArtistDetails(artistID, refresh, cdm.getCurrSimTypeName(), cdm.getCurrPopularity(),
                    callback);
        } catch (Exception ex) {
            Popup.showErrorPopup(ex, Popup.ERROR_MSG_PREFIX.ERROR_OCC_WHILE, "retrieve artist details.",
                    Popup.ERROR_LVL.NORMAL, null);
        }
    }
}

From source file:com.sun.labs.aura.music.wsitm.client.ui.swidget.SimpleSearchSwidget.java

License:Open Source License

private VerticalPanel getItemInfoList(final String title, final ItemInfo[] itemInfo, String highlightID,
        boolean getArtistOnClick, boolean displayPopularity, PopSortedMultiWordSuggestOracle oracle) {

    Grid artistGrid;//from www  .  jav  a  2s  . c  om
    if (displayPopularity) {
        artistGrid = new Grid(itemInfo.length + 1, 2);
        artistGrid.setCellSpacing(5);
        artistGrid.setWidget(0, 0, new HTML("<b>Name</b>"));
        artistGrid.setWidget(0, 1, new HTML("<b>Popularity</b>"));
    } else {
        artistGrid = new Grid(itemInfo.length, 1);
    }

    // Find the maximum values for score and popularity
    double maxPopularity = 0;
    for (ItemInfo iI : itemInfo) {
        if (iI.getPopularity() > maxPopularity) {
            maxPopularity = iI.getPopularity();
        }
    }

    for (int i = 0; i < itemInfo.length; i++) {

        if (oracle != null) {
            oracle.add(itemInfo[i].getItemName(), itemInfo[i].getPopularity());
        }

        Label label = new Label(itemInfo[i].getItemName());
        label.addClickHandler(new DEClickHandler<String>(itemInfo[i].getId()) {
            @Override
            public void onClick(ClickEvent event) {
                // Add search attention if necessary
                cdm.getSearchAttentionManager().processUserClick(data);
            }
        });
        label.addClickHandler(new ItemInfoClickHandler(itemInfo[i], getArtistOnClick));
        label.setTitle("Score: " + itemInfo[i].getScore() + " Popularity:" + itemInfo[i].getPopularity());
        if (highlightID != null && highlightID.equals(itemInfo[i].getId())) {
            label.setStyleName("itemInfoHighlight");
        } else {
            label.setStyleName("itemInfo");
        }

        if (displayPopularity) {
            artistGrid.setWidget(i + 1, 0, label);
            artistGrid.setWidget(i + 1, 1,
                    WebLib.getPopularityHisto(itemInfo[i].getPopularity() / maxPopularity, false, 10, 100));
        } else {
            artistGrid.setWidget(i, 0, label);
        }
    }

    VerticalPanel w;
    if (!getArtistOnClick) {
        Grid titleWidget = new Grid(1, 2);
        titleWidget.setWidget(0, 0, new HTML("<h2>" + title + "</h2>"));
        Label l = new Label(" Cloud");
        l.setStyleName("tinyInfo");
        l.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent ce) {
                TagDisplayLib.showTagCloud(title, itemInfo, TagDisplayLib.ORDER.SHUFFLE, cdm);
            }
        });
        titleWidget.setWidget(0, 1, l);
        w = WebLib.createSection(titleWidget, artistGrid);
    } else {
        w = WebLib.createSection(title, artistGrid);
    }
    w.setStyleName("infoList");
    if (displayPopularity) {
        w.setWidth("325px");
    } else {
        w.setWidth("200px");
    }
    return w;
}

From source file:com.sun.labs.aura.music.wsitm.client.ui.TagDisplayLib.java

License:Open Source License

/**
 * Return a panel containing the tags cloud passed in parameter. If panel
 * will be used in pop-up, pass the DialogBox that will contain it in d to add
 * so the pop-up can be closed when a tag is clicked on
 * @param tags//  www.  j a  va  2  s. com
 * @param d
 * @return
 */
public static Panel getTagsInPanel(ItemInfo[] tags, PopupPanel d, ORDER order, ClientDataManager cdm,
        TagColorType colorTheme) {
    Panel p = new FlowPanel();
    if (d != null) {
        p.setWidth("600px");
    }
    HorizontalPanel innerP = new HorizontalPanel();
    innerP.setSpacing(4);

    if (tags != null && tags.length > 0) {

        double max = 0;
        double min = 1;
        double tempScore;
        for (ItemInfo tag : tags) {
            tempScore = Math.abs(tag.getScore());
            if (tempScore > max) {
                max = tempScore;
            } else if (tempScore < min) {
                min = tempScore;
            }
        }
        double range = max - min;

        if (order == ORDER.SHUFFLE) {
            Arrays.sort(tags, ItemInfo.getRandomSorter());
        } else if (order == ORDER.DESC) {
            Arrays.sort(tags, ItemInfo.getScoreSorter());
        } else if (order == ORDER.ALPHABETICAL) {
            Arrays.sort(tags, ItemInfo.getNameSorter());
        }

        for (int i = 0; i < tags.length; i++) {
            boolean isTag = tags[i].getId().startsWith("artist-tag:");
            int colorId = i % 2;

            int fontSize;
            if (tags.length == 1 || range == 0) {
                fontSize = scoreToFontSize(1);
            } else {
                fontSize = scoreToFontSize((Math.abs(tags[i].getScore()) - min) / range);
            }

            Label sL;
            if (isTag) {
                sL = new ContextMenuTagLabel(tags[i], cdm);
            } else {
                sL = new SpannedLabel(tags[i].getItemName());
            }

            sL.getElement().getStyle().setPropertyPx("fontSize", fontSize);
            setColorToElem(sL, colorId, tags[i].getScore(), null, colorTheme);
            sL.addStyleName("pointer");
            sL.addClickHandler(new DDEClickHandler<ItemInfo, Boolean>(tags[i], isTag) {
                @Override
                public void onClick(ClickEvent event) {
                    String tagLink = data.getId();
                    if (!sndData) {
                        History.newItem("artist:" + data.getId());
                    } else {
                        if (!tagLink.startsWith("artist-tag:")) {
                            tagLink = ClientDataManager.nameToKey(tagLink);
                        }
                        History.newItem("tag:" + tagLink);
                    }
                }
            });
            if (d != null) {
                sL.addClickHandler(new DEClickHandler<PopupPanel>(d) {

                    @Override
                    public void onClick(ClickEvent event) {
                        data.hide();
                    }
                });
            }
            p.add(sL);
            p.add(new SpannedLabel("    "));
        }
        return p;
    } else {
        return null;
    }
}