com.lowagie.text.List Java Examples

The following examples show how to use com.lowagie.text.List. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RtfParser.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Imports the mappings defined in the RtfImportMappings into the
 * RtfImportHeader of this RtfParser2.
 * 
 * @param importMappings 
 * 		The RtfImportMappings to import.
 * @since 2.1.3
 */
private void handleImportMappings(RtfImportMappings importMappings) {
	Iterator it = importMappings.getFontMappings().keySet().iterator();
	while(it.hasNext()) {
		String fontNr = (String) it.next();
		this.importMgr.importFont(fontNr, (String) importMappings.getFontMappings().get(fontNr));
	}
	it = importMappings.getColorMappings().keySet().iterator();
	while(it.hasNext()) {
		String colorNr = (String) it.next();
		this.importMgr.importColor(colorNr, (Color) importMappings.getColorMappings().get(colorNr));
	}
	it = importMappings.getListMappings().keySet().iterator();
	while(it.hasNext()) {
		String listNr = (String) it.next();
		this.importMgr.importList(listNr, (String)importMappings.getListMappings().get(listNr));
	}
	it = importMappings.getStylesheetListMappings().keySet().iterator();
	while(it.hasNext()) {
		String stylesheetListNr = (String) it.next();
		this.importMgr.importStylesheetList(stylesheetListNr, (List) importMappings.getStylesheetListMappings().get(stylesheetListNr));
	}
	
}
 
Example #2
Source File: PdfCell.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private void addList(List list, float left, float right, int alignment) {
	PdfChunk chunk;
	PdfChunk overflow;
	ArrayList allActions = new ArrayList();
	processActions(list, null, allActions);
	int aCounter = 0;
	for (Iterator it = list.getItems().iterator(); it.hasNext();) {
		Element ele = (Element) it.next();
		switch (ele.type()) {
			case Element.LISTITEM:
				ListItem item = (ListItem) ele;
				line = new PdfLine(left + item.getIndentationLeft(), right, alignment, item.getLeading());
				line.setListItem(item);
				for (Iterator j = item.getChunks().iterator(); j.hasNext();) {
					chunk = new PdfChunk((Chunk) j.next(), (PdfAction) allActions.get(aCounter++));
					while ((overflow = line.add(chunk)) != null) {
						addLine(line);
						line = new PdfLine(left + item.getIndentationLeft(), right, alignment, item.getLeading());
						chunk = overflow;
					}
					line.resetAlignment();
					addLine(line);
					line = new PdfLine(left + item.getIndentationLeft(), right, alignment, leading);
				}
				break;
			case Element.LIST:
				List sublist = (List) ele;
				addList(sublist, left + sublist.getIndentationLeft(), right, alignment);
				break;
		}
	}
}
 
Example #3
Source File: PdfCell.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Processes all actions contained in the cell.
 * 
 * @param element an element in the cell
 * @param action an action that should be coupled to the cell
 * @param allActions
 */

protected void processActions(Element element, PdfAction action, ArrayList allActions) {
	if (element.type() == Element.ANCHOR) {
		String url = ((Anchor) element).getReference();
		if (url != null) {
			action = new PdfAction(url);
		}
	}
	Iterator i;
	switch (element.type()) {
		case Element.PHRASE:
		case Element.SECTION:
		case Element.ANCHOR:
		case Element.CHAPTER:
		case Element.LISTITEM:
		case Element.PARAGRAPH:
			for (i = ((ArrayList) element).iterator(); i.hasNext();) {
				processActions((Element) i.next(), action, allActions);
			}
			break;
		case Element.CHUNK:
			allActions.add(action);
			break;
		case Element.LIST:
			for (i = ((List) element).getItems().iterator(); i.hasNext();) {
				processActions((Element) i.next(), action, allActions);
			}
			break;
		default:
			int n = element.getChunks().size();
			while (n-- > 0) {
				allActions.add(action);
			}
			break;
	}
}
 
Example #4
Source File: PdfCell.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void addList(List list, float left, float right, int alignment) {
    PdfChunk chunk;
    PdfChunk overflow;
    ArrayList allActions = new ArrayList();
    processActions(list, null, allActions);
    int aCounter = 0;
    for (Iterator it = list.getItems().iterator(); it.hasNext();) {
        Element ele = (Element)it.next();
        switch (ele.type()) {
            case Element.LISTITEM:
                ListItem item = (ListItem)ele;
                line = new PdfLine(left + item.getIndentationLeft(), right, alignment, item.getLeading());
                line.setListItem(item);
                for (Iterator j = item.getChunks().iterator(); j.hasNext();) {
                    chunk = new PdfChunk((Chunk) j.next(), (PdfAction) (allActions.get(aCounter++)));
                    while ((overflow = line.add(chunk)) != null) {
                        addLine(line);
                        line = new PdfLine(left + item.getIndentationLeft(), right, alignment, item.getLeading());
                        chunk = overflow;
                    }
                    line.resetAlignment();
                    addLine(line);
                    line = new PdfLine(left + item.getIndentationLeft(), right, alignment, leading);
                }
                break;
            case Element.LIST:
                List sublist = (List)ele;
                addList(sublist, left + sublist.getIndentationLeft(), right, alignment);
                break;
        }
    }
}
 
Example #5
Source File: PdfCell.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Processes all actions contained in the cell.
 * @param element	an element in the cell
 * @param action	an action that should be coupled to the cell
 * @param allActions
 */

protected void processActions(Element element, PdfAction action, ArrayList allActions) {
    if (element.type() == Element.ANCHOR) {
        String url = ((Anchor) element).getReference();
        if (url != null) {
            action = new PdfAction(url);
        }
    }
    Iterator i;
    switch (element.type()) {
        case Element.PHRASE:
        case Element.SECTION:
        case Element.ANCHOR:
        case Element.CHAPTER:
        case Element.LISTITEM:
        case Element.PARAGRAPH:
            for (i = ((ArrayList) element).iterator(); i.hasNext();) {
                processActions((Element) i.next(), action, allActions);
            }
            break;
        case Element.CHUNK:
            allActions.add(action);
            break;
        case Element.LIST:
            for (i = ((List) element).getItems().iterator(); i.hasNext();) {
                processActions((Element) i.next(), action, allActions);
            }
            break;
        default:
            int n = element.getChunks().size();
            while (n-- > 0)
                allActions.add(action);
            break;
    }
}
 
Example #6
Source File: RtfImportMgr.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Imports a stylesheet list value. The stylesheet number for the stylesheet defined
 * is determined and then the resulting mapping is added.
 */
public boolean importStylesheetList(String listNr, List listIn) {
    RtfList rtfList = new RtfList(this.rtfDoc, listIn);
    rtfList.setRtfDocument(this.rtfDoc);
    // TODO HGS - Finish implementation of import
    //this.importStylesheetListMapping.put(listNr, Integer.toString(this.rtfDoc.getDocumentHeader().getRtfParagraphStyle(styleName)(rtfList)));
    return true;
}
 
Example #7
Source File: ElementFactory.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Creates a List object based on a list of properties.
 * 
 * @param attributes
 * @return the List
 */
public static List getList(Properties attributes) {
	List list = new List();

	list.setNumbered(Utilities.checkTrueOrFalse(attributes, ElementTags.NUMBERED));
	list.setLettered(Utilities.checkTrueOrFalse(attributes, ElementTags.LETTERED));
	list.setLowercase(Utilities.checkTrueOrFalse(attributes, ElementTags.LOWERCASE));
	list.setAutoindent(Utilities.checkTrueOrFalse(attributes, ElementTags.AUTO_INDENT_ITEMS));
	list.setAlignindent(Utilities.checkTrueOrFalse(attributes, ElementTags.ALIGN_INDENTATION_ITEMS));

	String value;

	value = attributes.getProperty(ElementTags.FIRST);
	if (value != null) {
		char character = value.charAt(0);
		if (Character.isLetter(character)) {
			list.setFirst(character);
		} else {
			list.setFirst(Integer.parseInt(value));
		}
	}

	value = attributes.getProperty(ElementTags.LISTSYMBOL);
	if (value != null) {
		list.setListSymbol(new Chunk(value, FontFactory.getFont(attributes)));
	}

	value = attributes.getProperty(ElementTags.INDENTATIONLEFT);
	if (value != null) {
		list.setIndentationLeft(Float.parseFloat(value + "f"));
	}

	value = attributes.getProperty(ElementTags.INDENTATIONRIGHT);
	if (value != null) {
		list.setIndentationRight(Float.parseFloat(value + "f"));
	}

	value = attributes.getProperty(ElementTags.SYMBOLINDENT);
	if (value != null) {
		list.setSymbolIndent(Float.parseFloat(value));
	}

	return list;
}
 
Example #8
Source File: ElementFactory.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Creates a List object based on a list of properties.
 * @param attributes
 * @return the List
 */
public static List getList(Properties attributes) {
	List list = new List();

	list.setNumbered(Utilities.checkTrueOrFalse(attributes,
			ElementTags.NUMBERED));
	list.setLettered(Utilities.checkTrueOrFalse(attributes,
			ElementTags.LETTERED));
	list.setLowercase(Utilities.checkTrueOrFalse(attributes,
			ElementTags.LOWERCASE));
	list.setAutoindent(Utilities.checkTrueOrFalse(attributes,
			ElementTags.AUTO_INDENT_ITEMS));
	list.setAlignindent(Utilities.checkTrueOrFalse(attributes,
			ElementTags.ALIGN_INDENTATION_ITEMS));

	String value;

	value = attributes.getProperty(ElementTags.FIRST);
	if (value != null) {
		char character = value.charAt(0);
		if (Character.isLetter(character)) {
			list.setFirst(character);
		} else {
			list.setFirst(Integer.parseInt(value));
		}
	}

	value = attributes.getProperty(ElementTags.LISTSYMBOL);
	if (value != null) {
		list
				.setListSymbol(new Chunk(value, FontFactory
						.getFont(attributes)));
	}

	value = attributes.getProperty(ElementTags.INDENTATIONLEFT);
	if (value != null) {
		list.setIndentationLeft(Float.parseFloat(value + "f"));
	}

	value = attributes.getProperty(ElementTags.INDENTATIONRIGHT);
	if (value != null) {
		list.setIndentationRight(Float.parseFloat(value + "f"));
	}

	value = attributes.getProperty(ElementTags.SYMBOLINDENT);
	if (value != null) {
		list.setSymbolIndent(Float.parseFloat(value));
	}

	return list;
}
 
Example #9
Source File: PatchRtfDocument.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public RtfBasicElement[] mapElement( Element element ) throws DocumentException {
  ArrayList<RtfBasicElement> rtfElements = new ArrayList<RtfBasicElement>();
  if ( element instanceof RtfBasicElement ) {
    RtfBasicElement rtfElement = (RtfBasicElement) element;
    rtfElement.setRtfDocument( rtfDoc );
    return new RtfBasicElement[] { rtfElement };
  }
  switch ( element.type() ) {
    case Element.CHUNK:
      Chunk chunk = (Chunk) element;
      if ( chunk.hasAttributes() ) {
        if ( chunk.getAttributes().containsKey( Chunk.IMAGE ) ) {
          rtfElements.add( new RtfImage( rtfDoc, chunk.getImage() ) );
        } else if ( chunk.getAttributes().containsKey( Chunk.NEWPAGE ) ) {
          rtfElements.add( new RtfNewPage( rtfDoc ) );
        } else if ( chunk.getAttributes().containsKey( Chunk.TAB ) ) {
          Float tabPos = (Float) ( (Object[]) chunk.getAttributes().get( Chunk.TAB ) )[1];
          RtfTab tab = new RtfTab( tabPos.floatValue(), RtfTab.TAB_LEFT_ALIGN );
          tab.setRtfDocument( rtfDoc );
          rtfElements.add( tab );
          rtfElements.add( new RtfChunk( rtfDoc, new Chunk( "\t" ) ) );
        } else {
          rtfElements.add( new RtfChunk( rtfDoc, (Chunk) element ) );
        }
      } else {
        rtfElements.add( new RtfChunk( rtfDoc, (Chunk) element ) );
      }
      break;
    case Element.PHRASE:
      rtfElements.add( new RtfPhrase( rtfDoc, (Phrase) element ) );
      break;
    case Element.PARAGRAPH:
      rtfElements.add( new RtfParagraph( rtfDoc, (Paragraph) element ) );
      break;
    case Element.ANCHOR:
      rtfElements.add( new RtfAnchor( rtfDoc, (Anchor) element ) );
      break;
    case Element.ANNOTATION:
      rtfElements.add( new RtfAnnotation( rtfDoc, (Annotation) element ) );
      break;
    case Element.IMGRAW:
    case Element.IMGTEMPLATE:
    case Element.JPEG:
      rtfElements.add( new RtfImage( rtfDoc, (Image) element ) );
      break;
    case Element.AUTHOR:
    case Element.SUBJECT:
    case Element.KEYWORDS:
    case Element.TITLE:
    case Element.PRODUCER:
    case Element.CREATIONDATE:
      rtfElements.add( new RtfInfoElement( rtfDoc, (Meta) element ) );
      break;
    case Element.LIST:
      rtfElements.add( new RtfList( rtfDoc, (List) element ) ); // TODO: Testing
      break;
    case Element.LISTITEM:
      rtfElements.add( new RtfListItem( rtfDoc, (ListItem) element ) ); // TODO: Testing
      break;
    case Element.SECTION:
      rtfElements.add( new RtfSection( rtfDoc, (Section) element ) );
      break;
    case Element.CHAPTER:
      rtfElements.add( new RtfChapter( rtfDoc, (Chapter) element ) );
      break;
    case Element.TABLE:
      if ( element instanceof Table ) {
        rtfElements.add( new PatchRtfTable( rtfDoc, (Table) element ) );
      } else {
        rtfElements.add( new PatchRtfTable( rtfDoc, ( (SimpleTable) element ).createTable() ) );
      }
      break;
    case Element.PTABLE:
      if ( element instanceof PdfPTable ) {
        rtfElements.add( new PatchRtfTable( rtfDoc, (PdfPTable) element ) );
      } else {
        rtfElements.add( new PatchRtfTable( rtfDoc, ( (SimpleTable) element ).createTable() ) );
      }
      break;
  }

  return rtfElements.toArray( new RtfBasicElement[rtfElements.size()] );
}