Homework 4: Implement a Constraint System for your Retained Object System

05-830, User Interface Software, Spring, 2003

Assigned: March 13
Due:: April 17 (note new date) April 3

The goal of this assignment is to add a constraint solver to your retained object model. This will allow arbitrary constraints to be added to the objects, to keep them connected. Requirements include:

  1. The constraint solver must support constraints expressed on any property of an object, including position properties (X, Y, etc.), color slots, line-thickness, etc.
  2. The programmers must be able to write their own constraints -- it is not sufficient for you just to provide a pre-selected set of constraints. So arbitrary code in the constraints must be allowed.
  3. New classes must be able to add new properties which have constraints in and on them. For example, I should be able to create a new class ValueRect as a subclass of Rectangle that has a new integer property called "value", and then have a constraint on the value slot that computes a new value based on some other properties, and also to have the color of the ValueRect depend on the value with a constraint.
  4. When a constraint recalculates a property of an object that will affect its appearance, then that object should be redrawn. One way to implement this is that when you invalidate any property on which drawing depends (position, color, line thickness, etc.) as a result of that slot containing a constraint that depends on some other value which changes, then put this property on a list. After the end of the constraint solving phase, then demand all the values on the list. If any value of an object changes, then mark that object for redrawing.
  5. You can use any of the constraint solving algorithms discussed in class, or make up your own. Recommended choices as constraint solvers are:
    1. Hudson's lazy constraint solver, discussed in class.
    2. The Amulet constraint solver, which supports pointer variables.
    3. Bjorn N. Freeman-Benson and Alan Borning's multi-way constraint solver.
    4. Brad Vander Zanden's sophisticated multi-way constraint solver.
  6. For objects with multiple ways to set the properties, such as lines where you can set the left or the X, if you implement a one-way constraint system (like A or B above), then you can specify which parameter can be constrained (e.g., X, but not left) and say that when there is a constraint, the other parameter cannot be set. That is, if there is a constraint on the X parameter of a line, then setting the left of that line is either a no-op or an error. If you implement a multi-way constraint system (e.g., C or D), then clearly setting any property should appropriately update the others.

Node-and-Edge Editor

For the last part of the assignment, you will use your GraphicalObjects, constraints, and behavior objects to create a simple node-and-edge drawing editor. You might modify your drawing editor from the previous assignment to create it. The new editor should have the following features, at a minimum:

The user interface is up to you. Most such editors use a tool palette to switch between creating nodes and edges, and being in moving mode. You can do this with Java Swing components if you want, but you can also use keyboard modifiers -- e.g., shift-drag to create edges, plain drag to create nodes, control-drag to move. If it isn't obvious how to use your editor, be sure to display Text objects that document it, preferably outside the drawing area.

In addition, I will be creating constraints of my own to test your designs, so be sure to provide some documentation or comments on how a programmer can create new constraints.

As always, we will probably end up refining this design as you work on the assignment.

Test Program

Please get the following program to work, and I will augment it with additional tests of my own. This will help you document your API for setting up constraints.


Back to Homework Overview
Back to 05-830 main page