edu.washington.cs.supple.render
Class AbstractSolver

java.lang.Object
  extended byedu.washington.cs.supple.render.AbstractSolver
All Implemented Interfaces:
Solver
Direct Known Subclasses:
BottomUpSearchSolver

public abstract class AbstractSolver
extends java.lang.Object
implements Solver

The base class for all UI solvers

Author:
kgajos

Field Summary
protected  java.util.Hashtable bags
           
static int BOTTOM_UP
          Variable ordering method
protected  ConstraintFactory constraintFactory
           
protected  CostFunction costFunction
           
protected  java.util.Vector currentRenderingConstraints
           
protected  java.util.Vector currentRenderingHints
           
protected  SearchParameters curSearchParameters
           
protected  Solution curSolution
           
protected  WidgetBag curSolutionRoot
           
protected  java.util.Vector finalSolutionListeners
           
protected  boolean interrupted
           
protected  SolverListener listener
           
static int MRV
          Variable ordering method
static int propagationLevels
           
protected  int searchCount
           
static int SORT_COST
          Value sorting method
static int SORT_COST_REVERSE
          Value sorting method
static int SORT_RANDOM
          Value sorting method
protected  java.util.Vector spies
           
static int TOP_DOWN
          Variable ordering method
static int valueSorting
           
static int variableOrdering
           
protected  WidgetFactory widgetFactory
           
 
Constructor Summary
AbstractSolver()
           
 
Method Summary
 void addFinalSolutionListener(FinalSolutionListener listener)
           
 void addSpy(SolverListener listener)
           
protected  void applyConstraint(RenderingConstraint constraint)
           
protected  void applyConstraints()
           
protected  void applyCostFunction(java.util.Vector widgets)
          Assigns the cost to each widget based on what the current cost function thinks about the assignment; if the cost function deems the widget unacceptable, it gets removed from the underlying data structure
protected  void applyHint(RenderingHint hint)
           
protected  void applyHints()
           
protected  void applyRenderingConstraint(RenderingConstraint constraint)
           
protected  void applySameRenderingConstraint(SameRenderingConstraint constraint)
          Given a same rendering constraint, this method creates all the necessary enforcement objects throughout the widget bag structure (the bag structure must be built before this method is called).
protected  void applySameRenderingHint(SameRenderingHint hint)
          Given a same rendering hint, this method creates all the necessary enforcement objects throughout the widget bag structure (the bag structure must be built before this method is called).
 WidgetBag buildBagStructure(UiObject object, SearchParameters searchParameters)
           
static java.util.Vector getBottomUpNodeList(WidgetBag root)
          returns a list of nodes -- bottom up (i.e.
static java.util.Vector getLeafNodes(WidgetBag root)
          returns a list of leaf nodes
protected  float getShortcutCost(java.util.Collection shortcuts)
           
 java.util.Vector getTopDownNodeList(WidgetBag root)
           
 void interruptSearch()
           
protected  void notifyFinalSolutionListeners(Solution soln)
           
protected  boolean notifySpies(Solution soln)
          For render-time notification to spies
 void removeFinalSolutionListener(FinalSolutionListener listener)
           
 void removeSpy(SolverListener listener)
           
protected  void reset()
           
 void setListener(SolverListener listener)
           
protected  void solutionFound(WidgetBag root)
          Used by subclasses to report a solution when one is found
protected  void solutionFound(WidgetBag root, java.util.Collection shortcuts)
           
abstract  Solution solve(UiObject object, java.awt.Dimension sizeConstraint)
          The interface for invoking the search routine
abstract  Solution solve(UiObject object, SearchParameters searchParameters, java.awt.Dimension sizeConstraint)
          The interface for invoking the search routine that allows you to override the search parameters
protected  void stop()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SORT_COST

public static final int SORT_COST
Value sorting method

See Also:
Constant Field Values

SORT_COST_REVERSE

public static final int SORT_COST_REVERSE
Value sorting method

See Also:
Constant Field Values

SORT_RANDOM

public static final int SORT_RANDOM
Value sorting method

See Also:
Constant Field Values

valueSorting

public static int valueSorting

BOTTOM_UP

public static final int BOTTOM_UP
Variable ordering method

See Also:
Constant Field Values

TOP_DOWN

public static final int TOP_DOWN
Variable ordering method

See Also:
Constant Field Values

MRV

public static final int MRV
Variable ordering method

See Also:
Constant Field Values

variableOrdering

public static int variableOrdering

widgetFactory

protected WidgetFactory widgetFactory

constraintFactory

protected ConstraintFactory constraintFactory

costFunction

protected CostFunction costFunction

curSearchParameters

protected SearchParameters curSearchParameters

listener

protected SolverListener listener

finalSolutionListeners

protected java.util.Vector finalSolutionListeners

spies

protected java.util.Vector spies

curSolutionRoot

protected WidgetBag curSolutionRoot

curSolution

protected Solution curSolution

bags

protected java.util.Hashtable bags

searchCount

protected int searchCount

interrupted

protected boolean interrupted

currentRenderingHints

protected java.util.Vector currentRenderingHints

currentRenderingConstraints

protected java.util.Vector currentRenderingConstraints

propagationLevels

public static int propagationLevels
Constructor Detail

AbstractSolver

public AbstractSolver()
Method Detail

solve

public abstract Solution solve(UiObject object,
                               java.awt.Dimension sizeConstraint)
                        throws java.lang.InterruptedException
The interface for invoking the search routine

Specified by:
solve in interface Solver
Parameters:
object - the description of the UI to be rendered
sizeConstraint - the maximum size
Returns:
The solved bag structure if all went well; null otherwise
Throws:
java.lang.InterruptedException

solve

public abstract Solution solve(UiObject object,
                               SearchParameters searchParameters,
                               java.awt.Dimension sizeConstraint)
                        throws java.lang.InterruptedException
The interface for invoking the search routine that allows you to override the search parameters

Specified by:
solve in interface Solver
Parameters:
object - the description of the UI to be rendered
sizeConstraint - the maximum size
searchParameters - hand-set parameters for the search
Returns:
The solved bag structure if all went well; null otherwise
Throws:
java.lang.InterruptedException

reset

protected void reset()

buildBagStructure

public WidgetBag buildBagStructure(UiObject object,
                                   SearchParameters searchParameters)

applyCostFunction

protected void applyCostFunction(java.util.Vector widgets)
Assigns the cost to each widget based on what the current cost function thinks about the assignment; if the cost function deems the widget unacceptable, it gets removed from the underlying data structure

Parameters:
widgets - a set of widgets to be "priced"; may get modified

applyHints

protected void applyHints()

applyHint

protected void applyHint(RenderingHint hint)

applySameRenderingHint

protected void applySameRenderingHint(SameRenderingHint hint)
Given a same rendering hint, this method creates all the necessary enforcement objects throughout the widget bag structure (the bag structure must be built before this method is called).

Parameters:
hint - same rendering hint

applyConstraints

protected void applyConstraints()

applyConstraint

protected void applyConstraint(RenderingConstraint constraint)

applySameRenderingConstraint

protected void applySameRenderingConstraint(SameRenderingConstraint constraint)
Given a same rendering constraint, this method creates all the necessary enforcement objects throughout the widget bag structure (the bag structure must be built before this method is called).

Parameters:
constraint - same rendering constraint

applyRenderingConstraint

protected void applyRenderingConstraint(RenderingConstraint constraint)

getBottomUpNodeList

public static java.util.Vector getBottomUpNodeList(WidgetBag root)
returns a list of nodes -- bottom up (i.e. guaranteeing that a parent node only appears after all of its children)

Parameters:
root - the root bag
Returns:
a bottom-up list of nodes in the bag structure

getLeafNodes

public static java.util.Vector getLeafNodes(WidgetBag root)
returns a list of leaf nodes

Parameters:
root - the root bag
Returns:
a list of leaf nodes in the bag structure

getTopDownNodeList

public java.util.Vector getTopDownNodeList(WidgetBag root)
Parameters:
root - the root bag
Returns:
a top-down list of nodes in the bag structure

solutionFound

protected void solutionFound(WidgetBag root)
Used by subclasses to report a solution when one is found

Parameters:
root - the root bag of a solution

solutionFound

protected void solutionFound(WidgetBag root,
                             java.util.Collection shortcuts)

interruptSearch

public void interruptSearch()
Specified by:
interruptSearch in interface Solver

stop

protected void stop()
             throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

setListener

public void setListener(SolverListener listener)
Specified by:
setListener in interface Solver

addSpy

public void addSpy(SolverListener listener)
Specified by:
addSpy in interface Solver

removeSpy

public void removeSpy(SolverListener listener)
Specified by:
removeSpy in interface Solver

notifySpies

protected boolean notifySpies(Solution soln)
For render-time notification to spies

Parameters:
soln - the current solution
Returns:

addFinalSolutionListener

public void addFinalSolutionListener(FinalSolutionListener listener)
Specified by:
addFinalSolutionListener in interface Solver

removeFinalSolutionListener

public void removeFinalSolutionListener(FinalSolutionListener listener)
Specified by:
removeFinalSolutionListener in interface Solver

notifyFinalSolutionListeners

protected void notifyFinalSolutionListeners(Solution soln)

getShortcutCost

protected float getShortcutCost(java.util.Collection shortcuts)