Java Code Examples for org.netbeans.api.visual.action.WidgetAction#Chain

The following examples show how to use org.netbeans.api.visual.action.WidgetAction#Chain . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SceneComponent.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private WidgetAction.State processOperator (Operator operator, WidgetAction.WidgetEvent event) {
    WidgetAction.State state;
    String tool = scene.getActiveTool ();

    WidgetAction.Chain priorActions = scene.getPriorActions ();
    if (! priorActions.getActions ().isEmpty ())
        if (operator.operate (priorActions, scene, event).isConsumed ())
            return WidgetAction.State.CONSUMED;

    if (lockedAction != null) {
        state = operator.operate (lockedAction, lockedWidget, event);
        if (! state.isConsumed ())
            state = processOperator (operator, tool, scene, event);
    } else
        state = processOperator (operator, tool, scene, event);

    lockedWidget = state.getLockedWidget ();
    lockedAction = state.getLockedAction ();
    scene.validate ();

    if (lockedWidget != null)
        scrollRectToVisible (scene.convertSceneToView (lockedWidget.convertLocalToScene (lockedWidget.getBounds ())));

    return state;
}
 
Example 2
Source File: SceneComponent.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private WidgetAction.State processSingleOperator (Operator operator, String tool, Widget widget, WidgetAction.WidgetEvent event) {
    WidgetAction.State state;

    state = operator.operate (widget.getActions (), widget, event);
    if (state.isConsumed ())
        return state;

    WidgetAction.Chain actions = widget.getActions (tool);
    if (actions != null) {
        state = operator.operate (actions, widget, event);
        if (state.isConsumed ())
            return state;
    }

    return WidgetAction.State.REJECTED;
}
 
Example 3
Source File: SceneComponent.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private WidgetAction.State processParentOperator (Operator operator, String tool, Widget widget, WidgetAction.WidgetKeyEvent event) {
    while (widget != null) {
        WidgetAction.State state;

        state = operator.operate (widget.getActions (), widget, event);
        if (state.isConsumed ())
            return state;

        WidgetAction.Chain actions = widget.getActions (tool);
        if (actions != null) {
            state = operator.operate (actions, widget, event);
            if (state.isConsumed ())
                return state;
        }

        widget = widget.getParentWidget ();
    }

    return WidgetAction.State.REJECTED;
}
 
Example 4
Source File: SceneComponent.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private WidgetAction.State processKeyOperator (Operator operator, WidgetAction.WidgetKeyEvent event) {
    WidgetAction.State state;
    String tool = scene.getActiveTool ();

    WidgetAction.Chain priorActions = scene.getPriorActions ();
    if (! priorActions.getActions ().isEmpty ())
        if (operator.operate (priorActions, scene, event).isConsumed ())
            return WidgetAction.State.CONSUMED;

    if (lockedAction != null) {
        state = operator.operate (lockedAction, lockedWidget, event);
        if (! state.isConsumed ())
            state = processKeyOperator (operator, tool, scene, event);
    } else
        state = processKeyOperator (operator, tool, scene, event);

    lockedWidget = state.getLockedWidget ();
    lockedAction = state.getLockedAction ();
    scene.validate ();

    if (lockedWidget != null)
        scrollRectToVisible (scene.convertSceneToView (lockedWidget.convertLocalToScene (lockedWidget.getBounds ())));

    return state;
}
 
Example 5
Source File: SceneComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private WidgetAction.State processOperator (Operator operator, String tool, Widget widget, WidgetAction.WidgetEvent event) {
    if (! widget.isVisible ()  ||  ! widget.isEnabled ())
        return WidgetAction.State.REJECTED;

    WidgetAction.State state;

    List<Widget> children = widget.getChildren ();
    Widget[] childrenArray = children.toArray (new Widget[children.size ()]);

    for (int i = childrenArray.length - 1; i >= 0; i --) {
        Widget child = childrenArray[i];
        state = processOperator (operator, tool, child, event);
        if (state.isConsumed ())
            return state;
    }

    state = operator.operate (widget.getActions (), widget, event);
    if (state.isConsumed ())
        return state;

    WidgetAction.Chain actions = widget.getActions (tool);
    if (actions != null) {
        state = operator.operate (actions, widget, event);
        if (state.isConsumed ())
            return state;
    }

    return WidgetAction.State.REJECTED;
}
 
Example 6
Source File: Widget.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new widget which will be used in a specified scene.
 * @param scene the scene where the widget is going to be used
 */
public Widget (Scene scene) {
    if (scene == null)
        scene = (Scene) this;
    this.scene = scene;
    children = new ArrayList<Widget> ();
    childrenUm = Collections.unmodifiableList (children);

    actionsChain = new WidgetAction.Chain ();

    opaque = false;
    font = null;
    background = (new DefaultLookFeel()).getBackground();//Color.WHITE;
    foreground = (new DefaultLookFeel()).getForeground();//Color.BLACK;
    border = BorderFactory.createEmptyBorder ();
    layout = LayoutFactory.createAbsoluteLayout ();
    preferredLocation = null;
    preferredBounds = null;
    checkClipping = false;
    enabled = true;

    location = new Point ();
    bounds = null;
    calculatedPreferredBounds = null;
    requiresFullValidation = true;
    requiresPartValidation = true;
}
 
Example 7
Source File: Widget.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and returns an action chain for a specified tool.
 * @param tool the tool
 * @return the action chain
 */
public final WidgetAction.Chain createActions (String tool) {
    if (tool == null)
        return actionsChain;
    if (toolsActions == EMPTY_HASH_MAP) {
        toolsActions = new HashMap<String, WidgetAction.Chain> ();
        toolsActions.put (null, actionsChain);
    }
    WidgetAction.Chain chain = toolsActions.get (tool);
    if (chain == null) {
        chain = new WidgetAction.Chain ();
        toolsActions.put (tool, chain);
    }
    return chain;
}
 
Example 8
Source File: ForwardKeyEventsAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public State keyTyped (Widget widget, WidgetKeyEvent event) {
    WidgetAction.Chain actions = forwardedToTool != null ? widget.getActions (forwardedToTool) : widget.getActions ();
    return actions != null ? actions.keyTyped (forwardToWidget, event) : State.REJECTED;
}
 
Example 9
Source File: ForwardKeyEventsAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public State keyPressed (Widget widget, WidgetKeyEvent event) {
    WidgetAction.Chain actions = forwardedToTool != null ? widget.getActions (forwardedToTool) : widget.getActions ();
    return actions != null ? actions.keyPressed (forwardToWidget, event) : State.REJECTED;
}
 
Example 10
Source File: ForwardKeyEventsAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public State keyReleased (Widget widget, WidgetKeyEvent event) {
    WidgetAction.Chain actions = forwardedToTool != null ? widget.getActions (forwardedToTool) : widget.getActions ();
    return actions != null ? actions.keyReleased (forwardToWidget, event) : State.REJECTED;
}
 
Example 11
Source File: SceneComponent.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private WidgetAction.State processLocationOperator (Operator operator, WidgetAction.WidgetLocationEvent event) {
    Point oldSceneLocation = scene.getLocation ();
    Rectangle oldVisibleRect = getVisibleRect ();
    Point viewPoint = event.getPoint ();
    Point oldScenePoint = scene.convertViewToScene (viewPoint);
    event.setPoint (new Point (oldScenePoint));

    WidgetAction.State state;
    Point location;
    String tool = scene.getActiveTool ();

    WidgetAction.Chain priorActions = scene.getPriorActions ();
    if (! priorActions.getActions ().isEmpty ()) {
        location = scene.getLocation ();
        event.translatePoint (location.x, location.y);
        if (operator.operate (priorActions, scene, event).isConsumed ())
            return WidgetAction.State.CONSUMED;
        event.translatePoint (- location.x, - location.y);
    }

    if (lockedAction != null) {
        location = lockedWidget.convertSceneToLocal (new Point ());
        event.translatePoint (location.x, location.y);
        state = operator.operate (lockedAction, lockedWidget, event);
        event.translatePoint (- location.x, - location.y);

        if (! state.isConsumed ()) {
            location = scene.getLocation ();
            event.translatePoint (location.x, location.y);
            state = processLocationOperator (operator, tool, scene, event);
        }
    } else {
        location = scene.getLocation ();
        event.translatePoint (location.x, location.y);
        state = processLocationOperator (operator, tool, scene, event);
    }

    lockedWidget = state.getLockedWidget ();
    lockedAction = state.getLockedAction ();
    scene.validate ();

    if (lockedAction != null) {
        Point sceneLocation = scene.getLocation ();
        Rectangle visibleRect = getVisibleRect ();
        int xadd = (int) ((sceneLocation.x - oldSceneLocation.x) * scene.getZoomFactor ());
        int yadd = (int) ((sceneLocation.y - oldSceneLocation.y) * scene.getZoomFactor ());
        if (xadd != 0  ||  yadd != 0)
            scrollRectToVisible (new Rectangle (oldVisibleRect.x + xadd, oldVisibleRect.y + yadd, visibleRect.width, visibleRect.height));
        scrollRectToVisible (new Rectangle (scene.convertSceneToView (oldScenePoint)));
    }

    return state;
}
 
Example 12
Source File: Scene.java    From netbeans with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a prior actions. These actions are executed before any other action in the scene.
 * If any of these actions consumes an event that the event processsing is stopped. Action locking is ignored.
 * @return the prior actions
 */
public final WidgetAction.Chain getPriorActions () {
    return priorActions;
}
 
Example 13
Source File: Widget.java    From netbeans with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a default action chain.
 * @return the default action chain.
 */
public final WidgetAction.Chain getActions () {
    return actionsChain;
}
 
Example 14
Source File: Widget.java    From netbeans with Apache License 2.0 2 votes vote down vote up
/**
 * Returns already created action chain for a specified tool.
 * @param tool the tool
 * @return the action chain; null, if no chain for the tool exists
 */
public final WidgetAction.Chain getActions (String tool) {
    return toolsActions.get (tool);
}