Package de.FeatureModellingTool.GraphicalEditor

Source Code of de.FeatureModellingTool.GraphicalEditor.ToolBar$ContextChangeListener

package de.FeatureModellingTool.GraphicalEditor;

import research.*;
import research.figure.ArrowTip;
import de.FeatureModellingTool.FeatureModel.*;
import de.reuse.Context;
import de.reuse.ContextImplementation;
import de.reuse.GroupMap;
import research.toolAction.ToolAction;
import research.toolAction.CreationToolAction;
import research.toolAction.ConnectionToolAction;

import javax.swing.*;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;

/**
* author: zhangwei
* Date: 2003-5-28
* Time: 20:09:04
*/
class ToolBar extends JToolBar {

    protected final ToolActionController controller = new ToolActionController();

    private DrawingEditor drawingEditor = null;

    private FeatureModel featureModel = null;
    private FeatureEditor featureEditor = null;
    private FeatureModelEditor featureModelEditor = null;

    private ConstraintModel constraintModel = null;
    private ConstraintModelEditor constraintModelEditor = null;
    private CompositeConstraintEditor plConstraintEditor = null;
    private GroupConstraintEditor gConstraintEditor = null;
    private VPConstraintEditor vpConstraintEditor = null;

    private ResourceComponentEditor resourceComponentEditor = null;
    private InteractionModel interactionModel = null;
    private InteractionModelEditor interactionModelEditor = null;
   
    private ModelValidation modelValidation = null;

    private FeatureModelSelectionTool fmsTool = null;
    private FeatureModelTraceTool fmtTool = null;
    private FeatureCreationTool ffcTool = null;
    private ResourceComponentCreationTool rccTool = null;
    private FeatureRelationCreationTool iccTool = null;
    private FeatureRelationCreationTool dvccTool = null;
    private FeatureRelationCreationTool rcTool = null;
    private FeatureRelationCreationTool mcTool = null;

    private PLConstraintCreationTool plcTool = null;
    private GroupConstraintCreationTool gcTool = null;
    private VPConstraintCreationTool vpcTool = null;
    private PLConnectionCreationTool plccTool = null;

    private InteractionCreationTool icTool = null;

    private GroupMap idToFigureMap = null;

    protected final Context context = new ContextImplementation();

    public ToolBar() {
        context.addContextChangeListener(new ContextChangeListener());

        fmsTool = new FeatureModelSelectionTool();
        fmtTool = new FeatureModelTraceTool();
        ffcTool = new FeatureCreationTool();
        rccTool = new ResourceComponentCreationTool();
        iccTool = new FeatureRelationCreationTool();
        dvccTool = new FeatureRelationCreationTool();
        rcTool = new FeatureRelationCreationTool();
        mcTool = new FeatureRelationCreationTool();

        plcTool = new PLConstraintCreationTool();
        gcTool = new GroupConstraintCreationTool();
        vpcTool = new VPConstraintCreationTool();
        plccTool = new PLConnectionCreationTool();

        icTool = new InteractionCreationTool();

        iccTool.getContext().putValue(FeatureRelationCreationTool.RELATION_NAME, FeatureRelation.DECOMPOSE);
        dvccTool.getContext().putValue(FeatureRelationCreationTool.RELATION_NAME, FeatureRelation.ATTRIBUTE);
        rcTool.getContext().putValue(FeatureRelationCreationTool.RELATION_NAME, FeatureRelation.REQUIRE);
        mcTool.getContext().putValue(FeatureRelationCreationTool.RELATION_NAME, FeatureRelation.EXCLUDE);

        ToolAction toolAction = null;
        ImageIcon toolIcon = null;
        ToolButton tooButton = null;

        toolAction = new ToolAction();
        toolIcon = new ImageIcon(getClass().getResource("image/select.png"));
        toolAction.putValue(Action.SMALL_ICON, toolIcon);
        toolAction.putValue(Action.SHORT_DESCRIPTION, "Select and Move Figures");
        toolAction.putValue(ToolAction.TOOL, fmsTool);
        controller.addToolAction(toolAction);
        controller.setDefaultToolAction(toolAction);
        toolAction.setSelected(true);
        tooButton = new ToolButton(toolAction);
        this.add(tooButton);

        /**
         toolAction = new ToolAction();
         toolIcon = new ImageIcon(getClass().getResource("image/select.png"));
         toolAction.putValue(Action.SMALL_ICON, toolIcon);
         toolAction.putValue(Action.SHORT_DESCRIPTION, "Trace Link Figures");
         toolAction.putValue(ToolAction.TOOL, fmtTool);
         controller.addToolAction(toolAction);
         toolAction.setSelected(false);
         tooButton = new ToolButton(toolAction);
         this.add(tooButton);
         **/

        /**
         toolAction = new CreationToolAction();
         toolIcon = new ImageIcon(getClass().getResource("image/rect.png"));
         toolAction.putValue(Action.SMALL_ICON, toolIcon);
         toolAction.putValue(Action.SHORT_DESCRIPTION, "Create a Rectangle Figure");
         toolAction.putValue(CreationToolAction.PROTOTYPE_FIGURE, new RectangleFigure());
         toolAction.putValue(ToolAction.TOOL, new CreationTool());
         controller.addToolAction(toolAction);
         toolAction.setSelected(false);
         tooButton = new ToolButton(toolAction);
         this.add(tooButton);
         **/

        this.addSeparator();

        toolAction = new CreationToolAction();
        toolIcon = new ImageIcon(getClass().getResource("image/feature.png"));
        toolAction.putValue(Action.SMALL_ICON, toolIcon);
        toolAction.putValue(Action.SHORT_DESCRIPTION, "Create or Modify Feature Figures");
        toolAction.putValue(CreationToolAction.PROTOTYPE_FIGURE, new FeatureFigure());
        toolAction.putValue(ToolAction.TOOL, ffcTool);
        controller.addToolAction(toolAction);
        toolAction.setSelected(false);
        tooButton = new ToolButton(toolAction);
        this.add(tooButton);

        toolAction = new CreationToolAction();
        toolIcon = new ImageIcon(getClass().getResource("image/resource.png"));
        toolAction.putValue(Action.SMALL_ICON, toolIcon);
        toolAction.putValue(Action.SHORT_DESCRIPTION, "Create or Modify Resource-Container Figures");
        toolAction.putValue(CreationToolAction.PROTOTYPE_FIGURE, new ResourceComponentFigure());
        toolAction.putValue(ToolAction.TOOL, rccTool);
        controller.addToolAction(toolAction);
        toolAction.setSelected(false);
        tooButton = new ToolButton(toolAction);
        this.add(tooButton);

        this.addSeparator();

        toolAction = new ConnectionToolAction();
        toolIcon = new ImageIcon(getClass().getResource("image/decompose.png"));
        toolAction.putValue(Action.SMALL_ICON, toolIcon);
        toolAction.putValue(Action.SHORT_DESCRIPTION, "Create an Decompose-Relation Figure");
        toolAction.putValue(CreationToolAction.PROTOTYPE_FIGURE, new DecomposeConnection());
        toolAction.putValue(ToolAction.TOOL, iccTool);
        controller.addToolAction(toolAction);
        toolAction.setSelected(false);
        tooButton = new ToolButton(toolAction);
        this.add(tooButton);

        toolAction = new ConnectionToolAction();
        toolIcon = new ImageIcon(getClass().getResource("image/attribute.png"));
        toolAction.putValue(Action.SMALL_ICON, toolIcon);
        toolAction.putValue(Action.SHORT_DESCRIPTION, "Create an Attribute-Relation Figure");
        toolAction.putValue(CreationToolAction.PROTOTYPE_FIGURE, new AttributeConnection());
        toolAction.putValue(ToolAction.TOOL, dvccTool);
        controller.addToolAction(toolAction);
        toolAction.setSelected(false);
        tooButton = new ToolButton(toolAction);
        this.add(tooButton);

        this.addSeparator();

        toolAction = new ConnectionToolAction();
        toolIcon = new ImageIcon(getClass().getResource("image/require_connection.png"));
        toolAction.putValue(Action.SMALL_ICON, toolIcon);
        toolAction.putValue(Action.SHORT_DESCRIPTION, "Create a Require-Relation Figure");
        ConstraintConnection prototype = new ConstraintConnection(FeatureRelation.REQUIRE);
        prototype.setEndDecoration(new ArrowTip());
        toolAction.putValue(CreationToolAction.PROTOTYPE_FIGURE, prototype);
        toolAction.putValue(ToolAction.TOOL, rcTool);
        controller.addToolAction(toolAction);
        toolAction.setSelected(false);
        tooButton = new ToolButton(toolAction);
        this.add(tooButton);

        toolAction = new ConnectionToolAction();
        toolIcon = new ImageIcon(getClass().getResource("image/mutex_connection.png"));
        toolAction.putValue(Action.SMALL_ICON, toolIcon);
        toolAction.putValue(Action.SHORT_DESCRIPTION, "Create a Exclude-Relation Figure");
        prototype = new ConstraintConnection(FeatureRelation.EXCLUDE);
        prototype.setMidDecoration(new CrossDecoration(5));
        toolAction.putValue(CreationToolAction.PROTOTYPE_FIGURE, prototype);
        toolAction.putValue(ToolAction.TOOL, mcTool);
        controller.addToolAction(toolAction);
        toolAction.setSelected(false);
        tooButton = new ToolButton(toolAction);
        this.add(tooButton);

        this.addSeparator();

        toolAction = new CreationToolAction();
        toolIcon = new ImageIcon(getClass().getResource("image/vp_contraint.png"));
        toolAction.putValue(Action.SMALL_ICON, toolIcon);
        toolAction.putValue(Action.SHORT_DESCRIPTION, "Create a VP Constraint Figure");
        toolAction.putValue(CreationToolAction.PROTOTYPE_FIGURE, new VPConstraintFigure());
        toolAction.putValue(ToolAction.TOOL, vpcTool);
        controller.addToolAction(toolAction);
        toolAction.setSelected(false);
        tooButton = new ToolButton(toolAction);
        this.add(tooButton);

        toolAction = new CreationToolAction();
        toolIcon = new ImageIcon(getClass().getResource("image/group_contraint.png"));
        toolAction.putValue(Action.SMALL_ICON, toolIcon);
        toolAction.putValue(Action.SHORT_DESCRIPTION, "Create a Group Constraint Figure");
        toolAction.putValue(CreationToolAction.PROTOTYPE_FIGURE, new GroupConstraintFigure());
        toolAction.putValue(ToolAction.TOOL, gcTool);
        controller.addToolAction(toolAction);
        toolAction.setSelected(false);
        tooButton = new ToolButton(toolAction);
        this.add(tooButton);

        toolAction = new CreationToolAction();
        toolIcon = new ImageIcon(getClass().getResource("image/composite_contraint.png"));
        toolAction.putValue(Action.SMALL_ICON, toolIcon);
        toolAction.putValue(Action.SHORT_DESCRIPTION, "Create a Composite Constraint Figure");
        toolAction.putValue(CreationToolAction.PROTOTYPE_FIGURE, new PLFigure());
        toolAction.putValue(ToolAction.TOOL, plcTool);
        controller.addToolAction(toolAction);
        toolAction.setSelected(false);
        tooButton = new ToolButton(toolAction);
        this.add(tooButton);

        toolAction = new ConnectionToolAction();
        toolIcon = new ImageIcon(getClass().getResource("image/c2f.png"));
        toolAction.putValue(Action.SMALL_ICON, toolIcon);
        toolAction.putValue(Action.SHORT_DESCRIPTION, "Create a Constraint Relation Figure");
        toolAction.putValue(CreationToolAction.PROTOTYPE_FIGURE, new PLConnection());
        toolAction.putValue(ToolAction.TOOL, plccTool);
        controller.addToolAction(toolAction);
        toolAction.setSelected(false);
        tooButton = new ToolButton(toolAction);
        this.add(tooButton);

        toolAction = new ConnectionToolAction();
        toolIcon = new ImageIcon(getClass().getResource("image/c2fn.png"));
        toolAction.putValue(Action.SMALL_ICON, toolIcon);
        toolAction.putValue(Action.SHORT_DESCRIPTION, "Create a Negation Constraint Relation Figure");
        toolAction.putValue(CreationToolAction.PROTOTYPE_FIGURE, new PLConnection(true));
        toolAction.putValue(ToolAction.TOOL, plccTool);
        controller.addToolAction(toolAction);
        toolAction.setSelected(false);
        tooButton = new ToolButton(toolAction);
        this.add(tooButton);

        /**
         toolAction = new TextAreaToolAction();
         toolIcon = new ImageIcon(getClass().getResource("image/comment.png"));
         toolAction.putValue(Action.SMALL_ICON, toolIcon);
         toolAction.putValue(Action.SHORT_DESCRIPTION, "Create a Comment Figure");
         toolAction.putValue(CreationToolAction.PROTOTYPE_FIGURE, new TextAreaFigure());
         toolAction.putValue(ToolAction.TOOL, new ConnectedTextAreaTool());
         controller.addToolAction(toolAction);
         toolAction.setSelected(false);
         tooButton = new ToolButton(toolAction);
         this.add(tooButton);
         **/

        this.addSeparator();
        toolAction = new ConnectionToolAction();
        toolIcon = new ImageIcon(getClass().getResource("image/interaction_connection.png"));
        toolAction.putValue(Action.SMALL_ICON, toolIcon);
        toolAction.putValue(Action.SHORT_DESCRIPTION, "Create an Interaction Figure");
        InteractionConnection proto = new InteractionConnection();
        toolAction.putValue(CreationToolAction.PROTOTYPE_FIGURE, proto);
        proto.setEndDecoration(new ArrowTip());
        toolAction.putValue(ToolAction.TOOL, icTool);
        controller.addToolAction(toolAction);
        toolAction.setSelected(false);
        tooButton = new ToolButton(toolAction);
        this.add(tooButton);

        this.addSeparator();
        toolIcon = new ImageIcon(getClass().getResource("image/lock.png"));
        JToggleButton stickButton = new JToggleButton(toolIcon);
        stickButton.setFocusable(false);
        this.add(stickButton);

        if (controller.getPolicy().equals(ToolActionController.CONTINUE_POLICY)) {
            stickButton.setSelected(true);
        } else {
            stickButton.setSelected(false);
        }

        stickButton.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                int state = e.getStateChange();

                if (state == ItemEvent.SELECTED)
                    controller.setPolicy(ToolActionController.CONTINUE_POLICY);
                else
                    controller.setPolicy(ToolActionController.DEFAULT_POLICY);

            }
        });

    }

    public Context getContext() {
        return context;
    }

    /**
     * public ToolActionController getController() {
     * return controller;
     * }
     */

    protected class ContextChangeListener implements PropertyChangeListener {
        public void propertyChange(PropertyChangeEvent e) {
            contextChange(e);
        }
    }

    protected void contextChange(PropertyChangeEvent e) {
        String propertyName = e.getPropertyName();

        if (ConstantDefinition.DRAWING_EDITOR.equals(propertyName)) {
            drawingEditor = (DrawingEditor) e.getNewValue();
            controller.setDrawingEditor(drawingEditor);
        } else if (ConstantDefinition.FEATURE_MODEL.equals(propertyName)) {
            featureModel = (FeatureModel) e.getNewValue();
            fmsTool.getContext().putValue(ConstantDefinition.FEATURE_MODEL, featureModel);
            ffcTool.getContext().putValue(ConstantDefinition.FEATURE_MODEL, featureModel);
            iccTool.getContext().putValue(ConstantDefinition.FEATURE_MODEL, featureModel);
            dvccTool.getContext().putValue(ConstantDefinition.FEATURE_MODEL, featureModel);
            rcTool.getContext().putValue(ConstantDefinition.FEATURE_MODEL, featureModel);
            mcTool.getContext().putValue(ConstantDefinition.FEATURE_MODEL, featureModel);
            plcTool.getContext().putValue(ConstantDefinition.FEATURE_MODEL, featureModel);
            gcTool.getContext().putValue(ConstantDefinition.FEATURE_MODEL, featureModel);
            vpcTool.getContext().putValue(ConstantDefinition.FEATURE_MODEL, featureModel);
            plccTool.getContext().putValue(ConstantDefinition.FEATURE_MODEL, featureModel);
            icTool.getContext().putValue(ConstantDefinition.FEATURE_MODEL, featureModel);
        } else if (ConstantDefinition.FEATURE_EDITOR.equals(propertyName)) {
            featureEditor = (FeatureEditor) e.getNewValue();
            ffcTool.getContext().putValue(ConstantDefinition.FEATURE_EDITOR, featureEditor);
        } else if (ConstantDefinition.RESOURCE_COMPONENT_EDITOR.equals(propertyName)) {
            resourceComponentEditor = (ResourceComponentEditor) e.getNewValue();
            rccTool.getContext().putValue(ConstantDefinition.RESOURCE_COMPONENT_EDITOR, resourceComponentEditor);
        } else if (ConstantDefinition.FEATURE_MODEL_EDITOR.equals(propertyName)) {
            featureModelEditor = (FeatureModelEditor) e.getNewValue();
            fmsTool.getContext().putValue(ConstantDefinition.FEATURE_MODEL_EDITOR, featureModelEditor);
            ffcTool.getContext().putValue(ConstantDefinition.FEATURE_MODEL_EDITOR, featureModelEditor);
            iccTool.getContext().putValue(ConstantDefinition.FEATURE_MODEL_EDITOR, featureModelEditor);
            dvccTool.getContext().putValue(ConstantDefinition.FEATURE_MODEL_EDITOR, featureModelEditor);
            rcTool.getContext().putValue(ConstantDefinition.FEATURE_MODEL_EDITOR, featureModelEditor);
            mcTool.getContext().putValue(ConstantDefinition.FEATURE_MODEL_EDITOR, featureModelEditor);
        } else if (ConstantDefinition.ID_TO_FIGURE_MAP.equals(propertyName)) {
            idToFigureMap = (GroupMap) e.getNewValue();
            fmsTool.getContext().putValue(ConstantDefinition.ID_TO_FIGURE_MAP, idToFigureMap);
            ffcTool.getContext().putValue(ConstantDefinition.ID_TO_FIGURE_MAP, idToFigureMap);
            rccTool.getContext().putValue(ConstantDefinition.ID_TO_FIGURE_MAP, idToFigureMap);
            iccTool.getContext().putValue(ConstantDefinition.ID_TO_FIGURE_MAP, idToFigureMap);
            dvccTool.getContext().putValue(ConstantDefinition.ID_TO_FIGURE_MAP, idToFigureMap);
            rcTool.getContext().putValue(ConstantDefinition.ID_TO_FIGURE_MAP, idToFigureMap);
            mcTool.getContext().putValue(ConstantDefinition.ID_TO_FIGURE_MAP, idToFigureMap);
            plcTool.getContext().putValue(ConstantDefinition.ID_TO_FIGURE_MAP, idToFigureMap);
            gcTool.getContext().putValue(ConstantDefinition.ID_TO_FIGURE_MAP, idToFigureMap);
            vpcTool.getContext().putValue(ConstantDefinition.ID_TO_FIGURE_MAP, idToFigureMap);
            plccTool.getContext().putValue(ConstantDefinition.ID_TO_FIGURE_MAP, idToFigureMap);
            icTool.getContext().putValue(ConstantDefinition.ID_TO_FIGURE_MAP, idToFigureMap);
        } else if (ConstantDefinition.CONSTRAINT_MODEL.equals(propertyName)) {
            constraintModel = (ConstraintModel) e.getNewValue();
            plcTool.getContext().putValue(ConstantDefinition.CONSTRAINT_MODEL, constraintModel);
            gcTool.getContext().putValue(ConstantDefinition.CONSTRAINT_MODEL, constraintModel);
            vpcTool.getContext().putValue(ConstantDefinition.CONSTRAINT_MODEL, constraintModel);
            plccTool.getContext().putValue(ConstantDefinition.CONSTRAINT_MODEL, constraintModel);
            fmsTool.getContext().putValue(ConstantDefinition.CONSTRAINT_MODEL, constraintModel);
        } else if (ConstantDefinition.CONSTRAINT_MODEL_EDITOR.equals(propertyName)) {
            constraintModelEditor = (ConstraintModelEditor) e.getNewValue();
            plcTool.getContext().putValue(ConstantDefinition.CONSTRAINT_MODEL_EDITOR, constraintModelEditor);
            gcTool.getContext().putValue(ConstantDefinition.CONSTRAINT_MODEL_EDITOR, constraintModelEditor);
            vpcTool.getContext().putValue(ConstantDefinition.CONSTRAINT_MODEL_EDITOR, constraintModelEditor);
            plccTool.getContext().putValue(ConstantDefinition.CONSTRAINT_MODEL_EDITOR, constraintModelEditor);
            fmsTool.getContext().putValue(ConstantDefinition.CONSTRAINT_MODEL_EDITOR, constraintModelEditor);
        } else if (ConstantDefinition.PL_CONSTRAINT_EDITOR.equals(propertyName)) {
            plConstraintEditor = (CompositeConstraintEditor) e.getNewValue();
            plcTool.getContext().putValue(ConstantDefinition.PL_CONSTRAINT_EDITOR, plConstraintEditor);
        } else if (ConstantDefinition.GROUP_CONSTRAINT_EDITOR.equals(propertyName)) {
            gConstraintEditor = (GroupConstraintEditor) e.getNewValue();
            gcTool.getContext().putValue(ConstantDefinition.GROUP_CONSTRAINT_EDITOR, gConstraintEditor);
        } else if (ConstantDefinition.VP_CONSTRAINT_EDITOR.equals(propertyName)) {
            vpConstraintEditor = (VPConstraintEditor) e.getNewValue();
            vpcTool.getContext().putValue(ConstantDefinition.VP_CONSTRAINT_EDITOR, vpConstraintEditor);
        } else if (ConstantDefinition.INTERACTION_MODEL.equals(propertyName)) {
            interactionModel = (InteractionModel) e.getNewValue();
            rccTool.getContext().putValue(ConstantDefinition.INTERACTION_MODEL, interactionModel);
            icTool.getContext().putValue(ConstantDefinition.INTERACTION_MODEL, interactionModel);
            fmsTool.getContext().putValue(ConstantDefinition.INTERACTION_MODEL, interactionModel);
        } else if (ConstantDefinition.INTERACTION_MODEL_EDITOR.equals(propertyName)) {
            interactionModelEditor = (InteractionModelEditor) e.getNewValue();
            rccTool.getContext().putValue(ConstantDefinition.INTERACTION_MODEL_EDITOR, interactionModelEditor);
            icTool.getContext().putValue(ConstantDefinition.INTERACTION_MODEL_EDITOR, interactionModelEditor);
            fmsTool.getContext().putValue(ConstantDefinition.INTERACTION_MODEL_EDITOR, interactionModelEditor);
        } else if (GraphicalEditor.MODEL_VALIDATION.equals(propertyName)) {
            modelValidation = (ModelValidation)e.getNewValue();
            iccTool.getContext().putValue(GraphicalEditor.MODEL_VALIDATION, modelValidation);
            dvccTool.getContext().putValue(GraphicalEditor.MODEL_VALIDATION, modelValidation);
            rcTool.getContext().putValue(GraphicalEditor.MODEL_VALIDATION, modelValidation);
            mcTool.getContext().putValue(GraphicalEditor.MODEL_VALIDATION, modelValidation);
            plccTool.getContext().putValue(GraphicalEditor.MODEL_VALIDATION, modelValidation);
            fmsTool.getContext().putValue(GraphicalEditor.MODEL_VALIDATION, modelValidation);
            fmtTool.getContext().putValue(GraphicalEditor.MODEL_VALIDATION, modelValidation);
        }
    }
}
TOP

Related Classes of de.FeatureModellingTool.GraphicalEditor.ToolBar$ContextChangeListener

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.