Package de.FeatureModellingTool.GraphicalEditor

Source Code of de.FeatureModellingTool.GraphicalEditor.GraphicalEditorImplementation$InteractionModelPropertyChangeListener

package de.FeatureModellingTool.GraphicalEditor;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Window;
import java.awt.datatransfer.DataFlavor;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.dnd.DropTargetListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.FilteredImageSource;
import java.awt.image.RGBImageFilter;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Serializable;
import java.io.Writer;
import java.net.URL;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.Vector;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.ImageIcon;
import javax.swing.JColorChooser;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JSpinner;
import javax.swing.JToolBar;
import javax.swing.SpinnerNumberModel;
import javax.swing.colorchooser.AbstractColorChooserPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.apache.batik.dom.GenericDOMImplementation;
import org.apache.batik.svggen.SVGGeneratorContext;
import org.apache.batik.svggen.SVGGraphics2D;
import org.freehep.util.export.ExportDialog;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;

import applet.WebConstantDefinition;

import research.ConnectionFigure;
import research.Drawing;
import research.DrawingEditor;
import research.DrawingView;
import research.Figure;
import research.FigureEnumeration;
import research.FigureSelectionListener;
import research.ReverseFigureEnumerator;
import research.SaturnDrawing;
import research.SaturnDrawingView;
import research.util.GlobalFunction;
import research.util.colorchooser.DefaultHSBAChooserPanel;
import research.util.colorchooser.DefaultRGBAChooserPanel;
import research.util.colorchooser.DefaultSwatchChooserPanel;
import Acme.JPM.Encoders.GifEncoder;
import de.FeatureModellingTool.Customize.Customization;
import de.FeatureModellingTool.Customize.CustomizationVersion;
import de.FeatureModellingTool.FeatureModel.CompositeConstraint;
import de.FeatureModellingTool.FeatureModel.CompositeConstraintPortType;
import de.FeatureModellingTool.FeatureModel.CompositeConstraintProperties;
import de.FeatureModellingTool.FeatureModel.CompositeConstraintType;
import de.FeatureModellingTool.FeatureModel.Constraint;
import de.FeatureModellingTool.FeatureModel.ConstraintModel;
import de.FeatureModellingTool.FeatureModel.Feature;
import de.FeatureModellingTool.FeatureModel.FeatureEditor;
import de.FeatureModellingTool.FeatureModel.FeatureModel;
import de.FeatureModellingTool.FeatureModel.FeatureModelEditor;
import de.FeatureModellingTool.FeatureModel.FeatureProperties;
import de.FeatureModellingTool.FeatureModel.GroupConstraint;
import de.FeatureModellingTool.FeatureModel.GroupConstraintProperties;
import de.FeatureModellingTool.FeatureModel.GroupConstraintType;
import de.FeatureModellingTool.FeatureModel.Interaction;
import de.FeatureModellingTool.FeatureModel.InteractionModel;
import de.FeatureModellingTool.FeatureModel.InteractionProperties;
import de.FeatureModellingTool.FeatureModel.ResourceComponent;
import de.FeatureModellingTool.FeatureModel.ResourceComponentProperties;
import de.FeatureModellingTool.FeatureModel.VPConstraint;
import de.FeatureModellingTool.FeatureModel.VPConstraintProperties;
import de.FeatureModellingTool.FeatureModel.VPConstraintType;
import de.FeatureModellingTool.Pattern.UI.AutoLayout;
import de.FeatureModellingTool.Pattern.UI.PatternSelection;
import de.FeatureModellingTool.Pattern.UI.AutoLayout.FeatureLayout;
import de.FeatureModellingTool.PatternBase.PatternBase;
import de.reuse.Context;
import de.reuse.DrawingEditorTabbedPane;
import de.reuse.GroupTreeMap;

/**
* author: zhangwei
* Date: 2003-5-30
* Time: 22:16:07
*/
public class GraphicalEditorImplementation implements GraphicalEditor {

    protected FeatureModel featureModel = null;
    protected ConstraintModel constraintModel = null;
    protected InteractionModel interactionModel = null;
    protected DropTarget dropTarget = null;

    private ToolBar toolBar = null;
    protected DrawingEditorTabbedPane editorArea = null;
    protected JSpinner scaler = null;
    protected JPopupMenu editorAreaPopupMenu = null;

    ModelValidation modelValidation = null;
   
    protected AddViewAction addViewAction = null;
    protected CloseViewAction closeViewAction = null;
    protected OpenViewAction openViewAction = null;
    protected RemoveViewAction removeViewAction = null;

    protected ChangeViewNameAction changeViewNameAction = null;

    //��˶���
    private EditorAction leftAlignAction = null;
    //��ֱ����
    private EditorAction vertAlignAction = null;
    //�Ҷ˶���
    private EditorAction rightAlignAction = null;
    //���˶���
    private EditorAction topAlignAction = null;
    //ˮƽ����
    private EditorAction horiAlignAction = null;
    //�׶˶���
    private EditorAction botAlignAction = null;
    //����ֲ�
    private EditorAction vertDistAction = null;
    //����ֲ�
    private EditorAction horiDistAction = null;

    private FigureDeleteAction figureDeleteAction = null;
    private FigureCopyAction figureCopyAction = null;
    private FigureCutAction figureCutAction = null;
    private FigurePasteAction figurePasteAction = null;
    private FigurePasteAsLinkAction figurePasteAsLinkAction = null;

    protected SelectAllAction selectAllAction = null;
    protected ToggleSelectAction toggleSelectAction = null;

    protected SendToBackAction sendToBackAction = null;
    protected SendToFrontAction sendToFrontAction = null;

    protected ExportViewAction exportViewAction = null;

    protected ChangeColorAction changeFillColorAction = null;
    protected ChangeColorAction changeFrameColorAction = null;
    protected ChangeColorAction changeTextColorAction = null;

    protected DropTargetListener dropTargetListener = null;

    protected ElementLocatorImplementation elementLocator = null;

    protected ActionMap actionMap = null;

    protected GraphicalEditorUIImplementation graphicalEditorUI = null;

    protected final CurrentViewFigureSelectionChangedListener currentViewFigureSelectionChangedListener = new CurrentViewFigureSelectionChangedListener();

    protected final ContextChangeListener contextChangeListener = new ContextChangeListener();

    protected final FeatureModelPropertyChangeListener featureModelPropertyChangeListener = new FeatureModelPropertyChangeListener();

    protected final ConstraintModelPropertyChangeListener constraintModelPropertyChangeListener = new ConstraintModelPropertyChangeListener();

    protected final InteractionModelPropertyChangeListener interactionModelPropertyChangeListener = new InteractionModelPropertyChangeListener();

    protected final ViewAddedOrRemovedListener viewAddedOrRemovedListener = new ViewAddedOrRemovedListener();

    protected final PopupMenuTriggeredListener popupMenuTriggeredListener = new PopupMenuTriggeredListener();

    protected final GroupTreeMap idToFigureMap = new GroupTreeMap();

    private final static ExportDialog exportDialog = new ExportDialog();

    private final static DefaultRGBAChooserPanel rgbaChooser =  new DefaultRGBAChooserPanel();
    private final static DefaultHSBAChooserPanel hsbaChooser =  new DefaultHSBAChooserPanel();
    private final static DefaultSwatchChooserPanel dsChooser =  new DefaultSwatchChooserPanel();

    public GraphicalEditorImplementation() {

        editorArea = new DrawingEditorTabbedPane();
        editorArea.addPropertyChangeListener(new DrawingEditorPropertyChangeListener());
        editorArea.addPropertyChangeListener(DrawingEditor.CURRENT_VIEW_CHANGED, new CurrentViewChangeListener());
        editorArea.addPropertyChangeListener(DrawingEditor.VIEW_ADDED, viewAddedOrRemovedListener);
        editorArea.addPropertyChangeListener(DrawingEditor.VIEW_REMOVED, viewAddedOrRemovedListener);
        editorArea.addPropertyChangeListener(DrawingEditor.POPUP_MENU_TRIGGERED, popupMenuTriggeredListener);

        try{
        toolBar = new ToolBar();
        }catch(Exception e){
          e.printStackTrace();
        }
       
        modelValidation = new ModelValidation(getContext());
        toolBar.getContext().putValue(MODEL_VALIDATION, modelValidation);  
       
        getContext().putValue(ConstantDefinition.DRAWING_EDITOR, editorArea);
        getContext().putValue(ConstantDefinition.ID_TO_FIGURE_MAP, idToFigureMap);
        getContext().addContextChangeListener(ConstantDefinition.FEATURE_MODEL, contextChangeListener);
        getContext().addContextChangeListener(ConstantDefinition.CONSTRAINT_MODEL, contextChangeListener);
        getContext().addContextChangeListener(ConstantDefinition.INTERACTION_MODEL, contextChangeListener);
        getContext().addContextChangeListener(ConstantDefinition.DROP_TARGET, contextChangeListener);
        scaler = new JSpinner(new SpinnerNumberModel(100, 10, 600, 5));
        scaler.setEnabled(false);
        scaler.setToolTipText("������ǰ��ͼ��ʾ����");
        scaler.setMaximumSize(scaler.getPreferredSize());
        scaler.setAlignmentX(0.5f);
        scaler.setAlignmentY(0.5f);
        scaler.getModel().addChangeListener(new SpinnerValueChangeListener());

        editorAreaPopupMenu = new JPopupMenu();

        addViewAction = new AddViewAction();
        addViewAction.putValue(ConstantDefinition.DRAWING_EDITOR, editorArea);
        closeViewAction = new CloseViewAction();
        closeViewAction.putValue(ConstantDefinition.DRAWING_EDITOR, editorArea);
        openViewAction = new OpenViewAction();
        openViewAction.putValue(ConstantDefinition.DRAWING_EDITOR, editorArea);
        removeViewAction = new RemoveViewAction();
        removeViewAction.putValue(ConstantDefinition.DRAWING_EDITOR, editorArea);
        changeViewNameAction  = new ChangeViewNameAction();
        changeViewNameAction.putValue(ConstantDefinition.DRAWING_EDITOR, editorArea);
        selectAllAction = new SelectAllAction();
        selectAllAction.putValue(ConstantDefinition.DRAWING_EDITOR, editorArea);
        toggleSelectAction = new ToggleSelectAction();
        toggleSelectAction.putValue(ConstantDefinition.DRAWING_EDITOR, editorArea);
        sendToBackAction = new SendToBackAction();
        sendToBackAction.putValue(ConstantDefinition.DRAWING_EDITOR, editorArea);
        sendToFrontAction = new SendToFrontAction();
        sendToFrontAction.putValue(ConstantDefinition.DRAWING_EDITOR, editorArea);
        exportViewAction = new ExportViewAction();
        exportViewAction.putValue(ConstantDefinition.DRAWING_EDITOR, editorArea);

        changeFillColorAction = new ChangeColorAction("�����ɫ", "fillColor");
        changeFillColorAction.putValue(ConstantDefinition.DRAWING_EDITOR, editorArea);
        changeFrameColorAction = new ChangeColorAction("�߿���ɫ", "frameColor");
        changeFrameColorAction.putValue(ConstantDefinition.DRAWING_EDITOR, editorArea);
        changeTextColorAction = new ChangeColorAction("������ɫ", "textColor");
        changeTextColorAction.putValue(ConstantDefinition.DRAWING_EDITOR, editorArea);


        leftAlignAction = new LeftAlignAction();
        leftAlignAction.putValue(ConstantDefinition.DRAWING_EDITOR, editorArea);
        vertAlignAction = new VertAlignAction();
        vertAlignAction.putValue(ConstantDefinition.DRAWING_EDITOR, editorArea);
        rightAlignAction = new RightAlignAction();
        rightAlignAction.putValue(ConstantDefinition.DRAWING_EDITOR, editorArea);

        topAlignAction = new TopAlignAction();
        topAlignAction.putValue(ConstantDefinition.DRAWING_EDITOR, editorArea);
        horiAlignAction = new HoriAlignAction();
        horiAlignAction.putValue(ConstantDefinition.DRAWING_EDITOR, editorArea);
        botAlignAction = new BotAlignAction();
        botAlignAction.putValue(ConstantDefinition.DRAWING_EDITOR, editorArea);

        vertDistAction = new VertDistAction();
        vertDistAction.putValue(ConstantDefinition.DRAWING_EDITOR, editorArea);
        horiDistAction = new HoriDistAction();
        horiDistAction.putValue(ConstantDefinition.DRAWING_EDITOR, editorArea);

        figureDeleteAction = new FigureDeleteAction();
        figureCopyAction = new FigureCopyAction();
        figureCutAction = new FigureCutAction();
        figurePasteAction = new FigurePasteAction();
        figurePasteAsLinkAction = new FigurePasteAsLinkAction();

        figureDeleteAction.putValue(ConstantDefinition.ID_TO_FIGURE_MAP, idToFigureMap);
        figureCopyAction.putValue(ConstantDefinition.ID_TO_FIGURE_MAP, idToFigureMap);
        figureCutAction.putValue(ConstantDefinition.ID_TO_FIGURE_MAP, idToFigureMap);
        figurePasteAction.putValue(ConstantDefinition.ID_TO_FIGURE_MAP, idToFigureMap);
        figurePasteAsLinkAction.putValue(ConstantDefinition.ID_TO_FIGURE_MAP, idToFigureMap);

        actionMap = new ActionMap();
        actionMap.put(addViewAction.getValue(Action.NAME), addViewAction);
        actionMap.put(closeViewAction.getValue(Action.NAME), closeViewAction);
        actionMap.put(openViewAction.getValue(Action.NAME), openViewAction);
        actionMap.put(removeViewAction.getValue(Action.NAME), removeViewAction);
        actionMap.put(exportViewAction.getValue(Action.NAME), exportViewAction);
        actionMap.put(changeViewNameAction.getValue(Action.NAME), changeViewNameAction);

        actionMap.put(ConstantDefinition.LEFT_ALIGN, leftAlignAction);
        actionMap.put(ConstantDefinition.VERTICAL_ALIGN, vertAlignAction);
        actionMap.put(ConstantDefinition.RIGHT_ALIGN, rightAlignAction);

        actionMap.put(ConstantDefinition.TOP_ALIGN, topAlignAction);
        actionMap.put(ConstantDefinition.HORIZONTAL_ALIGN, horiAlignAction);
        actionMap.put(ConstantDefinition.BOTTOM_ALIGN, botAlignAction);

        actionMap.put(ConstantDefinition.VERTICAL_DISTRIBUTE, vertDistAction);
        actionMap.put(ConstantDefinition.HORIZONTAL_DISTRIBUTE, horiDistAction);

        actionMap.put(ConstantDefinition.FIGURE_DELETE_ACTION, figureDeleteAction);
        actionMap.put(ConstantDefinition.FIGURE_COPY_ACTION, figureCopyAction);
        actionMap.put(ConstantDefinition.FIGURE_CUT_ACTION, figureCutAction);
        actionMap.put(ConstantDefinition.FIGURE_PASTE_ACTION, figurePasteAction);
        actionMap.put(ConstantDefinition.FIGURE_PASTE_AS_LINK_ACTION, figurePasteAsLinkAction);

        actionMap.put(ConstantDefinition.FIGURE_SELECT_ALL_ACTION, selectAllAction);
        actionMap.put(ConstantDefinition.FIGURE_TOGGLE_SELECT_ACTION, toggleSelectAction);

        actionMap.put(ConstantDefinition.SEND_TO_BACK, sendToBackAction);
        actionMap.put(ConstantDefinition.SEND_TO_FRONT, sendToFrontAction);

        actionMap.put(ConstantDefinition.FILL_COLOR_CAHNGE_ACTION, changeFillColorAction);
        actionMap.put(ConstantDefinition.FRAME_COLOR_CAHNGE_ACTION, changeFrameColorAction);
        actionMap.put(ConstantDefinition.TEXT_COLOR_CAHNGE_ACTION, changeTextColorAction);

        //gh start
        this.customizationUndecideAction = new CustomizationUndecideAction();
        this.customizationUndecideAction.putValue(ConstantDefinition.ID_TO_FIGURE_MAP, idToFigureMap);
        this.actionMap.put(ConstantDefinition.CUSTOMIZATION_UNDECIDE , this.customizationUndecideAction);
       
        this.customizationSelectAction = new CustomizationSelectAction();
        this.customizationSelectAction.putValue(ConstantDefinition.ID_TO_FIGURE_MAP, idToFigureMap);
        this.actionMap.put(ConstantDefinition.CUSTOMIZATION_SELECT , this.customizationSelectAction);
       
        this.customizationUnselectAction = new CustomizationUnselectAction();
        this.customizationUnselectAction.putValue(ConstantDefinition.ID_TO_FIGURE_MAP, idToFigureMap);
        this.actionMap.put(ConstantDefinition.CUSTOMIZATION_UNSELECT , this.customizationUnselectAction);
        //gh end
       
        dropTargetListener = new InerDropTargetListener();
    }

   
    public Context getContext() {
        return toolBar.getContext();
    }

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

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

        if (ConstantDefinition.FEATURE_MODEL.equals(propertyName)) {
            if (featureModel != null)
                featureModel.removePropertyChangeListener(featureModelPropertyChangeListener);

            featureModel = (FeatureModel) e.getNewValue();

            if (featureModel != null)
                featureModel.addPropertyChangeListener(featureModelPropertyChangeListener);
        } else if (ConstantDefinition.CONSTRAINT_MODEL.equals(propertyName)) {
            if (constraintModel != null)
                constraintModel.removePropertyChangeListener(constraintModelPropertyChangeListener);

            constraintModel = (ConstraintModel) e.getNewValue();

            if (constraintModel != null)
                constraintModel.addPropertyChangeListener(constraintModelPropertyChangeListener);
        } else if (ConstantDefinition.INTERACTION_MODEL.equals(propertyName)) {
            if (interactionModel != null)
                interactionModel.removePropertyChangeListener(interactionModelPropertyChangeListener);

            interactionModel = (InteractionModel) e.getNewValue();

            if (interactionModel != null)
                interactionModel.addPropertyChangeListener(interactionModelPropertyChangeListener);
        } else if (ConstantDefinition.DROP_TARGET.equals(propertyName)) {

            if (dropTarget != null) {
                dropTarget.setComponent(null);
                dropTarget.setActive(false);
            }

            dropTarget = (DropTarget) e.getNewValue();

            if (dropTarget != null) {
                dropTarget.setComponent((JComponent) editorArea.getCurrentView());
                //dropTarget.setComponent(editorArea);
                dropTarget.setActive(true);
            }
        }
    }

    protected class PopupMenuTriggeredListener implements PropertyChangeListener {
        public void propertyChange(PropertyChangeEvent e) {
            String propertyName = e.getPropertyName();

            if (DrawingEditor.POPUP_MENU_TRIGGERED.equals(propertyName)) {
                int childCount = editorAreaPopupMenu.getComponentCount();

                if (childCount > 0) {
                    Point p = (Point) e.getNewValue();
                    editorAreaPopupMenu.show((Component) e.getSource(), p.x, p.y);
                }
            }
        }
    }

    protected class ViewAddedOrRemovedListener implements PropertyChangeListener {
        public void propertyChange(PropertyChangeEvent e) {
            String propertyName = e.getPropertyName();

            if (DrawingEditor.VIEW_ADDED.equals(propertyName)) {
                DrawingView view = (DrawingView) e.getNewValue();
                //����id��figure��ӳ���
                if (idToFigureMap != null) {
                    FigureEnumeration fe = view.getDrawing().getFigures();
                    while (fe.hasMoreElements()) {
                        Figure figure = fe.nextFigure();

                        idToFigureMap.add(figure.getAttribute("id"), figure);
                    }
                }
            } else if (DrawingEditor.VIEW_REMOVED.equals(propertyName)) {
                DrawingView view = (DrawingView) e.getOldValue();
                //����id��figure��ӳ���
                if (idToFigureMap != null) {
                    FigureEnumeration fe = view.getDrawing().getFigures();
                    while (fe.hasMoreElements()) {
                        Figure figure = fe.nextFigure();

                        idToFigureMap.remove(figure.getAttribute("id"), figure);
                    }
                }
            }
        }
    }

    protected class InteractionModelPropertyChangeListener implements PropertyChangeListener {
        public void propertyChange(PropertyChangeEvent evt) {
            Object src = evt.getSource();

            if (src instanceof Interaction) {
                Interaction target = (Interaction) src;
                String propertyName = evt.getPropertyName();

                if (propertyName.equals(InteractionProperties.NAME)
                        || propertyName.equals(InteractionProperties.TYPE)) {
                    Set set = idToFigureMap.get(target.getID());

                    if (set == null) return;

                    //update the figure's display
                    Iterator iterator = set.iterator();
                    while (iterator.hasNext()) {
                        Figure fig = (Figure) iterator.next();
                        fig.setAttribute("text", target.getType() + ":" + target.getName());
                        fig.invalidate();
                    }
                }
            } else if (src instanceof ResourceComponent) {
                ResourceComponent rc = (ResourceComponent) src;
                String propertyName = evt.getPropertyName();
                if (propertyName.equals(ResourceComponentProperties.NAME)) {
                    Set set = idToFigureMap.get(rc.getID());

                    if (set == null) return;

                    //update the figure's display
                    Iterator iterator = set.iterator();
                    while (iterator.hasNext()) {
                        Figure fig = (Figure) iterator.next();
                        fig.setAttribute("text", rc.getName());
                        fig.invalidate();
                    }
                }
            }

            DrawingView view = editorArea.getCurrentView();
            if (view != null)
                view.repairDamage();
        }
    }

    protected class ConstraintModelPropertyChangeListener implements PropertyChangeListener {
        public void propertyChange(PropertyChangeEvent evt) {
            Object src = evt.getSource();

            if (!(src instanceof Constraint))
                return;

            if (src instanceof GroupConstraint) {
                GroupConstraint target = (GroupConstraint) src;
                String propertyName = evt.getPropertyName();

                if (propertyName.equals(GroupConstraintProperties.TYPE)) {
                    Set set = idToFigureMap.get(target.getID());
                    if (set == null) return;

                    //update the figure's display

                    GroupConstraintType gType = target.getType();

                    String value = null;

                    if (GroupConstraintType.SingleGroup.equals(gType)) {
                        value = GroupConstraintFigure.Single;
                    } else if (GroupConstraintType.MultiGroup.equals(gType)) {
                        value = GroupConstraintFigure.Multi;
                    } else if (GroupConstraintType.AllGroup.equals(gType)) {
                        value = GroupConstraintFigure.All;
                    }

                    Iterator iterator = set.iterator();
                    while (iterator.hasNext()) {
                        Figure fig = (Figure) iterator.next();
                        fig.setAttribute(GroupConstraintFigure.GroupType, value);
                        fig.invalidate();
                    }
                }
            } else if (src instanceof VPConstraint) {
                VPConstraint target = (VPConstraint) src;
                String propertyName = evt.getPropertyName();

                if (propertyName.equals(VPConstraintProperties.TYPE)) {
                    Set set = idToFigureMap.get(target.getID());
                    if (set == null) return;

                    //update the figure's display

                    VPConstraintType gType = target.getType();

                    String value = null;

                    if (VPConstraintType.SingleVP.equals(gType)) {
                        value = VPConstraintFigure.Single;
                    } else if (VPConstraintType.MultiVP.equals(gType)) {
                        value = VPConstraintFigure.Multi;
                    } else if (VPConstraintType.AllVP.equals(gType)) {
                        value = VPConstraintFigure.All;
                    }

                    Iterator iterator = set.iterator();
                    while (iterator.hasNext()) {
                        Figure fig = (Figure) iterator.next();
                        fig.setAttribute(VPConstraintFigure.VPType, value);
                        fig.invalidate();
                    }
                }
            } else if (src instanceof CompositeConstraint) {

                CompositeConstraint target = (CompositeConstraint) src;
                String propertyName = evt.getPropertyName();

                if (propertyName.equals(CompositeConstraintProperties.PL_TYPE)) {
                    //find the figure
                    Set set = idToFigureMap.get(target.getID());
                    if (set == null) return;

                    //update the figure's display

                    CompositeConstraintType plType = target.getPLType();

                    Integer value = null;

                    if (CompositeConstraintType.L2R_Implication.equals(plType)) {
                        value = PLFigure.L2R_REQUIRE;
                    } else if (CompositeConstraintType.R2L_Implication.equals(plType)) {
                        value = PLFigure.R2L_REQUIRE;
                    } else if (CompositeConstraintType.Mutex.equals(plType)) {
                        value = PLFigure.MUTEX;
                    } else if (CompositeConstraintType.Equivalence.equals(plType)) {
                        value = PLFigure.EQUIVALENCE;
                    }

                    Iterator iterator = set.iterator();
                    while (iterator.hasNext()) {
                        Figure fig = (Figure) iterator.next();
                        fig.setAttribute(PLFigure.PLType, value);
                        fig.invalidate();
                    }
                } else if (propertyName.equals(CompositeConstraintProperties.SOURCE_TYPE)) {
                    //find the figure
                    Set set = idToFigureMap.get(target.getID());
                    if (set == null) return;

                    //update the figure's display

                    CompositeConstraintPortType sourceType = target.getSourceType();

                    String value = null;

                    if (CompositeConstraintPortType.Single.equals(sourceType)) {
                        value = PLFigure.Single;
                    } else if (CompositeConstraintPortType.Multi.equals(sourceType)) {
                        value = PLFigure.Multi;
                    } else {
                        value = PLFigure.All;
                    }

                    Iterator iterator = set.iterator();
                    while (iterator.hasNext()) {
                        Figure fig = (Figure) iterator.next();
                        fig.setAttribute(PLFigure.SourceType, value);
                        fig.invalidate();
                    }
                } else if (propertyName.equals(CompositeConstraintProperties.SINK_TYPE)) {
                    //find the figure
                    Set set = idToFigureMap.get(target.getID());
                    if (set == null) return;

                    //update the figure's display

                    CompositeConstraintPortType sinkType = target.getSinkType();

                    String value = null;

                    if (CompositeConstraintPortType.Single.equals(sinkType)) {
                        value = PLFigure.Single;
                    } else if (CompositeConstraintPortType.Multi.equals(sinkType)) {
                        value = PLFigure.Multi;
                    } else {
                        value = PLFigure.All;
                    }

                    Iterator iterator = set.iterator();
                    while (iterator.hasNext()) {
                        Figure fig = (Figure) iterator.next();
                        fig.setAttribute(PLFigure.SinkType, value);
                        fig.invalidate();
                    }
                }
            }

            DrawingView view = editorArea.getCurrentView();
            if (view != null)
                view.repairDamage();
        }
    }

    protected class FeatureModelPropertyChangeListener implements PropertyChangeListener {
        public void propertyChange(PropertyChangeEvent evt) {
            Object src = evt.getSource();

            if (!(src instanceof Feature))
                return;

            Feature target = (Feature) src;
            String propertyName = evt.getPropertyName();

            if (propertyName.equals(FeatureProperties.NAME)) {
                //find the figure
                Set set = idToFigureMap.get(target.getID());

                if (set == null) return;

                //update the figure's display
                Iterator iterator = set.iterator();
                while (iterator.hasNext()) {
                    FeatureFigure fig = (FeatureFigure) iterator.next();
                    fig.setText(target.getName());
                    fig.invalidate();
                }

            } else if (propertyName.equals(FeatureProperties.VARIABILITY)) {
                //find the figure
                Set set = idToFigureMap.get(target.getID());

                if (set == null) return;

                //update the figure's display
                Iterator iterator = set.iterator();
                while (iterator.hasNext()) {
                    Figure fig = (Figure) iterator.next();
                    fig.setAttribute(FeatureProperties.VARIABILITY, target.getVariability().getName());
                    fig.invalidate();
                }
            } else if (propertyName.equals(FeatureProperties.BINDINGTIME)){
               //find the figure
                Set set = idToFigureMap.get(target.getID());

                if (set == null) return;

                //update the figure's display
                Iterator iterator = set.iterator();
                while (iterator.hasNext()) {
                    Figure fig = (Figure) iterator.next();
                    fig.setAttribute(FeatureProperties.BINDINGTIME, target.getBindingTime().getName());
                    fig.invalidate();
                }
            }

            DrawingView view = editorArea.getCurrentView();
            if (view != null)
                view.repairDamage();

        }
    }

    public GraphicalEditorUI getGraphicalEditorUI() {

        if (graphicalEditorUI == null) {
            graphicalEditorUI = new GraphicalEditorUIImplementation();
        }

        return graphicalEditorUI;
    }

    public ElementLocator getElementLocator() {

        if (elementLocator == null) {
            elementLocator = new ElementLocatorImplementation();
        }

        return elementLocator;
    }

    public ActionMap getActionMap() {
        return actionMap;
    }

    public DropTargetListener getDropTargetListener() {
        return dropTargetListener;
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        editorArea.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        editorArea.removePropertyChangeListener(listener);
    }

    public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
        editorArea.addPropertyChangeListener(propertyName, listener);
    }

    public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
        editorArea.removePropertyChangeListener(propertyName, listener);
    }

    public ArrayList getSelection() {
        DrawingView currentView = editorArea.getCurrentView();
        if (currentView == null) return null;

        Vector selection = currentView.getSelection();
        if ((selection == null) || (selection.size() <= 0)) return null;

        ArrayList selectionList = new ArrayList(selection.size());
        for (int i = 0; i < selection.size(); i++) {
            Figure fig = (Figure) selection.get(i);
            selectionList.add(fig.getAttribute("id"));
        }

        return selectionList;
    }

    protected class GraphicalEditorUIImplementation implements GraphicalEditorUI {
        public JToolBar getToolBar() {
            return toolBar;
        }

        public JComponent getEditorArea() {
            return editorArea;
        }

        public JComponent getScaleComponent() {
            return scaler;
        }

        public JPopupMenu getEditorAreaPopupMenu() {
            return editorAreaPopupMenu;
        }
    }

    protected class SpinnerValueChangeListener implements ChangeListener {
        public void stateChanged(ChangeEvent e) {
            DrawingView currentView = editorArea.getCurrentView();

            if (currentView != null) {
                Integer number = (Integer) scaler.getModel().getValue();
                double scale = number.intValue() / 100.0;
                currentView.setScale(scale);

                Dimension newSize = currentView.getPageSize();
                newSize.width = (int) (newSize.width * scale);
                newSize.height = (int) (newSize.height * scale);
                ((JComponent) currentView).setSize(newSize);

                ((JComponent) currentView).invalidate();
                ((JComponent) currentView).repaint();

            }
        }
    }

    protected class CurrentViewFigureSelectionChangedListener implements FigureSelectionListener {
        @Override
        public void figureSelectionChanged(DrawingView view) {
            updateAlignActionsUI();
            updateEditActionsUI();
        }
    }

    protected class CurrentViewChangeListener implements PropertyChangeListener {
        public void propertyChange(PropertyChangeEvent e) {
            String propertyName = e.getPropertyName();

            if (propertyName.equals(DrawingEditor.CURRENT_VIEW_CHANGED)) {
                DrawingView oView = (DrawingView) e.getOldValue();
                DrawingView cView = (DrawingView) e.getNewValue();

                if ((oView == null) && (cView != null)) {
                    scaler.setEnabled(true);
                    scaler.validate();
                }

                if ((oView != null) && (cView == null)) {
                    scaler.setEnabled(false);
                    scaler.validate();
                }

                if (cView != null) {
                    int scale = (int) (cView.getScale() * 100);
                    scaler.setValue(new Integer(scale));
                }

                if (oView != null)
                    oView.removeFigureSelectionListener(currentViewFigureSelectionChangedListener);

                if (cView != null)
                    cView.addFigureSelectionListener(currentViewFigureSelectionChangedListener);

                if (dropTarget != null)
                    dropTarget.setComponent((JComponent) cView);
                //dropTarget.setComponent(editorArea);


                changeViewNameAction.putValue(ConstantDefinition.CURRENT_VIEW_NAME, cView.getDrawing().getTitle());
            }

        }
    }

    protected class DrawingEditorPropertyChangeListener implements PropertyChangeListener {

        @Override
        public void propertyChange(PropertyChangeEvent e) {
            String propertyName = e.getPropertyName();

            if (propertyName.equals(DrawingEditor.CURRENT_VIEW_CHANGED)) {
                Object oldV = e.getOldValue();
                Object newV = e.getNewValue();

                if ((oldV == null) && (newV != null)) {
                    if (closeViewAction.isEnabled()) {
                        closeViewAction.firePropertyChange("enabled", Boolean.FALSE, Boolean.TRUE);
                    }
                    if (removeViewAction.isEnabled()) {
                        removeViewAction.firePropertyChange("enabled", Boolean.FALSE, Boolean.TRUE);
                    }
                    if (exportViewAction.isEnabled()) {
                        exportViewAction.firePropertyChange("enabled", Boolean.FALSE, Boolean.TRUE);
                    }

                    if (changeViewNameAction.isEnabled()){
                       changeViewNameAction.firePropertyChange("enabled", Boolean.FALSE, Boolean.TRUE);
                    }

                } else if ((oldV != null) && (newV == null)) {
                    if (!closeViewAction.isEnabled()) {
                        closeViewAction.firePropertyChange("enabled", Boolean.TRUE, Boolean.FALSE);
                    }
                    if (!removeViewAction.isEnabled()) {
                        removeViewAction.firePropertyChange("enabled", Boolean.TRUE, Boolean.FALSE);
                    }
                    if (!exportViewAction.isEnabled()) {
                        exportViewAction.firePropertyChange("enabled", Boolean.TRUE, Boolean.FALSE);
                    }
                    if (!changeViewNameAction.isEnabled()) {
                        changeViewNameAction.firePropertyChange("enabled", Boolean.TRUE, Boolean.FALSE);
                    }
                }

                updateAlignActionsUI();

                figureDeleteAction.putValue(ConstantDefinition.DRAWING_VIEW, newV);
                figureCopyAction.putValue(ConstantDefinition.DRAWING_VIEW, newV);
                figureCutAction.putValue(ConstantDefinition.DRAWING_VIEW, newV);
                figurePasteAction.putValue(ConstantDefinition.DRAWING_VIEW, newV);
                figurePasteAsLinkAction.putValue(ConstantDefinition.DRAWING_VIEW, newV);

                updateEditActionsUI();
            }
        }

    }

    protected void updateAlignActionsUI() {
        boolean newState = leftAlignAction.isEnabled();
        boolean oldState = !newState;

        leftAlignAction.firePropertyChange("enabled", oldState, newState);
        vertAlignAction.firePropertyChange("enabled", oldState, newState);
        rightAlignAction.firePropertyChange("enabled", oldState, newState);

        topAlignAction.firePropertyChange("enabled", oldState, newState);
        horiAlignAction.firePropertyChange("enabled", oldState, newState);
        botAlignAction.firePropertyChange("enabled", oldState, newState);

        newState = vertDistAction.isEnabled();
        oldState = !newState;

        vertDistAction.firePropertyChange("enabled", oldState, newState);
        horiDistAction.firePropertyChange("enabled", oldState, newState);
    }

    protected void updateEditActionsUI() {

        boolean newState = figureDeleteAction.isEnabled();
        boolean oldState = !newState;

        figureDeleteAction.firePropertyChange("enabled", oldState, newState);
        figureCopyAction.firePropertyChange("enabled", oldState, newState);
        figureCutAction.firePropertyChange("enabled", oldState, newState);
        sendToBackAction.firePropertyChange("enabled", oldState, newState);
        sendToFrontAction.firePropertyChange("enabled", oldState, newState);

        newState = figurePasteAction.isEnabled();
        oldState = !newState;
        figurePasteAction.firePropertyChange("enabled", oldState, newState);
        figurePasteAsLinkAction.firePropertyChange("enabled", oldState, newState);

        newState = selectAllAction.isEnabled();
        oldState = !newState;
        selectAllAction.firePropertyChange("enabled", oldState, newState);
        toggleSelectAction.firePropertyChange("enabled", oldState, newState);
       
        //gh start
        newState = this.customizationUndecideAction.isEnabled();
        oldState = !newState;
        this.customizationUndecideAction.firePropertyChange("enabled" , oldState , newState);
        this.customizationSelectAction.firePropertyChange("enabled" , oldState , newState);
        this.customizationUnselectAction.firePropertyChange("enabled" , oldState , newState);
        this.usePatternAction.firePropertyChange("enabled" , oldState , newState);
        //gh end
    }

    protected class AddViewAction extends EditorAction {
        protected boolean isDoing = false;

        protected int count = 0;

        public AddViewAction() {
            this.putValue(Action.NAME, "addView");
            isDoing = false;
        }

        @Override
        public boolean isEnabled() {
            if (!super.isEnabled()) return false;

            String viewName = (String) this.getValue(ConstantDefinition.VIEW_NAME);
            Drawing drawing = (Drawing) this.getValue(ConstantDefinition.DRAWING);

            if ((viewName == null) && (drawing == null)) return false;

            return true;
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;
            if (isDoing) return;

            isDoing = true;

            String viewName = (String) this.getValue(ConstantDefinition.VIEW_NAME);
            Drawing drawing = (Drawing) this.getValue(ConstantDefinition.DRAWING);

            SaturnDrawingView view = createDrawingView();

            if (drawing == null) {
                drawing = createDrawing();
                drawing.setTitle(viewName);
            }

            view.setDrawing(drawing);

            DrawingEditor drawingEditor = (DrawingEditor) getValue(ConstantDefinition.DRAWING_EDITOR);
            drawingEditor.add(view);

            this.putValue(ConstantDefinition.VIEW_NAME, null);
            this.putValue(ConstantDefinition.DRAWING, null);

            isDoing = false;
        }

        protected SaturnDrawingView createDrawingView() {
            return new SaturnDrawingView(1600, 1200);
        }

        protected SaturnDrawing createDrawing() {
            return new SaturnDrawing();
        }
    }

    protected class CloseViewAction extends EditorAction {

        public CloseViewAction() {
            this.putValue(Action.NAME, "closeView");
        }

        public boolean isEnabled() {
            if (!super.isEnabled()) return false;
            if (editorArea.getCurrentView() == null) return false;
            return true;
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            DrawingView currentView = editorArea.getCurrentView();

            String viewName = currentView.getDrawing().getTitle();
            editorArea.close(currentView);

            this.putValue(ConstantDefinition.VIEW_NAME, viewName);

            if (!openViewAction.isEnabled()) {
                openViewAction.firePropertyChange("enabled", Boolean.FALSE, Boolean.TRUE);
            }
        }

    }

    protected class OpenViewAction extends EditorAction {
        public OpenViewAction() {
            this.putValue(Action.NAME, "openView");
        }

        public boolean isEnabled() {
            if (!super.isEnabled()) return false;
            if (editorArea.getClosedViews().length <= 0) return false;
            return true;
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            DrawingView[] views = editorArea.getClosedViews();

            for (int i = 0; i < views.length; i++) {
                editorArea.open(views[i]);
            }
        }
    }

    protected class RemoveViewAction extends EditorAction {
        public RemoveViewAction() {
            this.putValue(Action.NAME, "removeView");
        }

        public boolean isEnabled() {
            if (!super.isEnabled()) return false;
            if (editorArea.getCurrentView() == null) return false;
            return true;
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            DrawingView currentView = editorArea.getCurrentView();

            String viewName = currentView.getDrawing().getTitle();

            selectAllAction.actionPerformed((ActionEvent) null);
            figureDeleteAction.actionPerformed((ActionEvent) null);
            editorArea.remove(currentView);

            this.putValue(ConstantDefinition.VIEW_NAME, viewName);
        }
    }

    protected class ChangeViewNameAction extends EditorAction {
        public ChangeViewNameAction() {
            this.putValue(Action.NAME, "changeViewName");
        }

        public boolean isEnabled() {
            if (!super.isEnabled()) return false;
            if (editorArea.getCurrentView() == null) return false;
            return true;
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            DrawingView currentView = editorArea.getCurrentView();
            String oldViewName = currentView.getDrawing().getTitle();
            String newViewName = (String)this.getValue(ConstantDefinition.NEW_VIEW_NAME);
            this.putValue(ConstantDefinition.NEW_VIEW_NAME, null);

            if ((newViewName == null) || (newViewName.equals(oldViewName)) || (newViewName.trim().equals(""))){
                return;
            }

            DrawingView[] views = editorArea.views();

            for (int i = 0; i < views.length; i ++){
                if (views[i].getDrawing().getTitle().equals(newViewName))
                    return;
            }

            editorArea.changeViewName(currentView, newViewName);

            this.putValue(ConstantDefinition.OLD_VIEW_NAME, oldViewName);
            this.putValue(ConstantDefinition.NEW_VIEW_NAME, newViewName);

            this.putValue(ConstantDefinition.CURRENT_VIEW_NAME, newViewName);
        }
    }

    protected class ToggleSelectAction extends EditorAction {
        public ToggleSelectAction() {
            this.putValue(Action.NAME, "����ѡ��");
        }

        public boolean isEnabled() {
            if (!super.isEnabled()) return false;
            if (editorArea.getCurrentView() == null) return false;
            return true;
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            DrawingView view = editorArea.getCurrentView();
            FigureEnumeration fe = view.getDrawing().getFigures();
            while (fe.hasMoreElements()) {
                Figure f = fe.nextFigure();
                view.toggleSelection(f);
            }

            view.repairDamage();
        }
    }

    protected class SelectAllAction extends EditorAction {
        public SelectAllAction() {
            this.putValue(Action.NAME, "ȫ��ѡ��");
        }

        public boolean isEnabled() {
            if (!super.isEnabled()) return false;
            if (editorArea.getCurrentView() == null) return false;
            return true;
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            DrawingView view = editorArea.getCurrentView();
            view.addToSelectionAll(view.getDrawing().getFigures());
            view.repairDamage();
        }
    }

    protected class SendToBackAction extends EditorAction {
        public SendToBackAction() {
            this.putValue(Action.NAME, "�����ײ�");
        }

        public boolean isEnabled() {
            if (!super.isEnabled()) return false;
            if (editorArea.getCurrentView() == null) return false;
            return true;
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            DrawingView view = editorArea.getCurrentView();
            FigureEnumeration fe = new ReverseFigureEnumerator(view.getSelectionZOrdered());

            while (fe.hasMoreElements()) {
                view.getDrawing().sendToBack(fe.nextFigure());
            }
            view.checkDamage();
        }
    }

    protected class SendToFrontAction extends EditorAction {
        public SendToFrontAction() {
            this.putValue(Action.NAME, "��������");
        }

        public boolean isEnabled() {
            if (!super.isEnabled()) return false;
            if (editorArea.getCurrentView() == null) return false;
            return true;
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            DrawingView view = editorArea.getCurrentView();
            FigureEnumeration fe = new ReverseFigureEnumerator(view.getSelectionZOrdered());

            while (fe.hasMoreElements()) {
                view.getDrawing().bringToFront(fe.nextFigure());
            }
            view.checkDamage();
        }
    }

    protected class ExportViewAction extends EditorAction {

        public static final int TRANSPARENT_BG_COLOR = 0x00efefef;

        public ExportViewAction() {
            this.putValue(Action.NAME, "exportView");
        }

        public boolean isEnabled() {
            if (!super.isEnabled()) return false;
            if (editorArea.getCurrentView() == null) return false;
            return true;
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            DrawingView view = editorArea.getCurrentView();

            JComponent comp = (JComponent) view;

            File imageFile = (File) this.getValue(ConstantDefinition.FILE);

            String imageType = (String) this.getValue(ConstantDefinition.IMAGE_TYPE);

            Image image = null;
            Graphics2D g2d = null;

            //get image information
            if (imageType.equalsIgnoreCase("gif")) {
                Rectangle rect = GlobalFunction.checkMinimumViewport(view);
                Dimension size = new Dimension(rect.width + 10, rect.height + 10);

                image = comp.createImage(size.width, size.height);

                g2d = (Graphics2D) image.getGraphics();
                g2d.setColor(new Color(TRANSPARENT_BG_COLOR));
                g2d.fillRect(0, 0, (int) size.getWidth(), (int) size.getHeight());

                g2d.translate(-rect.x + 5, -rect.y + 5);

                view.drawDrawing(g2d);

            } else if (imageType.equalsIgnoreCase("svg")) {
                // Get a DOMImplementation
                DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();

                // Create an instance of org.w3c.dom.Document
                Document document = domImpl.createDocument(null, "svg", null);

                SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);

                //ctx.setEmbeddedFontsOn(true);
                // Create an instance of the SVG Generator
                g2d = new SVGGraphics2D(ctx, false);

                Rectangle rect = GlobalFunction.checkMinimumViewport(view);
                Dimension size = new Dimension(rect.width + 10, rect.height + 10);

                g2d.translate(-rect.x + 5, -rect.y + 5);
                ((SVGGraphics2D) g2d).setSVGCanvasSize(size);

                view.drawDrawing(g2d);

            } else if (imageType.equalsIgnoreCase("emf")) {

            }

            //write image into file
            try {

                if (imageType.equalsIgnoreCase("gif")) {
                    FileOutputStream out = new FileOutputStream(imageFile);
                    FilteredImageSource fis =
                            new FilteredImageSource(image.getSource(),
                                    new TransFilter(TRANSPARENT_BG_COLOR));
                    GifEncoder ge = new GifEncoder(fis, out);
                    ge.encode();
                    out.flush();
                    out.close();
                } else if (imageType.equalsIgnoreCase("svg")) {
                    FileOutputStream out = new FileOutputStream(imageFile);
                    boolean useCSS = true; // we want to use CSS style attribute
                    //Writer outer = new OutputStreamWriter(out, "iso8859-1");
                    Writer outer = new OutputStreamWriter(out, "UTF-8");
                    ((SVGGraphics2D) g2d).stream(outer, useCSS);
                    outer.flush();
                    outer.close();
                } else {
                    //version 2
                    Rectangle rect = GlobalFunction.checkMinimumViewport(view);
                    Dimension size = new Dimension((rect.x + rect.width) * 2 + 5, (rect.y + rect.height) * 2 + 5);

                    Dimension oldSize = view.getSize();
                    ((SaturnDrawingView) view).setSizeTemp(size);

                    /**
                     SaveAsDialog saveAs = new SaveAsDialog();
                     saveAs.addAllExportFileTypes();
                     saveAs.showExportDialog((Component) getValue(de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.UI_FRAME),
                     "����ͼ���ʽ", (Component) view, view.getDrawing().getTitle());
                     **/

                    exportDialog.showExportDialog((Component) getValue(de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.UI_FRAME), "Export view as ...", (Component) view, view.getDrawing().getTitle());

                    ((SaturnDrawingView) view).setSizeTemp(oldSize);
                }
            } catch (IOException ioe) {
                System.out.println(ioe);
            } finally {
                if (g2d != null)
                    g2d.dispose();

                this.putValue(ConstantDefinition.FILE, null);
                this.putValue(ConstantDefinition.IMAGE_TYPE, null);
            }

        }

        /**
         * RGBImageFilter that turns on transparency for pixels of a specified color.
         */
        class TransFilter extends RGBImageFilter {
            int _transBG;

            public TransFilter(int bg) {
                _transBG = bg;
                canFilterIndexColorModel = true;
            }

            public int filterRGB(int x, int y, int rgb) {
                // background color w/any alpha level? make it transparent
                if ((rgb & 0x00ffffff) == _transBG) return _transBG;
                return 0xff000000 | rgb;  // make it 100% opaque
            }
        }
    }


    protected abstract class EditorAction extends AbstractAction {
        public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
            super.firePropertyChange(propertyName, oldValue, newValue);
        }
    }

    protected abstract class AlignAction extends EditorAction {

        protected transient Rectangle rect = null;

        public boolean isEnabled() {
            if (!super.isEnabled()) return false;

            DrawingView currentView = editorArea.getCurrentView();
            if (currentView == null) return false;

            Vector selection = currentView.getSelection();

            if (selection == null) return false;
            if (selection.size() < 2) return false;

            //AlignAction����connectionFigure��Ч�����Ҫ�жϵ�ǰѡ���ͼԪ�з�connectionFigure����Ŀ�Ƿ����2
            Iterator iterator = selection.iterator();
            int figureCount = 0;

            while (iterator.hasNext()) {
                Figure figure = (Figure) iterator.next();
                if (!(figure instanceof ConnectionFigure))
                    figureCount++;
            }

            if (figureCount < 2) return false;

            return true;
        }

        protected void caculateAffectedArea() {

            Vector selection = editorArea.getCurrentView().getSelection();

            Iterator iterator = selection.iterator();

            rect = null;

            while (iterator.hasNext()) {
                Figure figure = (Figure) iterator.next();
                if (!(figure instanceof ConnectionFigure)) {
                    if (rect == null) {
                        rect = figure.getDisplayBox();
                    } else {
                        rect.add(figure.getDisplayBox());
                    }
                }
            }

        }
    }

    protected abstract class DistAction extends EditorAction {

        protected transient Rectangle rect = null;

        public boolean isEnabled() {
            if (!super.isEnabled()) return false;

            DrawingView currentView = editorArea.getCurrentView();
            if (currentView == null) return false;

            Vector selection = currentView.getSelection();

            if (selection == null) return false;
            if (selection.size() < 3) return false;

            //DistAction����connectionFigure��Ч�����Ҫ�жϵ�ǰѡ���ͼԪ�з�connectionFigure����Ŀ�Ƿ����3
            Iterator iterator = selection.iterator();
            int figureCount = 0;

            while (iterator.hasNext()) {
                Figure figure = (Figure) iterator.next();
                if (!(figure instanceof ConnectionFigure))
                    figureCount++;
            }

            if (figureCount < 3) return false;

            return true;
        }

        protected void caculateAffectedArea() {

            Vector selection = editorArea.getCurrentView().getSelection();

            Iterator iterator = selection.iterator();

            rect = null;

            while (iterator.hasNext()) {
                Figure figure = (Figure) iterator.next();
                if (!(figure instanceof ConnectionFigure)) {
                    if (rect == null) {
                        rect = new Rectangle(figure.center().x, figure.center().y, 0, 0);
                    } else {
                        rect.add(figure.center());
                    }
                }
            }

        }

    }

    protected class LeftAlignAction extends AlignAction {

        public LeftAlignAction() {
            this.putValue(Action.NAME, "��˶���");
            try{
//              this.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("image/align_left.gif")));
              this.putValue(Action.SMALL_ICON, new ImageIcon(new URL(WebConstantDefinition.RES_HOST+"align_left.gif")));
            }catch(Exception e){
              e.printStackTrace();
            }
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            caculateAffectedArea();

            Vector selection = editorArea.getCurrentView().getSelection();

            Iterator iterator = selection.iterator();

            Rectangle r = new Rectangle();
            int limit = rect.x;
            while (iterator.hasNext()) {
                Figure figure = (Figure) iterator.next();
                if (!(figure instanceof ConnectionFigure)) {
                    figure.moveBy(limit - figure.getDisplayBox(r).x, 0);
                }
            }

            editorArea.getCurrentView().repairDamage();
        }
    }

    protected class VertAlignAction extends AlignAction {

        public VertAlignAction() {
            this.putValue(Action.NAME, "��ֱ����");
            try{
              this.putValue(Action.SMALL_ICON, new ImageIcon(new URL(WebConstantDefinition.RES_HOST+"align_vertical.gif")));
            }catch(Exception e){
              e.printStackTrace();
            }
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            caculateAffectedArea();

            Vector selection = editorArea.getCurrentView().getSelection();

            Iterator iterator = selection.iterator();

            Rectangle r = new Rectangle();
            int limit = rect.x + rect.width / 2;
            while (iterator.hasNext()) {
                Figure figure = (Figure) iterator.next();
                if (!(figure instanceof ConnectionFigure)) {
                    figure.moveBy(limit - figure.center().x, 0);
                }
            }

            editorArea.getCurrentView().repairDamage();
        }
    }

    protected class RightAlignAction extends AlignAction {

        public RightAlignAction() {
            this.putValue(Action.NAME, "�Ҷ˶���");
            try{
//              this.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("image/align_right.gif")));
              this.putValue(Action.SMALL_ICON, new ImageIcon(new URL(WebConstantDefinition.RES_HOST+"align_right.gif")));
            }catch(Exception e){
              e.printStackTrace();
            }
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            caculateAffectedArea();

            Vector selection = editorArea.getCurrentView().getSelection();

            Iterator iterator = selection.iterator();

            Rectangle r = new Rectangle();
            int limit = rect.x + rect.width;
            while (iterator.hasNext()) {
                Figure figure = (Figure) iterator.next();
                if (!(figure instanceof ConnectionFigure)) {
                    figure.moveBy(limit - (figure.getDisplayBox(r).x + r.width), 0);
                }
            }

            editorArea.getCurrentView().repairDamage();
        }
    }

    protected class TopAlignAction extends AlignAction {

        public TopAlignAction() {
            this.putValue(Action.NAME, "���˶���");
            this.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("image/align_top.gif")));
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            caculateAffectedArea();

            Vector selection = editorArea.getCurrentView().getSelection();

            Iterator iterator = selection.iterator();

            Rectangle r = new Rectangle();
            int limit = rect.y;
            while (iterator.hasNext()) {
                Figure figure = (Figure) iterator.next();
                if (!(figure instanceof ConnectionFigure)) {
                    figure.moveBy(0, limit - figure.getDisplayBox(r).y);
                }
            }

            editorArea.getCurrentView().repairDamage();
        }
    }

    protected class HoriAlignAction extends AlignAction {

        public HoriAlignAction() {
            this.putValue(Action.NAME, "ˮƽ����");
            try{
              this.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("image/align_right.gif")));
              this.putValue(Action.SMALL_ICON, new ImageIcon(new URL(WebConstantDefinition.RES_HOST+"align_right.gif")));
            }catch(Exception e){
              e.printStackTrace();
            }
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            caculateAffectedArea();

            Vector selection = editorArea.getCurrentView().getSelection();

            Iterator iterator = selection.iterator();

            Rectangle r = new Rectangle();
            int limit = rect.y + rect.height / 2;
            while (iterator.hasNext()) {
                Figure figure = (Figure) iterator.next();
                if (!(figure instanceof ConnectionFigure)) {
                    figure.moveBy(0, limit - figure.center().y);
                }
            }

            editorArea.getCurrentView().repairDamage();
        }
    }

    protected class BotAlignAction extends AlignAction {

        public BotAlignAction() {
            this.putValue(Action.NAME, "�׶˶���");
            try{
//              this.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("image/align_bottom.gif")));
              this.putValue(Action.SMALL_ICON, new ImageIcon(new URL(WebConstantDefinition.RES_HOST+"align_bottom.gif")));
            }catch(Exception e){
              e.printStackTrace();
            }
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            caculateAffectedArea();

            Vector selection = editorArea.getCurrentView().getSelection();

            Iterator iterator = selection.iterator();

            Rectangle r = new Rectangle();
            int limit = rect.y + rect.height;
            while (iterator.hasNext()) {
                Figure figure = (Figure) iterator.next();
                if (!(figure instanceof ConnectionFigure)) {
                    figure.moveBy(0, limit - (figure.getDisplayBox(r).y + r.height));
                }
            }

            editorArea.getCurrentView().repairDamage();
        }
    }

    protected class VertDistAction extends DistAction {

        ArrayList arrayList = new ArrayList();

        public VertDistAction() {
            this.putValue(Action.NAME, "��ֱ�ֲ�");
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            caculateAffectedArea();

            Iterator iterator = editorArea.getCurrentView().getSelection().iterator();
            int figureCount = 0;

            arrayList.clear();

            while (iterator.hasNext()) {
                Figure figure = (Figure) iterator.next();
                if (!(figure instanceof ConnectionFigure)) {
                    figureCount++;

                    Point center = figure.center();
                    if (arrayList.isEmpty()) {
                        arrayList.add(figure);
                    } else {
                        int i;
                        for (i = 0; i < arrayList.size(); i++) {
                            Figure fig = (Figure) arrayList.get(i);
                            if (center.y < fig.center().y) {
                                arrayList.add(i, figure);
                                break;
                            }
                        }

                        if (i == arrayList.size())
                            arrayList.add(figure);
                    }

                }
            }

            int filled = 0;
            for (int i = 0; i < arrayList.size(); i++) {
                Figure fig = (Figure) arrayList.get(i);

                if ((i == 0) || (i == arrayList.size() - 1)) {
                    filled += fig.getDisplayBox().height / 2;
                } else {
                    filled += fig.getDisplayBox().height;
                }

            }

            double unit = (rect.height * 1.0 - filled) / (figureCount - 1);

            Rectangle r = ((Figure) arrayList.get(0)).getDisplayBox();
            int base = r.y + r.height;
            for (int i = 1; i < arrayList.size() - 1; i++) {
                Figure fig = (Figure) arrayList.get(i);
                fig.moveBy(0, (int) (base + unit * i - fig.getDisplayBox(r).y));
                base += r.height;
            }

            editorArea.getCurrentView().repairDamage();
        }
    }

    protected class HoriDistAction extends DistAction {

        ArrayList arrayList = new ArrayList();

        public HoriDistAction() {
            this.putValue(Action.NAME, "ˮƽ�ֲ�");
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            caculateAffectedArea();

            Iterator iterator = editorArea.getCurrentView().getSelection().iterator();
            int figureCount = 0;

            arrayList.clear();

            while (iterator.hasNext()) {
                Figure figure = (Figure) iterator.next();
                if (!(figure instanceof ConnectionFigure)) {
                    figureCount++;

                    Point center = figure.center();
                    if (arrayList.isEmpty()) {
                        arrayList.add(figure);
                    } else {
                        int i;
                        for (i = 0; i < arrayList.size(); i++) {
                            Figure fig = (Figure) arrayList.get(i);
                            if (center.x < fig.center().x) {
                                arrayList.add(i, figure);
                                break;
                            }
                        }

                        if (i == arrayList.size())
                            arrayList.add(figure);
                    }

                }
            }

            int filled = 0;
            for (int i = 0; i < arrayList.size(); i++) {
                Figure fig = (Figure) arrayList.get(i);

                if ((i == 0) || (i == arrayList.size() - 1)) {
                    filled += fig.getDisplayBox().width / 2;
                } else {
                    filled += fig.getDisplayBox().width;
                }

            }

            double unit = (rect.width * 1.0 - filled) / (figureCount - 1);

            Rectangle r = ((Figure) arrayList.get(0)).getDisplayBox();
            int base = r.x + r.width;
            for (int i = 1; i < arrayList.size() - 1; i++) {
                Figure fig = (Figure) arrayList.get(i);
                fig.moveBy((int) (base + unit * i - fig.getDisplayBox(r).x), 0);
                base += r.width;
            }

            editorArea.getCurrentView().repairDamage();
        }
    }

    protected class ChangeColorAction extends EditorAction {
        protected String attributeName;

        public ChangeColorAction(String name, String attributeName) {
            this.putValue(Action.NAME, name);
            this.attributeName = attributeName;
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            Component uiFrame = (Component) this.getValue(ConstantDefinition.UI_FRAME);

            FigureEnumeration fe = editorArea.getCurrentView().selectionElements();

            Figure first = null;

            if(fe.hasMoreElements())
                first = fe.nextFigure();
            else
                return;

            Color current  = (Color) first.getAttribute(attributeName);

            Color color = showDialog(uiFrame, "��ѡ����ɫ", current);

            if (color == null) return;

            first.setAttribute(attributeName, color);
            while (fe.hasMoreElements()) {
                fe.nextFigure().setAttribute(attributeName, color);
            }

            editorArea.getCurrentView().checkDamage();
        }
    }

    //gh start
    protected CustomizationUndecideAction customizationUndecideAction = null;
    protected CustomizationSelectAction customizationSelectAction = null;
    protected CustomizationUnselectAction customizationUnselectAction = null;
   
    protected class CustomizationAction extends EditorAction {
        private Customization state = Customization.Undecided;
       
        public CustomizationAction(Customization state) {
          this.state = state;
        }

        @Override
        public boolean isEnabled() {
            if (!super.isEnabled()) return false;
            if (editorArea.getCurrentView() == null) return false;

      CustomizationVersion cv = (CustomizationVersion)getContext().getValue(ConstantDefinition.CURRENT_CUSTOMIZATION_VERSION);
            if (cv == null) {
              return false;
            }
           
            boolean result = false;
            List selection = getSelection();
            if (selection != null) {
              for (int i = 0; i < selection.size(); i++) {
                  String fID = (String) selection.get(i);
                  result = result || cv.isFeatureCustomizable(fID);
              }
            }

            return result;
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;
     
      CustomizationVersion cv = (CustomizationVersion)getContext().getValue(ConstantDefinition.CURRENT_CUSTOMIZATION_VERSION);
     
            List selection = getSelection();
            if (selection != null) {
              for (int i = 0; i < selection.size(); i++) {
                  String fID = (String) selection.get(i);
                  if (cv.isFeatureCustomizable(fID)) {
                Set set = (Set)idToFigureMap.get(fID);
                for (Iterator itFigure = set.iterator() ; itFigure.hasNext() ; ) {
                    Figure figure = (Figure)itFigure.next();
                    cv.setCustomization(fID, state);
                    figure.setAttribute(ConstantDefinition.CURRENT_CUSTOMIZATION_CUSTOMIZABLE , new Boolean(cv.isFeatureCustomizable(fID)));
              figure.setAttribute(ConstantDefinition.CURRENT_CUSTOMIZATION, state);
                   }
                  }
              }
             
              editorArea.getCurrentView().drawingRequestUpdate(null);
            }
        }
//
//        public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
//            super.firePropertyChange(propertyName, oldValue, newValue);
//        }
   }
   
    protected class CustomizationUndecideAction extends CustomizationAction {
      public CustomizationUndecideAction()  {
            super(Customization.Undecided);
            this.putValue(Action.NAME, "��ԭ");
      }
    }
   
    protected class CustomizationSelectAction extends CustomizationAction {
      public CustomizationSelectAction() {
        super(Customization.Selected);
            this.putValue(Action.NAME, "ѡ��");
      }
    }
   
    protected class CustomizationUnselectAction extends CustomizationAction {
      public CustomizationUnselectAction() {
        super(Customization.Unselected);
            this.putValue(Action.NAME, "�Ƴ�");
      }
    }
   
    public CustomizationUndecideAction getCustomizationUndecideAction() {
      return customizationUndecideAction;
    }
   
    public CustomizationSelectAction getCustomizationSelectAction() {
      return customizationSelectAction;
    }
   
    public CustomizationUnselectAction getCustomizationUnselectAction() {
      return customizationUnselectAction;
    }
//    public PatternGraphicalEditor pge;
//    protected PasteFeatureTreeAction pasteFeatureTreeAction = new PasteFeatureTreeAction();
//    public PasteFeatureTreeAction getPasteFeatureTreeAction() {
//      return this.pasteFeatureTreeAction;
//    }
//    protected class PasteFeatureTreeAction extends EditorAction {
//        public PasteFeatureTreeAction() {
//            this.putValue(Action.NAME, "����ģ��");
//       }
//
//        public boolean isEnabled() {
//            if (!super.isEnabled()) return false;
//            if (editorArea.getCurrentView() == null) return false;
//
//            List selection = getSelection();
//            if (selection != null && selection.size()==1 && featureModel.containsFeature((String)selection.get(0))) {
//              return true;
//            }
//
//            return false;
//        }
//
//        public void actionPerformed(ActionEvent e) {
//            if (!isEnabled()) return;
//      Feature rSrc = null;
//      Iterator<Feature> itFeature = pge.featureModel.getAllFeature().values().iterator();
//      if (itFeature.hasNext())
//        rSrc = pge.featureModel.getRootFeature(itFeature.next().getID());
//
//            List selection = getSelection();
//            if (selection.size()>0 && rSrc!=null)
//              FeatureModelHelper.pasteFeatureTree(
//                rSrc, pge.featureModel , pge.constraintModel
//                , pge.getEditorArea().getCurrentView() , featureModel.getFeature((String)selection.get(0))
//                , featureModel , constraintModel , editorArea.getCurrentView()
//                , (FeatureModelEditor)getContext().getValue(GraphicalEditor.FEATURE_MODEL_EDITOR)
//                , (FeatureEditor)getContext().getValue(GraphicalEditor.FEATURE_EDITOR));
//           
//          
//        }
//   }
   
    protected UsePatternAction_Base usePatternAction = new UsePatternAction_Base();
   
    public UsePatternAction_Base getUsePatternAction_Base() {
      return this.usePatternAction;
    }
   
    protected class UsePatternAction_Base extends EditorAction {
        public UsePatternAction_Base() {
            this.putValue(Action.NAME, "Use Pattern");
        }

        @Override
        public boolean isEnabled() {
            if (!super.isEnabled()) return false;
            if (editorArea.getCurrentView() == null) return false;
           
            return getSelection()!=null;
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            List selection = getSelection();
            if (selection != null) {
              PatternBase pb = (PatternBase)getContext().getValue(de.FeatureModellingTool.Pattern.ConstantDefinition.PATTERN_BASE);
              Component container = (Component)getContext().getValue("CONTAINER");
             
              PatternSelection patternSelection = new PatternSelection(pb);
        int result = JOptionPane.showConfirmDialog(container , patternSelection, "��ѡ����ҪӦ�õ�ģʽ", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);
       
        if (result == JOptionPane.OK_OPTION && patternSelection.template!=null) {
          Hashtable<String , Integer> htCount = patternSelection.getCloneCount();
 
          Feature root = (Feature)patternSelection.template.getFeatureModel().getAllFeature().values().iterator().next();
          root = patternSelection.template.getFeatureModel().getRootFeature(root.getID());
         
                for (int i = 0; i < selection.size(); i++) {
                    String fID = (String) selection.get(i);
                    Feature feature = featureModel.getFeature(fID);
                    if (feature!=null) {
                      Hashtable<String , String>nameMap = new Hashtable<String , String>();
                      Hashtable<String , Figure>figureMap = new Hashtable<String , Figure>();
                       
                        FeatureEditor featureEditor = (FeatureEditor) getContext().getValue(de.FeatureModellingTool.GraphicalEditor.GraphicalEditor.FEATURE_EDITOR);
                        FeatureModelEditor featureModelEditor = (FeatureModelEditor) getContext().getValue(de.FeatureModellingTool.GraphicalEditor.GraphicalEditor.FEATURE_MODEL_EDITOR);
                       
                        de.FeatureModellingTool.Pattern.FeatureModelHelper.pasteFeatureTree(root, patternSelection.template.getFeatureModel(), patternSelection.template.getConstraintModel(), feature , featureModel, constraintModel, editorArea.getCurrentView(), featureModelEditor , featureEditor , htCount , nameMap , figureMap);
                     
                      AutoLayout layout = new AutoLayout();
                      for (Iterator<String> itFeature=figureMap.keySet().iterator() ; itFeature.hasNext() ; ) {
                        String featureID = itFeature.next();
                        Feature desFeature = featureModel.getFeature(featureID);
                        Figure desFigure = figureMap.get(featureID);
                       
                        layout.addFeature(desFeature, desFigure.size().width, desFigure.size().height);
                      }
                      layout.caculateLayout();
                     
                      Figure rootFigure = figureMap.get(feature.getID());
                      int off_x = rootFigure.getDisplayBox().x - layout.getFeatureLayout(feature).x;
                      int root_off_x;
                      if (off_x<0) {
                        root_off_x = -1 * off_x;
                        off_x = 0;
                      } else {
                        root_off_x = 0;
                      }
                      int off_y = rootFigure.getDisplayBox().y;
                     
                      for (Iterator<String> itFeature=figureMap.keySet().iterator() ; itFeature.hasNext() ; ) {
                        String featureID = itFeature.next();
                        if (featureID.equals(feature.getID())) {
                          rootFigure.moveBy(root_off_x, 0);
                        } else {
                          Feature desFeature = featureModel.getFeature(featureID);
                          Figure desFigure = figureMap.get(featureID);
                         
                          FeatureLayout flo = layout.getFeatureLayout(desFeature);
                          desFigure.moveBy(flo.x + off_x, flo.y + off_y);
                        }
                      }
                    }
                }
        }
          }
        }
    }

//gh end
   
    protected final JColorChooser pane = new JColorChooser(Color.white);
    protected final WindowAdapter windowListener = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            Window w = e.getWindow();
            w.setVisible(false);
        }
    };
    protected final ComponentAdapter componentListener = new ComponentAdapter() {
        public void componentHidden(ComponentEvent e) {
            Window w = (Window) e.getComponent();
            w.dispose();
        }
    };

    protected Color showDialog(Component component, String title, Color color) throws HeadlessException {
        /**
        pane.addChooserPanel(rgbaChooser);
        ColorTracker ok = new ColorTracker(pane);
        JDialog dialog = JColorChooser.createDialog(component, title, true, pane, ok, null);
        dialog.addWindowListener(windowListener);
        dialog.addComponentListener(componentListener);

        dialog.setVisible(true); // blocks until user brings dialog down...

        Color rst = ok.getColor();

        dialog.removeWindowListener(windowListener);
        dialog.removeComponentListener(componentListener);
        pane.removeChooserPanel(rgbaChooser);       

        return rst;
        **/

        AbstractColorChooserPanel[] accp = pane.getChooserPanels();
        for(int i = 0; i < accp.length; i++){
           pane.removeChooserPanel(accp[i]);
        }
        pane.addChooserPanel(rgbaChooser);
        pane.addChooserPanel(hsbaChooser);
        pane.addChooserPanel(dsChooser);

        if(color != null)
            pane.setColor(color);

        ColorTracker ok = new ColorTracker(pane);
        JDialog dialog = JColorChooser.createDialog(component, title, true, pane, ok, null);
        dialog.addWindowListener(windowListener);
        dialog.addComponentListener(componentListener);

        dialog.setVisible(true); // blocks until user brings dialog down...

        Color rst = ok.getColor();

        dialog.removeWindowListener(windowListener);
        dialog.removeComponentListener(componentListener);
        pane.removeChooserPanel(rgbaChooser);
        pane.removeChooserPanel(hsbaChooser);
        pane.removeChooserPanel(dsChooser);

        return rst;
    }

    class ColorTracker implements ActionListener, Serializable {
        JColorChooser chooser;
        Color color;

        public ColorTracker(JColorChooser c) {
            chooser = c;
        }

        public void actionPerformed(ActionEvent e) {
            color = chooser.getColor();
        }

        public Color getColor() {
            return color;
        }
    }

    protected class InerDropTargetListener implements DropTargetListener {
        public void dragEnter(DropTargetDragEvent dtde) {
        }

        public void dragOver(DropTargetDragEvent dtde) {
        }

        public void dropActionChanged(DropTargetDragEvent dtde) {

        }

        public void dragExit(DropTargetEvent dte) {
        }

        public void drop(DropTargetDropEvent dtde) {

            if (!dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                dtde.rejectDrop();
                return;
            }

            Object data = null;

            try {
                //DataFlavor[] flavors = dtde.getTransferable().getTransferDataFlavors();
                //for(int i = 0; i < flavors.length;i ++ ){
                //    System.out.println(flavors[i] + " " + i);
                //}
                data = dtde.getTransferable().getTransferData(DataFlavor.stringFlavor);

                DataFlavor.getTextPlainUnicodeFlavor();
            } catch (Throwable e) {
                dtde.rejectDrop();
                System.out.println(e);
                return;
            }

            String id = null;

            if (String.class.isInstance(data)) {
                id = (String) data;
            } else if (InputStream.class.isInstance(data)) {
                String charset = DataFlavor.stringFlavor.getParameter("charset").trim();
                InputStream input = (InputStream) data;
                InputStreamReader isr = null;

                StringBuffer str = new StringBuffer();
                int in = -1;

                try {
                    while ((in = isr.read()) >= 0) {
                        if (in != 0)
                            str.append((char) in);
                    }
                    id = str.toString();
                } catch (IOException ioe) {
                    dtde.dropComplete(false);
                    return;
                }

            }

            Feature feature = null;
            ResourceComponent rc = null;

            feature = featureModel.getFeature(id);
            if (feature == null)
                rc = interactionModel.getResourceComponent(id);


            if ((feature == null) && (rc == null)) {
                dtde.dropComplete(false);
                return;
            }

            dtde.dropComplete(true);

            DropTarget dropTarget = (DropTarget) dtde.getSource();

            DrawingView drawingView = (DrawingView) dropTarget.getComponent();

            if (feature != null) {
                FeatureFigure ff = new FeatureFigure();
                ff.setAttribute("id", id);
                ff.setAttribute(FeatureFigure.IS_A_LINK, Boolean.TRUE);
                ff.setAttribute("text", feature.getName());
                ff.setAttribute(FeatureProperties.VARIABILITY, feature.getVariability().getName());
                ff.setAttribute(FeatureProperties.BINDINGTIME, feature.getBindingTime().getName());

                Point location = dtde.getLocation();
                double scale = drawingView.getScale();
                int realX = (int) (location.getX() / scale + 0.5);
                int realY = (int) (location.getY() / scale + 0.5);

                ff.basicDisplayBox(new Point(realX, realY), null);

                idToFigureMap.add(id, ff);
                drawingView.add(ff);
            } else if (rc != null) {
                ResourceComponentFigure rcf = new ResourceComponentFigure();
                rcf.setAttribute("id", id);
                rcf.setAttribute(FeatureFigure.IS_A_LINK, Boolean.TRUE);
                rcf.setAttribute("text", rc.getName());
                rcf.setAttribute(FeatureProperties.VARIABILITY, rc.getVariability().getName());

                Point location = dtde.getLocation();
                double scale = drawingView.getScale();
                int realX = (int) (location.getX() / scale + 0.5);
                int realY = (int) (location.getY() / scale + 0.5);

                rcf.basicDisplayBox(new Point(realX, realY), null);

                idToFigureMap.add(id, rcf);
                drawingView.add(rcf);
            }

            drawingView.repairDamage();
        }
    };

    protected class ElementLocatorImplementation implements ElementLocator {

        private TreeSet treeSet = new TreeSet();

        public void locateInCurrentView(String elementID) {
            Set figSet = idToFigureMap.get(elementID);

            if (figSet == null) return;

            DrawingView drawingView = editorArea.getCurrentView();
            drawingView.clearSelection();

            Iterator iterator = figSet.iterator();

            treeSet.clear();

            while (iterator.hasNext()) {
                Figure fig = (Figure) iterator.next();

                if (drawingView.getDrawing().includes(fig)) {
                    String type = (String) fig.getAttribute("type");
                    if ((type != null) && (type.equals("interactionTitle"))) continue;
                    drawingView.addToSelection(fig);
                    treeSet.add(fig);
                }
            }

            drawingView.repairDamage();

            adjustFigureToCenter(drawingView, treeSet.iterator());

        }

        public void locateInDefinitionView(String elementID) {
            Set figSet = idToFigureMap.get(elementID);

            if (figSet == null) return;

            Figure definition = null;

            Iterator iterator = figSet.iterator();

            while (iterator.hasNext()) {
                Figure fig = (Figure) iterator.next();
                Boolean value = (Boolean) fig.getAttribute("isALink");

                if ((value == null) || (!value.booleanValue())) {
                    definition = fig;
                    break;
                }
            }

            DrawingView[] views = editorArea.toArray();

            for (int i = 0; i < views.length; i++) {
                DrawingView drawingView = views[i];
                if (drawingView.getDrawing().includes(definition)) {
                    String type = (String) definition.getAttribute("type");
                    if ((type != null) && (type.equals("interactionTitle"))) continue;
                    drawingView.clearSelection();
                    drawingView.addToSelection(definition);
                    drawingView.repairDamage();
                    editorArea.setCurrentView(drawingView);
                    adjustFigureToCenter(drawingView, definition);
                    break;
                }
            }

        }

        protected void adjustFigureToCenter(DrawingView drawingView, Figure fig) {
            if (!drawingView.getDrawing().includes(fig)) return;

            adjustFigureToCenter(drawingView, fig.getDisplayBox());

        }

        protected void adjustFigureToCenter(DrawingView drawingView, Iterator figIterator) {
            Rectangle rect = null;
            if (figIterator.hasNext()) rect = ((Figure) figIterator.next()).getDisplayBox();

            while (figIterator.hasNext()) {
                Figure fig = (Figure) figIterator.next();
                rect.union(fig.getDisplayBox());
            }

            if (rect == null) return;

            adjustFigureToCenter(drawingView, rect);

        }

        protected void adjustFigureToCenter(DrawingView drawingView, Rectangle rect) {

            if (!(drawingView instanceof JComponent)) return;

            JComponent com = (JComponent) drawingView;

            double scale = drawingView.getScale();
            rect.x = (int) (rect.x * scale);
            rect.y = (int) (rect.y * scale);
            rect.width = (int) (rect.width * scale);
            rect.height = (int) (rect.height * scale);

            rect.x -= rect.width;
            rect.y -= rect.height;
            rect.width *= 3;
            rect.height *= 3;

            if (rect.width < 20) {
                rect.x -= 20;
                rect.width += 40;
            }

            if (rect.height < 20) {
                rect.y -= 20;
                rect.height += 40;
            }

            com.scrollRectToVisible(rect);
        }
    }
   
    //gh start
    public PropertyChangeListener getCurrentCustomizationVersionChangeLisenter() {
      return new CurrentCustomizationVersionChangeLisenter();
    }
   
    protected class CurrentCustomizationVersionChangeLisenter implements PropertyChangeListener {
         public void propertyChange(PropertyChangeEvent e) {
            if (de.FeatureModellingTool.Customize.ConstantDefinition.PROPERTYCHANGE_CURRENTCUSTOMIZATIONVERSION.equals(e.getPropertyName())) {
          CustomizationVersion cv = (CustomizationVersion)e.getNewValue();
                
          getContext().putValue(ConstantDefinition.CURRENT_CUSTOMIZATION_VERSION , cv);
              Set sFigureId = idToFigureMap.keySet();
              for (Iterator itSetId = sFigureId.iterator() ; itSetId.hasNext() ; ) {
                String id = (String)itSetId.next();
                Set set = (Set)idToFigureMap.get(id);
                for (Iterator itFigure = set.iterator() ; itFigure.hasNext() ; ) {
                  Figure figure = (Figure)itFigure.next();
                  if (figure instanceof FeatureFigure) {
                    figure.setAttribute(ConstantDefinition.CURRENT_CUSTOMIZATION_CUSTOMIZABLE , new Boolean(cv == null ? true : cv.isFeatureCustomizable(id)));
                    figure.setAttribute(ConstantDefinition.CURRENT_CUSTOMIZATION , cv == null ? null : cv.getCustomizationById(id));
                  }
                 }
              }
             
              updateEditActionsUI();
              editorArea.getCurrentView().drawingRequestUpdate(null);
            }
       }
    }
    //gh end
}
TOP

Related Classes of de.FeatureModellingTool.GraphicalEditor.GraphicalEditorImplementation$InteractionModelPropertyChangeListener

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.