use of org.csstudio.display.builder.editor.undo.AddWidgetAction in project org.csstudio.display.builder by kasemir.
the class DisplayEditor method createWidget.
/**
* @param region Requested location and size of the new widget
* @param desc Description for widget to create
*/
private void createWidget(final Rectangle2D region, final WidgetDescriptor desc) {
// Create widget of that type
final Widget widget = desc.createWidget();
// Size to rubberbanded region, optionally constrained by grid
final Point2D location = selection_tracker.gridConstrain(region.getMinX(), region.getMinY());
widget.propX().setValue((int) location.getX());
widget.propY().setValue((int) location.getY());
final Point2D size = selection_tracker.gridConstrain(region.getWidth(), region.getHeight());
widget.propWidth().setValue((int) size.getX());
widget.propHeight().setValue((int) size.getY());
// Add to model
final ChildrenProperty target = model.runtimeChildren();
widget_naming.setDefaultName(model, widget);
undo.execute(new AddWidgetAction(selection, target, widget));
// De-activate the palette, so rubberband will from now on select widgets
palette.clearSelectedWidgetType();
// Select the new widget
selection.setSelection(Arrays.asList(widget));
}
use of org.csstudio.display.builder.editor.undo.AddWidgetAction in project org.csstudio.display.builder by kasemir.
the class DisplayEditor method addWidgets.
/**
* @param widgets Widgets to be added to existing model
*/
private void addWidgets(final List<Widget> widgets) {
// Dropped into a sub-group or the main display?
ChildrenProperty target = group_handler.getActiveParentChildren();
if (target == null)
target = model.runtimeChildren();
Widget container = target.getWidget();
// Correct all dropped widget locations relative to container
Point2D offset = GeometryTools.getContainerOffset(container);
// Also account for scroll pane
Point2D origin = JFXGeometryTools.getContentOrigin(model_root);
int dx = (int) (offset.getX() - origin.getX());
int dy = (int) (offset.getY() - origin.getY());
// Add dropped widgets
try {
final ListIterator<Widget> it = widgets.listIterator();
if (container instanceof ArrayWidget) {
if (target.getValue().isEmpty()) {
// Drop first widget into ArrayWidget
Widget widget = it.next();
widget.propX().setValue(widget.propX().getValue() - dx);
widget.propY().setValue(widget.propY().getValue() - dy);
widget_naming.setDefaultName(container.getDisplayModel(), widget);
undo.execute(new AddWidgetAction(selection, target, widget));
}
// Hide highlight, since not adding to ArrayWidget container
if (it.hasNext())
group_handler.hide();
// Re-assign target, container, etc. to use ArrayWidget's parent
target = ChildrenProperty.getParentsChildren(container);
container = target.getWidget();
offset = GeometryTools.getContainerOffset(container);
origin = JFXGeometryTools.getContentOrigin(model_root);
dx = (int) (offset.getX() - origin.getX());
dy = (int) (offset.getY() - origin.getY());
}
while (it.hasNext()) {
Widget widget = it.next();
widget.propX().setValue(widget.propX().getValue() - dx);
widget.propY().setValue(widget.propY().getValue() - dy);
widget_naming.setDefaultName(container.getDisplayModel(), widget);
undo.execute(new AddWidgetAction(selection, target, widget));
}
selection.setSelection(widgets);
} catch (Exception ex) {
logger.log(Level.SEVERE, "Cannot add widgets", ex);
}
}
Aggregations