Selection and editing of annotations

Lab 3: Selecting and editing annotations

There are two things you may have noticed after Lab 2: first, the interaction of showing either the photo or the annotations, while an interesting idea based on the practice of drawing on the back of a photo, doesn’t really work out so well. The second is that we would like to be able to interact with our annotations, such as to move them around.

In this homework, we’re going to take advantage of the MVC design we created in Lab 2 to refactor our design. We’re going to change the drawing of our annotations such that the double-click to flip the photo will instead just toggle the drawing of annotations on top of the photo. (This part of the assignment probably only involves changing one or a couple lines of code.)

Second, we want to handle selecting, moving, and editing our annotations. To handle this, you’ll probably need to refactor your photo component. You’ll need to handle picking: when the user clicks on the component, you’ll need to map that click to whatever object, if any, was clicked. This will also involve some kind of a hit testing algorithm to see if a given position intersects with a given annotation.

You’ll also need to handle selection: keeping track of what object is selected. For this assignment, you can handle the simple case where the user can choose one object to select by clicking on it. If the user clicks on another object, the new object is selected. If the user clicks on the background, then the selection becomes empty.

The user should be able to change the color of a selected annotation. You may want to add a toolbar button that shows a JColorChooser to set the color of the selection annotation.

Bonus tasks

  • [State Machines] β€” Extend your component using Swing States to use a state machine to manage the various input events and associated state. If you refactor your annotations to use a CStateMachine and CShapes for your annotations, you get picking β€œfor free”. If you have an existing solution that works, you may find it easier to use a BasicInputStateMachine. You can use a tag to manage selections of annotations. (4 points)

  • [Multiple selections] β€” handle multiple selected annotations to move or edit multiple annotations at the same time. Shift-clicking an unselected annotation should add it to the current selection. Shift-clicking a selected annotation should remove it from the current selection. (2 points)

Deliverable

Submit your completed assignment using the class Moodle.