Assignments | Course Home | Documentation | Linux Lab Hours | Schedule & Lecture Notes | Submit

Saint Louis University

Computer Science 290
Object-Oriented Software Design

Michael Goldwasser

Fall 2011

Dept. of Math & Computer Science

Assignment 03

Improved SceneEditor

Contents:


Overview

Topic: Improved SceneEditor
Related Reading: Ch. 6 of text
Due: Tuesday, 11 October 2011, 11:59pm

For this assignment, we make several improvements to the SceneEditor project from Chapter 6 of the text.


Collaboration Policy

For this assignment, you may work in pairs (if you are having trouble finding a partner, please contact me as soon as possible).

Please make sure you adhere to the policies on academic integrity in this regard.


Formal Requirements

Our goal is to make the following four improvements to the SceneEditor application (based upon the scene3 implementation from the textbook).

  1. Rather than displaying basic outlined forms for the shapes, we wish to allow concrete shape classes to use a combination of both outlined and filled shapes. For example, the car should be displayed with filled body and tires, but the outlined roof.

  2. Rather than highlighting selected shapes using the template pattern in the book, we would like to display control points at the corners of a selected shape's bounding box (we use circles of radius 2 for our highlights).

  3. The book has an aggravating user interface in the following respect. If you click and drag on a previously selected shape, that shape is not translated because the initial mouse click has the effect of deselecting the shape prior to the mouse drag.

    We prefer the following behavior. A standard mouse click should toggle the selected state, as with the original program. If a mouse press/drag begins on an unselected shape, the shape should become selected and immediately dragged. However if a mouse press/drag begins on a selected shape, we wish to have that shape remain selected and consequentially dragged.

  4. We want to allow the user to resize a selected shape by dragging any of the control points. For example, if the user clicks and drags the top-right control point, the shape should resize automatically so that the top-right corner of the bounding box aligns with the moving mouse pointer (the bottom-left corner in this case should remain fixed).

    For the regular assignment, you may assume that the user will never drag the moving corner beyond the extent of the opposite fixed corner. That is, if the top-right corner is being moved, the user is presumed to keep it above and to the right of the bottom-left corner. (see extra credit description for more robust behavior).


Demonstration

Since a picture is worth a thousand words, we offer the following demonstration of all four improvements.


Advice

We address each of the four desired improvements.

  1. We have already implemented the first improvement to allow a mix of filled and outlined components for a shape. To do this, we have had to modify the CompoundShape class as well as minor modifications to both the CarShape and HouseShape classes.

    Within the CompoundShape class we still maintain the private GeneralPath instance for the outlined versions of all shapes. But we have added an additional Area instance for the filled shapes. We have modified the add method to include a boolean flag as a second parameter to designate whether each new piece should be filled. In either case it is added to the GeneralPath, yet in the filled case it is also added to the Area instance.

    Please note that when a translate occurs, it is necessary to transform the path and the area. Similarly, within draw we must draw the path and the area.

  2. You can determine the bounding box for a shape by calling the getBounds2D() method upon the underlying GeneralPath instance. Note: you need not worry about the Area instance for the bounding box as our model ensures that the GeneralPath has the full extent.

  3. Make sure you first understand the cause of the problem. Only then should you decide how to redesign the logic to support the new semantics.

  4. This is definately the most complicated part of the project. Yet it is possible to support resizing without making any changes to the concrete classes. This is because the underlying GeneralPath and Area objects support arbitrary affine transformations. An example of that appears in the existinging CompoundShape.translate method.

    Note that the AffineTransform class provides a getScaleInstance to perform scaling. However the scale is performed relative to the origin of the coordinate system as a fixed point. If you try to use that transformation by itself, you will not get the desired effect in general. Objects would appear to drift away from the origin when enlarged.

    Instead, you will need to carefully combine transformations. Specifically, the corner opposite to the one being dragged should appear fixed for this operation. You can accomplish this by first translating the shape so that the opposite corner lies at the origin. Then you can safely perform the scale, and finally do another translation so that the origin returns to the original position of the fixed corner (for related discussion, see related CSCI 146 assignment, although you need not formulate the low-level matrices).


Original Source Code

Although we have based on project on the version of the code given by our textbook's author, we wish to have you begin with our modified code. This version includes the implementation for Improvement A.

Download files here or get them at turing.slu.edu:/Public/goldwasser/290/assignments/scene4


Artifacts to Submit

Please submit the source code for your entire project exported together into a single .jar file. That jar file must include both the .java files and .class files. In Eclipse, you can build such a JAR file from a project by going to "File -> Export" menu, selecing "Java -> JAR file" as the type, and then on the next screen make sure to select the option "Export Java source files and resources".

You must also include a readme.txt file with your assignment. Your readme file should clearly explain all major modifications that you made from the original code base, and the reason for those design decisions. When working as a pair, the readme should also provide an overview of the contributions that each team member made to the project. If you create the readme as a file within the eclipse project, please make sure that it is included within the jar file. Alternatively, you may feel free to submit the readme as a separate file from the jar.


Extra Credit

Try the following on our demonstration. Grab and drag the top-right corner of a shape and pull it downward so that it goes even lower than the bottom edge of that shape. Our software allows such a drag and in essence inverts the displayed shape with the "top" appearing below the "bottom". We similarly perform left-to-right flips if a left control point is pulled to the right of the right edge or vice versa.

For extra credit, support such robust functionality with your own project.


Michael Goldwasser
CSCI 290, Fall 2011
Last modified: Tuesday, 27 September 2011
Assignments | Course Home | Documentation | Linux Lab Hours | Schedule & Lecture Notes | Submit