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:48:52
* To change this template use Options | File Templates.
*/
abstract class DistAction 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() < 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() {
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 = new Rectangle(figure.center().x, figure.center().y, 0, 0);
} else {
rect.add(figure.center());
}
}
}
}
}