Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/outerj/pollo/xmleditor/displayspec/ChainedDisplaySpecification.java


1   package org.outerj.pollo.xmleditor.displayspec;
2   
3   import org.w3c.dom.Element;
4   
5   import java.awt.*;
6   import java.util.ArrayList;
7   
8   /**
9    * A wrapper class around a display specification that allows chaining it.
10   * The way chaining works is that if the current instance returns null,
11   * the next instance is consulted for a value. Note that the methods in
12   * IDisplaySpecification are supposed to always return a value, so make
13   * sure that on the end of the chain there's a display specification that
14   * always return something for each method.
15   *
16   * @author Bruno Dumon
17   */
18  public class ChainedDisplaySpecification implements IDisplaySpecification
19  {
20      protected ArrayList displaySpecs = new ArrayList();
21  
22      public void add(IDisplaySpecification displaySpec)
23      {
24          displaySpecs.add(displaySpec);
25      }
26  
27      public Color getBackgroundColor()
28      {
29          for (int i = 0; i < displaySpecs.size(); i++)
30          {
31              Color result = ((IDisplaySpecification)displaySpecs.get(i)).getBackgroundColor();
32              if (result != null)
33                  return result;
34          }
35          return null;
36      }
37  
38      public ElementSpec getElementSpec(String namespaceURI, String localName, Element parent)
39      {
40          for (int i = 0; i < displaySpecs.size(); i++)
41          {
42              ElementSpec result = ((IDisplaySpecification)displaySpecs.get(i))
43                  .getElementSpec(namespaceURI, localName, parent);
44              if (result != null)
45                  return result;
46          }
47          return null;
48      }
49  
50      public ElementSpec getElementSpec(Element element)
51      {
52          for (int i = 0; i < displaySpecs.size(); i++)
53          {
54              ElementSpec result = ((IDisplaySpecification)displaySpecs.get(i))
55                  .getElementSpec(element);
56              if (result != null)
57                  return result;
58          }
59          return null;
60      }
61  
62      public int getTreeType()
63      {
64          for (int i = 0; i < displaySpecs.size(); i++)
65          {
66              int result = ((IDisplaySpecification)displaySpecs.get(i)).getTreeType();
67              if (result != -1)
68                  return result;
69          }
70          return IDisplaySpecification.POLLO_TREE;
71      }
72  }