package drawing; import java.util.Collection; import format.*; import java.lang.Math; /** * The abstract class AnnotateTool represents any tool that may be used to * annotate a Layer. */ abstract class AnnotateTool {} /** * The abstract class DrawTool represents any annotation tool (by inheritance) * that may make visible, drawing-like markings on the screen. */ abstract class DrawTool extends AnnotateTool { /** * The color of the drawing that the tool will produce. */ Color color; /** * The line thickness of the drawing that the tool will produce. */ double strokeSize; /** * The draw method creates a Drawing using the selected DrawTool. * @return Returns the Drawing created by the tool. */ /*@ // // No requirements // ensures // // The returned Drawing has the tool's color and stroke size // \result.color == color && \result.strokeSize == strokeSize; @*/ abstract Drawing draw(); } /** * The PenTool represents a tool that mimics the use of a pen. Namely, * it creates freehand, opaque lines. */ class PenTool extends DrawTool { /** * The draw method creates a Drawing with the characteristics of a pen. * @return Returns the Drawing created by the tool. */ Drawing draw() {return null;} } /** * The HighlighterTool represents a tool that mimics the use of a highlighter. * Namely, it creates freehand, semi-transparent markings that allow covered * to show through. */ class HighlighterTool extends DrawTool { /** * The draw method creates a Drawing with the characteristics of a * highlighter. * @return Returns the Drawing created by the tool. */ Drawing draw() {return null;} } /** * The ShapeTool represents a tool that creates a number of different shapes. */ class ShapeTool extends DrawTool { /** * The selected shape for the tool to draw. */ Shape shape; /** * The draw method creates a Drawing with the characteristics of a number * of different shapes. * @return Returns the Drawing created by the tool. */ Drawing draw() {return null;} } /** * The Eraser tool represents a tool that can erase drawings from a layer. */ class EraserTool extends AnnotateTool { /** * The size of the selection area to delete. */ double strokeSize; /** * The erase method removes any drawing from the active layer that is within * strokeSize pixels of the cursor when clicked * @param point The position of the desired area to erase. * @param movedLayer The layer to remove annotations from */ /*@ // // No requirements // ensures // // Any annotation containing a Point within strokeSize distance from // point should be removed from the layer's annotations // (\forall Drawing drawing ; \old(movedLayer.annotations.contains(drawing)) ; (\forall Point drawPoint ; drawing.points.contains(drawPoint) ; !movedLayer.annotations.contains(drawing) <==> Math.sqrt(Math.pow(drawPoint.x - point.x, 2) + Math.pow(drawPoint.y - point.y, 2)) <= strokeSize)); @*/ void erase(layer.Layer movedLayer, Point point) {} } /** * The TextTool represents a tool that can create text annotations on a layer. */ class TextTool extends AnnotateTool { /** * The font of the typed text from the tool. */ Font font; /** * The createTextBox method creates a textbox to be used for typed * annotations. * @param position The Point of the top-left corner of the textbox. * @param width The width of the textbox to create. * @param height The height of the textbox to create. * @return Returns a Textbox with the specified attributes. */ /*@ // // No requirements // ensures // // The returned textbox should have the specified values // \result.position == position && \result.width == width && \result.height == height; @*/ Textbox createTextBox(Point position, int width, int height) {return null;} /** * The drawText method, given a string and textbox, inserts the * text into the textbox at its current cursor location * @param content The string to add to the textbox * @param textbox The textbox to add text to */ /*@ // // No requirements // ensures // // The textbox should get the new specified string as its content // textbox.content == content; @*/ void drawText(String content, Textbox textbox) {} } /** * The Textbox class represents a textbox that has a size, position, * and accompanying text. */ class Textbox { /** * The position of the top-left corner of the box. */ Point position; /** * The width of the box in pixels. */ int width; /** * The height of the box in pixels. */ int height; /** * The font of the text in the textbox. */ Font font; /** * The text that is currently present in the box. */ String content; /** * The current position of the cursor in the textbox. */ int cursorPosition; }