<commit_before>package org.csstudio.opibuilder.widgets.figures;

import org.csstudio.opibuilder.widgets.Activator;
import org.csstudio.swt.widgets.figures.ITextFigure;
import org.csstudio.ui.util.CustomMediaFactory;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Image;

/**
 * Figure for the menu button.
 *
 * @author <NAME>
 *
 */
public class MenuButtonFigure extends Label implements ITextFigure{

    public static final int ICON_WIDTH = 15;

    private static final Image downArrow = CustomMediaFactory.getInstance().
            getImageFromPlugin(Activator.PLUGIN_ID, "icons/downArrow.png");

    private boolean showDownArrow = false;

    @Override
    public void setText(String s) {
        super.setText(s);
        layoutIcons();
    }

    @Override
    public void setBounds(Rectangle rect) {
        super.setBounds(rect);
        layoutIcons();
    }

    /**
     * Control the appearance of the down arrow indicator
     * on the menu button.
     *
     * @param showArrow if the arrow is to be shown.
     */
    public void showDownArrow(boolean showArrow) {
        this.showDownArrow = showArrow;
        if(showArrow) {
            setIcon(downArrow);
        } else {
            setIcon(null);
        }
        layoutIcons();
    }

    /**
     * Layout the contents of the widget so that, if an icon is displayed, it is
     * right aligned and the text remains centred.
     */
    private void layoutIcons() {
        if(showDownArrow) {
            setLabelAlignment(PositionConstants.RIGHT);
            setTextPlacement(PositionConstants.WEST);
        } else {
            setLabelAlignment(PositionConstants.CENTER);
        }
    }
}<commit_msg>Refactor new figure class<commit_after>package org.csstudio.opibuilder.widgets.figures;

import org.csstudio.opibuilder.widgets.Activator;
import org.csstudio.swt.widgets.figures.ITextFigure;
import org.csstudio.ui.util.CustomMediaFactory;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Image;

/**
 * Figure for the menu button.
 *
 * @author <NAME>
 *
 */
public class MenuButtonFigure extends Label implements ITextFigure{

    public static final int ICON_WIDTH = 15;

    private static final Image downArrow = CustomMediaFactory.getInstance().
            getImageFromPlugin(Activator.PLUGIN_ID, "icons/downArrow.png");

    @Override
    public void setText(String s) {
        super.setText(s);
        updateLayout();
    }

    @Override
    public void setBounds(Rectangle rect) {
        super.setBounds(rect);
        updateLayout();
    }

    /**
     * Control the appearance of the down arrow indicator
     * on the menu button.
     *
     * @param showArrow if the arrow is to be shown.
     */
    public void showDownArrow(boolean showArrow) {
        if(showArrow) {
            setIcon(downArrow);
            setLabelAlignment(PositionConstants.RIGHT);
            setTextPlacement(PositionConstants.WEST);
        } else {
            setIcon(null);
            setLabelAlignment(PositionConstants.CENTER);
        }
        updateLayout();
    }

    /**
     * Layout the contents of the widget so that, if an icon is displayed, it is
     * right aligned and the text remains centred.
     */
    private void updateLayout() {
        setIconTextGap((getBounds().width - this.getTextBounds().width - ICON_WIDTH)/2);
    }
}
{'fraction_non_alphanumeric': 0.09392575928008999, 'fraction_numerical': 0.003093363329583802, 'mean_word_length': 2.7090719499478624, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6039901', 'n_tokens_mistral': 1028, 'n_tokens_neox': 1020, 'n_words': 246}