Example usage for com.lowagie.text List size

List of usage examples for com.lowagie.text List size

Introduction

In this page you can find the example usage for com.lowagie.text List size.

Prototype

public int size() 

Source Link

Document

Gets the size of the list.

Usage

From source file:Driver.RunTestCases.java

License:Open Source License

public void generateReport() {

    File file = new File("Report1.pdf");
    FileOutputStream fileout = null;
    try {/*from   w  w w  .j  av a2s  .c  o  m*/
        fileout = new FileOutputStream(file);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    Document document = new Document();
    try {
        PdfWriter.getInstance(document, fileout);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    document.addAuthor("AGTT");
    document.addTitle("AGTT Report");

    document.open();
    Boolean status = true;
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new FileReader("Results.txt"));
        String line = null;
        String testCase = null;
        Chunk chunk = null;
        int index = 0;
        List list = new List();
        while ((line = reader.readLine()) != null) {
            if (line.contains("Case")) {

                if (index > 0) {
                    System.out.println(line + status + list.size());
                    if (status == false) {
                        chunk.setBackground(Color.RED);
                    }
                    if (status == true) {
                        chunk.setBackground(Color.GREEN);
                    }
                    document.add(chunk);
                    document.add((Element) list);
                    status = true;
                    list = new List();
                    testCase = null;
                }
                chunk = new Chunk(line + "\n");
                Font font = new Font(Font.TIMES_ROMAN);
                font.setSize(18);
                chunk.setFont(font);
                index++;
            } else {
                if (line.contains("not")) {
                    status = false;
                }
                list.add(line);
            }
            //   document.add(chunk);
        }
    } catch (IOException | DocumentException e) {
        e.printStackTrace();
    }
    document.close();
}

From source file:org.areasy.common.doclet.Doclet.java

License:Open Source License

/**
 * Processes all packages of a given javadoc root.
 *
 * @param root The javadoc root.//from   ww w  . j a v a  2 s.co  m
 * @throws Exception
 */
private void listClasses(RootDoc root) throws Exception {
    try {
        Document.initialize();

        Document.open();

        Bookmarks.init();
    } catch (IOException e) {
        log.error("Failed to open PDF file for writing", e);
        return;
    }

    // Prepare index
    index = new Index(Document.getWriter(), Document.instance());

    // Print title page
    CustomTitle title = new CustomTitle(Document.instance());
    State.setCurrentHeaderType(HEADER_DETAILS);
    title.print();

    // Print description page
    CustomDescription description = new CustomDescription(Document.instance());
    State.setCurrentHeaderType(HEADER_DETAILS);
    description.print();

    // Print javadoc overview
    State.setCurrentHeaderType(HEADER_OVERVIEW);
    Overview.print(root);

    State.setCurrentHeaderType(HEADER_API);

    ClassDoc[] classes = root.classes();

    Map pkgMap = null;
    if (DefaultConfiguration.getPackageOrder() != null) {
        // Use a custom comparator to sort the list of packages in a custom way
        Comparator cmp = new Comparator() {

            public int compare(Object packageName1, Object packageName2) {
                String packageOrder = DefaultConfiguration.getPackageOrder();
                PackageDoc package1 = (PackageDoc) packageName1;
                PackageDoc package2 = (PackageDoc) packageName2;
                int retval1 = packageOrder.indexOf(package1.name());
                int retval2 = packageOrder.indexOf(package2.name());

                if (retval1 < retval2)
                    return -1;
                if (retval1 > retval2)
                    return 1;

                return 0;
            }
        };

        pkgMap = new TreeMap(cmp);
    } else {
        // Use a treemap to create an alphabetically sorted list of all packages
        pkgMap = new TreeMap();
    }

    // Iterate through all single, separately specified classes
    for (int i = 0; i < classes.length; i++) {
        // Fetch the classes list for the package of this class
        List classList = (List) pkgMap.get(classes[i].containingPackage());
        if (classList == null) {
            // If there's no list for this package yet, create one
            classList = new ArrayList();
            pkgMap.put(classes[i].containingPackage(), classList);
        }

        // Store class in the list for this package
        classList.add(classes[i]);
    }

    // Prepare alphabetically sorted list of all classes for bookmarks
    Bookmarks.prepareBookmarkEntries(pkgMap);

    // Now process all packages and classes
    for (Iterator i = pkgMap.entrySet().iterator(); i.hasNext();) {
        // Get package..
        Map.Entry entry = (Map.Entry) i.next();
        PackageDoc pkgDoc = (PackageDoc) entry.getKey();
        List pkgList = (List) entry.getValue();

        // Get list of classes in package...
        ClassDoc[] pkgClasses = (ClassDoc[]) pkgList.toArray(new ClassDoc[pkgList.size()]);
        State.increasePackageChapter();

        // Print package info (includes printing classes info)
        printPackage(pkgDoc, pkgClasses);
    }

    Appendices.print();

    index.create();

    Bookmarks.createBookmarkOutline();

    String endMessage = "PDF completed: " + file.getPath();
    String line = DocletUtility.getLine(endMessage.length());
    log.debug(line);
    log.debug(endMessage);
    log.debug(line);

    // step 5: we close the document
    Document.close();
}

From source file:org.gbif.ipt.task.Eml2Rtf.java

License:Apache License

/**
 * Add authors section./*from w  w  w.ja  v  a2s .co  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:sim.util.media.chart.TimeSeriesChartGenerator.java

License:Academic Free License

public void moveSeries(int index, boolean up) {
    java.util.List allSeries = dataset.getSeries();
    int count = allSeries.size();

    if ((index > 0 && up) || (index < count - 1 && !up)) // it's not the first or the last given the move
    {/*w  w w  .jav  a2  s .  com*/
        // this requires removing everything from the dataset and resinserting, duh
        ArrayList items = new ArrayList(allSeries);
        dataset.removeAllSeries();

        int delta = up ? -1 : 1;
        // now rearrange
        items.add(index + delta, items.remove(index));

        // rebuild the dataset
        for (int i = 0; i < count; i++)
            dataset.addSeries(((XYSeries) (items.get(i))));

        // adjust the seriesAttributes' indices         
        Component[] c = seriesAttributes.getComponents();
        SeriesAttributes csa;
        (csa = (SeriesAttributes) c[index]).setSeriesIndex(index + delta);
        csa.rebuildGraphicsDefinitions();
        (csa = (SeriesAttributes) c[index + delta]).setSeriesIndex(index);
        csa.rebuildGraphicsDefinitions();

        seriesAttributes.remove(index + delta);
        //seriesAttributes.add((SeriesAttributes)(c[index+delta]), index);
        seriesAttributes.add(csa, index);

        revalidate();

        // adjust the stoppables, too
        stoppables.add(index + delta, stoppables.remove(index));
    }

}