// AddSeg.java // Command class to add a Segment object to the drawing. // Written by THC for CS 5 HW 3. Modified by Scot Drysdale // for Vornoi Tool. import java.awt.*; public class AddSeg extends Command { private Segment currentSeg = null; // Segment currently being constructed // When the mouse is pressed, remember its position, create a new Segment with // coincident endpoints, and add the new Segment to the front of the drawing. public void executeClick(Point p, Drawing dwg) { if(currentSeg == null) // First point of pair? { currentSeg = new Segment(p, p); dwg.setTempShape(currentSeg); } else // Second point, so add segment to drawing { currentSeg.setEndpoint2(p); dwg.add(currentSeg); currentSeg = null; dwg.setTempShape(null); } } // Update the segment currently being added public void executeMove(Point p, Drawing dwg) { if(currentSeg != null) currentSeg.setEndpoint2(p); } }