use of org.csstudio.swt.widgets.figures.ActionButtonFigure in project yamcs-studio by yamcs.
the class Draw2DButtonEditPartDelegate method doCreateFigure.
/* (non-Javadoc)
* @see org.csstudio.opibuilder.widgets.editparts.IButtonEditPartDelegate#doCreateFigure()
*/
@Override
public IFigure doCreateFigure() {
ActionButtonModel model = editpart.getWidgetModel();
final ActionButtonFigure buttonFigure = new ActionButtonFigure(editpart.getExecutionMode() == ExecutionMode.RUN_MODE);
buttonFigure.setText(model.getText());
buttonFigure.setToggleStyle(model.isToggleButton());
buttonFigure.setImagePath(model.getImagePath());
editpart.updatePropSheet();
return buttonFigure;
}
use of org.csstudio.swt.widgets.figures.ActionButtonFigure in project yamcs-studio by yamcs.
the class Draw2DButtonEditPartDelegate method registerPropertyChangeHandlers.
/* (non-Javadoc)
* @see org.csstudio.opibuilder.widgets.editparts.IButtonEditPartDelegate#registerPropertyChangeHandlers()
*/
@Override
public void registerPropertyChangeHandlers() {
// text
IWidgetPropertyChangeHandler textHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
ActionButtonFigure figure = (ActionButtonFigure) refreshableFigure;
figure.setText(newValue.toString());
figure.calculateTextPosition();
return true;
}
};
editpart.setPropertyChangeHandler(ActionButtonModel.PROP_TEXT, textHandler);
// image
IWidgetPropertyChangeHandler imageHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
ActionButtonFigure figure = (ActionButtonFigure) refreshableFigure;
IPath absolutePath = (IPath) newValue;
if (absolutePath != null && !absolutePath.isEmpty() && !absolutePath.isAbsolute())
absolutePath = ResourceUtil.buildAbsolutePath(editpart.getWidgetModel(), absolutePath);
figure.setImagePath(absolutePath);
return true;
}
};
editpart.setPropertyChangeHandler(ActionButtonModel.PROP_IMAGE, imageHandler);
// width
IWidgetPropertyChangeHandler widthHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
ActionButtonFigure figure = (ActionButtonFigure) refreshableFigure;
Integer height = (Integer) editpart.getPropertyValue(ActionButtonModel.PROP_HEIGHT);
figure.calculateTextPosition((Integer) newValue, height);
return true;
}
};
editpart.setPropertyChangeHandler(ActionButtonModel.PROP_WIDTH, widthHandler);
// height
IWidgetPropertyChangeHandler heightHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
ActionButtonFigure figure = (ActionButtonFigure) refreshableFigure;
Integer width = (Integer) editpart.getPropertyValue(ActionButtonModel.PROP_WIDTH);
figure.calculateTextPosition(width, (Integer) newValue);
return true;
}
};
editpart.setPropertyChangeHandler(ActionButtonModel.PROP_HEIGHT, heightHandler);
// button style
final IWidgetPropertyChangeHandler buttonStyleHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
ActionButtonFigure figure = (ActionButtonFigure) refreshableFigure;
figure.setToggleStyle((Boolean) newValue);
editpart.updatePropSheet();
return true;
}
};
editpart.getWidgetModel().getProperty(ActionButtonModel.PROP_TOGGLE_BUTTON).addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
buttonStyleHandler.handleChange(evt.getOldValue(), evt.getNewValue(), editpart.getFigure());
}
});
}
use of org.csstudio.swt.widgets.figures.ActionButtonFigure in project yamcs-studio by yamcs.
the class Draw2DButtonEditPartDelegate method hookMouseClickAction.
/* (non-Javadoc)
* @see org.csstudio.opibuilder.widgets.editparts.IButtonEditPartDelegate#hookMouseClickAction()
*/
@Override
public void hookMouseClickAction() {
((ActionButtonFigure) editpart.getFigure()).addActionListener(new ButtonActionListener() {
@Override
public void actionPerformed(int mouseEventState) {
List<AbstractWidgetAction> actions = editpart.getHookedActions();
if (actions != null) {
for (AbstractWidgetAction action : actions) {
if (action instanceof OpenDisplayAction)
((OpenDisplayAction) action).runWithModifiers((mouseEventState & SWT.CONTROL) != 0, (mouseEventState & SWT.SHIFT) != 0);
else
action.run();
}
}
}
});
}
Aggregations