Package research.align

Source Code of research.align.AlignAndDistService$CurrentViewFigureSelectionChangedListener

package research.align;

import context.Context;
import manager.ManagerInterface;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;

import research.DrawingEditor;

import javax.swing.*;

/**
* Created by IntelliJ IDEA.
* User: saturn
* Date: 2003-10-15
* Time: 19:06:19
* To change this template use Options | File Templates.
*/
class AlignAndDistService implements ConstantDefinition {

    protected Context cont;

    //��˶���
    protected AlignAction leftAlignAction = new LeftAlignAction();
    //��ֱ����
    protected AlignAction vertAlignAction = new VertAlignAction();
    //�Ҷ˶���
    protected AlignAction rightAlignAction = new RightAlignAction();
    //���˶���
    protected AlignAction topAlignAction = new TopAlignAction();
    //ˮƽ����
    protected AlignAction horiAlignAction = new HoriAlignAction();
    //�׶˶���
    protected AlignAction botAlignAction = new BotAlignAction();

    //����ֲ�
    protected DistAction vertDistAction = new VertDistAction();
    //����ֲ�
    protected DistAction horiDistAction = new HoriDistAction();

    protected final ContextChangeListener contextChangeListener = new ContextChangeListener();
    protected final CurrentViewFigureSelectionChangedListener currentViewFigureSelectionChangedListener = new CurrentViewFigureSelectionChangedListener();
    protected final CurrentViewChangeListener currentViewChangeListener = new CurrentViewChangeListener();

    public AlignAndDistService() {
        ManagerInterface mi = context.Manager.getInstance();

        try {
            cont = (Context) mi.getInstance(context.Manager.CONTEXT, Context.class);
        } catch (Exception e) {
            e.printStackTrace();
        }

        cont.addContextChangeListener(contextChangeListener);
    }

    public Context getContext() {
        return cont;
    }

    public ActionMap getActionMap() {
        ActionMap actionMap = new ActionMap();

        actionMap.put(LEFT_ALIGN_INTERFACE, leftAlignAction);
        actionMap.put(VERTICAL_ALIGN_INTERFACE, vertAlignAction);
        actionMap.put(RIGHT_ALIGN_INTERFACE, rightAlignAction);

        actionMap.put(TOP_ALIGN_INTERFACE, topAlignAction);
        actionMap.put(HORIZONTAL_ALIGN_INTERFACE, horiAlignAction);
        actionMap.put(BOTTOM_ALIGN_INTERFACE, botAlignAction);

        actionMap.put(VERTICAL_DISTRIBUTION_INTERFACE, vertDistAction);
        actionMap.put(HORIZONTAL_DISTRIBUTION_INTERFACE, horiDistAction);

        return actionMap;

    }

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

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

        if (ConstantDefinition.DRAWING_EDITOR.equals(propertyName)) {
            DrawingEditor drawingEditorOld = (DrawingEditor) e.getOldValue();
            DrawingEditor drawingEditorNew = (DrawingEditor) e.getNewValue();

            leftAlignAction.putValue(ConstantDefinition.DRAWING_EDITOR, drawingEditorNew);
            vertAlignAction.putValue(ConstantDefinition.DRAWING_EDITOR, drawingEditorNew);
            rightAlignAction.putValue(ConstantDefinition.DRAWING_EDITOR, drawingEditorNew);

            topAlignAction.putValue(ConstantDefinition.DRAWING_EDITOR, drawingEditorNew);
            horiAlignAction.putValue(ConstantDefinition.DRAWING_EDITOR, drawingEditorNew);
            botAlignAction.putValue(ConstantDefinition.DRAWING_EDITOR, drawingEditorNew);

            vertDistAction.putValue(ConstantDefinition.DRAWING_EDITOR, drawingEditorNew);
            horiDistAction.putValue(ConstantDefinition.DRAWING_EDITOR, drawingEditorNew);

            if (drawingEditorOld != null) {
                drawingEditorOld.removePropertyChangeListener(DrawingEditor.SELECTION_CHANGED, currentViewFigureSelectionChangedListener);
                drawingEditorOld.removePropertyChangeListener(DrawingEditor.CURRENT_VIEW_CHANGED, currentViewChangeListener);
            }

            if (drawingEditorNew != null) {
                drawingEditorNew.addPropertyChangeListener(DrawingEditor.SELECTION_CHANGED, currentViewFigureSelectionChangedListener);
                drawingEditorNew.addPropertyChangeListener(DrawingEditor.CURRENT_VIEW_CHANGED, currentViewChangeListener);
            }

            updateState();
        }
    }

    protected class CurrentViewFigureSelectionChangedListener implements PropertyChangeListener {
        public void propertyChange(PropertyChangeEvent e) {
            String propertyName = e.getPropertyName();
            if (propertyName.equals(DrawingEditor.SELECTION_CHANGED)) {
                updateState();
            }
        }
    }

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

            if (propertyName.equals(DrawingEditor.CURRENT_VIEW_CHANGED)) {
                updateState();
            }
        }
    }

    protected void updateState() {
        Boolean newState;
        Boolean oldState;

        newState = Boolean.valueOf(leftAlignAction.isEnabled());
        oldState = Boolean.valueOf(!newState.booleanValue());

        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 = Boolean.valueOf(vertDistAction.isEnabled());
        oldState = Boolean.valueOf(!newState.booleanValue());

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

}
TOP

Related Classes of research.align.AlignAndDistService$CurrentViewFigureSelectionChangedListener

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.