Java 类org.eclipse.draw2d.ToggleButton 实例源码

项目:scouter    文件:XYGraphToolbar.java   
/** Create buttons enumerated in <code>ZoomType</code>
    *  @param flags Bitwise 'or' of flags
    *  @see XYGraphFlags#COMBINED_ZOOM
    *  @see XYGraphFlags#SEPARATE_ZOOM
 */
private void createZoomButtons(final int flags) {
    for(final ZoomType zoomType : ZoomType.values()){
        if (! zoomType.useWithFlags(flags))
            continue;
        final ImageFigure imageFigure =  new ImageFigure(zoomType.getIconImage());
        final Label tip = new Label(zoomType.getDescription());
        final ToggleButton button = new ToggleButton(imageFigure);
        button.setBackgroundColor(ColorConstants.button);
        button.setOpaque(true);
        final ToggleModel model = new ToggleModel();
        model.addChangeListener(new ChangeListener(){
            public void handleStateChanged(ChangeEvent event) {
                if(event.getPropertyName().equals("selected") && 
                        button.isSelected()){
                    xyGraph.setZoomType(zoomType);
                }               
            }
        });

        button.setModel(model);
        button.setToolTip(tip);
        addButton(button);
        zoomGroup.add(model);

        if(zoomType == ZoomType.NONE)
            zoomGroup.setDefault(model);
    }
}