Model-View-Controller (MVC) is the foundational design pattern for graphical user interfaces. In this assignment you'll demonstrate your understanding of MVC by implementing a doodle, or sketching, program. You should also make use of Java Layouts, and standard Swing components where possible.
Your doodle program will have the following attributes:
- It will include a menu bar with a file menu. Within file, you will have options to save and load doodles, to create a new doodle, and to exit the program. Be sure to prompt the user to save before overwriting any changes they've made when creating a new doodle, loading a doodle or exiting the program.
- It will have a palette on the left hand side supporting, at a minimum, color selection and stroke thickness/width (you should display the colors and lines graphically, not as text!). The last button in the color palette should invoke a JColorChooser to select a custom color. When you choose a color from the color palette, the color will be used for any new strokes that you make. Past stroke colors should not be altered and should always be rendered appropriately (i.e. color is part of your model). Similarly for width.
- The main area of the screen is a canvas that supports drawing by using mouse strokes (i.e. drawing one or more lines using the mouse). Mouse down begins a stroke, mouse dragged defines the body of a stroke, and mouse up defines the end of a stroke, using the appropriate color and line width (see above). On mouse up, the playbar (timeline) ticks must be updated such that each tick on the timeline is equally spaced and correponds to the *end* of a stroke.
- At the bottom of the screen, there will be playback controls (JButtons with icons) and a playback bar (JSlider). Initially, there are no ticks on the bar. Each time a stroke is completed a tick is added to the bar.
- The playback controls at the bottom include: a play button that causes the strokes to be drawn, from the current slider position to the end, as they were drawn on the canvas. The start button rewinds to the start of the animation, and the end button goes to the end of the animation (you are free to decide if rewinding automatically starts playing the animation, or if it just moves the scrubber).
- The playback bar must support scrubbing (the ability to move backward and forward through the animation). Minimally (for part marks) stroke may appear or disappear as you move the slider. For full marks, playback animation must include an aspect of time. You can assume, for playback, that each stroke takes constant time to draw (for example, 1s to appear). Another way to think of this: minimally, for part marks, you simply need to show entire strokes. For full marks, you must show point-to-point drawing within the stroke (i.e. polyline). (PS: A neat enhancement would be to accurately represent time for a stroke. This is not required.)
- File saving and loading must be supported using a JFileChooser. You can save in either text or binary formats (you can just serialize an object, for example). Your JFileChooser should filter out just your supported data files (i.e. you should save using a file extension, and filter to show just those files).
- In drawing, if you scrub back, some of your later strokes will vanish on the display. At this point, if you begin drawing, the non-displayed strokes should be removed from your model and new strokes that you create will be appended to the visible strokes on the display. If you begin drawing partway through a previous stroke, that stroke will truncated to just include points up to the new point where you start drawing (and the scrubber will update based on your new line length). This is a simple form of undo/redo, as in on undo, if you start acting, future events (post-undo point) are deleted from the application model.
- Finally, we expect a dynamic layout. The canvas should be fully accessible regardless of the size of the window, by resizing itself to fit the available space. The color chooser and stroke chooser need to expand and contract based upon available space; how the layout changes is a visual design decision left to you. At the bottom of the screen, playback buttons must be positioned approximately as indicated, and the slider should expand and contract appropriately to fill available remaining space. You may set a "reasonable" minimum size (e.g. 400X300, 200X150, etc.). There should be no limit to the maximum size.
- Widget Library
- Layout Managers
- Some 2D graphics (leveraged from A1)
90% of your grade is based on meeting these core requirements.
- MVC Architecture for application, including one model and at least 2 views.
- Drawing in main window, timeline synchronization, playback support.
- Dynamic layout that handles resizing properly (i.e. panels and controls scale during resize).
- Color choosing and width selection supported and explicitly maintained.
- Save and Load supported through file save and file open dialogs. Saving and loading preserves all attributes of model.
- Appropriate use of widgets, and options enabled/disabled in UI (e.g. playback button disabled when no content in drawing, file save disabled when no content in drawing).
- All widgets are Java 8/Swing-based. No third party/platform native code is allowed. You are allowed to use sample code provided in class (including the vecmath.jar file).
10% of your assignment grade is based on the enhancement of your choice. Choose one or more features from the list below totalling 10%.
- When the canvas resizes to fit the available space, it maintains its aspect ratio (i.e. it can only be resized equally in both directions). The canvas is not cut off during resizing (5 marks).
- A View menu in the menu bar contains radio buttons for selecting whether the canvas will resize itself to fit the window (as described above), or instead display scrollbars when the window is too small (new requirement). (5 marks).
- Accurate representation of time. It should take an amount of time to play back a stroke that is proportional to how long it took to draw, and the tick-marks on the playback bar should be spaced appropriately. (10 marks).
- Adding JSON or XML-based saving and loading, in addition to your other data file format (5 marks). If you choose this option, you are allowed to use a third-party JSON andor XML library to process your data. However, you (a) must include the appropriate JAR file in your submission, (b) your makefile `make run` command should include the JAR file, and (c) you should document the use of this JAR file in your README.TXT. Your JFileChooser dialog should be updated to work with both supported file formats (i.e. your basic file format, and this format).
- Ability to play animations both forward and backward (5 marks).
- Customizable color palette, as in you can wholly or partially customize color buttons in palette (5 marks).
- Dynamic use of widgets; if display gets to small, perhaps pull a subset of widgets out of application view to support more compressed presentation of options, e.g. replace stroke width with combo box, color palette with subset of buttons (5 or more depending on extent).
- Undockable toolbars to create floating palettes (10 marks).
- System-level copy paste to support pasting to outside program (e.g. ms paint, photoshop, etc.). (10 marks).
- All files required to build and run your project. If you implemented the JSON/XML enhancement, you should also include relevant JAR files (see above).
- A Makefile that will build, then execute, your project by typing only "make run" from the command line.
- A 'readme.txt' file that documents your application, including the enhancement that you chose.
- Deliverables including makefile and readme.txt.
- All of the functional requirements above (related to drawing, color and width, playback and scrubbing, file save and load functionality).
- Program architecture: implements MVC as described, views stay coordinated.
- Enhancements (up to 10%)
Submit the following to your personal Git repository, in the A2/ folder:
Submission will be assessed roughly as follows:
Versions1.0. Initial version.
1.1. Feb 6. Added JSON/XML libraries to the enhancement specification.
1.2. Feb 8. Adding wording to clarify that the enhancement is required, not optional.
1.3. Feb 14. Changed file-save to only require a single format for full marks. Additional formats can be done for the enhancement (as indicated). Updated JSON/XML requirement to indicate that the enhancement must work with the JFileChooser dialog, and that file formats should be filtered.
1.4. Feb 20. Clarified that there needs to be multiple views.
1.5. Feb 22. Added vecmath.jar to the list of allowed source code.
1.6. Feb 25. Clarified the the play button plays from current position to the end of the animation.