Exemplo n.º 1
0
 /**
  * Adds a <CODE>Chunk</CODE>, <CODE>Anchor</CODE> or another <CODE>Phrase</CODE> to this <CODE>
  * Phrase</CODE>.
  *
  * @param o an object of type <CODE>Chunk</CODE>, <CODE>Anchor</CODE> or <CODE>Phrase</CODE>
  * @return a boolean
  * @throws ClassCastException when you try to add something that isn't a <CODE>Chunk</CODE>,
  *     <CODE>Anchor</CODE> or <CODE>Phrase</CODE>
  */
 public boolean add(Object o) {
   if (o == null) return false;
   if (o instanceof String) {
     return super.add(new Chunk((String) o, font));
   }
   if (o instanceof RtfElementInterface) {
     return super.add(o);
   }
   try {
     Element element = (Element) o;
     switch (element.type()) {
       case Element.CHUNK:
         return addChunk((Chunk) o);
       case Element.PHRASE:
       case Element.PARAGRAPH:
         Phrase phrase = (Phrase) o;
         boolean success = true;
         Element e;
         for (Iterator i = phrase.iterator(); i.hasNext(); ) {
           e = (Element) i.next();
           if (e instanceof Chunk) {
             success &= addChunk((Chunk) e);
           } else {
             success &= this.add(e);
           }
         }
         return success;
       case Element.MARKED:
       case Element.ANCHOR:
       case Element.ANNOTATION:
       case Element.TABLE: // case added by David Freels
       case Element.PTABLE: // case added by mr. Karen Vardanyan
         // This will only work for PDF!!! Not for RTF/HTML
       case Element.LIST:
       case Element.YMARK:
         return super.add(o);
       default:
         throw new ClassCastException(String.valueOf(element.type()));
     }
   } catch (ClassCastException cce) {
     throw new ClassCastException("Insertion of illegal Element: " + cce.getMessage());
   }
 }