Search in sources :

Example 6 with UndoableActionManager

use of org.csstudio.display.builder.util.undo.UndoableActionManager in project org.csstudio.display.builder by kasemir.

the class CreateGroupAction method run.

@Override
public void run() {
    editor.getWidgetSelectionHandler().clear();
    // Create group that surrounds the original widget boundaries
    final GroupWidget group = new GroupWidget();
    // Get bounds of widgets relative to their container,
    // which might be a group within the display
    // or the display itself
    final Rectangle2D rect = GeometryTools.getBounds(widgets);
    // Inset depends on representation and changes with group style and font.
    // Can be obtained via group.runtimePropInsets() _after_ the group has
    // been represented. For this reason Style.NONE is used, where the inset
    // is always 0. An alternative could be Style.LINE, with an inset of 1.
    final int inset = 0;
    group.propStyle().setValue(Style.NONE);
    group.propTransparent().setValue(true);
    group.propX().setValue((int) rect.getMinX() - inset);
    group.propY().setValue((int) rect.getMinY() - inset);
    group.propWidth().setValue((int) rect.getWidth() + 2 * inset);
    group.propHeight().setValue((int) rect.getHeight() + 2 * inset);
    group.propName().setValue(org.csstudio.display.builder.model.Messages.GroupWidget_Name);
    final ChildrenProperty parent_children = ChildrenProperty.getParentsChildren(widgets.get(0));
    final UndoableActionManager undo = editor.getUndoableActionManager();
    undo.execute(new GroupWidgetsAction(parent_children, group, widgets, (int) rect.getMinX(), (int) rect.getMinY()));
    editor.getWidgetSelectionHandler().toggleSelection(group);
}
Also used : ChildrenProperty(org.csstudio.display.builder.model.ChildrenProperty) UndoableActionManager(org.csstudio.display.builder.util.undo.UndoableActionManager) Rectangle2D(javafx.geometry.Rectangle2D) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) GroupWidgetsAction(org.csstudio.display.builder.editor.undo.GroupWidgetsAction)

Example 7 with UndoableActionManager

use of org.csstudio.display.builder.util.undo.UndoableActionManager in project org.csstudio.display.builder by kasemir.

the class ToolbarHandler method addUndo.

private void addUndo(final boolean active) {
    final Button undo = newButton(ToolIcons.UNDO, Messages.Undo_TT);
    final Button redo = newButton(ToolIcons.REDO, Messages.Redo_TT);
    final UndoableActionManager undo_mgr = plot.getUndoableActionManager();
    undo.setDisable(!undo_mgr.canUndo());
    redo.setDisable(!undo_mgr.canRedo());
    if (active) {
        undo.setOnAction(event -> plot.getUndoableActionManager().undoLast());
        redo.setOnAction(event -> plot.getUndoableActionManager().redoLast());
        undo_mgr.addListener((to_undo, to_redo) -> {
            Platform.runLater(() -> {
                if (to_undo == null) {
                    undo.setDisable(true);
                    undo.setTooltip(new Tooltip(Messages.Undo_TT));
                } else {
                    undo.setDisable(false);
                    undo.setTooltip(new Tooltip(NLS.bind(Messages.Undo_Fmt_TT, to_undo)));
                }
                if (to_redo == null) {
                    redo.setDisable(true);
                    redo.setTooltip(new Tooltip(Messages.Redo_TT));
                } else {
                    redo.setDisable(false);
                    redo.setTooltip(new Tooltip(NLS.bind(Messages.Redo_Fmt_TT, to_redo)));
                }
            });
        });
    }
}
Also used : Button(javafx.scene.control.Button) ToggleButton(javafx.scene.control.ToggleButton) UndoableActionManager(org.csstudio.display.builder.util.undo.UndoableActionManager) Tooltip(javafx.scene.control.Tooltip)

Aggregations

UndoableActionManager (org.csstudio.display.builder.util.undo.UndoableActionManager)7 Button (javafx.scene.control.Button)3 ToggleButton (javafx.scene.control.ToggleButton)3 Tooltip (javafx.scene.control.Tooltip)3 Widget (org.csstudio.display.builder.model.Widget)3 ArrayList (java.util.ArrayList)2 GroupWidget (org.csstudio.display.builder.model.widgets.GroupWidget)2 Collection (java.util.Collection)1 List (java.util.List)1 Optional (java.util.Optional)1 Level (java.util.logging.Level)1 ActionEvent (javafx.event.ActionEvent)1 EventHandler (javafx.event.EventHandler)1 HPos (javafx.geometry.HPos)1 Insets (javafx.geometry.Insets)1 Pos (javafx.geometry.Pos)1 Rectangle2D (javafx.geometry.Rectangle2D)1 Node (javafx.scene.Node)1 CheckBox (javafx.scene.control.CheckBox)1 ComboBox (javafx.scene.control.ComboBox)1