Search in sources :

Example 1 with WrappableTextFigure

use of org.csstudio.swt.widgets.figures.WrappableTextFigure in project yamcs-studio by yamcs.

the class LabelEditPart method doCreateFigure.

@Override
protected IFigure doCreateFigure() {
    TextFigure labelFigure = createTextFigure();
    labelFigure.setOpaque(!getWidgetModel().isTransparent());
    labelFigure.setHorizontalAlignment(getWidgetModel().getHorizontalAlignment());
    labelFigure.setVerticalAlignment(getWidgetModel().getVerticalAlignment());
    labelFigure.setSelectable(determinSelectable());
    labelFigure.setText(getWidgetModel().getText());
    labelFigure.setFontPixels(getWidgetModel().getFont().isSizeInPixels());
    if (labelFigure instanceof WrappableTextFigure)
        ((WrappableTextFigure) labelFigure).setShowScrollbar(getWidgetModel().isShowScrollbar());
    updatePropertyVisibility();
    return labelFigure;
}
Also used : WrappableTextFigure(org.csstudio.swt.widgets.figures.WrappableTextFigure) ITextFigure(org.csstudio.swt.widgets.figures.ITextFigure) TextFigure(org.csstudio.swt.widgets.figures.TextFigure) WrappableTextFigure(org.csstudio.swt.widgets.figures.WrappableTextFigure)

Example 2 with WrappableTextFigure

use of org.csstudio.swt.widgets.figures.WrappableTextFigure in project yamcs-studio by yamcs.

the class LabelEditPart method registerPropertyChangeHandlers.

@Override
protected void registerPropertyChangeHandlers() {
    setPropertyChangeHandler(PROP_TEXT, (oldValue, newValue, figure) -> {
        ((TextFigure) figure).setText((String) newValue);
        Display.getCurrent().timerExec(10, () -> {
            if (getWidgetModel().isAutoSize()) {
                getWidgetModel().setSize(((TextFigure) figure).getAutoSizeDimension());
            }
        });
        return true;
    });
    setPropertyChangeHandler(PROP_ACTIONS, (oldValue, newValue, figure) -> {
        ((TextFigure) figure).setSelectable(determinSelectable());
        return false;
    });
    setPropertyChangeHandler(PROP_TOOLTIP, (oldValue, newValue, figure) -> {
        ((TextFigure) figure).setSelectable(determinSelectable());
        return false;
    });
    IWidgetPropertyChangeHandler handler = (oldValue, newValue, figure) -> {
        Display.getCurrent().timerExec(10, () -> {
            if (getWidgetModel().isAutoSize()) {
                getWidgetModel().setSize(((TextFigure) figure).getAutoSizeDimension());
                figure.revalidate();
            }
        });
        return true;
    };
    setPropertyChangeHandler(PROP_FONT, handler);
    setPropertyChangeHandler(PROP_BORDER_STYLE, handler);
    setPropertyChangeHandler(PROP_BORDER_WIDTH, handler);
    setPropertyChangeHandler(PROP_TRANSPARENT, (oldValue, newValue, figure) -> {
        ((TextFigure) figure).setOpaque(!(Boolean) newValue);
        return true;
    });
    setPropertyChangeHandler(PROP_AUTOSIZE, (oldValue, newValue, figure) -> {
        if ((Boolean) newValue) {
            getWidgetModel().setSize(((TextFigure) figure).getAutoSizeDimension());
            figure.revalidate();
        }
        return true;
    });
    setPropertyChangeHandler(PROP_ALIGN_H, (oldValue, newValue, figure) -> {
        ((TextFigure) figure).setHorizontalAlignment(H_ALIGN.values()[(Integer) newValue]);
        return true;
    });
    setPropertyChangeHandler(PROP_ALIGN_V, (oldValue, newValue, figure) -> {
        ((TextFigure) figure).setVerticalAlignment(V_ALIGN.values()[(Integer) newValue]);
        return true;
    });
    setPropertyChangeHandler(PROP_WRAP_WORDS, (oldValue, newValue, figure) -> {
        AbstractWidgetModel model = getWidgetModel();
        var parent = model.getParent();
        parent.removeChild(model);
        parent.addChild(model);
        parent.selectWidget(model, true);
        return false;
    });
    getWidgetModel().getProperty(PROP_WRAP_WORDS).addPropertyChangeListener(evt -> updatePropertyVisibility());
    setPropertyChangeHandler(PROP_SHOW_SCROLLBAR, (oldValue, newValue, figure) -> {
        if (figure instanceof WrappableTextFigure) {
            ((WrappableTextFigure) figure).setShowScrollbar((Boolean) newValue);
        }
        return false;
    });
}
Also used : WrappableTextFigure(org.csstudio.swt.widgets.figures.WrappableTextFigure) PROP_ALIGN_H(org.csstudio.opibuilder.widgets.model.LabelModel.PROP_ALIGN_H) PROP_TOOLTIP(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_TOOLTIP) AbstractWidgetEditPart(org.csstudio.opibuilder.editparts.AbstractWidgetEditPart) PROP_BORDER_WIDTH(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_BORDER_WIDTH) PROP_ACTIONS(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_ACTIONS) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) RequestConstants(org.eclipse.gef.RequestConstants) IFigure(org.eclipse.draw2d.IFigure) ITextFigure(org.csstudio.swt.widgets.figures.ITextFigure) PROP_ALIGN_V(org.csstudio.opibuilder.widgets.model.LabelModel.PROP_ALIGN_V) Request(org.eclipse.gef.Request) PROP_AUTOSIZE(org.csstudio.opibuilder.widgets.model.LabelModel.PROP_AUTOSIZE) PROP_TEXT(org.csstudio.opibuilder.widgets.model.LabelModel.PROP_TEXT) H_ALIGN(org.csstudio.swt.widgets.figures.TextFigure.H_ALIGN) PROP_WRAP_WORDS(org.csstudio.opibuilder.widgets.model.LabelModel.PROP_WRAP_WORDS) ExecutionMode(org.csstudio.opibuilder.editparts.ExecutionMode) LabelModel(org.csstudio.opibuilder.widgets.model.LabelModel) Display(org.eclipse.swt.widgets.Display) PROP_FONT(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_FONT) TextFigure(org.csstudio.swt.widgets.figures.TextFigure) V_ALIGN(org.csstudio.swt.widgets.figures.TextFigure.V_ALIGN) PROP_SHOW_SCROLLBAR(org.csstudio.opibuilder.widgets.model.LabelModel.PROP_SHOW_SCROLLBAR) PROP_TRANSPARENT(org.csstudio.opibuilder.widgets.model.LabelModel.PROP_TRANSPARENT) EditPolicy(org.eclipse.gef.EditPolicy) PROP_BORDER_STYLE(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_BORDER_STYLE) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) WrappableTextFigure(org.csstudio.swt.widgets.figures.WrappableTextFigure) ITextFigure(org.csstudio.swt.widgets.figures.ITextFigure) TextFigure(org.csstudio.swt.widgets.figures.TextFigure) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) WrappableTextFigure(org.csstudio.swt.widgets.figures.WrappableTextFigure)

Aggregations

ITextFigure (org.csstudio.swt.widgets.figures.ITextFigure)2 TextFigure (org.csstudio.swt.widgets.figures.TextFigure)2 WrappableTextFigure (org.csstudio.swt.widgets.figures.WrappableTextFigure)2 AbstractWidgetEditPart (org.csstudio.opibuilder.editparts.AbstractWidgetEditPart)1 ExecutionMode (org.csstudio.opibuilder.editparts.ExecutionMode)1 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)1 PROP_ACTIONS (org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_ACTIONS)1 PROP_BORDER_STYLE (org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_BORDER_STYLE)1 PROP_BORDER_WIDTH (org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_BORDER_WIDTH)1 PROP_FONT (org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_FONT)1 PROP_TOOLTIP (org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_TOOLTIP)1 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)1 LabelModel (org.csstudio.opibuilder.widgets.model.LabelModel)1 PROP_ALIGN_H (org.csstudio.opibuilder.widgets.model.LabelModel.PROP_ALIGN_H)1 PROP_ALIGN_V (org.csstudio.opibuilder.widgets.model.LabelModel.PROP_ALIGN_V)1 PROP_AUTOSIZE (org.csstudio.opibuilder.widgets.model.LabelModel.PROP_AUTOSIZE)1 PROP_SHOW_SCROLLBAR (org.csstudio.opibuilder.widgets.model.LabelModel.PROP_SHOW_SCROLLBAR)1 PROP_TEXT (org.csstudio.opibuilder.widgets.model.LabelModel.PROP_TEXT)1 PROP_TRANSPARENT (org.csstudio.opibuilder.widgets.model.LabelModel.PROP_TRANSPARENT)1 PROP_WRAP_WORDS (org.csstudio.opibuilder.widgets.model.LabelModel.PROP_WRAP_WORDS)1