Generated on Thu Nov 2 14:49:35 2006 for Gecode/J by doxygen 1.5.0

LayoutCursor.java

Go to the documentation of this file.
00001 /* -*- indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Marco Kuhlmann <kuhlmann@ps.uni-sb.de>
00005  *     Guido Tack <tack@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Marco Kuhlmann, 2005
00009  *     Guido Tack, 2006
00010  *
00011  *  Last modified:
00012  *     $Date: 2006-10-26 11:31:58 +0200 (Thu, 26 Oct 2006) $ by $Author: tack $
00013  *     $Revision: 3796 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  See the file "LICENSE" for information on usage and
00020  *  redistribution of this file, and for a
00021  *     DISCLAIMER OF ALL WARRANTIES.
00022  *
00023  */
00024 
00025 package org.gecode.gist;
00026 
00027 import java.util.*;
00028 
00029 public class LayoutCursor extends DefaultNodeCursor {
00030     
00031     public LayoutCursor(VisualNode theNode) {
00032         super(theNode);
00033     }
00034         
00035     private VisualNode getVisualNode() {
00036         return ((VisualNode) super.getCurrentNode());
00037     }
00038     
00039     public boolean mayMoveDownwards() {
00040         if (super.mayMoveDownwards()) {
00041             return (getVisualNode().isDirty() && ! getVisualNode().isHidden());
00042         } else {
00043             return false;
00044         }
00045     }
00046     
00047     public void processCurrentNode() {
00048         VisualNode currentNode = getVisualNode();
00049         if (currentNode.isDirty()) {
00050             Extent extent = new Extent(currentNode.getWidth());
00051             int numberOfChildren = currentNode.getNumberOfChildren();
00052             Shape shape;
00053             if (numberOfChildren == -1) {
00054                 shape = currentNode.getUnknownShape();
00055             } else if (currentNode.isHidden()) {
00056                 shape = currentNode.getHiddenShape();
00057             } else if (numberOfChildren == 0) {
00058                 shape = new Shape(extent);
00059             } else {
00060                 Iterator childrenIterator;
00061                 ShapeList childShapes = new ShapeList(currentNode.getHorizontalOffset());
00062                 childrenIterator = currentNode.childrenIterator();
00063                 while (childrenIterator.hasNext()) {
00064                     VisualNode nextChild = (VisualNode) childrenIterator.next();
00065                     childShapes.add(nextChild.getShape());
00066                 }
00067                 Shape subtreeShape = childShapes.getMergedShape();
00068                 subtreeShape.extend(- extent.extentL, - extent.extentR);
00069                 shape = new Shape(extent, subtreeShape);
00070                 Iterator offsetIterator = childShapes.offsetIterator();
00071                 childrenIterator = currentNode.childrenIterator();
00072                 while (childrenIterator.hasNext()) {
00073                     VisualNode nextChild = (VisualNode) childrenIterator.next();
00074                     int childOffset = ((Integer) offsetIterator.next()).intValue();
00075                     nextChild.setOffset(childOffset);
00076                 }
00077             }
00078             currentNode.setShape(shape);
00079             currentNode.setBoundingBox(shape.getBoundingBox());
00080             currentNode.setDirty(false);
00081         }
00082     }
00083     
00084 }