List of usage examples for com.lowagie.text List add
public boolean add(Object o)
Object
to the List
. From source file:org.gbif.ipt.task.Eml2Rtf.java
License:Apache License
/** * Add authors section./*from www . j a va 2 s.c o m*/ * * @param doc Document * @param eml EML * @throws DocumentException if problem occurs during add */ private void addAuthors(Document doc, Eml eml) throws DocumentException { // Creating set of authors with different names. (first names + last names). HashSet<Agent> tempAgents = new LinkedHashSet<Agent>(); if (exists(eml.getResourceCreator()) && exists(eml.getResourceCreator().getLastName())) { tempAgents.add(eml.getResourceCreator()); } if (exists(eml.getMetadataProvider()) && exists(eml.getMetadataProvider().getLastName())) { tempAgents.add(eml.getMetadataProvider()); } tempAgents.addAll(eml.getAssociatedParties()); // comparing and removing those repeated agents with same name and same address. Collection<Integer> toRemove = new ArrayList<Integer>(); int counter = 0; for (Iterator<Agent> i = tempAgents.iterator(); i.hasNext(); counter++) { if (toRemove.contains(counter)) { i.next(); i.remove(); } else { Agent agentA = i.next(); // when second iterator should be start boolean flag = false; int countTemp = 0; for (Iterator<Agent> j = tempAgents.iterator(); j.hasNext(); countTemp++) { Agent agentB = j.next(); if (flag) { if (equal(agentA.getLastName(), agentB.getLastName()) && equal(agentA.getFirstName(), agentB.getFirstName()) && equal(agentA.getAddress(), agentB.getAddress())) { toRemove.add(countTemp); } } else if (agentA.equals(agentB)) { flag = true; } } } } Agent[] agentsArray = new Agent[tempAgents.size()]; tempAgents.toArray(agentsArray); // Adding authors Paragraph p = new Paragraph(); p.setFont(font); p.setAlignment(Element.ALIGN_CENTER); java.util.List<Agent> affiliations = new ArrayList<Agent>(); int superScriptCounter = 1; for (int c = 0; c < agentsArray.length; c++) { if (exists(agentsArray[c].getLastName())) { if (c != 0) { p.add(", "); } // First Name and Last Name if (exists(agentsArray[c].getFirstName())) { p.add(agentsArray[c].getFirstName() + " "); } p.add(agentsArray[c].getLastName()); // Looking for addresses and organisations of other authors // (superscripts should not be repeated). boolean isRepeated = false; // look into the affiliations array to find any previous repeated agent info. for (int index = 0; index < affiliations.size(); index++) { if (equal(agentsArray[c].getAddress(), affiliations.get(index).getAddress()) && equal(agentsArray[c].getOrganisation(), affiliations.get(index).getOrganisation())) { p.add(createSuperScript(String.valueOf(index + 1))); isRepeated = true; break; } } // if the agent is not repeated. if (!isRepeated) { p.add(createSuperScript(String.valueOf(superScriptCounter))); affiliations.add(agentsArray[c]); superScriptCounter++; } } } doc.add(p); p.clear(); doc.add(Chunk.NEWLINE); tempAgents.clear(); // <AFFILIATIONS> p = new Paragraph(); p.setFont(font); p.setAlignment(Element.ALIGN_JUSTIFIED); for (int c = 0; c < affiliations.size(); c++) { if (c != 0) { p.add("; "); } p.add((c + 1) + " "); if (exists(affiliations.get(c).getOrganisation())) { p.add(affiliations.get(c).getOrganisation() + ", "); } if (exists(affiliations.get(c).getAddress().getAddress())) { p.add(affiliations.get(c).getAddress().getAddress() + ", "); } if (exists(affiliations.get(c).getAddress().getPostalCode())) { p.add(affiliations.get(c).getAddress().getPostalCode() + ", "); } if (exists(affiliations.get(c).getAddress().getCity())) { p.add(affiliations.get(c).getAddress().getCity()); } if (exists(affiliations.get(c).getAddress().getCountry())) { VocabularyConcept concept = vocabManager.get(Constants.VOCAB_URI_COUNTRY) .findConcept(affiliations.get(c).getAddress().getCountry()); // write country in default language as matched from vocabulary or original value if (exists(concept)) { p.add(", " + WordUtils.capitalizeFully(concept.getPreferredTerm(DEFAULT_LANGUAGE).getTitle())); } else { p.add(", " + WordUtils.capitalizeFully(affiliations.get(c).getAddress().getCountry())); } } } doc.add(p); p.clear(); doc.add(Chunk.NEWLINE); // <Corresponding Authors> p = new Paragraph(); p.setAlignment(Element.ALIGN_JUSTIFIED); p.add(new Phrase(getText("rtf.authors") + ": ", fontTitle)); p.setFont(font); boolean isFirst = true; if (exists(eml.getResourceCreator())) { if (exists(eml.getResourceCreator().getFirstName())) { p.add(eml.getResourceCreator().getFirstName() + " "); } p.add(eml.getResourceCreator().getLastName()); if (exists(eml.getResourceCreator().getEmail())) { p.add(" (" + eml.getResourceCreator().getEmail() + ")"); } isFirst = false; } if (exists(eml.getMetadataProvider())) { boolean sameAsCreator = false; if (!isFirst) { sameAsCreator = equal(eml.getMetadataProvider().getAddress(), eml.getResourceCreator().getAddress()) && equal(eml.getMetadataProvider().getEmail(), eml.getResourceCreator().getEmail()); } if (!sameAsCreator) { p.add(", "); if (exists(eml.getMetadataProvider().getFirstName())) { p.add(eml.getMetadataProvider().getFirstName() + " "); } p.add(eml.getMetadataProvider().getLastName()); if (exists(eml.getMetadataProvider().getEmail())) { p.add(" (" + eml.getMetadataProvider().getEmail() + ")"); } } } p.add(Chunk.NEWLINE); doc.add(p); p.clear(); }
From source file:org.gbif.ipt.task.Eml2Rtf.java
License:Apache License
/** * Add methods section./*ww w . j av a2s.c om*/ * * @param doc Document * @param eml EML * @throws DocumentException if problem occurs during add */ private void addMethods(Document doc, Eml eml) throws DocumentException { if (exists(eml.getMethodSteps()) && !eml.getMethodSteps().isEmpty() || exists(eml.getStudyExtent()) || exists(eml.getStudyExtent()) || exists(eml.getStudyExtent())) { Paragraph p = new Paragraph(); p.setAlignment(Element.ALIGN_JUSTIFIED); p.setFont(font); p.add(new Phrase(getText("rtf.methods"), fontTitle)); p.add(Chunk.NEWLINE); p.add(Chunk.NEWLINE); if (exists(eml.getStudyExtent())) { p.add(new Phrase(getText("rtf.methods.studyExtent"), fontTitle)); p.add(Chunk.NEWLINE); p.add(eml.getStudyExtent().replace("\r\n", "\n")); p.add(Chunk.NEWLINE); p.add(Chunk.NEWLINE); } if (exists(eml.getStudyExtent())) { p.add(new Phrase(getText("rtf.methods.sampling"), fontTitle)); p.add(Chunk.NEWLINE); p.add(eml.getSampleDescription().replace("\r\n", "\n")); p.add(Chunk.NEWLINE); p.add(Chunk.NEWLINE); } if (exists(eml.getQualityControl())) { p.add(new Phrase(getText("rtf.methods.quality"), fontTitle)); p.add(Chunk.NEWLINE); p.add(eml.getQualityControl().replace("\r\n", "\n")); p.add(Chunk.NEWLINE); p.add(Chunk.NEWLINE); } if (eml.getMethodSteps().size() == 1) { p.add(new Phrase(getText("rtf.methods.description"), fontTitle)); p.add(Chunk.NEWLINE); p.add(eml.getMethodSteps().get(0).replace("\r\n", "\n")); p.add(Chunk.NEWLINE); p.add(Chunk.NEWLINE); } else if (eml.getMethodSteps().size() > 1) { p.add(new Phrase(getText("rtf.methods.description") + ". ", fontTitle)); p.add(Chunk.NEWLINE); p.add(Chunk.NEWLINE); List list = new List(List.UNORDERED, 0); list.setIndentationLeft(20); for (String method : eml.getMethodSteps()) { list.add(new ListItem(method.replace("\r\n", "\n"), font)); } p.add(list); } doc.add(p); p.clear(); } }
From source file:org.pz.platypus.plugin.pdf.PdfOutfile.java
License:Open Source License
/** * Adds a paragraph to the currently active bullet list. * * @param para the paragraph to add//w w w .j av a2 s . c o m */ public void addParagraphToList(Paragraph para) { if (para == null) { return; // TODO: should add an error message } List currList; try { currList = (List) bulletLists.peek(); } catch (EmptyStackException ese) { return; // TODO: should add an errro message } ListItem li = new ListItem(para); if (currList != null) { currList.add(li); } iTPara = null; }
From source file:org.pz.platypus.plugin.pdf.PdfOutfile.java
License:Open Source License
/** * End the currently active bullet list. This removes it from the stack of active * bullet lists and adds it to the current column. *///from ww w . j av a 2 s .c om public void endPlainBulletList() { List currList; try { currList = (List) bulletLists.pop(); } catch (EmptyStackException ese) { return; // TODO: should add an error message } // if in a paragraph, add the paragraph to the list before closing the list. if (iTPara != null) { addParagraphToList(iTPara); } // if this list is part of another list (here called the outer list) add it to that list. if (!bulletLists.empty()) { List outerList = (List) bulletLists.peek(); outerList.add(currList); } // if not, add it to the column of text. else { iTColumn.addElement(currList); } }
From source file:org.sonar.report.pdf.DefaultPDFReporter.java
License:Open Source License
private void printProjectInfo(Project project, Section section) throws DocumentException, org.dom4j.DocumentException { List data = new List(); data.add(new ListItem(super.getTextProperty("general.name") + ": " + project.getName())); data.add(new ListItem(super.getTextProperty("general.description") + ": " + project.getDescription())); data.add(new ListItem(super.getTextProperty("general.modules") + ": ")); List sublist = new List(); if (project.getSubprojects().size() != 0) { Iterator<Project> it = project.getSubprojects().iterator(); while (it.hasNext()) { sublist.add(new ListItem(it.next().getName())); }//from w w w . j a v a 2 s . c o m } else { sublist.add(new ListItem(super.getTextProperty("general.no_modules"))); } sublist.setIndentationLeft(indentation); data.add(sublist); section.add(data); printMeasures(project.getMeasures(), section); }
From source file:questions.objects.NestedList.java
public static void main(String[] args) { Document document = new Document(); try {//from w ww . j a va 2s . com PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); List list; ListItem listItem; List sublist; list = new List(true); list.setPreSymbol("Chapter "); list.setPostSymbol(": "); listItem = new ListItem("Isaac Asimov"); list.add(listItem); sublist = new List(true); sublist.setIndentationLeft(10); sublist.setPreSymbol("1."); sublist.add("The Foundation Trilogy"); sublist.add("The Complete Robot"); sublist.add("Caves of Steel"); sublist.add("The Naked Sun"); list.add(sublist); listItem = new ListItem("John Irving"); list.add(listItem); sublist = new List(true); sublist.setIndentationLeft(10); sublist.setPreSymbol("Section 2."); sublist.add("The World according to Garp"); sublist.add("Hotel New Hampshire"); sublist.add("A prayer for Owen Meany"); sublist.add("Widow for a year"); list.add(sublist); listItem = new ListItem("Kurt Vonnegut"); list.add(listItem); sublist = new List(true); sublist.setIndentationLeft(10); sublist.setPreSymbol("3."); sublist.setPostSymbol("# "); sublist.add("Slaughterhouse 5"); sublist.add("Welcome to the Monkey House"); sublist.add("The great pianola"); sublist.add("Galapagos"); list.add(sublist); document.add(list); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } document.close(); }
From source file:questions.objects.NestingLists.java
public static void main(String[] args) throws IOException, DocumentException { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open();/*from w w w .j ava2s . com*/ List list1 = new List(List.ORDERED, 20); list1.add(new ListItem(new Chunk("Level 1 - Item 1"))); list1.add(new ListItem(new Chunk("Level 1 - Item 2"))); list1.add(new ListItem(new Chunk("Level 1 - Item 3"))); List list2 = new List(List.ORDERED, 20); list2.add(new ListItem(new Chunk("Level 2 - Item 1"))); list2.add(new ListItem(new Chunk("Level 2 - Item 2"))); List list3 = new List(List.ORDERED, 20); list3.add(new ListItem(new Chunk("Level 3 - Item 1"))); list3.add(new ListItem(new Chunk("Level 3 - Item 2"))); list3.add(new ListItem(new Chunk("Level 3 - Item 3"))); list3.add(new ListItem(new Chunk("Level 3 - Item 4"))); list2.add(list3); list1.add(list2); list1.add(new ListItem(new Chunk("Level 1 - Item 4"))); document.add(list1); document.close(); }