use of org.eclipse.draw2d.IFigure in project yamcs-studio by yamcs.
the class ThermometerEditPart method registerPropertyChangeHandlers.
/**
* {@inheritDoc}
*/
@Override
protected void registerPropertyChangeHandlers() {
registerCommonPropertyChangeHandlers();
// fillColor
IWidgetPropertyChangeHandler fillColorHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
ThermometerFigure thermometer = (ThermometerFigure) refreshableFigure;
thermometer.setFillColor(((OPIColor) newValue).getSWTColor());
return false;
}
};
setPropertyChangeHandler(ThermometerModel.PROP_FILL_COLOR, fillColorHandler);
// fillBackgroundColor
IWidgetPropertyChangeHandler fillBackColorHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
ThermometerFigure thermometer = (ThermometerFigure) refreshableFigure;
thermometer.setFillBackgroundColor(((OPIColor) newValue).getSWTColor());
return false;
}
};
setPropertyChangeHandler(ThermometerModel.PROP_FILLBACKGROUND_COLOR, fillBackColorHandler);
// show bulb
IWidgetPropertyChangeHandler showBulbHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
ThermometerFigure thermometer = (ThermometerFigure) refreshableFigure;
thermometer.setShowBulb((Boolean) newValue);
return false;
}
};
setPropertyChangeHandler(ThermometerModel.PROP_SHOW_BULB, showBulbHandler);
// unit
IWidgetPropertyChangeHandler fahrenheitHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
ThermometerFigure thermometer = (ThermometerFigure) refreshableFigure;
thermometer.setTemperatureUnit(TemperatureUnit.values()[(Integer) newValue]);
return false;
}
};
setPropertyChangeHandler(ThermometerModel.PROP_UNIT, fahrenheitHandler);
// effect 3D
IWidgetPropertyChangeHandler effect3DHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
ThermometerFigure thermo = (ThermometerFigure) refreshableFigure;
thermo.setEffect3D((Boolean) newValue);
return false;
}
};
setPropertyChangeHandler(ThermometerModel.PROP_EFFECT3D, effect3DHandler);
// Change fill color when "FillColor Alarm Sensitive" property changes.
IWidgetPropertyChangeHandler fillColorAlarmSensitiveHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure refreshableFigure) {
ThermometerFigure figure = (ThermometerFigure) refreshableFigure;
boolean sensitive = (Boolean) newValue;
figure.setFillColor(delegate.calculateAlarmColor(sensitive, getWidgetModel().getFillColor()));
return true;
}
};
setPropertyChangeHandler(ThermometerModel.PROP_FILLCOLOR_ALARM_SENSITIVE, fillColorAlarmSensitiveHandler);
// Change fill color when alarm severity changes.
delegate.addAlarmSeverityListener(new AlarmSeverityListener() {
@Override
public boolean severityChanged(AlarmSeverity severity, IFigure figure) {
if (!getWidgetModel().isFillColorAlarmSensitive())
return false;
ThermometerFigure thermo = (ThermometerFigure) figure;
thermo.setFillColor(delegate.calculateAlarmColor(getWidgetModel().isFillColorAlarmSensitive(), getWidgetModel().getFillColor()));
return true;
}
});
}
use of org.eclipse.draw2d.IFigure in project yamcs-studio by yamcs.
the class XYGraphEditPart method registerAxesAmountChangeHandler.
private void registerAxesAmountChangeHandler() {
final IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure refreshableFigure) {
XYGraphModel model = (XYGraphModel) getModel();
IXYGraph xyGraph = ((ToolbarArmedXYGraph) refreshableFigure).getXYGraph();
int currentAxisAmount = xyGraph.getAxisList().size();
// add axis
if ((Integer) newValue > currentAxisAmount) {
for (int i = 0; i < (Integer) newValue - currentAxisAmount; i++) {
for (AxisProperty axisProperty : AxisProperty.values()) {
String propID = XYGraphModel.makeAxisPropID(axisProperty.propIDPre, i + currentAxisAmount);
model.setPropertyVisible(propID, true);
}
xyGraph.addAxis(axisList.get(i + currentAxisAmount));
}
} else if ((Integer) newValue < currentAxisAmount) {
// remove axis
for (int i = 0; i < currentAxisAmount - (Integer) newValue; i++) {
for (AxisProperty axisProperty : AxisProperty.values()) {
String propID = XYGraphModel.makeAxisPropID(axisProperty.propIDPre, i + (Integer) newValue);
model.setPropertyVisible(propID, false);
}
xyGraph.removeAxis(axisList.get(i + (Integer) newValue));
}
}
return true;
}
};
getWidgetModel().getProperty(XYGraphModel.PROP_AXIS_COUNT).addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
handler.handleChange(evt.getOldValue(), evt.getNewValue(), getFigure());
}
});
// setPropertyChangeHandler(XYGraphModel.PROP_AXES_AMOUNT, handler);
}
use of org.eclipse.draw2d.IFigure in project yamcs-studio by yamcs.
the class PerformAutoSizeAction method run.
@Override
public void run(IAction action) {
if (getContainerEditpart().getChildren().size() <= 0) {
return;
}
CompoundCommand compoundCommand = new CompoundCommand("Perform AutoSize");
AbstractContainerEditpart containerEditpart = getContainerEditpart();
AbstractContainerModel containerModel = containerEditpart.getWidgetModel();
// temporary unlock children so children will not be resized.
if (containerEditpart instanceof GroupingContainerEditPart) {
compoundCommand.add(new SetWidgetPropertyCommand(containerModel, GroupingContainerModel.PROP_LOCK_CHILDREN, false));
}
IFigure figure = getContainerFigure();
Rectangle childrenRange = GeometryUtil.getChildrenRange(containerEditpart);
Point tranlateSize = new Point(childrenRange.x, childrenRange.y);
compoundCommand.add(new SetBoundsCommand(containerModel, new Rectangle(containerModel.getLocation().translate(tranlateSize), new Dimension(childrenRange.width + figure.getInsets().left + figure.getInsets().right, childrenRange.height + figure.getInsets().top + figure.getInsets().bottom))));
for (Object editpart : containerEditpart.getChildren()) {
AbstractWidgetModel widget = ((AbstractBaseEditPart) editpart).getWidgetModel();
compoundCommand.add(new SetBoundsCommand(widget, new Rectangle(widget.getLocation().translate(tranlateSize.getNegated()), widget.getSize())));
}
// recover lock
if (containerEditpart instanceof GroupingContainerEditPart) {
Object oldvalue = containerEditpart.getWidgetModel().getPropertyValue(GroupingContainerModel.PROP_LOCK_CHILDREN);
compoundCommand.add(new SetWidgetPropertyCommand(containerModel, GroupingContainerModel.PROP_LOCK_CHILDREN, oldvalue));
}
execute(compoundCommand);
}
use of org.eclipse.draw2d.IFigure in project yamcs-studio by yamcs.
the class AbstractBoolControlEditPart method registerCommonPropertyChangeHandlers.
/**
* Registers property change handlers for the properties defined in
* {@link AbstractBoolWidgetModel}. This method is provided for the convenience
* of subclasses, which can call this method in their implementation of
* {@link #registerPropertyChangeHandlers()}.
*/
@Override
protected void registerCommonPropertyChangeHandlers() {
configureButtonListener((AbstractBoolControlFigure) getFigure());
super.registerCommonPropertyChangeHandlers();
// toggle button
final IWidgetPropertyChangeHandler toggleHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
AbstractBoolControlFigure figure = (AbstractBoolControlFigure) refreshableFigure;
figure.setToggle((Boolean) newValue);
return true;
}
};
getWidgetModel().getProperty(AbstractBoolControlModel.PROP_TOGGLE_BUTTON).addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
toggleHandler.handleChange(evt.getOldValue(), evt.getNewValue(), getFigure());
}
});
// setPropertyChangeHandler(AbstractBoolControlModel.PROP_TOGGLE_BUTTON, handler);
// show confirm dialog
IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
AbstractBoolControlFigure figure = (AbstractBoolControlFigure) refreshableFigure;
figure.setShowConfirmDialog(getWidgetModel().getShowConfirmDialog());
return true;
}
};
setPropertyChangeHandler(AbstractBoolControlModel.PROP_CONFIRM_DIALOG, handler);
// confirm tip
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
AbstractBoolControlFigure figure = (AbstractBoolControlFigure) refreshableFigure;
figure.setConfirmTip((String) newValue);
return true;
}
};
setPropertyChangeHandler(AbstractBoolControlModel.PROP_CONFIRM_TIP, handler);
// password
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
AbstractBoolControlFigure figure = (AbstractBoolControlFigure) refreshableFigure;
figure.setPassword((String) newValue);
return true;
}
};
setPropertyChangeHandler(AbstractBoolControlModel.PROP_PASSWORD, handler);
// enabled. WidgetBaseEditPart will force the widget as disabled in edit model,
// which is not the case for the bool control widget
IWidgetPropertyChangeHandler enableHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
AbstractBoolControlFigure figure = (AbstractBoolControlFigure) refreshableFigure;
figure.setEnabled((Boolean) newValue);
return true;
}
};
setPropertyChangeHandler(AbstractBoolControlModel.PROP_ENABLED, enableHandler);
}
use of org.eclipse.draw2d.IFigure in project yamcs-studio by yamcs.
the class AbstractPolyEditPart method registerPropertyChangeHandlers.
/**
* {@inheritDoc}
*/
@Override
protected void registerPropertyChangeHandlers() {
super.registerPropertyChangeHandlers();
// points
IWidgetPropertyChangeHandler pointsHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
Polyline polyline = (Polyline) refreshableFigure;
PointList points = (PointList) newValue;
if (points.size() != polyline.getPoints().size()) {
anchorMap = null;
// delete connections on deleted points
if (points.size() < polyline.getPoints().size()) {
for (ConnectionModel conn : getWidgetModel().getSourceConnections()) {
if (Integer.parseInt(conn.getSourceTerminal()) >= points.size()) {
conn.disconnect();
}
}
for (ConnectionModel conn : getWidgetModel().getTargetConnections()) {
if (Integer.parseInt(conn.getTargetTerminal()) >= points.size()) {
conn.disconnect();
}
}
}
}
// deselect the widget (this refreshes the polypoint drag
// handles)
int selectionState = getSelected();
setSelected(EditPart.SELECTED_NONE);
polyline.setPoints(points);
doRefreshVisuals(polyline);
// restore the selection state
setSelected(selectionState);
return false;
}
};
setPropertyChangeHandler(AbstractPolyModel.PROP_POINTS, pointsHandler);
IWidgetPropertyChangeHandler rotationHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
getWidgetModel().setPoints(PointsUtil.rotatePoints(getWidgetModel().getOriginalPoints().getCopy(), (Double) newValue), false);
return false;
}
};
setPropertyChangeHandler(AbstractPolyModel.PROP_ROTATION, rotationHandler);
}
Aggregations