use of org.csstudio.swt.widgets.figures.ArrayFigure in project yamcs-studio by yamcs.
the class ArrayEditPart method registerPropertyChangeHandlers.
@Override
protected void registerPropertyChangeHandlers() {
IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
for (AbstractWidgetModel child : getWidgetModel().getAllChildren()) {
child.setEnabled((Boolean) newValue);
}
return true;
}
};
setPropertyChangeHandler(AbstractWidgetModel.PROP_ENABLED, handler);
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
VType value = (VType) newValue;
if (value instanceof VNumberArray) {
Object wrappedArray = VTypeHelper.getWrappedArray(((VNumberArray) value));
if (wrappedArray != null)
setValue(wrappedArray);
else
setValue(VTypeHelper.getDoubleArray(value));
} else {
if (value instanceof VEnum)
setValue(new String[] { ((VEnum) value).getValue() });
else if (value instanceof VString)
setValue(new String[] { ((VString) value).getValue() });
else if (value instanceof VStringArray)
setValue(((VStringArray) value).getData().toArray());
else
setValue(VTypeHelper.getDoubleArray(value));
}
return false;
}
};
setPropertyChangeHandler(ArrayModel.PROP_PVVALUE, handler);
getWidgetModel().getProperty(ArrayModel.PROP_PVNAME).addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
updatePropSheet();
}
});
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
registerLoadPVDataTypeListener();
return false;
}
};
setPropertyChangeHandler(ArrayModel.PROP_PVNAME, handler);
getWidgetModel().getProperty(ArrayModel.PROP_DATA_TYPE).addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
initValueArray();
}
});
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
updateWidgetSize();
return false;
}
};
setPropertyChangeHandler(ArrayModel.PROP_BORDER_STYLE, handler);
setPropertyChangeHandler(ArrayModel.PROP_BORDER_WIDTH, handler);
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
getArrayFigure().setArrayLength((Integer) newValue);
return false;
}
};
setPropertyChangeHandler(ArrayModel.PROP_ARRAY_LENGTH, handler);
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
((ArrayFigure) figure).setSpinnerWidth((Integer) newValue);
keepElementSize = true;
getWidgetModel().setSize(((ArrayFigure) figure).getPreferredSize());
keepElementSize = false;
return false;
}
};
setPropertyChangeHandler(ArrayModel.PROP_SPINNER_WIDTH, handler);
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
((ArrayFigure) figure).setHorizontal((Boolean) newValue);
keepElementSize = true;
getWidgetModel().setSize(((ArrayFigure) figure).getPreferredSize());
keepElementSize = false;
return false;
}
};
setPropertyChangeHandler(ArrayModel.PROP_HORIZONTAL, handler);
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
((ArrayFigure) figure).setShowScrollbar((Boolean) newValue);
keepElementSize = true;
getWidgetModel().setSize(((ArrayFigure) figure).getPreferredSize());
keepElementSize = false;
return false;
}
};
setPropertyChangeHandler(ArrayModel.PROP_SHOW_SCROLLBAR, handler);
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
((ArrayFigure) figure).setShowSpinner((Boolean) newValue);
keepElementSize = true;
getWidgetModel().setSize(((ArrayFigure) figure).getPreferredSize());
keepElementSize = false;
return false;
}
};
setPropertyChangeHandler(ArrayModel.PROP_SHOW_SPINNER, handler);
PropertyChangeListener sizePropertyChangeListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (getWidgetModel().getChildren().size() == 0 || inSync || keepElementSize)
return;
Dimension elementSize = getArrayFigure().getElementSize();
int delta = (Integer) evt.getNewValue() - (Integer) evt.getOldValue();
int elementWH = elementSize.height;
String propID = evt.getPropertyName();
boolean elementCountDirection = false;
if (getWidgetModel().isHorizontal() && propID.equals(AbstractWidgetModel.PROP_WIDTH)) {
elementWH = elementSize.width;
elementCountDirection = true;
} else if (!getWidgetModel().isHorizontal() && propID.equals(AbstractWidgetModel.PROP_HEIGHT)) {
elementWH = elementSize.height;
elementCountDirection = true;
}
if (elementCountDirection) {
int deltaElementsCount = Math.round((float) delta / elementWH);
int idelta = (Math.round((float) delta / elementWH) * elementWH);
setPropertyValue(propID, (Integer) evt.getOldValue() + idelta, false);
int visibleElementsCount = getArrayFigure().getVisibleElementsCount() + deltaElementsCount;
setPropertyValue(ArrayModel.PROP_VISIBLE_ELEMENTS_COUNT, visibleElementsCount);
setValue(getValue());
} else {
int wh;
if (propID.equals(AbstractWidgetModel.PROP_WIDTH))
wh = getArrayFigure().getElementSize().width;
else
wh = getArrayFigure().getElementSize().height;
syncAllChildrenProperties(propID, wh + delta);
}
}
};
getWidgetModel().getProperty(AbstractWidgetModel.PROP_WIDTH).addPropertyChangeListener(sizePropertyChangeListener);
getWidgetModel().getProperty(AbstractWidgetModel.PROP_HEIGHT).addPropertyChangeListener(sizePropertyChangeListener);
}
use of org.csstudio.swt.widgets.figures.ArrayFigure in project yamcs-studio by yamcs.
the class ArrayEditPart method doCreateFigure.
@Override
protected IFigure doCreateFigure() {
ArrayFigure figure = new ArrayFigure();
ArrayModel model = getWidgetModel();
figure.setArrayLength(model.getArrayLength());
figure.setHorizontal(model.isHorizontal());
figure.setSpinnerWidth(model.getSpinnerWidth());
figure.setShowSpinner(model.isShowSpinner());
figure.setShowScrollbar(model.isShowScrollbar());
figure.setIndex(0);
figure.addIndexChangeListener(new IManualValueChangeListener() {
@Override
public void manualValueChanged(double newValue) {
setValue(getValue());
}
});
updatePropSheet();
return figure;
}
Aggregations