COMP 303 - Lecture Notes for Week 8 - Frameworks

Frameworks

Application Frameworks

Applets

Applets

.

Applets

Example Applet

Example Applet

.

Applets as a Framework

Collections Framework

Collections Framework: Interface Types

Collections Framework: Classes

Collections Framework

.

Collection Interface Type

boolean add(Object obj) 
boolean addAll(Collection c) 
void clear() 
boolean contains(Object obj) 
boolean containsAll(Collection c) 
boolean equals(Object obj) 
int hashCode() 
boolean isEmpty() 
Iterator iterator() 
boolean remove(Object obj) 
boolean removeAll(Collection c) 
boolean retainAll(Collection c) 
int size() 
Object[] toArray() 
Object[] toArray(Object[] a) 

Iterator Interface Type

boolean hasNext()
Object next()
void remove()

AbstractCollection Class

public Object[] toArray()
  {
     Object[] result = new Object[size()];
     Iterator e = iterator();
     for (int i=0; e.hasNext(); i++)
        result[i] = e.next();
     return result;
  }

AbstractCollection Class

Adding a new Class to the Framework

Adding a new Class to the Framework

.

Sets

Lists

boolean add(int index, Object obj)
boolean addAll(int index, Collection c)
Object get(int index)
int indexOf(Object obj)
int lastIndexOf(Object obj)
ListIterator listIterator()
ListIterator listIterator(int index)
Object remove(int index)
Object set(int index, int Object)
List subList(int fromIndex, int toIndex)

List Iterators

int nextIndex()
int previousIndex()
boolean hasPrevious()
Object previous()
void set(Object obj)

List Classes

List Classes

.

Optional Operations

Views

Views

Graph Editor Framework

Graph Editor Framework

User Interface

User Interface

.

Mouse Operations

Division of Responsibility

Adding Nodes and Edges

Adding Nodes and Edges

PROTOTYPE Pattern

Context

  1. A system instantiates objects of classes that are not known when the system is built.
  2. You do not want to require a separate class for each kind of object.
  3. You want to avoid a separate hierarchy of classes whose responsibility it is to create the objects.

Solution

  1. Define a prototype interface type that is common to all created objects.
  2. Supply a prototype object for each kind of object that the system creates.
  3. Clone the prototype object whenever a new object of the given kind is required.

PROTOTYPE Pattern

.

PROTOTYPE Pattern

Name in Design Pattern
Actual name (graph editor)
Prototype
Node
ConcretePrototype1
CircleNode
Creator
The GraphPanel that handles the mouse operation for adding new nodes


Framework Classes

Node Connection Points

.

Framework Classes

Framework Classes

Framework UI Classes

A Framework Instance

Programmer responsibilities

A Framework Instance

.

A Framework Instance

Generic Framework Code

Add New Node

public void mousePressed(MouseEvent event)
{
   Point2D mousePoint = event.getPoint();
   Object tool = toolBar.getSelectedTool();
   ...
   if (tool instanceof Node)
   {
      Node prototype = (Node) tool;
      Node newNode = (Node)prototype.clone();
      graph.add(newNode, mousePoint);
   }
   ...
   repaint();
}

Add New Node

.

Add New Edge

Add New Edge

Add New Edge

.

Enhancing the Framework

Enhancing the Framework

.

Enhancing the Framework

Using the Framework Enhancement

Another Framework Instance

.

Another Framework Instance

Edge Properties

.

Multiline String Property Editor

.

Enhancing the Framework II

Enhancing the Framework II


.