Package research.align

Source Code of research.align.AlignAction

package research.align;

import research.DrawingView;
import research.Figure;
import research.ConnectionFigure;
import research.DrawingEditor;

import java.awt.*;
import java.util.Vector;
import java.util.Iterator;

/**
* Created by IntelliJ IDEA.
* User: saturn
* Date: 2003-10-15
* Time: 18:44:55
* To change this template use Options | File Templates.
*/
abstract class AlignAction extends EditorAction {

    protected transient Rectangle rect = null;

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

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

        if(drawingEditor == null) return false;

        DrawingView currentView = drawingEditor.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() {

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

        Vector selection = drawingEditor.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());
                }
            }
        }

    }
}
TOP

Related Classes of research.align.AlignAction

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.