}
}
public void doConstruction(ConstructionStep step) {
if (step.getConstructionType() == CENTRE_RADIUS) {
Point centre = (Point)step.getInputs()[0];
Object obj1 = step.getInputs()[1];
boolean radiusReference = (obj1 instanceof GeometricalObject);
double radius;
if (radiusReference) {
if (step.getInputs()[1] instanceof Line)
radius = ((Line)obj1).getLength();
else
radius = ((Circle)obj1).getRadius();
}
else {
radius = ((Double)obj1).doubleValue();
if (!(radius > 0)) {
JOptionPane.showMessageDialog(this, "Please enter positive value for " +
"radius", "Try Again", JOptionPane.ERROR_MESSAGE);
initDialog();
}
}
Circle newCircle = new Circle(centre, radius);
newCircle.addToObjects(objects);
if (radiusReference)
if (obj1 instanceof Line) {
((Line)obj1).addPropertyChangeListener(Line.PROP_LENGTH, newCircle);
newCircle.addPropertyChangeListener(Circle.PROP_RADIUS, (Line)obj1);
}
else {
((Circle)obj1).addPropertyChangeListener(Circle.PROP_RADIUS, newCircle);
newCircle.addPropertyChangeListener(Circle.PROP_RADIUS, (Circle)obj1);
}
clearAndHide();
step.setOutputs(new Object[]{newCircle});
fireUndoableEditUpdate(new UndoableEditEvent(this, step));
}
else if (step.getConstructionType() == THREE_POINTS) {
Point point1 = (Point)step.getInputs()[0];
Point point2 = (Point)step.getInputs()[1];
Point point3 = (Point)step.getInputs()[2];
Line line12 = new Line(point1, point2);
Line line23 = new Line(point2, point3);
if (!((line12.isParallel(line23))||(point1.equalTo(point2))
|| (point2.equalTo(point3)) || (point3.equalTo(point1)))) {
Circle newCircle = new Circle(point1, point2, point3);
newCircle.addToObjects(objects);
clearAndHide();
step.setOutputs(new Object[]{newCircle.getCentre(), newCircle});
fireUndoableEditUpdate(new UndoableEditEvent(this, step));