Example usage for java.awt Button.ClickListener Button.ClickListener

List of usage examples for java.awt Button.ClickListener Button.ClickListener

Introduction

In this page you can find the example usage for java.awt Button.ClickListener Button.ClickListener.

Prototype

Button.ClickListener

Source Link

Usage

From source file:com.esofthead.mycollab.community.ui.chart.PieChartWrapper.java

@Override
protected final ComponentContainer createLegendBox() {
    final CustomLayout boxWrapper = CustomLayoutExt.createLayout("legendBox");
    final CssLayout mainLayout = new CssLayout();

    mainLayout.setSizeUndefined();//from  ww  w. ja va  2s .  c  o m
    final List keys = pieDataSet.getKeys();

    for (int i = 0; i < keys.size(); i++) {
        final HorizontalLayout layout = new HorizontalLayout();
        layout.setMargin(new MarginInfo(false, false, false, true));
        layout.addStyleName("inline-block");
        final Comparable key = (Comparable) keys.get(i);
        final String color = "<div style = \" width:8px;height:8px;border-radius:5px;background: #"
                + GenericChartWrapper.CHART_COLOR_STR[i % GenericChartWrapper.CHART_COLOR_STR.length] + "\" />";
        final Label lblCircle = new Label(color);
        lblCircle.setContentMode(ContentMode.HTML);

        String btnCaption;
        if (enumKeyCls == null) {
            btnCaption = String.format("%s(%d)", key, pieDataSet.getValue(key).intValue());
        } else {
            btnCaption = String.format("%s(%d)", AppContext.getMessage(enumKeyCls, key.toString()),
                    pieDataSet.getValue(key).intValue());
        }
        final Button btnLink = new Button(btnCaption, new Button.ClickListener() {
            private static final long serialVersionUID = 1L;

            @Override
            public void buttonClick(final ClickEvent event) {
                PieChartWrapper.this.onClickedDescription(key.toString());
            }
        });
        btnLink.addStyleName("link");
        layout.addComponent(lblCircle);
        layout.setComponentAlignment(lblCircle, Alignment.MIDDLE_CENTER);
        layout.addComponent(btnLink);
        layout.setComponentAlignment(btnLink, Alignment.MIDDLE_CENTER);
        layout.setSizeUndefined();
        mainLayout.addComponent(layout);
    }
    boxWrapper.setWidth("100%");
    boxWrapper.addComponent(mainLayout, "legendBoxContent");
    return boxWrapper;
}

From source file:com.esofthead.mycollab.ui.chart.PieChartWrapper.java

@Override
protected final ComponentContainer createLegendBox() {
    final CssLayout mainLayout = new CssLayout();
    mainLayout.addStyleName("legendBoxContent");
    mainLayout.setSizeUndefined();// w w w . j av a  2 s  . c  o m
    final List keys = pieDataSet.getKeys();

    for (int i = 0; i < keys.size(); i++) {
        MHorizontalLayout layout = new MHorizontalLayout()
                .withMargin(new MarginInfo(false, false, false, true));
        layout.addStyleName("inline-block");
        layout.setSizeUndefined();
        layout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);

        final Comparable key = (Comparable) keys.get(i);
        int colorIndex = i % CHART_COLOR_STR.size();
        final String color = "<div style = \" width:13px;height:13px;background: #"
                + CHART_COLOR_STR.get(colorIndex) + "\" />";
        final Label lblCircle = new Label(color);
        lblCircle.setContentMode(ContentMode.HTML);

        String btnCaption;
        if (enumKeyCls == null) {
            if (key instanceof Key) {
                btnCaption = String.format("%s (%d)", StringUtils.trim(((Key) key).getDisplayName(), 20, true),
                        pieDataSet.getValue(key).intValue());
            } else {
                btnCaption = String.format("%s (%d)", key, pieDataSet.getValue(key).intValue());
            }
        } else {
            btnCaption = String.format("%s(%d)", AppContext.getMessage(enumKeyCls, key.toString()),
                    pieDataSet.getValue(key).intValue());
        }
        final Button btnLink = new Button(StringUtils.trim(btnCaption, 25, true), new Button.ClickListener() {
            private static final long serialVersionUID = 1L;

            @Override
            public void buttonClick(final ClickEvent event) {
                if (key instanceof Key) {
                    clickLegendItem(((Key) key).getKey());
                } else {
                    clickLegendItem(key.toString());
                }
            }
        });
        btnLink.setDescription(btnCaption);
        btnLink.addStyleName(UIConstants.BUTTON_LINK);
        layout.with(lblCircle, btnLink);
        mainLayout.addComponent(layout);
    }
    mainLayout.setWidth("100%");
    return mainLayout;
}