Package limelight.ui.model

Source Code of limelight.ui.model.PanelIterator

//- Copyright © 2008-2011 8th Light, Inc. All Rights Reserved.
//- Limelight and all included source files are distributed under terms of the MIT License.

package limelight.ui.model;

import limelight.LimelightException;
import limelight.ui.Panel;

import java.util.Iterator;
import java.util.Stack;

// TODO MDM Does anyone use me?
public class PanelIterator implements Iterator<Panel>
{
  private final Stack<Iterator<Panel>> iterators = new Stack<Iterator<Panel>>();
  private Panel next;

  public PanelIterator(PanelBase root)
  {
    this.next = root;
    if(root instanceof ParentPanel)
      iterators.push(((ParentPanel)root).getChildren().iterator());
  }

  public boolean hasNext()
  {
    return next != null;
  }

  public Panel next()
  {
    Panel value = next;
    next = null;
    if(value != null)
    {
      Iterator<Panel> iterator = findNextValidIterator();
      if(iterator != null)
      {
        next = iterator.next();

        if(next instanceof ParentPanelBase)
        {
          final ParentPanelBase nextParent = (ParentPanelBase) next;
          if(nextParent.hasChildren())
            iterators.push(nextParent.getChildren().iterator());
        }
      }
    }

    return value;
  }

  private Iterator<Panel> findNextValidIterator()
  {
    while(!iterators.empty() && !iterators.peek().hasNext())
      iterators.pop();

    if(iterators.empty())
      return null;
    else
      return iterators.peek();
  }

  public void remove()
  {
    throw new LimelightException("Iterator.remove is not allowed");
  }
}
TOP

Related Classes of limelight.ui.model.PanelIterator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.