Search in sources :

Example 1 with WidgetScaleData

use of org.csstudio.opibuilder.datadefinition.WidgetScaleData in project yamcs-studio by yamcs.

the class AbstractWidgetModel method configureBaseProperties.

protected void configureBaseProperties() {
    addProperty(new IntegerProperty(PROP_WIDTH, "Width", WidgetPropertyCategory.Position, 100, 1, 10000));
    addProperty(new IntegerProperty(PROP_HEIGHT, "Height", WidgetPropertyCategory.Position, 100, 1, 10000));
    addProperty(new IntegerProperty(PROP_XPOS, "X", WidgetPropertyCategory.Position, 0));
    addProperty(new IntegerProperty(PROP_YPOS, "Y", WidgetPropertyCategory.Position, 0));
    addProperty(new ColorProperty(PROP_COLOR_BACKGROUND, "Background Color", WidgetPropertyCategory.Display, new RGB(240, 240, 240)));
    addProperty(new ColorProperty(PROP_COLOR_FOREGROUND, "Foreground Color", WidgetPropertyCategory.Display, new RGB(192, 192, 192)));
    addProperty(new FontProperty(PROP_FONT, "Font", WidgetPropertyCategory.Display, MediaService.DEFAULT_FONT));
    addProperty(new ColorProperty(PROP_BORDER_COLOR, "Border Color", WidgetPropertyCategory.Border, new RGB(0, 128, 255)));
    addProperty(new ComboProperty(PROP_BORDER_STYLE, "Border Style", WidgetPropertyCategory.Border, BorderStyle.stringValues(), 0));
    addProperty(new IntegerProperty(PROP_BORDER_WIDTH, "Border Width", WidgetPropertyCategory.Border, 1, 0, 1000));
    addProperty(new BooleanProperty(PROP_ENABLED, "Enabled", WidgetPropertyCategory.Behavior, true));
    addProperty(new BooleanProperty(PROP_VISIBLE, "Visible", WidgetPropertyCategory.Behavior, true));
    addProperty(new ScriptProperty(PROP_SCRIPTS, "Scripts", WidgetPropertyCategory.Behavior));
    addProperty(new ActionsProperty(PROP_ACTIONS, "Actions", WidgetPropertyCategory.Behavior));
    addProperty(new StringProperty(PROP_TOOLTIP, "Tooltip", WidgetPropertyCategory.Display, "", true));
    addProperty(new RulesProperty(PROP_RULES, "Rules", WidgetPropertyCategory.Behavior));
    addProperty(new ComplexDataProperty(PROP_SCALE_OPTIONS, "Scale Options", WidgetPropertyCategory.Position, new WidgetScaleData(this, true, true, false), "Set Scale Options"));
    addProperty(new StringProperty(PROP_WIDGET_UID, "Widget UID", WidgetPropertyCategory.Basic, new UID().toString()));
    // update the WUID saved in connections without triggering anything
    getProperty(PROP_WIDGET_UID).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            for (ConnectionModel connection : sourceConnections) {
                connection.setPropertyValue(ConnectionModel.PROP_SRC_WUID, evt.getNewValue(), false);
            }
            for (ConnectionModel connection : targetConnections) {
                connection.setPropertyValue(ConnectionModel.PROP_TGT_WUID, evt.getNewValue(), false);
            }
        }
    });
    setPropertyVisibleAndSavable(PROP_WIDGET_UID, false, true);
    WidgetDescriptor descriptor = WidgetsService.getInstance().getWidgetDescriptor(getTypeID());
    String name;
    name = descriptor == null ? getTypeID().substring(getTypeID().lastIndexOf(".") + 1) : descriptor.getName();
    addProperty(new StringProperty(PROP_NAME, "Name", WidgetPropertyCategory.Basic, name));
    addProperty(new UnchangableStringProperty(PROP_WIDGET_TYPE, "Widget Type", WidgetPropertyCategory.Basic, name));
    addProperty(new UnsavableListProperty(PROP_SRC_CONNECTIONS, "Source Connections", WidgetPropertyCategory.Display, sourceConnections));
    setPropertyVisible(PROP_SRC_CONNECTIONS, false);
    addProperty(new UnsavableListProperty(PROP_TGT_CONNECTIONS, "Target Connections", WidgetPropertyCategory.Display, targetConnections));
    setPropertyVisible(PROP_TGT_CONNECTIONS, false);
}
Also used : ComboProperty(org.csstudio.opibuilder.properties.ComboProperty) IntegerProperty(org.csstudio.opibuilder.properties.IntegerProperty) ComplexDataProperty(org.csstudio.opibuilder.properties.ComplexDataProperty) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) BooleanProperty(org.csstudio.opibuilder.properties.BooleanProperty) ActionsProperty(org.csstudio.opibuilder.properties.ActionsProperty) UnchangableStringProperty(org.csstudio.opibuilder.properties.UnchangableStringProperty) ScriptProperty(org.csstudio.opibuilder.properties.ScriptProperty) StringProperty(org.csstudio.opibuilder.properties.StringProperty) UnchangableStringProperty(org.csstudio.opibuilder.properties.UnchangableStringProperty) WidgetDescriptor(org.csstudio.opibuilder.util.WidgetDescriptor) RGB(org.eclipse.swt.graphics.RGB) RulesProperty(org.csstudio.opibuilder.properties.RulesProperty) FontProperty(org.csstudio.opibuilder.properties.FontProperty) UID(java.rmi.server.UID) UnsavableListProperty(org.csstudio.opibuilder.properties.UnsavableListProperty) ColorProperty(org.csstudio.opibuilder.properties.ColorProperty) WidgetScaleData(org.csstudio.opibuilder.datadefinition.WidgetScaleData)

Example 2 with WidgetScaleData

use of org.csstudio.opibuilder.datadefinition.WidgetScaleData in project yamcs-studio by yamcs.

the class AbstractPolyModel method doScale.

@Override
protected void doScale(double widthRatio, double heightRatio) {
    if (initialPoints == null) {
        initialPoints = getPoints();
    }
    PointList pl = initialPoints.getCopy();
    Point initLoc = pl.getBounds().getLocation();
    pl.translate((int) Math.round(initLoc.x * widthRatio) - initLoc.x, (int) Math.round(initLoc.y * heightRatio) - initLoc.y);
    WidgetScaleData scaleOptions = getScaleOptions();
    if (scaleOptions.isKeepWHRatio() && scaleOptions.isHeightScalable() && scaleOptions.isWidthScalable()) {
        widthRatio = Math.min(widthRatio, heightRatio);
        heightRatio = widthRatio;
    } else if (!scaleOptions.isHeightScalable())
        heightRatio = 1;
    else if (!scaleOptions.isWidthScalable())
        widthRatio = 1;
    PointsUtil.scalePoints(pl, widthRatio, heightRatio);
    setPoints(pl, true);
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Point(org.eclipse.draw2d.geometry.Point) WidgetScaleData(org.csstudio.opibuilder.datadefinition.WidgetScaleData)

Example 3 with WidgetScaleData

use of org.csstudio.opibuilder.datadefinition.WidgetScaleData in project yamcs-studio by yamcs.

the class AbstractWidgetModel method getScaledSize.

/**
 *Get the widget size after scaled.
 * @param widthRatio Ratio of width change.
 * @param heightRatio Ratio of height change.
 * @return the new size.
 */
protected Dimension getScaledSize(double widthRatio, double heightRatio) {
    WidgetScaleData scaleOptions = getScaleOptions();
    int newW = originSize.width, newH = originSize.height;
    if (scaleOptions.isKeepWHRatio() && scaleOptions.isHeightScalable() && scaleOptions.isWidthScalable()) {
        if (widthRatio <= heightRatio) {
            newW = (int) Math.round(originSize.width * widthRatio);
            newH = originSize.height * newW / originSize.width;
        } else {
            newH = (int) Math.round(originSize.height * heightRatio);
            newW = originSize.width * newH / originSize.height;
        }
    } else {
        if (scaleOptions.isHeightScalable()) {
            newH = (int) Math.round(originSize.height * heightRatio);
        }
        if (scaleOptions.isWidthScalable()) {
            newW = (int) Math.round(originSize.width * widthRatio);
        }
    }
    return new Dimension(newW, newH);
}
Also used : Dimension(org.eclipse.draw2d.geometry.Dimension) WidgetScaleData(org.csstudio.opibuilder.datadefinition.WidgetScaleData) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

WidgetScaleData (org.csstudio.opibuilder.datadefinition.WidgetScaleData)3 Point (org.eclipse.draw2d.geometry.Point)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 UID (java.rmi.server.UID)1 ActionsProperty (org.csstudio.opibuilder.properties.ActionsProperty)1 BooleanProperty (org.csstudio.opibuilder.properties.BooleanProperty)1 ColorProperty (org.csstudio.opibuilder.properties.ColorProperty)1 ComboProperty (org.csstudio.opibuilder.properties.ComboProperty)1 ComplexDataProperty (org.csstudio.opibuilder.properties.ComplexDataProperty)1 FontProperty (org.csstudio.opibuilder.properties.FontProperty)1 IntegerProperty (org.csstudio.opibuilder.properties.IntegerProperty)1 RulesProperty (org.csstudio.opibuilder.properties.RulesProperty)1 ScriptProperty (org.csstudio.opibuilder.properties.ScriptProperty)1 StringProperty (org.csstudio.opibuilder.properties.StringProperty)1 UnchangableStringProperty (org.csstudio.opibuilder.properties.UnchangableStringProperty)1 UnsavableListProperty (org.csstudio.opibuilder.properties.UnsavableListProperty)1 WidgetDescriptor (org.csstudio.opibuilder.util.WidgetDescriptor)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 PointList (org.eclipse.draw2d.geometry.PointList)1